|
1 | | -# Append current directory to CMAKE_MODULE_PATH for making device specific cmake modules visible |
2 | | -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) |
3 | | - |
4 | | -# Target definition |
5 | | -set(CMAKE_SYSTEM_NAME Generic) |
6 | | -set(CMAKE_SYSTEM_PROCESSOR arm) |
7 | | - |
8 | | -#--------------------------------------------------------------------------------------- |
9 | | -# Set toolchain paths |
10 | | -#--------------------------------------------------------------------------------------- |
11 | | -set(TOOLCHAIN arm) |
12 | | - |
13 | | -if(NOT DEFINED TOOLCHAIN_PREFIX) |
14 | | - if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) |
15 | | - set(TOOLCHAIN_PREFIX "/usr") |
16 | | - elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) |
17 | | - set(TOOLCHAIN_PREFIX "/usr/local") |
18 | | - elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) |
19 | | - if($ENV{MINGW_PREFIX} MATCHES "^.*/(mingw|clang)64$") |
20 | | - set(TOOLCHAIN_PREFIX $ENV{MINGW_PREFIX}) |
21 | | - # STRING(REGEX REPLACE "^.*/(mingw|clang)64$" "/\\164" TOOLCHAIN_PREFIX $ENV{MINGW_PREFIX}) |
22 | | - elseif(EXISTS "C:/Keil") |
23 | | - set(TOOLCHAIN_PREFIX "C:/Keil") |
24 | | - else() |
25 | | - message(STATUS "Please specify the TOOLCHAIN_PREFIX !\n For example: -DTOOLCHAIN_PREFIX=\"C:/Program Files/GNU Tools ARM Embedded\" ") |
26 | | - endif() |
27 | | - else() |
28 | | - set(TOOLCHAIN_PREFIX "/usr") |
29 | | - message(STATUS "No TOOLCHAIN_PREFIX specified, using default: " ${TOOLCHAIN_PREFIX}) |
30 | | - endif() |
31 | | -endif() |
32 | | -set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) |
33 | | -set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include) |
34 | | -set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib) |
35 | | - |
36 | | -# Set system depended extensions |
37 | | -if(WIN32) |
38 | | - set(TOOLCHAIN_EXT ".exe" ) |
39 | | -else() |
40 | | - set(TOOLCHAIN_EXT "" ) |
41 | | -endif() |
42 | | - |
43 | | -# Perform compiler test with static library |
44 | | -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
45 | | - |
46 | | -#--------------------------------------------------------------------------------------- |
47 | | -# Set compiler/linker flags |
48 | | -#--------------------------------------------------------------------------------------- |
49 | | - |
50 | | -# Object build options |
51 | | -# -O0 No optimizations, reduce compilation time and make debugging produce the expected results. |
52 | | -# -mthumb Generat thumb instructions. |
53 | | -# -fno-builtin Do not use built-in functions provided by GCC. |
54 | | -# -Wall Print only standard warnings, for all use Wextra |
55 | | -# -ffunction-sections Place each function item into its own section in the output file. |
56 | | -# -fdata-sections Place each data item into its own section in the output file. |
57 | | -# -fomit-frame-pointer Omit the frame pointer in functions that don’t need one. |
58 | | -# -mabi=aapcs Defines enums to be a variable sized type. |
59 | | -set(OBJECT_GEN_FLAGS "--thumb --gnu --split_sections") |
60 | | - |
61 | | -set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} --c99 " CACHE INTERNAL "C Compiler options") |
62 | | -set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} --cpp11 " CACHE INTERNAL "C++ Compiler options") |
63 | | -set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} " CACHE INTERNAL "ASM Compiler options") |
64 | | - |
65 | | - |
66 | | -# -Wl,--gc-sections Perform the dead code elimination. |
67 | | -# --specs=nano.specs Link with newlib-nano. |
68 | | -# --specs=nosys.specs No syscalls, provide empty implementations for the POSIX system calls. |
69 | | -set(MAPFILE "${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker Map File") |
70 | | -set(CMAKE_EXE_LINKER_FLAGS "" CACHE INTERNAL "Linker options") |
71 | | - |
72 | | -#--------------------------------------------------------------------------------------- |
73 | | -# Set debug/release build configuration Options |
74 | | -#--------------------------------------------------------------------------------------- |
75 | | - |
76 | | -# Options for DEBUG build |
77 | | -# -Og Enables optimizations that do not interfere with debugging. |
78 | | -# -g Produce debugging information in the operating system’s native format. |
79 | | -set(CMAKE_C_FLAGS_DEBUG "-O0 --debug" CACHE INTERNAL "C Compiler options for debug build type") |
80 | | -set(CMAKE_CXX_FLAGS_DEBUG "-O0 --debug" CACHE INTERNAL "C++ Compiler options for debug build type") |
81 | | -set(CMAKE_ASM_FLAGS_DEBUG "--debug" CACHE INTERNAL "ASM Compiler options for debug build type") |
82 | | -set(CMAKE_EXE_LINKER_FLAGS_DEBUG "--debug" CACHE INTERNAL "Linker options for debug build type") |
83 | | - |
84 | | -# Options for RELEASE build |
85 | | -# -Os Optimize for size. -Os enables all -O2 optimizations. |
86 | | -# -flto Runs the standard link-time optimizer. |
87 | | -set(CMAKE_C_FLAGS_RELEASE "-Ospace --no_debug" CACHE INTERNAL "C Compiler options for release build type") |
88 | | -set(CMAKE_CXX_FLAGS_RELEASE "-Ospace --no_debug" CACHE INTERNAL "C++ Compiler options for release build type") |
89 | | -set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") |
90 | | -set(CMAKE_EXE_LINKER_FLAGS_RELEASE "--no_debug" CACHE INTERNAL "Linker options for release build type") |
91 | | -# set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-g3 -flto" CACHE INTERNAL "Linker options for release build type") |
92 | | - |
93 | | - |
94 | | -#--------------------------------------------------------------------------------------- |
95 | | -# Set compilers |
96 | | -#--------------------------------------------------------------------------------------- |
97 | | -set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}cc${TOOLCHAIN_EXT} CACHE INTERNAL "C Compiler") |
98 | | -set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}c++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler") |
99 | | -set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}cc${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler") |
100 | | - |
101 | | -set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${${TOOLCHAIN}} ${CMAKE_PREFIX_PATH}) |
102 | | -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
103 | | -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) |
104 | | -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) |
105 | | -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
106 | | - |
| 1 | +# Append current directory to CMAKE_MODULE_PATH for making device specific cmake modules visible |
| 2 | +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) |
| 3 | + |
| 4 | +# Target definition |
| 5 | +set(CMAKE_SYSTEM_NAME Generic) |
| 6 | +set(CMAKE_SYSTEM_PROCESSOR arm) |
| 7 | + |
| 8 | +#--------------------------------------------------------------------------------------- |
| 9 | +# Set toolchain paths |
| 10 | +#--------------------------------------------------------------------------------------- |
| 11 | +set(TOOLCHAIN arm) |
| 12 | + |
| 13 | +if(NOT DEFINED TOOLCHAIN_PREFIX) |
| 14 | + if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) |
| 15 | + set(TOOLCHAIN_PREFIX "/usr") |
| 16 | + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) |
| 17 | + set(TOOLCHAIN_PREFIX "/usr/local") |
| 18 | + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) |
| 19 | + if($ENV{MINGW_PREFIX} MATCHES "^.*/(mingw|clang)64$") |
| 20 | + set(TOOLCHAIN_PREFIX $ENV{MINGW_PREFIX}) |
| 21 | + # STRING(REGEX REPLACE "^.*/(mingw|clang)64$" "/\\164" TOOLCHAIN_PREFIX $ENV{MINGW_PREFIX}) |
| 22 | + elseif(EXISTS "C:/Keil") |
| 23 | + set(TOOLCHAIN_PREFIX "C:/Keil") |
| 24 | + else() |
| 25 | + message(STATUS "Please specify the TOOLCHAIN_PREFIX !\n For example: -DTOOLCHAIN_PREFIX=\"C:/Program Files/GNU Tools ARM Embedded\" ") |
| 26 | + endif() |
| 27 | + else() |
| 28 | + set(TOOLCHAIN_PREFIX "/usr") |
| 29 | + message(STATUS "No TOOLCHAIN_PREFIX specified, using default: " ${TOOLCHAIN_PREFIX}) |
| 30 | + endif() |
| 31 | +endif() |
| 32 | +set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) |
| 33 | +set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include) |
| 34 | +set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib) |
| 35 | + |
| 36 | +# Set system depended extensions |
| 37 | +if(WIN32) |
| 38 | + set(TOOLCHAIN_EXT ".exe" ) |
| 39 | +else() |
| 40 | + set(TOOLCHAIN_EXT "" ) |
| 41 | +endif() |
| 42 | + |
| 43 | +# Perform compiler test with static library |
| 44 | +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
| 45 | + |
| 46 | +#--------------------------------------------------------------------------------------- |
| 47 | +# Set compiler/linker flags |
| 48 | +#--------------------------------------------------------------------------------------- |
| 49 | + |
| 50 | +# Object build options |
| 51 | +# -O0 No optimizations, reduce compilation time and make debugging produce the expected results. |
| 52 | +# -mthumb Generat thumb instructions. |
| 53 | +# -fno-builtin Do not use built-in functions provided by GCC. |
| 54 | +# -Wall Print only standard warnings, for all use Wextra |
| 55 | +# -ffunction-sections Place each function item into its own section in the output file. |
| 56 | +# -fdata-sections Place each data item into its own section in the output file. |
| 57 | +# -fomit-frame-pointer Omit the frame pointer in functions that don’t need one. |
| 58 | +# -mabi=aapcs Defines enums to be a variable sized type. |
| 59 | +set(OBJECT_GEN_FLAGS "--thumb --gnu --split_sections") |
| 60 | + |
| 61 | +set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} --c99 " CACHE INTERNAL "C Compiler options") |
| 62 | +set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} --cpp11 " CACHE INTERNAL "C++ Compiler options") |
| 63 | +set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} " CACHE INTERNAL "ASM Compiler options") |
| 64 | + |
| 65 | + |
| 66 | +# -Wl,--gc-sections Perform the dead code elimination. |
| 67 | +# --specs=nano.specs Link with newlib-nano. |
| 68 | +# --specs=nosys.specs No syscalls, provide empty implementations for the POSIX system calls. |
| 69 | +set(MAPFILE "${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker Map File") |
| 70 | +set(CMAKE_EXE_LINKER_FLAGS "" CACHE INTERNAL "Linker options") |
| 71 | + |
| 72 | +#--------------------------------------------------------------------------------------- |
| 73 | +# Set debug/release build configuration Options |
| 74 | +#--------------------------------------------------------------------------------------- |
| 75 | + |
| 76 | +# Options for DEBUG build |
| 77 | +# -Og Enables optimizations that do not interfere with debugging. |
| 78 | +# -g Produce debugging information in the operating system’s native format. |
| 79 | +set(CMAKE_C_FLAGS_DEBUG "-O0 --debug" CACHE INTERNAL "C Compiler options for debug build type") |
| 80 | +set(CMAKE_CXX_FLAGS_DEBUG "-O0 --debug" CACHE INTERNAL "C++ Compiler options for debug build type") |
| 81 | +set(CMAKE_ASM_FLAGS_DEBUG "--debug" CACHE INTERNAL "ASM Compiler options for debug build type") |
| 82 | +set(CMAKE_EXE_LINKER_FLAGS_DEBUG "--debug" CACHE INTERNAL "Linker options for debug build type") |
| 83 | + |
| 84 | +# Options for SPY build are same as DEBUG options |
| 85 | +set(CMAKE_C_FLAGS_SPY "${CMAKE_C_FLAGS_DEBUG} -DQ_SPY" CACHE INTERNAL "C Compiler options for spy build type") |
| 86 | +set(CMAKE_CXX_FLAGS_SPY "${CMAKE_CXX_FLAGS_DEBUG} -DQ_SPY" CACHE INTERNAL "C++ Compiler options for spy build type") |
| 87 | +set(CMAKE_ASM_FLAGS_SPY "${CMAKE_ASM_FLAGS_DEBUG} -DQ_SPY" CACHE INTERNAL "ASM Compiler options for spy build type") |
| 88 | +set(CMAKE_EXE_LINKER_FLAGS_SPY "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE INTERNAL "Linker options for spy build type") |
| 89 | + |
| 90 | +# Options for RELEASE build |
| 91 | +# -Os Optimize for size. -Os enables all -O2 optimizations. |
| 92 | +# -flto Runs the standard link-time optimizer. |
| 93 | +set(CMAKE_C_FLAGS_RELEASE "-Ospace --no_debug" CACHE INTERNAL "C Compiler options for release build type") |
| 94 | +set(CMAKE_CXX_FLAGS_RELEASE "-Ospace --no_debug" CACHE INTERNAL "C++ Compiler options for release build type") |
| 95 | +set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") |
| 96 | +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "--no_debug" CACHE INTERNAL "Linker options for release build type") |
| 97 | +# set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-g3 -flto" CACHE INTERNAL "Linker options for release build type") |
| 98 | + |
| 99 | + |
| 100 | +#--------------------------------------------------------------------------------------- |
| 101 | +# Set compilers |
| 102 | +#--------------------------------------------------------------------------------------- |
| 103 | +set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}cc${TOOLCHAIN_EXT} CACHE INTERNAL "C Compiler") |
| 104 | +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}c++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler") |
| 105 | +set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}cc${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler") |
| 106 | + |
| 107 | +set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${${TOOLCHAIN}} ${CMAKE_PREFIX_PATH}) |
| 108 | +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
| 109 | +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) |
| 110 | +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) |
| 111 | +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 112 | + |
0 commit comments