Anas Nashif | 3ae5262 | 2019-04-06 09:08:09 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | |
Mark Ruvald Pedersen | 59036db | 2018-12-19 16:27:55 +0100 | [diff] [blame] | 3 | # *DOCUMENTATION* |
| 4 | # |
| 5 | # Note that this is *NOT* the top-level CMakeLists.txt. That's in the |
| 6 | # application. See the Application Development Primer documentation |
| 7 | # for details. |
| 8 | # |
| 9 | # To see a list of typical targets execute "make usage" |
| 10 | # More info can be located in ./README.rst |
| 11 | # Comments in this file are targeted only to the developer, do not |
| 12 | # expect to learn how to build the kernel reading this file. |
| 13 | |
Sebastian Bøe | ee9af86 | 2018-06-04 11:47:45 +0200 | [diff] [blame] | 14 | if(NOT DEFINED ZEPHYR_BINARY_DIR) |
Anas Nashif | f2cb20c | 2019-06-18 14:45:40 -0400 | [diff] [blame] | 15 | message(FATAL_ERROR "A user error has occurred. |
Sebastian Bøe | ee9af86 | 2018-06-04 11:47:45 +0200 | [diff] [blame] | 16 | cmake was invoked with '${CMAKE_CURRENT_LIST_DIR}' specified as the source directory, |
| 17 | but it must be invoked with an application source directory, |
| 18 | such as '${CMAKE_CURRENT_LIST_DIR}/samples/hello_world'. |
| 19 | Debug variables: |
| 20 | CMAKE_CACHEFILE_DIR: ${CMAKE_CACHEFILE_DIR} |
| 21 | ") |
| 22 | endif() |
| 23 | |
Marc Herbert | d3d3394 | 2019-05-31 15:37:40 -0700 | [diff] [blame] | 24 | |
| 25 | # See https://gitlab.kitware.com/cmake/cmake/issues/16228 |
| 26 | # and https://cmake.org/pipermail/cmake/2019-May/thread.html#69496 |
| 27 | if(NOT ZEPHYR_BASE STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 28 | message(WARNING "ZEPHYR_BASE doesn't match CMAKE_CURRENT_SOURCE_DIR |
| 29 | ZEPHYR_BASE = ${ZEPHYR_BASE} |
| 30 | PWD = $ENV{PWD} |
| 31 | CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR} |
| 32 | You may be using a mix of symbolic links and real paths which causes \ |
| 33 | subtle and hard to debug CMake issues.") |
| 34 | endif() |
| 35 | # For Zephyr more specifically this breaks (at least) |
| 36 | # -fmacro-prefix-map=${ZEPHYR_BASE}= |
| 37 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 38 | |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 39 | # In some cases the "final" things are not used at all and "_prebuilt" |
| 40 | # is the last station. See "logical_target_for_zephyr_elf" below for |
| 41 | # details. |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 42 | set(CMAKE_EXECUTABLE_SUFFIX .elf) |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 43 | |
| 44 | # Zephyr build system will use a dynamic number of linking stages based on build |
| 45 | # configuration. |
| 46 | # |
| 47 | # Currently up to three linking stages may be executed: |
| 48 | # zephyr_pre0: First linking stage |
| 49 | # zephyr_pre1: Second linking stage |
| 50 | # zephyr_final: Final linking stage |
| 51 | # |
| 52 | # There will at minimum be a single linking stage. |
| 53 | # When only a single linking stage is required, the `zephyr_pre0` will be mapped |
| 54 | # into the `zephyr_final` target. |
| 55 | # |
| 56 | # Multiple linking stages are required in the following cases: |
| 57 | # - device handles structs must be generated (CONFIG_HAS_DTS=y) |
| 58 | # - ISR tables must be generated (CONFIG_GEN_ISR_TABLES=y) |
| 59 | # - Kernel objects hash tables (CONFIG_USERSPACE=y) |
| 60 | # - Application memory partitions (CONFIG_USERSPACE=y) |
| 61 | # |
| 62 | # Some generators require that memory locations has been fixed, thus those are |
| 63 | # placed at the second linking stage. |
| 64 | # |
| 65 | # When all three linking stages are active, then the following properties applies: |
| 66 | # - zephyr_pre0: linker sections may resize / addresses may relocate |
| 67 | # - zephyr_pre1: All linker section sizes are fixed, addresses cannot change |
| 68 | # - zephyr_final: Final image. |
| 69 | # |
| 70 | set(ZEPHYR_CURRENT_LINKER_PASS 0) |
| 71 | set(ZEPHYR_CURRENT_LINKER_CMD linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}.cmd) |
| 72 | set(ZEPHYR_LINK_STAGE_EXECUTABLE zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}) |
| 73 | |
| 74 | # ZEPHYR_PREBUILT_EXECUTABLE is used outside of this file, therefore keep the |
| 75 | # existing variable to allow slowly cleanup of linking stage handling. |
| 76 | # Three stage linking active: pre0 -> pre1 -> final, this will correspond to `pre1` |
| 77 | # Two stage linking active: pre0 -> final, this will correspond to `pre0` |
| 78 | if(CONFIG_USERSPACE OR CONFIG_HAS_DTS) |
| 79 | set(ZEPHYR_PREBUILT_EXECUTABLE zephyr_pre1) |
| 80 | else() |
| 81 | set(ZEPHYR_PREBUILT_EXECUTABLE zephyr_pre0) |
| 82 | endif() |
| 83 | set(ZEPHYR_FINAL_EXECUTABLE zephyr_final) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 84 | |
Mark Ruvald Pedersen | 11d6bae | 2019-04-29 16:57:37 +0200 | [diff] [blame] | 85 | # Set some phony targets to collect dependencies |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 86 | set(OFFSETS_H_TARGET offsets_h) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 87 | set(SYSCALL_LIST_H_TARGET syscall_list_h_target) |
| 88 | set(DRIVER_VALIDATION_H_TARGET driver_validation_h_target) |
| 89 | set(KOBJ_TYPES_H_TARGET kobj_types_h_target) |
Andrew Boie | c1c54b1 | 2020-03-16 12:48:00 -0700 | [diff] [blame] | 90 | set(PARSE_SYSCALLS_TARGET parse_syscalls_target) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 91 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 92 | define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT BRIEF_DOCS " " FULL_DOCS " ") |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 93 | set_property( GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-little${ARCH}) # BFD format |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 94 | |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 95 | # "zephyr_interface" is a source-less library that encapsulates all the global |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 96 | # compiler options needed by all source files. All zephyr libraries, |
| 97 | # including the library named "zephyr" link with this library to |
| 98 | # obtain these flags. |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 99 | # https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#interface-libraries |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 100 | add_library(zephyr_interface INTERFACE) |
| 101 | |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 102 | # "zephyr" is a catch-all CMake library for source files that can be |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 103 | # built purely with the include paths, defines, and other compiler |
| 104 | # flags that come with zephyr_interface. |
| 105 | zephyr_library_named(zephyr) |
| 106 | |
| 107 | zephyr_include_directories( |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 108 | include |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 109 | ${PROJECT_BINARY_DIR}/include/generated |
| 110 | ${USERINCLUDE} |
| 111 | ${STDINCLUDE} |
| 112 | ) |
| 113 | |
Torsten Rasmussen | c2842c3 | 2021-06-10 15:38:20 +0200 | [diff] [blame] | 114 | include(${ZEPHYR_BASE}/cmake/linker_script/${ARCH}/linker.cmake OPTIONAL) |
| 115 | |
Sebastian Bøe | 4036339 | 2019-01-25 10:14:13 +0100 | [diff] [blame] | 116 | # Don't add non-existing include directories, it creates noise and |
| 117 | # warnings in some tooling |
| 118 | foreach(optional_include_dir |
| 119 | ${SOC_DIR}/${ARCH}/${SOC_PATH} |
| 120 | ${SOC_DIR}/${ARCH}/${SOC_PATH}/include |
Anas Nashif | c8080d8 | 2022-07-21 10:22:13 -0400 | [diff] [blame] | 121 | ${SOC_DIR}/${ARCH}/${SOC_PATH}/include/${SOC_NAME} |
Sebastian Bøe | 4036339 | 2019-01-25 10:14:13 +0100 | [diff] [blame] | 122 | ${SOC_DIR}/${ARCH}/${SOC_FAMILY}/include |
Andy Ross | 544a38e | 2020-06-25 17:42:51 -0700 | [diff] [blame] | 123 | ${SOC_DIR}/${ARCH}/${SOC_FAMILY}/common/include |
Sebastian Bøe | 4036339 | 2019-01-25 10:14:13 +0100 | [diff] [blame] | 124 | ) |
| 125 | if(EXISTS ${optional_include_dir}) |
| 126 | zephyr_include_directories(${optional_include_dir}) |
| 127 | endif() |
| 128 | endforeach() |
| 129 | |
Torsten Rasmussen | 9a12f8b | 2022-08-22 16:45:23 +0200 | [diff] [blame] | 130 | # Don't inherit compiler flags from the environment |
| 131 | foreach(var AFLAGS CFLAGS CXXFLAGS CPPFLAGS LDFLAGS) |
| 132 | if(DEFINED ENV{${var}}) |
| 133 | message(WARNING "The environment variable '${var}' was set to $ENV{${var}}, " |
| 134 | "but Zephyr ignores flags from the environment. Use 'cmake " |
| 135 | "-DEXTRA_${var}=$ENV{${var}}' instead." |
| 136 | ) |
| 137 | unset(ENV{${var}}) |
| 138 | endif() |
| 139 | endforeach() |
| 140 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 141 | zephyr_compile_definitions( |
| 142 | KERNEL |
| 143 | __ZEPHYR__=1 |
Anas Nashif | 34aebad | 2018-01-03 12:26:19 -0500 | [diff] [blame] | 144 | ) |
| 145 | |
Yuval Peress | 53ef68d | 2022-03-29 13:52:59 -0600 | [diff] [blame] | 146 | # Ensure that include/zephyr/toolchain.h includes toolchain/other.h for all off-tree toolchains |
Danny Oerndrup | 94202f3 | 2021-07-16 11:50:40 +0200 | [diff] [blame] | 147 | if(TOOLCHAIN_USE_CUSTOM) |
| 148 | zephyr_compile_definitions(__TOOLCHAIN_CUSTOM__) |
| 149 | endif() |
| 150 | |
Stephanos Ioannidis | 9672858 | 2022-08-11 03:06:46 +0900 | [diff] [blame] | 151 | # @Intent: Set compiler specific flag for disabling strict aliasing rule |
| 152 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_strict_aliasing>>) |
| 153 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,no_strict_aliasing>>) |
| 154 | |
Nikolay Agishev | 0dec4cf | 2022-12-22 15:46:04 +0400 | [diff] [blame] | 155 | # Extra warnings options for twister run |
| 156 | if (CONFIG_COMPILER_WARNINGS_AS_ERRORS) |
| 157 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warnings_as_errors>>) |
| 158 | zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,warnings_as_errors>>) |
| 159 | zephyr_link_libraries($<TARGET_PROPERTY:linker,warnings_as_errors>) |
| 160 | endif() |
| 161 | |
Mark Ruvald Pedersen | 0159207 | 2019-01-10 12:07:51 +0100 | [diff] [blame] | 162 | # @Intent: Set compiler flags to enable buffer overflow checks in libc functions |
Keith Packard | 62bc9bf | 2022-04-26 19:24:11 -0700 | [diff] [blame] | 163 | # @details: |
| 164 | # Kconfig.zephyr "Detect buffer overflows in libc calls" is a kconfig choice, |
| 165 | # ensuring at most *one* of CONFIG_FORTIFY_SOURCE_{COMPILE_TIME,RUN_TIME} is |
| 166 | # set. Refer to Kconfig.zephyr for selection logic and description of these |
| 167 | # choices. Toolchains set both of the security_fortify_{compile_time,run_time} |
| 168 | # properties and the Kconfig settings are used here to select between those. |
| 169 | # |
| 170 | if(CONFIG_FORTIFY_SOURCE_RUN_TIME) |
| 171 | zephyr_compile_definitions($<TARGET_PROPERTY:compiler,security_fortify_run_time> ) |
| 172 | elseif(CONFIG_FORTIFY_SOURCE_COMPILE_TIME) |
| 173 | zephyr_compile_definitions($<TARGET_PROPERTY:compiler,security_fortify_compile_time> ) |
| 174 | endif() |
Mark Ruvald Pedersen | 0159207 | 2019-01-10 12:07:51 +0100 | [diff] [blame] | 175 | |
| 176 | # @Intent: Set compiler flags to detect general stack overflows across all functions |
| 177 | if(CONFIG_STACK_CANARIES) |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 178 | zephyr_compile_options($<TARGET_PROPERTY:compiler,security_canaries>) |
Anas Nashif | 34aebad | 2018-01-03 12:26:19 -0500 | [diff] [blame] | 179 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 180 | |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 181 | # @Intent: Obtain compiler optimizations flags and store in variables |
| 182 | # @details: |
| 183 | # Kconfig.zephyr "Optimization level" is a kconfig choice, ensuring |
| 184 | # only *one* of CONFIG_{NO,DEBUG,SPEED,SIZE}_OPTIMIZATIONS is set. |
| 185 | # Refer to Kconfig.zephyr for selection logic and description of these choices. |
| 186 | # toolchain_cc_optimize_*() macros must provide the mapping from these kconfigs |
| 187 | # to compiler flags. Each macro will store the flags in a CMake variable, whose |
| 188 | # name is passed as argument (somewhat like by reference). |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 189 | # |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 190 | # If the user wants to tweak the optimizations, there are two ways: |
| 191 | # 1) Using EXTRA_CFLAGS which is applied regardless of kconfig choice, or |
| 192 | # 2) Rely on override support being implemented by your toolchain_cc_optimize_*() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 193 | # |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 194 | get_property(OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG TARGET compiler PROPERTY no_optimization) |
| 195 | get_property(OPTIMIZE_FOR_DEBUG_FLAG TARGET compiler PROPERTY optimization_debug) |
| 196 | get_property(OPTIMIZE_FOR_SPEED_FLAG TARGET compiler PROPERTY optimization_speed) |
| 197 | get_property(OPTIMIZE_FOR_SIZE_FLAG TARGET compiler PROPERTY optimization_size) |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 198 | |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 199 | # From kconfig choice, pick the actual OPTIMIZATION_FLAG to use. |
| 200 | # Kconfig choice ensures only one of these CONFIG_*_OPTIMIZATIONS is set. |
Alberto Escolar Piedras | f60527a | 2018-01-22 15:35:54 +0100 | [diff] [blame] | 201 | if(CONFIG_NO_OPTIMIZATIONS) |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 202 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG}) |
| 203 | elseif(CONFIG_DEBUG_OPTIMIZATIONS) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 204 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_DEBUG_FLAG}) |
Aurelien Jarno | e8413d1 | 2018-06-16 23:40:04 +0200 | [diff] [blame] | 205 | elseif(CONFIG_SPEED_OPTIMIZATIONS) |
| 206 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SPEED_FLAG}) |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 207 | elseif(CONFIG_SIZE_OPTIMIZATIONS) |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 208 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SIZE_FLAG}) # Default in kconfig |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 209 | else() |
Anas Nashif | 885aaf2 | 2019-01-18 19:15:19 -0500 | [diff] [blame] | 210 | assert(0 "Unreachable code. Expected optimization level to have been chosen. See Kconfig.zephyr") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 211 | endif() |
| 212 | |
Ulf Magnusson | de42aea | 2020-02-07 00:48:22 +0100 | [diff] [blame] | 213 | if(NOT CONFIG_ARCH_IS_SET) |
| 214 | message(WARNING "\ |
| 215 | None of the CONFIG_<arch> (e.g. CONFIG_X86) symbols are set. \ |
| 216 | Select one of them from the SOC_SERIES_* symbol or, lacking that, from the \ |
| 217 | SOC_* symbol.") |
| 218 | endif() |
| 219 | |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 220 | # Apply the final optimization flag(s) |
| 221 | zephyr_compile_options(${OPTIMIZATION_FLAG}) |
| 222 | |
Mark Ruvald Pedersen | 63df409 | 2019-02-18 23:54:30 +0100 | [diff] [blame] | 223 | # @Intent: Obtain compiler specific flags related to C++ that are not influenced by kconfig |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 224 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,required>>) |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 225 | |
Mark Ruvald Pedersen | 63df409 | 2019-02-18 23:54:30 +0100 | [diff] [blame] | 226 | # @Intent: Obtain compiler specific flags for compiling under different ISO standards of C++ |
Stephanos Ioannidis | 4a64bfe | 2022-12-09 06:16:44 +0900 | [diff] [blame] | 227 | if(CONFIG_CPP) |
Ulf Magnusson | 9b6c2f4 | 2019-05-15 23:01:58 +0200 | [diff] [blame] | 228 | # From kconfig choice, pick a single dialect. |
| 229 | # Kconfig choice ensures only one of these CONFIG_STD_CPP* is set. |
| 230 | if(CONFIG_STD_CPP98) |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 231 | set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp98>) |
Torsten Rasmussen | 917d502 | 2021-09-30 21:01:57 +0200 | [diff] [blame] | 232 | list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp98}) |
Ulf Magnusson | 9b6c2f4 | 2019-05-15 23:01:58 +0200 | [diff] [blame] | 233 | elseif(CONFIG_STD_CPP11) |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 234 | set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp11>) # Default in kconfig |
Torsten Rasmussen | 917d502 | 2021-09-30 21:01:57 +0200 | [diff] [blame] | 235 | list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp11}) |
Ulf Magnusson | 9b6c2f4 | 2019-05-15 23:01:58 +0200 | [diff] [blame] | 236 | elseif(CONFIG_STD_CPP14) |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 237 | set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp14>) |
Torsten Rasmussen | 917d502 | 2021-09-30 21:01:57 +0200 | [diff] [blame] | 238 | list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp14}) |
Ulf Magnusson | 9b6c2f4 | 2019-05-15 23:01:58 +0200 | [diff] [blame] | 239 | elseif(CONFIG_STD_CPP17) |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 240 | set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp17>) |
Torsten Rasmussen | 917d502 | 2021-09-30 21:01:57 +0200 | [diff] [blame] | 241 | list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp17}) |
Alexander Wachter | ad130f2 | 2021-07-14 10:50:21 +0200 | [diff] [blame] | 242 | elseif(CONFIG_STD_CPP2A) |
| 243 | set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp2a>) |
Torsten Rasmussen | 917d502 | 2021-09-30 21:01:57 +0200 | [diff] [blame] | 244 | list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp20}) |
Dan Kalowsky | c0811e9 | 2021-07-09 10:46:46 -0700 | [diff] [blame] | 245 | elseif(CONFIG_STD_CPP20) |
| 246 | set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp20>) |
Torsten Rasmussen | 917d502 | 2021-09-30 21:01:57 +0200 | [diff] [blame] | 247 | list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp20}) |
Dan Kalowsky | 9b33391 | 2021-07-09 10:54:11 -0700 | [diff] [blame] | 248 | elseif(CONFIG_STD_CPP2B) |
| 249 | set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp2b>) |
Torsten Rasmussen | 917d502 | 2021-09-30 21:01:57 +0200 | [diff] [blame] | 250 | list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp20}) |
Ulf Magnusson | 9b6c2f4 | 2019-05-15 23:01:58 +0200 | [diff] [blame] | 251 | else() |
| 252 | assert(0 "Unreachable code. Expected C++ standard to have been chosen. See Kconfig.zephyr.") |
| 253 | endif() |
Torsten Rasmussen | 917d502 | 2021-09-30 21:01:57 +0200 | [diff] [blame] | 254 | set(CMAKE_CXX_COMPILE_FEATURES ${CMAKE_CXX_COMPILE_FEATURES} PARENT_SCOPE) |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 255 | |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 256 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:${STD_CPP_DIALECT_FLAGS}>) |
Ulf Magnusson | 9b6c2f4 | 2019-05-15 23:01:58 +0200 | [diff] [blame] | 257 | endif() |
Mark Ruvald Pedersen | 63df409 | 2019-02-18 23:54:30 +0100 | [diff] [blame] | 258 | |
Stephanos Ioannidis | 404e7a9 | 2022-12-09 19:43:43 +0900 | [diff] [blame] | 259 | if(NOT CONFIG_CPP_EXCEPTIONS) |
Mark Ruvald Pedersen | 63df409 | 2019-02-18 23:54:30 +0100 | [diff] [blame] | 260 | # @Intent: Obtain compiler specific flags related to C++ Exceptions |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 261 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,no_exceptions>>) |
Mark Ruvald Pedersen | 63df409 | 2019-02-18 23:54:30 +0100 | [diff] [blame] | 262 | endif() |
| 263 | |
Stephanos Ioannidis | a3b28ff | 2022-12-09 20:06:15 +0900 | [diff] [blame] | 264 | if(NOT CONFIG_CPP_RTTI) |
Mark Ruvald Pedersen | 63df409 | 2019-02-18 23:54:30 +0100 | [diff] [blame] | 265 | # @Intent: Obtain compiler specific flags related to C++ Run Time Type Information |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 266 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,no_rtti>>) |
Mark Ruvald Pedersen | 63df409 | 2019-02-18 23:54:30 +0100 | [diff] [blame] | 267 | endif() |
| 268 | |
Andy Ross | fe04adf | 2019-02-27 11:53:18 -0800 | [diff] [blame] | 269 | if(CONFIG_MISRA_SANE) |
Danny Oerndrup | 8e5a95e | 2019-05-16 12:53:58 +0200 | [diff] [blame] | 270 | # @Intent: Obtain toolchain compiler flags relating to MISRA. |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 271 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_error_misra_sane>>) |
| 272 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_error_misra_sane>>) |
Andy Ross | fe04adf | 2019-02-27 11:53:18 -0800 | [diff] [blame] | 273 | endif() |
| 274 | |
Flavio Ceolin | b587e8d | 2020-08-26 09:48:33 -0700 | [diff] [blame] | 275 | # This is intend to be temporary. Once we have fixed the violations that |
| 276 | # prevents build Zephyr, these flags shall be part of the default flags. |
| 277 | if(CONFIG_CODING_GUIDELINE_CHECK) |
| 278 | # @Intent: Obtain toolchain compiler flags relating to coding guideline |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 279 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_error_coding_guideline>>) |
Flavio Ceolin | b587e8d | 2020-08-26 09:48:33 -0700 | [diff] [blame] | 280 | endif() |
| 281 | |
Danny Oerndrup | 4ddbc00 | 2019-06-11 13:55:53 +0200 | [diff] [blame] | 282 | # @Intent: Set compiler specific macro inclusion of AUTOCONF_H |
Torsten Rasmussen | f109e68 | 2020-08-13 15:49:46 +0200 | [diff] [blame] | 283 | zephyr_compile_options("SHELL: $<TARGET_PROPERTY:compiler,imacros> ${AUTOCONF_H}") |
Danny Oerndrup | 4ddbc00 | 2019-06-11 13:55:53 +0200 | [diff] [blame] | 284 | |
Keith Packard | 6c5d806 | 2023-02-08 14:56:50 -0800 | [diff] [blame] | 285 | if(CONFIG_COMPILER_FREESTANDING) |
Keith Packard | d0c75f3 | 2020-10-26 19:07:50 -0700 | [diff] [blame] | 286 | # @Intent: Set compiler specific flag for bare metal freestanding option |
Jaroslaw Stelter | 69913ad | 2022-07-04 17:22:18 +0200 | [diff] [blame] | 287 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,freestanding>>) |
| 288 | zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:compiler,freestanding>>) |
Keith Packard | d0c75f3 | 2020-10-26 19:07:50 -0700 | [diff] [blame] | 289 | endif() |
Danny Oerndrup | faa72b7 | 2019-06-11 15:56:57 +0200 | [diff] [blame] | 290 | |
Keith Packard | b3073f0 | 2022-10-13 15:04:00 -0700 | [diff] [blame] | 291 | if (CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_IO_FLOAT) |
| 292 | # @Intent: Set compiler specific flag to disable printf-related optimizations |
| 293 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_printf_return_value>>) |
| 294 | endif() |
| 295 | |
Danny Oerndrup | e34ed7c | 2019-06-12 14:56:46 +0200 | [diff] [blame] | 296 | # @Intent: Set compiler specific flag for tentative definitions, no-common |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 297 | zephyr_compile_options($<TARGET_PROPERTY:compiler,no_common>) |
Danny Oerndrup | e34ed7c | 2019-06-12 14:56:46 +0200 | [diff] [blame] | 298 | |
Danny Oerndrup | e0569ac | 2019-07-23 09:00:55 +0200 | [diff] [blame] | 299 | # @Intent: Set compiler specific flag for production of debug information |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 300 | zephyr_compile_options($<TARGET_PROPERTY:compiler,debug>) |
Danny Oerndrup | e0569ac | 2019-07-23 09:00:55 +0200 | [diff] [blame] | 301 | |
Fabio Baltieri | 3f8f713 | 2023-03-29 10:11:46 +0100 | [diff] [blame] | 302 | if(CONFIG_COMPILER_SAVE_TEMPS) |
| 303 | # @Intent: Set compiler specific flag for saving temporary object files |
| 304 | zephyr_compile_options($<TARGET_PROPERTY:compiler,save_temps>) |
| 305 | endif() |
| 306 | |
Gerard Marull-Paretas | 99ebe39 | 2023-05-05 09:58:12 +0200 | [diff] [blame] | 307 | if(NOT CONFIG_COMPILER_TRACK_MACRO_EXPANSION) |
| 308 | # @Intent: Set compiler specific flags to not track macro expansion |
| 309 | zephyr_compile_options($<TARGET_PROPERTY:compiler,no_track_macro_expansion>) |
| 310 | endif() |
| 311 | |
Arvin Farahmand | e430b7b | 2021-04-15 11:20:10 -0400 | [diff] [blame] | 312 | if(CONFIG_COMPILER_COLOR_DIAGNOSTICS) |
Arvin Farahmand | b8f5968 | 2021-04-15 11:20:10 -0400 | [diff] [blame] | 313 | # @Intent: Set compiler specific flag for diagnostic messages |
| 314 | zephyr_compile_options($<TARGET_PROPERTY:compiler,diagnostic>) |
| 315 | endif() |
| 316 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 317 | zephyr_compile_options( |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 318 | ${TOOLCHAIN_C_FLAGS} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 319 | ) |
| 320 | |
Mark Ruvald Pedersen | cb0fd45 | 2019-01-30 21:48:25 +0100 | [diff] [blame] | 321 | # @Intent: Obtain compiler specific flags related to assembly |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 322 | # ToDo: Remember to get feedback from Oticon on this, as they might use the `ASM_BASE_FLAG` since this is done this way. |
| 323 | zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,required>>) |
Mark Ruvald Pedersen | cb0fd45 | 2019-01-30 21:48:25 +0100 | [diff] [blame] | 324 | |
Nazar Kazakov | f483b1b | 2022-03-16 21:07:43 +0000 | [diff] [blame] | 325 | # @Intent: Enforce standard integer type correspondence to match Zephyr usage. |
Nicolas Pitre | b86aa65 | 2019-07-02 16:22:04 -0400 | [diff] [blame] | 326 | # (must be after compiler specific flags) |
Nicolas Pitre | 0a386db | 2022-06-20 13:18:14 -0400 | [diff] [blame] | 327 | if(CONFIG_ENFORCE_ZEPHYR_STDINT) |
Yuval Peress | 53ef68d | 2022-03-29 13:52:59 -0600 | [diff] [blame] | 328 | zephyr_compile_options("SHELL: $<TARGET_PROPERTY:compiler,imacros> ${ZEPHYR_BASE}/include/zephyr/toolchain/zephyr_stdint.h") |
Stephanos Ioannidis | a1a6619 | 2021-09-12 19:33:15 +0900 | [diff] [blame] | 329 | endif() |
Nicolas Pitre | b86aa65 | 2019-07-02 16:22:04 -0400 | [diff] [blame] | 330 | |
Mark Ruvald Pedersen | cb0fd45 | 2019-01-30 21:48:25 +0100 | [diff] [blame] | 331 | # Common toolchain-agnostic assembly flags |
| 332 | zephyr_compile_options( |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 333 | $<$<COMPILE_LANGUAGE:ASM>:-D_ASMLANGUAGE> |
| 334 | ) |
| 335 | |
Mark Ruvald Pedersen | 1f01325 | 2019-04-25 15:46:11 +0200 | [diff] [blame] | 336 | # @Intent: Set fundamental linker specific flags |
| 337 | toolchain_ld_base() |
Aurelien Jarno | c6727d4 | 2018-11-26 13:48:34 +0100 | [diff] [blame] | 338 | |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 339 | toolchain_ld_force_undefined_symbols( |
| 340 | _OffsetAbsSyms |
| 341 | _ConfigAbsSyms |
| 342 | ) |
| 343 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 344 | if(NOT CONFIG_NATIVE_APPLICATION) |
Mark Ruvald Pedersen | 65f02c0 | 2019-04-25 16:31:30 +0200 | [diff] [blame] | 345 | # @Intent: Set linker specific flags for bare metal target |
| 346 | toolchain_ld_baremetal() |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 347 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 348 | |
Stephanos Ioannidis | a9b35f0 | 2023-01-17 01:53:59 +0900 | [diff] [blame] | 349 | if(CONFIG_CPP AND NOT CONFIG_MINIMAL_LIBCPP) |
Mark Ruvald Pedersen | 3db09aa | 2019-04-26 08:43:04 +0200 | [diff] [blame] | 350 | # @Intent: Set linker specific flags for C++ |
| 351 | toolchain_ld_cpp() |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 352 | endif() |
| 353 | |
Danny Oerndrup | 8eaa906 | 2019-05-16 12:49:31 +0200 | [diff] [blame] | 354 | # @Intent: Add the basic toolchain warning flags |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 355 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_base>>) |
| 356 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_base>>) |
Danny Oerndrup | bdb229f | 2019-05-06 15:19:27 +0200 | [diff] [blame] | 357 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 358 | # ========================================================================== |
| 359 | # |
| 360 | # cmake -DW=... settings |
| 361 | # |
| 362 | # W=1 - warnings that may be relevant and does not occur too often |
| 363 | # W=2 - warnings that occur quite often but may still be relevant |
| 364 | # W=3 - the more obscure warnings, can most likely be ignored |
| 365 | # ========================================================================== |
Danny Oerndrup | 8eaa906 | 2019-05-16 12:49:31 +0200 | [diff] [blame] | 366 | # @Intent: Add cmake -DW toolchain supported warnings, if any |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 367 | if(W MATCHES "1") |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 368 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_dw_1>>) |
| 369 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_dw_1>>) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 370 | endif() |
| 371 | |
| 372 | if(W MATCHES "2") |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 373 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_dw_2>>) |
| 374 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_dw_2>>) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 375 | endif() |
| 376 | |
| 377 | if(W MATCHES "3") |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 378 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_dw_3>>) |
| 379 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_dw_3>>) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 380 | endif() |
| 381 | |
Danny Oerndrup | 8eaa906 | 2019-05-16 12:49:31 +0200 | [diff] [blame] | 382 | # @Intent: Add extended, more specific, toolchain warning flags |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 383 | zephyr_compile_options($<TARGET_PROPERTY:compiler,warning_extended>) |
Benoit Leforestier | 04dad59 | 2019-01-25 13:57:03 +0100 | [diff] [blame] | 384 | |
Danny Oerndrup | 025ffa2 | 2019-05-16 12:58:40 +0200 | [diff] [blame] | 385 | # @Intent: Trigger an error when a declaration does not specify a type |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 386 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warning_error_implicit_int>>) |
| 387 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,warning_error_implicit_int>>) |
Danny Oerndrup | 025ffa2 | 2019-05-16 12:58:40 +0200 | [diff] [blame] | 388 | |
Flavio Ceolin | 8259931 | 2022-08-22 08:47:03 -0700 | [diff] [blame] | 389 | # @Intent: Do not make position independent code / executable |
| 390 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_position_independent>>) |
Alberto Escolar Piedras | 01348d3 | 2023-05-04 13:43:41 +0200 | [diff] [blame] | 391 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,no_position_independent>>) |
Daniel Leung | 81c3b31 | 2023-02-24 17:39:07 -0800 | [diff] [blame] | 392 | zephyr_link_libraries($<TARGET_PROPERTY:linker,no_position_independent>) |
Flavio Ceolin | 8259931 | 2022-08-22 08:47:03 -0700 | [diff] [blame] | 393 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 394 | # Allow the user to inject options when calling cmake, e.g. |
| 395 | # 'cmake -DEXTRA_CFLAGS="-Werror -Wno-deprecated-declarations" ..' |
Sebastian Bøe | 9f59045 | 2017-11-10 12:22:23 +0100 | [diff] [blame] | 396 | include(cmake/extra_flags.cmake) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 397 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 398 | zephyr_cc_option(-fno-asynchronous-unwind-tables) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 399 | |
Flavio Ceolin | ac5d45a | 2023-01-22 12:47:36 -0800 | [diff] [blame] | 400 | if(CONFIG_USERSPACE) |
| 401 | zephyr_compile_options($<TARGET_PROPERTY:compiler,no_global_merge>) |
| 402 | endif() |
| 403 | |
Daniel Leung | 02b2035 | 2020-09-28 11:27:11 -0700 | [diff] [blame] | 404 | if(CONFIG_THREAD_LOCAL_STORAGE) |
| 405 | # Only support local exec TLS model at this point. |
| 406 | zephyr_cc_option(-ftls-model=local-exec) |
| 407 | endif() |
| 408 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 409 | if(CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT) |
| 410 | if(CONFIG_OMIT_FRAME_POINTER) |
| 411 | zephyr_cc_option(-fomit-frame-pointer) |
| 412 | else() |
| 413 | zephyr_cc_option(-fno-omit-frame-pointer) |
| 414 | endif() |
| 415 | endif() |
| 416 | |
Sebastian Bøe | 244451b | 2019-02-27 08:28:25 +0100 | [diff] [blame] | 417 | separate_arguments(COMPILER_OPT_AS_LIST UNIX_COMMAND ${CONFIG_COMPILER_OPT}) |
| 418 | zephyr_compile_options(${COMPILER_OPT_AS_LIST}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 419 | |
| 420 | # TODO: Include arch compiler options at this point. |
| 421 | |
Kumar Gala | 2d12766 | 2023-01-20 23:21:23 +0000 | [diff] [blame] | 422 | if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" AND |
Kumar Gala | 9f8913c | 2023-03-16 14:58:27 +0000 | [diff] [blame] | 423 | NOT CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM" AND |
| 424 | NOT CMAKE_C_COMPILER_ID STREQUAL "ARMClang") |
Danny Oerndrup | cbbbdea | 2019-05-06 15:21:58 +0200 | [diff] [blame] | 425 | # GCC assumed |
| 426 | zephyr_cc_option(-fno-reorder-functions) |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 427 | |
Stephanos Ioannidis | 5af932f | 2022-08-15 22:44:06 +0900 | [diff] [blame] | 428 | # GCC 11 and above may generate a warning when dereferencing a constant |
| 429 | # address pointer whose address is below the value specified by the |
| 430 | # `min-pagesize` parameter (defaults to 0x1000). The `min-pagesize` parameter |
| 431 | # is set to 0 such that GCC never generates any warnings for the constant |
| 432 | # address pointers. For more details, refer to the GCC PR99578. |
| 433 | zephyr_cc_option(--param=min-pagesize=0) |
| 434 | |
Anas Nashif | 7ee8bb9 | 2018-02-11 14:36:21 -0600 | [diff] [blame] | 435 | if(NOT ${ZEPHYR_TOOLCHAIN_VARIANT} STREQUAL "xcc") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 436 | zephyr_cc_option(-fno-defer-pop) |
| 437 | endif() |
Nicolas Pitre | f005735 | 2022-04-06 13:36:40 -0400 | [diff] [blame] | 438 | else() |
| 439 | # Clang produces false positive vla warnings |
| 440 | zephyr_cc_option(-Wno-vla) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 441 | endif() |
| 442 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 443 | zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage) |
| 444 | |
Marc Herbert | 28a5657 | 2019-04-11 16:34:04 -0700 | [diff] [blame] | 445 | # If the compiler supports it, strip the ${ZEPHYR_BASE} prefix from the |
| 446 | # __FILE__ macro used in __ASSERT*, in the |
| 447 | # .noinit."/home/joe/zephyr/fu/bar.c" section names and in any |
| 448 | # application code. This saves some memory, stops leaking user locations |
| 449 | # in binaries, makes failure logs more deterministic and most |
| 450 | # importantly makes builds more deterministic |
Martin Jäger | a0ffaa7 | 2023-03-29 16:06:30 +0200 | [diff] [blame] | 451 | if(CONFIG_BUILD_OUTPUT_STRIP_PATHS) |
| 452 | # If several match then the last one wins. This matters for instances |
| 453 | # like tests/ and samples/: they're inside all of them! Then let's |
| 454 | # strip as little as possible. |
| 455 | zephyr_cc_option(-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=CMAKE_SOURCE_DIR) |
| 456 | zephyr_cc_option(-fmacro-prefix-map=${ZEPHYR_BASE}=ZEPHYR_BASE) |
| 457 | if(WEST_TOPDIR) |
| 458 | zephyr_cc_option(-fmacro-prefix-map=${WEST_TOPDIR}=WEST_TOPDIR) |
| 459 | endif() |
Marc Herbert | eddbf3c | 2019-06-11 16:57:37 -0700 | [diff] [blame] | 460 | endif() |
Marc Herbert | 28a5657 | 2019-04-11 16:34:04 -0700 | [diff] [blame] | 461 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 462 | # TODO: Archiver arguments |
| 463 | # ar_option(D) |
| 464 | |
Håkon Øye Amundsen | d6551b5 | 2018-11-29 09:08:08 +0000 | [diff] [blame] | 465 | # Declare MPU userspace dependencies before the linker scripts to make |
| 466 | # sure the order of dependencies are met |
Andrew Boie | 41f6011 | 2019-01-31 15:53:24 -0800 | [diff] [blame] | 467 | if(CONFIG_USERSPACE) |
Daniel Leung | 2117a2a | 2021-07-12 13:33:32 -0700 | [diff] [blame] | 468 | add_custom_target(app_smem) |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 469 | set(APP_SMEM_ALIGNED_DEP app_smem_aligned_linker) |
| 470 | set(APP_SMEM_UNALIGNED_DEP app_smem_unaligned_linker) |
Håkon Øye Amundsen | d6551b5 | 2018-11-29 09:08:08 +0000 | [diff] [blame] | 471 | endif() |
| 472 | |
Daniel Leung | 1117169 | 2021-03-18 14:00:07 -0700 | [diff] [blame] | 473 | if(CONFIG_USERSPACE) |
| 474 | set(KOBJECT_LINKER_DEP kobject_linker) |
| 475 | endif() |
| 476 | |
Håkon Øye Amundsen | a449439 | 2018-11-29 09:14:27 +0000 | [diff] [blame] | 477 | get_property(TOPT GLOBAL PROPERTY TOPT) |
Oleg Zhurakivskyy | 2211935 | 2019-03-08 11:29:33 +0200 | [diff] [blame] | 478 | set_ifndef( TOPT -Wl,-T) # clang doesn't pick -T for some reason and complains, |
| 479 | # while -Wl,-T works for both, gcc and clang |
Håkon Øye Amundsen | a449439 | 2018-11-29 09:14:27 +0000 | [diff] [blame] | 480 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 481 | if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT) |
| 482 | set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT}) |
Sebastian Bøe | c1aa9d1 | 2018-04-12 14:48:05 +0200 | [diff] [blame] | 483 | if(NOT EXISTS ${LINKER_SCRIPT}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 484 | set(LINKER_SCRIPT ${CONFIG_CUSTOM_LINKER_SCRIPT}) |
Sebastian Bøe | c1aa9d1 | 2018-04-12 14:48:05 +0200 | [diff] [blame] | 485 | assert_exists(CONFIG_CUSTOM_LINKER_SCRIPT) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 486 | endif() |
| 487 | else() |
| 488 | # Try a board specific linker file |
| 489 | set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld) |
| 490 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 491 | # If not available, try an SoC specific linker file |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 492 | set(LINKER_SCRIPT ${SOC_DIR}/${ARCH}/${SOC_PATH}/linker.ld) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 493 | endif() |
| 494 | endif() |
| 495 | |
| 496 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 497 | message(FATAL_ERROR "Could not find linker script: '${LINKER_SCRIPT}'. Corrupted configuration?") |
| 498 | endif() |
| 499 | |
Torsten Rasmussen | 9170977 | 2022-02-04 10:27:13 +0100 | [diff] [blame] | 500 | if(DEFINED BUILD_VERSION) |
| 501 | set(build_version_argument "-DBUILD_VERSION=${BUILD_VERSION}") |
Frank Terbeck | a85a76d | 2022-03-08 20:09:51 +0100 | [diff] [blame] | 502 | elseif(NOT ZEPHYR_GIT_INDEX) |
| 503 | set(ZEPHYR_GIT_INDEX ZEPHYR_GIT_INDEX-NOTFOUND CACHE PATH |
| 504 | "Path to Zephyr git repository index file") |
| 505 | if(EXISTS ${ZEPHYR_BASE}/.git/index) |
| 506 | set(ZEPHYR_GIT_DIR ${ZEPHYR_BASE}/.git/index CACHE PATH |
| 507 | "Path to Zephyr git repository index file" FORCE) |
| 508 | elseif(EXISTS ${ZEPHYR_BASE}/.git) |
| 509 | # Likely a git-submodule. Let's ask git where the real database is located. |
| 510 | find_package(Git QUIET) |
| 511 | if(GIT_FOUND) |
| 512 | execute_process( |
| 513 | COMMAND ${GIT_EXECUTABLE} rev-parse --absolute-git-dir |
| 514 | WORKING_DIRECTORY ${ZEPHYR_BASE} |
| 515 | OUTPUT_VARIABLE zephyr_git_dir |
| 516 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 517 | ERROR_STRIP_TRAILING_WHITESPACE |
| 518 | ERROR_VARIABLE stderr |
| 519 | RESULT_VARIABLE return_code) |
| 520 | if(return_code) |
| 521 | message(WARNING "BUILD_VERSION: git rev-parse failed: ${stderr}") |
| 522 | else() |
| 523 | if(NOT "${stderr}" STREQUAL "") |
| 524 | message(WARNING "BUILD_VERSION: git rev-parse warned: ${stderr}") |
| 525 | endif() |
| 526 | set(ZEPHYR_GIT_INDEX ${zephyr_git_dir}/index CACHE PATH |
| 527 | "Path to Zephyr git repository index file" FORCE) |
| 528 | endif() |
| 529 | else() |
| 530 | message(WARNING "Could not find git installation, " |
| 531 | "please specify '-DBUILD_VERSION=<version>'") |
| 532 | endif() |
| 533 | else() |
| 534 | message(WARNING "ZEPHYR_BASE=${ZEPHYR_BASE} doesn't appear to be a git " |
| 535 | "repository, please specify '-DBUILD_VERSION=<version>'") |
| 536 | endif() |
Torsten Rasmussen | 9170977 | 2022-02-04 10:27:13 +0100 | [diff] [blame] | 537 | endif() |
Frank Terbeck | a85a76d | 2022-03-08 20:09:51 +0100 | [diff] [blame] | 538 | |
| 539 | if(ZEPHYR_GIT_INDEX) |
| 540 | set(git_dependency ${ZEPHYR_GIT_INDEX}) |
| 541 | endif() |
| 542 | |
Torsten Rasmussen | 9170977 | 2022-02-04 10:27:13 +0100 | [diff] [blame] | 543 | add_custom_command( |
| 544 | OUTPUT ${PROJECT_BINARY_DIR}/include/generated/version.h |
| 545 | COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} |
| 546 | -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/version.h |
Torsten Rasmussen | 2c757f9 | 2023-03-23 08:43:01 +0100 | [diff] [blame] | 547 | -DVERSION_TYPE=KERNEL |
| 548 | -DVERSION_FILE=${ZEPHYR_BASE}/VERSION |
Torsten Rasmussen | 9170977 | 2022-02-04 10:27:13 +0100 | [diff] [blame] | 549 | ${build_version_argument} |
| 550 | -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake |
| 551 | DEPENDS ${ZEPHYR_BASE}/VERSION ${git_dependency} |
| 552 | ) |
| 553 | add_custom_target(version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/version.h) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 554 | |
Torsten Rasmussen | 99064c2 | 2023-03-23 08:45:26 +0100 | [diff] [blame] | 555 | if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION) |
| 556 | add_custom_command( |
| 557 | OUTPUT ${PROJECT_BINARY_DIR}/include/generated/app_version.h |
| 558 | COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} |
| 559 | -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/app_version.h |
| 560 | -DVERSION_TYPE=APP |
| 561 | -DVERSION_FILE=${APPLICATION_SOURCE_DIR}/VERSION |
| 562 | ${build_version_argument} |
| 563 | -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake |
| 564 | DEPENDS ${APPLICATION_SOURCE_DIR}/VERSION ${git_dependency} |
| 565 | ) |
| 566 | add_custom_target(app_version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/app_version.h) |
| 567 | add_dependencies(zephyr_interface app_version_h) |
| 568 | endif() |
| 569 | |
Sebastian Bøe | 6f946e2 | 2018-01-09 10:52:57 +0100 | [diff] [blame] | 570 | # Unfortunately, the order in which CMakeLists.txt code is processed |
| 571 | # matters so we need to be careful about how we order the processing |
| 572 | # of subdirectories. One example is "Compiler flags added late in the |
| 573 | # build are not exported to external build systems #5605"; when we |
| 574 | # integrate with an external build system we read out all compiler |
| 575 | # flags when the external project is created. So an external project |
| 576 | # defined in subsys or ext will not get global flags added by drivers/ |
| 577 | # or tests/ as the subdirectories are ordered now. |
| 578 | # |
| 579 | # Another example of when the order matters is the reading and writing |
| 580 | # of global properties such as ZEPHYR_LIBS or |
| 581 | # GENERATED_KERNEL_OBJECT_FILES. |
| 582 | # |
| 583 | # Arch is placed early because it defines important compiler flags |
| 584 | # that must be exported to external build systems defined in |
| 585 | # e.g. subsys/. |
| 586 | add_subdirectory(arch) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 587 | add_subdirectory(lib) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 588 | # We use include instead of add_subdirectory to avoid creating a new directory scope. |
| 589 | # This is because source file properties are directory scoped, including the GENERATED |
| 590 | # property which is set implicitly for custom command outputs |
| 591 | include(misc/generated/CMakeLists.txt) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 592 | |
Erwan Gouriou | ba31cb5 | 2018-09-13 16:25:53 +0200 | [diff] [blame] | 593 | if(EXISTS ${SOC_DIR}/${ARCH}/CMakeLists.txt) |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 594 | add_subdirectory(${SOC_DIR}/${ARCH} soc/${ARCH}) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 595 | else() |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 596 | add_subdirectory(${SOC_DIR}/${ARCH}/${SOC_PATH} soc/${ARCH}/${SOC_PATH}) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 597 | endif() |
| 598 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 599 | add_subdirectory(boards) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 600 | add_subdirectory(subsys) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 601 | add_subdirectory(drivers) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 602 | |
Torsten Rasmussen | bd7569f | 2019-03-19 10:38:18 +0100 | [diff] [blame] | 603 | # Include zephyr modules generated CMake file. |
Torsten Rasmussen | 2fc062b | 2020-08-24 11:01:04 +0200 | [diff] [blame] | 604 | foreach(module_name ${ZEPHYR_MODULE_NAMES}) |
| 605 | # Note the second, binary_dir parameter requires the added |
| 606 | # subdirectory to have its own, local cmake target(s). If not then |
| 607 | # this binary_dir is created but stays empty. Object files land in |
| 608 | # the main binary dir instead. |
| 609 | # https://cmake.org/pipermail/cmake/2019-June/069547.html |
Torsten Rasmussen | 3d88083 | 2021-01-19 12:01:38 +0100 | [diff] [blame] | 610 | zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${module_name}) |
Torsten Rasmussen | ab7ec17 | 2020-08-25 13:32:33 +0200 | [diff] [blame] | 611 | if(NOT ${ZEPHYR_${MODULE_NAME_UPPER}_CMAKE_DIR} STREQUAL "") |
| 612 | set(ZEPHYR_CURRENT_MODULE_DIR ${ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR}) |
| 613 | set(ZEPHYR_CURRENT_CMAKE_DIR ${ZEPHYR_${MODULE_NAME_UPPER}_CMAKE_DIR}) |
| 614 | add_subdirectory(${ZEPHYR_CURRENT_CMAKE_DIR} ${CMAKE_BINARY_DIR}/modules/${module_name}) |
| 615 | endif() |
Torsten Rasmussen | 2fc062b | 2020-08-24 11:01:04 +0200 | [diff] [blame] | 616 | endforeach() |
Torsten Rasmussen | ab7ec17 | 2020-08-25 13:32:33 +0200 | [diff] [blame] | 617 | # Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR and ZEPHYR_CURRENT_CMAKE_DIR. |
Torsten Rasmussen | 2fc062b | 2020-08-24 11:01:04 +0200 | [diff] [blame] | 618 | set(ZEPHYR_CURRENT_MODULE_DIR) |
Torsten Rasmussen | ab7ec17 | 2020-08-25 13:32:33 +0200 | [diff] [blame] | 619 | set(ZEPHYR_CURRENT_CMAKE_DIR) |
Torsten Rasmussen | 7e9d1bd | 2019-02-05 10:36:22 +0100 | [diff] [blame] | 620 | |
Keith Packard | 87a3060 | 2022-11-02 14:49:23 -0700 | [diff] [blame] | 621 | get_property(LIBC_LINK_LIBRARIES TARGET zephyr_interface PROPERTY LIBC_LINK_LIBRARIES) |
| 622 | zephyr_link_libraries(${LIBC_LINK_LIBRARIES}) |
| 623 | |
Andrew Boie | 5960119 | 2020-05-29 13:24:51 -0700 | [diff] [blame] | 624 | set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h) |
| 625 | set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json) |
| 626 | set(struct_tags_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/struct_tags.json) |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 627 | |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 628 | # The syscalls subdirs txt file is constructed by python containing a list of folders to use for |
| 629 | # dependency handling, including empty folders. |
| 630 | # Windows: The list is used to specify DIRECTORY list with CMAKE_CONFIGURE_DEPENDS attribute. |
| 631 | # Other OS: The list will update whenever a file is added/removed/modified and ensure a re-build. |
| 632 | set(syscalls_subdirs_txt ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_subdirs.txt) |
| 633 | |
| 634 | # As syscalls_subdirs_txt is updated whenever a file is modified, this file can not be used for |
| 635 | # monitoring of added / removed folders. A trigger file is thus used for correct dependency |
| 636 | # handling. The trigger file will update when a folder is added / removed. |
| 637 | set(syscalls_subdirs_trigger ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_subdirs.trigger) |
| 638 | |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 639 | if(NOT (${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)) |
| 640 | set(syscalls_links --create-links ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_links) |
| 641 | endif() |
| 642 | |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 643 | # When running CMake it must be ensured that all dependencies are correctly acquired. |
| 644 | execute_process( |
| 645 | COMMAND |
| 646 | ${PYTHON_EXECUTABLE} |
Anas Nashif | 9ee1e32 | 2022-07-11 10:57:02 -0400 | [diff] [blame] | 647 | ${ZEPHYR_BASE}/scripts/build/subfolder_list.py |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 648 | --directory ${ZEPHYR_BASE}/include # Walk this directory |
| 649 | --out-file ${syscalls_subdirs_txt} # Write file with discovered folder |
Jamie McCrae | ec70444 | 2023-01-04 16:08:36 +0000 | [diff] [blame] | 650 | --trigger-file ${syscalls_subdirs_trigger} # Trigger file that is used for json generation |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 651 | ${syscalls_links} # If defined, create symlinks for dependencies |
| 652 | ) |
Carles Cufi | 3ad1f27 | 2019-07-18 10:38:25 +0200 | [diff] [blame] | 653 | file(STRINGS ${syscalls_subdirs_txt} PARSE_SYSCALLS_PATHS_DEPENDS ENCODING UTF-8) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 654 | |
| 655 | if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows) |
| 656 | # On windows only adding/removing files or folders will be reflected in depends. |
| 657 | # Hence adding a file requires CMake to re-run to add this file to the file list. |
| 658 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${PARSE_SYSCALLS_PATHS_DEPENDS}) |
| 659 | |
| 660 | # Also On Windows each header file must be monitored as file modifications are not reflected |
| 661 | # on directory level. |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 662 | file(GLOB_RECURSE PARSE_SYSCALLS_HEADER_DEPENDS ${ZEPHYR_BASE}/include/*.h) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 663 | else() |
| 664 | # The syscall parsing depends on the folders in order to detect add/removed/modified files. |
| 665 | # When a folder is removed, CMake will try to find a target that creates that dependency. |
| 666 | # This command sets up the target for CMake to find. |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 667 | # Without this code, CMake will fail with the following error: |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 668 | # <folder> needed by '<target>', missing and no known rule to make it |
| 669 | # when a folder is removed. |
| 670 | add_custom_command(OUTPUT ${PARSE_SYSCALLS_PATHS_DEPENDS} |
| 671 | COMMAND ${CMAKE_COMMAND} -E echo "" |
| 672 | COMMENT "Preparing syscall dependency handling" |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 673 | ) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 674 | |
| 675 | add_custom_command( |
| 676 | OUTPUT |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 677 | ${syscalls_subdirs_trigger} |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 678 | COMMAND |
| 679 | ${PYTHON_EXECUTABLE} |
Anas Nashif | 9ee1e32 | 2022-07-11 10:57:02 -0400 | [diff] [blame] | 680 | ${ZEPHYR_BASE}/scripts/build/subfolder_list.py |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 681 | --directory ${ZEPHYR_BASE}/include # Walk this directory |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 682 | --out-file ${syscalls_subdirs_txt} # Write file with discovered folder |
Jamie McCrae | ec70444 | 2023-01-04 16:08:36 +0000 | [diff] [blame] | 683 | --trigger-file ${syscalls_subdirs_trigger} # Trigger file that is used for json generation |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 684 | ${syscalls_links} # If defined, create symlinks for dependencies |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 685 | DEPENDS ${PARSE_SYSCALLS_PATHS_DEPENDS} |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 686 | ) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 687 | |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 688 | # Ensure subdir file always exists when specifying CMake dependency. |
| 689 | if(NOT EXISTS ${syscalls_subdirs_txt}) |
| 690 | file(WRITE ${syscalls_subdirs_txt} "") |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 691 | endif() |
| 692 | |
| 693 | # On other OS'es, modifying a file is reflected on the folder timestamp and hence detected |
| 694 | # when using depend on directory level. |
| 695 | # Thus CMake only needs to re-run when sub-directories are added / removed, which is indicated |
| 696 | # using a trigger file. |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 697 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${syscalls_subdirs_txt}) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 698 | endif() |
| 699 | |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 700 | # syscall declarations are searched for in the SYSCALL_INCLUDE_DIRS |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 701 | if(CONFIG_APPLICATION_DEFINED_SYSCALL) |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 702 | list(APPEND SYSCALL_INCLUDE_DIRS ${APPLICATION_SOURCE_DIR}) |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 703 | endif() |
| 704 | |
Andrew Boie | c186387 | 2019-11-21 23:11:29 -0800 | [diff] [blame] | 705 | if(CONFIG_ZTEST) |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 706 | list(APPEND SYSCALL_INCLUDE_DIRS ${ZEPHYR_BASE}/subsys/testsuite/ztest/include) |
Andrew Boie | c186387 | 2019-11-21 23:11:29 -0800 | [diff] [blame] | 707 | endif() |
| 708 | |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 709 | foreach(d ${SYSCALL_INCLUDE_DIRS}) |
| 710 | list(APPEND parse_syscalls_include_args |
| 711 | --include ${d} |
| 712 | ) |
| 713 | endforeach() |
| 714 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 715 | add_custom_command( |
| 716 | OUTPUT |
| 717 | ${syscalls_json} |
Andrew Boie | 5960119 | 2020-05-29 13:24:51 -0700 | [diff] [blame] | 718 | ${struct_tags_json} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 719 | COMMAND |
| 720 | ${PYTHON_EXECUTABLE} |
Anas Nashif | 92575fd | 2022-07-11 10:58:14 -0400 | [diff] [blame] | 721 | ${ZEPHYR_BASE}/scripts/build/parse_syscalls.py |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 722 | --include ${ZEPHYR_BASE}/include # Read files from this dir |
Andrew Boie | fed960b | 2020-05-29 13:33:12 -0700 | [diff] [blame] | 723 | --include ${ZEPHYR_BASE}/drivers # For net sockets |
| 724 | --include ${ZEPHYR_BASE}/subsys/net # More net sockets |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 725 | ${parse_syscalls_include_args} # Read files from these dirs also |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 726 | --json-file ${syscalls_json} # Write this file |
Andrew Boie | 5960119 | 2020-05-29 13:24:51 -0700 | [diff] [blame] | 727 | --tag-struct-file ${struct_tags_json} # Write subsystem list to this file |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 728 | DEPENDS ${syscalls_subdirs_trigger} ${PARSE_SYSCALLS_HEADER_DEPENDS} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 729 | ) |
| 730 | |
Keith Packard | d0c75f3 | 2020-10-26 19:07:50 -0700 | [diff] [blame] | 731 | # Make sure Picolibc is built before the rest of the system; there's no explicit |
| 732 | # reference to any of the files as they're all picked up by various compiler |
| 733 | # settings |
| 734 | if(CONFIG_PICOLIBC_USE_MODULE) |
| 735 | set(picolibc_dependency PicolibcBuild) |
| 736 | endif() |
| 737 | |
| 738 | add_custom_target(${SYSCALL_LIST_H_TARGET} DEPENDS ${syscall_list_h} ${picolibc_dependency}) |
Torsten Rasmussen | c4c79f5 | 2021-02-09 22:27:59 +0100 | [diff] [blame] | 739 | |
Torsten Rasmussen | c4c79f5 | 2021-02-09 22:27:59 +0100 | [diff] [blame] | 740 | set_property(TARGET ${SYSCALL_LIST_H_TARGET} |
| 741 | APPEND PROPERTY |
| 742 | ADDITIONAL_CLEAN_FILES |
| 743 | ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscalls |
| 744 | ) |
| 745 | |
Andrew Boie | c1c54b1 | 2020-03-16 12:48:00 -0700 | [diff] [blame] | 746 | add_custom_target(${PARSE_SYSCALLS_TARGET} |
Joakim Andersson | 08d2f48 | 2020-08-04 18:26:43 +0200 | [diff] [blame] | 747 | DEPENDS |
| 748 | ${syscalls_json} |
Joakim Andersson | d268f82 | 2020-08-04 18:31:48 +0200 | [diff] [blame] | 749 | ${struct_tags_json} |
Joakim Andersson | 08d2f48 | 2020-08-04 18:26:43 +0200 | [diff] [blame] | 750 | ) |
Andrew Boie | 9ff64bb | 2019-11-05 09:39:05 -0800 | [diff] [blame] | 751 | |
| 752 | # 64-bit systems do not require special handling of 64-bit system call |
| 753 | # parameters or return values, indicate this to the system call boilerplate |
| 754 | # generation script. |
| 755 | if(CONFIG_64BIT) |
| 756 | set(SYSCALL_LONG_REGISTERS_ARG --long-registers) |
| 757 | endif() |
| 758 | |
Andy Ross | cfeb07e | 2020-03-05 21:14:02 -0800 | [diff] [blame] | 759 | if(CONFIG_TIMEOUT_64BIT) |
Nicolas Pitre | 2cdac33 | 2022-03-04 21:21:38 -0500 | [diff] [blame] | 760 | set(SYSCALL_SPLIT_TIMEOUT_ARG --split-type k_timeout_t --split-type k_ticks_t) |
Andy Ross | cfeb07e | 2020-03-05 21:14:02 -0800 | [diff] [blame] | 761 | endif() |
| 762 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 763 | add_custom_command(OUTPUT include/generated/syscall_dispatch.c ${syscall_list_h} |
| 764 | # Also, some files are written to include/generated/syscalls/ |
| 765 | COMMAND |
| 766 | ${PYTHON_EXECUTABLE} |
Anas Nashif | c74d20e | 2022-07-11 10:54:14 -0400 | [diff] [blame] | 767 | ${ZEPHYR_BASE}/scripts/build/gen_syscalls.py |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 768 | --json-file ${syscalls_json} # Read this file |
| 769 | --base-output include/generated/syscalls # Write to this dir |
| 770 | --syscall-dispatch include/generated/syscall_dispatch.c # Write this file |
Andrew Boie | 353acf4 | 2018-07-23 18:10:15 -0700 | [diff] [blame] | 771 | --syscall-list ${syscall_list_h} |
Daniel Leung | 751de22 | 2023-03-10 14:07:59 -0800 | [diff] [blame] | 772 | $<$<BOOL:${CONFIG_USERSPACE}>:--gen-mrsh-files> |
Andrew Boie | 9ff64bb | 2019-11-05 09:39:05 -0800 | [diff] [blame] | 773 | ${SYSCALL_LONG_REGISTERS_ARG} |
Andy Ross | cfeb07e | 2020-03-05 21:14:02 -0800 | [diff] [blame] | 774 | ${SYSCALL_SPLIT_TIMEOUT_ARG} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 775 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
Andrew Boie | c1c54b1 | 2020-03-16 12:48:00 -0700 | [diff] [blame] | 776 | DEPENDS ${PARSE_SYSCALLS_TARGET} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 777 | ) |
| 778 | |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 779 | # This is passed into all calls to the gen_kobject_list.py script. |
Jamie McCrae | ec70444 | 2023-01-04 16:08:36 +0000 | [diff] [blame] | 780 | set(gen_kobject_list_include_args --include-subsystem-list ${struct_tags_json}) |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 781 | |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 782 | set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/driver-validation.h) |
| 783 | add_custom_command( |
| 784 | OUTPUT ${DRV_VALIDATION} |
| 785 | COMMAND |
| 786 | ${PYTHON_EXECUTABLE} |
Anas Nashif | efbadbb | 2022-07-11 10:53:29 -0400 | [diff] [blame] | 787 | ${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 788 | --validation-output ${DRV_VALIDATION} |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 789 | ${gen_kobject_list_include_args} |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 790 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 791 | DEPENDS |
Anas Nashif | efbadbb | 2022-07-11 10:53:29 -0400 | [diff] [blame] | 792 | ${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py |
Andrew Boie | c1c54b1 | 2020-03-16 12:48:00 -0700 | [diff] [blame] | 793 | ${PARSE_SYSCALLS_TARGET} |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 794 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 795 | ) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 796 | add_custom_target(${DRIVER_VALIDATION_H_TARGET} DEPENDS ${DRV_VALIDATION}) |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 797 | |
Torsten Rasmussen | d7862cf | 2020-02-12 15:42:09 +0100 | [diff] [blame] | 798 | include(${ZEPHYR_BASE}/cmake/kobj.cmake) |
Leandro Pereira | 39dc7d0 | 2018-04-05 13:59:33 -0700 | [diff] [blame] | 799 | gen_kobj(KOBJ_INCLUDE_PATH) |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 800 | |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 801 | # Add a pseudo-target that is up-to-date when all generated headers |
| 802 | # are up-to-date. |
| 803 | |
| 804 | add_custom_target(zephyr_generated_headers) |
| 805 | add_dependencies(zephyr_generated_headers |
Torsten Rasmussen | 9170977 | 2022-02-04 10:27:13 +0100 | [diff] [blame] | 806 | offsets_h version_h |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 807 | ) |
| 808 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 809 | # Generate offsets.c.obj from offsets.c |
| 810 | # Generate offsets.h from offsets.c.obj |
| 811 | |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 812 | set(OFFSETS_LIB offsets) |
| 813 | |
Klaus Petersen | c66cb76 | 2018-11-15 10:37:46 +0100 | [diff] [blame] | 814 | set(OFFSETS_C_PATH ${ARCH_DIR}/${ARCH}/core/offsets/offsets.c) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 815 | set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h) |
| 816 | |
Klaus Petersen | 62e55e5 | 2019-02-04 12:10:57 +0100 | [diff] [blame] | 817 | add_library( ${OFFSETS_LIB} OBJECT ${OFFSETS_C_PATH}) |
Stephanos Ioannidis | 2d74604 | 2019-10-25 00:08:21 +0900 | [diff] [blame] | 818 | target_include_directories(${OFFSETS_LIB} PRIVATE |
| 819 | kernel/include |
| 820 | ${ARCH_DIR}/${ARCH}/include |
| 821 | ) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 822 | target_link_libraries(${OFFSETS_LIB} zephyr_interface) |
Joakim Andersson | d268f82 | 2020-08-04 18:31:48 +0200 | [diff] [blame] | 823 | add_dependencies(zephyr_interface |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 824 | ${SYSCALL_LIST_H_TARGET} |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 825 | ${DRIVER_VALIDATION_H_TARGET} |
| 826 | ${KOBJ_TYPES_H_TARGET} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 827 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 828 | |
| 829 | add_custom_command( |
| 830 | OUTPUT ${OFFSETS_H_PATH} |
Anas Nashif | e234c21 | 2022-07-11 10:53:45 -0400 | [diff] [blame] | 831 | COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/gen_offset_header.py |
Klaus Petersen | 62e55e5 | 2019-02-04 12:10:57 +0100 | [diff] [blame] | 832 | -i $<TARGET_OBJECTS:${OFFSETS_LIB}> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 833 | -o ${OFFSETS_H_PATH} |
Sebastian Bøe | 5962aab | 2019-08-15 14:45:59 +0200 | [diff] [blame] | 834 | DEPENDS |
| 835 | ${OFFSETS_LIB} |
| 836 | $<TARGET_OBJECTS:${OFFSETS_LIB}> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 837 | ) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 838 | add_custom_target(${OFFSETS_H_TARGET} DEPENDS ${OFFSETS_H_PATH}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 839 | |
Sebastian Bøe | 89516fb | 2017-12-01 15:25:06 +0100 | [diff] [blame] | 840 | zephyr_get_include_directories_for_lang(C ZEPHYR_INCLUDES) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 841 | |
| 842 | add_subdirectory(kernel) |
| 843 | |
| 844 | # Read list content |
| 845 | get_property(ZEPHYR_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_LIBS) |
| 846 | |
| 847 | foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY}) |
Torsten Rasmussen | d952004 | 2021-04-14 17:11:39 +0200 | [diff] [blame] | 848 | get_property(lib_type TARGET ${zephyr_lib} PROPERTY TYPE) |
Torsten Rasmussen | d952004 | 2021-04-14 17:11:39 +0200 | [diff] [blame] | 849 | # To prevent CMake failure when a driver is enabled, for example: REGULATOR=y |
| 850 | # we disable any Zephyr libraries without sources and adds the `empty_file.c`. |
| 851 | if(${lib_type} STREQUAL STATIC_LIBRARY |
Torsten Rasmussen | d952004 | 2021-04-14 17:11:39 +0200 | [diff] [blame] | 852 | AND NOT ${zephyr_lib} STREQUAL app |
| 853 | ) |
Torsten Rasmussen | 25578be | 2021-04-23 09:09:49 +0200 | [diff] [blame] | 854 | get_property(source_list TARGET ${zephyr_lib} PROPERTY SOURCES) |
| 855 | get_property(lib_imported TARGET ${zephyr_lib} PROPERTY IMPORTED) |
| 856 | if(NOT source_list |
| 857 | AND NOT ${lib_imported} |
Torsten Rasmussen | d952004 | 2021-04-14 17:11:39 +0200 | [diff] [blame] | 858 | ) |
Torsten Rasmussen | 153196b | 2021-09-06 16:42:21 +0200 | [diff] [blame] | 859 | get_property(allow_empty TARGET ${zephyr_lib} PROPERTY ALLOW_EMPTY) |
| 860 | if(NOT "${allow_empty}") |
| 861 | message(WARNING |
| 862 | "No SOURCES given to Zephyr library: ${zephyr_lib}\nExcluding target from build." |
| 863 | ) |
| 864 | endif() |
Torsten Rasmussen | 25578be | 2021-04-23 09:09:49 +0200 | [diff] [blame] | 865 | target_sources(${zephyr_lib} PRIVATE ${ZEPHYR_BASE}/misc/empty_file.c) |
| 866 | set_property(TARGET ${zephyr_lib} PROPERTY EXCLUDE_FROM_ALL TRUE) |
| 867 | list(REMOVE_ITEM ZEPHYR_LIBS_PROPERTY ${zephyr_lib}) |
| 868 | continue() |
| 869 | endif() |
Torsten Rasmussen | d952004 | 2021-04-14 17:11:39 +0200 | [diff] [blame] | 870 | endif() |
Torsten Rasmussen | 25578be | 2021-04-23 09:09:49 +0200 | [diff] [blame] | 871 | |
| 872 | # TODO: Could this become an INTERFACE property of zephyr_interface? |
| 873 | add_dependencies(${zephyr_lib} zephyr_generated_headers) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 874 | endforeach() |
| 875 | |
| 876 | get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) |
| 877 | |
Adithya Baglody | 62e152a | 2018-11-13 15:34:02 +0530 | [diff] [blame] | 878 | if (CONFIG_CODE_DATA_RELOCATION) |
| 879 | set(CODE_RELOCATION_DEP code_relocation_source_lib) |
| 880 | endif() # CONFIG_CODE_DATA_RELOCATION |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 881 | |
Daniel Leung | c745995 | 2021-03-19 12:09:05 -0700 | [diff] [blame] | 882 | # Give the linker script targets all of the include directories so |
| 883 | # that cmake can successfully find the linker scripts' header |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 884 | # dependencies. |
| 885 | zephyr_get_include_directories_for_lang(C |
| 886 | ZEPHYR_INCLUDE_DIRS |
| 887 | STRIP_PREFIX # Don't use a -I prefix |
| 888 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 889 | |
Flavio Ceolin | 0b13b44 | 2022-01-05 17:19:53 -0800 | [diff] [blame] | 890 | if(CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC) |
| 891 | set(number_of_dynamic_devices ${CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC_NUM}) |
| 892 | else() |
| 893 | set(number_of_dynamic_devices 0) |
| 894 | endif() |
| 895 | |
Morten Priess | a846e72 | 2021-04-21 09:06:02 +0200 | [diff] [blame] | 896 | if(CONFIG_HAS_DTS) |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 897 | # dev_handles.c is generated from ${ZEPHYR_LINK_STAGE_EXECUTABLE} by |
Morten Priess | a846e72 | 2021-04-21 09:06:02 +0200 | [diff] [blame] | 898 | # gen_handles.py |
| 899 | add_custom_command( |
| 900 | OUTPUT dev_handles.c |
| 901 | COMMAND |
| 902 | ${PYTHON_EXECUTABLE} |
Anas Nashif | 80f4b5d | 2022-07-11 10:48:04 -0400 | [diff] [blame] | 903 | ${ZEPHYR_BASE}/scripts/build/gen_handles.py |
Morten Priess | a846e72 | 2021-04-21 09:06:02 +0200 | [diff] [blame] | 904 | --output-source dev_handles.c |
Jordan Yates | 2994247 | 2022-07-10 13:46:17 +1000 | [diff] [blame] | 905 | --output-graphviz dev_graph.dot |
Flavio Ceolin | 0b13b44 | 2022-01-05 17:19:53 -0800 | [diff] [blame] | 906 | --num-dynamic-devices ${number_of_dynamic_devices} |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 907 | --kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}> |
Morten Priess | a846e72 | 2021-04-21 09:06:02 +0200 | [diff] [blame] | 908 | --zephyr-base ${ZEPHYR_BASE} |
Torsten Rasmussen | c9804d2 | 2021-05-21 21:34:58 +0200 | [diff] [blame] | 909 | --start-symbol "$<TARGET_PROPERTY:linker,devices_start_symbol>" |
Torsten Rasmussen | 6d72d91 | 2022-01-05 11:25:26 +0100 | [diff] [blame] | 910 | VERBATIM |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 911 | DEPENDS ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
Morten Priess | a846e72 | 2021-04-21 09:06:02 +0200 | [diff] [blame] | 912 | ) |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 913 | set_property(GLOBAL APPEND PROPERTY GENERATED_APP_SOURCE_FILES dev_handles.c) |
| 914 | |
| 915 | # gen_handles runs on `__device_handles_pass1` so pass this info to the linker script generator |
| 916 | list(APPEND LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE "LINKER_DEVICE_HANDLES_PASS1") |
Morten Priess | a846e72 | 2021-04-21 09:06:02 +0200 | [diff] [blame] | 917 | endif() |
Peter Bigot | d554d34 | 2020-06-30 10:05:35 -0500 | [diff] [blame] | 918 | |
Adithya Baglody | 62e152a | 2018-11-13 15:34:02 +0530 | [diff] [blame] | 919 | if(CONFIG_CODE_DATA_RELOCATION) |
Mark Ruvald Pedersen | 86a3e8f | 2019-05-03 10:33:03 +0200 | [diff] [blame] | 920 | # @Intent: Linker script to relocate .text, data and .bss sections |
| 921 | toolchain_ld_relocation() |
Adithya Baglody | 62e152a | 2018-11-13 15:34:02 +0530 | [diff] [blame] | 922 | endif() |
| 923 | |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 924 | if(CONFIG_USERSPACE) |
Torsten Rasmussen | e37d9e6 | 2020-11-20 18:39:30 +0100 | [diff] [blame] | 925 | zephyr_get_compile_options_for_lang_as_string(C compiler_flags_priv) |
Torsten Rasmussen | e0758c3 | 2020-08-21 19:13:53 +0200 | [diff] [blame] | 926 | string(REPLACE "$<TARGET_PROPERTY:compiler,coverage>" "" |
| 927 | NO_COVERAGE_FLAGS "${compiler_flags_priv}" |
| 928 | ) |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 929 | |
Anas Nashif | efbadbb | 2022-07-11 10:53:29 -0400 | [diff] [blame] | 930 | set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py) |
Anas Nashif | d859997 | 2022-07-11 10:56:46 -0400 | [diff] [blame] | 931 | set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/build/process_gperf.py) |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 932 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 933 | |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 934 | get_property(CSTD GLOBAL PROPERTY CSTD) |
| 935 | set_ifndef(CSTD c99) |
| 936 | |
| 937 | # @Intent: Obtain compiler specific flag for specifying the c standard |
| 938 | zephyr_compile_options( |
| 939 | $<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,cstd>${CSTD}> |
| 940 | ) |
| 941 | set(CMAKE_C_COMPILE_FEATURES ${compile_features_${CSTD}} PARENT_SCOPE) |
| 942 | |
| 943 | # @Intent: Configure linker scripts, i.e. generate linker scripts with variables substituted |
| 944 | toolchain_ld_configure_files() |
| 945 | |
| 946 | if(CONFIG_USERSPACE) |
| 947 | set(APP_SMEM_ALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_aligned.ld") |
| 948 | set(APP_SMEM_UNALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_unaligned.ld") |
| 949 | |
| 950 | if(CONFIG_LINKER_USE_PINNED_SECTION) |
| 951 | set(APP_SMEM_PINNED_ALIGNED_LD |
| 952 | "${PROJECT_BINARY_DIR}/include/generated/app_smem_pinned_aligned.ld") |
| 953 | set(APP_SMEM_PINNED_UNALIGNED_LD |
| 954 | "${PROJECT_BINARY_DIR}/include/generated/app_smem_pinned_unaligned.ld") |
| 955 | |
| 956 | if(NOT CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT) |
| 957 | # The libc partition may hold symbols that are required during boot process, |
| 958 | # for example, stack guard (if enabled). So the libc partition must be pinned |
| 959 | # if not sections are in physical memory at boot, as the paging mechanism is |
| 960 | # only initialized post-kernel. |
| 961 | set_property(TARGET app_smem APPEND PROPERTY pinned_partitions "z_libc_partition") |
| 962 | endif() |
| 963 | |
| 964 | get_property(APP_SMEM_PINNED_PARTITION_LIST TARGET app_smem PROPERTY pinned_partitions) |
| 965 | if(APP_SMEM_PINNED_PARTITION_LIST) |
| 966 | list(JOIN APP_SMEM_PINNED_PARTITION_LIST "," APP_SMEM_PINNED_PARTITION_LIST_ARG_CSL) |
| 967 | set(APP_SMEM_PINNED_PARTITION_LIST_ARG "--pinpartitions=${APP_SMEM_PINNED_PARTITION_LIST_ARG_CSL}") |
| 968 | endif() |
| 969 | endif() |
| 970 | |
| 971 | set(OBJ_FILE_DIR "${PROJECT_BINARY_DIR}/../") |
| 972 | |
| 973 | if(CONFIG_NEWLIB_LIBC) |
Keith Packard | d0c75f3 | 2020-10-26 19:07:50 -0700 | [diff] [blame] | 974 | set(LIBC_PART -l libc.a z_libc_partition -l libm.a z_libc_partition) |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 975 | endif() |
| 976 | if(CONFIG_NEWLIB_LIBC_NANO) |
Keith Packard | d0c75f3 | 2020-10-26 19:07:50 -0700 | [diff] [blame] | 977 | set(LIBC_PART -l libc_nano.a z_libc_partition -l libm_nano.a z_libc_partition) |
| 978 | endif() |
| 979 | if(CONFIG_PICOLIBC) |
| 980 | set(LIBC_PART -l libc.a z_libc_partition) |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 981 | endif() |
| 982 | |
| 983 | add_custom_command( |
| 984 | OUTPUT ${APP_SMEM_UNALIGNED_LD} ${APP_SMEM_PINNED_UNALIGNED_LD} |
| 985 | COMMAND ${PYTHON_EXECUTABLE} |
Anas Nashif | 6e1a335 | 2022-07-11 10:46:17 -0400 | [diff] [blame] | 986 | ${ZEPHYR_BASE}/scripts/build/gen_app_partitions.py |
Torsten Rasmussen | f643b8b | 2021-11-24 15:35:47 +0100 | [diff] [blame] | 987 | -f ${CMAKE_BINARY_DIR}/compile_commands.json |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 988 | -o ${APP_SMEM_UNALIGNED_LD} |
| 989 | $<$<BOOL:${APP_SMEM_PINNED_UNALIGNED_LD}>:--pinoutput=${APP_SMEM_PINNED_UNALIGNED_LD}> |
| 990 | ${APP_SMEM_PINNED_PARTITION_LIST_ARG} |
Keith Packard | d0c75f3 | 2020-10-26 19:07:50 -0700 | [diff] [blame] | 991 | ${LIBC_PART} |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 992 | $<TARGET_PROPERTY:zephyr_property_target,COMPILE_OPTIONS> |
| 993 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 994 | DEPENDS |
| 995 | kernel |
Andy Ross | 6cfb186 | 2022-08-11 16:45:57 -0700 | [diff] [blame] | 996 | ${CMAKE_BINARY_DIR}/compile_commands.json |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 997 | ${ZEPHYR_LIBS_PROPERTY} |
| 998 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ |
| 999 | COMMAND_EXPAND_LISTS |
| 1000 | COMMENT "Generating app_smem_unaligned linker section" |
| 1001 | ) |
| 1002 | |
| 1003 | add_custom_target( |
| 1004 | ${APP_SMEM_ALIGNED_DEP} |
| 1005 | DEPENDS |
| 1006 | ${APP_SMEM_ALIGNED_LD} |
| 1007 | ${APP_SMEM_PINNED_ALIGNED_LD} |
| 1008 | ) |
| 1009 | |
| 1010 | add_custom_target( |
| 1011 | ${APP_SMEM_UNALIGNED_DEP} |
| 1012 | DEPENDS |
| 1013 | ${APP_SMEM_UNALIGNED_LD} |
| 1014 | ${APP_SMEM_PINNED_UNALIGNED_LD} |
| 1015 | ) |
| 1016 | |
| 1017 | set(APP_SMEM_UNALIGNED_LIB app_smem_unaligned_output_obj_renamed_lib) |
| 1018 | list(APPEND LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE "LINKER_APP_SMEM_UNALIGNED") |
| 1019 | endif() |
| 1020 | |
| 1021 | if (CONFIG_USERSPACE) |
| 1022 | add_custom_command( |
| 1023 | OUTPUT ${APP_SMEM_ALIGNED_LD} ${APP_SMEM_PINNED_ALIGNED_LD} |
| 1024 | COMMAND ${PYTHON_EXECUTABLE} |
Anas Nashif | 6e1a335 | 2022-07-11 10:46:17 -0400 | [diff] [blame] | 1025 | ${ZEPHYR_BASE}/scripts/build/gen_app_partitions.py |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1026 | -e $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}> |
| 1027 | -o ${APP_SMEM_ALIGNED_LD} |
| 1028 | $<$<BOOL:${APP_SMEM_PINNED_ALIGNED_LD}>:--pinoutput=${APP_SMEM_PINNED_ALIGNED_LD}> |
| 1029 | ${APP_SMEM_PINNED_PARTITION_LIST_ARG} |
Keith Packard | d0c75f3 | 2020-10-26 19:07:50 -0700 | [diff] [blame] | 1030 | ${LIBC_PART} |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1031 | $<TARGET_PROPERTY:zephyr_property_target,COMPILE_OPTIONS> |
| 1032 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 1033 | DEPENDS |
| 1034 | kernel |
| 1035 | ${ZEPHYR_LIBS_PROPERTY} |
| 1036 | ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
| 1037 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ |
| 1038 | COMMAND_EXPAND_LISTS |
| 1039 | COMMENT "Generating app_smem_aligned linker section" |
| 1040 | ) |
| 1041 | endif() |
| 1042 | |
| 1043 | if(CONFIG_USERSPACE) |
| 1044 | # This CONFIG_USERSPACE block is to create place holders to reserve space |
| 1045 | # for the gperf generated structures for zephyr_prebuilt.elf. |
| 1046 | # These place holders are there so that the placement of kobjects would be |
| 1047 | # the same between linking zephyr_prebuilt.elf and zephyr.elf, as |
| 1048 | # the gperf hash table is hashed on the addresses of kobjects. |
| 1049 | # The placeholders are generated from app_smem_unaligned_prebuilt.elf. |
| 1050 | |
| 1051 | set(KOBJECT_PREBUILT_HASH_LIST kobject_prebuilt_hash.gperf) |
| 1052 | set(KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE kobject_prebuilt_hash_preprocessed.c) |
| 1053 | set(KOBJECT_PREBUILT_HASH_OUTPUT_SRC kobject_prebuilt_hash.c) |
| 1054 | |
| 1055 | add_custom_command( |
| 1056 | OUTPUT ${KOBJECT_PREBUILT_HASH_LIST} |
| 1057 | COMMAND |
| 1058 | ${PYTHON_EXECUTABLE} |
| 1059 | ${GEN_KOBJ_LIST} |
| 1060 | --kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}> |
| 1061 | --gperf-output ${KOBJECT_PREBUILT_HASH_LIST} |
| 1062 | ${gen_kobject_list_include_args} |
| 1063 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 1064 | DEPENDS |
| 1065 | ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
| 1066 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1067 | ) |
| 1068 | add_custom_target( |
| 1069 | kobj_prebuilt_hash_list |
| 1070 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_LIST} |
| 1071 | ) |
| 1072 | |
| 1073 | add_custom_command( |
| 1074 | OUTPUT ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE} |
| 1075 | COMMAND |
| 1076 | ${GPERF} |
| 1077 | --output-file ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE} |
| 1078 | --multiple-iterations 10 |
| 1079 | ${KOBJECT_PREBUILT_HASH_LIST} |
| 1080 | DEPENDS kobj_prebuilt_hash_list ${KOBJECT_PREBUILT_HASH_LIST} |
| 1081 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1082 | ) |
| 1083 | add_custom_target( |
| 1084 | kobj_prebuilt_hash_output_src_pre |
| 1085 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE} |
| 1086 | ) |
| 1087 | |
| 1088 | add_custom_command( |
| 1089 | OUTPUT ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC} |
| 1090 | COMMAND |
| 1091 | ${PYTHON_EXECUTABLE} |
| 1092 | ${PROCESS_GPERF} |
| 1093 | -i ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE} |
| 1094 | -o ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC} |
| 1095 | -p "struct z_object" |
| 1096 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 1097 | DEPENDS kobj_prebuilt_hash_output_src_pre ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE} |
| 1098 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1099 | ) |
| 1100 | add_custom_target( |
| 1101 | kobj_prebuilt_hash_output_src |
| 1102 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC} |
| 1103 | ) |
| 1104 | |
| 1105 | add_library( |
| 1106 | kobj_prebuilt_hash_output_lib |
| 1107 | OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC} |
| 1108 | ) |
| 1109 | |
| 1110 | set_source_files_properties(${KOBJECT_PREBUILT_HASH_OUTPUT_SRC} |
| 1111 | PROPERTIES COMPILE_FLAGS |
| 1112 | "${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections") |
| 1113 | |
| 1114 | target_compile_definitions(kobj_prebuilt_hash_output_lib |
| 1115 | PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS> |
| 1116 | ) |
| 1117 | |
| 1118 | target_include_directories(kobj_prebuilt_hash_output_lib |
| 1119 | PUBLIC $<TARGET_PROPERTY:zephyr_interface,INTERFACE_INCLUDE_DIRECTORIES> |
| 1120 | ) |
| 1121 | |
| 1122 | target_include_directories(kobj_prebuilt_hash_output_lib SYSTEM |
| 1123 | PUBLIC $<TARGET_PROPERTY:zephyr_interface,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES> |
| 1124 | ) |
| 1125 | |
| 1126 | set(KOBJECT_LINKER_HEADER_DATA "${PROJECT_BINARY_DIR}/include/generated/linker-kobject-prebuilt-data.h") |
| 1127 | |
| 1128 | add_custom_command( |
| 1129 | OUTPUT ${KOBJECT_LINKER_HEADER_DATA} |
| 1130 | COMMAND |
| 1131 | ${PYTHON_EXECUTABLE} |
Anas Nashif | d5dcf20 | 2022-07-11 10:53:38 -0400 | [diff] [blame] | 1132 | ${ZEPHYR_BASE}/scripts/build/gen_kobject_placeholders.py |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1133 | --object $<TARGET_OBJECTS:kobj_prebuilt_hash_output_lib> |
| 1134 | --outdir ${PROJECT_BINARY_DIR}/include/generated |
| 1135 | --datapct ${CONFIG_KOBJECT_DATA_AREA_RESERVE_EXTRA_PERCENT} |
| 1136 | --rodata ${CONFIG_KOBJECT_RODATA_AREA_EXTRA_BYTES} |
| 1137 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 1138 | DEPENDS |
Torsten Rasmussen | 0454351 | 2022-02-03 15:14:44 +0100 | [diff] [blame] | 1139 | kobj_prebuilt_hash_output_lib $<TARGET_OBJECTS:kobj_prebuilt_hash_output_lib> |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1140 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1141 | ) |
| 1142 | |
| 1143 | add_custom_target( |
| 1144 | ${KOBJECT_LINKER_DEP} |
| 1145 | DEPENDS |
| 1146 | ${KOBJECT_LINKER_HEADER_DATA} |
| 1147 | ) |
| 1148 | endif() |
| 1149 | |
| 1150 | if(CONFIG_USERSPACE OR CONFIG_HAS_DTS) |
| 1151 | configure_linker_script( |
| 1152 | ${ZEPHYR_CURRENT_LINKER_CMD} |
| 1153 | "${LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE}" |
| 1154 | ${CODE_RELOCATION_DEP} |
| 1155 | ${APP_SMEM_UNALIGNED_DEP} |
| 1156 | ${APP_SMEM_UNALIGNED_LD} |
| 1157 | ${APP_SMEM_PINNED_UNALIGNED_LD} |
| 1158 | zephyr_generated_headers |
| 1159 | ) |
| 1160 | |
| 1161 | add_custom_target( |
| 1162 | linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}_script |
| 1163 | DEPENDS |
| 1164 | ${ZEPHYR_CURRENT_LINKER_CMD} |
| 1165 | ) |
| 1166 | |
| 1167 | set_property(TARGET |
| 1168 | linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}_script |
| 1169 | PROPERTY INCLUDE_DIRECTORIES |
| 1170 | ${ZEPHYR_INCLUDE_DIRS} |
| 1171 | ) |
| 1172 | |
| 1173 | add_executable(${ZEPHYR_LINK_STAGE_EXECUTABLE} misc/empty_file.c) |
| 1174 | toolchain_ld_link_elf( |
| 1175 | TARGET_ELF ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
| 1176 | OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map |
| 1177 | LIBRARIES_PRE_SCRIPT "" |
| 1178 | LINKER_SCRIPT ${PROJECT_BINARY_DIR}/${ZEPHYR_CURRENT_LINKER_CMD} |
| 1179 | LIBRARIES_POST_SCRIPT "" |
| 1180 | DEPENDENCIES ${CODE_RELOCATION_DEP} |
| 1181 | ) |
| 1182 | target_byproducts(TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
| 1183 | BYPRODUCTS ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map |
| 1184 | ) |
| 1185 | set_property(TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/${ZEPHYR_CURRENT_LINKER_CMD}) |
| 1186 | add_dependencies(${ZEPHYR_LINK_STAGE_EXECUTABLE} linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}_script ${OFFSETS_LIB}) |
| 1187 | |
| 1188 | math(EXPR ZEPHYR_CURRENT_LINKER_PASS "1 + ${ZEPHYR_CURRENT_LINKER_PASS}") |
| 1189 | endif() |
| 1190 | |
| 1191 | set(ZEPHYR_CURRENT_LINKER_CMD linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}.cmd) |
| 1192 | set(ZEPHYR_LINK_STAGE_EXECUTABLE zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}) |
| 1193 | list(APPEND LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE "LINKER_ZEPHYR_PREBUILT") |
| 1194 | |
| 1195 | if(CONFIG_GEN_ISR_TABLES) |
| 1196 | if(CONFIG_GEN_SW_ISR_TABLE) |
| 1197 | list(APPEND GEN_ISR_TABLE_EXTRA_ARG --sw-isr-table) |
| 1198 | endif() |
| 1199 | |
| 1200 | if(CONFIG_GEN_IRQ_VECTOR_TABLE) |
| 1201 | list(APPEND GEN_ISR_TABLE_EXTRA_ARG --vector-table) |
| 1202 | endif() |
| 1203 | |
| 1204 | # isr_tables.c is generated from ${ZEPHYR_LINK_STAGE_EXECUTABLE} by |
| 1205 | # gen_isr_tables.py |
| 1206 | add_custom_command( |
| 1207 | OUTPUT isr_tables.c isrList.bin |
| 1208 | COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command> |
| 1209 | $<TARGET_PROPERTY:bintools,elfconvert_flag> |
| 1210 | $<TARGET_PROPERTY:bintools,elfconvert_flag_intarget>${OUTPUT_FORMAT} |
| 1211 | $<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>binary |
| 1212 | $<TARGET_PROPERTY:bintools,elfconvert_flag_section_only>.intList |
| 1213 | $<TARGET_PROPERTY:bintools,elfconvert_flag_infile>$<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}> |
| 1214 | $<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>isrList.bin |
| 1215 | $<TARGET_PROPERTY:bintools,elfconvert_flag_final> |
| 1216 | COMMAND ${PYTHON_EXECUTABLE} |
Anas Nashif | c36307e | 2022-07-11 10:51:50 -0400 | [diff] [blame] | 1217 | ${ZEPHYR_BASE}/scripts/build/gen_isr_tables.py |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1218 | --output-source isr_tables.c |
| 1219 | --kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}> |
| 1220 | --intlist isrList.bin |
| 1221 | $<$<BOOL:${CONFIG_BIG_ENDIAN}>:--big-endian> |
| 1222 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug> |
| 1223 | ${GEN_ISR_TABLE_EXTRA_ARG} |
| 1224 | DEPENDS ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
| 1225 | COMMAND_EXPAND_LISTS |
| 1226 | ) |
| 1227 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c) |
| 1228 | endif() |
| 1229 | |
| 1230 | if(CONFIG_USERSPACE) |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1231 | set(KOBJECT_HASH_LIST kobject_hash.gperf) |
| 1232 | set(KOBJECT_HASH_OUTPUT_SRC_PRE kobject_hash_preprocessed.c) |
| 1233 | set(KOBJECT_HASH_OUTPUT_SRC kobject_hash.c) |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1234 | set(KOBJECT_HASH_OUTPUT_OBJ_RENAMED kobject_hash_renamed.o) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1235 | |
| 1236 | # Essentially what we are doing here is extracting some information |
| 1237 | # out of the nearly finished elf file, generating the source code |
| 1238 | # for a hash table based on that information, and then compiling and |
| 1239 | # linking the hash table back into a now even more nearly finished |
Marc Herbert | 4a10eea | 2019-04-16 15:39:45 -0700 | [diff] [blame] | 1240 | # elf file. More information in gen_kobject_list.py --help. |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1241 | |
| 1242 | # Use the script GEN_KOBJ_LIST to scan the kernel binary's |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1243 | # (${ZEPHYR_LINK_STAGE_EXECUTABLE}) DWARF information to produce a table of kernel |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1244 | # objects (KOBJECT_HASH_LIST) which we will then pass to gperf |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1245 | add_custom_command( |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1246 | OUTPUT ${KOBJECT_HASH_LIST} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1247 | COMMAND |
| 1248 | ${PYTHON_EXECUTABLE} |
| 1249 | ${GEN_KOBJ_LIST} |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1250 | --kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}> |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1251 | --gperf-output ${KOBJECT_HASH_LIST} |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 1252 | ${gen_kobject_list_include_args} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1253 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 1254 | DEPENDS |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1255 | ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1256 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1257 | ) |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1258 | add_custom_target( |
| 1259 | kobj_hash_list |
| 1260 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_LIST} |
| 1261 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1262 | |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1263 | # Use gperf to generate C code (KOBJECT_HASH_OUTPUT_SRC_PRE) which implements a |
| 1264 | # perfect hashtable based on KOBJECT_HASH_LIST |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1265 | add_custom_command( |
Torsten Rasmussen | 0454351 | 2022-02-03 15:14:44 +0100 | [diff] [blame] | 1266 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC_PRE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1267 | COMMAND |
| 1268 | ${GPERF} |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1269 | --output-file ${KOBJECT_HASH_OUTPUT_SRC_PRE} |
Daniel Leung | 1117169 | 2021-03-18 14:00:07 -0700 | [diff] [blame] | 1270 | --multiple-iterations 10 |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1271 | ${KOBJECT_HASH_LIST} |
| 1272 | DEPENDS kobj_hash_list ${KOBJECT_HASH_LIST} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1273 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1274 | ) |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1275 | add_custom_target( |
| 1276 | kobj_hash_output_src_pre |
| 1277 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC_PRE} |
| 1278 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1279 | |
| 1280 | # For our purposes the code/data generated by gperf is not optimal. |
| 1281 | # |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1282 | # The script PROCESS_GPERF creates a new c file KOBJECT_HASH_OUTPUT_SRC based on |
| 1283 | # KOBJECT_HASH_OUTPUT_SRC_PRE to greatly reduce the amount of code/data generated |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1284 | # since we know we are always working with pointer values |
| 1285 | add_custom_command( |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1286 | OUTPUT ${KOBJECT_HASH_OUTPUT_SRC} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1287 | COMMAND |
Sebastian Bøe | 1b60070 | 2018-06-21 14:34:42 +0200 | [diff] [blame] | 1288 | ${PYTHON_EXECUTABLE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1289 | ${PROCESS_GPERF} |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1290 | -i ${KOBJECT_HASH_OUTPUT_SRC_PRE} |
| 1291 | -o ${KOBJECT_HASH_OUTPUT_SRC} |
Andrew Boie | 2dc2ecf | 2020-03-11 07:13:07 -0700 | [diff] [blame] | 1292 | -p "struct z_object" |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1293 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Torsten Rasmussen | 0454351 | 2022-02-03 15:14:44 +0100 | [diff] [blame] | 1294 | DEPENDS kobj_hash_output_src_pre ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC_PRE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1295 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1296 | ) |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1297 | add_custom_target( |
| 1298 | kobj_hash_output_src |
| 1299 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC} |
| 1300 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1301 | |
| 1302 | # We need precise control of where generated text/data ends up in the final |
| 1303 | # kernel image. Disable function/data sections and use objcopy to move |
| 1304 | # generated data into special section names |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1305 | add_library( |
| 1306 | kobj_hash_output_lib |
Torsten Rasmussen | 47304d4 | 2021-11-02 12:06:05 +0100 | [diff] [blame] | 1307 | OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1308 | ) |
| 1309 | |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1310 | set_source_files_properties(${KOBJECT_HASH_OUTPUT_SRC} |
| 1311 | PROPERTIES COMPILE_FLAGS |
Andrew Boie | a514898 | 2019-03-14 17:04:11 -0700 | [diff] [blame] | 1312 | "${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections") |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 1313 | |
Torsten Rasmussen | 47304d4 | 2021-11-02 12:06:05 +0100 | [diff] [blame] | 1314 | target_compile_definitions(kobj_hash_output_lib |
| 1315 | PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS> |
| 1316 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1317 | |
Torsten Rasmussen | 47304d4 | 2021-11-02 12:06:05 +0100 | [diff] [blame] | 1318 | target_include_directories(kobj_hash_output_lib |
| 1319 | PUBLIC $<TARGET_PROPERTY:zephyr_interface,INTERFACE_INCLUDE_DIRECTORIES> |
| 1320 | ) |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 1321 | |
Torsten Rasmussen | 47304d4 | 2021-11-02 12:06:05 +0100 | [diff] [blame] | 1322 | target_include_directories(kobj_hash_output_lib SYSTEM |
| 1323 | PUBLIC $<TARGET_PROPERTY:zephyr_interface,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES> |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1324 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1325 | |
| 1326 | add_custom_command( |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1327 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_OBJ_RENAMED} |
Torsten Rasmussen | c060b07 | 2020-08-18 14:46:06 +0200 | [diff] [blame] | 1328 | COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command> |
| 1329 | $<TARGET_PROPERTY:bintools,elfconvert_flag> |
Flavio Ceolin | 02d5290 | 2022-12-20 13:29:51 -0800 | [diff] [blame] | 1330 | $<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.literal=.kobject_data.literal |
Torsten Rasmussen | c060b07 | 2020-08-18 14:46:06 +0200 | [diff] [blame] | 1331 | $<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.data=.kobject_data.data |
Jim Shu | 70e1dee | 2021-07-08 01:11:34 +0800 | [diff] [blame] | 1332 | $<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.sdata=.kobject_data.sdata |
Torsten Rasmussen | c060b07 | 2020-08-18 14:46:06 +0200 | [diff] [blame] | 1333 | $<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.text=.kobject_data.text |
| 1334 | $<TARGET_PROPERTY:bintools,elfconvert_flag_section_rename>.rodata=.kobject_data.rodata |
Torsten Rasmussen | 47304d4 | 2021-11-02 12:06:05 +0100 | [diff] [blame] | 1335 | $<TARGET_PROPERTY:bintools,elfconvert_flag_infile>$<TARGET_OBJECTS:kobj_hash_output_lib> |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1336 | $<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KOBJECT_HASH_OUTPUT_OBJ_RENAMED} |
Torsten Rasmussen | f160dee | 2020-09-04 10:05:00 +0200 | [diff] [blame] | 1337 | $<TARGET_PROPERTY:bintools,elfconvert_flag_final> |
Torsten Rasmussen | 0454351 | 2022-02-03 15:14:44 +0100 | [diff] [blame] | 1338 | DEPENDS kobj_hash_output_lib $<TARGET_OBJECTS:kobj_hash_output_lib> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1339 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
Torsten Rasmussen | c060b07 | 2020-08-18 14:46:06 +0200 | [diff] [blame] | 1340 | COMMAND_EXPAND_LISTS |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1341 | ) |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1342 | add_custom_target( |
| 1343 | kobj_hash_output_obj_renamed |
| 1344 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_OBJ_RENAMED} |
| 1345 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1346 | |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1347 | add_library(kobj_hash_output_obj_renamed_lib STATIC IMPORTED GLOBAL) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1348 | set_property( |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1349 | TARGET kobj_hash_output_obj_renamed_lib |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1350 | PROPERTY |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1351 | IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_OBJ_RENAMED} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1352 | ) |
| 1353 | add_dependencies( |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1354 | kobj_hash_output_obj_renamed_lib |
| 1355 | kobj_hash_output_obj_renamed |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1356 | ) |
| 1357 | |
Daniel Leung | 28c3512 | 2021-03-18 12:02:19 -0700 | [diff] [blame] | 1358 | set_property( |
| 1359 | GLOBAL APPEND PROPERTY |
| 1360 | GENERATED_KERNEL_OBJECT_FILES kobj_hash_output_obj_renamed_lib |
| 1361 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1362 | endif() |
| 1363 | |
Daniel Leung | c745995 | 2021-03-19 12:09:05 -0700 | [diff] [blame] | 1364 | configure_linker_script( |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1365 | ${ZEPHYR_CURRENT_LINKER_CMD} |
| 1366 | "${LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE}" |
Daniel Leung | c745995 | 2021-03-19 12:09:05 -0700 | [diff] [blame] | 1367 | ${APP_SMEM_ALIGNED_DEP} |
Daniel Leung | 1117169 | 2021-03-18 14:00:07 -0700 | [diff] [blame] | 1368 | ${KOBJECT_LINKER_DEP} |
Daniel Leung | c745995 | 2021-03-19 12:09:05 -0700 | [diff] [blame] | 1369 | ${CODE_RELOCATION_DEP} |
| 1370 | zephyr_generated_headers |
| 1371 | ) |
| 1372 | |
| 1373 | add_custom_target( |
| 1374 | linker_zephyr_prebuilt_script_target |
| 1375 | DEPENDS |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1376 | ${ZEPHYR_CURRENT_LINKER_CMD} |
Daniel Leung | c745995 | 2021-03-19 12:09:05 -0700 | [diff] [blame] | 1377 | ) |
| 1378 | |
| 1379 | set_property(TARGET |
| 1380 | linker_zephyr_prebuilt_script_target |
| 1381 | PROPERTY INCLUDE_DIRECTORIES |
| 1382 | ${ZEPHYR_INCLUDE_DIRS} |
| 1383 | ) |
| 1384 | |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1385 | # Read global variables into local variables |
| 1386 | get_property(GASF GLOBAL PROPERTY GENERATED_APP_SOURCE_FILES) |
| 1387 | get_property(GKOF GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES) |
| 1388 | get_property(GKSF GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES) |
| 1389 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1390 | # FIXME: Is there any way to get rid of empty_file.c? |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1391 | add_executable( ${ZEPHYR_LINK_STAGE_EXECUTABLE} misc/empty_file.c ${GASF}) |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1392 | toolchain_ld_link_elf( |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1393 | TARGET_ELF ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
| 1394 | OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1395 | LIBRARIES_PRE_SCRIPT "" |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1396 | LINKER_SCRIPT ${PROJECT_BINARY_DIR}/${ZEPHYR_CURRENT_LINKER_CMD} |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1397 | DEPENDENCIES ${CODE_RELOCATION_DEP} |
| 1398 | ) |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1399 | target_byproducts(TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
| 1400 | BYPRODUCTS ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map |
Torsten Rasmussen | c4c79f5 | 2021-02-09 22:27:59 +0100 | [diff] [blame] | 1401 | ) |
Daniel Leung | c745995 | 2021-03-19 12:09:05 -0700 | [diff] [blame] | 1402 | set_property(TARGET |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1403 | ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
| 1404 | PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/${ZEPHYR_CURRENT_LINKER_CMD} |
Daniel Leung | c745995 | 2021-03-19 12:09:05 -0700 | [diff] [blame] | 1405 | ) |
| 1406 | add_dependencies( |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1407 | ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
Daniel Leung | c745995 | 2021-03-19 12:09:05 -0700 | [diff] [blame] | 1408 | linker_zephyr_prebuilt_script_target |
| 1409 | ${OFFSETS_LIB} |
| 1410 | ) |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 1411 | |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1412 | set(generated_kernel_files ${GKSF} ${GKOF}) |
| 1413 | if(NOT generated_kernel_files) |
| 1414 | # Use the prebuilt elf as the final elf since we don't have a |
| 1415 | # generation stage. |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1416 | set(logical_target_for_zephyr_elf ${ZEPHYR_LINK_STAGE_EXECUTABLE}) |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1417 | else() |
Daniel Leung | cdd02a9 | 2021-03-19 12:18:52 -0700 | [diff] [blame] | 1418 | # The final linker pass uses the same source linker script of the |
| 1419 | # previous passes, but this time with a different output |
| 1420 | # file and preprocessed with the define LINKER_ZEPHYR_FINAL. |
Mark Ruvald Pedersen | 4c81197 | 2019-04-29 17:16:54 +0200 | [diff] [blame] | 1421 | configure_linker_script( |
Daniel Leung | cdd02a9 | 2021-03-19 12:18:52 -0700 | [diff] [blame] | 1422 | linker.cmd |
Torsten Rasmussen | 1fa3f15 | 2021-11-01 12:53:28 +0100 | [diff] [blame] | 1423 | "LINKER_ZEPHYR_FINAL" |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 1424 | ${CODE_RELOCATION_DEP} |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1425 | ${ZEPHYR_LINK_STAGE_EXECUTABLE} |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 1426 | zephyr_generated_headers |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 1427 | ) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1428 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1429 | add_custom_target( |
Daniel Leung | cdd02a9 | 2021-03-19 12:18:52 -0700 | [diff] [blame] | 1430 | linker_zephyr_final_script_target |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1431 | DEPENDS |
Daniel Leung | cdd02a9 | 2021-03-19 12:18:52 -0700 | [diff] [blame] | 1432 | linker.cmd |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1433 | ) |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 1434 | set_property(TARGET |
Daniel Leung | cdd02a9 | 2021-03-19 12:18:52 -0700 | [diff] [blame] | 1435 | linker_zephyr_final_script_target |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 1436 | PROPERTY INCLUDE_DIRECTORIES |
| 1437 | ${ZEPHYR_INCLUDE_DIRS} |
| 1438 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1439 | |
Jordan Yates | 8d93217 | 2021-10-20 20:09:39 +1000 | [diff] [blame] | 1440 | add_executable( ${ZEPHYR_FINAL_EXECUTABLE} misc/empty_file.c ${GASF} ${GKSF}) |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1441 | toolchain_ld_link_elf( |
| 1442 | TARGET_ELF ${ZEPHYR_FINAL_EXECUTABLE} |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1443 | OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_FINAL_EXECUTABLE}.map |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1444 | LIBRARIES_PRE_SCRIPT ${GKOF} |
Daniel Leung | cdd02a9 | 2021-03-19 12:18:52 -0700 | [diff] [blame] | 1445 | LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker.cmd |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1446 | LIBRARIES_POST_SCRIPT "" |
| 1447 | DEPENDENCIES ${CODE_RELOCATION_DEP} |
| 1448 | ) |
Daniel Leung | cdd02a9 | 2021-03-19 12:18:52 -0700 | [diff] [blame] | 1449 | set_property(TARGET ${ZEPHYR_FINAL_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker.cmd) |
| 1450 | add_dependencies( ${ZEPHYR_FINAL_EXECUTABLE} linker_zephyr_final_script_target) |
Mark Ruvald Pedersen | 37d4947 | 2019-05-07 15:20:20 +0200 | [diff] [blame] | 1451 | |
| 1452 | # Use the pass2 elf as the final elf |
| 1453 | set(logical_target_for_zephyr_elf ${ZEPHYR_FINAL_EXECUTABLE}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1454 | endif() |
| 1455 | |
Sebastian Bøe | 0fc3934 | 2018-10-16 13:25:04 +0200 | [diff] [blame] | 1456 | # Export the variable to the application's scope to allow the |
| 1457 | # application to know what the name of the final elf target is. |
| 1458 | set(logical_target_for_zephyr_elf ${logical_target_for_zephyr_elf} PARENT_SCOPE) |
| 1459 | |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1460 | # Override the base name of the last, "logical" .elf output (and last .map) so: |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1461 | # 1. it doesn't depend on the number of passes above and the |
| 1462 | # post_build_commands below can always find it no matter which is it; |
| 1463 | # 2. it can be defined in Kconfig |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1464 | set_target_properties(${logical_target_for_zephyr_elf} PROPERTIES OUTPUT_NAME ${KERNEL_NAME}) |
| 1465 | |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1466 | set(post_build_commands "") |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1467 | set(post_build_byproducts "") |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1468 | |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1469 | list(APPEND |
| 1470 | post_build_commands |
| 1471 | COMMAND |
Mark Ruvald Pedersen | d8df801 | 2022-03-16 13:21:39 +0100 | [diff] [blame] | 1472 | ${CMAKE_COMMAND} -E copy ${logical_target_for_zephyr_elf}.map ${KERNEL_MAP_NAME} |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1473 | ) |
Torsten Rasmussen | c4c79f5 | 2021-02-09 22:27:59 +0100 | [diff] [blame] | 1474 | list(APPEND post_build_byproducts ${KERNEL_MAP_NAME}) |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1475 | |
Håkon Øye Amundsen | c086b93 | 2018-11-26 09:47:16 +0000 | [diff] [blame] | 1476 | if(NOT CONFIG_BUILD_NO_GAP_FILL) |
| 1477 | # Use ';' as separator to get proper space in resulting command. |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1478 | set(GAP_FILL "$<TARGET_PROPERTY:bintools,elfconvert_flag_gapfill>0xff") |
Håkon Øye Amundsen | c086b93 | 2018-11-26 09:47:16 +0000 | [diff] [blame] | 1479 | endif() |
| 1480 | |
Danny Oerndrup | c41e712 | 2019-07-18 15:16:39 +0200 | [diff] [blame] | 1481 | if(CONFIG_OUTPUT_PRINT_MEMORY_USAGE) |
Torsten Rasmussen | d537be0 | 2021-02-02 21:06:11 +0100 | [diff] [blame] | 1482 | target_link_libraries(${logical_target_for_zephyr_elf} $<TARGET_PROPERTY:linker,memusage>) |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1483 | |
| 1484 | get_property(memusage_build_command TARGET bintools PROPERTY memusage_command) |
| 1485 | if(memusage_build_command) |
| 1486 | # Note: The use of generator expressions allows downstream extensions to add/change the post build. |
| 1487 | # Unfortunately, the BYPRODUCTS does not allow for generator expression, so question is if we |
| 1488 | # should remove the downstream ability from start. |
| 1489 | # Or fix the output name, by the use of `get_property` |
| 1490 | list(APPEND |
| 1491 | post_build_commands |
Torsten Rasmussen | 571f48f | 2020-09-04 21:07:46 +0200 | [diff] [blame] | 1492 | COMMAND $<TARGET_PROPERTY:bintools,memusage_command> |
| 1493 | $<TARGET_PROPERTY:bintools,memusage_flag> |
| 1494 | $<TARGET_PROPERTY:bintools,memusage_infile>${KERNEL_ELF_NAME} |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1495 | ) |
| 1496 | |
| 1497 | # For now, the byproduct can only be supported upstream on byproducts name, |
| 1498 | # cause byproduct does not support generator expressions |
| 1499 | get_property(memusage_byproducts TARGET bintools PROPERTY memusage_byproducts) |
| 1500 | list(APPEND |
| 1501 | post_build_byproducts |
| 1502 | ${memusage_byproducts} |
| 1503 | ) |
| 1504 | endif() |
Danny Oerndrup | c41e712 | 2019-07-18 15:16:39 +0200 | [diff] [blame] | 1505 | endif() |
| 1506 | |
Torsten Rasmussen | d51a67b | 2022-01-12 14:21:07 +0100 | [diff] [blame] | 1507 | if(CONFIG_BUILD_OUTPUT_ADJUST_LMA) |
| 1508 | math(EXPR adjustment "${CONFIG_BUILD_OUTPUT_ADJUST_LMA}" OUTPUT_FORMAT DECIMAL) |
| 1509 | list(APPEND |
| 1510 | post_build_commands |
| 1511 | COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command> |
| 1512 | $<TARGET_PROPERTY:bintools,elfconvert_flag_final> |
| 1513 | $<TARGET_PROPERTY:bintools,elfconvert_flag_lma_adjust>${adjustment} |
| 1514 | $<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME} |
| 1515 | $<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_ELF_NAME} |
| 1516 | ) |
| 1517 | endif() |
| 1518 | |
Stephanos Ioannidis | 404e7a9 | 2022-12-09 19:43:43 +0900 | [diff] [blame] | 1519 | if(NOT CONFIG_CPP_EXCEPTIONS) |
Chen Peng1 | 8c069c3 | 2022-03-07 18:36:53 +0800 | [diff] [blame] | 1520 | set(eh_frame_section ".eh_frame") |
| 1521 | else() |
| 1522 | set(eh_frame_section "") |
| 1523 | endif() |
| 1524 | set(remove_sections_argument_list "") |
| 1525 | foreach(section .comment COMMON ${eh_frame_section}) |
| 1526 | list(APPEND remove_sections_argument_list |
| 1527 | $<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>${section}) |
| 1528 | endforeach() |
| 1529 | |
Kumar Gala | d541913 | 2019-08-13 13:44:20 -0500 | [diff] [blame] | 1530 | if(CONFIG_BUILD_OUTPUT_HEX OR BOARD_FLASH_RUNNER STREQUAL openocd) |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1531 | get_property(elfconvert_formats TARGET bintools PROPERTY elfconvert_formats) |
| 1532 | if(ihex IN_LIST elfconvert_formats) |
| 1533 | list(APPEND |
| 1534 | post_build_commands |
| 1535 | COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command> |
| 1536 | $<TARGET_PROPERTY:bintools,elfconvert_flag> |
| 1537 | ${GAP_FILL} |
| 1538 | $<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>ihex |
Chen Peng1 | 8c069c3 | 2022-03-07 18:36:53 +0800 | [diff] [blame] | 1539 | ${remove_sections_argument_list} |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1540 | $<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME} |
| 1541 | $<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_HEX_NAME} |
Torsten Rasmussen | f160dee | 2020-09-04 10:05:00 +0200 | [diff] [blame] | 1542 | $<TARGET_PROPERTY:bintools,elfconvert_flag_final> |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1543 | ) |
| 1544 | list(APPEND |
| 1545 | post_build_byproducts |
| 1546 | ${KERNEL_HEX_NAME} |
| 1547 | # ${out_hex_byprod} # Is this needed ? |
| 1548 | ) |
| 1549 | endif() |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1550 | endif() |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1551 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1552 | if(CONFIG_BUILD_OUTPUT_BIN) |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1553 | get_property(elfconvert_formats TARGET bintools PROPERTY elfconvert_formats) |
| 1554 | if(binary IN_LIST elfconvert_formats) |
| 1555 | list(APPEND |
| 1556 | post_build_commands |
| 1557 | COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command> |
| 1558 | $<TARGET_PROPERTY:bintools,elfconvert_flag> |
| 1559 | ${GAP_FILL} |
| 1560 | $<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>binary |
Chen Peng1 | 8c069c3 | 2022-03-07 18:36:53 +0800 | [diff] [blame] | 1561 | ${remove_sections_argument_list} |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1562 | $<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME} |
| 1563 | $<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_BIN_NAME} |
Torsten Rasmussen | f160dee | 2020-09-04 10:05:00 +0200 | [diff] [blame] | 1564 | $<TARGET_PROPERTY:bintools,elfconvert_flag_final> |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1565 | ) |
| 1566 | list(APPEND |
| 1567 | post_build_byproducts |
| 1568 | ${KERNEL_BIN_NAME} |
| 1569 | # ${out_hex_byprod} # Is this needed ? |
| 1570 | ) |
| 1571 | endif() |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1572 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1573 | |
Pete Johanson | 310a464 | 2020-12-31 16:51:52 -0500 | [diff] [blame] | 1574 | if(CONFIG_BUILD_OUTPUT_BIN AND CONFIG_BUILD_OUTPUT_UF2) |
Peter Johanson | 3f33207 | 2022-01-27 00:45:27 -0500 | [diff] [blame] | 1575 | if(CONFIG_BUILD_OUTPUT_UF2_USE_FLASH_BASE) |
| 1576 | set(flash_addr "${CONFIG_FLASH_BASE_ADDRESS}") |
| 1577 | else() |
| 1578 | set(flash_addr "${CONFIG_FLASH_LOAD_OFFSET}") |
| 1579 | endif() |
| 1580 | |
| 1581 | if(CONFIG_BUILD_OUTPUT_UF2_USE_FLASH_OFFSET) |
| 1582 | # Note, the `+ 0` in formula below avoids errors in cases where a Kconfig |
| 1583 | # variable is undefined and thus expands to nothing. |
| 1584 | math(EXPR flash_addr |
| 1585 | "${flash_addr} + ${CONFIG_FLASH_LOAD_OFFSET} + 0" |
| 1586 | OUTPUT_FORMAT HEXADECIMAL |
| 1587 | ) |
| 1588 | endif() |
| 1589 | |
Pete Johanson | 310a464 | 2020-12-31 16:51:52 -0500 | [diff] [blame] | 1590 | list(APPEND |
| 1591 | post_build_commands |
Anas Nashif | a8a9766 | 2022-07-11 10:57:15 -0400 | [diff] [blame] | 1592 | COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/uf2conv.py |
Pete Johanson | 310a464 | 2020-12-31 16:51:52 -0500 | [diff] [blame] | 1593 | -c |
| 1594 | -f ${CONFIG_BUILD_OUTPUT_UF2_FAMILY_ID} |
Peter Johanson | 3f33207 | 2022-01-27 00:45:27 -0500 | [diff] [blame] | 1595 | -b ${flash_addr} |
Pete Johanson | 310a464 | 2020-12-31 16:51:52 -0500 | [diff] [blame] | 1596 | -o ${KERNEL_UF2_NAME} |
| 1597 | ${KERNEL_BIN_NAME} |
| 1598 | ) |
| 1599 | list(APPEND |
| 1600 | post_build_byproducts |
| 1601 | ${KERNEL_UF2_NAME} |
| 1602 | ) |
| 1603 | endif() |
Anas Nashif | fdbf2db | 2020-10-20 14:31:56 -0400 | [diff] [blame] | 1604 | |
Torsten Rasmussen | fffaf05 | 2021-10-12 23:08:36 +0200 | [diff] [blame] | 1605 | if(CONFIG_BUILD_OUTPUT_META) |
| 1606 | list(APPEND |
| 1607 | post_build_commands |
| 1608 | COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/zephyr_module.py |
| 1609 | ${WEST_ARG} |
| 1610 | ${ZEPHYR_MODULES_ARG} |
| 1611 | ${ZEPHYR_EXTRA_MODULES_ARG} |
| 1612 | --meta-out ${KERNEL_META_NAME} |
Torsten Rasmussen | 1a51993 | 2021-11-04 18:35:50 +0100 | [diff] [blame] | 1613 | $<$<BOOL:${CONFIG_BUILD_OUTPUT_META_STATE_PROPAGATE}>:--meta-state-propagate> |
Torsten Rasmussen | fffaf05 | 2021-10-12 23:08:36 +0200 | [diff] [blame] | 1614 | ) |
| 1615 | list(APPEND |
| 1616 | post_build_byproducts |
| 1617 | ${KERNEL_META_NAME} |
| 1618 | ) |
| 1619 | endif() |
| 1620 | |
Anas Nashif | fdbf2db | 2020-10-20 14:31:56 -0400 | [diff] [blame] | 1621 | # Cleanup intermediate files |
| 1622 | if(CONFIG_CLEANUP_INTERMEDIATE_FILES) |
Torsten Rasmussen | d2cdee5 | 2021-11-25 12:23:34 +0100 | [diff] [blame] | 1623 | foreach(index RANGE ${ZEPHYR_CURRENT_LINKER_PASS}) |
| 1624 | # Those files can be very large in some cases, delete them as we do not need them. |
Anas Nashif | fdbf2db | 2020-10-20 14:31:56 -0400 | [diff] [blame] | 1625 | list(APPEND |
| 1626 | post_build_commands |
| 1627 | COMMAND |
Torsten Rasmussen | d2cdee5 | 2021-11-25 12:23:34 +0100 | [diff] [blame] | 1628 | ${CMAKE_COMMAND} -E remove zephyr_pre${index}.elf |
Anas Nashif | fdbf2db | 2020-10-20 14:31:56 -0400 | [diff] [blame] | 1629 | ) |
Torsten Rasmussen | d2cdee5 | 2021-11-25 12:23:34 +0100 | [diff] [blame] | 1630 | endforeach() |
Anas Nashif | fdbf2db | 2020-10-20 14:31:56 -0400 | [diff] [blame] | 1631 | endif() |
| 1632 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1633 | if(CONFIG_BUILD_OUTPUT_S19) |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1634 | get_property(elfconvert_formats TARGET bintools PROPERTY elfconvert_formats) |
| 1635 | if(srec IN_LIST elfconvert_formats) |
| 1636 | # Should we print a warning if case the tools does not support converting to s19 ? |
| 1637 | list(APPEND |
| 1638 | post_build_commands |
| 1639 | COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command> |
| 1640 | $<TARGET_PROPERTY:bintools,elfconvert_flag> |
| 1641 | ${GAP_FILL} |
| 1642 | $<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>srec |
| 1643 | $<TARGET_PROPERTY:bintools,elfconvert_flag_srec_len>1 |
| 1644 | $<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME} |
| 1645 | $<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_S19_NAME} |
Torsten Rasmussen | f160dee | 2020-09-04 10:05:00 +0200 | [diff] [blame] | 1646 | $<TARGET_PROPERTY:bintools,elfconvert_flag_final> |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1647 | ) |
| 1648 | list(APPEND |
| 1649 | post_build_byproducts |
| 1650 | ${KERNEL_S19_NAME} |
| 1651 | # ${out_S19_byprod} # Is this needed ? |
| 1652 | |
| 1653 | ) |
| 1654 | endif() |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1655 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1656 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1657 | if(CONFIG_OUTPUT_DISASSEMBLY) |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1658 | if(CONFIG_OUTPUT_DISASSEMBLE_ALL) |
| 1659 | set(disassembly_type "$<TARGET_PROPERTY:bintools,disassembly_flag_all>") |
Rohit Gujarathi | 35713f2 | 2020-05-07 10:08:37 +0530 | [diff] [blame] | 1660 | else() |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1661 | set(disassembly_type "$<TARGET_PROPERTY:bintools,disassembly_flag_inline_source>") |
Rohit Gujarathi | 35713f2 | 2020-05-07 10:08:37 +0530 | [diff] [blame] | 1662 | endif() |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1663 | list(APPEND |
| 1664 | post_build_commands |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1665 | COMMAND $<TARGET_PROPERTY:bintools,disassembly_command> |
| 1666 | $<TARGET_PROPERTY:bintools,disassembly_flag> |
| 1667 | ${disassembly_type} |
Torsten Rasmussen | c060b07 | 2020-08-18 14:46:06 +0200 | [diff] [blame] | 1668 | $<TARGET_PROPERTY:bintools,disassembly_flag_infile>${KERNEL_ELF_NAME} |
| 1669 | $<TARGET_PROPERTY:bintools,disassembly_flag_outfile>${KERNEL_LST_NAME} |
Torsten Rasmussen | f160dee | 2020-09-04 10:05:00 +0200 | [diff] [blame] | 1670 | $<TARGET_PROPERTY:bintools,disassembly_flag_final> |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1671 | ) |
| 1672 | list(APPEND |
| 1673 | post_build_byproducts |
| 1674 | ${KERNEL_LST_NAME} |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1675 | # ${out_disassembly_byprod} # Needed ?? |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1676 | ) |
| 1677 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1678 | |
Anas Nashif | 47a673f | 2022-06-27 10:08:37 -0400 | [diff] [blame] | 1679 | if(CONFIG_OUTPUT_SYMBOLS) |
| 1680 | list(APPEND |
| 1681 | post_build_commands |
| 1682 | COMMAND $<TARGET_PROPERTY:bintools,symbols_command> |
| 1683 | $<TARGET_PROPERTY:bintools,symbols_flag> |
| 1684 | $<TARGET_PROPERTY:bintools,symbols_infile>${KERNEL_ELF_NAME} |
| 1685 | $<TARGET_PROPERTY:bintools,symbols_outfile>${KERNEL_SYMBOLS_NAME} |
| 1686 | $<TARGET_PROPERTY:bintools,symbols_final> |
| 1687 | ) |
| 1688 | list(APPEND |
| 1689 | post_build_byproducts |
| 1690 | ${KERNEL_SYMBOLS_NAME} |
| 1691 | ) |
| 1692 | endif() |
| 1693 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1694 | if(CONFIG_OUTPUT_STAT) |
Torsten Rasmussen | c060b07 | 2020-08-18 14:46:06 +0200 | [diff] [blame] | 1695 | # zephyr_post_build(TOOLS bintools COMMAND readelf FLAGS headers INFILE file OUTFILE outfile) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1696 | list(APPEND |
| 1697 | post_build_commands |
Torsten Rasmussen | c060b07 | 2020-08-18 14:46:06 +0200 | [diff] [blame] | 1698 | COMMAND $<TARGET_PROPERTY:bintools,readelf_command> |
| 1699 | $<TARGET_PROPERTY:bintools,readelf_flag> |
| 1700 | $<TARGET_PROPERTY:bintools,readelf_flag_headers> |
Torsten Rasmussen | 2d1a3d9 | 2021-05-20 17:38:57 +0200 | [diff] [blame] | 1701 | $<TARGET_PROPERTY:bintools,readelf_flag_infile>${KERNEL_ELF_NAME} |
| 1702 | $<TARGET_PROPERTY:bintools,readelf_flag_outfile>${KERNEL_STAT_NAME} |
Torsten Rasmussen | f160dee | 2020-09-04 10:05:00 +0200 | [diff] [blame] | 1703 | $<TARGET_PROPERTY:bintools,readelf_flag_final> |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1704 | ) |
| 1705 | list(APPEND |
| 1706 | post_build_byproducts |
| 1707 | ${KERNEL_STAT_NAME} |
| 1708 | ) |
| 1709 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1710 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1711 | if(CONFIG_BUILD_OUTPUT_STRIPPED) |
| 1712 | list(APPEND |
| 1713 | post_build_commands |
Torsten Rasmussen | c060b07 | 2020-08-18 14:46:06 +0200 | [diff] [blame] | 1714 | COMMAND $<TARGET_PROPERTY:bintools,strip_command> |
| 1715 | $<TARGET_PROPERTY:bintools,strip_flag> |
| 1716 | $<TARGET_PROPERTY:bintools,strip_flag_all> |
| 1717 | $<TARGET_PROPERTY:bintools,strip_flag_infile>${KERNEL_ELF_NAME} |
| 1718 | $<TARGET_PROPERTY:bintools,strip_flag_outfile>${KERNEL_STRIP_NAME} |
Torsten Rasmussen | f160dee | 2020-09-04 10:05:00 +0200 | [diff] [blame] | 1719 | $<TARGET_PROPERTY:bintools,strip_flag_final> |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1720 | ) |
| 1721 | list(APPEND |
| 1722 | post_build_byproducts |
| 1723 | ${KERNEL_STRIP_NAME} |
| 1724 | ) |
| 1725 | endif() |
| 1726 | |
| 1727 | if(CONFIG_BUILD_OUTPUT_EXE) |
| 1728 | list(APPEND |
| 1729 | post_build_commands |
| 1730 | COMMAND |
| 1731 | ${CMAKE_COMMAND} -E copy ${KERNEL_ELF_NAME} ${KERNEL_EXE_NAME} |
| 1732 | ) |
| 1733 | list(APPEND |
| 1734 | post_build_byproducts |
| 1735 | ${KERNEL_EXE_NAME} |
| 1736 | ) |
| 1737 | endif() |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1738 | |
Torsten Rasmussen | c8ddc34 | 2022-01-10 11:02:26 +0100 | [diff] [blame] | 1739 | if(CONFIG_BUILD_OUTPUT_INFO_HEADER) |
| 1740 | list(APPEND |
| 1741 | post_build_commands |
Anas Nashif | 09b4bec | 2022-07-11 10:55:13 -0400 | [diff] [blame] | 1742 | COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/gen_image_info.py |
Torsten Rasmussen | c8ddc34 | 2022-01-10 11:02:26 +0100 | [diff] [blame] | 1743 | --elf-file=${KERNEL_ELF_NAME} |
| 1744 | --header-file=${PROJECT_BINARY_DIR}/include/public/zephyr_image_info.h |
Torsten Rasmussen | d51a67b | 2022-01-12 14:21:07 +0100 | [diff] [blame] | 1745 | $<$<BOOL:${adjustment}>:--adjusted-lma=${adjustment}> |
Torsten Rasmussen | c8ddc34 | 2022-01-10 11:02:26 +0100 | [diff] [blame] | 1746 | ) |
| 1747 | list(APPEND |
| 1748 | post_build_byproducts |
| 1749 | ${PROJECT_BINARY_DIR}/include/public/zephyr_image_info.h |
| 1750 | ) |
| 1751 | endif() |
| 1752 | |
Martí Bolívar | f66a0c3 | 2020-08-18 11:28:04 -0700 | [diff] [blame] | 1753 | # Generate and use MCUboot related artifacts as needed. |
| 1754 | if(CONFIG_BOOTLOADER_MCUBOOT) |
Jamie McCrae | 176c805 | 2023-03-23 13:42:33 +0000 | [diff] [blame] | 1755 | get_target_property(signing_script zephyr_property_target SIGNING_SCRIPT) |
| 1756 | if(NOT signing_script) |
| 1757 | set_target_properties(zephyr_property_target PROPERTIES SIGNING_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/cmake/mcuboot.cmake) |
| 1758 | endif() |
| 1759 | endif() |
| 1760 | |
| 1761 | # Include signing script, if set |
| 1762 | get_target_property(signing_script zephyr_property_target SIGNING_SCRIPT) |
| 1763 | if(signing_script) |
| 1764 | message(STATUS "Including signing script: ${signing_script}") |
| 1765 | |
| 1766 | include(${signing_script}) |
Martí Bolívar | f66a0c3 | 2020-08-18 11:28:04 -0700 | [diff] [blame] | 1767 | endif() |
| 1768 | |
Madhurima Paruchuri | fa738b0 | 2022-10-26 13:34:09 +0000 | [diff] [blame] | 1769 | # Generate USB-C VIF policies in XML format |
| 1770 | if (CONFIG_BUILD_OUTPUT_VIF) |
| 1771 | include(${CMAKE_CURRENT_LIST_DIR}/cmake/vif.cmake) |
| 1772 | endif() |
| 1773 | |
Rajavardhan Gundi | ecdea1c | 2019-01-25 11:53:13 +0530 | [diff] [blame] | 1774 | get_property(extra_post_build_commands |
| 1775 | GLOBAL PROPERTY |
| 1776 | extra_post_build_commands |
| 1777 | ) |
| 1778 | |
| 1779 | list(APPEND |
| 1780 | post_build_commands |
| 1781 | ${extra_post_build_commands} |
| 1782 | ) |
| 1783 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1784 | get_property(extra_post_build_byproducts |
| 1785 | GLOBAL PROPERTY |
| 1786 | extra_post_build_byproducts |
| 1787 | ) |
| 1788 | |
| 1789 | list(APPEND |
| 1790 | post_build_byproducts |
| 1791 | ${extra_post_build_byproducts} |
| 1792 | ) |
| 1793 | |
Krzysztof Chruscinski | 3392301 | 2022-03-29 15:47:01 +0200 | [diff] [blame] | 1794 | if(CONFIG_LOG_DICTIONARY_DB) |
Daniel Leung | 1c9e89c | 2022-01-26 14:44:55 -0800 | [diff] [blame] | 1795 | set(log_dict_db_output --json=${PROJECT_BINARY_DIR}/log_dictionary.json) |
Daniel Leung | ba488d1 | 2022-02-04 13:18:13 -0800 | [diff] [blame] | 1796 | elseif(CONFIG_LOG_MIPI_SYST_USE_CATALOG) |
| 1797 | set(log_dict_db_output --syst=${PROJECT_BINARY_DIR}/mipi_syst_collateral.xml) |
| 1798 | endif() |
Daniel Leung | a5ab1a7 | 2021-04-02 12:54:53 -0700 | [diff] [blame] | 1799 | |
Daniel Leung | ba488d1 | 2022-02-04 13:18:13 -0800 | [diff] [blame] | 1800 | if(log_dict_db_output) |
Daniel Leung | a5ab1a7 | 2021-04-02 12:54:53 -0700 | [diff] [blame] | 1801 | list(APPEND |
| 1802 | post_build_commands |
| 1803 | COMMAND |
| 1804 | ${PYTHON_EXECUTABLE} |
| 1805 | ${ZEPHYR_BASE}/scripts/logging/dictionary/database_gen.py |
| 1806 | ${KERNEL_ELF_NAME} |
Daniel Leung | 1c9e89c | 2022-01-26 14:44:55 -0800 | [diff] [blame] | 1807 | ${log_dict_db_output} |
Torsten Rasmussen | 9170977 | 2022-02-04 10:27:13 +0100 | [diff] [blame] | 1808 | --build-header ${PROJECT_BINARY_DIR}/include/generated/version.h |
Daniel Leung | a5ab1a7 | 2021-04-02 12:54:53 -0700 | [diff] [blame] | 1809 | ) |
| 1810 | list(APPEND |
| 1811 | post_build_byproducts |
| 1812 | ${LOG_DICT_DB_NAME} |
| 1813 | ) |
Daniel Leung | 1c9e89c | 2022-01-26 14:44:55 -0800 | [diff] [blame] | 1814 | |
| 1815 | unset(log_dict_db_output) |
Daniel Leung | a5ab1a7 | 2021-04-02 12:54:53 -0700 | [diff] [blame] | 1816 | endif() |
| 1817 | |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1818 | # Add post_build_commands to post-process the final .elf file produced by |
Jordan Yates | 28b2e55 | 2021-10-20 20:19:28 +1000 | [diff] [blame] | 1819 | # either the ZEPHYR_LINK_STAGE_EXECUTABLE or the KERNEL_ELF executable |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1820 | # targets above. |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1821 | add_custom_command( |
| 1822 | TARGET ${logical_target_for_zephyr_elf} |
| 1823 | POST_BUILD |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1824 | ${post_build_commands} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1825 | BYPRODUCTS |
| 1826 | ${post_build_byproducts} |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1827 | COMMENT "Generating files from ${KERNEL_ELF_NAME} for board: ${BOARD}" |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1828 | COMMAND_EXPAND_LISTS |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1829 | # NB: COMMENT only works for some CMake-Generators |
Rajavardhan Gundi | ecdea1c | 2019-01-25 11:53:13 +0530 | [diff] [blame] | 1830 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1831 | |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1832 | # To populate with hex files to merge, do the following: |
| 1833 | # set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE ${my_local_list}) |
| 1834 | # Note that the zephyr.hex file will not be included automatically. |
| 1835 | get_property(HEX_FILES_TO_MERGE GLOBAL PROPERTY HEX_FILES_TO_MERGE) |
| 1836 | if(HEX_FILES_TO_MERGE) |
| 1837 | # Merge in out-of-tree hex files. |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1838 | set(MERGED_HEX_NAME merged.hex) |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1839 | |
| 1840 | add_custom_command( |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1841 | OUTPUT ${MERGED_HEX_NAME} |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1842 | COMMAND |
| 1843 | ${PYTHON_EXECUTABLE} |
Anas Nashif | 72e7fa8 | 2022-07-11 10:55:37 -0400 | [diff] [blame] | 1844 | ${ZEPHYR_BASE}/scripts/build/mergehex.py |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1845 | -o ${MERGED_HEX_NAME} |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1846 | ${HEX_FILES_TO_MERGE} |
| 1847 | DEPENDS ${HEX_FILES_TO_MERGE} ${logical_target_for_zephyr_elf} |
| 1848 | ) |
| 1849 | |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1850 | add_custom_target(mergehex ALL DEPENDS ${MERGED_HEX_NAME}) |
Torsten Rasmussen | d38da9d | 2020-06-30 09:55:54 +0200 | [diff] [blame] | 1851 | list(APPEND RUNNERS_DEPS mergehex) |
Håkon Øye Amundsen | c9a2a5e | 2020-01-03 08:25:03 +0000 | [diff] [blame] | 1852 | |
| 1853 | message(VERBOSE "Merging hex files: ${HEX_FILES_TO_MERGE}") |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1854 | endif() |
| 1855 | |
Filip Kokosinski | 9442804 | 2021-08-30 13:09:48 +0200 | [diff] [blame] | 1856 | if(SUPPORTED_EMU_PLATFORMS) |
| 1857 | list(GET SUPPORTED_EMU_PLATFORMS 0 default_emu) |
Anas Nashif | a1d1810 | 2022-02-14 22:08:42 -0500 | [diff] [blame] | 1858 | if(EXISTS ${ZEPHYR_BASE}/cmake/emu/${default_emu}.cmake) |
| 1859 | add_custom_target(run DEPENDS run_${default_emu}) |
| 1860 | endif() |
Filip Kokosinski | 9442804 | 2021-08-30 13:09:48 +0200 | [diff] [blame] | 1861 | |
| 1862 | foreach(EMU_PLATFORM ${SUPPORTED_EMU_PLATFORMS}) |
Anas Nashif | a1d1810 | 2022-02-14 22:08:42 -0500 | [diff] [blame] | 1863 | if(EXISTS ${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake) |
| 1864 | include(${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake) |
| 1865 | endif() |
Filip Kokosinski | 9442804 | 2021-08-30 13:09:48 +0200 | [diff] [blame] | 1866 | endforeach() |
| 1867 | |
| 1868 | if(TARGET debugserver_${default_emu}) |
| 1869 | add_custom_target(debugserver DEPENDS debugserver_${default_emu}) |
| 1870 | endif() |
Anas Nashif | fd276ae | 2017-12-21 16:45:45 -0500 | [diff] [blame] | 1871 | else() |
| 1872 | add_custom_target(run |
| 1873 | COMMAND |
| 1874 | ${CMAKE_COMMAND} -E echo |
| 1875 | "===================================================" |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 1876 | "Emulation/Simulation not supported with this board." |
Anas Nashif | fd276ae | 2017-12-21 16:45:45 -0500 | [diff] [blame] | 1877 | "===================================================" |
| 1878 | ) |
Anas Nashif | c15d3c9 | 2017-11-21 18:54:55 -0500 | [diff] [blame] | 1879 | endif() |
| 1880 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1881 | add_subdirectory(cmake/flash) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1882 | add_subdirectory(cmake/usage) |
| 1883 | add_subdirectory(cmake/reports) |
| 1884 | |
Marc Herbert | 8372310 | 2019-06-17 13:26:11 -0700 | [diff] [blame] | 1885 | if(NOT CONFIG_TEST) |
Andrew Boie | 411686f | 2018-05-24 13:18:36 -0700 | [diff] [blame] | 1886 | if(CONFIG_ASSERT AND (NOT CONFIG_FORCE_NO_ASSERT)) |
Sebastian Bøe | fa8f9d4 | 2019-12-06 12:54:53 +0100 | [diff] [blame] | 1887 | message(WARNING "__ASSERT() statements are globally ENABLED") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1888 | endif() |
Marc Herbert | 8372310 | 2019-06-17 13:26:11 -0700 | [diff] [blame] | 1889 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1890 | |
Vincent Wan | a2bc514 | 2020-01-09 14:20:44 -0800 | [diff] [blame] | 1891 | if(CONFIG_BOARD_DEPRECATED_RELEASE) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1892 | message(WARNING " |
| 1893 | WARNING: The board '${BOARD}' is deprecated and will be |
Vincent Wan | a2bc514 | 2020-01-09 14:20:44 -0800 | [diff] [blame] | 1894 | removed in version ${CONFIG_BOARD_DEPRECATED_RELEASE}" |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 1895 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1896 | endif() |
Paul Sokolovsky | 1c6a7d7 | 2019-06-06 21:12:14 +0300 | [diff] [blame] | 1897 | |
Vincent Wan | 180b4df | 2020-01-08 17:10:51 -0800 | [diff] [blame] | 1898 | if(CONFIG_SOC_DEPRECATED_RELEASE) |
| 1899 | message(WARNING " |
| 1900 | WARNING: The SoC '${SOC_NAME}' is deprecated and will be |
| 1901 | removed in version ${CONFIG_SOC_DEPRECATED_RELEASE}" |
| 1902 | ) |
| 1903 | endif() |
| 1904 | |
Sebastian Bøe | e50e12d | 2019-08-29 16:19:32 +0200 | [diff] [blame] | 1905 | # In CMake projects, 'CMAKE_BUILD_TYPE' usually determines the |
| 1906 | # optimization flag, but in Zephyr it is determined through |
| 1907 | # Kconfig. Here we give a warning when there is a mismatch between the |
| 1908 | # two in case the user is not aware of this. |
| 1909 | set(build_types None Debug Release RelWithDebInfo MinSizeRel) |
| 1910 | |
| 1911 | if((CMAKE_BUILD_TYPE IN_LIST build_types) AND (NOT NO_BUILD_TYPE_WARNING)) |
| 1912 | string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_uppercase) |
Torsten Rasmussen | 05bb855 | 2021-12-10 15:06:30 +0100 | [diff] [blame] | 1913 | # The CMAKE_C_FLAGS_<build_type> is a string, so we do a regex to see if the |
| 1914 | # optimization flag is present in that string. |
| 1915 | # To avoid false-positive matches, the flag must either be matched first |
| 1916 | # or last in string, or come after / followed by minimum a space. |
| 1917 | if(NOT (CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_uppercase} MATCHES "(^| )${OPTIMIZATION_FLAG}($| )")) |
Sebastian Bøe | e50e12d | 2019-08-29 16:19:32 +0200 | [diff] [blame] | 1918 | message(WARNING " |
| 1919 | The CMake build type was set to '${CMAKE_BUILD_TYPE}', but the optimization flag was set to '${OPTIMIZATION_FLAG}'. |
| 1920 | This may be intentional and the warning can be turned off by setting the CMake variable 'NO_BUILD_TYPE_WARNING'" |
| 1921 | ) |
| 1922 | endif() |
| 1923 | endif() |
| 1924 | |
Stephanos Ioannidis | fd4700d | 2021-09-11 22:06:28 +0900 | [diff] [blame] | 1925 | # @Intent: Set compiler specific flags for standard C/C++ includes |
Paul Sokolovsky | 1c6a7d7 | 2019-06-06 21:12:14 +0300 | [diff] [blame] | 1926 | # Done at the very end, so any other system includes which may |
| 1927 | # be added by Zephyr components were first in list. |
Torsten Rasmussen | c55c64e | 2020-08-18 14:47:53 +0200 | [diff] [blame] | 1928 | # Note, the compile flags are moved, but the system include is still present here. |
| 1929 | zephyr_compile_options($<TARGET_PROPERTY:compiler,nostdinc>) |
| 1930 | target_include_directories(zephyr_interface SYSTEM INTERFACE $<TARGET_PROPERTY:compiler,nostdinc_include>) |
Torsten Rasmussen | a5917f0 | 2020-09-09 15:42:32 +0200 | [diff] [blame] | 1931 | |
Stephanos Ioannidis | cf211aa | 2022-12-10 03:19:58 +0900 | [diff] [blame] | 1932 | if(CONFIG_MINIMAL_LIBCPP) |
Stephanos Ioannidis | fd4700d | 2021-09-11 22:06:28 +0900 | [diff] [blame] | 1933 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,nostdincxx>>) |
| 1934 | endif() |
| 1935 | |
Torsten Rasmussen | a5917f0 | 2020-09-09 15:42:32 +0200 | [diff] [blame] | 1936 | # Finally export all build flags from Zephyr |
| 1937 | add_subdirectory_ifdef( |
| 1938 | CONFIG_MAKEFILE_EXPORTS |
| 1939 | cmake/makefile_exports |
| 1940 | ) |