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")
|
56
|
42 #cmake -DCMAKE_LINKER=/path/to/linker -DCMAKE_CXX_LINK_EXECUTABLE="<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
|
|
43 set(CMAKE_C_LINK_EXECUTABLE "/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-ld -L. -T kernel-cmake.ld -o kernel.elf -b binary -nostdlib <OBJECTS> ${LIBRARY_FILE}")
|
54
|
44
|
47
|
45 endif (APPLE)
|
42
|
46
|
|
47 # -DCMAKE_BUILD_TYPE=Debug
|
|
48 set(CMAKE_C_FLAGS_DEBUG "-O0")
|
|
49
|
|
50 if (${USE_CUDA})
|
|
51 include_directories("/usr/local/cuda/include")
|
|
52 set(NVCCFLAG "-std=c++11" "-g" "-O0" )
|
|
53 if (UNIX AND NOT APPLE) # LINUX
|
|
54 set(CUDA_LINK_FLAGS "-L/usr/local/cuda/lib64 -lcuda -lcudart")
|
|
55 elseif (APPLE)
|
|
56 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")
|
|
57 endif()
|
|
58 find_package(CUDA REQUIRED)
|
|
59 SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CUDA_LINK_FLAGS}" )
|
|
60 endif()
|
|
61
|
|
62 include_directories(".")
|
|
63
|
|
64 macro( GearsCommand )
|
|
65 set( _OPTIONS_ARGS )
|
|
66 set( _ONE_VALUE_ARGS TARGET )
|
|
67 set( _MULTI_VALUE_ARGS SOURCES )
|
|
68 cmake_parse_arguments( _Gears "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
|
|
69
|
43
|
70 set (_Gears_CBC_SOURCES)
|
42
|
71 set (_Gears_CSOURCES)
|
|
72 foreach(i ${_Gears_SOURCES})
|
|
73 if (${i} MATCHES "\\.cbc")
|
|
74 string(REGEX REPLACE "(.*).cbc" "c/\\1.c" j ${i})
|
|
75 add_custom_command (
|
|
76 OUTPUT ${j}
|
|
77 DEPENDS ${i}
|
|
78 COMMAND "perl" "gearsTools/generate_stub.pl" "-o" ${j} ${i}
|
|
79 )
|
43
|
80 list(APPEND _Gears_CBC_SOURCES ${j})
|
42
|
81 elseif (${i} MATCHES "\\.cu")
|
|
82 string(REGEX REPLACE "(.*).cu" "c/\\1.ptx" j ${i})
|
|
83 add_custom_command (
|
|
84 OUTPUT ${j}
|
|
85 DEPENDS ${i}
|
|
86 COMMAND nvcc ${NVCCFLAG} -c -ptx -o ${j} ${i}
|
|
87 )
|
43
|
88 list(APPEND _Gears_CBC_SOURCES ${j})
|
42
|
89 else()
|
|
90 set(j ${i})
|
43
|
91 list(APPEND _Gears_CSOURCES ${j})
|
42
|
92 endif()
|
|
93 endforeach(i)
|
|
94
|
|
95 add_custom_command (
|
|
96 OUTPUT c/${_Gears_TARGET}-context.c
|
43
|
97 DEPENDS ${_Gears_CBC_SOURCES}
|
|
98 COMMAND "perl" "gearsTools/generate_context.pl" "-o" ${_Gears_TARGET} ${_Gears_CBC_SOURCES}
|
42
|
99 )
|
53
|
100 add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} c/${_Gears_TARGET}-context.c )
|
|
101 # target_link_libraries(${_Gears_TARGET} m pthread)
|
42
|
102 endmacro()
|
|
103
|
|
104
|
53
|
105 GearsCommand (
|
42
|
106 TARGET
|
|
107 kernel
|
|
108 SOURCES
|
52
|
109 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
|
|
110 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
|
111 lib/string.c entry.S
|
42
|
112 )
|
|
113
|
|
114
|