42
|
1 cmake_minimum_required(VERSION 3.8)
|
43
|
2 project(xv6cbc C ASM)
|
42
|
3
|
54
|
4 # https://github.com/llvm-mirror/libcxx/blob/master/cmake/Modules/HandleCompilerRT.cmake
|
|
5 function(find_compiler_rt_library dest)
|
|
6 set(dest "" PARENT_SCOPE)
|
|
7 set(CLANG_COMMAND ${CMAKE_C_COMPILER}
|
|
8 "--print-libgcc-file-name")
|
|
9 if (CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET)
|
|
10 list(APPEND CLANG_COMMAND "--target=${CMAKE_C_COMPILER_TARGET}")
|
|
11 endif()
|
|
12 string(REPLACE " " ";" LIBC_C_FLAGS "${LIBC_C_FLAGS}")
|
|
13 list(APPEND CLANG_COMMAND ${LIBC_C_FLAGS})
|
|
14 execute_process(
|
|
15 COMMAND ${CLANG_COMMAND}
|
|
16 RESULT_VARIABLE HAD_ERROR
|
|
17 OUTPUT_VARIABLE LIBRARY_FILE
|
|
18 )
|
|
19 string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
|
|
20 set(${dest} "${LIBRARY_FILE}" PARENT_SCOPE)
|
|
21 endfunction()
|
|
22
|
55
|
23
|
|
24
|
42
|
25 set(USE_CUDA,0)
|
|
26 # -DUSE_CUDA
|
|
27 # add_definitions("-Wall -g -O")
|
|
28
|
47
|
29 if (APPLE)
|
|
30 set(CMAKE_C_COMPILER $ENV{CBC_LANG_COMPILER})
|
|
31 add_definitions("-Wall -g -arch arm -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -I. -g -O0
|
|
32 -Wno-macro-redefined -Wno-gnu-designator -Wno-sometimes-uninitialized -Wno-tautological-compare
|
|
33 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include
|
|
34 -Wno-nullability-completeness -Wno-expansion-to-defined")
|
54
|
35 set(CMAKE_EXE_LINKER_FLAGS "-L. -arch armv7 -T kernel-cmake.ld -o kernel.elf ")
|
47
|
36 else (APPLE)
|
|
37 set(CMAKE_C_COMPILER /mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc)
|
53
|
38 set(CMAKE_ASM_COMPILER /mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc)
|
|
39 add_definitions("-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-
|
47
|
40 -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -I. -g -O0")
|
54
|
41 find_compiler_rt_library("LIBRARY_FILE")
|
55
|
42 set(CMAKE_C_LINK_EXECUTABLE "/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-ld -L. -T kernel-cmake.ld ${LIBRARY_FILE} -o kernel.elf -b binary -nostdlib ")
|
54
|
43
|
47
|
44 endif (APPLE)
|
42
|
45
|
|
46 # -DCMAKE_BUILD_TYPE=Debug
|
|
47 set(CMAKE_C_FLAGS_DEBUG "-O0")
|
|
48
|
|
49 if (${USE_CUDA})
|
|
50 include_directories("/usr/local/cuda/include")
|
|
51 set(NVCCFLAG "-std=c++11" "-g" "-O0" )
|
|
52 if (UNIX AND NOT APPLE) # LINUX
|
|
53 set(CUDA_LINK_FLAGS "-L/usr/local/cuda/lib64 -lcuda -lcudart")
|
|
54 elseif (APPLE)
|
|
55 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")
|
|
56 endif()
|
|
57 find_package(CUDA REQUIRED)
|
|
58 SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CUDA_LINK_FLAGS}" )
|
|
59 endif()
|
|
60
|
|
61 include_directories(".")
|
|
62
|
|
63 macro( GearsCommand )
|
|
64 set( _OPTIONS_ARGS )
|
|
65 set( _ONE_VALUE_ARGS TARGET )
|
|
66 set( _MULTI_VALUE_ARGS SOURCES )
|
|
67 cmake_parse_arguments( _Gears "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
|
|
68
|
43
|
69 set (_Gears_CBC_SOURCES)
|
42
|
70 set (_Gears_CSOURCES)
|
|
71 foreach(i ${_Gears_SOURCES})
|
|
72 if (${i} MATCHES "\\.cbc")
|
|
73 string(REGEX REPLACE "(.*).cbc" "c/\\1.c" j ${i})
|
|
74 add_custom_command (
|
|
75 OUTPUT ${j}
|
|
76 DEPENDS ${i}
|
|
77 COMMAND "perl" "gearsTools/generate_stub.pl" "-o" ${j} ${i}
|
|
78 )
|
43
|
79 list(APPEND _Gears_CBC_SOURCES ${j})
|
42
|
80 elseif (${i} MATCHES "\\.cu")
|
|
81 string(REGEX REPLACE "(.*).cu" "c/\\1.ptx" j ${i})
|
|
82 add_custom_command (
|
|
83 OUTPUT ${j}
|
|
84 DEPENDS ${i}
|
|
85 COMMAND nvcc ${NVCCFLAG} -c -ptx -o ${j} ${i}
|
|
86 )
|
43
|
87 list(APPEND _Gears_CBC_SOURCES ${j})
|
42
|
88 else()
|
|
89 set(j ${i})
|
43
|
90 list(APPEND _Gears_CSOURCES ${j})
|
42
|
91 endif()
|
|
92 endforeach(i)
|
|
93
|
|
94 add_custom_command (
|
|
95 OUTPUT c/${_Gears_TARGET}-context.c
|
43
|
96 DEPENDS ${_Gears_CBC_SOURCES}
|
|
97 COMMAND "perl" "gearsTools/generate_context.pl" "-o" ${_Gears_TARGET} ${_Gears_CBC_SOURCES}
|
42
|
98 )
|
53
|
99 add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} c/${_Gears_TARGET}-context.c )
|
|
100 # target_link_libraries(${_Gears_TARGET} m pthread)
|
42
|
101 endmacro()
|
|
102
|
|
103
|
53
|
104 GearsCommand (
|
42
|
105 TARGET
|
|
106 kernel
|
|
107 SOURCES
|
52
|
108 lib/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
|
|
109 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
|
54
|
110 lib/string.c entry.S
|
42
|
111 )
|
|
112
|
|
113
|