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