42
|
1 cmake_minimum_required(VERSION 3.8)
|
43
|
2 project(xv6cbc C ASM)
|
62
|
3 set(BUILD_DIR ${PROJECT_BINARY_DIR})
|
59
|
4 add_subdirectory(tools)
|
61
|
5 add_subdirectory(usr)
|
66
|
6 enable_language(C ASM)
|
42
|
7
|
55
|
8
|
42
|
9 set(USE_CUDA,0)
|
|
10 # -DUSE_CUDA
|
|
11 # add_definitions("-Wall -g -O")
|
|
12
|
|
13 # -DCMAKE_BUILD_TYPE=Debug
|
|
14 set(CMAKE_C_FLAGS_DEBUG "-O0")
|
58
|
15 add_definitions(${PMAKE_ARGS})
|
|
16
|
|
17 #add_custom_command(OUTPUT tools
|
|
18 # COMMAND "cd ${CMAKE_CURRENT_SOURCE_DIR}/tools && make run"
|
|
19 #)
|
|
20 # #WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tools
|
|
21
|
42
|
22
|
|
23 if (${USE_CUDA})
|
|
24 include_directories("/usr/local/cuda/include")
|
69
|
25 include_directories(${CMAKE_SOURCE_DIR})
|
42
|
26 set(NVCCFLAG "-std=c++11" "-g" "-O0" )
|
|
27 if (UNIX AND NOT APPLE) # LINUX
|
|
28 set(CUDA_LINK_FLAGS "-L/usr/local/cuda/lib64 -lcuda -lcudart")
|
|
29 elseif (APPLE)
|
|
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")
|
|
31 endif()
|
|
32 find_package(CUDA REQUIRED)
|
|
33 SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CUDA_LINK_FLAGS}" )
|
|
34 endif()
|
|
35
|
70
|
36 set(CMAKE_BEFORE_PROJECT_PATH "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}")
|
42
|
37 include_directories(".")
|
61
|
38 configure_file("${CMAKE_SOURCE_DIR}/kernel-cmake.ld" "${CMAKE_CURRENT_BINARY_DIR}/kernel-cmake.ld" COPYONLY)
|
42
|
39
|
|
40 macro( GearsCommand )
|
66
|
41 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXV6KERNEL")
|
61
|
42 set(CMAKE_C_COMPILER "${CBC_COM}")
|
|
43 set(CMAKE_LINKER "${X_CMAKE_LINKER}")
|
|
44 set(CMAKE_C_LINK_EXECUTABLE "${X_CMAKE_C_LINK_EXECUTABLE}")
|
42
|
45 set( _OPTIONS_ARGS )
|
|
46 set( _ONE_VALUE_ARGS TARGET )
|
|
47 set( _MULTI_VALUE_ARGS SOURCES )
|
|
48 cmake_parse_arguments( _Gears "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
|
69
|
49 set(CMAKE_KERNEL_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_Gears_TARGET}.dir")
|
42
|
50
|
43
|
51 set (_Gears_CBC_SOURCES)
|
42
|
52 set (_Gears_CSOURCES)
|
|
53 foreach(i ${_Gears_SOURCES})
|
|
54 if (${i} MATCHES "\\.cbc")
|
|
55 string(REGEX REPLACE "(.*).cbc" "c/\\1.c" j ${i})
|
|
56 add_custom_command (
|
69
|
57 OUTPUT ${CMAKE_KERNEL_OUTPUT_DIR}/${j}
|
42
|
58 DEPENDS ${i}
|
69
|
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
|
60 )
|
70
|
61 list(APPEND _Gears_CBC_SOURCES "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_Gears_TARGET}.dir/${j}")
|
|
62 #list(APPEND _Gears_CBC_SOURCES ${j})
|
42
|
63 elseif (${i} MATCHES "\\.cu")
|
|
64 string(REGEX REPLACE "(.*).cu" "c/\\1.ptx" j ${i})
|
|
65 add_custom_command (
|
69
|
66 OUTPUT ${CMAKE_KERNEL_OUTPUT_DIR}/${j}
|
42
|
67 DEPENDS ${i}
|
|
68 COMMAND nvcc ${NVCCFLAG} -c -ptx -o ${j} ${i}
|
|
69 )
|
43
|
70 list(APPEND _Gears_CBC_SOURCES ${j})
|
42
|
71 else()
|
|
72 set(j ${i})
|
70
|
73 #list(APPEND _Gears_CSOURCES "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_Gears_TARGET}.dir/${j}")
|
43
|
74 list(APPEND _Gears_CSOURCES ${j})
|
42
|
75 endif()
|
|
76 endforeach(i)
|
|
77
|
61
|
78 #target_link_libraries(syslib)
|
70
|
79 file(COPY "${CMAKE_SOURCE_DIR}/context.h" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
42
|
80 add_custom_command (
|
69
|
81 OUTPUT ${CMAKE_KERNEL_OUTPUT_DIR}/c/${_Gears_TARGET}-context.c
|
66
|
82 DEPENDS ${_Gears_CBC_SOURCES} fs.img initcode
|
69
|
83 COMMAND "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_context.pl" "-o" ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_Gears_TARGET} ${_Gears_CBC_SOURCES}
|
42
|
84 )
|
70
|
85 add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${CMAKE_KERNEL_OUTPUT_DIR}/c/${_Gears_TARGET}-context.c )
|
53
|
86 # target_link_libraries(${_Gears_TARGET} m pthread)
|
42
|
87 endmacro()
|
|
88
|
66
|
89
|
|
90 set(CMAKE_C_FLAGS "${INITOCDE_CFLAGS}")
|
|
91 set(CMAKE_ASM_LINK_EXECUTABLE "${INITOCDE_LINK_EXECUTABLE}")
|
70
|
92 add_executable(initcode.o ${CMAKE_SOURCE_DIR}/initcode.S)
|
|
93 set_target_properties(initcode.o PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BEFORE_PROJECT_PATH}/kernel.dir")
|
66
|
94 add_custom_command(
|
70
|
95 OUTPUT "initcode"
|
66
|
96 DEPENDS initcode.o
|
70
|
97 COMMAND "arm-none-eabi-objcopy" "-S" "-O" "binary" "--prefix-symbols=\"_binary_build/initcode\"" "${CMAKE_BEFORE_PROJECT_PATH}/kernel.dir/initcode.o" "initcode"
|
66
|
98 )
|
70
|
99 #file(COPY "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/initcode.o.dir/initcode" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
|
100
|
42
|
101
|
53
|
102 GearsCommand (
|
42
|
103 TARGET
|
|
104 kernel
|
|
105 SOURCES
|
61
|
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
|
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
|
108 entry.S
|
42
|
109 )
|