Sebastian Bøe | ee9af86 | 2018-06-04 11:47:45 +0200 | [diff] [blame] | 1 | if(NOT DEFINED ZEPHYR_BINARY_DIR) |
| 2 | message(FATAL_ERROR "A user error has occured. |
| 3 | cmake was invoked with '${CMAKE_CURRENT_LIST_DIR}' specified as the source directory, |
| 4 | but it must be invoked with an application source directory, |
| 5 | such as '${CMAKE_CURRENT_LIST_DIR}/samples/hello_world'. |
| 6 | Debug variables: |
| 7 | CMAKE_CACHEFILE_DIR: ${CMAKE_CACHEFILE_DIR} |
| 8 | ") |
| 9 | endif() |
| 10 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 11 | project(Zephyr-Kernel VERSION ${PROJECT_VERSION}) |
| 12 | enable_language(C CXX ASM) |
| 13 | |
| 14 | # *DOCUMENTATION* |
| 15 | # |
| 16 | # Note that this is *NOT* the top-level CMakeLists.txt. That's in the |
| 17 | # application. See the Application Development Primer documentation |
| 18 | # for details. |
| 19 | # |
| 20 | # To see a list of typical targets execute "make usage" |
| 21 | # More info can be located in ./README.rst |
| 22 | # Comments in this file are targeted only to the developer, do not |
| 23 | # expect to learn how to build the kernel reading this file. |
| 24 | |
| 25 | # Verify that the toolchain can compile a dummy file, if it is not we |
| 26 | # won't be able to test for compatiblity with certain C flags. |
| 27 | check_c_compiler_flag("" toolchain_is_ok) |
| 28 | assert(toolchain_is_ok "The toolchain is unable to build a dummy C file. See CMakeError.log.") |
| 29 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 30 | set(CMAKE_EXECUTABLE_SUFFIX .elf) |
| 31 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 32 | if(NOT PROPERTY_LINKER_SCRIPT_DEFINES) |
| 33 | set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__GCC_LINKER_CMD__) |
| 34 | endif() |
| 35 | |
| 36 | define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT BRIEF_DOCS " " FULL_DOCS " ") |
| 37 | set_property( GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-little${ARCH}) |
| 38 | |
| 39 | # zephyr_interface is a source-less library that has all the global |
| 40 | # compiler options needed by all source files. All zephyr libraries, |
| 41 | # including the library named "zephyr" link with this library to |
| 42 | # obtain these flags. |
| 43 | add_library(zephyr_interface INTERFACE) |
| 44 | |
| 45 | # zephyr is a catchall CMake library for source files that can be |
| 46 | # built purely with the include paths, defines, and other compiler |
| 47 | # flags that come with zephyr_interface. |
| 48 | zephyr_library_named(zephyr) |
| 49 | |
| 50 | zephyr_include_directories( |
| 51 | kernel/include |
| 52 | arch/${ARCH}/include |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 53 | ${SOC_DIR}/${ARCH}/${SOC_PATH} |
| 54 | ${SOC_DIR}/${ARCH}/${SOC_PATH}/include |
| 55 | ${SOC_DIR}/${ARCH}/${SOC_FAMILY}/include |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 56 | include |
| 57 | include/drivers |
| 58 | ${PROJECT_BINARY_DIR}/include/generated |
| 59 | ${USERINCLUDE} |
| 60 | ${STDINCLUDE} |
| 61 | ) |
| 62 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 63 | zephyr_compile_definitions( |
| 64 | KERNEL |
| 65 | __ZEPHYR__=1 |
Anas Nashif | 34aebad | 2018-01-03 12:26:19 -0500 | [diff] [blame] | 66 | ) |
| 67 | |
Thomas Ebert Hansen | 15bc615 | 2018-07-12 12:01:55 +0200 | [diff] [blame] | 68 | if(NOT CONFIG_NO_OPTIMIZATIONS) |
Anas Nashif | 34aebad | 2018-01-03 12:26:19 -0500 | [diff] [blame] | 69 | zephyr_compile_definitions( |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 70 | _FORTIFY_SOURCE=2 |
| 71 | ) |
Anas Nashif | 34aebad | 2018-01-03 12:26:19 -0500 | [diff] [blame] | 72 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 73 | |
Anas Nashif | daf7716 | 2018-04-09 21:53:26 -0500 | [diff] [blame] | 74 | if(BUILD_VERSION) |
| 75 | zephyr_compile_definitions( |
| 76 | BUILD_VERSION=${BUILD_VERSION} |
| 77 | ) |
| 78 | endif() |
| 79 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 80 | # We need to set an optimization level. |
| 81 | # Default to -Os |
Alberto Escolar Piedras | f60527a | 2018-01-22 15:35:54 +0100 | [diff] [blame] | 82 | # unless CONFIG_NO_OPTIMIZATIONS is set, then it is -O0 |
| 83 | # or unless CONFIG_DEBUG is set, then it is -Og |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 84 | # |
| 85 | # also, some toolchain's break with -Os, and some toolchain's break |
| 86 | # with -Og so allow them to override what flag to use |
| 87 | # |
| 88 | # Finally, the user can use Kconfig to add compiler options that will |
| 89 | # come after these options and override them |
Alberto Escolar Piedras | f60527a | 2018-01-22 15:35:54 +0100 | [diff] [blame] | 90 | set_ifndef(OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG "-O0") |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 91 | set_ifndef(OPTIMIZE_FOR_DEBUG_FLAG "-Og") |
| 92 | set_ifndef(OPTIMIZE_FOR_SIZE_FLAG "-Os") |
Aurelien Jarno | e8413d1 | 2018-06-16 23:40:04 +0200 | [diff] [blame] | 93 | set_ifndef(OPTIMIZE_FOR_SPEED_FLAG "-O2") |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 94 | |
Alberto Escolar Piedras | f60527a | 2018-01-22 15:35:54 +0100 | [diff] [blame] | 95 | if(CONFIG_NO_OPTIMIZATIONS) |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 96 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG}) |
| 97 | elseif(CONFIG_DEBUG_OPTIMIZATIONS) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 98 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_DEBUG_FLAG}) |
Aurelien Jarno | e8413d1 | 2018-06-16 23:40:04 +0200 | [diff] [blame] | 99 | elseif(CONFIG_SPEED_OPTIMIZATIONS) |
| 100 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SPEED_FLAG}) |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 101 | elseif(CONFIG_SIZE_OPTIMIZATIONS) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 102 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SIZE_FLAG}) # Default |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 103 | else() |
| 104 | assert(0 "Unreachable code. Expected optimization level to have been chosen. See misc/Kconfig.") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 105 | endif() |
| 106 | |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 107 | # Dialects of C++, corresponding to the multiple published ISO standards. |
| 108 | # Which standard it implements can be selected using the -std= command-line option. |
| 109 | set_ifndef(DIALECT_STD_CPP98 "c++98") |
| 110 | set_ifndef(DIALECT_STD_CPP11 "c++11") |
| 111 | set_ifndef(DIALECT_STD_CPP14 "c++14") |
| 112 | set_ifndef(DIALECT_STD_CPP17 "c++17") |
| 113 | set_ifndef(DIALECT_STD_CPP2A "c++2a") |
| 114 | |
| 115 | if(CONFIG_STD_CPP98) |
| 116 | set(STD_CPP_DIALECT ${DIALECT_STD_CPP98}) |
| 117 | elseif(CONFIG_STD_CPP11) |
| 118 | set(STD_CPP_DIALECT ${DIALECT_STD_CPP11}) # Default |
| 119 | elseif(CONFIG_STD_CPP14) |
| 120 | set(STD_CPP_DIALECT ${DIALECT_STD_CPP14}) |
| 121 | elseif(CONFIG_STD_CPP17) |
| 122 | set(STD_CPP_DIALECT ${DIALECT_STD_CPP17}) |
| 123 | elseif(CONFIG_STD_CPP2A) |
| 124 | set(STD_CPP_DIALECT ${DIALECT_STD_CPP2A}) |
| 125 | else() |
| 126 | assert(0 "Unreachable code. Expected C++ standard to have been chosen. See misc/Kconfig.") |
| 127 | endif() |
| 128 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 129 | zephyr_compile_options( |
| 130 | ${OPTIMIZATION_FLAG} # Usually -Os |
| 131 | -g # TODO: build configuration enough? |
| 132 | -Wall |
| 133 | -Wformat |
| 134 | -Wformat-security |
| 135 | -Wno-format-zero-length |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 136 | -imacros ${AUTOCONF_H} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 137 | -ffreestanding |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 138 | -Wno-main |
| 139 | ${NOSTDINC_F} |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 140 | ${TOOLCHAIN_C_FLAGS} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 141 | ) |
| 142 | |
| 143 | zephyr_compile_options( |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 144 | $<$<COMPILE_LANGUAGE:CXX>:-std=${STD_CPP_DIALECT}> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 145 | $<$<COMPILE_LANGUAGE:CXX>:-fcheck-new> |
| 146 | $<$<COMPILE_LANGUAGE:CXX>:-ffunction-sections> |
| 147 | $<$<COMPILE_LANGUAGE:CXX>:-fdata-sections> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 148 | |
| 149 | $<$<COMPILE_LANGUAGE:ASM>:-xassembler-with-cpp> |
| 150 | $<$<COMPILE_LANGUAGE:ASM>:-D_ASMLANGUAGE> |
| 151 | ) |
| 152 | |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 153 | if(NOT CONFIG_RTTI) |
| 154 | zephyr_compile_options( |
| 155 | $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti> |
| 156 | ) |
| 157 | endif() |
| 158 | |
| 159 | if(NOT CONFIG_EXCEPTIONS) |
| 160 | zephyr_compile_options( |
| 161 | $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions> |
| 162 | ) |
| 163 | endif() |
| 164 | |
Aurelien Jarno | c6727d4 | 2018-11-26 13:48:34 +0100 | [diff] [blame] | 165 | zephyr_ld_options( |
| 166 | ${TOOLCHAIN_LD_FLAGS} |
| 167 | ) |
| 168 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 169 | if(NOT CONFIG_NATIVE_APPLICATION) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 170 | zephyr_ld_options( |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 171 | -nostdlib |
| 172 | -static |
| 173 | -no-pie |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 174 | ) |
| 175 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 176 | |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 177 | if(CONFIG_LIB_CPLUSPLUS) |
| 178 | zephyr_ld_options( |
| 179 | -lstdc++ |
| 180 | ) |
| 181 | endif() |
| 182 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 183 | # ========================================================================== |
| 184 | # |
| 185 | # cmake -DW=... settings |
| 186 | # |
| 187 | # W=1 - warnings that may be relevant and does not occur too often |
| 188 | # W=2 - warnings that occur quite often but may still be relevant |
| 189 | # W=3 - the more obscure warnings, can most likely be ignored |
| 190 | # ========================================================================== |
| 191 | if(W MATCHES "1") |
| 192 | zephyr_compile_options( |
| 193 | -Wextra |
| 194 | -Wunused |
| 195 | -Wno-unused-parameter |
| 196 | -Wmissing-declarations |
| 197 | -Wmissing-format-attribute |
| 198 | -Wold-style-definition |
| 199 | ) |
| 200 | zephyr_cc_option( |
| 201 | -Wmissing-prototypes |
| 202 | -Wmissing-include-dirs |
| 203 | -Wunused-but-set-variable |
| 204 | -Wno-missing-field-initializers |
| 205 | ) |
| 206 | endif() |
| 207 | |
| 208 | if(W MATCHES "2") |
| 209 | zephyr_compile_options( |
| 210 | -Waggregate-return |
| 211 | -Wcast-align |
| 212 | -Wdisabled-optimization |
| 213 | -Wnested-externs |
| 214 | -Wshadow |
| 215 | ) |
| 216 | zephyr_cc_option( |
| 217 | -Wlogical-op |
| 218 | -Wmissing-field-initializers |
| 219 | ) |
| 220 | endif() |
| 221 | |
| 222 | if(W MATCHES "3") |
| 223 | zephyr_compile_options( |
| 224 | -Wbad-function-cast |
| 225 | -Wcast-qual |
| 226 | -Wconversion |
| 227 | -Wpacked |
| 228 | -Wpadded |
| 229 | -Wpointer-arith |
| 230 | -Wredundant-decls |
| 231 | -Wswitch-default |
| 232 | ) |
| 233 | zephyr_cc_option( |
| 234 | -Wpacked-bitfield-compat |
| 235 | -Wvla |
| 236 | ) |
| 237 | endif() |
| 238 | |
| 239 | # Allow the user to inject options when calling cmake, e.g. |
| 240 | # 'cmake -DEXTRA_CFLAGS="-Werror -Wno-deprecated-declarations" ..' |
Sebastian Bøe | 9f59045 | 2017-11-10 12:22:23 +0100 | [diff] [blame] | 241 | include(cmake/extra_flags.cmake) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 242 | |
| 243 | if(CONFIG_READABLE_ASM) |
| 244 | zephyr_cc_option(-fno-reorder-blocks) |
| 245 | zephyr_cc_option(-fno-ipa-cp-clone) |
| 246 | zephyr_cc_option(-fno-partial-inlining) |
| 247 | endif() |
| 248 | |
| 249 | zephyr_cc_option(-fno-asynchronous-unwind-tables) |
| 250 | zephyr_cc_option(-fno-pie) |
| 251 | zephyr_cc_option(-fno-pic) |
| 252 | zephyr_cc_option(-fno-strict-overflow) |
| 253 | zephyr_cc_option(-Wno-pointer-sign) |
| 254 | |
Sebastian Bøe | 703dc59 | 2017-11-29 10:19:50 +0100 | [diff] [blame] | 255 | zephyr_compile_options_ifdef(CONFIG_STACK_CANARIES -fstack-protector-all) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 256 | |
| 257 | if(CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT) |
| 258 | if(CONFIG_OMIT_FRAME_POINTER) |
| 259 | zephyr_cc_option(-fomit-frame-pointer) |
| 260 | else() |
| 261 | zephyr_cc_option(-fno-omit-frame-pointer) |
| 262 | endif() |
| 263 | endif() |
| 264 | |
Aurelien Jarno | 92a6898 | 2018-06-16 23:40:04 +0200 | [diff] [blame] | 265 | separate_arguments(CONFIG_COMPILER_OPT_AS_LIST UNIX_COMMAND ${CONFIG_COMPILER_OPT}) |
| 266 | zephyr_compile_options(${CONFIG_COMPILER_OPT_AS_LIST}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 267 | |
| 268 | # TODO: Include arch compiler options at this point. |
| 269 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 270 | if(CMAKE_C_COMPILER_ID STREQUAL "Clang") |
| 271 | zephyr_cc_option( |
Anas Nashif | 72edc4e | 2018-05-02 00:09:31 -0500 | [diff] [blame] | 272 | #FIXME: need to fix all of those |
| 273 | -Wno-sometimes-uninitialized |
| 274 | -Wno-shift-overflow |
| 275 | -Wno-missing-braces |
| 276 | -Wno-self-assign |
| 277 | -Wno-address-of-packed-member |
| 278 | -Wno-unused-function |
| 279 | -Wno-initializer-overrides |
| 280 | -Wno-section |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 281 | -Wno-unknown-warning-option |
| 282 | -Wno-unused-variable |
| 283 | -Wno-format-invalid-specifier |
| 284 | -Wno-gnu |
| 285 | # comparison of unsigned expression < 0 is always false |
| 286 | -Wno-tautological-compare |
| 287 | ) |
| 288 | else() # GCC assumed |
| 289 | zephyr_cc_option( |
| 290 | -Wno-unused-but-set-variable |
| 291 | -fno-reorder-functions |
| 292 | ) |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 293 | |
Anas Nashif | 7ee8bb9 | 2018-02-11 14:36:21 -0600 | [diff] [blame] | 294 | if(NOT ${ZEPHYR_TOOLCHAIN_VARIANT} STREQUAL "xcc") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 295 | zephyr_cc_option(-fno-defer-pop) |
| 296 | endif() |
| 297 | endif() |
| 298 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 299 | zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage) |
| 300 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 301 | zephyr_system_include_directories(${NOSTDINC}) |
| 302 | |
| 303 | # Force an error when things like SYS_INIT(foo, ...) occur with a missing header. |
| 304 | zephyr_cc_option(-Werror=implicit-int) |
| 305 | |
Mark Ruvald Pedersen | 28394cc | 2018-09-14 14:24:53 +0200 | [diff] [blame] | 306 | # Prohibit void pointer arithmetic. Illegal in C99 |
| 307 | zephyr_cc_option(-Wpointer-arith) |
| 308 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 309 | # Prohibit date/time macros, which would make the build non-deterministic |
| 310 | # cc-option(-Werror=date-time) |
| 311 | |
| 312 | # TODO: Archiver arguments |
| 313 | # ar_option(D) |
| 314 | |
Håkon Øye Amundsen | d6551b5 | 2018-11-29 09:08:08 +0000 | [diff] [blame] | 315 | # Declare MPU userspace dependencies before the linker scripts to make |
| 316 | # sure the order of dependencies are met |
| 317 | if(CONFIG_CPU_HAS_MPU AND CONFIG_USERSPACE) |
| 318 | if(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT AND CONFIG_APP_SHARED_MEM ) |
| 319 | set(APP_SMEM_DEP app_smem_linker) |
| 320 | endif() |
| 321 | if(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT AND CONFIG_ARC AND CONFIG_APPLICATION_MEMORY) |
| 322 | set(ALIGN_SIZING_DEP app_sizing_prebuilt linker_app_sizing_script) |
| 323 | endif() |
| 324 | if(CONFIG_ARM) |
| 325 | set(PRIV_STACK_DEP priv_stacks_prebuilt) |
| 326 | endif() |
| 327 | endif() |
| 328 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 329 | set_ifndef(LINKERFLAGPREFIX -Wl) |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 330 | |
| 331 | if(NOT CONFIG_NATIVE_APPLICATION) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 332 | zephyr_ld_options( |
| 333 | ${LINKERFLAGPREFIX},-X |
| 334 | ${LINKERFLAGPREFIX},-N |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 335 | ) |
| 336 | endif() |
| 337 | |
| 338 | zephyr_ld_options( |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 339 | ${LINKERFLAGPREFIX},--gc-sections |
| 340 | ${LINKERFLAGPREFIX},--build-id=none |
| 341 | ) |
| 342 | |
Daniel Leung | 6600c64 | 2018-10-19 10:15:19 -0700 | [diff] [blame] | 343 | if(NOT CONFIG_NATIVE_APPLICATION) |
Håkon Øye Amundsen | 2a3f434 | 2018-11-29 09:12:38 +0000 | [diff] [blame] | 344 | set(NOSTDINC_F -nostdinc) |
| 345 | endif() |
| 346 | |
Håkon Øye Amundsen | a449439 | 2018-11-29 09:14:27 +0000 | [diff] [blame] | 347 | get_property(TOPT GLOBAL PROPERTY TOPT) |
| 348 | set_ifndef( TOPT -T) |
| 349 | |
Håkon Øye Amundsen | 2a3f434 | 2018-11-29 09:12:38 +0000 | [diff] [blame] | 350 | if(NOT CONFIG_NATIVE_APPLICATION) |
Daniel Leung | 6600c64 | 2018-10-19 10:15:19 -0700 | [diff] [blame] | 351 | # Funny thing is if this is set to =error, some architectures will |
| 352 | # skip this flag even though the compiler flag check passes |
| 353 | # (e.g. ARC and Xtensa). So warning should be the default for now. |
| 354 | # |
| 355 | # Skip this for native application as Zephyr only provides |
| 356 | # additions to the host toolchain linker script. The relocation |
| 357 | # sections (.rel*) requires us to override those provided |
| 358 | # by host toolchain. As we can't account for all possible |
| 359 | # combination of compiler and linker on all machines used |
| 360 | # for development, it is better to turn this off. |
| 361 | # |
| 362 | # CONFIG_LINKER_ORPHAN_SECTION_PLACE is to place the orphan sections |
| 363 | # without any warnings or errors, which is the default behavior. |
| 364 | # So there is no need to explicity set a linker flag. |
| 365 | if(CONFIG_LINKER_ORPHAN_SECTION_WARN) |
| 366 | zephyr_ld_options( |
| 367 | ${LINKERFLAGPREFIX},--orphan-handling=warn |
| 368 | ) |
| 369 | elseif(CONFIG_LINKER_ORPHAN_SECTION_ERROR) |
| 370 | zephyr_ld_options( |
| 371 | ${LINKERFLAGPREFIX},--orphan-handling=error |
| 372 | ) |
| 373 | endif() |
| 374 | endif() |
| 375 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 376 | if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT) |
| 377 | set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT}) |
Sebastian Bøe | c1aa9d1 | 2018-04-12 14:48:05 +0200 | [diff] [blame] | 378 | if(NOT EXISTS ${LINKER_SCRIPT}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 379 | set(LINKER_SCRIPT ${CONFIG_CUSTOM_LINKER_SCRIPT}) |
Sebastian Bøe | c1aa9d1 | 2018-04-12 14:48:05 +0200 | [diff] [blame] | 380 | assert_exists(CONFIG_CUSTOM_LINKER_SCRIPT) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 381 | endif() |
| 382 | else() |
| 383 | # Try a board specific linker file |
| 384 | set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld) |
| 385 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 386 | # If not available, try an SoC specific linker file |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 387 | set(LINKER_SCRIPT ${SOC_DIR}/${ARCH}/${SOC_PATH}/linker.ld) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 388 | endif() |
| 389 | endif() |
| 390 | |
| 391 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 392 | message(FATAL_ERROR "Could not find linker script: '${LINKER_SCRIPT}'. Corrupted configuration?") |
| 393 | endif() |
| 394 | |
Kristian Klomsten Skordal | 0225e95 | 2018-01-30 11:26:42 +0100 | [diff] [blame] | 395 | # Custom section support in linker scripts requires that the application source |
| 396 | # directory is in the preprocessor search path, in order to find the custom |
| 397 | # linker script fragments. |
| 398 | if(CONFIG_CUSTOM_RODATA_LD OR CONFIG_CUSTOM_RWDATA_LD OR CONFIG_CUSTOM_SECTIONS_LD) |
| 399 | zephyr_include_directories(${APPLICATION_SOURCE_DIR}) |
| 400 | endif() |
| 401 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 402 | configure_file(version.h.in ${PROJECT_BINARY_DIR}/include/generated/version.h) |
| 403 | |
Håkon Øye Amundsen | 611b0d1 | 2018-11-29 09:15:33 +0000 | [diff] [blame] | 404 | function(construct_add_custom_command_for_linker_pass linker_output_name output_variable) |
| 405 | set(linker_cmd_file_name ${linker_output_name}.cmd) |
| 406 | |
| 407 | if (${linker_output_name} MATCHES "^linker_pass_final$") |
| 408 | set(linker_pass_define -DLINKER_PASS2) |
| 409 | else() |
| 410 | set(linker_pass_define "") |
| 411 | endif() |
| 412 | |
| 413 | # Different generators deal with depfiles differently. |
| 414 | if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") |
| 415 | # Note that the IMPLICIT_DEPENDS option is currently supported only |
| 416 | # for Makefile generators and will be ignored by other generators. |
| 417 | set(linker_script_dep IMPLICIT_DEPENDS C ${LINKER_SCRIPT}) |
| 418 | elseif(CMAKE_GENERATOR STREQUAL "Ninja") |
| 419 | # Using DEPFILE with other generators than Ninja is an error. |
| 420 | set(linker_script_dep DEPFILE ${PROJECT_BINARY_DIR}/${linker_cmd_file_name}.dep) |
| 421 | else() |
| 422 | # TODO: How would the linker script dependencies work for non-linker |
| 423 | # script generators. |
| 424 | message(STATUS "Warning; this generator is not well supported. The |
| 425 | Linker script may not be regenerated when it should.") |
| 426 | set(linker_script_dep "") |
| 427 | endif() |
| 428 | |
| 429 | zephyr_get_include_directories_for_lang(C current_includes) |
| 430 | get_filename_component(base_name ${CMAKE_CURRENT_BINARY_DIR} NAME) |
| 431 | get_property(current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES) |
| 432 | |
| 433 | set(${output_variable} |
| 434 | OUTPUT ${linker_cmd_file_name} |
| 435 | DEPENDS ${LINKER_SCRIPT} |
| 436 | ${linker_script_dep} |
| 437 | COMMAND ${CMAKE_C_COMPILER} |
| 438 | -x assembler-with-cpp |
| 439 | ${NOSTDINC_F} |
| 440 | ${NOSYSDEF_CFLAG} |
| 441 | -MD -MF ${linker_cmd_file_name}.dep -MT ${base_name}/${linker_cmd_file_name} |
| 442 | ${current_includes} |
| 443 | ${current_defines} |
| 444 | ${linker_pass_define} |
| 445 | -E ${LINKER_SCRIPT} |
| 446 | -P # Prevent generation of debug `#line' directives. |
| 447 | -o ${linker_cmd_file_name} |
| 448 | VERBATIM |
| 449 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR} |
| 450 | |
| 451 | PARENT_SCOPE |
| 452 | ) |
| 453 | endfunction() |
| 454 | |
Sebastian Bøe | 6f946e2 | 2018-01-09 10:52:57 +0100 | [diff] [blame] | 455 | # Unfortunately, the order in which CMakeLists.txt code is processed |
| 456 | # matters so we need to be careful about how we order the processing |
| 457 | # of subdirectories. One example is "Compiler flags added late in the |
| 458 | # build are not exported to external build systems #5605"; when we |
| 459 | # integrate with an external build system we read out all compiler |
| 460 | # flags when the external project is created. So an external project |
| 461 | # defined in subsys or ext will not get global flags added by drivers/ |
| 462 | # or tests/ as the subdirectories are ordered now. |
| 463 | # |
| 464 | # Another example of when the order matters is the reading and writing |
| 465 | # of global properties such as ZEPHYR_LIBS or |
| 466 | # GENERATED_KERNEL_OBJECT_FILES. |
| 467 | # |
| 468 | # Arch is placed early because it defines important compiler flags |
| 469 | # that must be exported to external build systems defined in |
| 470 | # e.g. subsys/. |
| 471 | add_subdirectory(arch) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 472 | add_subdirectory(lib) |
| 473 | add_subdirectory(misc) |
| 474 | # We use include instead of add_subdirectory to avoid creating a new directory scope. |
| 475 | # This is because source file properties are directory scoped, including the GENERATED |
| 476 | # property which is set implicitly for custom command outputs |
| 477 | include(misc/generated/CMakeLists.txt) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 478 | |
Erwan Gouriou | ba31cb5 | 2018-09-13 16:25:53 +0200 | [diff] [blame] | 479 | if(EXISTS ${SOC_DIR}/${ARCH}/CMakeLists.txt) |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 480 | add_subdirectory(${SOC_DIR}/${ARCH} soc/${ARCH}) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 481 | else() |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 482 | add_subdirectory(${SOC_DIR}/${ARCH}/${SOC_PATH} soc/${ARCH}/${SOC_PATH}) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 483 | endif() |
| 484 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 485 | add_subdirectory(boards) |
| 486 | add_subdirectory(ext) |
| 487 | add_subdirectory(subsys) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 488 | add_subdirectory(drivers) |
| 489 | add_subdirectory(tests) |
| 490 | |
Sebastian Bøe | 2ead15d | 2017-11-29 17:46:37 +0100 | [diff] [blame] | 491 | set(syscall_macros_h ${ZEPHYR_BINARY_DIR}/include/generated/syscall_macros.h) |
| 492 | |
| 493 | add_custom_target(syscall_macros_h_target DEPENDS ${syscall_macros_h}) |
| 494 | add_custom_command( OUTPUT ${syscall_macros_h} |
| 495 | COMMAND |
| 496 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 497 | ${ZEPHYR_BASE}/scripts/gen_syscall_header.py |
Sebastian Bøe | 2ead15d | 2017-11-29 17:46:37 +0100 | [diff] [blame] | 498 | > ${syscall_macros_h} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 499 | DEPENDS ${ZEPHYR_BASE}/scripts/gen_syscall_header.py |
Sebastian Bøe | 2ead15d | 2017-11-29 17:46:37 +0100 | [diff] [blame] | 500 | ) |
| 501 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 502 | |
| 503 | set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h) |
| 504 | set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json) |
| 505 | |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 506 | # The syscalls subdirs txt file is constructed by python containing a list of folders to use for |
| 507 | # dependency handling, including empty folders. |
| 508 | # Windows: The list is used to specify DIRECTORY list with CMAKE_CONFIGURE_DEPENDS attribute. |
| 509 | # Other OS: The list will update whenever a file is added/removed/modified and ensure a re-build. |
| 510 | set(syscalls_subdirs_txt ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_subdirs.txt) |
| 511 | |
| 512 | # As syscalls_subdirs_txt is updated whenever a file is modified, this file can not be used for |
| 513 | # monitoring of added / removed folders. A trigger file is thus used for correct dependency |
| 514 | # handling. The trigger file will update when a folder is added / removed. |
| 515 | set(syscalls_subdirs_trigger ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_subdirs.trigger) |
| 516 | |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 517 | if(NOT (${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)) |
| 518 | set(syscalls_links --create-links ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_links) |
| 519 | endif() |
| 520 | |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 521 | # When running CMake it must be ensured that all dependencies are correctly acquired. |
| 522 | execute_process( |
| 523 | COMMAND |
| 524 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 525 | ${ZEPHYR_BASE}/scripts/subfolder_list.py |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 526 | --directory ${ZEPHYR_BASE}/include # Walk this directory |
| 527 | --out-file ${syscalls_subdirs_txt} # Write file with discovered folder |
| 528 | --trigger ${syscalls_subdirs_trigger} # Trigger file that is used for json generation |
| 529 | ${syscalls_links} # If defined, create symlinks for dependencies |
| 530 | ) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 531 | file(STRINGS ${syscalls_subdirs_txt} PARSE_SYSCALLS_PATHS_DEPENDS) |
| 532 | |
| 533 | if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows) |
| 534 | # On windows only adding/removing files or folders will be reflected in depends. |
| 535 | # Hence adding a file requires CMake to re-run to add this file to the file list. |
| 536 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${PARSE_SYSCALLS_PATHS_DEPENDS}) |
| 537 | |
| 538 | # Also On Windows each header file must be monitored as file modifications are not reflected |
| 539 | # on directory level. |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 540 | file(GLOB_RECURSE PARSE_SYSCALLS_HEADER_DEPENDS ${ZEPHYR_BASE}/include/*.h) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 541 | else() |
| 542 | # The syscall parsing depends on the folders in order to detect add/removed/modified files. |
| 543 | # When a folder is removed, CMake will try to find a target that creates that dependency. |
| 544 | # This command sets up the target for CMake to find. |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 545 | # Without this code, CMake will fail with the following error: |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 546 | # <folder> needed by '<target>', missing and no known rule to make it |
| 547 | # when a folder is removed. |
| 548 | add_custom_command(OUTPUT ${PARSE_SYSCALLS_PATHS_DEPENDS} |
| 549 | COMMAND ${CMAKE_COMMAND} -E echo "" |
| 550 | COMMENT "Preparing syscall dependency handling" |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 551 | ) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 552 | |
| 553 | add_custom_command( |
| 554 | OUTPUT |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 555 | ${syscalls_subdirs_trigger} |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 556 | COMMAND |
| 557 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 558 | ${ZEPHYR_BASE}/scripts/subfolder_list.py |
| 559 | --directory ${ZEPHYR_BASE}/include # Walk this directory |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 560 | --out-file ${syscalls_subdirs_txt} # Write file with discovered folder |
| 561 | --trigger ${syscalls_subdirs_trigger} # Trigger file that is used for json generation |
| 562 | ${syscalls_links} # If defined, create symlinks for dependencies |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 563 | DEPENDS ${PARSE_SYSCALLS_PATHS_DEPENDS} |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 564 | ) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 565 | |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 566 | # Ensure subdir file always exists when specifying CMake dependency. |
| 567 | if(NOT EXISTS ${syscalls_subdirs_txt}) |
| 568 | file(WRITE ${syscalls_subdirs_txt} "") |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 569 | endif() |
| 570 | |
| 571 | # On other OS'es, modifying a file is reflected on the folder timestamp and hence detected |
| 572 | # when using depend on directory level. |
| 573 | # Thus CMake only needs to re-run when sub-directories are added / removed, which is indicated |
| 574 | # using a trigger file. |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 575 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${syscalls_subdirs_txt}) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 576 | endif() |
| 577 | |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 578 | # SYSCALL_INCLUDE_DIRECTORY will include the directories that needs to be |
| 579 | # searched for syscall declarations if CONFIG_APPLICATION_DEFINED_SYSCALL is set |
| 580 | if(CONFIG_APPLICATION_DEFINED_SYSCALL) |
| 581 | set(SYSCALL_INCLUDE_DIRECTORY --include ${APPLICATION_SOURCE_DIR}) |
| 582 | endif() |
| 583 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 584 | add_custom_command( |
| 585 | OUTPUT |
| 586 | ${syscalls_json} |
| 587 | COMMAND |
| 588 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 589 | ${ZEPHYR_BASE}/scripts/parse_syscalls.py |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 590 | --include ${ZEPHYR_BASE}/include # Read files from this dir |
| 591 | ${SYSCALL_INCLUDE_DIRECTORY} |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 592 | --json-file ${syscalls_json} # Write this file |
| 593 | DEPENDS ${syscalls_subdirs_trigger} ${PARSE_SYSCALLS_HEADER_DEPENDS} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 594 | ) |
| 595 | |
| 596 | add_custom_target(syscall_list_h_target DEPENDS ${syscall_list_h}) |
| 597 | add_custom_command(OUTPUT include/generated/syscall_dispatch.c ${syscall_list_h} |
| 598 | # Also, some files are written to include/generated/syscalls/ |
| 599 | COMMAND |
| 600 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 601 | ${ZEPHYR_BASE}/scripts/gen_syscalls.py |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 602 | --json-file ${syscalls_json} # Read this file |
| 603 | --base-output include/generated/syscalls # Write to this dir |
| 604 | --syscall-dispatch include/generated/syscall_dispatch.c # Write this file |
Andrew Boie | 353acf4 | 2018-07-23 18:10:15 -0700 | [diff] [blame] | 605 | --syscall-list ${syscall_list_h} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 606 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 607 | DEPENDS ${syscalls_json} |
| 608 | ) |
| 609 | |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 610 | set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/driver-validation.h) |
| 611 | add_custom_command( |
| 612 | OUTPUT ${DRV_VALIDATION} |
| 613 | COMMAND |
| 614 | ${PYTHON_EXECUTABLE} |
| 615 | ${ZEPHYR_BASE}/scripts/gen_kobject_list.py |
| 616 | --validation-output ${DRV_VALIDATION} |
| 617 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 618 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 619 | ) |
| 620 | add_custom_target(driver_validation_h_target DEPENDS ${DRV_VALIDATION}) |
| 621 | |
Leandro Pereira | 39dc7d0 | 2018-04-05 13:59:33 -0700 | [diff] [blame] | 622 | include($ENV{ZEPHYR_BASE}/cmake/kobj.cmake) |
| 623 | gen_kobj(KOBJ_INCLUDE_PATH) |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 624 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 625 | # Generate offsets.c.obj from offsets.c |
| 626 | # Generate offsets.h from offsets.c.obj |
| 627 | |
Anas Nashif | 644b31d | 2018-11-17 21:15:14 -0500 | [diff] [blame] | 628 | set(OFFSETS_C_PATH ${ZEPHYR_BASE}/arch/${ARCH}/core/offsets/offsets.c) |
| 629 | set(OFFSETS_O_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/offsets.dir/arch/${ARCH}/core/offsets/offsets.c.obj) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 630 | set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h) |
| 631 | |
Anas Nashif | 644b31d | 2018-11-17 21:15:14 -0500 | [diff] [blame] | 632 | add_library( offsets STATIC ${OFFSETS_C_PATH}) |
| 633 | target_link_libraries(offsets zephyr_interface) |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 634 | add_dependencies( offsets |
| 635 | syscall_list_h_target |
| 636 | syscall_macros_h_target |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 637 | driver_validation_h_target |
Leandro Pereira | 39dc7d0 | 2018-04-05 13:59:33 -0700 | [diff] [blame] | 638 | kobj_types_h_target |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 639 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 640 | |
| 641 | add_custom_command( |
| 642 | OUTPUT ${OFFSETS_H_PATH} |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 643 | COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/gen_offset_header.py |
Anas Nashif | 644b31d | 2018-11-17 21:15:14 -0500 | [diff] [blame] | 644 | -i ${OFFSETS_O_PATH} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 645 | -o ${OFFSETS_H_PATH} |
| 646 | DEPENDS offsets |
| 647 | ) |
| 648 | add_custom_target(offsets_h DEPENDS ${OFFSETS_H_PATH}) |
| 649 | |
| 650 | zephyr_include_directories(${TOOLCHAIN_INCLUDES}) |
| 651 | |
Sebastian Bøe | 89516fb | 2017-12-01 15:25:06 +0100 | [diff] [blame] | 652 | zephyr_get_include_directories_for_lang(C ZEPHYR_INCLUDES) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 653 | |
| 654 | add_subdirectory(kernel) |
| 655 | |
| 656 | # Read list content |
| 657 | get_property(ZEPHYR_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_LIBS) |
| 658 | |
| 659 | foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY}) |
| 660 | # TODO: Could this become an INTERFACE property of zephyr_interface? |
| 661 | add_dependencies(${zephyr_lib} offsets_h) |
Sebastian Bøe | 4ece94d | 2017-12-05 13:22:19 +0100 | [diff] [blame] | 662 | |
Sebastian Bøe | 64edbaf | 2018-01-09 12:45:19 +0100 | [diff] [blame] | 663 | # Verify that all (non-imported) libraries have source |
| 664 | # files. Libraries without source files are not supported because |
| 665 | # they are an indication that something has been misconfigured. |
| 666 | get_target_property(lib_imported ${zephyr_lib} IMPORTED) |
| 667 | get_target_property(lib_sources ${zephyr_lib} SOURCES) |
Sebastian Bøe | 4ece94d | 2017-12-05 13:22:19 +0100 | [diff] [blame] | 668 | if(lib_sources STREQUAL lib_sources-NOTFOUND |
| 669 | AND (NOT (${zephyr_lib} STREQUAL app)) |
Sebastian Bøe | 64edbaf | 2018-01-09 12:45:19 +0100 | [diff] [blame] | 670 | AND (NOT lib_imported) |
Sebastian Bøe | 4ece94d | 2017-12-05 13:22:19 +0100 | [diff] [blame] | 671 | ) |
| 672 | # app is not checked because it's sources are added to it after |
| 673 | # this CMakeLists.txt file has been processed |
| 674 | message(FATAL_ERROR "\ |
| 675 | The Zephyr library '${zephyr_lib}' was created without source files. \ |
Sebastian Bøe | 64edbaf | 2018-01-09 12:45:19 +0100 | [diff] [blame] | 676 | Empty (non-imported) libraries are not supported. \ |
Sebastian Bøe | 4ece94d | 2017-12-05 13:22:19 +0100 | [diff] [blame] | 677 | Either make sure that the library has the sources it should have, \ |
| 678 | or make sure it is not created when it has no source files.") |
| 679 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 680 | endforeach() |
| 681 | |
| 682 | get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) |
| 683 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 684 | if(CONFIG_APPLICATION_MEMORY) |
| 685 | # Objects default to being in kernel space, and then we exclude |
| 686 | # certain items. |
| 687 | set(kernel_object_file_list |
| 688 | ${ZEPHYR_LIBS_PROPERTY} |
| 689 | kernel |
| 690 | ) |
| 691 | list( |
| 692 | REMOVE_ITEM |
| 693 | kernel_object_file_list |
| 694 | app |
| 695 | ) |
| 696 | |
| 697 | # The zephyr libraries in zephyr/lib/ and zephyr/test/ belong in |
| 698 | # userspace. |
| 699 | |
| 700 | # NB: The business logic for determing what source files are in |
| 701 | # kernel space and what source files are in user space is |
| 702 | # fragile. Fix ASAP. |
| 703 | # |
| 704 | # The intended design is that certain directories are designated as |
| 705 | # containing userspace code and others for kernel space code. The |
| 706 | # implementation we have however is not working on directories of |
| 707 | # code, it is working on zephyr libraries. It is exploiting the fact |
| 708 | # that zephyr libraries follow a naming scheme as described in |
| 709 | # extensions.cmake:zephyr_library_get_current_dir_lib_name |
| 710 | # |
| 711 | # But code from test/ and lib/ that is placed in the "zephyr" |
| 712 | # library (with zephyr_sources()) will not be in a library that is |
| 713 | # prefixed with lib__ or test__ and will end up in the wrong address |
| 714 | # space. |
| 715 | set(application_space_dirs |
| 716 | lib |
| 717 | tests |
| 718 | ) |
| 719 | foreach(f ${kernel_object_file_list}) |
| 720 | foreach(app_dir ${application_space_dirs}) |
| 721 | if(${f} MATCHES "^${app_dir}__") # Begins with ${app_dir}__, e.g. lib__libc |
| 722 | list( |
| 723 | REMOVE_ITEM |
| 724 | kernel_object_file_list |
| 725 | ${f} |
| 726 | ) |
| 727 | endif() |
| 728 | endforeach() |
| 729 | endforeach() |
| 730 | |
| 731 | # Create a list ks, with relative paths to kernel space libs. |
| 732 | foreach(f ${kernel_object_file_list}) |
| 733 | get_target_property(target_name ${f} NAME) |
| 734 | get_target_property(target_binary_dir ${f} BINARY_DIR) |
| 735 | |
| 736 | string(REPLACE |
| 737 | ${PROJECT_BINARY_DIR} |
| 738 | "" |
| 739 | fixed_path |
| 740 | ${target_binary_dir} |
| 741 | ) |
| 742 | |
| 743 | # Append / if not empty |
| 744 | if(fixed_path) |
| 745 | set(fixed_path "${fixed_path}/") |
| 746 | endif() |
| 747 | |
| 748 | # Cut off leading / if present |
| 749 | if(fixed_path MATCHES "^/.+") |
| 750 | string(SUBSTRING ${fixed_path} 1 -1 fixed_path) |
| 751 | endif() |
| 752 | |
Sebastian Bøe | 1c2de10 | 2018-01-02 15:54:16 +0100 | [diff] [blame] | 753 | set(fixed_path "${fixed_path}lib${target_name}.a") |
| 754 | |
| 755 | if(CMAKE_GENERATOR STREQUAL "Ninja") |
| 756 | # Ninja invokes the linker from the root of the build directory |
| 757 | # (APPLICATION_BINARY_DIR) instead of from the build/zephyr |
| 758 | # directory (PROJECT_BINARY_DIR). So for linker-defs.h to get |
| 759 | # the correct path we need to prefix with zephyr/. |
| 760 | set(fixed_path "zephyr/${fixed_path}") |
| 761 | endif() |
| 762 | |
| 763 | list(APPEND ks ${fixed_path}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 764 | endforeach() |
| 765 | |
Sebastian Bøe | cbe7b4f | 2018-08-03 16:15:05 +0200 | [diff] [blame] | 766 | # We are done constructing kernel_object_file_list, now we inject |
| 767 | # this list into the linker script through the define |
| 768 | # KERNELSPACE_OBJECT_FILES |
| 769 | set(def -DKERNELSPACE_OBJECT_FILES=) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 770 | foreach(f ${ks}) |
Sebastian Bøe | cbe7b4f | 2018-08-03 16:15:05 +0200 | [diff] [blame] | 771 | set(def "${def} ${f}") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 772 | endforeach() |
Håkon Øye Amundsen | 611b0d1 | 2018-11-29 09:15:33 +0000 | [diff] [blame] | 773 | set_property(GLOBAL APPEND PROPERTY |
| 774 | PROPERTY_LINKER_SCRIPT_DEFINES |
| 775 | ${def} |
| 776 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 777 | endif() # CONFIG_APPLICATION_MEMORY |
| 778 | |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 779 | |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 780 | |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 781 | construct_add_custom_command_for_linker_pass(linker custom_command) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 782 | add_custom_command( |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 783 | ${custom_command} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 784 | ) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 785 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 786 | add_custom_target( |
| 787 | linker_script |
| 788 | DEPENDS |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 789 | ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} |
Adithya Baglody | c69fb0d | 2018-08-04 19:48:52 +0530 | [diff] [blame] | 790 | ${APP_SMEM_DEP} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 791 | linker.cmd |
| 792 | offsets_h |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 793 | ) |
| 794 | |
| 795 | # Give the 'linker_script' target all of the include directories so |
| 796 | # that cmake can successfully find the linker_script's header |
| 797 | # dependencies. |
| 798 | zephyr_get_include_directories_for_lang(C |
| 799 | ZEPHYR_INCLUDE_DIRS |
| 800 | STRIP_PREFIX # Don't use a -I prefix |
| 801 | ) |
| 802 | set_property(TARGET |
| 803 | linker_script |
| 804 | PROPERTY INCLUDE_DIRECTORIES |
| 805 | ${ZEPHYR_INCLUDE_DIRS} |
| 806 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 807 | |
| 808 | set(zephyr_lnk |
| 809 | ${LINKERFLAGPREFIX},-Map=${PROJECT_BINARY_DIR}/${KERNEL_MAP_NAME} |
| 810 | -u_OffsetAbsSyms |
| 811 | -u_ConfigAbsSyms |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 812 | ${LINKERFLAGPREFIX},--whole-archive |
| 813 | ${ZEPHYR_LIBS_PROPERTY} |
| 814 | ${LINKERFLAGPREFIX},--no-whole-archive |
| 815 | kernel |
Anas Nashif | 644b31d | 2018-11-17 21:15:14 -0500 | [diff] [blame] | 816 | ${OFFSETS_O_PATH} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 817 | ${LIB_INCLUDE_DIR} |
| 818 | -L${PROJECT_BINARY_DIR} |
| 819 | ${TOOLCHAIN_LIBS} |
| 820 | ) |
| 821 | |
| 822 | if(CONFIG_GEN_ISR_TABLES) |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 823 | if(CONFIG_GEN_SW_ISR_TABLE) |
| 824 | list(APPEND GEN_ISR_TABLE_EXTRA_ARG --sw-isr-table) |
| 825 | endif() |
| 826 | |
| 827 | if(CONFIG_GEN_IRQ_VECTOR_TABLE) |
| 828 | list(APPEND GEN_ISR_TABLE_EXTRA_ARG --vector-table) |
| 829 | endif() |
| 830 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 831 | # isr_tables.c is generated from zephyr_prebuilt by |
| 832 | # gen_isr_tables.py |
| 833 | add_custom_command( |
| 834 | OUTPUT isr_tables.c |
| 835 | COMMAND ${CMAKE_OBJCOPY} |
| 836 | -I ${OUTPUT_FORMAT} |
| 837 | -O binary |
| 838 | --only-section=.intList |
| 839 | $<TARGET_FILE:zephyr_prebuilt> |
| 840 | isrList.bin |
| 841 | COMMAND ${PYTHON_EXECUTABLE} |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 842 | ${ZEPHYR_BASE}/arch/common/gen_isr_tables.py |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 843 | --output-source isr_tables.c |
Rajavardhan Gundi | 1e6adba | 2017-12-24 15:18:57 +0530 | [diff] [blame] | 844 | --kernel $<TARGET_FILE:zephyr_prebuilt> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 845 | --intlist isrList.bin |
Yasushi SHOJI | 6fc0d77 | 2018-10-09 18:59:16 +0900 | [diff] [blame] | 846 | $<$<BOOL:${CONFIG_BIG_ENDIAN}>:--big-endian> |
Sebastian Bøe | a55279a | 2018-01-04 14:08:39 +0100 | [diff] [blame] | 847 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug> |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 848 | ${GEN_ISR_TABLE_EXTRA_ARG} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 849 | DEPENDS zephyr_prebuilt |
| 850 | ) |
| 851 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c) |
| 852 | endif() |
| 853 | |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 854 | if(CONFIG_ARM AND CONFIG_USERSPACE) |
| 855 | set(GEN_PRIV_STACKS $ENV{ZEPHYR_BASE}/scripts/gen_priv_stacks.py) |
| 856 | set(PROCESS_PRIV_STACKS_GPERF $ENV{ZEPHYR_BASE}/scripts/process_gperf.py) |
| 857 | |
| 858 | set(PRIV_STACKS priv_stacks_hash.gperf) |
| 859 | set(PRIV_STACKS_OUTPUT_SRC_PRE priv_stacks_hash_preprocessed.c) |
| 860 | set(PRIV_STACKS_OUTPUT_SRC priv_stacks_hash.c) |
| 861 | set(PRIV_STACKS_OUTPUT_OBJ priv_stacks_hash.c.obj) |
| 862 | set(PRIV_STACKS_OUTPUT_OBJ_RENAMED priv_stacks_hash_renamed.o) |
| 863 | |
| 864 | # Essentially what we are doing here is extracting some information |
| 865 | # out of the nearly finished elf file, generating the source code |
| 866 | # for a hash table based on that information, and then compiling and |
| 867 | # linking the hash table back into a now even more nearly finished |
| 868 | # elf file. |
| 869 | |
| 870 | # Use the script GEN_PRIV_STACKS to scan the kernel binary's |
| 871 | # (zephyr_prebuilt) DWARF information to produce a table of kernel |
| 872 | # objects (PRIV_STACKS) which we will then pass to gperf |
| 873 | add_custom_command( |
| 874 | OUTPUT ${PRIV_STACKS} |
| 875 | COMMAND |
| 876 | ${PYTHON_EXECUTABLE} |
| 877 | ${GEN_PRIV_STACKS} |
| 878 | --kernel $<TARGET_FILE:priv_stacks_prebuilt> |
| 879 | --output ${PRIV_STACKS} |
| 880 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 881 | DEPENDS priv_stacks_prebuilt |
| 882 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 883 | ) |
| 884 | add_custom_target(priv_stacks DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS}) |
| 885 | |
| 886 | # Use gperf to generate C code (PRIV_STACKS_OUTPUT_SRC_PRE) which implements a |
| 887 | # perfect hashtable based on PRIV_STACKS |
| 888 | add_custom_command( |
| 889 | OUTPUT ${PRIV_STACKS_OUTPUT_SRC_PRE} |
| 890 | COMMAND |
| 891 | ${GPERF} -C |
| 892 | --output-file ${PRIV_STACKS_OUTPUT_SRC_PRE} |
| 893 | ${PRIV_STACKS} |
Andy Gross | 878f39c | 2018-05-01 01:10:26 -0500 | [diff] [blame] | 894 | DEPENDS priv_stacks ${PRIV_STACKS} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 895 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 896 | ) |
| 897 | add_custom_target(priv_stacks_output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC_PRE}) |
| 898 | |
| 899 | # For our purposes the code/data generated by gperf is not optimal. |
| 900 | # |
| 901 | # The script PROCESS_GPERF creates a new c file OUTPUT_SRC based on |
| 902 | # OUTPUT_SRC_PRE to greatly reduce the amount of code/data generated |
| 903 | # since we know we are always working with pointer values |
| 904 | add_custom_command( |
| 905 | OUTPUT ${PRIV_STACKS_OUTPUT_SRC} |
| 906 | COMMAND |
Sebastian Bøe | 1b60070 | 2018-06-21 14:34:42 +0200 | [diff] [blame] | 907 | ${PYTHON_EXECUTABLE} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 908 | ${PROCESS_PRIV_STACKS_GPERF} |
| 909 | -i ${PRIV_STACKS_OUTPUT_SRC_PRE} |
| 910 | -o ${PRIV_STACKS_OUTPUT_SRC} |
| 911 | -p "struct _k_priv_stack_map" |
| 912 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Andy Gross | 878f39c | 2018-05-01 01:10:26 -0500 | [diff] [blame] | 913 | DEPENDS priv_stacks_output_src_pre ${PRIV_STACKS_OUTPUT_SRC_PRE} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 914 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 915 | ) |
| 916 | add_custom_target(priv_stacks_output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC}) |
| 917 | |
| 918 | # We need precise control of where generated text/data ends up in the final |
| 919 | # kernel image. Disable function/data sections and use objcopy to move |
| 920 | # generated data into special section names |
| 921 | add_library(priv_stacks_output_lib STATIC |
| 922 | ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC} |
| 923 | ) |
| 924 | |
| 925 | target_link_libraries(priv_stacks_output_lib zephyr_interface) |
| 926 | |
| 927 | # Turn off -ffunction-sections, etc. |
| 928 | # NB: Using a library instead of target_compile_options(priv_stacks_output_lib |
| 929 | # [...]) because a library's options have precedence |
| 930 | add_library(priv_stacks_output_lib_interface INTERFACE) |
| 931 | target_compile_options(priv_stacks_output_lib_interface INTERFACE |
| 932 | -fno-function-sections |
| 933 | -fno-data-sections |
| 934 | ) |
| 935 | target_link_libraries(priv_stacks_output_lib priv_stacks_output_lib_interface) |
| 936 | |
| 937 | set(PRIV_STACKS_OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/priv_stacks_output_lib.dir/${PRIV_STACKS_OUTPUT_OBJ}) |
| 938 | |
| 939 | add_custom_command( |
| 940 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED} |
| 941 | COMMAND |
| 942 | ${CMAKE_OBJCOPY} |
| 943 | --rename-section .bss=.priv_stacks.noinit |
| 944 | --rename-section .data=.priv_stacks.data |
| 945 | --rename-section .text=.priv_stacks.text |
| 946 | --rename-section .rodata=.priv_stacks.rodata |
| 947 | ${PRIV_STACKS_OUTPUT_OBJ_PATH} |
| 948 | ${PRIV_STACKS_OUTPUT_OBJ_RENAMED} |
| 949 | DEPENDS priv_stacks_output_lib |
| 950 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 951 | ) |
| 952 | add_custom_target(priv_stacks_output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED}) |
| 953 | |
| 954 | add_library(priv_stacks_output_obj_renamed_lib STATIC IMPORTED GLOBAL) |
| 955 | set_property( |
| 956 | TARGET priv_stacks_output_obj_renamed_lib |
| 957 | PROPERTY |
| 958 | IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED} |
| 959 | ) |
| 960 | add_dependencies( |
| 961 | priv_stacks_output_obj_renamed_lib |
| 962 | priv_stacks_output_obj_renamed |
| 963 | ) |
| 964 | |
| 965 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES priv_stacks_output_obj_renamed_lib) |
| 966 | endif() |
| 967 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 968 | if(CONFIG_USERSPACE) |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 969 | set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/gen_kobject_list.py) |
| 970 | set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/process_gperf.py) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 971 | |
| 972 | set(OBJ_LIST kobject_hash.gperf) |
| 973 | set(OUTPUT_SRC_PRE kobject_hash_preprocessed.c) |
| 974 | set(OUTPUT_SRC kobject_hash.c) |
| 975 | set(OUTPUT_OBJ kobject_hash.c.obj) |
| 976 | set(OUTPUT_OBJ_RENAMED kobject_hash_renamed.o) |
| 977 | |
| 978 | # Essentially what we are doing here is extracting some information |
| 979 | # out of the nearly finished elf file, generating the source code |
| 980 | # for a hash table based on that information, and then compiling and |
| 981 | # linking the hash table back into a now even more nearly finished |
| 982 | # elf file. |
| 983 | |
| 984 | # Use the script GEN_KOBJ_LIST to scan the kernel binary's |
| 985 | # (zephyr_prebuilt) DWARF information to produce a table of kernel |
| 986 | # objects (OBJ_LIST) which we will then pass to gperf |
| 987 | add_custom_command( |
| 988 | OUTPUT ${OBJ_LIST} |
| 989 | COMMAND |
| 990 | ${PYTHON_EXECUTABLE} |
| 991 | ${GEN_KOBJ_LIST} |
| 992 | --kernel $<TARGET_FILE:zephyr_prebuilt> |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 993 | --gperf-output ${OBJ_LIST} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 994 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 995 | DEPENDS zephyr_prebuilt |
| 996 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 997 | ) |
| 998 | add_custom_target(obj_list DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OBJ_LIST}) |
| 999 | |
| 1000 | # Use gperf to generate C code (OUTPUT_SRC_PRE) which implements a |
| 1001 | # perfect hashtable based on OBJ_LIST |
| 1002 | add_custom_command( |
| 1003 | OUTPUT ${OUTPUT_SRC_PRE} |
| 1004 | COMMAND |
| 1005 | ${GPERF} |
| 1006 | --output-file ${OUTPUT_SRC_PRE} |
| 1007 | ${OBJ_LIST} |
Sebastian Bøe | f5758b5 | 2018-01-31 10:42:46 +0100 | [diff] [blame] | 1008 | DEPENDS obj_list ${OBJ_LIST} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1009 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1010 | ) |
| 1011 | add_custom_target(output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC_PRE}) |
| 1012 | |
| 1013 | # For our purposes the code/data generated by gperf is not optimal. |
| 1014 | # |
| 1015 | # The script PROCESS_GPERF creates a new c file OUTPUT_SRC based on |
| 1016 | # OUTPUT_SRC_PRE to greatly reduce the amount of code/data generated |
| 1017 | # since we know we are always working with pointer values |
| 1018 | add_custom_command( |
| 1019 | OUTPUT ${OUTPUT_SRC} |
| 1020 | COMMAND |
Sebastian Bøe | 1b60070 | 2018-06-21 14:34:42 +0200 | [diff] [blame] | 1021 | ${PYTHON_EXECUTABLE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1022 | ${PROCESS_GPERF} |
| 1023 | -i ${OUTPUT_SRC_PRE} |
| 1024 | -o ${OUTPUT_SRC} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1025 | -p "struct _k_object" |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1026 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Sebastian Bøe | f5758b5 | 2018-01-31 10:42:46 +0100 | [diff] [blame] | 1027 | DEPENDS output_src_pre ${OUTPUT_SRC_PRE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1028 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1029 | ) |
| 1030 | add_custom_target(output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC}) |
| 1031 | |
| 1032 | # We need precise control of where generated text/data ends up in the final |
| 1033 | # kernel image. Disable function/data sections and use objcopy to move |
| 1034 | # generated data into special section names |
| 1035 | add_library(output_lib STATIC |
| 1036 | ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC} |
| 1037 | ) |
| 1038 | |
Adithya Baglody | ce9a5a2 | 2018-01-29 15:58:51 +0530 | [diff] [blame] | 1039 | # always compile kobject_hash.c at optimization -Os |
| 1040 | set_source_files_properties(${OUTPUT_SRC} PROPERTIES COMPILE_FLAGS -Os) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1041 | target_link_libraries(output_lib zephyr_interface) |
| 1042 | |
| 1043 | # Turn off -ffunction-sections, etc. |
| 1044 | # NB: Using a library instead of target_compile_options(output_lib |
| 1045 | # [...]) because a library's options have precedence |
| 1046 | add_library(output_lib_interface INTERFACE) |
| 1047 | target_compile_options(output_lib_interface INTERFACE |
| 1048 | -fno-function-sections |
| 1049 | -fno-data-sections |
| 1050 | ) |
| 1051 | target_link_libraries(output_lib output_lib_interface) |
| 1052 | |
| 1053 | set(OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/output_lib.dir/${OUTPUT_OBJ}) |
| 1054 | |
| 1055 | add_custom_command( |
| 1056 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED} |
| 1057 | COMMAND |
| 1058 | ${CMAKE_OBJCOPY} |
| 1059 | --rename-section .data=.kobject_data.data |
| 1060 | --rename-section .text=.kobject_data.text |
| 1061 | --rename-section .rodata=.kobject_data.rodata |
| 1062 | ${OUTPUT_OBJ_PATH} |
| 1063 | ${OUTPUT_OBJ_RENAMED} |
| 1064 | DEPENDS output_lib |
| 1065 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1066 | ) |
| 1067 | add_custom_target(output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED}) |
| 1068 | |
| 1069 | add_library(output_obj_renamed_lib STATIC IMPORTED GLOBAL) |
| 1070 | set_property( |
| 1071 | TARGET output_obj_renamed_lib |
| 1072 | PROPERTY |
| 1073 | IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED} |
| 1074 | ) |
| 1075 | add_dependencies( |
| 1076 | output_obj_renamed_lib |
| 1077 | output_obj_renamed |
| 1078 | ) |
| 1079 | |
| 1080 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES output_obj_renamed_lib) |
| 1081 | endif() |
| 1082 | |
| 1083 | # Read global variables into local variables |
| 1084 | get_property(GKOF GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES) |
| 1085 | get_property(GKSF GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES) |
| 1086 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 1087 | |
Alberto Escolar Piedras | c288241 | 2018-07-05 10:51:03 +0200 | [diff] [blame] | 1088 | get_property(CSTD GLOBAL PROPERTY CSTD) |
| 1089 | set_ifndef(CSTD c99) |
| 1090 | |
| 1091 | zephyr_compile_options( |
| 1092 | $<$<COMPILE_LANGUAGE:C>:-std=${CSTD}> |
| 1093 | ) |
| 1094 | |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1095 | configure_file( |
Ioannis Glaropoulos | c15c491 | 2018-11-29 14:26:01 +0100 | [diff] [blame] | 1096 | $ENV{ZEPHYR_BASE}/include/arch/arc/v2/app_data_alignment.ld |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1097 | ${PROJECT_BINARY_DIR}/include/generated/app_data_alignment.ld) |
| 1098 | |
Shawn Mosley | 573f32b | 2018-04-26 10:14:02 -0400 | [diff] [blame] | 1099 | configure_file( |
| 1100 | $ENV{ZEPHYR_BASE}/include/arch/arm/cortex_m/scripts/app_smem.ld |
| 1101 | ${PROJECT_BINARY_DIR}/include/generated/app_smem.ld) |
| 1102 | |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1103 | if(CONFIG_CPU_HAS_MPU AND CONFIG_USERSPACE) |
| 1104 | |
Shawn Mosley | 573f32b | 2018-04-26 10:14:02 -0400 | [diff] [blame] | 1105 | if(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT AND CONFIG_APP_SHARED_MEM) |
Shawn Mosley | 573f32b | 2018-04-26 10:14:02 -0400 | [diff] [blame] | 1106 | set(APP_SMEM_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem.ld") |
| 1107 | set(OBJ_FILE_DIR "${PROJECT_BINARY_DIR}/../") |
| 1108 | |
| 1109 | add_custom_target( |
| 1110 | ${APP_SMEM_DEP} ALL |
Adithya Baglody | c69fb0d | 2018-08-04 19:48:52 +0530 | [diff] [blame] | 1111 | DEPENDS app |
Adithya Baglody | c764e02 | 2018-09-19 11:28:27 +0530 | [diff] [blame] | 1112 | kernel |
Shawn Mosley | 573f32b | 2018-04-26 10:14:02 -0400 | [diff] [blame] | 1113 | ) |
| 1114 | |
| 1115 | add_custom_command( |
| 1116 | TARGET ${APP_SMEM_DEP} |
Adithya Baglody | c69fb0d | 2018-08-04 19:48:52 +0530 | [diff] [blame] | 1117 | COMMAND ${PYTHON_EXECUTABLE} |
| 1118 | ${ZEPHYR_BASE}/scripts/gen_app_partitions.py |
Shawn Mosley | 573f32b | 2018-04-26 10:14:02 -0400 | [diff] [blame] | 1119 | -d ${OBJ_FILE_DIR} |
| 1120 | -o ${APP_SMEM_LD} |
Adithya Baglody | c69fb0d | 2018-08-04 19:48:52 +0530 | [diff] [blame] | 1121 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Shawn Mosley | 573f32b | 2018-04-26 10:14:02 -0400 | [diff] [blame] | 1122 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ |
| 1123 | COMMENT "Generating power of 2 aligned app_smem linker section" |
| 1124 | ) |
| 1125 | endif() |
| 1126 | |
| 1127 | |
Ioannis Glaropoulos | c15c491 | 2018-11-29 14:26:01 +0100 | [diff] [blame] | 1128 | if(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT AND CONFIG_ARC AND CONFIG_APPLICATION_MEMORY) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1129 | |
| 1130 | construct_add_custom_command_for_linker_pass(linker_app_sizing custom_command) |
| 1131 | add_custom_command( |
| 1132 | ${custom_command} |
| 1133 | ) |
| 1134 | |
| 1135 | add_custom_target( |
| 1136 | linker_app_sizing_script |
| 1137 | DEPENDS |
| 1138 | linker_app_sizing.cmd |
| 1139 | offsets_h |
Adithya Baglody | c764e02 | 2018-09-19 11:28:27 +0530 | [diff] [blame] | 1140 | ${APP_SMEM_DEP} |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1141 | ) |
| 1142 | |
| 1143 | set_property(TARGET |
| 1144 | linker_app_sizing_script |
| 1145 | PROPERTY INCLUDE_DIRECTORIES |
| 1146 | ${ZEPHYR_INCLUDE_DIRS} |
| 1147 | ) |
| 1148 | |
| 1149 | # For systems with MPUs, the size of the application data section must |
| 1150 | # be determined so that MPU alignment requirements can be met. |
| 1151 | # Create a app_sizing_prebuilt target so we can do this before the |
| 1152 | # other ELF files are built |
| 1153 | set(GEN_APP_ALIGN $ENV{ZEPHYR_BASE}/scripts/gen_alignment_script.py) |
| 1154 | add_executable( app_sizing_prebuilt misc/empty_file.c) |
| 1155 | target_link_libraries(app_sizing_prebuilt ${TOPT} ${PROJECT_BINARY_DIR}/linker_app_sizing.cmd ${zephyr_lnk}) |
| 1156 | set_property(TARGET app_sizing_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_app_sizing.cmd) |
Shawn Mosley | 573f32b | 2018-04-26 10:14:02 -0400 | [diff] [blame] | 1157 | add_dependencies( app_sizing_prebuilt linker_app_sizing_script offsets ) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1158 | |
| 1159 | add_custom_command( |
| 1160 | TARGET app_sizing_prebuilt |
| 1161 | POST_BUILD |
| 1162 | COMMAND ${PYTHON_EXECUTABLE} ${GEN_APP_ALIGN} |
| 1163 | --output ./include/generated/app_data_alignment.ld |
| 1164 | --kernel $<TARGET_FILE:app_sizing_prebuilt> |
| 1165 | VERBATIM |
| 1166 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ |
| 1167 | ) |
| 1168 | endif() |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1169 | |
Wayne Ren | 5a0ba2f | 2018-02-12 19:17:04 +0800 | [diff] [blame] | 1170 | if(CONFIG_ARM) |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1171 | construct_add_custom_command_for_linker_pass(linker_priv_stacks custom_command) |
| 1172 | add_custom_command( |
| 1173 | ${custom_command} |
| 1174 | ) |
| 1175 | |
| 1176 | add_custom_target( |
| 1177 | linker_priv_stacks_script |
| 1178 | DEPENDS |
Adithya Baglody | d4b5ab6 | 2018-09-18 11:52:52 +0530 | [diff] [blame] | 1179 | ${ALIGN_SIZING_DEP} ${APP_SMEM_DEP} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1180 | linker_priv_stacks.cmd |
| 1181 | offsets_h |
| 1182 | ) |
| 1183 | |
| 1184 | set_property(TARGET |
| 1185 | linker_priv_stacks_script |
| 1186 | PROPERTY INCLUDE_DIRECTORIES |
| 1187 | ${ZEPHYR_INCLUDE_DIRS} |
| 1188 | ) |
| 1189 | |
| 1190 | set(PRIV_STACK_LIB priv_stacks_output_obj_renamed_lib) |
| 1191 | add_executable( priv_stacks_prebuilt misc/empty_file.c) |
| 1192 | target_link_libraries(priv_stacks_prebuilt ${TOPT} ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd ${zephyr_lnk}) |
| 1193 | set_property(TARGET priv_stacks_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd) |
| 1194 | add_dependencies( priv_stacks_prebuilt ${ALIGN_SIZING_DEP} linker_priv_stacks_script offsets) |
Wayne Ren | 5a0ba2f | 2018-02-12 19:17:04 +0800 | [diff] [blame] | 1195 | endif() |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1196 | |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1197 | endif() |
| 1198 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1199 | # FIXME: Is there any way to get rid of empty_file.c? |
| 1200 | add_executable( zephyr_prebuilt misc/empty_file.c) |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1201 | target_link_libraries(zephyr_prebuilt ${TOPT} ${PROJECT_BINARY_DIR}/linker.cmd ${PRIV_STACK_LIB} ${zephyr_lnk}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1202 | set_property(TARGET zephyr_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker.cmd) |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1203 | add_dependencies( zephyr_prebuilt ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} linker_script offsets) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1204 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 1205 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1206 | if(GKOF OR GKSF) |
| 1207 | set(logical_target_for_zephyr_elf kernel_elf) |
| 1208 | |
| 1209 | # The second linker pass uses the same source linker script of the |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 1210 | # first pass (LINKER_SCRIPT), but this time with a different output |
| 1211 | # file and preprocessed with the define LINKER_PASS2. |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 1212 | construct_add_custom_command_for_linker_pass(linker_pass_final custom_command) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1213 | add_custom_command( |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 1214 | ${custom_command} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1215 | ) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1216 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1217 | add_custom_target( |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 1218 | linker_pass_final_script |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1219 | DEPENDS |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1220 | ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1221 | zephyr_prebuilt |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 1222 | linker_pass_final.cmd |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1223 | offsets_h |
| 1224 | ) |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 1225 | set_property(TARGET |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 1226 | linker_pass_final_script |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 1227 | PROPERTY INCLUDE_DIRECTORIES |
| 1228 | ${ZEPHYR_INCLUDE_DIRS} |
| 1229 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1230 | |
| 1231 | add_executable( kernel_elf misc/empty_file.c ${GKSF}) |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 1232 | target_link_libraries(kernel_elf ${GKOF} ${TOPT} ${PROJECT_BINARY_DIR}/linker_pass_final.cmd ${zephyr_lnk}) |
| 1233 | set_property(TARGET kernel_elf PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_pass_final.cmd) |
Adithya Baglody | c69fb0d | 2018-08-04 19:48:52 +0530 | [diff] [blame] | 1234 | add_dependencies( kernel_elf ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} linker_pass_final_script) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1235 | else() |
| 1236 | set(logical_target_for_zephyr_elf zephyr_prebuilt) |
| 1237 | # Use the prebuilt elf as the final elf since we don't have a |
| 1238 | # generation stage. |
| 1239 | endif() |
| 1240 | |
Sebastian Bøe | 0fc3934 | 2018-10-16 13:25:04 +0200 | [diff] [blame] | 1241 | # Export the variable to the application's scope to allow the |
| 1242 | # application to know what the name of the final elf target is. |
| 1243 | set(logical_target_for_zephyr_elf ${logical_target_for_zephyr_elf} PARENT_SCOPE) |
| 1244 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1245 | # To avoid having the same logical target name for the zephyr lib and |
| 1246 | # the zephyr elf, we set the kernel_elf file name to zephyr.elf. |
| 1247 | set_target_properties(${logical_target_for_zephyr_elf} PROPERTIES OUTPUT_NAME ${KERNEL_NAME}) |
| 1248 | |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1249 | set(post_build_commands "") |
| 1250 | |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1251 | list_append_ifdef(CONFIG_CHECK_LINK_MAP |
| 1252 | post_build_commands |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 1253 | COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/check_link_map.py ${KERNEL_MAP_NAME} |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1254 | ) |
| 1255 | |
Håkon Øye Amundsen | c086b93 | 2018-11-26 09:47:16 +0000 | [diff] [blame] | 1256 | if(NOT CONFIG_BUILD_NO_GAP_FILL) |
| 1257 | # Use ';' as separator to get proper space in resulting command. |
| 1258 | set(GAP_FILL "--gap-fill;0xff") |
| 1259 | endif() |
| 1260 | |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1261 | list_append_ifdef( |
| 1262 | CONFIG_BUILD_OUTPUT_HEX |
| 1263 | post_build_commands |
Håkon Øye Amundsen | c086b93 | 2018-11-26 09:47:16 +0000 | [diff] [blame] | 1264 | COMMAND ${CMAKE_OBJCOPY} -S -Oihex ${GAP_FILL} -R .comment -R COMMON -R .eh_frame ${KERNEL_ELF_NAME} ${KERNEL_HEX_NAME} |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1265 | ) |
| 1266 | |
| 1267 | list_append_ifdef( |
| 1268 | CONFIG_BUILD_OUTPUT_BIN |
| 1269 | post_build_commands |
Håkon Øye Amundsen | c086b93 | 2018-11-26 09:47:16 +0000 | [diff] [blame] | 1270 | COMMAND ${CMAKE_OBJCOPY} -S -Obinary ${GAP_FILL} -R .comment -R COMMON -R .eh_frame ${KERNEL_ELF_NAME} ${KERNEL_BIN_NAME} |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1271 | ) |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1272 | |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1273 | list_append_ifdef( |
| 1274 | CONFIG_BUILD_OUTPUT_S19 |
| 1275 | post_build_commands |
Håkon Øye Amundsen | c086b93 | 2018-11-26 09:47:16 +0000 | [diff] [blame] | 1276 | COMMAND ${CMAKE_OBJCOPY} ${GAP_FILL} --srec-len 1 --output-target=srec ${KERNEL_ELF_NAME} ${KERNEL_S19_NAME} |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1277 | ) |
| 1278 | |
| 1279 | list_append_ifdef( |
Anas Nashif | 1f1143a | 2017-11-22 13:03:53 -0500 | [diff] [blame] | 1280 | CONFIG_OUTPUT_DISASSEMBLY |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1281 | post_build_commands |
| 1282 | COMMAND ${CMAKE_OBJDUMP} -S ${KERNEL_ELF_NAME} > ${KERNEL_LST_NAME} |
| 1283 | ) |
| 1284 | |
| 1285 | list_append_ifdef( |
Anas Nashif | 1f1143a | 2017-11-22 13:03:53 -0500 | [diff] [blame] | 1286 | CONFIG_OUTPUT_STAT |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1287 | post_build_commands |
| 1288 | COMMAND ${CMAKE_READELF} -e ${KERNEL_ELF_NAME} > ${KERNEL_STAT_NAME} |
| 1289 | ) |
| 1290 | |
| 1291 | list_append_ifdef( |
| 1292 | CONFIG_BUILD_OUTPUT_STRIPPED |
| 1293 | post_build_commands |
| 1294 | COMMAND ${CMAKE_STRIP} --strip-all ${KERNEL_ELF_NAME} -o ${KERNEL_STRIP_NAME} |
| 1295 | ) |
| 1296 | |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1297 | list_append_ifdef( |
| 1298 | CONFIG_BUILD_OUTPUT_EXE |
| 1299 | post_build_commands |
Anas Nashif | 951393f | 2018-10-16 10:54:53 -0400 | [diff] [blame] | 1300 | COMMAND ${CMAKE_COMMAND} -E copy ${KERNEL_ELF_NAME} ${KERNEL_EXE_NAME} |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1301 | ) |
| 1302 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1303 | add_custom_command( |
| 1304 | TARGET ${logical_target_for_zephyr_elf} |
| 1305 | POST_BUILD |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1306 | ${post_build_commands} |
| 1307 | COMMENT "Generating files from zephyr.elf for board: ${BOARD}" |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1308 | # NB: COMMENT only works for some CMake-Generators |
| 1309 | ) |
| 1310 | |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1311 | # To populate with hex files to merge, do the following: |
| 1312 | # set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE ${my_local_list}) |
| 1313 | # Note that the zephyr.hex file will not be included automatically. |
| 1314 | get_property(HEX_FILES_TO_MERGE GLOBAL PROPERTY HEX_FILES_TO_MERGE) |
| 1315 | if(HEX_FILES_TO_MERGE) |
| 1316 | # Merge in out-of-tree hex files. |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1317 | set(MERGED_HEX_NAME merged.hex) |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1318 | |
| 1319 | add_custom_command( |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1320 | OUTPUT ${MERGED_HEX_NAME} |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1321 | COMMAND |
| 1322 | ${PYTHON_EXECUTABLE} |
| 1323 | ${ZEPHYR_BASE}/scripts/mergehex.py |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1324 | -o ${MERGED_HEX_NAME} |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1325 | ${HEX_FILES_TO_MERGE} |
| 1326 | DEPENDS ${HEX_FILES_TO_MERGE} ${logical_target_for_zephyr_elf} |
| 1327 | ) |
| 1328 | |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1329 | add_custom_target(mergehex ALL DEPENDS ${MERGED_HEX_NAME}) |
Håkon Øye Amundsen | 0da5d24 | 2018-12-05 09:15:40 +0000 | [diff] [blame] | 1330 | list(APPEND FLASH_DEPS mergehex) |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1331 | endif() |
| 1332 | |
Sebastian Bøe | dbdd722 | 2017-12-19 13:20:10 +0100 | [diff] [blame] | 1333 | if(CONFIG_OUTPUT_PRINT_MEMORY_USAGE) |
| 1334 | # Use --print-memory-usage with the first link. |
| 1335 | # |
| 1336 | # Don't use this option with the second link because seeing it twice |
| 1337 | # could confuse users and using it on the second link would suppress |
| 1338 | # it when the first link has a ram/flash-usage issue. |
| 1339 | set(option ${LINKERFLAGPREFIX},--print-memory-usage) |
| 1340 | string(MAKE_C_IDENTIFIER check${option} check) |
Sebastian Bøe | ba0b283 | 2017-12-21 10:16:43 +0100 | [diff] [blame] | 1341 | |
Sebastian Bøe | c34b7a3 | 2017-12-27 15:21:54 +0100 | [diff] [blame] | 1342 | set(SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) |
Sebastian Bøe | ba0b283 | 2017-12-21 10:16:43 +0100 | [diff] [blame] | 1343 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${option}") |
Sebastian Bøe | 71b849f | 2018-04-17 15:08:58 +0200 | [diff] [blame] | 1344 | zephyr_check_compiler_flag(C "" ${check}) |
Sebastian Bøe | c34b7a3 | 2017-12-27 15:21:54 +0100 | [diff] [blame] | 1345 | set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS}) |
Sebastian Bøe | ba0b283 | 2017-12-21 10:16:43 +0100 | [diff] [blame] | 1346 | |
Sebastian Bøe | dbdd722 | 2017-12-19 13:20:10 +0100 | [diff] [blame] | 1347 | target_link_libraries_ifdef(${check} zephyr_prebuilt ${option}) |
| 1348 | endif() |
| 1349 | |
Anas Nashif | c15d3c9 | 2017-11-21 18:54:55 -0500 | [diff] [blame] | 1350 | if(EMU_PLATFORM) |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 1351 | include(${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake) |
Anas Nashif | fd276ae | 2017-12-21 16:45:45 -0500 | [diff] [blame] | 1352 | else() |
| 1353 | add_custom_target(run |
| 1354 | COMMAND |
| 1355 | ${CMAKE_COMMAND} -E echo |
| 1356 | "===================================================" |
| 1357 | "Emulation/Simulation not supported with this board." |
| 1358 | "===================================================" |
| 1359 | ) |
Anas Nashif | c15d3c9 | 2017-11-21 18:54:55 -0500 | [diff] [blame] | 1360 | endif() |
| 1361 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1362 | add_subdirectory(cmake/flash) |
| 1363 | |
| 1364 | add_subdirectory(cmake/usage) |
| 1365 | add_subdirectory(cmake/reports) |
| 1366 | |
Andrew Boie | 411686f | 2018-05-24 13:18:36 -0700 | [diff] [blame] | 1367 | if(CONFIG_ASSERT AND (NOT CONFIG_FORCE_NO_ASSERT)) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1368 | message(WARNING " |
| 1369 | ------------------------------------------------------------ |
| 1370 | --- WARNING: __ASSERT() statements are globally ENABLED --- |
Ioannis Glaropoulos | f90416c | 2018-05-31 11:05:12 +0200 | [diff] [blame] | 1371 | --- The kernel will run more slowly and use more memory --- |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1372 | ------------------------------------------------------------" |
| 1373 | ) |
| 1374 | endif() |
| 1375 | |
| 1376 | if(CONFIG_BOARD_DEPRECATED) |
| 1377 | message(WARNING " |
| 1378 | WARNING: The board '${BOARD}' is deprecated and will be |
| 1379 | removed in version ${CONFIG_BOARD_DEPRECATED}" |
| 1380 | ) |
| 1381 | endif() |
Andrew Boie | df48e11 | 2018-01-12 09:54:24 -0800 | [diff] [blame] | 1382 | |
| 1383 | if(CONFIG_X86 AND CONFIG_USERSPACE AND NOT CONFIG_X86_NO_MELTDOWN) |
| 1384 | message(WARNING " |
| 1385 | WARNING: You have enabled CONFIG_USERSPACE on an x86-based target. |
| 1386 | If your CPU is vulnerable to the Meltdown CPU bug, security of |
| 1387 | supervisor-only memory pages is not guaranteed. This version of Zephyr |
| 1388 | does not contain a fix for this issue." |
| 1389 | ) |
| 1390 | endif() |