annotate src/CMakeLists.txt @ 70:1e1c6feb7d83

fix build initcode
author anatofuz
date Tue, 30 Jul 2019 18:00:52 +0900
parents f236eba62a76
children 0bf6872eb250
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
997c54d8912c fix include dir
kono
parents:
diff changeset
1 cmake_minimum_required(VERSION 3.8)
43
b94d72292dfa fix build arm asm file
anatofuz
parents: 42
diff changeset
2 project(xv6cbc C ASM)
62
a28580a75faa fix build fs.img
anatofuz
parents: 61
diff changeset
3 set(BUILD_DIR ${PROJECT_BINARY_DIR})
59
8f435de13b91 fix cmakefiles
tobaru
parents: 58
diff changeset
4 add_subdirectory(tools)
61
b3a3224e1823 fix link arguments...
anatofuz
parents: 59
diff changeset
5 add_subdirectory(usr)
66
101b229f182d build initcode
anatofuz
parents: 64
diff changeset
6 enable_language(C ASM)
42
997c54d8912c fix include dir
kono
parents:
diff changeset
7
55
4f5d1aa8b594 fix use linker
anatofuz
parents: 54
diff changeset
8
42
997c54d8912c fix include dir
kono
parents:
diff changeset
9 set(USE_CUDA,0)
997c54d8912c fix include dir
kono
parents:
diff changeset
10 # -DUSE_CUDA
997c54d8912c fix include dir
kono
parents:
diff changeset
11 # add_definitions("-Wall -g -O")
997c54d8912c fix include dir
kono
parents:
diff changeset
12
997c54d8912c fix include dir
kono
parents:
diff changeset
13 # -DCMAKE_BUILD_TYPE=Debug
997c54d8912c fix include dir
kono
parents:
diff changeset
14 set(CMAKE_C_FLAGS_DEBUG "-O0")
58
f1b965f53d3b add tools userlists
tobaru
parents: 56
diff changeset
15 add_definitions(${PMAKE_ARGS})
f1b965f53d3b add tools userlists
tobaru
parents: 56
diff changeset
16
f1b965f53d3b add tools userlists
tobaru
parents: 56
diff changeset
17 #add_custom_command(OUTPUT tools
f1b965f53d3b add tools userlists
tobaru
parents: 56
diff changeset
18 # COMMAND "cd ${CMAKE_CURRENT_SOURCE_DIR}/tools && make run"
f1b965f53d3b add tools userlists
tobaru
parents: 56
diff changeset
19 #)
f1b965f53d3b add tools userlists
tobaru
parents: 56
diff changeset
20 # #WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tools
f1b965f53d3b add tools userlists
tobaru
parents: 56
diff changeset
21
42
997c54d8912c fix include dir
kono
parents:
diff changeset
22
997c54d8912c fix include dir
kono
parents:
diff changeset
23 if (${USE_CUDA})
997c54d8912c fix include dir
kono
parents:
diff changeset
24 include_directories("/usr/local/cuda/include")
69
f236eba62a76 off-the-shelf cmakefile
anatofuz
parents: 66
diff changeset
25 include_directories(${CMAKE_SOURCE_DIR})
42
997c54d8912c fix include dir
kono
parents:
diff changeset
26 set(NVCCFLAG "-std=c++11" "-g" "-O0" )
997c54d8912c fix include dir
kono
parents:
diff changeset
27 if (UNIX AND NOT APPLE) # LINUX
997c54d8912c fix include dir
kono
parents:
diff changeset
28 set(CUDA_LINK_FLAGS "-L/usr/local/cuda/lib64 -lcuda -lcudart")
997c54d8912c fix include dir
kono
parents:
diff changeset
29 elseif (APPLE)
997c54d8912c fix include dir
kono
parents:
diff changeset
30 set(CUDA_LINK_FLAGS "-framework CUDA -lc++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names /usr/local/cuda/lib/libcudart_static.a -Wl,-rpath,/usr/local/cuda/lib")
997c54d8912c fix include dir
kono
parents:
diff changeset
31 endif()
997c54d8912c fix include dir
kono
parents:
diff changeset
32 find_package(CUDA REQUIRED)
997c54d8912c fix include dir
kono
parents:
diff changeset
33 SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CUDA_LINK_FLAGS}" )
997c54d8912c fix include dir
kono
parents:
diff changeset
34 endif()
997c54d8912c fix include dir
kono
parents:
diff changeset
35
70
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
36 set(CMAKE_BEFORE_PROJECT_PATH "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}")
42
997c54d8912c fix include dir
kono
parents:
diff changeset
37 include_directories(".")
61
b3a3224e1823 fix link arguments...
anatofuz
parents: 59
diff changeset
38 configure_file("${CMAKE_SOURCE_DIR}/kernel-cmake.ld" "${CMAKE_CURRENT_BINARY_DIR}/kernel-cmake.ld" COPYONLY)
42
997c54d8912c fix include dir
kono
parents:
diff changeset
39
997c54d8912c fix include dir
kono
parents:
diff changeset
40 macro( GearsCommand )
66
101b229f182d build initcode
anatofuz
parents: 64
diff changeset
41 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXV6KERNEL")
61
b3a3224e1823 fix link arguments...
anatofuz
parents: 59
diff changeset
42 set(CMAKE_C_COMPILER "${CBC_COM}")
b3a3224e1823 fix link arguments...
anatofuz
parents: 59
diff changeset
43 set(CMAKE_LINKER "${X_CMAKE_LINKER}")
b3a3224e1823 fix link arguments...
anatofuz
parents: 59
diff changeset
44 set(CMAKE_C_LINK_EXECUTABLE "${X_CMAKE_C_LINK_EXECUTABLE}")
42
997c54d8912c fix include dir
kono
parents:
diff changeset
45 set( _OPTIONS_ARGS )
997c54d8912c fix include dir
kono
parents:
diff changeset
46 set( _ONE_VALUE_ARGS TARGET )
997c54d8912c fix include dir
kono
parents:
diff changeset
47 set( _MULTI_VALUE_ARGS SOURCES )
997c54d8912c fix include dir
kono
parents:
diff changeset
48 cmake_parse_arguments( _Gears "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
69
f236eba62a76 off-the-shelf cmakefile
anatofuz
parents: 66
diff changeset
49 set(CMAKE_KERNEL_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_Gears_TARGET}.dir")
42
997c54d8912c fix include dir
kono
parents:
diff changeset
50
43
b94d72292dfa fix build arm asm file
anatofuz
parents: 42
diff changeset
51 set (_Gears_CBC_SOURCES)
42
997c54d8912c fix include dir
kono
parents:
diff changeset
52 set (_Gears_CSOURCES)
997c54d8912c fix include dir
kono
parents:
diff changeset
53 foreach(i ${_Gears_SOURCES})
997c54d8912c fix include dir
kono
parents:
diff changeset
54 if (${i} MATCHES "\\.cbc")
997c54d8912c fix include dir
kono
parents:
diff changeset
55 string(REGEX REPLACE "(.*).cbc" "c/\\1.c" j ${i})
997c54d8912c fix include dir
kono
parents:
diff changeset
56 add_custom_command (
69
f236eba62a76 off-the-shelf cmakefile
anatofuz
parents: 66
diff changeset
57 OUTPUT ${CMAKE_KERNEL_OUTPUT_DIR}/${j}
42
997c54d8912c fix include dir
kono
parents:
diff changeset
58 DEPENDS ${i}
69
f236eba62a76 off-the-shelf cmakefile
anatofuz
parents: 66
diff changeset
59 COMMAND "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_stub.pl" "-o" ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_Gears_TARGET}.dir/${j} ${CMAKE_SOURCE_DIR}/${i}
42
997c54d8912c fix include dir
kono
parents:
diff changeset
60 )
70
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
61 list(APPEND _Gears_CBC_SOURCES "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_Gears_TARGET}.dir/${j}")
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
62 #list(APPEND _Gears_CBC_SOURCES ${j})
42
997c54d8912c fix include dir
kono
parents:
diff changeset
63 elseif (${i} MATCHES "\\.cu")
997c54d8912c fix include dir
kono
parents:
diff changeset
64 string(REGEX REPLACE "(.*).cu" "c/\\1.ptx" j ${i})
997c54d8912c fix include dir
kono
parents:
diff changeset
65 add_custom_command (
69
f236eba62a76 off-the-shelf cmakefile
anatofuz
parents: 66
diff changeset
66 OUTPUT ${CMAKE_KERNEL_OUTPUT_DIR}/${j}
42
997c54d8912c fix include dir
kono
parents:
diff changeset
67 DEPENDS ${i}
997c54d8912c fix include dir
kono
parents:
diff changeset
68 COMMAND nvcc ${NVCCFLAG} -c -ptx -o ${j} ${i}
997c54d8912c fix include dir
kono
parents:
diff changeset
69 )
43
b94d72292dfa fix build arm asm file
anatofuz
parents: 42
diff changeset
70 list(APPEND _Gears_CBC_SOURCES ${j})
42
997c54d8912c fix include dir
kono
parents:
diff changeset
71 else()
997c54d8912c fix include dir
kono
parents:
diff changeset
72 set(j ${i})
70
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
73 #list(APPEND _Gears_CSOURCES "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_Gears_TARGET}.dir/${j}")
43
b94d72292dfa fix build arm asm file
anatofuz
parents: 42
diff changeset
74 list(APPEND _Gears_CSOURCES ${j})
42
997c54d8912c fix include dir
kono
parents:
diff changeset
75 endif()
997c54d8912c fix include dir
kono
parents:
diff changeset
76 endforeach(i)
997c54d8912c fix include dir
kono
parents:
diff changeset
77
61
b3a3224e1823 fix link arguments...
anatofuz
parents: 59
diff changeset
78 #target_link_libraries(syslib)
70
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
79 file(COPY "${CMAKE_SOURCE_DIR}/context.h" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
42
997c54d8912c fix include dir
kono
parents:
diff changeset
80 add_custom_command (
69
f236eba62a76 off-the-shelf cmakefile
anatofuz
parents: 66
diff changeset
81 OUTPUT ${CMAKE_KERNEL_OUTPUT_DIR}/c/${_Gears_TARGET}-context.c
66
101b229f182d build initcode
anatofuz
parents: 64
diff changeset
82 DEPENDS ${_Gears_CBC_SOURCES} fs.img initcode
69
f236eba62a76 off-the-shelf cmakefile
anatofuz
parents: 66
diff changeset
83 COMMAND "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_context.pl" "-o" ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_Gears_TARGET} ${_Gears_CBC_SOURCES}
42
997c54d8912c fix include dir
kono
parents:
diff changeset
84 )
70
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
85 add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${CMAKE_KERNEL_OUTPUT_DIR}/c/${_Gears_TARGET}-context.c )
53
435bfab09924 fix cmakefiles
kono
parents: 52
diff changeset
86 # target_link_libraries(${_Gears_TARGET} m pthread)
42
997c54d8912c fix include dir
kono
parents:
diff changeset
87 endmacro()
997c54d8912c fix include dir
kono
parents:
diff changeset
88
66
101b229f182d build initcode
anatofuz
parents: 64
diff changeset
89
101b229f182d build initcode
anatofuz
parents: 64
diff changeset
90 set(CMAKE_C_FLAGS "${INITOCDE_CFLAGS}")
101b229f182d build initcode
anatofuz
parents: 64
diff changeset
91 set(CMAKE_ASM_LINK_EXECUTABLE "${INITOCDE_LINK_EXECUTABLE}")
70
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
92 add_executable(initcode.o ${CMAKE_SOURCE_DIR}/initcode.S)
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
93 set_target_properties(initcode.o PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BEFORE_PROJECT_PATH}/kernel.dir")
66
101b229f182d build initcode
anatofuz
parents: 64
diff changeset
94 add_custom_command(
70
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
95 OUTPUT "initcode"
66
101b229f182d build initcode
anatofuz
parents: 64
diff changeset
96 DEPENDS initcode.o
70
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
97 COMMAND "arm-none-eabi-objcopy" "-S" "-O" "binary" "--prefix-symbols=\"_binary_build/initcode\"" "${CMAKE_BEFORE_PROJECT_PATH}/kernel.dir/initcode.o" "initcode"
66
101b229f182d build initcode
anatofuz
parents: 64
diff changeset
98 )
70
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
99 #file(COPY "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/initcode.o.dir/initcode" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
1e1c6feb7d83 fix build initcode
anatofuz
parents: 69
diff changeset
100
42
997c54d8912c fix include dir
kono
parents:
diff changeset
101
53
435bfab09924 fix cmakefiles
kono
parents: 52
diff changeset
102 GearsCommand (
42
997c54d8912c fix include dir
kono
parents:
diff changeset
103 TARGET
997c54d8912c fix include dir
kono
parents:
diff changeset
104 kernel
997c54d8912c fix include dir
kono
parents:
diff changeset
105 SOURCES
61
b3a3224e1823 fix link arguments...
anatofuz
parents: 59
diff changeset
106 string.c arm.c asm.S bio.c buddy.c console.cbc exec.c file.cbc fs.c log.c main.c memide.c pipe.cbc proc.cbc spinlock.cbc
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
107 start.c swtch.S syscall.cbc sysfile.cbc sysproc.c trap_asm.S trap.c vm.c device/picirq.c device/timer.c device/uart.c
61
b3a3224e1823 fix link arguments...
anatofuz
parents: 59
diff changeset
108 entry.S
42
997c54d8912c fix include dir
kono
parents:
diff changeset
109 )