Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1 | project(Zephyr-Kernel VERSION ${PROJECT_VERSION}) |
| 2 | enable_language(C CXX ASM) |
| 3 | |
| 4 | # *DOCUMENTATION* |
| 5 | # |
| 6 | # Note that this is *NOT* the top-level CMakeLists.txt. That's in the |
| 7 | # application. See the Application Development Primer documentation |
| 8 | # for details. |
| 9 | # |
| 10 | # To see a list of typical targets execute "make usage" |
| 11 | # More info can be located in ./README.rst |
| 12 | # Comments in this file are targeted only to the developer, do not |
| 13 | # expect to learn how to build the kernel reading this file. |
| 14 | |
| 15 | # Verify that the toolchain can compile a dummy file, if it is not we |
| 16 | # won't be able to test for compatiblity with certain C flags. |
| 17 | check_c_compiler_flag("" toolchain_is_ok) |
| 18 | assert(toolchain_is_ok "The toolchain is unable to build a dummy C file. See CMakeError.log.") |
| 19 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 20 | set(CMAKE_EXECUTABLE_SUFFIX .elf) |
| 21 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 22 | if(NOT PROPERTY_LINKER_SCRIPT_DEFINES) |
| 23 | set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__GCC_LINKER_CMD__) |
| 24 | endif() |
| 25 | |
| 26 | define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT BRIEF_DOCS " " FULL_DOCS " ") |
| 27 | set_property( GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-little${ARCH}) |
| 28 | |
| 29 | # zephyr_interface is a source-less library that has all the global |
| 30 | # compiler options needed by all source files. All zephyr libraries, |
| 31 | # including the library named "zephyr" link with this library to |
| 32 | # obtain these flags. |
| 33 | add_library(zephyr_interface INTERFACE) |
| 34 | |
| 35 | # zephyr is a catchall CMake library for source files that can be |
| 36 | # built purely with the include paths, defines, and other compiler |
| 37 | # flags that come with zephyr_interface. |
| 38 | zephyr_library_named(zephyr) |
| 39 | |
| 40 | zephyr_include_directories( |
| 41 | kernel/include |
| 42 | arch/${ARCH}/include |
| 43 | arch/${ARCH}/soc/${SOC_PATH} |
| 44 | arch/${ARCH}/soc/${SOC_PATH}/include |
| 45 | arch/${ARCH}/soc/${SOC_FAMILY}/include |
| 46 | ${BOARD_DIR} |
| 47 | include |
| 48 | include/drivers |
| 49 | ${PROJECT_BINARY_DIR}/include/generated |
| 50 | ${USERINCLUDE} |
| 51 | ${STDINCLUDE} |
| 52 | ) |
| 53 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 54 | zephyr_compile_definitions( |
| 55 | KERNEL |
| 56 | __ZEPHYR__=1 |
Anas Nashif | 34aebad | 2018-01-03 12:26:19 -0500 | [diff] [blame] | 57 | ) |
| 58 | |
| 59 | if(NOT CONFIG_COVERAGE) |
| 60 | zephyr_compile_definitions( |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 61 | _FORTIFY_SOURCE=2 |
| 62 | ) |
Anas Nashif | 34aebad | 2018-01-03 12:26:19 -0500 | [diff] [blame] | 63 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 64 | |
| 65 | # We need to set an optimization level. |
| 66 | # Default to -Os |
Alberto Escolar Piedras | f60527a | 2018-01-22 15:35:54 +0100 | [diff] [blame] | 67 | # unless CONFIG_NO_OPTIMIZATIONS is set, then it is -O0 |
| 68 | # or unless CONFIG_DEBUG is set, then it is -Og |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 69 | # |
| 70 | # also, some toolchain's break with -Os, and some toolchain's break |
| 71 | # with -Og so allow them to override what flag to use |
| 72 | # |
| 73 | # Finally, the user can use Kconfig to add compiler options that will |
| 74 | # come after these options and override them |
Alberto Escolar Piedras | f60527a | 2018-01-22 15:35:54 +0100 | [diff] [blame] | 75 | set_ifndef(OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG "-O0") |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 76 | set_ifndef(OPTIMIZE_FOR_DEBUG_FLAG "-Og") |
| 77 | set_ifndef(OPTIMIZE_FOR_SIZE_FLAG "-Os") |
| 78 | |
Alberto Escolar Piedras | f60527a | 2018-01-22 15:35:54 +0100 | [diff] [blame] | 79 | if(CONFIG_NO_OPTIMIZATIONS) |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 80 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG}) |
| 81 | elseif(CONFIG_DEBUG_OPTIMIZATIONS) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 82 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_DEBUG_FLAG}) |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 83 | elseif(CONFIG_SIZE_OPTIMIZATIONS) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 84 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SIZE_FLAG}) # Default |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 85 | else() |
| 86 | 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] | 87 | endif() |
| 88 | |
| 89 | zephyr_compile_options( |
| 90 | ${OPTIMIZATION_FLAG} # Usually -Os |
| 91 | -g # TODO: build configuration enough? |
| 92 | -Wall |
| 93 | -Wformat |
| 94 | -Wformat-security |
| 95 | -Wno-format-zero-length |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 96 | -imacros ${AUTOCONF_H} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 97 | -ffreestanding |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 98 | -Wno-main |
| 99 | ${NOSTDINC_F} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 100 | ) |
| 101 | |
| 102 | zephyr_compile_options( |
| 103 | $<$<COMPILE_LANGUAGE:C>:-std=c99> |
| 104 | |
| 105 | $<$<COMPILE_LANGUAGE:CXX>:-std=c++11> |
| 106 | $<$<COMPILE_LANGUAGE:CXX>:-fcheck-new> |
| 107 | $<$<COMPILE_LANGUAGE:CXX>:-ffunction-sections> |
| 108 | $<$<COMPILE_LANGUAGE:CXX>:-fdata-sections> |
| 109 | $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti> |
| 110 | $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions> |
| 111 | |
| 112 | $<$<COMPILE_LANGUAGE:ASM>:-xassembler-with-cpp> |
| 113 | $<$<COMPILE_LANGUAGE:ASM>:-D_ASMLANGUAGE> |
| 114 | ) |
| 115 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 116 | if(NOT CONFIG_NATIVE_APPLICATION) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 117 | zephyr_ld_options( |
| 118 | -nostartfiles |
| 119 | -nodefaultlibs |
| 120 | -nostdlib |
| 121 | -static |
| 122 | -no-pie |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 123 | ) |
| 124 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 125 | |
| 126 | # ========================================================================== |
| 127 | # |
| 128 | # cmake -DW=... settings |
| 129 | # |
| 130 | # W=1 - warnings that may be relevant and does not occur too often |
| 131 | # W=2 - warnings that occur quite often but may still be relevant |
| 132 | # W=3 - the more obscure warnings, can most likely be ignored |
| 133 | # ========================================================================== |
| 134 | if(W MATCHES "1") |
| 135 | zephyr_compile_options( |
| 136 | -Wextra |
| 137 | -Wunused |
| 138 | -Wno-unused-parameter |
| 139 | -Wmissing-declarations |
| 140 | -Wmissing-format-attribute |
| 141 | -Wold-style-definition |
| 142 | ) |
| 143 | zephyr_cc_option( |
| 144 | -Wmissing-prototypes |
| 145 | -Wmissing-include-dirs |
| 146 | -Wunused-but-set-variable |
| 147 | -Wno-missing-field-initializers |
| 148 | ) |
| 149 | endif() |
| 150 | |
| 151 | if(W MATCHES "2") |
| 152 | zephyr_compile_options( |
| 153 | -Waggregate-return |
| 154 | -Wcast-align |
| 155 | -Wdisabled-optimization |
| 156 | -Wnested-externs |
| 157 | -Wshadow |
| 158 | ) |
| 159 | zephyr_cc_option( |
| 160 | -Wlogical-op |
| 161 | -Wmissing-field-initializers |
| 162 | ) |
| 163 | endif() |
| 164 | |
| 165 | if(W MATCHES "3") |
| 166 | zephyr_compile_options( |
| 167 | -Wbad-function-cast |
| 168 | -Wcast-qual |
| 169 | -Wconversion |
| 170 | -Wpacked |
| 171 | -Wpadded |
| 172 | -Wpointer-arith |
| 173 | -Wredundant-decls |
| 174 | -Wswitch-default |
| 175 | ) |
| 176 | zephyr_cc_option( |
| 177 | -Wpacked-bitfield-compat |
| 178 | -Wvla |
| 179 | ) |
| 180 | endif() |
| 181 | |
| 182 | # Allow the user to inject options when calling cmake, e.g. |
| 183 | # 'cmake -DEXTRA_CFLAGS="-Werror -Wno-deprecated-declarations" ..' |
Sebastian Bøe | 9f59045 | 2017-11-10 12:22:23 +0100 | [diff] [blame] | 184 | include(cmake/extra_flags.cmake) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 185 | |
| 186 | if(CONFIG_READABLE_ASM) |
| 187 | zephyr_cc_option(-fno-reorder-blocks) |
| 188 | zephyr_cc_option(-fno-ipa-cp-clone) |
| 189 | zephyr_cc_option(-fno-partial-inlining) |
| 190 | endif() |
| 191 | |
| 192 | zephyr_cc_option(-fno-asynchronous-unwind-tables) |
| 193 | zephyr_cc_option(-fno-pie) |
| 194 | zephyr_cc_option(-fno-pic) |
| 195 | zephyr_cc_option(-fno-strict-overflow) |
| 196 | zephyr_cc_option(-Wno-pointer-sign) |
| 197 | |
Sebastian Bøe | 703dc59 | 2017-11-29 10:19:50 +0100 | [diff] [blame] | 198 | zephyr_compile_options_ifdef(CONFIG_STACK_CANARIES -fstack-protector-all) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 199 | |
| 200 | if(CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT) |
| 201 | if(CONFIG_OMIT_FRAME_POINTER) |
| 202 | zephyr_cc_option(-fomit-frame-pointer) |
| 203 | else() |
| 204 | zephyr_cc_option(-fno-omit-frame-pointer) |
| 205 | endif() |
| 206 | endif() |
| 207 | |
| 208 | zephyr_compile_options(${CONFIG_COMPILER_OPT}) |
| 209 | |
| 210 | # TODO: Include arch compiler options at this point. |
| 211 | |
| 212 | # TODO: This Clang check is broken |
| 213 | if(CMAKE_C_COMPILER_ID STREQUAL "Clang") |
| 214 | zephyr_cc_option( |
| 215 | -Wno-unknown-warning-option |
| 216 | -Wno-unused-variable |
| 217 | -Wno-format-invalid-specifier |
| 218 | -Wno-gnu |
| 219 | # comparison of unsigned expression < 0 is always false |
| 220 | -Wno-tautological-compare |
| 221 | ) |
| 222 | else() # GCC assumed |
| 223 | zephyr_cc_option( |
| 224 | -Wno-unused-but-set-variable |
| 225 | -fno-reorder-functions |
| 226 | ) |
Anas Nashif | 7ee8bb9 | 2018-02-11 14:36:21 -0600 | [diff] [blame] | 227 | if(NOT ${ZEPHYR_TOOLCHAIN_VARIANT} STREQUAL "xcc") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 228 | zephyr_cc_option(-fno-defer-pop) |
| 229 | endif() |
| 230 | endif() |
| 231 | |
| 232 | zephyr_cc_option_ifdef(CONFIG_DEBUG_SECTION_MISMATCH -fno-inline-functions-called-once) |
| 233 | zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage) |
| 234 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 235 | zephyr_system_include_directories(${NOSTDINC}) |
| 236 | |
| 237 | # Force an error when things like SYS_INIT(foo, ...) occur with a missing header. |
| 238 | zephyr_cc_option(-Werror=implicit-int) |
| 239 | |
| 240 | # Prohibit date/time macros, which would make the build non-deterministic |
| 241 | # cc-option(-Werror=date-time) |
| 242 | |
| 243 | # TODO: Archiver arguments |
| 244 | # ar_option(D) |
| 245 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 246 | set_ifndef(LINKERFLAGPREFIX -Wl) |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 247 | |
| 248 | if(NOT CONFIG_NATIVE_APPLICATION) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 249 | zephyr_ld_options( |
| 250 | ${LINKERFLAGPREFIX},-X |
| 251 | ${LINKERFLAGPREFIX},-N |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 252 | ) |
| 253 | endif() |
| 254 | |
| 255 | zephyr_ld_options( |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 256 | ${LINKERFLAGPREFIX},--gc-sections |
| 257 | ${LINKERFLAGPREFIX},--build-id=none |
| 258 | ) |
| 259 | |
| 260 | if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT) |
| 261 | set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT}) |
| 262 | if(NOT EXISTS LINKER_SCRIPT) |
| 263 | set(LINKER_SCRIPT ${CONFIG_CUSTOM_LINKER_SCRIPT}) |
| 264 | if(NOT EXISTS LINKER_SCRIPT) |
| 265 | message(FATAL_ERROR "CONFIG_HAVE_CUSTOM_LINKER_SCRIPT was set, but no linker script was found at '${CONFIG_CUSTOM_LINKER_SCRIPT}'") |
| 266 | endif() |
| 267 | endif() |
| 268 | else() |
| 269 | # Try a board specific linker file |
| 270 | set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld) |
| 271 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 272 | # If not available, try an SoC specific linker file |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 273 | set(LINKER_SCRIPT ${ZEPHYR_BASE}/arch/${ARCH}/soc/${SOC_PATH}/linker.ld) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 274 | endif() |
| 275 | endif() |
| 276 | |
| 277 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 278 | message(FATAL_ERROR "Could not find linker script: '${LINKER_SCRIPT}'. Corrupted configuration?") |
| 279 | endif() |
| 280 | |
Kristian Klomsten Skordal | 0225e95 | 2018-01-30 11:26:42 +0100 | [diff] [blame] | 281 | # Custom section support in linker scripts requires that the application source |
| 282 | # directory is in the preprocessor search path, in order to find the custom |
| 283 | # linker script fragments. |
| 284 | if(CONFIG_CUSTOM_RODATA_LD OR CONFIG_CUSTOM_RWDATA_LD OR CONFIG_CUSTOM_SECTIONS_LD) |
| 285 | zephyr_include_directories(${APPLICATION_SOURCE_DIR}) |
| 286 | endif() |
| 287 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 288 | configure_file(version.h.in ${PROJECT_BINARY_DIR}/include/generated/version.h) |
| 289 | |
Sebastian Bøe | 6f946e2 | 2018-01-09 10:52:57 +0100 | [diff] [blame] | 290 | # Unfortunately, the order in which CMakeLists.txt code is processed |
| 291 | # matters so we need to be careful about how we order the processing |
| 292 | # of subdirectories. One example is "Compiler flags added late in the |
| 293 | # build are not exported to external build systems #5605"; when we |
| 294 | # integrate with an external build system we read out all compiler |
| 295 | # flags when the external project is created. So an external project |
| 296 | # defined in subsys or ext will not get global flags added by drivers/ |
| 297 | # or tests/ as the subdirectories are ordered now. |
| 298 | # |
| 299 | # Another example of when the order matters is the reading and writing |
| 300 | # of global properties such as ZEPHYR_LIBS or |
| 301 | # GENERATED_KERNEL_OBJECT_FILES. |
| 302 | # |
| 303 | # Arch is placed early because it defines important compiler flags |
| 304 | # that must be exported to external build systems defined in |
| 305 | # e.g. subsys/. |
| 306 | add_subdirectory(arch) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 307 | add_subdirectory(lib) |
| 308 | add_subdirectory(misc) |
| 309 | # We use include instead of add_subdirectory to avoid creating a new directory scope. |
| 310 | # This is because source file properties are directory scoped, including the GENERATED |
| 311 | # property which is set implicitly for custom command outputs |
| 312 | include(misc/generated/CMakeLists.txt) |
| 313 | add_subdirectory(boards) |
| 314 | add_subdirectory(ext) |
| 315 | add_subdirectory(subsys) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 316 | add_subdirectory(drivers) |
| 317 | add_subdirectory(tests) |
| 318 | |
Sebastian Bøe | 2ead15d | 2017-11-29 17:46:37 +0100 | [diff] [blame] | 319 | set(syscall_macros_h ${ZEPHYR_BINARY_DIR}/include/generated/syscall_macros.h) |
| 320 | |
| 321 | add_custom_target(syscall_macros_h_target DEPENDS ${syscall_macros_h}) |
| 322 | add_custom_command( OUTPUT ${syscall_macros_h} |
| 323 | COMMAND |
| 324 | ${PYTHON_EXECUTABLE} |
| 325 | ${PROJECT_SOURCE_DIR}/scripts/gen_syscall_header.py |
| 326 | > ${syscall_macros_h} |
| 327 | DEPENDS ${PROJECT_SOURCE_DIR}/scripts/gen_syscall_header.py |
| 328 | ) |
| 329 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 330 | # This command is a hack to support commands that are always run. Any |
| 331 | # target that depends on always_rebuild will always be rebuilt. |
| 332 | add_custom_command(OUTPUT always_rebuild COMMAND cmake -E echo Building for board ${BOARD}) |
| 333 | |
| 334 | set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h) |
| 335 | set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json) |
| 336 | |
| 337 | add_custom_command( |
| 338 | OUTPUT |
| 339 | ${syscalls_json} |
| 340 | COMMAND |
| 341 | ${PYTHON_EXECUTABLE} |
| 342 | ${PROJECT_SOURCE_DIR}/scripts/parse_syscalls.py |
| 343 | --include ${PROJECT_SOURCE_DIR}/include # Read files from this dir |
| 344 | --json-file ${syscalls_json} # Write this file |
| 345 | DEPENDS always_rebuild |
| 346 | ) |
| 347 | |
| 348 | add_custom_target(syscall_list_h_target DEPENDS ${syscall_list_h}) |
| 349 | add_custom_command(OUTPUT include/generated/syscall_dispatch.c ${syscall_list_h} |
| 350 | # Also, some files are written to include/generated/syscalls/ |
| 351 | COMMAND |
| 352 | ${PYTHON_EXECUTABLE} |
| 353 | ${PROJECT_SOURCE_DIR}/scripts/gen_syscalls.py |
| 354 | --json-file ${syscalls_json} # Read this file |
| 355 | --base-output include/generated/syscalls # Write to this dir |
| 356 | --syscall-dispatch include/generated/syscall_dispatch.c # Write this file |
| 357 | > ${syscall_list_h} # Write stdout to this file |
| 358 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 359 | DEPENDS ${syscalls_json} |
| 360 | ) |
| 361 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 362 | # Generate offsets.c.obj from offsets.c |
| 363 | # Generate offsets.h from offsets.c.obj |
| 364 | |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 365 | set(OFFSETS_C_PATH ${ZEPHYR_BASE}/arch/${ARCH}/core/offsets/offsets.c) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 366 | set(OFFSETS_O_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/offsets.dir/arch/${ARCH}/core/offsets/offsets.c.obj) |
| 367 | set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h) |
| 368 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 369 | add_library( offsets STATIC ${OFFSETS_C_PATH}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 370 | target_link_libraries(offsets zephyr_interface) |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 371 | add_dependencies( offsets |
| 372 | syscall_list_h_target |
| 373 | syscall_macros_h_target |
| 374 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 375 | |
| 376 | add_custom_command( |
| 377 | OUTPUT ${OFFSETS_H_PATH} |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 378 | COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/gen_offset_header.py |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 379 | -i ${OFFSETS_O_PATH} |
| 380 | -o ${OFFSETS_H_PATH} |
| 381 | DEPENDS offsets |
| 382 | ) |
| 383 | add_custom_target(offsets_h DEPENDS ${OFFSETS_H_PATH}) |
| 384 | |
| 385 | zephyr_include_directories(${TOOLCHAIN_INCLUDES}) |
| 386 | |
Sebastian Bøe | 89516fb | 2017-12-01 15:25:06 +0100 | [diff] [blame] | 387 | zephyr_get_include_directories_for_lang(C ZEPHYR_INCLUDES) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 388 | |
| 389 | add_subdirectory(kernel) |
| 390 | |
| 391 | # Read list content |
| 392 | get_property(ZEPHYR_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_LIBS) |
| 393 | |
| 394 | foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY}) |
| 395 | # TODO: Could this become an INTERFACE property of zephyr_interface? |
| 396 | add_dependencies(${zephyr_lib} offsets_h) |
Sebastian Bøe | 4ece94d | 2017-12-05 13:22:19 +0100 | [diff] [blame] | 397 | |
Sebastian Bøe | 64edbaf | 2018-01-09 12:45:19 +0100 | [diff] [blame] | 398 | # Verify that all (non-imported) libraries have source |
| 399 | # files. Libraries without source files are not supported because |
| 400 | # they are an indication that something has been misconfigured. |
| 401 | get_target_property(lib_imported ${zephyr_lib} IMPORTED) |
| 402 | get_target_property(lib_sources ${zephyr_lib} SOURCES) |
Sebastian Bøe | 4ece94d | 2017-12-05 13:22:19 +0100 | [diff] [blame] | 403 | if(lib_sources STREQUAL lib_sources-NOTFOUND |
| 404 | AND (NOT (${zephyr_lib} STREQUAL app)) |
Sebastian Bøe | 64edbaf | 2018-01-09 12:45:19 +0100 | [diff] [blame] | 405 | AND (NOT lib_imported) |
Sebastian Bøe | 4ece94d | 2017-12-05 13:22:19 +0100 | [diff] [blame] | 406 | ) |
| 407 | # app is not checked because it's sources are added to it after |
| 408 | # this CMakeLists.txt file has been processed |
| 409 | message(FATAL_ERROR "\ |
| 410 | The Zephyr library '${zephyr_lib}' was created without source files. \ |
Sebastian Bøe | 64edbaf | 2018-01-09 12:45:19 +0100 | [diff] [blame] | 411 | Empty (non-imported) libraries are not supported. \ |
Sebastian Bøe | 4ece94d | 2017-12-05 13:22:19 +0100 | [diff] [blame] | 412 | Either make sure that the library has the sources it should have, \ |
| 413 | or make sure it is not created when it has no source files.") |
| 414 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 415 | endforeach() |
| 416 | |
| 417 | get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) |
| 418 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 419 | get_property(LINKER_SCRIPT_DEFINES GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES) |
| 420 | |
| 421 | if(CONFIG_APPLICATION_MEMORY) |
| 422 | # Objects default to being in kernel space, and then we exclude |
| 423 | # certain items. |
| 424 | set(kernel_object_file_list |
| 425 | ${ZEPHYR_LIBS_PROPERTY} |
| 426 | kernel |
| 427 | ) |
| 428 | list( |
| 429 | REMOVE_ITEM |
| 430 | kernel_object_file_list |
| 431 | app |
| 432 | ) |
| 433 | |
| 434 | # The zephyr libraries in zephyr/lib/ and zephyr/test/ belong in |
| 435 | # userspace. |
| 436 | |
| 437 | # NB: The business logic for determing what source files are in |
| 438 | # kernel space and what source files are in user space is |
| 439 | # fragile. Fix ASAP. |
| 440 | # |
| 441 | # The intended design is that certain directories are designated as |
| 442 | # containing userspace code and others for kernel space code. The |
| 443 | # implementation we have however is not working on directories of |
| 444 | # code, it is working on zephyr libraries. It is exploiting the fact |
| 445 | # that zephyr libraries follow a naming scheme as described in |
| 446 | # extensions.cmake:zephyr_library_get_current_dir_lib_name |
| 447 | # |
| 448 | # But code from test/ and lib/ that is placed in the "zephyr" |
| 449 | # library (with zephyr_sources()) will not be in a library that is |
| 450 | # prefixed with lib__ or test__ and will end up in the wrong address |
| 451 | # space. |
| 452 | set(application_space_dirs |
| 453 | lib |
| 454 | tests |
| 455 | ) |
| 456 | foreach(f ${kernel_object_file_list}) |
| 457 | foreach(app_dir ${application_space_dirs}) |
| 458 | if(${f} MATCHES "^${app_dir}__") # Begins with ${app_dir}__, e.g. lib__libc |
| 459 | list( |
| 460 | REMOVE_ITEM |
| 461 | kernel_object_file_list |
| 462 | ${f} |
| 463 | ) |
| 464 | endif() |
| 465 | endforeach() |
| 466 | endforeach() |
| 467 | |
| 468 | # Create a list ks, with relative paths to kernel space libs. |
| 469 | foreach(f ${kernel_object_file_list}) |
| 470 | get_target_property(target_name ${f} NAME) |
| 471 | get_target_property(target_binary_dir ${f} BINARY_DIR) |
| 472 | |
| 473 | string(REPLACE |
| 474 | ${PROJECT_BINARY_DIR} |
| 475 | "" |
| 476 | fixed_path |
| 477 | ${target_binary_dir} |
| 478 | ) |
| 479 | |
| 480 | # Append / if not empty |
| 481 | if(fixed_path) |
| 482 | set(fixed_path "${fixed_path}/") |
| 483 | endif() |
| 484 | |
| 485 | # Cut off leading / if present |
| 486 | if(fixed_path MATCHES "^/.+") |
| 487 | string(SUBSTRING ${fixed_path} 1 -1 fixed_path) |
| 488 | endif() |
| 489 | |
Sebastian Bøe | 1c2de10 | 2018-01-02 15:54:16 +0100 | [diff] [blame] | 490 | set(fixed_path "${fixed_path}lib${target_name}.a") |
| 491 | |
| 492 | if(CMAKE_GENERATOR STREQUAL "Ninja") |
| 493 | # Ninja invokes the linker from the root of the build directory |
| 494 | # (APPLICATION_BINARY_DIR) instead of from the build/zephyr |
| 495 | # directory (PROJECT_BINARY_DIR). So for linker-defs.h to get |
| 496 | # the correct path we need to prefix with zephyr/. |
| 497 | set(fixed_path "zephyr/${fixed_path}") |
| 498 | endif() |
| 499 | |
| 500 | list(APPEND ks ${fixed_path}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 501 | endforeach() |
| 502 | |
| 503 | # We are done constructing kernel_object_file_list, now we inject this |
| 504 | # information into the linker script through -D's |
| 505 | list(LENGTH kernel_object_file_list NUM_KERNEL_OBJECT_FILES) |
| 506 | list(APPEND LINKER_SCRIPT_DEFINES -DNUM_KERNEL_OBJECT_FILES=${NUM_KERNEL_OBJECT_FILES}) |
| 507 | set(i 0) |
| 508 | foreach(f ${ks}) |
| 509 | list(APPEND LINKER_SCRIPT_DEFINES -DKERNEL_OBJECT_FILE_${i}=${f}) |
| 510 | math(EXPR i "${i}+1") |
| 511 | endforeach() |
| 512 | endif() # CONFIG_APPLICATION_MEMORY |
| 513 | |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 514 | # Declare MPU userspace dependencies before the linker scripts to make |
| 515 | # sure the order of dependencies are met |
| 516 | if(CONFIG_CPU_HAS_MPU AND CONFIG_USERSPACE) |
Andy Gross | e1fc5c2 | 2018-02-15 08:07:17 -0600 | [diff] [blame] | 517 | if(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT AND CONFIG_APPLICATION_MEMORY) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 518 | set(ALIGN_SIZING_DEP app_sizing_prebuilt linker_app_sizing_script) |
| 519 | endif() |
Wayne Ren | 5a0ba2f | 2018-02-12 19:17:04 +0800 | [diff] [blame] | 520 | if(CONFIG_ARM) |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 521 | set(PRIV_STACK_DEP priv_stacks_prebuilt) |
Wayne Ren | 5a0ba2f | 2018-02-12 19:17:04 +0800 | [diff] [blame] | 522 | endif() |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 523 | endif() |
| 524 | |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 525 | function(construct_add_custom_command_for_linker_pass linker_output_name output_variable) |
| 526 | set(linker_cmd_file_name ${linker_output_name}.cmd) |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 527 | |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 528 | if (${linker_output_name} MATCHES "^linker_pass_final$") |
| 529 | set(LINKER_PASS_DEFINE -DLINKER_PASS2) |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 530 | else() |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 531 | set(LINKER_PASS_DEFINE "") |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 532 | endif() |
| 533 | |
Sebastian Bøe | a0b9129 | 2017-12-31 10:56:32 +0100 | [diff] [blame] | 534 | # Different generators deal with depfiles differently. |
| 535 | if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") |
| 536 | # Note that the IMPLICIT_DEPENDS option is currently supported only |
| 537 | # for Makefile generators and will be ignored by other generators. |
| 538 | set(LINKER_SCRIPT_DEP IMPLICIT_DEPENDS C ${LINKER_SCRIPT}) |
| 539 | elseif(CMAKE_GENERATOR STREQUAL "Ninja") |
| 540 | # Using DEPFILE with other generators than Ninja is an error. |
| 541 | set(LINKER_SCRIPT_DEP DEPFILE ${PROJECT_BINARY_DIR}/${linker_cmd_file_name}.dep) |
| 542 | else() |
| 543 | # TODO: How would the linker script dependencies work for non-linker |
| 544 | # script generators. |
| 545 | message(STATUS "Warning; this generator is not well supported. The |
| 546 | Linker script may not be regenerated when it should.") |
| 547 | set(LINKER_SCRIPT_DEP "") |
| 548 | endif() |
| 549 | |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 550 | set(${output_variable} |
| 551 | OUTPUT ${linker_cmd_file_name} |
| 552 | DEPENDS ${LINKER_SCRIPT} |
| 553 | ${LINKER_SCRIPT_DEP} |
| 554 | COMMAND ${CMAKE_C_COMPILER} |
| 555 | -x assembler-with-cpp |
| 556 | ${NOSTDINC_F} |
| 557 | -undef |
| 558 | -MD -MF ${linker_cmd_file_name}.dep -MT ${BASE_NAME}/${linker_cmd_file_name} |
| 559 | ${ZEPHYR_INCLUDES} |
| 560 | ${LINKER_SCRIPT_DEFINES} |
| 561 | ${LINKER_PASS_DEFINE} |
Sebastian Bøe | 8062a88 | 2018-01-03 16:02:49 +0100 | [diff] [blame] | 562 | -E ${LINKER_SCRIPT} |
| 563 | -P # Prevent generation of debug `#line' directives. |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 564 | -o ${linker_cmd_file_name} |
| 565 | VERBATIM |
| 566 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR} |
| 567 | |
| 568 | PARENT_SCOPE |
| 569 | ) |
| 570 | endfunction() |
| 571 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 572 | get_filename_component(BASE_NAME ${CMAKE_CURRENT_BINARY_DIR} NAME) |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 573 | construct_add_custom_command_for_linker_pass(linker custom_command) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 574 | add_custom_command( |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 575 | ${custom_command} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 576 | ) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 577 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 578 | add_custom_target( |
| 579 | linker_script |
| 580 | DEPENDS |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 581 | ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 582 | linker.cmd |
| 583 | offsets_h |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 584 | ) |
| 585 | |
| 586 | # Give the 'linker_script' target all of the include directories so |
| 587 | # that cmake can successfully find the linker_script's header |
| 588 | # dependencies. |
| 589 | zephyr_get_include_directories_for_lang(C |
| 590 | ZEPHYR_INCLUDE_DIRS |
| 591 | STRIP_PREFIX # Don't use a -I prefix |
| 592 | ) |
| 593 | set_property(TARGET |
| 594 | linker_script |
| 595 | PROPERTY INCLUDE_DIRECTORIES |
| 596 | ${ZEPHYR_INCLUDE_DIRS} |
| 597 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 598 | |
Anas Nashif | 5146dbb | 2017-12-21 23:43:48 -0500 | [diff] [blame] | 599 | get_property(E_KERNEL_ENTRY GLOBAL PROPERTY E_KERNEL_ENTRY) |
| 600 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 601 | set(zephyr_lnk |
| 602 | ${LINKERFLAGPREFIX},-Map=${PROJECT_BINARY_DIR}/${KERNEL_MAP_NAME} |
| 603 | -u_OffsetAbsSyms |
| 604 | -u_ConfigAbsSyms |
Anas Nashif | 5146dbb | 2017-12-21 23:43:48 -0500 | [diff] [blame] | 605 | ${E_KERNEL_ENTRY} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 606 | ${LINKERFLAGPREFIX},--start-group |
| 607 | ${LINKERFLAGPREFIX},--whole-archive |
| 608 | ${ZEPHYR_LIBS_PROPERTY} |
| 609 | ${LINKERFLAGPREFIX},--no-whole-archive |
| 610 | kernel |
| 611 | ${OFFSETS_O_PATH} |
| 612 | ${LINKERFLAGPREFIX},--end-group |
| 613 | ${LIB_INCLUDE_DIR} |
| 614 | -L${PROJECT_BINARY_DIR} |
| 615 | ${TOOLCHAIN_LIBS} |
| 616 | ) |
| 617 | |
| 618 | if(CONFIG_GEN_ISR_TABLES) |
| 619 | # isr_tables.c is generated from zephyr_prebuilt by |
| 620 | # gen_isr_tables.py |
| 621 | add_custom_command( |
| 622 | OUTPUT isr_tables.c |
| 623 | COMMAND ${CMAKE_OBJCOPY} |
| 624 | -I ${OUTPUT_FORMAT} |
| 625 | -O binary |
| 626 | --only-section=.intList |
| 627 | $<TARGET_FILE:zephyr_prebuilt> |
| 628 | isrList.bin |
| 629 | COMMAND ${PYTHON_EXECUTABLE} |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 630 | ${ZEPHYR_BASE}/arch/common/gen_isr_tables.py |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 631 | --output-source isr_tables.c |
Rajavardhan Gundi | 1e6adba | 2017-12-24 15:18:57 +0530 | [diff] [blame] | 632 | --kernel $<TARGET_FILE:zephyr_prebuilt> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 633 | --intlist isrList.bin |
Sebastian Bøe | a55279a | 2018-01-04 14:08:39 +0100 | [diff] [blame] | 634 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 635 | --sw-isr-table |
| 636 | --vector-table |
| 637 | DEPENDS zephyr_prebuilt |
| 638 | ) |
| 639 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c) |
| 640 | endif() |
| 641 | |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 642 | if(CONFIG_ARM AND CONFIG_USERSPACE) |
| 643 | set(GEN_PRIV_STACKS $ENV{ZEPHYR_BASE}/scripts/gen_priv_stacks.py) |
| 644 | set(PROCESS_PRIV_STACKS_GPERF $ENV{ZEPHYR_BASE}/scripts/process_gperf.py) |
| 645 | |
| 646 | set(PRIV_STACKS priv_stacks_hash.gperf) |
| 647 | set(PRIV_STACKS_OUTPUT_SRC_PRE priv_stacks_hash_preprocessed.c) |
| 648 | set(PRIV_STACKS_OUTPUT_SRC priv_stacks_hash.c) |
| 649 | set(PRIV_STACKS_OUTPUT_OBJ priv_stacks_hash.c.obj) |
| 650 | set(PRIV_STACKS_OUTPUT_OBJ_RENAMED priv_stacks_hash_renamed.o) |
| 651 | |
| 652 | # Essentially what we are doing here is extracting some information |
| 653 | # out of the nearly finished elf file, generating the source code |
| 654 | # for a hash table based on that information, and then compiling and |
| 655 | # linking the hash table back into a now even more nearly finished |
| 656 | # elf file. |
| 657 | |
| 658 | # Use the script GEN_PRIV_STACKS to scan the kernel binary's |
| 659 | # (zephyr_prebuilt) DWARF information to produce a table of kernel |
| 660 | # objects (PRIV_STACKS) which we will then pass to gperf |
| 661 | add_custom_command( |
| 662 | OUTPUT ${PRIV_STACKS} |
| 663 | COMMAND |
| 664 | ${PYTHON_EXECUTABLE} |
| 665 | ${GEN_PRIV_STACKS} |
| 666 | --kernel $<TARGET_FILE:priv_stacks_prebuilt> |
| 667 | --output ${PRIV_STACKS} |
| 668 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 669 | DEPENDS priv_stacks_prebuilt |
| 670 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 671 | ) |
| 672 | add_custom_target(priv_stacks DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS}) |
| 673 | |
| 674 | # Use gperf to generate C code (PRIV_STACKS_OUTPUT_SRC_PRE) which implements a |
| 675 | # perfect hashtable based on PRIV_STACKS |
| 676 | add_custom_command( |
| 677 | OUTPUT ${PRIV_STACKS_OUTPUT_SRC_PRE} |
| 678 | COMMAND |
| 679 | ${GPERF} -C |
| 680 | --output-file ${PRIV_STACKS_OUTPUT_SRC_PRE} |
| 681 | ${PRIV_STACKS} |
| 682 | DEPENDS priv_stacks |
| 683 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 684 | ) |
| 685 | add_custom_target(priv_stacks_output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC_PRE}) |
| 686 | |
| 687 | # For our purposes the code/data generated by gperf is not optimal. |
| 688 | # |
| 689 | # The script PROCESS_GPERF creates a new c file OUTPUT_SRC based on |
| 690 | # OUTPUT_SRC_PRE to greatly reduce the amount of code/data generated |
| 691 | # since we know we are always working with pointer values |
| 692 | add_custom_command( |
| 693 | OUTPUT ${PRIV_STACKS_OUTPUT_SRC} |
| 694 | COMMAND |
| 695 | ${PROCESS_PRIV_STACKS_GPERF} |
| 696 | -i ${PRIV_STACKS_OUTPUT_SRC_PRE} |
| 697 | -o ${PRIV_STACKS_OUTPUT_SRC} |
| 698 | -p "struct _k_priv_stack_map" |
| 699 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 700 | DEPENDS priv_stacks_output_src_pre |
| 701 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 702 | ) |
| 703 | add_custom_target(priv_stacks_output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC}) |
| 704 | |
| 705 | # We need precise control of where generated text/data ends up in the final |
| 706 | # kernel image. Disable function/data sections and use objcopy to move |
| 707 | # generated data into special section names |
| 708 | add_library(priv_stacks_output_lib STATIC |
| 709 | ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC} |
| 710 | ) |
| 711 | |
| 712 | target_link_libraries(priv_stacks_output_lib zephyr_interface) |
| 713 | |
| 714 | # Turn off -ffunction-sections, etc. |
| 715 | # NB: Using a library instead of target_compile_options(priv_stacks_output_lib |
| 716 | # [...]) because a library's options have precedence |
| 717 | add_library(priv_stacks_output_lib_interface INTERFACE) |
| 718 | target_compile_options(priv_stacks_output_lib_interface INTERFACE |
| 719 | -fno-function-sections |
| 720 | -fno-data-sections |
| 721 | ) |
| 722 | target_link_libraries(priv_stacks_output_lib priv_stacks_output_lib_interface) |
| 723 | |
| 724 | set(PRIV_STACKS_OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/priv_stacks_output_lib.dir/${PRIV_STACKS_OUTPUT_OBJ}) |
| 725 | |
| 726 | add_custom_command( |
| 727 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED} |
| 728 | COMMAND |
| 729 | ${CMAKE_OBJCOPY} |
| 730 | --rename-section .bss=.priv_stacks.noinit |
| 731 | --rename-section .data=.priv_stacks.data |
| 732 | --rename-section .text=.priv_stacks.text |
| 733 | --rename-section .rodata=.priv_stacks.rodata |
| 734 | ${PRIV_STACKS_OUTPUT_OBJ_PATH} |
| 735 | ${PRIV_STACKS_OUTPUT_OBJ_RENAMED} |
| 736 | DEPENDS priv_stacks_output_lib |
| 737 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 738 | ) |
| 739 | add_custom_target(priv_stacks_output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED}) |
| 740 | |
| 741 | add_library(priv_stacks_output_obj_renamed_lib STATIC IMPORTED GLOBAL) |
| 742 | set_property( |
| 743 | TARGET priv_stacks_output_obj_renamed_lib |
| 744 | PROPERTY |
| 745 | IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED} |
| 746 | ) |
| 747 | add_dependencies( |
| 748 | priv_stacks_output_obj_renamed_lib |
| 749 | priv_stacks_output_obj_renamed |
| 750 | ) |
| 751 | |
| 752 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES priv_stacks_output_obj_renamed_lib) |
| 753 | endif() |
| 754 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 755 | if(CONFIG_USERSPACE) |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 756 | set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/gen_kobject_list.py) |
| 757 | set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/process_gperf.py) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 758 | |
| 759 | set(OBJ_LIST kobject_hash.gperf) |
| 760 | set(OUTPUT_SRC_PRE kobject_hash_preprocessed.c) |
| 761 | set(OUTPUT_SRC kobject_hash.c) |
| 762 | set(OUTPUT_OBJ kobject_hash.c.obj) |
| 763 | set(OUTPUT_OBJ_RENAMED kobject_hash_renamed.o) |
| 764 | |
| 765 | # Essentially what we are doing here is extracting some information |
| 766 | # out of the nearly finished elf file, generating the source code |
| 767 | # for a hash table based on that information, and then compiling and |
| 768 | # linking the hash table back into a now even more nearly finished |
| 769 | # elf file. |
| 770 | |
| 771 | # Use the script GEN_KOBJ_LIST to scan the kernel binary's |
| 772 | # (zephyr_prebuilt) DWARF information to produce a table of kernel |
| 773 | # objects (OBJ_LIST) which we will then pass to gperf |
| 774 | add_custom_command( |
| 775 | OUTPUT ${OBJ_LIST} |
| 776 | COMMAND |
| 777 | ${PYTHON_EXECUTABLE} |
| 778 | ${GEN_KOBJ_LIST} |
| 779 | --kernel $<TARGET_FILE:zephyr_prebuilt> |
| 780 | --output ${OBJ_LIST} |
| 781 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 782 | DEPENDS zephyr_prebuilt |
| 783 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 784 | ) |
| 785 | add_custom_target(obj_list DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OBJ_LIST}) |
| 786 | |
| 787 | # Use gperf to generate C code (OUTPUT_SRC_PRE) which implements a |
| 788 | # perfect hashtable based on OBJ_LIST |
| 789 | add_custom_command( |
| 790 | OUTPUT ${OUTPUT_SRC_PRE} |
| 791 | COMMAND |
| 792 | ${GPERF} |
| 793 | --output-file ${OUTPUT_SRC_PRE} |
| 794 | ${OBJ_LIST} |
Sebastian Bøe | f5758b5 | 2018-01-31 10:42:46 +0100 | [diff] [blame] | 795 | DEPENDS obj_list ${OBJ_LIST} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 796 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 797 | ) |
| 798 | add_custom_target(output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC_PRE}) |
| 799 | |
| 800 | # For our purposes the code/data generated by gperf is not optimal. |
| 801 | # |
| 802 | # The script PROCESS_GPERF creates a new c file OUTPUT_SRC based on |
| 803 | # OUTPUT_SRC_PRE to greatly reduce the amount of code/data generated |
| 804 | # since we know we are always working with pointer values |
| 805 | add_custom_command( |
| 806 | OUTPUT ${OUTPUT_SRC} |
| 807 | COMMAND |
| 808 | ${PROCESS_GPERF} |
| 809 | -i ${OUTPUT_SRC_PRE} |
| 810 | -o ${OUTPUT_SRC} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 811 | -p "struct _k_object" |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 812 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Sebastian Bøe | f5758b5 | 2018-01-31 10:42:46 +0100 | [diff] [blame] | 813 | DEPENDS output_src_pre ${OUTPUT_SRC_PRE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 814 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 815 | ) |
| 816 | add_custom_target(output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC}) |
| 817 | |
| 818 | # We need precise control of where generated text/data ends up in the final |
| 819 | # kernel image. Disable function/data sections and use objcopy to move |
| 820 | # generated data into special section names |
| 821 | add_library(output_lib STATIC |
| 822 | ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC} |
| 823 | ) |
| 824 | |
Adithya Baglody | ce9a5a2 | 2018-01-29 15:58:51 +0530 | [diff] [blame] | 825 | # always compile kobject_hash.c at optimization -Os |
| 826 | set_source_files_properties(${OUTPUT_SRC} PROPERTIES COMPILE_FLAGS -Os) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 827 | target_link_libraries(output_lib zephyr_interface) |
| 828 | |
| 829 | # Turn off -ffunction-sections, etc. |
| 830 | # NB: Using a library instead of target_compile_options(output_lib |
| 831 | # [...]) because a library's options have precedence |
| 832 | add_library(output_lib_interface INTERFACE) |
| 833 | target_compile_options(output_lib_interface INTERFACE |
| 834 | -fno-function-sections |
| 835 | -fno-data-sections |
| 836 | ) |
| 837 | target_link_libraries(output_lib output_lib_interface) |
| 838 | |
| 839 | set(OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/output_lib.dir/${OUTPUT_OBJ}) |
| 840 | |
| 841 | add_custom_command( |
| 842 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED} |
| 843 | COMMAND |
| 844 | ${CMAKE_OBJCOPY} |
| 845 | --rename-section .data=.kobject_data.data |
| 846 | --rename-section .text=.kobject_data.text |
| 847 | --rename-section .rodata=.kobject_data.rodata |
| 848 | ${OUTPUT_OBJ_PATH} |
| 849 | ${OUTPUT_OBJ_RENAMED} |
| 850 | DEPENDS output_lib |
| 851 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 852 | ) |
| 853 | add_custom_target(output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED}) |
| 854 | |
| 855 | add_library(output_obj_renamed_lib STATIC IMPORTED GLOBAL) |
| 856 | set_property( |
| 857 | TARGET output_obj_renamed_lib |
| 858 | PROPERTY |
| 859 | IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED} |
| 860 | ) |
| 861 | add_dependencies( |
| 862 | output_obj_renamed_lib |
| 863 | output_obj_renamed |
| 864 | ) |
| 865 | |
| 866 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES output_obj_renamed_lib) |
| 867 | endif() |
| 868 | |
| 869 | # Read global variables into local variables |
| 870 | get_property(GKOF GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES) |
| 871 | get_property(GKSF GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES) |
| 872 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 873 | get_property(TOPT GLOBAL PROPERTY TOPT) |
| 874 | set_ifndef( TOPT -T) |
| 875 | |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 876 | configure_file( |
| 877 | $ENV{ZEPHYR_BASE}/include/arch/arm/cortex_m/scripts/app_data_alignment.ld |
| 878 | ${PROJECT_BINARY_DIR}/include/generated/app_data_alignment.ld) |
| 879 | |
| 880 | if(CONFIG_CPU_HAS_MPU AND CONFIG_USERSPACE) |
| 881 | |
Andy Gross | e1fc5c2 | 2018-02-15 08:07:17 -0600 | [diff] [blame] | 882 | if(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT AND CONFIG_APPLICATION_MEMORY) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 883 | |
| 884 | construct_add_custom_command_for_linker_pass(linker_app_sizing custom_command) |
| 885 | add_custom_command( |
| 886 | ${custom_command} |
| 887 | ) |
| 888 | |
| 889 | add_custom_target( |
| 890 | linker_app_sizing_script |
| 891 | DEPENDS |
| 892 | linker_app_sizing.cmd |
| 893 | offsets_h |
| 894 | ) |
| 895 | |
| 896 | set_property(TARGET |
| 897 | linker_app_sizing_script |
| 898 | PROPERTY INCLUDE_DIRECTORIES |
| 899 | ${ZEPHYR_INCLUDE_DIRS} |
| 900 | ) |
| 901 | |
| 902 | # For systems with MPUs, the size of the application data section must |
| 903 | # be determined so that MPU alignment requirements can be met. |
| 904 | # Create a app_sizing_prebuilt target so we can do this before the |
| 905 | # other ELF files are built |
| 906 | set(GEN_APP_ALIGN $ENV{ZEPHYR_BASE}/scripts/gen_alignment_script.py) |
| 907 | add_executable( app_sizing_prebuilt misc/empty_file.c) |
| 908 | target_link_libraries(app_sizing_prebuilt ${TOPT} ${PROJECT_BINARY_DIR}/linker_app_sizing.cmd ${zephyr_lnk}) |
| 909 | set_property(TARGET app_sizing_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_app_sizing.cmd) |
| 910 | add_dependencies( app_sizing_prebuilt linker_app_sizing_script offsets) |
| 911 | |
| 912 | add_custom_command( |
| 913 | TARGET app_sizing_prebuilt |
| 914 | POST_BUILD |
| 915 | COMMAND ${PYTHON_EXECUTABLE} ${GEN_APP_ALIGN} |
| 916 | --output ./include/generated/app_data_alignment.ld |
| 917 | --kernel $<TARGET_FILE:app_sizing_prebuilt> |
| 918 | VERBATIM |
| 919 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ |
| 920 | ) |
| 921 | endif() |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 922 | |
Wayne Ren | 5a0ba2f | 2018-02-12 19:17:04 +0800 | [diff] [blame] | 923 | if(CONFIG_ARM) |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 924 | construct_add_custom_command_for_linker_pass(linker_priv_stacks custom_command) |
| 925 | add_custom_command( |
| 926 | ${custom_command} |
| 927 | ) |
| 928 | |
| 929 | add_custom_target( |
| 930 | linker_priv_stacks_script |
| 931 | DEPENDS |
| 932 | ${ALIGN_SIZING_DEP} |
| 933 | linker_priv_stacks.cmd |
| 934 | offsets_h |
| 935 | ) |
| 936 | |
| 937 | set_property(TARGET |
| 938 | linker_priv_stacks_script |
| 939 | PROPERTY INCLUDE_DIRECTORIES |
| 940 | ${ZEPHYR_INCLUDE_DIRS} |
| 941 | ) |
| 942 | |
| 943 | set(PRIV_STACK_LIB priv_stacks_output_obj_renamed_lib) |
| 944 | add_executable( priv_stacks_prebuilt misc/empty_file.c) |
| 945 | target_link_libraries(priv_stacks_prebuilt ${TOPT} ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd ${zephyr_lnk}) |
| 946 | set_property(TARGET priv_stacks_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd) |
| 947 | 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] | 948 | endif() |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 949 | |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 950 | endif() |
| 951 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 952 | # FIXME: Is there any way to get rid of empty_file.c? |
| 953 | add_executable( zephyr_prebuilt misc/empty_file.c) |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 954 | 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] | 955 | 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] | 956 | 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] | 957 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 958 | |
| 959 | if(NOT CONFIG_NATIVE_APPLICATION) |
| 960 | set(NOSTDINC_F -nostdinc) |
| 961 | endif() |
| 962 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 963 | if(GKOF OR GKSF) |
| 964 | set(logical_target_for_zephyr_elf kernel_elf) |
| 965 | |
| 966 | # 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] | 967 | # first pass (LINKER_SCRIPT), but this time with a different output |
| 968 | # file and preprocessed with the define LINKER_PASS2. |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 969 | 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] | 970 | add_custom_command( |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 971 | ${custom_command} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 972 | ) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 973 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 974 | add_custom_target( |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 975 | linker_pass_final_script |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 976 | DEPENDS |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 977 | ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 978 | zephyr_prebuilt |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 979 | linker_pass_final.cmd |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 980 | offsets_h |
| 981 | ) |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 982 | set_property(TARGET |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 983 | linker_pass_final_script |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 984 | PROPERTY INCLUDE_DIRECTORIES |
| 985 | ${ZEPHYR_INCLUDE_DIRS} |
| 986 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 987 | |
| 988 | add_executable( kernel_elf misc/empty_file.c ${GKSF}) |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 989 | target_link_libraries(kernel_elf ${GKOF} ${TOPT} ${PROJECT_BINARY_DIR}/linker_pass_final.cmd ${zephyr_lnk}) |
| 990 | set_property(TARGET kernel_elf PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_pass_final.cmd) |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 991 | 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] | 992 | else() |
| 993 | set(logical_target_for_zephyr_elf zephyr_prebuilt) |
| 994 | # Use the prebuilt elf as the final elf since we don't have a |
| 995 | # generation stage. |
| 996 | endif() |
| 997 | |
| 998 | # To avoid having the same logical target name for the zephyr lib and |
| 999 | # the zephyr elf, we set the kernel_elf file name to zephyr.elf. |
| 1000 | set_target_properties(${logical_target_for_zephyr_elf} PROPERTIES OUTPUT_NAME ${KERNEL_NAME}) |
| 1001 | |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1002 | set(post_build_commands "") |
| 1003 | |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1004 | list_append_ifdef(CONFIG_CHECK_LINK_MAP |
| 1005 | post_build_commands |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 1006 | 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] | 1007 | ) |
| 1008 | |
| 1009 | list_append_ifdef( |
| 1010 | CONFIG_BUILD_OUTPUT_HEX |
| 1011 | post_build_commands |
| 1012 | COMMAND ${CMAKE_OBJCOPY} -S -Oihex -R .comment -R COMMON -R .eh_frame ${KERNEL_ELF_NAME} ${KERNEL_HEX_NAME} |
| 1013 | ) |
| 1014 | |
| 1015 | list_append_ifdef( |
| 1016 | CONFIG_BUILD_OUTPUT_BIN |
| 1017 | post_build_commands |
| 1018 | COMMAND ${CMAKE_OBJCOPY} -S -Obinary -R .comment -R COMMON -R .eh_frame ${KERNEL_ELF_NAME} ${KERNEL_BIN_NAME} |
| 1019 | ) |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1020 | |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1021 | list_append_ifdef( |
| 1022 | CONFIG_BUILD_OUTPUT_S19 |
| 1023 | post_build_commands |
| 1024 | COMMAND ${CMAKE_OBJCOPY} --srec-len 1 --output-target=srec ${KERNEL_ELF_NAME} ${KERNEL_S19_NAME} |
| 1025 | ) |
| 1026 | |
| 1027 | list_append_ifdef( |
Anas Nashif | 1f1143a | 2017-11-22 13:03:53 -0500 | [diff] [blame] | 1028 | CONFIG_OUTPUT_DISASSEMBLY |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1029 | post_build_commands |
| 1030 | COMMAND ${CMAKE_OBJDUMP} -S ${KERNEL_ELF_NAME} > ${KERNEL_LST_NAME} |
| 1031 | ) |
| 1032 | |
| 1033 | list_append_ifdef( |
Anas Nashif | 1f1143a | 2017-11-22 13:03:53 -0500 | [diff] [blame] | 1034 | CONFIG_OUTPUT_STAT |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1035 | post_build_commands |
| 1036 | COMMAND ${CMAKE_READELF} -e ${KERNEL_ELF_NAME} > ${KERNEL_STAT_NAME} |
| 1037 | ) |
| 1038 | |
| 1039 | list_append_ifdef( |
| 1040 | CONFIG_BUILD_OUTPUT_STRIPPED |
| 1041 | post_build_commands |
| 1042 | COMMAND ${CMAKE_STRIP} --strip-all ${KERNEL_ELF_NAME} -o ${KERNEL_STRIP_NAME} |
| 1043 | ) |
| 1044 | |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1045 | list_append_ifdef( |
| 1046 | CONFIG_BUILD_OUTPUT_EXE |
| 1047 | post_build_commands |
| 1048 | COMMAND ${CMAKE_COMMAND} -E rename ${KERNEL_ELF_NAME} ${KERNEL_EXE_NAME} |
| 1049 | ) |
| 1050 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1051 | add_custom_command( |
| 1052 | TARGET ${logical_target_for_zephyr_elf} |
| 1053 | POST_BUILD |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1054 | ${post_build_commands} |
| 1055 | COMMENT "Generating files from zephyr.elf for board: ${BOARD}" |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1056 | # NB: COMMENT only works for some CMake-Generators |
| 1057 | ) |
| 1058 | |
Sebastian Bøe | dbdd722 | 2017-12-19 13:20:10 +0100 | [diff] [blame] | 1059 | if(CONFIG_OUTPUT_PRINT_MEMORY_USAGE) |
| 1060 | # Use --print-memory-usage with the first link. |
| 1061 | # |
| 1062 | # Don't use this option with the second link because seeing it twice |
| 1063 | # could confuse users and using it on the second link would suppress |
| 1064 | # it when the first link has a ram/flash-usage issue. |
| 1065 | set(option ${LINKERFLAGPREFIX},--print-memory-usage) |
| 1066 | string(MAKE_C_IDENTIFIER check${option} check) |
Sebastian Bøe | ba0b283 | 2017-12-21 10:16:43 +0100 | [diff] [blame] | 1067 | |
Sebastian Bøe | c34b7a3 | 2017-12-27 15:21:54 +0100 | [diff] [blame] | 1068 | set(SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) |
Sebastian Bøe | ba0b283 | 2017-12-21 10:16:43 +0100 | [diff] [blame] | 1069 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${option}") |
| 1070 | check_c_compiler_flag("" ${check}) |
Sebastian Bøe | c34b7a3 | 2017-12-27 15:21:54 +0100 | [diff] [blame] | 1071 | set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS}) |
Sebastian Bøe | ba0b283 | 2017-12-21 10:16:43 +0100 | [diff] [blame] | 1072 | |
Sebastian Bøe | dbdd722 | 2017-12-19 13:20:10 +0100 | [diff] [blame] | 1073 | target_link_libraries_ifdef(${check} zephyr_prebuilt ${option}) |
| 1074 | endif() |
| 1075 | |
Anas Nashif | c15d3c9 | 2017-11-21 18:54:55 -0500 | [diff] [blame] | 1076 | if(EMU_PLATFORM) |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 1077 | include(${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake) |
Anas Nashif | fd276ae | 2017-12-21 16:45:45 -0500 | [diff] [blame] | 1078 | else() |
| 1079 | add_custom_target(run |
| 1080 | COMMAND |
| 1081 | ${CMAKE_COMMAND} -E echo |
| 1082 | "===================================================" |
| 1083 | "Emulation/Simulation not supported with this board." |
| 1084 | "===================================================" |
| 1085 | ) |
Anas Nashif | c15d3c9 | 2017-11-21 18:54:55 -0500 | [diff] [blame] | 1086 | endif() |
| 1087 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1088 | add_subdirectory(cmake/flash) |
| 1089 | |
| 1090 | add_subdirectory(cmake/usage) |
| 1091 | add_subdirectory(cmake/reports) |
| 1092 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1093 | if(CONFIG_ASSERT) |
| 1094 | message(WARNING " |
| 1095 | ------------------------------------------------------------ |
| 1096 | --- WARNING: __ASSERT() statements are globally ENABLED --- |
| 1097 | --- The kernel will run more slowly and uses more memory --- |
| 1098 | ------------------------------------------------------------" |
| 1099 | ) |
| 1100 | endif() |
| 1101 | |
| 1102 | if(CONFIG_BOARD_DEPRECATED) |
| 1103 | message(WARNING " |
| 1104 | WARNING: The board '${BOARD}' is deprecated and will be |
| 1105 | removed in version ${CONFIG_BOARD_DEPRECATED}" |
| 1106 | ) |
| 1107 | endif() |
Andrew Boie | df48e11 | 2018-01-12 09:54:24 -0800 | [diff] [blame] | 1108 | |
| 1109 | if(CONFIG_X86 AND CONFIG_USERSPACE AND NOT CONFIG_X86_NO_MELTDOWN) |
| 1110 | message(WARNING " |
| 1111 | WARNING: You have enabled CONFIG_USERSPACE on an x86-based target. |
| 1112 | If your CPU is vulnerable to the Meltdown CPU bug, security of |
| 1113 | supervisor-only memory pages is not guaranteed. This version of Zephyr |
| 1114 | does not contain a fix for this issue." |
| 1115 | ) |
| 1116 | endif() |