annotate src/CMakeLists.txt @ 54:aa0095c4c2b0

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