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