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 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 39 | # Verify that the toolchain can compile a dummy file, if it is not we |
Anas Nashif | f2cb20c | 2019-06-18 14:45:40 -0400 | [diff] [blame] | 40 | # won't be able to test for compatibility with certain C flags. |
Sebastian Bøe | 6212ec9 | 2019-08-28 13:02:51 +0200 | [diff] [blame] | 41 | zephyr_check_compiler_flag(C "" toolchain_is_ok) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 42 | assert(toolchain_is_ok "The toolchain is unable to build a dummy C file. See CMakeError.log.") |
| 43 | |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 44 | # In some cases the "final" things are not used at all and "_prebuilt" |
| 45 | # is the last station. See "logical_target_for_zephyr_elf" below for |
| 46 | # details. |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 47 | set(CMAKE_EXECUTABLE_SUFFIX .elf) |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 48 | set(ZEPHYR_PREBUILT_EXECUTABLE zephyr_prebuilt) |
Mark Ruvald Pedersen | 37d4947 | 2019-05-07 15:20:20 +0200 | [diff] [blame] | 49 | set(ZEPHYR_FINAL_EXECUTABLE zephyr_final) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 50 | |
Mark Ruvald Pedersen | 11d6bae | 2019-04-29 16:57:37 +0200 | [diff] [blame] | 51 | # Set some phony targets to collect dependencies |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 52 | set(OFFSETS_H_TARGET offsets_h) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 53 | set(SYSCALL_LIST_H_TARGET syscall_list_h_target) |
| 54 | set(DRIVER_VALIDATION_H_TARGET driver_validation_h_target) |
| 55 | set(KOBJ_TYPES_H_TARGET kobj_types_h_target) |
| 56 | set(LINKER_SCRIPT_TARGET linker_script_target) |
Andrew Boie | c1c54b1 | 2020-03-16 12:48:00 -0700 | [diff] [blame] | 57 | set(PARSE_SYSCALLS_TARGET parse_syscalls_target) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 58 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 59 | define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT BRIEF_DOCS " " FULL_DOCS " ") |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 60 | 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] | 61 | |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 62 | # "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] | 63 | # compiler options needed by all source files. All zephyr libraries, |
| 64 | # including the library named "zephyr" link with this library to |
| 65 | # obtain these flags. |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 66 | # 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] | 67 | add_library(zephyr_interface INTERFACE) |
| 68 | |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 69 | # "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] | 70 | # built purely with the include paths, defines, and other compiler |
| 71 | # flags that come with zephyr_interface. |
| 72 | zephyr_library_named(zephyr) |
| 73 | |
| 74 | zephyr_include_directories( |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 75 | include |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 76 | ${PROJECT_BINARY_DIR}/include/generated |
| 77 | ${USERINCLUDE} |
| 78 | ${STDINCLUDE} |
| 79 | ) |
| 80 | |
Sebastian Bøe | 4036339 | 2019-01-25 10:14:13 +0100 | [diff] [blame] | 81 | # Don't add non-existing include directories, it creates noise and |
| 82 | # warnings in some tooling |
| 83 | foreach(optional_include_dir |
| 84 | ${SOC_DIR}/${ARCH}/${SOC_PATH} |
| 85 | ${SOC_DIR}/${ARCH}/${SOC_PATH}/include |
| 86 | ${SOC_DIR}/${ARCH}/${SOC_FAMILY}/include |
| 87 | ) |
| 88 | if(EXISTS ${optional_include_dir}) |
| 89 | zephyr_include_directories(${optional_include_dir}) |
| 90 | endif() |
| 91 | endforeach() |
| 92 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 93 | zephyr_compile_definitions( |
| 94 | KERNEL |
| 95 | __ZEPHYR__=1 |
Anas Nashif | 34aebad | 2018-01-03 12:26:19 -0500 | [diff] [blame] | 96 | ) |
| 97 | |
Mark Ruvald Pedersen | 0159207 | 2019-01-10 12:07:51 +0100 | [diff] [blame] | 98 | # @Intent: Set compiler flags to enable buffer overflow checks in libc functions |
| 99 | # @config in CONFIG_NO_OPTIMIZATIONS optional : Optimizations may affect security |
| 100 | toolchain_cc_security_fortify() |
| 101 | |
| 102 | # @Intent: Set compiler flags to detect general stack overflows across all functions |
| 103 | if(CONFIG_STACK_CANARIES) |
| 104 | toolchain_cc_security_canaries() |
Anas Nashif | 34aebad | 2018-01-03 12:26:19 -0500 | [diff] [blame] | 105 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 106 | |
Anas Nashif | daf7716 | 2018-04-09 21:53:26 -0500 | [diff] [blame] | 107 | if(BUILD_VERSION) |
| 108 | zephyr_compile_definitions( |
| 109 | BUILD_VERSION=${BUILD_VERSION} |
| 110 | ) |
| 111 | endif() |
| 112 | |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 113 | # @Intent: Obtain compiler optimizations flags and store in variables |
| 114 | # @details: |
| 115 | # Kconfig.zephyr "Optimization level" is a kconfig choice, ensuring |
| 116 | # only *one* of CONFIG_{NO,DEBUG,SPEED,SIZE}_OPTIMIZATIONS is set. |
| 117 | # Refer to Kconfig.zephyr for selection logic and description of these choices. |
| 118 | # toolchain_cc_optimize_*() macros must provide the mapping from these kconfigs |
| 119 | # to compiler flags. Each macro will store the flags in a CMake variable, whose |
| 120 | # name is passed as argument (somewhat like by reference). |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 121 | # |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 122 | # If the user wants to tweak the optimizations, there are two ways: |
| 123 | # 1) Using EXTRA_CFLAGS which is applied regardless of kconfig choice, or |
| 124 | # 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] | 125 | # |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 126 | toolchain_cc_optimize_for_no_optimizations_flag(OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG) |
| 127 | toolchain_cc_optimize_for_debug_flag(OPTIMIZE_FOR_DEBUG_FLAG) |
| 128 | toolchain_cc_optimize_for_speed_flag(OPTIMIZE_FOR_SPEED_FLAG) |
| 129 | toolchain_cc_optimize_for_size_flag(OPTIMIZE_FOR_SIZE_FLAG) |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 130 | |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 131 | # From kconfig choice, pick the actual OPTIMIZATION_FLAG to use. |
| 132 | # Kconfig choice ensures only one of these CONFIG_*_OPTIMIZATIONS is set. |
Alberto Escolar Piedras | f60527a | 2018-01-22 15:35:54 +0100 | [diff] [blame] | 133 | if(CONFIG_NO_OPTIMIZATIONS) |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 134 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_NO_OPTIMIZATIONS_FLAG}) |
| 135 | elseif(CONFIG_DEBUG_OPTIMIZATIONS) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 136 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_DEBUG_FLAG}) |
Aurelien Jarno | e8413d1 | 2018-06-16 23:40:04 +0200 | [diff] [blame] | 137 | elseif(CONFIG_SPEED_OPTIMIZATIONS) |
| 138 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SPEED_FLAG}) |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 139 | elseif(CONFIG_SIZE_OPTIMIZATIONS) |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 140 | set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SIZE_FLAG}) # Default in kconfig |
Sebastian Bøe | 600c8f7 | 2018-01-24 10:40:32 +0100 | [diff] [blame] | 141 | else() |
Anas Nashif | 885aaf2 | 2019-01-18 19:15:19 -0500 | [diff] [blame] | 142 | assert(0 "Unreachable code. Expected optimization level to have been chosen. See Kconfig.zephyr") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 143 | endif() |
| 144 | |
Ulf Magnusson | de42aea | 2020-02-07 00:48:22 +0100 | [diff] [blame] | 145 | if(NOT CONFIG_ARCH_IS_SET) |
| 146 | message(WARNING "\ |
| 147 | None of the CONFIG_<arch> (e.g. CONFIG_X86) symbols are set. \ |
| 148 | Select one of them from the SOC_SERIES_* symbol or, lacking that, from the \ |
| 149 | SOC_* symbol.") |
| 150 | endif() |
| 151 | |
Mark Ruvald Pedersen | 0b3c65f | 2019-01-30 10:12:30 +0100 | [diff] [blame] | 152 | # Apply the final optimization flag(s) |
| 153 | zephyr_compile_options(${OPTIMIZATION_FLAG}) |
| 154 | |
Mark Ruvald Pedersen | 63df409 | 2019-02-18 23:54:30 +0100 | [diff] [blame] | 155 | # @Intent: Obtain compiler specific flags related to C++ that are not influenced by kconfig |
| 156 | toolchain_cc_cpp_base_flags(CPP_BASE_FLAGS) |
| 157 | foreach(flag ${CPP_BASE_FLAGS}) |
| 158 | zephyr_compile_options( |
| 159 | $<$<COMPILE_LANGUAGE:CXX>:${flag}> |
| 160 | ) |
| 161 | endforeach() |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 162 | |
Mark Ruvald Pedersen | 63df409 | 2019-02-18 23:54:30 +0100 | [diff] [blame] | 163 | # @Intent: Obtain compiler specific flags for compiling under different ISO standards of C++ |
| 164 | toolchain_cc_cpp_dialect_std_98_flags(CPP_DIALECT_STD_98_FLAGS) |
| 165 | toolchain_cc_cpp_dialect_std_11_flags(CPP_DIALECT_STD_11_FLAGS) |
| 166 | toolchain_cc_cpp_dialect_std_14_flags(CPP_DIALECT_STD_14_FLAGS) |
| 167 | toolchain_cc_cpp_dialect_std_17_flags(CPP_DIALECT_STD_17_FLAGS) |
| 168 | toolchain_cc_cpp_dialect_std_2a_flags(CPP_DIALECT_STD_2A_FLAGS) |
| 169 | |
Ulf Magnusson | 9b6c2f4 | 2019-05-15 23:01:58 +0200 | [diff] [blame] | 170 | if(CONFIG_CPLUSPLUS) |
| 171 | # From kconfig choice, pick a single dialect. |
| 172 | # Kconfig choice ensures only one of these CONFIG_STD_CPP* is set. |
| 173 | if(CONFIG_STD_CPP98) |
| 174 | set(STD_CPP_DIALECT_FLAGS ${CPP_DIALECT_STD_98_FLAGS}) |
| 175 | elseif(CONFIG_STD_CPP11) |
| 176 | set(STD_CPP_DIALECT_FLAGS ${CPP_DIALECT_STD_11_FLAGS}) # Default in kconfig |
| 177 | elseif(CONFIG_STD_CPP14) |
| 178 | set(STD_CPP_DIALECT_FLAGS ${CPP_DIALECT_STD_14_FLAGS}) |
| 179 | elseif(CONFIG_STD_CPP17) |
| 180 | set(STD_CPP_DIALECT_FLAGS ${CPP_DIALECT_STD_17_FLAGS}) |
| 181 | elseif(CONFIG_STD_CPP2A) |
| 182 | set(STD_CPP_DIALECT_FLAGS ${CPP_DIALECT_STD_2A_FLAGS}) |
| 183 | else() |
| 184 | assert(0 "Unreachable code. Expected C++ standard to have been chosen. See Kconfig.zephyr.") |
| 185 | endif() |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 186 | |
Ulf Magnusson | 9b6c2f4 | 2019-05-15 23:01:58 +0200 | [diff] [blame] | 187 | foreach(flag ${STD_CPP_DIALECT_FLAGS}) |
| 188 | zephyr_compile_options( |
| 189 | $<$<COMPILE_LANGUAGE:CXX>:${flag}> |
| 190 | ) |
| 191 | endforeach() |
| 192 | endif() |
Mark Ruvald Pedersen | 63df409 | 2019-02-18 23:54:30 +0100 | [diff] [blame] | 193 | |
| 194 | if(NOT CONFIG_EXCEPTIONS) |
| 195 | # @Intent: Obtain compiler specific flags related to C++ Exceptions |
| 196 | toolchain_cc_cpp_no_exceptions_flag(CPP_NO_EXCEPTIONS_FLAG) |
| 197 | zephyr_compile_options( |
| 198 | $<$<COMPILE_LANGUAGE:CXX>:${CPP_NO_EXCEPTIONS_FLAG}> |
| 199 | ) |
| 200 | endif() |
| 201 | |
| 202 | if(NOT CONFIG_RTTI) |
| 203 | # @Intent: Obtain compiler specific flags related to C++ Run Time Type Information |
| 204 | toolchain_cc_cpp_no_rtti_flag(CPP_NO_RTTI_FLAG) |
| 205 | zephyr_compile_options( |
| 206 | $<$<COMPILE_LANGUAGE:CXX>:${CPP_NO_RTTI_FLAG}> |
| 207 | ) |
| 208 | endif() |
| 209 | |
Andy Ross | fe04adf | 2019-02-27 11:53:18 -0800 | [diff] [blame] | 210 | if(CONFIG_MISRA_SANE) |
Danny Oerndrup | 8e5a95e | 2019-05-16 12:53:58 +0200 | [diff] [blame] | 211 | # @Intent: Obtain toolchain compiler flags relating to MISRA. |
| 212 | toolchain_cc_warning_error_misra_sane(CC_MISRA_SANE_FLAG) |
| 213 | toolchain_cc_cpp_warning_error_misra_sane(CPP_MISRA_SANE_FLAG) |
| 214 | zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:${CC_MISRA_SANE_FLAG}>) |
| 215 | zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:${CPP_MISRA_SANE_FLAG}>) |
Andy Ross | fe04adf | 2019-02-27 11:53:18 -0800 | [diff] [blame] | 216 | endif() |
| 217 | |
Danny Oerndrup | 4ddbc00 | 2019-06-11 13:55:53 +0200 | [diff] [blame] | 218 | # @Intent: Set compiler specific macro inclusion of AUTOCONF_H |
| 219 | toolchain_cc_imacros(${AUTOCONF_H}) |
| 220 | |
Danny Oerndrup | faa72b7 | 2019-06-11 15:56:57 +0200 | [diff] [blame] | 221 | # @Intent: Set compiler specific flag for bare metal freestanding option |
| 222 | toolchain_cc_freestanding() |
| 223 | |
Danny Oerndrup | e34ed7c | 2019-06-12 14:56:46 +0200 | [diff] [blame] | 224 | # @Intent: Set compiler specific flag for tentative definitions, no-common |
| 225 | toolchain_cc_nocommon() |
| 226 | |
Danny Oerndrup | e0569ac | 2019-07-23 09:00:55 +0200 | [diff] [blame] | 227 | # @Intent: Set compiler specific flag for production of debug information |
| 228 | toolchain_cc_produce_debug_info() |
| 229 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 230 | zephyr_compile_options( |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 231 | ${TOOLCHAIN_C_FLAGS} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 232 | ) |
| 233 | |
Mark Ruvald Pedersen | cb0fd45 | 2019-01-30 21:48:25 +0100 | [diff] [blame] | 234 | # @Intent: Obtain compiler specific flags related to assembly |
| 235 | toolchain_cc_asm_base_flags(ASM_BASE_FLAG) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 236 | zephyr_compile_options( |
Mark Ruvald Pedersen | cb0fd45 | 2019-01-30 21:48:25 +0100 | [diff] [blame] | 237 | $<$<COMPILE_LANGUAGE:ASM>:${ASM_BASE_FLAG}> |
| 238 | ) |
| 239 | |
Nicolas Pitre | b86aa65 | 2019-07-02 16:22:04 -0400 | [diff] [blame] | 240 | # @Intent: Enforce standard integer type correspondance to match Zephyr usage. |
| 241 | # (must be after compiler specific flags) |
| 242 | toolchain_cc_imacros(${ZEPHYR_BASE}/include/toolchain/zephyr_stdint.h) |
| 243 | |
Mark Ruvald Pedersen | cb0fd45 | 2019-01-30 21:48:25 +0100 | [diff] [blame] | 244 | # Common toolchain-agnostic assembly flags |
| 245 | zephyr_compile_options( |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 246 | $<$<COMPILE_LANGUAGE:ASM>:-D_ASMLANGUAGE> |
| 247 | ) |
| 248 | |
Mark Ruvald Pedersen | 1f01325 | 2019-04-25 15:46:11 +0200 | [diff] [blame] | 249 | # @Intent: Set fundamental linker specific flags |
| 250 | toolchain_ld_base() |
Aurelien Jarno | c6727d4 | 2018-11-26 13:48:34 +0100 | [diff] [blame] | 251 | |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 252 | toolchain_ld_force_undefined_symbols( |
| 253 | _OffsetAbsSyms |
| 254 | _ConfigAbsSyms |
| 255 | ) |
| 256 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 257 | if(NOT CONFIG_NATIVE_APPLICATION) |
Mark Ruvald Pedersen | 65f02c0 | 2019-04-25 16:31:30 +0200 | [diff] [blame] | 258 | # @Intent: Set linker specific flags for bare metal target |
| 259 | toolchain_ld_baremetal() |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 260 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 261 | |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 262 | if(CONFIG_LIB_CPLUSPLUS) |
Mark Ruvald Pedersen | 3db09aa | 2019-04-26 08:43:04 +0200 | [diff] [blame] | 263 | # @Intent: Set linker specific flags for C++ |
| 264 | toolchain_ld_cpp() |
Benoit Leforestier | 26e0f9a | 2018-10-23 18:20:51 +0200 | [diff] [blame] | 265 | endif() |
| 266 | |
Danny Oerndrup | 8eaa906 | 2019-05-16 12:49:31 +0200 | [diff] [blame] | 267 | # @Intent: Add the basic toolchain warning flags |
Danny Oerndrup | bdb229f | 2019-05-06 15:19:27 +0200 | [diff] [blame] | 268 | toolchain_cc_warning_base() |
| 269 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 270 | # ========================================================================== |
| 271 | # |
| 272 | # cmake -DW=... settings |
| 273 | # |
| 274 | # W=1 - warnings that may be relevant and does not occur too often |
| 275 | # W=2 - warnings that occur quite often but may still be relevant |
| 276 | # W=3 - the more obscure warnings, can most likely be ignored |
| 277 | # ========================================================================== |
Danny Oerndrup | 8eaa906 | 2019-05-16 12:49:31 +0200 | [diff] [blame] | 278 | # @Intent: Add cmake -DW toolchain supported warnings, if any |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 279 | if(W MATCHES "1") |
Danny Oerndrup | 8650b15 | 2019-05-06 14:34:43 +0200 | [diff] [blame] | 280 | toolchain_cc_warning_dw_1() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 281 | endif() |
| 282 | |
| 283 | if(W MATCHES "2") |
Danny Oerndrup | 8650b15 | 2019-05-06 14:34:43 +0200 | [diff] [blame] | 284 | toolchain_cc_warning_dw_2() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 285 | endif() |
| 286 | |
| 287 | if(W MATCHES "3") |
Danny Oerndrup | 8650b15 | 2019-05-06 14:34:43 +0200 | [diff] [blame] | 288 | toolchain_cc_warning_dw_3() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 289 | endif() |
| 290 | |
Danny Oerndrup | 8eaa906 | 2019-05-16 12:49:31 +0200 | [diff] [blame] | 291 | # @Intent: Add extended, more specific, toolchain warning flags |
Danny Oerndrup | cbbbdea | 2019-05-06 15:21:58 +0200 | [diff] [blame] | 292 | toolchain_cc_warning_extended() |
Benoit Leforestier | 04dad59 | 2019-01-25 13:57:03 +0100 | [diff] [blame] | 293 | |
Danny Oerndrup | 025ffa2 | 2019-05-16 12:58:40 +0200 | [diff] [blame] | 294 | # @Intent: Trigger an error when a declaration does not specify a type |
| 295 | toolchain_cc_warning_error_implicit_int() |
| 296 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 297 | # Allow the user to inject options when calling cmake, e.g. |
| 298 | # 'cmake -DEXTRA_CFLAGS="-Werror -Wno-deprecated-declarations" ..' |
Sebastian Bøe | 9f59045 | 2017-11-10 12:22:23 +0100 | [diff] [blame] | 299 | include(cmake/extra_flags.cmake) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 300 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 301 | zephyr_cc_option(-fno-asynchronous-unwind-tables) |
| 302 | zephyr_cc_option(-fno-pie) |
| 303 | zephyr_cc_option(-fno-pic) |
| 304 | zephyr_cc_option(-fno-strict-overflow) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 305 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 306 | if(CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT) |
| 307 | if(CONFIG_OMIT_FRAME_POINTER) |
| 308 | zephyr_cc_option(-fomit-frame-pointer) |
| 309 | else() |
| 310 | zephyr_cc_option(-fno-omit-frame-pointer) |
| 311 | endif() |
| 312 | endif() |
| 313 | |
Sebastian Bøe | 244451b | 2019-02-27 08:28:25 +0100 | [diff] [blame] | 314 | separate_arguments(COMPILER_OPT_AS_LIST UNIX_COMMAND ${CONFIG_COMPILER_OPT}) |
| 315 | zephyr_compile_options(${COMPILER_OPT_AS_LIST}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 316 | |
| 317 | # TODO: Include arch compiler options at this point. |
| 318 | |
Danny Oerndrup | cbbbdea | 2019-05-06 15:21:58 +0200 | [diff] [blame] | 319 | if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") |
| 320 | # GCC assumed |
| 321 | zephyr_cc_option(-fno-reorder-functions) |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 322 | |
Anas Nashif | 7ee8bb9 | 2018-02-11 14:36:21 -0600 | [diff] [blame] | 323 | if(NOT ${ZEPHYR_TOOLCHAIN_VARIANT} STREQUAL "xcc") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 324 | zephyr_cc_option(-fno-defer-pop) |
| 325 | endif() |
| 326 | endif() |
| 327 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 328 | zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage) |
| 329 | |
Marc Herbert | 28a5657 | 2019-04-11 16:34:04 -0700 | [diff] [blame] | 330 | # If the compiler supports it, strip the ${ZEPHYR_BASE} prefix from the |
| 331 | # __FILE__ macro used in __ASSERT*, in the |
| 332 | # .noinit."/home/joe/zephyr/fu/bar.c" section names and in any |
| 333 | # application code. This saves some memory, stops leaking user locations |
| 334 | # in binaries, makes failure logs more deterministic and most |
| 335 | # importantly makes builds more deterministic |
Marc Herbert | f67dcdb | 2019-05-31 15:28:38 -0700 | [diff] [blame] | 336 | |
Marc Herbert | eddbf3c | 2019-06-11 16:57:37 -0700 | [diff] [blame] | 337 | # If several match then the last one wins. This matters for instances |
| 338 | # like tests/ and samples/: they're inside all of them! Then let's |
| 339 | # strip as little as possible. |
Marc Herbert | f67dcdb | 2019-05-31 15:28:38 -0700 | [diff] [blame] | 340 | zephyr_cc_option(-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=CMAKE_SOURCE_DIR) |
| 341 | zephyr_cc_option(-fmacro-prefix-map=${ZEPHYR_BASE}=ZEPHYR_BASE) |
Marc Herbert | eddbf3c | 2019-06-11 16:57:37 -0700 | [diff] [blame] | 342 | if(WEST_TOPDIR) |
| 343 | zephyr_cc_option(-fmacro-prefix-map=${WEST_TOPDIR}=WEST_TOPDIR) |
| 344 | endif() |
Marc Herbert | 28a5657 | 2019-04-11 16:34:04 -0700 | [diff] [blame] | 345 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 346 | # TODO: Archiver arguments |
| 347 | # ar_option(D) |
| 348 | |
Håkon Øye Amundsen | d6551b5 | 2018-11-29 09:08:08 +0000 | [diff] [blame] | 349 | # Declare MPU userspace dependencies before the linker scripts to make |
| 350 | # sure the order of dependencies are met |
Andrew Boie | 41f6011 | 2019-01-31 15:53:24 -0800 | [diff] [blame] | 351 | if(CONFIG_USERSPACE) |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 352 | set(APP_SMEM_ALIGNED_DEP app_smem_aligned_linker) |
| 353 | set(APP_SMEM_UNALIGNED_DEP app_smem_unaligned_linker) |
Håkon Øye Amundsen | d6551b5 | 2018-11-29 09:08:08 +0000 | [diff] [blame] | 354 | endif() |
| 355 | |
Håkon Øye Amundsen | a449439 | 2018-11-29 09:14:27 +0000 | [diff] [blame] | 356 | get_property(TOPT GLOBAL PROPERTY TOPT) |
Oleg Zhurakivskyy | 2211935 | 2019-03-08 11:29:33 +0200 | [diff] [blame] | 357 | set_ifndef( TOPT -Wl,-T) # clang doesn't pick -T for some reason and complains, |
| 358 | # while -Wl,-T works for both, gcc and clang |
Håkon Øye Amundsen | a449439 | 2018-11-29 09:14:27 +0000 | [diff] [blame] | 359 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 360 | if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT) |
| 361 | set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT}) |
Sebastian Bøe | c1aa9d1 | 2018-04-12 14:48:05 +0200 | [diff] [blame] | 362 | if(NOT EXISTS ${LINKER_SCRIPT}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 363 | set(LINKER_SCRIPT ${CONFIG_CUSTOM_LINKER_SCRIPT}) |
Sebastian Bøe | c1aa9d1 | 2018-04-12 14:48:05 +0200 | [diff] [blame] | 364 | assert_exists(CONFIG_CUSTOM_LINKER_SCRIPT) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 365 | endif() |
| 366 | else() |
| 367 | # Try a board specific linker file |
| 368 | set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld) |
| 369 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 370 | # If not available, try an SoC specific linker file |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 371 | set(LINKER_SCRIPT ${SOC_DIR}/${ARCH}/${SOC_PATH}/linker.ld) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 372 | endif() |
| 373 | endif() |
| 374 | |
| 375 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 376 | message(FATAL_ERROR "Could not find linker script: '${LINKER_SCRIPT}'. Corrupted configuration?") |
| 377 | endif() |
| 378 | |
| 379 | configure_file(version.h.in ${PROJECT_BINARY_DIR}/include/generated/version.h) |
| 380 | |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 381 | # Error-out when the deprecated naming convention is found (until |
| 382 | # after 1.14.0 has been released) |
| 383 | foreach(path |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 384 | ${BOARD_DIR}/dts.fixup |
| 385 | ${PROJECT_SOURCE_DIR}/soc/${ARCH}/${SOC_PATH}/dts.fixup |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 386 | ${APPLICATION_SOURCE_DIR}/dts.fixup |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 387 | ) |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 388 | if(EXISTS ${path}) |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 389 | message(FATAL_ERROR |
| 390 | "A deprecated filename has been detected. Porting is required." |
| 391 | "The file '${path}' exists, but it should be named dts_fixup.h instead." |
| 392 | "See https://github.com/zephyrproject-rtos/zephyr/pull/10352 for more details" |
| 393 | ) |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 394 | endif() |
| 395 | endforeach() |
| 396 | |
| 397 | set_ifndef( DTS_BOARD_FIXUP_FILE ${BOARD_DIR}/dts_fixup.h) |
| 398 | set_ifndef( DTS_SOC_FIXUP_FILE ${SOC_DIR}/${ARCH}/${SOC_PATH}/dts_fixup.h) |
| 399 | set( DTS_APP_FIXUP_FILE ${APPLICATION_SOURCE_DIR}/dts_fixup.h) |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 400 | |
Ulf Magnusson | 4e85006 | 2020-01-16 13:29:53 +0100 | [diff] [blame] | 401 | set_ifndef(DTS_CAT_OF_FIXUP_FILES ${ZEPHYR_BINARY_DIR}/include/generated/devicetree_fixups.h) |
Sebastian Bøe | 361fdaa | 2019-01-28 13:40:50 +0100 | [diff] [blame] | 402 | |
| 403 | # Concatenate the fixups into a single header file for easy |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 404 | # #include'ing |
Ulf Magnusson | 4e85006 | 2020-01-16 13:29:53 +0100 | [diff] [blame] | 405 | file(WRITE ${DTS_CAT_OF_FIXUP_FILES} "/* May only be included by devicetree.h */\n\n") |
Martí Bolívar | 21c7d42 | 2020-05-08 16:06:48 -0700 | [diff] [blame] | 406 | set(DISCOVERED_FIXUP_FILES) |
Sebastian Bøe | 361fdaa | 2019-01-28 13:40:50 +0100 | [diff] [blame] | 407 | foreach(fixup_file |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 408 | ${DTS_BOARD_FIXUP_FILE} |
| 409 | ${DTS_SOC_FIXUP_FILE} |
| 410 | ${DTS_APP_FIXUP_FILE} |
| 411 | ${shield_dts_fixups} |
| 412 | ) |
Sebastian Bøe | 361fdaa | 2019-01-28 13:40:50 +0100 | [diff] [blame] | 413 | if(EXISTS ${fixup_file}) |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 414 | file(READ ${fixup_file} contents) |
| 415 | file(APPEND ${DTS_CAT_OF_FIXUP_FILES} "${contents}") |
Martí Bolívar | 21c7d42 | 2020-05-08 16:06:48 -0700 | [diff] [blame] | 416 | string(APPEND DISCOVERED_FIXUP_FILES "- ${fixup_file}\n") |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 417 | endif() |
| 418 | endforeach() |
| 419 | |
Martí Bolívar | 21c7d42 | 2020-05-08 16:06:48 -0700 | [diff] [blame] | 420 | if (DISCOVERED_FIXUP_FILES) |
| 421 | message(WARNING "One or more dts_fixup.h files detected:\n${DISCOVERED_FIXUP_FILES}Use of these files is deprecated; use the devicetree.h API instead.") |
| 422 | endif() |
| 423 | |
Sebastian Bøe | 6f946e2 | 2018-01-09 10:52:57 +0100 | [diff] [blame] | 424 | # Unfortunately, the order in which CMakeLists.txt code is processed |
| 425 | # matters so we need to be careful about how we order the processing |
| 426 | # of subdirectories. One example is "Compiler flags added late in the |
| 427 | # build are not exported to external build systems #5605"; when we |
| 428 | # integrate with an external build system we read out all compiler |
| 429 | # flags when the external project is created. So an external project |
| 430 | # defined in subsys or ext will not get global flags added by drivers/ |
| 431 | # or tests/ as the subdirectories are ordered now. |
| 432 | # |
| 433 | # Another example of when the order matters is the reading and writing |
| 434 | # of global properties such as ZEPHYR_LIBS or |
| 435 | # GENERATED_KERNEL_OBJECT_FILES. |
| 436 | # |
| 437 | # Arch is placed early because it defines important compiler flags |
| 438 | # that must be exported to external build systems defined in |
| 439 | # e.g. subsys/. |
| 440 | add_subdirectory(arch) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 441 | add_subdirectory(lib) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 442 | # We use include instead of add_subdirectory to avoid creating a new directory scope. |
| 443 | # This is because source file properties are directory scoped, including the GENERATED |
| 444 | # property which is set implicitly for custom command outputs |
| 445 | include(misc/generated/CMakeLists.txt) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 446 | |
Erwan Gouriou | ba31cb5 | 2018-09-13 16:25:53 +0200 | [diff] [blame] | 447 | if(EXISTS ${SOC_DIR}/${ARCH}/CMakeLists.txt) |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 448 | add_subdirectory(${SOC_DIR}/${ARCH} soc/${ARCH}) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 449 | else() |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 450 | add_subdirectory(${SOC_DIR}/${ARCH}/${SOC_PATH} soc/${ARCH}/${SOC_PATH}) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 451 | endif() |
| 452 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 453 | add_subdirectory(boards) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 454 | add_subdirectory(subsys) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 455 | add_subdirectory(drivers) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 456 | |
Torsten Rasmussen | bd7569f | 2019-03-19 10:38:18 +0100 | [diff] [blame] | 457 | # Include zephyr modules generated CMake file. |
| 458 | if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt) |
Carles Cufi | 3ad1f27 | 2019-07-18 10:38:25 +0200 | [diff] [blame] | 459 | file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt ZEPHYR_MODULES_TXT |
| 460 | ENCODING UTF-8) |
Torsten Rasmussen | 08eabb8 | 2019-12-06 12:19:35 +0100 | [diff] [blame] | 461 | set(module_names) |
Torsten Rasmussen | bd7569f | 2019-03-19 10:38:18 +0100 | [diff] [blame] | 462 | |
| 463 | foreach(module ${ZEPHYR_MODULES_TXT}) |
Carles Cufi | 766edd4 | 2019-03-31 22:29:30 +0200 | [diff] [blame] | 464 | # Match "<name>":"<path>" for each line of file, each corresponding to |
| 465 | # one module. The use of quotes is required due to CMake not supporting |
| 466 | # lazy regexes (it supports greedy only). |
| 467 | string(REGEX REPLACE "\"(.*)\":\".*\"" "\\1" module_name ${module}) |
| 468 | string(REGEX REPLACE "\".*\":\"(.*)\"" "\\1" module_path ${module}) |
Torsten Rasmussen | 08eabb8 | 2019-12-06 12:19:35 +0100 | [diff] [blame] | 469 | |
| 470 | list(APPEND module_names ${module_name}) |
| 471 | |
| 472 | string(TOUPPER ${module_name} MODULE_NAME_UPPER) |
| 473 | set(ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR ${module_path}) |
Torsten Rasmussen | 2da4550 | 2020-05-06 23:58:34 +0200 | [diff] [blame] | 474 | set(ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR ${module_path} PARENT_SCOPE) |
Torsten Rasmussen | 08eabb8 | 2019-12-06 12:19:35 +0100 | [diff] [blame] | 475 | endforeach() |
| 476 | |
| 477 | foreach(module_name ${module_names}) |
Marc Herbert | d3d3394 | 2019-05-31 15:37:40 -0700 | [diff] [blame] | 478 | # Note the second, binary_dir parameter requires the added |
| 479 | # subdirectory to have its own, local cmake target(s). If not then |
| 480 | # this binary_dir is created but stays empty. Object files land in |
| 481 | # the main binary dir instead. |
| 482 | # https://cmake.org/pipermail/cmake/2019-June/069547.html |
Torsten Rasmussen | 08eabb8 | 2019-12-06 12:19:35 +0100 | [diff] [blame] | 483 | string(TOUPPER ${module_name} MODULE_NAME_UPPER) |
| 484 | set(ZEPHYR_CURRENT_MODULE_DIR ${ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR}) |
Torsten Rasmussen | 4b68f95 | 2020-01-09 12:31:58 +0100 | [diff] [blame] | 485 | add_subdirectory(${ZEPHYR_CURRENT_MODULE_DIR} ${CMAKE_BINARY_DIR}/modules/${module_name}) |
Torsten Rasmussen | bd7569f | 2019-03-19 10:38:18 +0100 | [diff] [blame] | 486 | endforeach() |
Torsten Rasmussen | f0fa7b8 | 2019-10-21 10:08:20 +0200 | [diff] [blame] | 487 | # Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR. |
| 488 | set(ZEPHYR_CURRENT_MODULE_DIR) |
Torsten Rasmussen | 605ae10 | 2019-02-12 10:19:38 +0100 | [diff] [blame] | 489 | endif() |
Torsten Rasmussen | 7e9d1bd | 2019-02-05 10:36:22 +0100 | [diff] [blame] | 490 | |
Andrew Boie | 5960119 | 2020-05-29 13:24:51 -0700 | [diff] [blame] | 491 | set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h) |
| 492 | set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json) |
| 493 | 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] | 494 | |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 495 | # The syscalls subdirs txt file is constructed by python containing a list of folders to use for |
| 496 | # dependency handling, including empty folders. |
| 497 | # Windows: The list is used to specify DIRECTORY list with CMAKE_CONFIGURE_DEPENDS attribute. |
| 498 | # Other OS: The list will update whenever a file is added/removed/modified and ensure a re-build. |
| 499 | set(syscalls_subdirs_txt ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_subdirs.txt) |
| 500 | |
| 501 | # As syscalls_subdirs_txt is updated whenever a file is modified, this file can not be used for |
| 502 | # monitoring of added / removed folders. A trigger file is thus used for correct dependency |
| 503 | # handling. The trigger file will update when a folder is added / removed. |
| 504 | set(syscalls_subdirs_trigger ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_subdirs.trigger) |
| 505 | |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 506 | if(NOT (${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)) |
| 507 | set(syscalls_links --create-links ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_links) |
| 508 | endif() |
| 509 | |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 510 | # When running CMake it must be ensured that all dependencies are correctly acquired. |
| 511 | execute_process( |
| 512 | COMMAND |
| 513 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 514 | ${ZEPHYR_BASE}/scripts/subfolder_list.py |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 515 | --directory ${ZEPHYR_BASE}/include # Walk this directory |
| 516 | --out-file ${syscalls_subdirs_txt} # Write file with discovered folder |
| 517 | --trigger ${syscalls_subdirs_trigger} # Trigger file that is used for json generation |
| 518 | ${syscalls_links} # If defined, create symlinks for dependencies |
| 519 | ) |
Carles Cufi | 3ad1f27 | 2019-07-18 10:38:25 +0200 | [diff] [blame] | 520 | file(STRINGS ${syscalls_subdirs_txt} PARSE_SYSCALLS_PATHS_DEPENDS ENCODING UTF-8) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 521 | |
| 522 | if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows) |
| 523 | # On windows only adding/removing files or folders will be reflected in depends. |
| 524 | # Hence adding a file requires CMake to re-run to add this file to the file list. |
| 525 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${PARSE_SYSCALLS_PATHS_DEPENDS}) |
| 526 | |
| 527 | # Also On Windows each header file must be monitored as file modifications are not reflected |
| 528 | # on directory level. |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 529 | file(GLOB_RECURSE PARSE_SYSCALLS_HEADER_DEPENDS ${ZEPHYR_BASE}/include/*.h) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 530 | else() |
| 531 | # The syscall parsing depends on the folders in order to detect add/removed/modified files. |
| 532 | # When a folder is removed, CMake will try to find a target that creates that dependency. |
| 533 | # This command sets up the target for CMake to find. |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 534 | # Without this code, CMake will fail with the following error: |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 535 | # <folder> needed by '<target>', missing and no known rule to make it |
| 536 | # when a folder is removed. |
| 537 | add_custom_command(OUTPUT ${PARSE_SYSCALLS_PATHS_DEPENDS} |
| 538 | COMMAND ${CMAKE_COMMAND} -E echo "" |
| 539 | COMMENT "Preparing syscall dependency handling" |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 540 | ) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 541 | |
| 542 | add_custom_command( |
| 543 | OUTPUT |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 544 | ${syscalls_subdirs_trigger} |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 545 | COMMAND |
| 546 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 547 | ${ZEPHYR_BASE}/scripts/subfolder_list.py |
| 548 | --directory ${ZEPHYR_BASE}/include # Walk this directory |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 549 | --out-file ${syscalls_subdirs_txt} # Write file with discovered folder |
| 550 | --trigger ${syscalls_subdirs_trigger} # Trigger file that is used for json generation |
| 551 | ${syscalls_links} # If defined, create symlinks for dependencies |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 552 | DEPENDS ${PARSE_SYSCALLS_PATHS_DEPENDS} |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 553 | ) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 554 | |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 555 | # Ensure subdir file always exists when specifying CMake dependency. |
| 556 | if(NOT EXISTS ${syscalls_subdirs_txt}) |
| 557 | file(WRITE ${syscalls_subdirs_txt} "") |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 558 | endif() |
| 559 | |
| 560 | # On other OS'es, modifying a file is reflected on the folder timestamp and hence detected |
| 561 | # when using depend on directory level. |
| 562 | # Thus CMake only needs to re-run when sub-directories are added / removed, which is indicated |
| 563 | # using a trigger file. |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 564 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${syscalls_subdirs_txt}) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 565 | endif() |
| 566 | |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 567 | # syscall declarations are searched for in the SYSCALL_INCLUDE_DIRS |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 568 | if(CONFIG_APPLICATION_DEFINED_SYSCALL) |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 569 | list(APPEND SYSCALL_INCLUDE_DIRS ${APPLICATION_SOURCE_DIR}) |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 570 | endif() |
| 571 | |
Andrew Boie | c186387 | 2019-11-21 23:11:29 -0800 | [diff] [blame] | 572 | if(CONFIG_ZTEST) |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 573 | list(APPEND SYSCALL_INCLUDE_DIRS ${ZEPHYR_BASE}/subsys/testsuite/ztest/include) |
Andrew Boie | c186387 | 2019-11-21 23:11:29 -0800 | [diff] [blame] | 574 | endif() |
| 575 | |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 576 | foreach(d ${SYSCALL_INCLUDE_DIRS}) |
| 577 | list(APPEND parse_syscalls_include_args |
| 578 | --include ${d} |
| 579 | ) |
| 580 | endforeach() |
| 581 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 582 | add_custom_command( |
| 583 | OUTPUT |
| 584 | ${syscalls_json} |
Andrew Boie | 5960119 | 2020-05-29 13:24:51 -0700 | [diff] [blame] | 585 | ${struct_tags_json} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 586 | COMMAND |
| 587 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 588 | ${ZEPHYR_BASE}/scripts/parse_syscalls.py |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 589 | --include ${ZEPHYR_BASE}/include # Read files from this dir |
Andrew Boie | fed960b | 2020-05-29 13:33:12 -0700 | [diff] [blame] | 590 | --include ${ZEPHYR_BASE}/drivers # For net sockets |
| 591 | --include ${ZEPHYR_BASE}/subsys/net # More net sockets |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 592 | ${parse_syscalls_include_args} # Read files from these dirs also |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 593 | --json-file ${syscalls_json} # Write this file |
Andrew Boie | 5960119 | 2020-05-29 13:24:51 -0700 | [diff] [blame] | 594 | --tag-struct-file ${struct_tags_json} # Write subsystem list to this file |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 595 | DEPENDS ${syscalls_subdirs_trigger} ${PARSE_SYSCALLS_HEADER_DEPENDS} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 596 | ) |
| 597 | |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 598 | add_custom_target(${SYSCALL_LIST_H_TARGET} DEPENDS ${syscall_list_h}) |
Andrew Boie | c1c54b1 | 2020-03-16 12:48:00 -0700 | [diff] [blame] | 599 | add_custom_target(${PARSE_SYSCALLS_TARGET} |
Andrew Boie | 5960119 | 2020-05-29 13:24:51 -0700 | [diff] [blame] | 600 | DEPENDS ${syscalls_json} ${struct_tags_json}) |
Andrew Boie | 9ff64bb | 2019-11-05 09:39:05 -0800 | [diff] [blame] | 601 | |
| 602 | # 64-bit systems do not require special handling of 64-bit system call |
| 603 | # parameters or return values, indicate this to the system call boilerplate |
| 604 | # generation script. |
| 605 | if(CONFIG_64BIT) |
| 606 | set(SYSCALL_LONG_REGISTERS_ARG --long-registers) |
| 607 | endif() |
| 608 | |
Andy Ross | cfeb07e | 2020-03-05 21:14:02 -0800 | [diff] [blame] | 609 | if(CONFIG_TIMEOUT_64BIT) |
| 610 | set(SYSCALL_SPLIT_TIMEOUT_ARG --split-type k_timeout_t) |
| 611 | endif() |
| 612 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 613 | add_custom_command(OUTPUT include/generated/syscall_dispatch.c ${syscall_list_h} |
| 614 | # Also, some files are written to include/generated/syscalls/ |
| 615 | COMMAND |
| 616 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 617 | ${ZEPHYR_BASE}/scripts/gen_syscalls.py |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 618 | --json-file ${syscalls_json} # Read this file |
| 619 | --base-output include/generated/syscalls # Write to this dir |
| 620 | --syscall-dispatch include/generated/syscall_dispatch.c # Write this file |
Andrew Boie | 353acf4 | 2018-07-23 18:10:15 -0700 | [diff] [blame] | 621 | --syscall-list ${syscall_list_h} |
Andrew Boie | 9ff64bb | 2019-11-05 09:39:05 -0800 | [diff] [blame] | 622 | ${SYSCALL_LONG_REGISTERS_ARG} |
Andy Ross | cfeb07e | 2020-03-05 21:14:02 -0800 | [diff] [blame] | 623 | ${SYSCALL_SPLIT_TIMEOUT_ARG} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 624 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
Andrew Boie | c1c54b1 | 2020-03-16 12:48:00 -0700 | [diff] [blame] | 625 | DEPENDS ${PARSE_SYSCALLS_TARGET} |
Sebastian Bøe | 0d3d725 | 2020-03-19 06:40:13 -0700 | [diff] [blame] | 626 | ${syscalls_json} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 627 | ) |
| 628 | |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 629 | # This is passed into all calls to the gen_kobject_list.py script. |
Andrew Boie | 5960119 | 2020-05-29 13:24:51 -0700 | [diff] [blame] | 630 | set(gen_kobject_list_include_args --include ${struct_tags_json}) |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 631 | |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 632 | set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/driver-validation.h) |
| 633 | add_custom_command( |
| 634 | OUTPUT ${DRV_VALIDATION} |
| 635 | COMMAND |
| 636 | ${PYTHON_EXECUTABLE} |
| 637 | ${ZEPHYR_BASE}/scripts/gen_kobject_list.py |
| 638 | --validation-output ${DRV_VALIDATION} |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 639 | ${gen_kobject_list_include_args} |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 640 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 641 | DEPENDS |
| 642 | ${ZEPHYR_BASE}/scripts/gen_kobject_list.py |
Andrew Boie | c1c54b1 | 2020-03-16 12:48:00 -0700 | [diff] [blame] | 643 | ${PARSE_SYSCALLS_TARGET} |
Andrew Boie | 5960119 | 2020-05-29 13:24:51 -0700 | [diff] [blame] | 644 | ${struct_tags_json} |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 645 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 646 | ) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 647 | add_custom_target(${DRIVER_VALIDATION_H_TARGET} DEPENDS ${DRV_VALIDATION}) |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 648 | |
Torsten Rasmussen | d7862cf | 2020-02-12 15:42:09 +0100 | [diff] [blame] | 649 | include(${ZEPHYR_BASE}/cmake/kobj.cmake) |
Leandro Pereira | 39dc7d0 | 2018-04-05 13:59:33 -0700 | [diff] [blame] | 650 | gen_kobj(KOBJ_INCLUDE_PATH) |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 651 | |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 652 | # Add a pseudo-target that is up-to-date when all generated headers |
| 653 | # are up-to-date. |
| 654 | |
| 655 | add_custom_target(zephyr_generated_headers) |
| 656 | add_dependencies(zephyr_generated_headers |
| 657 | offsets_h |
| 658 | ) |
| 659 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 660 | # Generate offsets.c.obj from offsets.c |
| 661 | # Generate offsets.h from offsets.c.obj |
| 662 | |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 663 | set(OFFSETS_LIB offsets) |
| 664 | |
Klaus Petersen | c66cb76 | 2018-11-15 10:37:46 +0100 | [diff] [blame] | 665 | set(OFFSETS_C_PATH ${ARCH_DIR}/${ARCH}/core/offsets/offsets.c) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 666 | set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h) |
| 667 | |
Klaus Petersen | 62e55e5 | 2019-02-04 12:10:57 +0100 | [diff] [blame] | 668 | add_library( ${OFFSETS_LIB} OBJECT ${OFFSETS_C_PATH}) |
Stephanos Ioannidis | 2d74604 | 2019-10-25 00:08:21 +0900 | [diff] [blame] | 669 | target_include_directories(${OFFSETS_LIB} PRIVATE |
| 670 | kernel/include |
| 671 | ${ARCH_DIR}/${ARCH}/include |
| 672 | ) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 673 | target_link_libraries(${OFFSETS_LIB} zephyr_interface) |
| 674 | add_dependencies( ${OFFSETS_LIB} |
| 675 | ${SYSCALL_LIST_H_TARGET} |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 676 | ${DRIVER_VALIDATION_H_TARGET} |
| 677 | ${KOBJ_TYPES_H_TARGET} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 678 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 679 | |
| 680 | add_custom_command( |
| 681 | OUTPUT ${OFFSETS_H_PATH} |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 682 | COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/gen_offset_header.py |
Klaus Petersen | 62e55e5 | 2019-02-04 12:10:57 +0100 | [diff] [blame] | 683 | -i $<TARGET_OBJECTS:${OFFSETS_LIB}> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 684 | -o ${OFFSETS_H_PATH} |
Sebastian Bøe | 5962aab | 2019-08-15 14:45:59 +0200 | [diff] [blame] | 685 | DEPENDS |
| 686 | ${OFFSETS_LIB} |
| 687 | $<TARGET_OBJECTS:${OFFSETS_LIB}> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 688 | ) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 689 | add_custom_target(${OFFSETS_H_TARGET} DEPENDS ${OFFSETS_H_PATH}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 690 | |
| 691 | zephyr_include_directories(${TOOLCHAIN_INCLUDES}) |
| 692 | |
Sebastian Bøe | 89516fb | 2017-12-01 15:25:06 +0100 | [diff] [blame] | 693 | zephyr_get_include_directories_for_lang(C ZEPHYR_INCLUDES) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 694 | |
| 695 | add_subdirectory(kernel) |
| 696 | |
| 697 | # Read list content |
| 698 | get_property(ZEPHYR_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_LIBS) |
| 699 | |
| 700 | foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY}) |
| 701 | # TODO: Could this become an INTERFACE property of zephyr_interface? |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 702 | add_dependencies(${zephyr_lib} zephyr_generated_headers) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 703 | endforeach() |
| 704 | |
| 705 | get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) |
| 706 | |
Adithya Baglody | 62e152a | 2018-11-13 15:34:02 +0530 | [diff] [blame] | 707 | if (CONFIG_CODE_DATA_RELOCATION) |
| 708 | set(CODE_RELOCATION_DEP code_relocation_source_lib) |
| 709 | endif() # CONFIG_CODE_DATA_RELOCATION |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 710 | |
Mark Ruvald Pedersen | 4c81197 | 2019-04-29 17:16:54 +0200 | [diff] [blame] | 711 | configure_linker_script( |
Mark Ruvald Pedersen | 1073fba | 2019-04-29 20:27:23 +0200 | [diff] [blame] | 712 | linker.cmd |
Mark Ruvald Pedersen | fbcea17 | 2019-04-29 20:35:12 +0200 | [diff] [blame] | 713 | "" |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 714 | ${APP_SMEM_ALIGNED_DEP} |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 715 | ${CODE_RELOCATION_DEP} |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 716 | zephyr_generated_headers |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 717 | ) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 718 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 719 | add_custom_target( |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 720 | ${LINKER_SCRIPT_TARGET} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 721 | DEPENDS |
| 722 | linker.cmd |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 723 | ) |
| 724 | |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 725 | # Give the '${LINKER_SCRIPT_TARGET}' target all of the include directories so |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 726 | # that cmake can successfully find the linker_script's header |
| 727 | # dependencies. |
| 728 | zephyr_get_include_directories_for_lang(C |
| 729 | ZEPHYR_INCLUDE_DIRS |
| 730 | STRIP_PREFIX # Don't use a -I prefix |
| 731 | ) |
| 732 | set_property(TARGET |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 733 | ${LINKER_SCRIPT_TARGET} |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 734 | PROPERTY INCLUDE_DIRECTORIES |
| 735 | ${ZEPHYR_INCLUDE_DIRS} |
| 736 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 737 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 738 | if(CONFIG_GEN_ISR_TABLES) |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 739 | if(CONFIG_GEN_SW_ISR_TABLE) |
| 740 | list(APPEND GEN_ISR_TABLE_EXTRA_ARG --sw-isr-table) |
| 741 | endif() |
| 742 | |
| 743 | if(CONFIG_GEN_IRQ_VECTOR_TABLE) |
| 744 | list(APPEND GEN_ISR_TABLE_EXTRA_ARG --vector-table) |
| 745 | endif() |
| 746 | |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 747 | # isr_tables.c is generated from ${ZEPHYR_PREBUILT_EXECUTABLE} by |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 748 | # gen_isr_tables.py |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 749 | set(obj_copy_cmd "") |
| 750 | bintools_objcopy( |
| 751 | RESULT_CMD_LIST obj_copy_cmd |
| 752 | TARGET_INPUT ${OUTPUT_FORMAT} |
| 753 | TARGET_OUTPUT "binary" |
| 754 | SECTION_ONLY ".intList" |
| 755 | FILE_INPUT $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}> |
| 756 | FILE_OUTPUT "isrList.bin" |
| 757 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 758 | add_custom_command( |
| 759 | OUTPUT isr_tables.c |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 760 | ${obj_copy_cmd} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 761 | COMMAND ${PYTHON_EXECUTABLE} |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 762 | ${ZEPHYR_BASE}/arch/common/gen_isr_tables.py |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 763 | --output-source isr_tables.c |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 764 | --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 765 | --intlist isrList.bin |
Yasushi SHOJI | 6fc0d77 | 2018-10-09 18:59:16 +0900 | [diff] [blame] | 766 | $<$<BOOL:${CONFIG_BIG_ENDIAN}>:--big-endian> |
Sebastian Bøe | a55279a | 2018-01-04 14:08:39 +0100 | [diff] [blame] | 767 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug> |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 768 | ${GEN_ISR_TABLE_EXTRA_ARG} |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 769 | DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 770 | ) |
| 771 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c) |
| 772 | endif() |
| 773 | |
Adithya Baglody | 62e152a | 2018-11-13 15:34:02 +0530 | [diff] [blame] | 774 | if(CONFIG_CODE_DATA_RELOCATION) |
Mark Ruvald Pedersen | 86a3e8f | 2019-05-03 10:33:03 +0200 | [diff] [blame] | 775 | # @Intent: Linker script to relocate .text, data and .bss sections |
| 776 | toolchain_ld_relocation() |
Adithya Baglody | 62e152a | 2018-11-13 15:34:02 +0530 | [diff] [blame] | 777 | endif() |
| 778 | |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 779 | if(CONFIG_USERSPACE) |
| 780 | zephyr_get_compile_options_for_lang_as_string(C compiler_flags_priv) |
| 781 | string(REPLACE "-ftest-coverage" "" NO_COVERAGE_FLAGS "${compiler_flags_priv}") |
| 782 | string(REPLACE "-fprofile-arcs" "" NO_COVERAGE_FLAGS "${NO_COVERAGE_FLAGS}") |
Daniel Leung | 84b1bba | 2019-04-01 15:57:35 -0700 | [diff] [blame] | 783 | string(REPLACE "-fno-inline" "" NO_COVERAGE_FLAGS "${NO_COVERAGE_FLAGS}") |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 784 | |
| 785 | get_property(include_dir_in_interface TARGET zephyr_interface |
| 786 | PROPERTY INTERFACE_INCLUDE_DIRECTORIES) |
| 787 | |
| 788 | get_property(sys_include_dir_in_interface TARGET zephyr_interface |
| 789 | PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) |
| 790 | |
| 791 | get_property(compile_definitions_interface TARGET zephyr_interface |
| 792 | PROPERTY INTERFACE_COMPILE_DEFINITIONS) |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 793 | |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 794 | set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/gen_kobject_list.py) |
| 795 | set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/process_gperf.py) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 796 | |
| 797 | set(OBJ_LIST kobject_hash.gperf) |
| 798 | set(OUTPUT_SRC_PRE kobject_hash_preprocessed.c) |
| 799 | set(OUTPUT_SRC kobject_hash.c) |
| 800 | set(OUTPUT_OBJ kobject_hash.c.obj) |
| 801 | set(OUTPUT_OBJ_RENAMED kobject_hash_renamed.o) |
| 802 | |
| 803 | # Essentially what we are doing here is extracting some information |
| 804 | # out of the nearly finished elf file, generating the source code |
| 805 | # for a hash table based on that information, and then compiling and |
| 806 | # linking the hash table back into a now even more nearly finished |
Marc Herbert | 4a10eea | 2019-04-16 15:39:45 -0700 | [diff] [blame] | 807 | # elf file. More information in gen_kobject_list.py --help. |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 808 | |
| 809 | # Use the script GEN_KOBJ_LIST to scan the kernel binary's |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 810 | # (${ZEPHYR_PREBUILT_EXECUTABLE}) DWARF information to produce a table of kernel |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 811 | # objects (OBJ_LIST) which we will then pass to gperf |
| 812 | add_custom_command( |
| 813 | OUTPUT ${OBJ_LIST} |
| 814 | COMMAND |
| 815 | ${PYTHON_EXECUTABLE} |
| 816 | ${GEN_KOBJ_LIST} |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 817 | --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}> |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 818 | --gperf-output ${OBJ_LIST} |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 819 | ${gen_kobject_list_include_args} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 820 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Corey Wharton | ccd15df | 2020-02-29 14:51:42 -0800 | [diff] [blame] | 821 | DEPENDS |
| 822 | ${ZEPHYR_PREBUILT_EXECUTABLE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 823 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 824 | ) |
| 825 | add_custom_target(obj_list DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OBJ_LIST}) |
| 826 | |
| 827 | # Use gperf to generate C code (OUTPUT_SRC_PRE) which implements a |
| 828 | # perfect hashtable based on OBJ_LIST |
| 829 | add_custom_command( |
| 830 | OUTPUT ${OUTPUT_SRC_PRE} |
| 831 | COMMAND |
| 832 | ${GPERF} |
| 833 | --output-file ${OUTPUT_SRC_PRE} |
| 834 | ${OBJ_LIST} |
Sebastian Bøe | f5758b5 | 2018-01-31 10:42:46 +0100 | [diff] [blame] | 835 | DEPENDS obj_list ${OBJ_LIST} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 836 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 837 | ) |
| 838 | add_custom_target(output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC_PRE}) |
| 839 | |
| 840 | # For our purposes the code/data generated by gperf is not optimal. |
| 841 | # |
| 842 | # The script PROCESS_GPERF creates a new c file OUTPUT_SRC based on |
| 843 | # OUTPUT_SRC_PRE to greatly reduce the amount of code/data generated |
| 844 | # since we know we are always working with pointer values |
| 845 | add_custom_command( |
| 846 | OUTPUT ${OUTPUT_SRC} |
| 847 | COMMAND |
Sebastian Bøe | 1b60070 | 2018-06-21 14:34:42 +0200 | [diff] [blame] | 848 | ${PYTHON_EXECUTABLE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 849 | ${PROCESS_GPERF} |
| 850 | -i ${OUTPUT_SRC_PRE} |
| 851 | -o ${OUTPUT_SRC} |
Andrew Boie | 2dc2ecf | 2020-03-11 07:13:07 -0700 | [diff] [blame] | 852 | -p "struct z_object" |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 853 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Sebastian Bøe | f5758b5 | 2018-01-31 10:42:46 +0100 | [diff] [blame] | 854 | DEPENDS output_src_pre ${OUTPUT_SRC_PRE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 855 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 856 | ) |
| 857 | add_custom_target(output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC}) |
| 858 | |
| 859 | # We need precise control of where generated text/data ends up in the final |
| 860 | # kernel image. Disable function/data sections and use objcopy to move |
| 861 | # generated data into special section names |
| 862 | add_library(output_lib STATIC |
| 863 | ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC} |
| 864 | ) |
| 865 | |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 866 | set_source_files_properties(${OUTPUT_SRC} PROPERTIES COMPILE_FLAGS |
Andrew Boie | a514898 | 2019-03-14 17:04:11 -0700 | [diff] [blame] | 867 | "${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections") |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 868 | |
| 869 | set_source_files_properties(${OUTPUT_SRC} |
| 870 | PROPERTIES COMPILE_DEFINITIONS "${compile_definitions_interface}") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 871 | |
| 872 | # Turn off -ffunction-sections, etc. |
| 873 | # NB: Using a library instead of target_compile_options(output_lib |
| 874 | # [...]) because a library's options have precedence |
| 875 | add_library(output_lib_interface INTERFACE) |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 876 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 877 | target_link_libraries(output_lib output_lib_interface) |
| 878 | |
Kumar Gala | 3713ea4 | 2019-03-14 11:50:08 -0500 | [diff] [blame] | 879 | foreach(incl ${include_dir_in_interface}) |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 880 | target_include_directories(output_lib_interface INTERFACE ${incl}) |
| 881 | endforeach() |
| 882 | |
Kumar Gala | 3713ea4 | 2019-03-14 11:50:08 -0500 | [diff] [blame] | 883 | foreach(incl ${sys_include_dir_in_interface}) |
| 884 | target_include_directories(output_lib_interface SYSTEM INTERFACE ${incl}) |
| 885 | endforeach() |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 886 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 887 | set(OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/output_lib.dir/${OUTPUT_OBJ}) |
| 888 | |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 889 | set(obj_copy_cmd "") |
| 890 | set(obj_copy_sections_rename |
| 891 | .data=.kobject_data.data |
| 892 | .text=.kobject_data.text |
| 893 | .rodata=.kobject_data.rodata |
| 894 | ) |
| 895 | bintools_objcopy( |
| 896 | RESULT_CMD_LIST obj_copy_cmd |
| 897 | SECTION_RENAME ${obj_copy_sections_rename} |
| 898 | FILE_INPUT ${OUTPUT_OBJ_PATH} |
| 899 | FILE_OUTPUT ${OUTPUT_OBJ_RENAMED} |
| 900 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 901 | add_custom_command( |
| 902 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED} |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 903 | ${obj_copy_cmd} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 904 | DEPENDS output_lib |
| 905 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 906 | ) |
| 907 | add_custom_target(output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED}) |
| 908 | |
| 909 | add_library(output_obj_renamed_lib STATIC IMPORTED GLOBAL) |
| 910 | set_property( |
| 911 | TARGET output_obj_renamed_lib |
| 912 | PROPERTY |
| 913 | IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED} |
| 914 | ) |
| 915 | add_dependencies( |
| 916 | output_obj_renamed_lib |
| 917 | output_obj_renamed |
| 918 | ) |
| 919 | |
| 920 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES output_obj_renamed_lib) |
| 921 | endif() |
| 922 | |
| 923 | # Read global variables into local variables |
| 924 | get_property(GKOF GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES) |
| 925 | get_property(GKSF GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES) |
| 926 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 927 | |
Alberto Escolar Piedras | c288241 | 2018-07-05 10:51:03 +0200 | [diff] [blame] | 928 | get_property(CSTD GLOBAL PROPERTY CSTD) |
| 929 | set_ifndef(CSTD c99) |
| 930 | |
Danny Oerndrup | 6331dae | 2019-06-13 15:33:03 +0200 | [diff] [blame] | 931 | # @Intent: Obtain compiler specific flag for specifying the c standard |
| 932 | toolchain_cc_cstd_flag(CC_CSTD ${CSTD}) |
Alberto Escolar Piedras | c288241 | 2018-07-05 10:51:03 +0200 | [diff] [blame] | 933 | zephyr_compile_options( |
Danny Oerndrup | 6331dae | 2019-06-13 15:33:03 +0200 | [diff] [blame] | 934 | $<$<COMPILE_LANGUAGE:C>:${CC_CSTD}> |
Alberto Escolar Piedras | c288241 | 2018-07-05 10:51:03 +0200 | [diff] [blame] | 935 | ) |
| 936 | |
Mark Ruvald Pedersen | 197197a | 2019-05-03 11:02:56 +0200 | [diff] [blame] | 937 | # @Intent: Configure linker scripts, i.e. generate linker scripts with variables substituted |
| 938 | toolchain_ld_configure_files() |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 939 | |
Andrew Boie | 4ce652e | 2019-02-22 16:08:44 -0800 | [diff] [blame] | 940 | if(CONFIG_USERSPACE) |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 941 | set(APP_SMEM_ALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_aligned.ld") |
| 942 | set(APP_SMEM_UNALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_unaligned.ld") |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 943 | set(OBJ_FILE_DIR "${PROJECT_BINARY_DIR}/../") |
| 944 | |
| 945 | add_custom_target( |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 946 | ${APP_SMEM_ALIGNED_DEP} |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 947 | DEPENDS |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 948 | ${APP_SMEM_ALIGNED_LD} |
| 949 | ) |
| 950 | |
| 951 | add_custom_target( |
| 952 | ${APP_SMEM_UNALIGNED_DEP} |
| 953 | DEPENDS |
| 954 | ${APP_SMEM_UNALIGNED_LD} |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 955 | ) |
| 956 | |
Andrew Boie | 4b4f773 | 2019-02-01 12:18:31 -0800 | [diff] [blame] | 957 | if(CONFIG_NEWLIB_LIBC) |
Andrew Boie | 17ce822 | 2019-02-21 13:44:54 -0800 | [diff] [blame] | 958 | set(NEWLIB_PART -l libc.a z_libc_partition) |
Andrew Boie | 4b4f773 | 2019-02-01 12:18:31 -0800 | [diff] [blame] | 959 | endif() |
Ioannis Glaropoulos | d58f8be | 2019-11-15 14:07:51 +0100 | [diff] [blame] | 960 | if(CONFIG_NEWLIB_LIBC_NANO) |
| 961 | set(NEWLIB_PART -l libc_nano.a z_libc_partition) |
| 962 | endif() |
Andrew Boie | e686aef | 2019-02-27 14:41:45 -0800 | [diff] [blame] | 963 | |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 964 | add_custom_command( |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 965 | OUTPUT ${APP_SMEM_UNALIGNED_LD} |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 966 | COMMAND ${PYTHON_EXECUTABLE} |
| 967 | ${ZEPHYR_BASE}/scripts/gen_app_partitions.py |
| 968 | -d ${OBJ_FILE_DIR} |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 969 | -o ${APP_SMEM_UNALIGNED_LD} |
Torsten Rasmussen | 5a703c8 | 2019-11-05 10:24:08 +0100 | [diff] [blame] | 970 | ${NEWLIB_PART} |
Torsten Rasmussen | 1f9723a | 2019-11-04 14:30:24 +0100 | [diff] [blame] | 971 | $<TARGET_PROPERTY:zephyr_property_target,COMPILE_OPTIONS> |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 972 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 973 | DEPENDS |
| 974 | kernel |
| 975 | ${ZEPHYR_LIBS_PROPERTY} |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 976 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ |
Torsten Rasmussen | 1f9723a | 2019-11-04 14:30:24 +0100 | [diff] [blame] | 977 | COMMAND_EXPAND_LISTS |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 978 | COMMENT "Generating app_smem_unaligned linker section" |
| 979 | ) |
| 980 | |
Mark Ruvald Pedersen | 4c81197 | 2019-04-29 17:16:54 +0200 | [diff] [blame] | 981 | configure_linker_script( |
Mark Ruvald Pedersen | 1073fba | 2019-04-29 20:27:23 +0200 | [diff] [blame] | 982 | linker_app_smem_unaligned.cmd |
Mark Ruvald Pedersen | fbcea17 | 2019-04-29 20:35:12 +0200 | [diff] [blame] | 983 | "-DLINKER_APP_SMEM_UNALIGNED" |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 984 | ${CODE_RELOCATION_DEP} |
| 985 | ${APP_SMEM_UNALIGNED_DEP} |
| 986 | ${APP_SMEM_UNALIGNED_LD} |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 987 | zephyr_generated_headers |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 988 | ) |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 989 | |
| 990 | add_custom_target( |
| 991 | linker_app_smem_unaligned_script |
| 992 | DEPENDS |
| 993 | linker_app_smem_unaligned.cmd |
| 994 | ) |
| 995 | |
| 996 | set_property(TARGET |
| 997 | linker_app_smem_unaligned_script |
| 998 | PROPERTY INCLUDE_DIRECTORIES |
| 999 | ${ZEPHYR_INCLUDE_DIRS} |
| 1000 | ) |
| 1001 | |
| 1002 | set(APP_SMEM_UNALIGNED_LIB app_smem_unaligned_output_obj_renamed_lib) |
| 1003 | add_executable( app_smem_unaligned_prebuilt misc/empty_file.c) |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1004 | toolchain_ld_link_elf( |
| 1005 | TARGET_ELF app_smem_unaligned_prebuilt |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1006 | OUTPUT_MAP ${PROJECT_BINARY_DIR}/app_smem_unaligned_prebuilt.map |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1007 | LIBRARIES_PRE_SCRIPT "" |
| 1008 | LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker_app_smem_unaligned.cmd |
| 1009 | LIBRARIES_POST_SCRIPT "" |
| 1010 | DEPENDENCIES ${CODE_RELOCATION_DEP} |
| 1011 | ) |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1012 | set_property(TARGET app_smem_unaligned_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_app_smem_unaligned.cmd) |
Mark Ruvald Pedersen | 85af280 | 2019-04-29 14:49:33 +0200 | [diff] [blame] | 1013 | add_dependencies( app_smem_unaligned_prebuilt linker_app_smem_unaligned_script ${OFFSETS_LIB}) |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1014 | |
| 1015 | add_custom_command( |
| 1016 | OUTPUT ${APP_SMEM_ALIGNED_LD} |
| 1017 | COMMAND ${PYTHON_EXECUTABLE} |
| 1018 | ${ZEPHYR_BASE}/scripts/gen_app_partitions.py |
| 1019 | -e $<TARGET_FILE:app_smem_unaligned_prebuilt> |
| 1020 | -o ${APP_SMEM_ALIGNED_LD} |
Torsten Rasmussen | 5a703c8 | 2019-11-05 10:24:08 +0100 | [diff] [blame] | 1021 | ${NEWLIB_PART} |
Torsten Rasmussen | 1f9723a | 2019-11-04 14:30:24 +0100 | [diff] [blame] | 1022 | $<TARGET_PROPERTY:zephyr_property_target,COMPILE_OPTIONS> |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1023 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 1024 | DEPENDS |
| 1025 | kernel |
| 1026 | ${ZEPHYR_LIBS_PROPERTY} |
| 1027 | app_smem_unaligned_prebuilt |
| 1028 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ |
Torsten Rasmussen | 1f9723a | 2019-11-04 14:30:24 +0100 | [diff] [blame] | 1029 | COMMAND_EXPAND_LISTS |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1030 | COMMENT "Generating app_smem_aligned linker section" |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 1031 | ) |
| 1032 | endif() |
| 1033 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1034 | # FIXME: Is there any way to get rid of empty_file.c? |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 1035 | add_executable( ${ZEPHYR_PREBUILT_EXECUTABLE} misc/empty_file.c) |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1036 | toolchain_ld_link_elf( |
| 1037 | TARGET_ELF ${ZEPHYR_PREBUILT_EXECUTABLE} |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1038 | OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_PREBUILT_EXECUTABLE}.map |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1039 | LIBRARIES_PRE_SCRIPT "" |
| 1040 | LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker.cmd |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1041 | DEPENDENCIES ${CODE_RELOCATION_DEP} |
| 1042 | ) |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 1043 | set_property(TARGET ${ZEPHYR_PREBUILT_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker.cmd) |
Andrew Boie | 28be793 | 2020-03-11 10:56:19 -0700 | [diff] [blame] | 1044 | add_dependencies( ${ZEPHYR_PREBUILT_EXECUTABLE} ${LINKER_SCRIPT_TARGET} ${OFFSETS_LIB}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1045 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 1046 | |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1047 | set(generated_kernel_files ${GKSF} ${GKOF}) |
| 1048 | if(NOT generated_kernel_files) |
| 1049 | # Use the prebuilt elf as the final elf since we don't have a |
| 1050 | # generation stage. |
| 1051 | set(logical_target_for_zephyr_elf ${ZEPHYR_PREBUILT_EXECUTABLE}) |
| 1052 | else() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1053 | # The second linker pass uses the same source linker script of the |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 1054 | # first pass (LINKER_SCRIPT), but this time with a different output |
| 1055 | # file and preprocessed with the define LINKER_PASS2. |
Mark Ruvald Pedersen | 4c81197 | 2019-04-29 17:16:54 +0200 | [diff] [blame] | 1056 | configure_linker_script( |
Mark Ruvald Pedersen | 1073fba | 2019-04-29 20:27:23 +0200 | [diff] [blame] | 1057 | linker_pass_final.cmd |
Mark Ruvald Pedersen | fbcea17 | 2019-04-29 20:35:12 +0200 | [diff] [blame] | 1058 | "-DLINKER_PASS2" |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 1059 | ${CODE_RELOCATION_DEP} |
| 1060 | ${ZEPHYR_PREBUILT_EXECUTABLE} |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 1061 | zephyr_generated_headers |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 1062 | ) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1063 | |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 1064 | set(LINKER_PASS_FINAL_SCRIPT_TARGET linker_pass_final_script_target) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1065 | add_custom_target( |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 1066 | ${LINKER_PASS_FINAL_SCRIPT_TARGET} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1067 | DEPENDS |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 1068 | linker_pass_final.cmd |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1069 | ) |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 1070 | set_property(TARGET |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 1071 | ${LINKER_PASS_FINAL_SCRIPT_TARGET} |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 1072 | PROPERTY INCLUDE_DIRECTORIES |
| 1073 | ${ZEPHYR_INCLUDE_DIRS} |
| 1074 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1075 | |
Mark Ruvald Pedersen | 37d4947 | 2019-05-07 15:20:20 +0200 | [diff] [blame] | 1076 | add_executable( ${ZEPHYR_FINAL_EXECUTABLE} misc/empty_file.c ${GKSF}) |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1077 | toolchain_ld_link_elf( |
| 1078 | TARGET_ELF ${ZEPHYR_FINAL_EXECUTABLE} |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1079 | OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_FINAL_EXECUTABLE}.map |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1080 | LIBRARIES_PRE_SCRIPT ${GKOF} |
| 1081 | LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker_pass_final.cmd |
| 1082 | LIBRARIES_POST_SCRIPT "" |
| 1083 | DEPENDENCIES ${CODE_RELOCATION_DEP} |
| 1084 | ) |
Mark Ruvald Pedersen | 37d4947 | 2019-05-07 15:20:20 +0200 | [diff] [blame] | 1085 | set_property(TARGET ${ZEPHYR_FINAL_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_pass_final.cmd) |
Andrew Boie | 28be793 | 2020-03-11 10:56:19 -0700 | [diff] [blame] | 1086 | add_dependencies( ${ZEPHYR_FINAL_EXECUTABLE} ${LINKER_PASS_FINAL_SCRIPT_TARGET}) |
Mark Ruvald Pedersen | 37d4947 | 2019-05-07 15:20:20 +0200 | [diff] [blame] | 1087 | |
| 1088 | # Use the pass2 elf as the final elf |
| 1089 | set(logical_target_for_zephyr_elf ${ZEPHYR_FINAL_EXECUTABLE}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1090 | endif() |
| 1091 | |
Sebastian Bøe | 0fc3934 | 2018-10-16 13:25:04 +0200 | [diff] [blame] | 1092 | # Export the variable to the application's scope to allow the |
| 1093 | # application to know what the name of the final elf target is. |
| 1094 | set(logical_target_for_zephyr_elf ${logical_target_for_zephyr_elf} PARENT_SCOPE) |
| 1095 | |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1096 | # 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] | 1097 | # 1. it doesn't depend on the number of passes above and the |
| 1098 | # post_build_commands below can always find it no matter which is it; |
| 1099 | # 2. it can be defined in Kconfig |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1100 | set_target_properties(${logical_target_for_zephyr_elf} PROPERTIES OUTPUT_NAME ${KERNEL_NAME}) |
| 1101 | |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1102 | set(post_build_commands "") |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1103 | set(post_build_byproducts "") |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1104 | |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1105 | list(APPEND |
| 1106 | post_build_commands |
| 1107 | COMMAND |
Torsten Rasmussen | 4df38c7 | 2020-06-11 10:48:06 +0200 | [diff] [blame] | 1108 | ${CMAKE_COMMAND} -E rename ${logical_target_for_zephyr_elf}.map ${KERNEL_MAP_NAME} |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1109 | ) |
| 1110 | |
Håkon Øye Amundsen | c086b93 | 2018-11-26 09:47:16 +0000 | [diff] [blame] | 1111 | if(NOT CONFIG_BUILD_NO_GAP_FILL) |
| 1112 | # Use ';' as separator to get proper space in resulting command. |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1113 | set(GAP_FILL "0xff") |
Håkon Øye Amundsen | c086b93 | 2018-11-26 09:47:16 +0000 | [diff] [blame] | 1114 | endif() |
| 1115 | |
Danny Oerndrup | c41e712 | 2019-07-18 15:16:39 +0200 | [diff] [blame] | 1116 | if(CONFIG_OUTPUT_PRINT_MEMORY_USAGE) |
| 1117 | # @Intent: Use the toolchain bintools method for printing memory usage |
| 1118 | set(memUsageCmd "") |
| 1119 | set(memUsageByProd "") |
| 1120 | bintools_print_mem_usage( |
| 1121 | RESULT_CMD_LIST memUsageCmd |
| 1122 | RESULT_BYPROD_LIST memUsageByProd |
| 1123 | ) |
| 1124 | list(APPEND |
| 1125 | post_build_commands |
| 1126 | ${memUsageCmd} |
| 1127 | ) |
| 1128 | list(APPEND |
| 1129 | post_build_byproducts |
| 1130 | ${memUsageByProd} |
| 1131 | ) |
| 1132 | endif() |
| 1133 | |
Kumar Gala | d541913 | 2019-08-13 13:44:20 -0500 | [diff] [blame] | 1134 | if(CONFIG_BUILD_OUTPUT_HEX OR BOARD_FLASH_RUNNER STREQUAL openocd) |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1135 | set(out_hex_cmd "") |
| 1136 | set(out_hex_byprod "") |
| 1137 | set(out_hex_sections_remove |
| 1138 | .comment |
| 1139 | COMMON |
| 1140 | .eh_frame |
| 1141 | ) |
| 1142 | bintools_objcopy( |
| 1143 | RESULT_CMD_LIST out_hex_cmd |
| 1144 | RESULT_BYPROD_LIST out_hex_byprod |
| 1145 | STRIP_ALL |
| 1146 | GAP_FILL ${GAP_FILL} |
| 1147 | TARGET_OUTPUT "ihex" |
| 1148 | SECTION_REMOVE ${out_hex_sections_remove} |
| 1149 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1150 | FILE_OUTPUT ${KERNEL_HEX_NAME} |
| 1151 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1152 | list(APPEND |
| 1153 | post_build_commands |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1154 | ${out_hex_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1155 | ) |
| 1156 | list(APPEND |
| 1157 | post_build_byproducts |
| 1158 | ${KERNEL_HEX_NAME} |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1159 | ${out_hex_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1160 | ) |
| 1161 | endif() |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1162 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1163 | if(CONFIG_BUILD_OUTPUT_BIN) |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1164 | set(out_bin_cmd "") |
| 1165 | set(out_bin_byprod "") |
| 1166 | set(out_bin_sections_remove |
| 1167 | .comment |
| 1168 | COMMON |
| 1169 | .eh_frame |
| 1170 | ) |
| 1171 | bintools_objcopy( |
| 1172 | RESULT_CMD_LIST out_bin_cmd |
| 1173 | RESULT_BYPROD_LIST out_bin_byprod |
| 1174 | STRIP_ALL |
| 1175 | GAP_FILL ${GAP_FILL} |
| 1176 | TARGET_OUTPUT "binary" |
| 1177 | SECTION_REMOVE ${out_bin_sections_remove} |
| 1178 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1179 | FILE_OUTPUT ${KERNEL_BIN_NAME} |
| 1180 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1181 | list(APPEND |
| 1182 | post_build_commands |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1183 | ${out_bin_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1184 | ) |
| 1185 | list(APPEND |
| 1186 | post_build_byproducts |
| 1187 | ${KERNEL_BIN_NAME} |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1188 | ${out_bin_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1189 | ) |
| 1190 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1191 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1192 | if(CONFIG_BUILD_OUTPUT_S19) |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1193 | set(out_S19_cmd "") |
| 1194 | set(out_S19_byprod "") |
| 1195 | bintools_objcopy( |
| 1196 | RESULT_CMD_LIST out_S19_cmd |
| 1197 | RESULT_BYPROD_LIST out_S19_byprod |
| 1198 | GAP_FILL ${GAP_FILL} |
| 1199 | TARGET_OUTPUT "srec" |
| 1200 | SREC_LEN 1 |
| 1201 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1202 | FILE_OUTPUT ${KERNEL_S19_NAME} |
| 1203 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1204 | list(APPEND |
| 1205 | post_build_commands |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1206 | ${out_S19_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1207 | ) |
| 1208 | list(APPEND |
| 1209 | post_build_byproducts |
| 1210 | ${KERNEL_S19_NAME} |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1211 | ${out_S19_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1212 | ) |
| 1213 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1214 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1215 | if(CONFIG_OUTPUT_DISASSEMBLY) |
Danny Oerndrup | 0760a53 | 2019-08-01 08:01:39 +0200 | [diff] [blame] | 1216 | set(out_disassembly_cmd "") |
| 1217 | set(out_disassembly_byprod "") |
Rohit Gujarathi | 35713f2 | 2020-05-07 10:08:37 +0530 | [diff] [blame] | 1218 | if(CONFIG_OUTPUT_DISASSEMBLE_ALL) |
| 1219 | set(disassembly_type DISASSEMBLE_ALL) |
| 1220 | else() |
| 1221 | set(disassembly_type DISASSEMBLE_SOURCE) |
| 1222 | endif() |
Danny Oerndrup | 0760a53 | 2019-08-01 08:01:39 +0200 | [diff] [blame] | 1223 | bintools_objdump( |
| 1224 | RESULT_CMD_LIST out_disassembly_cmd |
| 1225 | RESULT_BYPROD_LIST out_disassembly_byprod |
Rohit Gujarathi | 35713f2 | 2020-05-07 10:08:37 +0530 | [diff] [blame] | 1226 | ${disassembly_type} |
Danny Oerndrup | 0760a53 | 2019-08-01 08:01:39 +0200 | [diff] [blame] | 1227 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1228 | FILE_OUTPUT ${KERNEL_LST_NAME} |
| 1229 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1230 | list(APPEND |
| 1231 | post_build_commands |
Danny Oerndrup | 0760a53 | 2019-08-01 08:01:39 +0200 | [diff] [blame] | 1232 | ${out_disassembly_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1233 | ) |
| 1234 | list(APPEND |
| 1235 | post_build_byproducts |
| 1236 | ${KERNEL_LST_NAME} |
Danny Oerndrup | 0760a53 | 2019-08-01 08:01:39 +0200 | [diff] [blame] | 1237 | ${out_disassembly_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1238 | ) |
| 1239 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1240 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1241 | if(CONFIG_OUTPUT_STAT) |
Danny Oerndrup | 919df01 | 2019-08-01 08:04:12 +0200 | [diff] [blame] | 1242 | set(out_stat_cmd "") |
| 1243 | set(out_stat_byprod "") |
| 1244 | bintools_readelf( |
| 1245 | RESULT_CMD_LIST out_stat_cmd |
| 1246 | RESULT_BYPROD_LIST out_stat_byprod |
| 1247 | HEADERS |
| 1248 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1249 | FILE_OUTPUT ${KERNEL_STAT_NAME} |
| 1250 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1251 | list(APPEND |
| 1252 | post_build_commands |
Danny Oerndrup | 919df01 | 2019-08-01 08:04:12 +0200 | [diff] [blame] | 1253 | ${out_stat_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1254 | ) |
| 1255 | list(APPEND |
| 1256 | post_build_byproducts |
| 1257 | ${KERNEL_STAT_NAME} |
Danny Oerndrup | 919df01 | 2019-08-01 08:04:12 +0200 | [diff] [blame] | 1258 | ${out_stat_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1259 | ) |
| 1260 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1261 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1262 | if(CONFIG_BUILD_OUTPUT_STRIPPED) |
Danny Oerndrup | 9336e3e | 2019-08-01 08:06:54 +0200 | [diff] [blame] | 1263 | set(out_stripped_cmd "") |
| 1264 | set(out_stripped_byprod "") |
| 1265 | bintools_strip( |
| 1266 | RESULT_CMD_LIST out_stripped_cmd |
| 1267 | RESULT_BYPROD_LIST out_stripped_byprod |
| 1268 | STRIP_ALL |
| 1269 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1270 | FILE_OUTPUT ${KERNEL_STRIP_NAME} |
| 1271 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1272 | list(APPEND |
| 1273 | post_build_commands |
Danny Oerndrup | 9336e3e | 2019-08-01 08:06:54 +0200 | [diff] [blame] | 1274 | ${out_stripped_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1275 | ) |
| 1276 | list(APPEND |
| 1277 | post_build_byproducts |
| 1278 | ${KERNEL_STRIP_NAME} |
Danny Oerndrup | 9336e3e | 2019-08-01 08:06:54 +0200 | [diff] [blame] | 1279 | ${out_stripped_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1280 | ) |
| 1281 | endif() |
| 1282 | |
| 1283 | if(CONFIG_BUILD_OUTPUT_EXE) |
| 1284 | list(APPEND |
| 1285 | post_build_commands |
| 1286 | COMMAND |
| 1287 | ${CMAKE_COMMAND} -E copy ${KERNEL_ELF_NAME} ${KERNEL_EXE_NAME} |
| 1288 | ) |
| 1289 | list(APPEND |
| 1290 | post_build_byproducts |
| 1291 | ${KERNEL_EXE_NAME} |
| 1292 | ) |
| 1293 | endif() |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1294 | |
Rajavardhan Gundi | ecdea1c | 2019-01-25 11:53:13 +0530 | [diff] [blame] | 1295 | get_property(extra_post_build_commands |
| 1296 | GLOBAL PROPERTY |
| 1297 | extra_post_build_commands |
| 1298 | ) |
| 1299 | |
| 1300 | list(APPEND |
| 1301 | post_build_commands |
| 1302 | ${extra_post_build_commands} |
| 1303 | ) |
| 1304 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1305 | get_property(extra_post_build_byproducts |
| 1306 | GLOBAL PROPERTY |
| 1307 | extra_post_build_byproducts |
| 1308 | ) |
| 1309 | |
| 1310 | list(APPEND |
| 1311 | post_build_byproducts |
| 1312 | ${extra_post_build_byproducts} |
| 1313 | ) |
| 1314 | |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1315 | # Add post_build_commands to post-process the final .elf file produced by |
| 1316 | # either the ZEPHYR_PREBUILT_EXECUTABLE or the KERNEL_ELF executable |
| 1317 | # targets above. |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1318 | add_custom_command( |
| 1319 | TARGET ${logical_target_for_zephyr_elf} |
| 1320 | POST_BUILD |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1321 | ${post_build_commands} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1322 | BYPRODUCTS |
| 1323 | ${post_build_byproducts} |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1324 | COMMENT "Generating files from ${KERNEL_ELF_NAME} for board: ${BOARD}" |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1325 | # NB: COMMENT only works for some CMake-Generators |
Rajavardhan Gundi | ecdea1c | 2019-01-25 11:53:13 +0530 | [diff] [blame] | 1326 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1327 | |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1328 | # To populate with hex files to merge, do the following: |
| 1329 | # set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE ${my_local_list}) |
| 1330 | # Note that the zephyr.hex file will not be included automatically. |
| 1331 | get_property(HEX_FILES_TO_MERGE GLOBAL PROPERTY HEX_FILES_TO_MERGE) |
| 1332 | if(HEX_FILES_TO_MERGE) |
| 1333 | # Merge in out-of-tree hex files. |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1334 | set(MERGED_HEX_NAME merged.hex) |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1335 | |
| 1336 | add_custom_command( |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1337 | OUTPUT ${MERGED_HEX_NAME} |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1338 | COMMAND |
| 1339 | ${PYTHON_EXECUTABLE} |
| 1340 | ${ZEPHYR_BASE}/scripts/mergehex.py |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1341 | -o ${MERGED_HEX_NAME} |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1342 | ${HEX_FILES_TO_MERGE} |
| 1343 | DEPENDS ${HEX_FILES_TO_MERGE} ${logical_target_for_zephyr_elf} |
| 1344 | ) |
| 1345 | |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1346 | add_custom_target(mergehex ALL DEPENDS ${MERGED_HEX_NAME}) |
Torsten Rasmussen | d38da9d | 2020-06-30 09:55:54 +0200 | [diff] [blame] | 1347 | list(APPEND RUNNERS_DEPS mergehex) |
Håkon Øye Amundsen | c9a2a5e | 2020-01-03 08:25:03 +0000 | [diff] [blame] | 1348 | |
| 1349 | message(VERBOSE "Merging hex files: ${HEX_FILES_TO_MERGE}") |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1350 | endif() |
| 1351 | |
Anas Nashif | c15d3c9 | 2017-11-21 18:54:55 -0500 | [diff] [blame] | 1352 | if(EMU_PLATFORM) |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 1353 | include(${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake) |
Anas Nashif | fd276ae | 2017-12-21 16:45:45 -0500 | [diff] [blame] | 1354 | else() |
| 1355 | add_custom_target(run |
| 1356 | COMMAND |
| 1357 | ${CMAKE_COMMAND} -E echo |
| 1358 | "===================================================" |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 1359 | "Emulation/Simulation not supported with this board." |
Anas Nashif | fd276ae | 2017-12-21 16:45:45 -0500 | [diff] [blame] | 1360 | "===================================================" |
| 1361 | ) |
Anas Nashif | c15d3c9 | 2017-11-21 18:54:55 -0500 | [diff] [blame] | 1362 | endif() |
| 1363 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1364 | add_subdirectory(cmake/flash) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1365 | add_subdirectory(cmake/usage) |
| 1366 | add_subdirectory(cmake/reports) |
| 1367 | |
Sebastian Bøe | d3a8fd4 | 2019-10-17 14:25:34 +0200 | [diff] [blame] | 1368 | add_subdirectory_ifdef( |
| 1369 | CONFIG_MAKEFILE_EXPORTS |
| 1370 | cmake/makefile_exports |
| 1371 | ) |
| 1372 | |
Marc Herbert | 8372310 | 2019-06-17 13:26:11 -0700 | [diff] [blame] | 1373 | if(NOT CONFIG_TEST) |
Andrew Boie | 411686f | 2018-05-24 13:18:36 -0700 | [diff] [blame] | 1374 | if(CONFIG_ASSERT AND (NOT CONFIG_FORCE_NO_ASSERT)) |
Sebastian Bøe | fa8f9d4 | 2019-12-06 12:54:53 +0100 | [diff] [blame] | 1375 | message(WARNING "__ASSERT() statements are globally ENABLED") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1376 | endif() |
Marc Herbert | 8372310 | 2019-06-17 13:26:11 -0700 | [diff] [blame] | 1377 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1378 | |
Vincent Wan | a2bc514 | 2020-01-09 14:20:44 -0800 | [diff] [blame] | 1379 | if(CONFIG_BOARD_DEPRECATED_RELEASE) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1380 | message(WARNING " |
| 1381 | WARNING: The board '${BOARD}' is deprecated and will be |
Vincent Wan | a2bc514 | 2020-01-09 14:20:44 -0800 | [diff] [blame] | 1382 | removed in version ${CONFIG_BOARD_DEPRECATED_RELEASE}" |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 1383 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1384 | endif() |
Paul Sokolovsky | 1c6a7d7 | 2019-06-06 21:12:14 +0300 | [diff] [blame] | 1385 | |
Vincent Wan | 180b4df | 2020-01-08 17:10:51 -0800 | [diff] [blame] | 1386 | if(CONFIG_SOC_DEPRECATED_RELEASE) |
| 1387 | message(WARNING " |
| 1388 | WARNING: The SoC '${SOC_NAME}' is deprecated and will be |
| 1389 | removed in version ${CONFIG_SOC_DEPRECATED_RELEASE}" |
| 1390 | ) |
| 1391 | endif() |
| 1392 | |
Sebastian Bøe | e50e12d | 2019-08-29 16:19:32 +0200 | [diff] [blame] | 1393 | # In CMake projects, 'CMAKE_BUILD_TYPE' usually determines the |
| 1394 | # optimization flag, but in Zephyr it is determined through |
| 1395 | # Kconfig. Here we give a warning when there is a mismatch between the |
| 1396 | # two in case the user is not aware of this. |
| 1397 | set(build_types None Debug Release RelWithDebInfo MinSizeRel) |
| 1398 | |
| 1399 | if((CMAKE_BUILD_TYPE IN_LIST build_types) AND (NOT NO_BUILD_TYPE_WARNING)) |
| 1400 | string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_uppercase) |
| 1401 | |
Jack Dähn | e41bdcd | 2019-11-15 19:01:39 +0100 | [diff] [blame] | 1402 | if(NOT (${OPTIMIZATION_FLAG} IN_LIST CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_uppercase})) |
Sebastian Bøe | e50e12d | 2019-08-29 16:19:32 +0200 | [diff] [blame] | 1403 | message(WARNING " |
| 1404 | The CMake build type was set to '${CMAKE_BUILD_TYPE}', but the optimization flag was set to '${OPTIMIZATION_FLAG}'. |
| 1405 | This may be intentional and the warning can be turned off by setting the CMake variable 'NO_BUILD_TYPE_WARNING'" |
| 1406 | ) |
| 1407 | endif() |
| 1408 | endif() |
| 1409 | |
Paul Sokolovsky | 1c6a7d7 | 2019-06-06 21:12:14 +0300 | [diff] [blame] | 1410 | # @Intent: Set compiler specific flags for standard C includes |
| 1411 | # Done at the very end, so any other system includes which may |
| 1412 | # be added by Zephyr components were first in list. |
| 1413 | toolchain_cc_nostdinc() |