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) |
| 57 | |
| 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 | if(CONFIG_ARM) |
| 355 | set(PRIV_STACK_DEP priv_stacks_prebuilt) |
| 356 | endif() |
| 357 | endif() |
| 358 | |
Håkon Øye Amundsen | a449439 | 2018-11-29 09:14:27 +0000 | [diff] [blame] | 359 | get_property(TOPT GLOBAL PROPERTY TOPT) |
Oleg Zhurakivskyy | 2211935 | 2019-03-08 11:29:33 +0200 | [diff] [blame] | 360 | set_ifndef( TOPT -Wl,-T) # clang doesn't pick -T for some reason and complains, |
| 361 | # while -Wl,-T works for both, gcc and clang |
Håkon Øye Amundsen | a449439 | 2018-11-29 09:14:27 +0000 | [diff] [blame] | 362 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 363 | if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT) |
| 364 | set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT}) |
Sebastian Bøe | c1aa9d1 | 2018-04-12 14:48:05 +0200 | [diff] [blame] | 365 | if(NOT EXISTS ${LINKER_SCRIPT}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 366 | set(LINKER_SCRIPT ${CONFIG_CUSTOM_LINKER_SCRIPT}) |
Sebastian Bøe | c1aa9d1 | 2018-04-12 14:48:05 +0200 | [diff] [blame] | 367 | assert_exists(CONFIG_CUSTOM_LINKER_SCRIPT) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 368 | endif() |
| 369 | else() |
| 370 | # Try a board specific linker file |
| 371 | set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld) |
| 372 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 373 | # If not available, try an SoC specific linker file |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 374 | set(LINKER_SCRIPT ${SOC_DIR}/${ARCH}/${SOC_PATH}/linker.ld) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 375 | endif() |
| 376 | endif() |
| 377 | |
| 378 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 379 | message(FATAL_ERROR "Could not find linker script: '${LINKER_SCRIPT}'. Corrupted configuration?") |
| 380 | endif() |
| 381 | |
Kristian Klomsten Skordal | 0225e95 | 2018-01-30 11:26:42 +0100 | [diff] [blame] | 382 | # Custom section support in linker scripts requires that the application source |
| 383 | # directory is in the preprocessor search path, in order to find the custom |
| 384 | # linker script fragments. |
| 385 | if(CONFIG_CUSTOM_RODATA_LD OR CONFIG_CUSTOM_RWDATA_LD OR CONFIG_CUSTOM_SECTIONS_LD) |
| 386 | zephyr_include_directories(${APPLICATION_SOURCE_DIR}) |
| 387 | endif() |
| 388 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 389 | configure_file(version.h.in ${PROJECT_BINARY_DIR}/include/generated/version.h) |
| 390 | |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 391 | # Error-out when the deprecated naming convention is found (until |
| 392 | # after 1.14.0 has been released) |
| 393 | foreach(path |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 394 | ${BOARD_DIR}/dts.fixup |
| 395 | ${PROJECT_SOURCE_DIR}/soc/${ARCH}/${SOC_PATH}/dts.fixup |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 396 | ${APPLICATION_SOURCE_DIR}/dts.fixup |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 397 | ) |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 398 | if(EXISTS ${path}) |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 399 | message(FATAL_ERROR |
| 400 | "A deprecated filename has been detected. Porting is required." |
| 401 | "The file '${path}' exists, but it should be named dts_fixup.h instead." |
| 402 | "See https://github.com/zephyrproject-rtos/zephyr/pull/10352 for more details" |
| 403 | ) |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 404 | endif() |
| 405 | endforeach() |
| 406 | |
| 407 | set_ifndef( DTS_BOARD_FIXUP_FILE ${BOARD_DIR}/dts_fixup.h) |
| 408 | set_ifndef( DTS_SOC_FIXUP_FILE ${SOC_DIR}/${ARCH}/${SOC_PATH}/dts_fixup.h) |
| 409 | set( DTS_APP_FIXUP_FILE ${APPLICATION_SOURCE_DIR}/dts_fixup.h) |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 410 | |
Ulf Magnusson | 4e85006 | 2020-01-16 13:29:53 +0100 | [diff] [blame] | 411 | 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] | 412 | |
| 413 | # Concatenate the fixups into a single header file for easy |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 414 | # #include'ing |
Ulf Magnusson | 4e85006 | 2020-01-16 13:29:53 +0100 | [diff] [blame] | 415 | file(WRITE ${DTS_CAT_OF_FIXUP_FILES} "/* May only be included by devicetree.h */\n\n") |
Sebastian Bøe | 361fdaa | 2019-01-28 13:40:50 +0100 | [diff] [blame] | 416 | foreach(fixup_file |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 417 | ${DTS_BOARD_FIXUP_FILE} |
| 418 | ${DTS_SOC_FIXUP_FILE} |
| 419 | ${DTS_APP_FIXUP_FILE} |
| 420 | ${shield_dts_fixups} |
| 421 | ) |
Sebastian Bøe | 361fdaa | 2019-01-28 13:40:50 +0100 | [diff] [blame] | 422 | if(EXISTS ${fixup_file}) |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 423 | file(READ ${fixup_file} contents) |
| 424 | file(APPEND ${DTS_CAT_OF_FIXUP_FILES} "${contents}") |
Sebastian Bøe | c23cc26 | 2018-10-09 16:03:29 +0200 | [diff] [blame] | 425 | endif() |
| 426 | endforeach() |
| 427 | |
Sebastian Bøe | 6f946e2 | 2018-01-09 10:52:57 +0100 | [diff] [blame] | 428 | # Unfortunately, the order in which CMakeLists.txt code is processed |
| 429 | # matters so we need to be careful about how we order the processing |
| 430 | # of subdirectories. One example is "Compiler flags added late in the |
| 431 | # build are not exported to external build systems #5605"; when we |
| 432 | # integrate with an external build system we read out all compiler |
| 433 | # flags when the external project is created. So an external project |
| 434 | # defined in subsys or ext will not get global flags added by drivers/ |
| 435 | # or tests/ as the subdirectories are ordered now. |
| 436 | # |
| 437 | # Another example of when the order matters is the reading and writing |
| 438 | # of global properties such as ZEPHYR_LIBS or |
| 439 | # GENERATED_KERNEL_OBJECT_FILES. |
| 440 | # |
| 441 | # Arch is placed early because it defines important compiler flags |
| 442 | # that must be exported to external build systems defined in |
| 443 | # e.g. subsys/. |
| 444 | add_subdirectory(arch) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 445 | add_subdirectory(lib) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 446 | # We use include instead of add_subdirectory to avoid creating a new directory scope. |
| 447 | # This is because source file properties are directory scoped, including the GENERATED |
| 448 | # property which is set implicitly for custom command outputs |
| 449 | include(misc/generated/CMakeLists.txt) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 450 | |
Erwan Gouriou | ba31cb5 | 2018-09-13 16:25:53 +0200 | [diff] [blame] | 451 | if(EXISTS ${SOC_DIR}/${ARCH}/CMakeLists.txt) |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 452 | add_subdirectory(${SOC_DIR}/${ARCH} soc/${ARCH}) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 453 | else() |
Anas Nashif | 96455d5 | 2018-09-04 14:34:06 -0500 | [diff] [blame] | 454 | add_subdirectory(${SOC_DIR}/${ARCH}/${SOC_PATH} soc/${ARCH}/${SOC_PATH}) |
Anas Nashif | 3d1252f | 2018-09-03 15:20:14 -0500 | [diff] [blame] | 455 | endif() |
| 456 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 457 | add_subdirectory(boards) |
| 458 | add_subdirectory(ext) |
| 459 | add_subdirectory(subsys) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 460 | add_subdirectory(drivers) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 461 | |
Torsten Rasmussen | bd7569f | 2019-03-19 10:38:18 +0100 | [diff] [blame] | 462 | # Include zephyr modules generated CMake file. |
| 463 | if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt) |
Carles Cufi | 3ad1f27 | 2019-07-18 10:38:25 +0200 | [diff] [blame] | 464 | file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt ZEPHYR_MODULES_TXT |
| 465 | ENCODING UTF-8) |
Torsten Rasmussen | 08eabb8 | 2019-12-06 12:19:35 +0100 | [diff] [blame] | 466 | set(module_names) |
Torsten Rasmussen | bd7569f | 2019-03-19 10:38:18 +0100 | [diff] [blame] | 467 | |
| 468 | foreach(module ${ZEPHYR_MODULES_TXT}) |
Carles Cufi | 766edd4 | 2019-03-31 22:29:30 +0200 | [diff] [blame] | 469 | # Match "<name>":"<path>" for each line of file, each corresponding to |
| 470 | # one module. The use of quotes is required due to CMake not supporting |
| 471 | # lazy regexes (it supports greedy only). |
| 472 | string(REGEX REPLACE "\"(.*)\":\".*\"" "\\1" module_name ${module}) |
| 473 | string(REGEX REPLACE "\".*\":\"(.*)\"" "\\1" module_path ${module}) |
Torsten Rasmussen | 08eabb8 | 2019-12-06 12:19:35 +0100 | [diff] [blame] | 474 | |
| 475 | list(APPEND module_names ${module_name}) |
| 476 | |
| 477 | string(TOUPPER ${module_name} MODULE_NAME_UPPER) |
| 478 | set(ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR ${module_path}) |
| 479 | endforeach() |
| 480 | |
| 481 | foreach(module_name ${module_names}) |
Marc Herbert | d3d3394 | 2019-05-31 15:37:40 -0700 | [diff] [blame] | 482 | # Note the second, binary_dir parameter requires the added |
| 483 | # subdirectory to have its own, local cmake target(s). If not then |
| 484 | # this binary_dir is created but stays empty. Object files land in |
| 485 | # the main binary dir instead. |
| 486 | # https://cmake.org/pipermail/cmake/2019-June/069547.html |
Torsten Rasmussen | 08eabb8 | 2019-12-06 12:19:35 +0100 | [diff] [blame] | 487 | string(TOUPPER ${module_name} MODULE_NAME_UPPER) |
| 488 | set(ZEPHYR_CURRENT_MODULE_DIR ${ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR}) |
Torsten Rasmussen | 4b68f95 | 2020-01-09 12:31:58 +0100 | [diff] [blame] | 489 | add_subdirectory(${ZEPHYR_CURRENT_MODULE_DIR} ${CMAKE_BINARY_DIR}/modules/${module_name}) |
Torsten Rasmussen | bd7569f | 2019-03-19 10:38:18 +0100 | [diff] [blame] | 490 | endforeach() |
Torsten Rasmussen | f0fa7b8 | 2019-10-21 10:08:20 +0200 | [diff] [blame] | 491 | # Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR. |
| 492 | set(ZEPHYR_CURRENT_MODULE_DIR) |
Torsten Rasmussen | 605ae10 | 2019-02-12 10:19:38 +0100 | [diff] [blame] | 493 | endif() |
Torsten Rasmussen | 7e9d1bd | 2019-02-05 10:36:22 +0100 | [diff] [blame] | 494 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 495 | set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h) |
| 496 | set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json) |
| 497 | |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 498 | # The syscalls subdirs txt file is constructed by python containing a list of folders to use for |
| 499 | # dependency handling, including empty folders. |
| 500 | # Windows: The list is used to specify DIRECTORY list with CMAKE_CONFIGURE_DEPENDS attribute. |
| 501 | # Other OS: The list will update whenever a file is added/removed/modified and ensure a re-build. |
| 502 | set(syscalls_subdirs_txt ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_subdirs.txt) |
| 503 | |
| 504 | # As syscalls_subdirs_txt is updated whenever a file is modified, this file can not be used for |
| 505 | # monitoring of added / removed folders. A trigger file is thus used for correct dependency |
| 506 | # handling. The trigger file will update when a folder is added / removed. |
| 507 | set(syscalls_subdirs_trigger ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_subdirs.trigger) |
| 508 | |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 509 | if(NOT (${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)) |
| 510 | set(syscalls_links --create-links ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls_links) |
| 511 | endif() |
| 512 | |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 513 | # When running CMake it must be ensured that all dependencies are correctly acquired. |
| 514 | execute_process( |
| 515 | COMMAND |
| 516 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 517 | ${ZEPHYR_BASE}/scripts/subfolder_list.py |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 518 | --directory ${ZEPHYR_BASE}/include # Walk this directory |
| 519 | --out-file ${syscalls_subdirs_txt} # Write file with discovered folder |
| 520 | --trigger ${syscalls_subdirs_trigger} # Trigger file that is used for json generation |
| 521 | ${syscalls_links} # If defined, create symlinks for dependencies |
| 522 | ) |
Carles Cufi | 3ad1f27 | 2019-07-18 10:38:25 +0200 | [diff] [blame] | 523 | file(STRINGS ${syscalls_subdirs_txt} PARSE_SYSCALLS_PATHS_DEPENDS ENCODING UTF-8) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 524 | |
| 525 | if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows) |
| 526 | # On windows only adding/removing files or folders will be reflected in depends. |
| 527 | # Hence adding a file requires CMake to re-run to add this file to the file list. |
| 528 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${PARSE_SYSCALLS_PATHS_DEPENDS}) |
| 529 | |
| 530 | # Also On Windows each header file must be monitored as file modifications are not reflected |
| 531 | # on directory level. |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 532 | file(GLOB_RECURSE PARSE_SYSCALLS_HEADER_DEPENDS ${ZEPHYR_BASE}/include/*.h) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 533 | else() |
| 534 | # The syscall parsing depends on the folders in order to detect add/removed/modified files. |
| 535 | # When a folder is removed, CMake will try to find a target that creates that dependency. |
| 536 | # This command sets up the target for CMake to find. |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 537 | # Without this code, CMake will fail with the following error: |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 538 | # <folder> needed by '<target>', missing and no known rule to make it |
| 539 | # when a folder is removed. |
| 540 | add_custom_command(OUTPUT ${PARSE_SYSCALLS_PATHS_DEPENDS} |
| 541 | COMMAND ${CMAKE_COMMAND} -E echo "" |
| 542 | COMMENT "Preparing syscall dependency handling" |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 543 | ) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 544 | |
| 545 | add_custom_command( |
| 546 | OUTPUT |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 547 | ${syscalls_subdirs_trigger} |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 548 | COMMAND |
| 549 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 550 | ${ZEPHYR_BASE}/scripts/subfolder_list.py |
| 551 | --directory ${ZEPHYR_BASE}/include # Walk this directory |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 552 | --out-file ${syscalls_subdirs_txt} # Write file with discovered folder |
| 553 | --trigger ${syscalls_subdirs_trigger} # Trigger file that is used for json generation |
| 554 | ${syscalls_links} # If defined, create symlinks for dependencies |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 555 | DEPENDS ${PARSE_SYSCALLS_PATHS_DEPENDS} |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 556 | ) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 557 | |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 558 | # Ensure subdir file always exists when specifying CMake dependency. |
| 559 | if(NOT EXISTS ${syscalls_subdirs_txt}) |
| 560 | file(WRITE ${syscalls_subdirs_txt} "") |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 561 | endif() |
| 562 | |
| 563 | # On other OS'es, modifying a file is reflected on the folder timestamp and hence detected |
| 564 | # when using depend on directory level. |
| 565 | # Thus CMake only needs to re-run when sub-directories are added / removed, which is indicated |
| 566 | # using a trigger file. |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 567 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${syscalls_subdirs_txt}) |
Torsten Rasmussen | f38e388 | 2018-06-07 15:50:31 +0200 | [diff] [blame] | 568 | endif() |
| 569 | |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 570 | # syscall declarations are searched for in the SYSCALL_INCLUDE_DIRS |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 571 | if(CONFIG_APPLICATION_DEFINED_SYSCALL) |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 572 | list(APPEND SYSCALL_INCLUDE_DIRS ${APPLICATION_SOURCE_DIR}) |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 573 | endif() |
| 574 | |
Andrew Boie | c186387 | 2019-11-21 23:11:29 -0800 | [diff] [blame] | 575 | if(CONFIG_ZTEST) |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 576 | list(APPEND SYSCALL_INCLUDE_DIRS ${ZEPHYR_BASE}/subsys/testsuite/ztest/include) |
Andrew Boie | c186387 | 2019-11-21 23:11:29 -0800 | [diff] [blame] | 577 | endif() |
| 578 | |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 579 | foreach(d ${SYSCALL_INCLUDE_DIRS}) |
| 580 | list(APPEND parse_syscalls_include_args |
| 581 | --include ${d} |
| 582 | ) |
| 583 | endforeach() |
| 584 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 585 | add_custom_command( |
| 586 | OUTPUT |
| 587 | ${syscalls_json} |
| 588 | COMMAND |
| 589 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 590 | ${ZEPHYR_BASE}/scripts/parse_syscalls.py |
Adithya Baglody | e67720b | 2018-07-02 14:59:19 +0530 | [diff] [blame] | 591 | --include ${ZEPHYR_BASE}/include # Read files from this dir |
Sebastian Bøe | 56f6e35 | 2018-04-30 15:59:16 +0200 | [diff] [blame] | 592 | ${parse_syscalls_include_args} # Read files from these dirs also |
Torsten Rasmussen | 080e32e | 2018-06-14 22:27:17 +0200 | [diff] [blame] | 593 | --json-file ${syscalls_json} # Write this file |
| 594 | DEPENDS ${syscalls_subdirs_trigger} ${PARSE_SYSCALLS_HEADER_DEPENDS} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 595 | ) |
| 596 | |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 597 | add_custom_target(${SYSCALL_LIST_H_TARGET} DEPENDS ${syscall_list_h}) |
Andrew Boie | 9ff64bb | 2019-11-05 09:39:05 -0800 | [diff] [blame] | 598 | |
| 599 | # 64-bit systems do not require special handling of 64-bit system call |
| 600 | # parameters or return values, indicate this to the system call boilerplate |
| 601 | # generation script. |
| 602 | if(CONFIG_64BIT) |
| 603 | set(SYSCALL_LONG_REGISTERS_ARG --long-registers) |
| 604 | endif() |
| 605 | |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 606 | add_custom_command(OUTPUT include/generated/syscall_dispatch.c ${syscall_list_h} |
| 607 | # Also, some files are written to include/generated/syscalls/ |
| 608 | COMMAND |
| 609 | ${PYTHON_EXECUTABLE} |
Alex Tereschenko | 3c1a78e | 2018-06-14 20:21:18 +0200 | [diff] [blame] | 610 | ${ZEPHYR_BASE}/scripts/gen_syscalls.py |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 611 | --json-file ${syscalls_json} # Read this file |
| 612 | --base-output include/generated/syscalls # Write to this dir |
| 613 | --syscall-dispatch include/generated/syscall_dispatch.c # Write this file |
Andrew Boie | 353acf4 | 2018-07-23 18:10:15 -0700 | [diff] [blame] | 614 | --syscall-list ${syscall_list_h} |
Andrew Boie | 9ff64bb | 2019-11-05 09:39:05 -0800 | [diff] [blame] | 615 | ${SYSCALL_LONG_REGISTERS_ARG} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 616 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 617 | DEPENDS ${syscalls_json} |
| 618 | ) |
| 619 | |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 620 | set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/driver-validation.h) |
| 621 | add_custom_command( |
| 622 | OUTPUT ${DRV_VALIDATION} |
| 623 | COMMAND |
| 624 | ${PYTHON_EXECUTABLE} |
| 625 | ${ZEPHYR_BASE}/scripts/gen_kobject_list.py |
| 626 | --validation-output ${DRV_VALIDATION} |
| 627 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Bradley Bolen | 4198ba7 | 2019-04-12 12:00:52 -0400 | [diff] [blame] | 628 | DEPENDS ${ZEPHYR_BASE}/scripts/gen_kobject_list.py |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 629 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 630 | ) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 631 | add_custom_target(${DRIVER_VALIDATION_H_TARGET} DEPENDS ${DRV_VALIDATION}) |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 632 | |
Leandro Pereira | 39dc7d0 | 2018-04-05 13:59:33 -0700 | [diff] [blame] | 633 | include($ENV{ZEPHYR_BASE}/cmake/kobj.cmake) |
| 634 | gen_kobj(KOBJ_INCLUDE_PATH) |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 635 | |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 636 | # Add a pseudo-target that is up-to-date when all generated headers |
| 637 | # are up-to-date. |
| 638 | |
| 639 | add_custom_target(zephyr_generated_headers) |
| 640 | add_dependencies(zephyr_generated_headers |
| 641 | offsets_h |
| 642 | ) |
| 643 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 644 | # Generate offsets.c.obj from offsets.c |
| 645 | # Generate offsets.h from offsets.c.obj |
| 646 | |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 647 | set(OFFSETS_LIB offsets) |
| 648 | |
Klaus Petersen | c66cb76 | 2018-11-15 10:37:46 +0100 | [diff] [blame] | 649 | set(OFFSETS_C_PATH ${ARCH_DIR}/${ARCH}/core/offsets/offsets.c) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 650 | set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h) |
| 651 | |
Klaus Petersen | 62e55e5 | 2019-02-04 12:10:57 +0100 | [diff] [blame] | 652 | add_library( ${OFFSETS_LIB} OBJECT ${OFFSETS_C_PATH}) |
Stephanos Ioannidis | 2d74604 | 2019-10-25 00:08:21 +0900 | [diff] [blame] | 653 | target_include_directories(${OFFSETS_LIB} PRIVATE |
| 654 | kernel/include |
| 655 | ${ARCH_DIR}/${ARCH}/include |
| 656 | ) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 657 | target_link_libraries(${OFFSETS_LIB} zephyr_interface) |
| 658 | add_dependencies( ${OFFSETS_LIB} |
| 659 | ${SYSCALL_LIST_H_TARGET} |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 660 | ${DRIVER_VALIDATION_H_TARGET} |
| 661 | ${KOBJ_TYPES_H_TARGET} |
Sebastian Bøe | 13a6840 | 2017-11-20 13:03:55 +0100 | [diff] [blame] | 662 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 663 | |
| 664 | add_custom_command( |
| 665 | OUTPUT ${OFFSETS_H_PATH} |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 666 | COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/gen_offset_header.py |
Klaus Petersen | 62e55e5 | 2019-02-04 12:10:57 +0100 | [diff] [blame] | 667 | -i $<TARGET_OBJECTS:${OFFSETS_LIB}> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 668 | -o ${OFFSETS_H_PATH} |
Sebastian Bøe | 5962aab | 2019-08-15 14:45:59 +0200 | [diff] [blame] | 669 | DEPENDS |
| 670 | ${OFFSETS_LIB} |
| 671 | $<TARGET_OBJECTS:${OFFSETS_LIB}> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 672 | ) |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 673 | add_custom_target(${OFFSETS_H_TARGET} DEPENDS ${OFFSETS_H_PATH}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 674 | |
| 675 | zephyr_include_directories(${TOOLCHAIN_INCLUDES}) |
| 676 | |
Sebastian Bøe | 89516fb | 2017-12-01 15:25:06 +0100 | [diff] [blame] | 677 | zephyr_get_include_directories_for_lang(C ZEPHYR_INCLUDES) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 678 | |
| 679 | add_subdirectory(kernel) |
| 680 | |
| 681 | # Read list content |
| 682 | get_property(ZEPHYR_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_LIBS) |
| 683 | |
| 684 | foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY}) |
| 685 | # TODO: Could this become an INTERFACE property of zephyr_interface? |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 686 | add_dependencies(${zephyr_lib} zephyr_generated_headers) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 687 | endforeach() |
| 688 | |
| 689 | get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) |
| 690 | |
Adithya Baglody | 62e152a | 2018-11-13 15:34:02 +0530 | [diff] [blame] | 691 | if (CONFIG_CODE_DATA_RELOCATION) |
| 692 | set(CODE_RELOCATION_DEP code_relocation_source_lib) |
| 693 | endif() # CONFIG_CODE_DATA_RELOCATION |
Sebastian Bøe | b85dd3c | 2017-12-31 10:39:23 +0100 | [diff] [blame] | 694 | |
Mark Ruvald Pedersen | 4c81197 | 2019-04-29 17:16:54 +0200 | [diff] [blame] | 695 | configure_linker_script( |
Mark Ruvald Pedersen | 1073fba | 2019-04-29 20:27:23 +0200 | [diff] [blame] | 696 | linker.cmd |
Mark Ruvald Pedersen | fbcea17 | 2019-04-29 20:35:12 +0200 | [diff] [blame] | 697 | "" |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 698 | ${PRIV_STACK_DEP} |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 699 | ${APP_SMEM_ALIGNED_DEP} |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 700 | ${CODE_RELOCATION_DEP} |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 701 | zephyr_generated_headers |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 702 | ) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 703 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 704 | add_custom_target( |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 705 | ${LINKER_SCRIPT_TARGET} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 706 | DEPENDS |
| 707 | linker.cmd |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 708 | ) |
| 709 | |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 710 | # 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] | 711 | # that cmake can successfully find the linker_script's header |
| 712 | # dependencies. |
| 713 | zephyr_get_include_directories_for_lang(C |
| 714 | ZEPHYR_INCLUDE_DIRS |
| 715 | STRIP_PREFIX # Don't use a -I prefix |
| 716 | ) |
| 717 | set_property(TARGET |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 718 | ${LINKER_SCRIPT_TARGET} |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 719 | PROPERTY INCLUDE_DIRECTORIES |
| 720 | ${ZEPHYR_INCLUDE_DIRS} |
| 721 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 722 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 723 | if(CONFIG_GEN_ISR_TABLES) |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 724 | if(CONFIG_GEN_SW_ISR_TABLE) |
| 725 | list(APPEND GEN_ISR_TABLE_EXTRA_ARG --sw-isr-table) |
| 726 | endif() |
| 727 | |
| 728 | if(CONFIG_GEN_IRQ_VECTOR_TABLE) |
| 729 | list(APPEND GEN_ISR_TABLE_EXTRA_ARG --vector-table) |
| 730 | endif() |
| 731 | |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 732 | # isr_tables.c is generated from ${ZEPHYR_PREBUILT_EXECUTABLE} by |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 733 | # gen_isr_tables.py |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 734 | set(obj_copy_cmd "") |
| 735 | bintools_objcopy( |
| 736 | RESULT_CMD_LIST obj_copy_cmd |
| 737 | TARGET_INPUT ${OUTPUT_FORMAT} |
| 738 | TARGET_OUTPUT "binary" |
| 739 | SECTION_ONLY ".intList" |
| 740 | FILE_INPUT $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}> |
| 741 | FILE_OUTPUT "isrList.bin" |
| 742 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 743 | add_custom_command( |
| 744 | OUTPUT isr_tables.c |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 745 | ${obj_copy_cmd} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 746 | COMMAND ${PYTHON_EXECUTABLE} |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 747 | ${ZEPHYR_BASE}/arch/common/gen_isr_tables.py |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 748 | --output-source isr_tables.c |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 749 | --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}> |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 750 | --intlist isrList.bin |
Yasushi SHOJI | 6fc0d77 | 2018-10-09 18:59:16 +0900 | [diff] [blame] | 751 | $<$<BOOL:${CONFIG_BIG_ENDIAN}>:--big-endian> |
Sebastian Bøe | a55279a | 2018-01-04 14:08:39 +0100 | [diff] [blame] | 752 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug> |
Rajavardhan Gundi | 08172cd | 2017-12-12 23:29:37 +0530 | [diff] [blame] | 753 | ${GEN_ISR_TABLE_EXTRA_ARG} |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 754 | DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 755 | ) |
| 756 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c) |
| 757 | endif() |
| 758 | |
Adithya Baglody | 62e152a | 2018-11-13 15:34:02 +0530 | [diff] [blame] | 759 | if(CONFIG_CODE_DATA_RELOCATION) |
Mark Ruvald Pedersen | 86a3e8f | 2019-05-03 10:33:03 +0200 | [diff] [blame] | 760 | # @Intent: Linker script to relocate .text, data and .bss sections |
| 761 | toolchain_ld_relocation() |
Adithya Baglody | 62e152a | 2018-11-13 15:34:02 +0530 | [diff] [blame] | 762 | endif() |
| 763 | |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 764 | if(CONFIG_USERSPACE) |
| 765 | zephyr_get_compile_options_for_lang_as_string(C compiler_flags_priv) |
| 766 | string(REPLACE "-ftest-coverage" "" NO_COVERAGE_FLAGS "${compiler_flags_priv}") |
| 767 | string(REPLACE "-fprofile-arcs" "" NO_COVERAGE_FLAGS "${NO_COVERAGE_FLAGS}") |
Daniel Leung | 84b1bba | 2019-04-01 15:57:35 -0700 | [diff] [blame] | 768 | string(REPLACE "-fno-inline" "" NO_COVERAGE_FLAGS "${NO_COVERAGE_FLAGS}") |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 769 | |
| 770 | get_property(include_dir_in_interface TARGET zephyr_interface |
| 771 | PROPERTY INTERFACE_INCLUDE_DIRECTORIES) |
| 772 | |
| 773 | get_property(sys_include_dir_in_interface TARGET zephyr_interface |
| 774 | PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) |
| 775 | |
| 776 | get_property(compile_definitions_interface TARGET zephyr_interface |
| 777 | PROPERTY INTERFACE_COMPILE_DEFINITIONS) |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 778 | endif() |
| 779 | |
| 780 | |
Marc Herbert | 4a10eea | 2019-04-16 15:39:45 -0700 | [diff] [blame] | 781 | # Warning most of this gperf code is duplicated below for |
| 782 | # gen_kobject_list.py / output_lib |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 783 | if(CONFIG_ARM AND CONFIG_USERSPACE) |
| 784 | set(GEN_PRIV_STACKS $ENV{ZEPHYR_BASE}/scripts/gen_priv_stacks.py) |
| 785 | set(PROCESS_PRIV_STACKS_GPERF $ENV{ZEPHYR_BASE}/scripts/process_gperf.py) |
| 786 | |
| 787 | set(PRIV_STACKS priv_stacks_hash.gperf) |
| 788 | set(PRIV_STACKS_OUTPUT_SRC_PRE priv_stacks_hash_preprocessed.c) |
| 789 | set(PRIV_STACKS_OUTPUT_SRC priv_stacks_hash.c) |
| 790 | set(PRIV_STACKS_OUTPUT_OBJ priv_stacks_hash.c.obj) |
| 791 | set(PRIV_STACKS_OUTPUT_OBJ_RENAMED priv_stacks_hash_renamed.o) |
| 792 | |
| 793 | # Essentially what we are doing here is extracting some information |
| 794 | # out of the nearly finished elf file, generating the source code |
| 795 | # for a hash table based on that information, and then compiling and |
| 796 | # linking the hash table back into a now even more nearly finished |
| 797 | # elf file. |
| 798 | |
| 799 | # Use the script GEN_PRIV_STACKS to scan the kernel binary's |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 800 | # (${ZEPHYR_PREBUILT_EXECUTABLE}) DWARF information to produce a table of kernel |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 801 | # objects (PRIV_STACKS) which we will then pass to gperf |
| 802 | add_custom_command( |
| 803 | OUTPUT ${PRIV_STACKS} |
| 804 | COMMAND |
| 805 | ${PYTHON_EXECUTABLE} |
| 806 | ${GEN_PRIV_STACKS} |
| 807 | --kernel $<TARGET_FILE:priv_stacks_prebuilt> |
| 808 | --output ${PRIV_STACKS} |
| 809 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 810 | DEPENDS priv_stacks_prebuilt |
| 811 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 812 | ) |
| 813 | add_custom_target(priv_stacks DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS}) |
| 814 | |
Sebastian Bøe | f17428a | 2020-01-29 15:39:33 +0100 | [diff] [blame] | 815 | if(${GPERF} STREQUAL GPERF-NOTFOUND) |
| 816 | message(FATAL_ERROR "Unable to find gperf") |
| 817 | endif() |
| 818 | |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 819 | # Use gperf to generate C code (PRIV_STACKS_OUTPUT_SRC_PRE) which implements a |
| 820 | # perfect hashtable based on PRIV_STACKS |
| 821 | add_custom_command( |
| 822 | OUTPUT ${PRIV_STACKS_OUTPUT_SRC_PRE} |
| 823 | COMMAND |
| 824 | ${GPERF} -C |
| 825 | --output-file ${PRIV_STACKS_OUTPUT_SRC_PRE} |
| 826 | ${PRIV_STACKS} |
Andy Gross | 878f39c | 2018-05-01 01:10:26 -0500 | [diff] [blame] | 827 | DEPENDS priv_stacks ${PRIV_STACKS} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 828 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 829 | ) |
| 830 | add_custom_target(priv_stacks_output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC_PRE}) |
| 831 | |
| 832 | # For our purposes the code/data generated by gperf is not optimal. |
| 833 | # |
| 834 | # The script PROCESS_GPERF creates a new c file OUTPUT_SRC based on |
| 835 | # OUTPUT_SRC_PRE to greatly reduce the amount of code/data generated |
| 836 | # since we know we are always working with pointer values |
| 837 | add_custom_command( |
| 838 | OUTPUT ${PRIV_STACKS_OUTPUT_SRC} |
| 839 | COMMAND |
Sebastian Bøe | 1b60070 | 2018-06-21 14:34:42 +0200 | [diff] [blame] | 840 | ${PYTHON_EXECUTABLE} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 841 | ${PROCESS_PRIV_STACKS_GPERF} |
| 842 | -i ${PRIV_STACKS_OUTPUT_SRC_PRE} |
| 843 | -o ${PRIV_STACKS_OUTPUT_SRC} |
| 844 | -p "struct _k_priv_stack_map" |
| 845 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Andy Gross | 878f39c | 2018-05-01 01:10:26 -0500 | [diff] [blame] | 846 | DEPENDS priv_stacks_output_src_pre ${PRIV_STACKS_OUTPUT_SRC_PRE} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 847 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 848 | ) |
| 849 | add_custom_target(priv_stacks_output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC}) |
| 850 | |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 851 | set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC} |
| 852 | PROPERTIES COMPILE_DEFINITIONS "${compile_definitions_interface}") |
| 853 | |
| 854 | set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC} |
| 855 | PROPERTIES COMPILE_FLAGS |
Andrew Boie | a514898 | 2019-03-14 17:04:11 -0700 | [diff] [blame] | 856 | "${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections ") |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 857 | |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 858 | # We need precise control of where generated text/data ends up in the final |
| 859 | # kernel image. Disable function/data sections and use objcopy to move |
| 860 | # generated data into special section names |
| 861 | add_library(priv_stacks_output_lib STATIC |
| 862 | ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_SRC} |
| 863 | ) |
| 864 | |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 865 | # Turn off -ffunction-sections, etc. |
| 866 | # NB: Using a library instead of target_compile_options(priv_stacks_output_lib |
| 867 | # [...]) because a library's options have precedence |
| 868 | add_library(priv_stacks_output_lib_interface INTERFACE) |
Kumar Gala | 3713ea4 | 2019-03-14 11:50:08 -0500 | [diff] [blame] | 869 | foreach(incl ${include_dir_in_interface}) |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 870 | target_include_directories(priv_stacks_output_lib_interface INTERFACE ${incl}) |
| 871 | endforeach() |
| 872 | |
Kumar Gala | 3713ea4 | 2019-03-14 11:50:08 -0500 | [diff] [blame] | 873 | foreach(incl ${sys_include_dir_in_interface}) |
| 874 | target_include_directories(priv_stacks_output_lib_interface SYSTEM INTERFACE ${incl}) |
| 875 | endforeach() |
| 876 | |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 877 | target_link_libraries(priv_stacks_output_lib priv_stacks_output_lib_interface) |
| 878 | |
| 879 | set(PRIV_STACKS_OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/priv_stacks_output_lib.dir/${PRIV_STACKS_OUTPUT_OBJ}) |
| 880 | |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 881 | set(obj_copy_cmd "") |
| 882 | set(obj_copy_sections_rename |
| 883 | .bss=.priv_stacks.noinit |
| 884 | .data=.priv_stacks.data |
| 885 | .text=.priv_stacks.text |
| 886 | .rodata=.priv_stacks.rodata |
| 887 | ) |
| 888 | bintools_objcopy( |
| 889 | RESULT_CMD_LIST obj_copy_cmd |
| 890 | SECTION_RENAME ${obj_copy_sections_rename} |
| 891 | FILE_INPUT ${PRIV_STACKS_OUTPUT_OBJ_PATH} |
| 892 | FILE_OUTPUT ${PRIV_STACKS_OUTPUT_OBJ_RENAMED} |
| 893 | ) |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 894 | add_custom_command( |
| 895 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED} |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 896 | ${obj_copy_cmd} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 897 | DEPENDS priv_stacks_output_lib |
| 898 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 899 | ) |
| 900 | add_custom_target(priv_stacks_output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED}) |
| 901 | |
| 902 | add_library(priv_stacks_output_obj_renamed_lib STATIC IMPORTED GLOBAL) |
| 903 | set_property( |
| 904 | TARGET priv_stacks_output_obj_renamed_lib |
| 905 | PROPERTY |
| 906 | IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${PRIV_STACKS_OUTPUT_OBJ_RENAMED} |
| 907 | ) |
| 908 | add_dependencies( |
| 909 | priv_stacks_output_obj_renamed_lib |
| 910 | priv_stacks_output_obj_renamed |
| 911 | ) |
| 912 | |
| 913 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES priv_stacks_output_obj_renamed_lib) |
| 914 | endif() |
| 915 | |
Marc Herbert | 4a10eea | 2019-04-16 15:39:45 -0700 | [diff] [blame] | 916 | # Warning: most of this gperf code is duplicated above for |
| 917 | # gen_priv_stacks.py / priv_stacks_output_lib |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 918 | if(CONFIG_USERSPACE) |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 919 | set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/gen_kobject_list.py) |
| 920 | set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/process_gperf.py) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 921 | |
| 922 | set(OBJ_LIST kobject_hash.gperf) |
| 923 | set(OUTPUT_SRC_PRE kobject_hash_preprocessed.c) |
| 924 | set(OUTPUT_SRC kobject_hash.c) |
| 925 | set(OUTPUT_OBJ kobject_hash.c.obj) |
| 926 | set(OUTPUT_OBJ_RENAMED kobject_hash_renamed.o) |
| 927 | |
| 928 | # Essentially what we are doing here is extracting some information |
| 929 | # out of the nearly finished elf file, generating the source code |
| 930 | # for a hash table based on that information, and then compiling and |
| 931 | # linking the hash table back into a now even more nearly finished |
Marc Herbert | 4a10eea | 2019-04-16 15:39:45 -0700 | [diff] [blame] | 932 | # elf file. More information in gen_kobject_list.py --help. |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 933 | |
| 934 | # 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] | 935 | # (${ZEPHYR_PREBUILT_EXECUTABLE}) DWARF information to produce a table of kernel |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 936 | # objects (OBJ_LIST) which we will then pass to gperf |
| 937 | add_custom_command( |
| 938 | OUTPUT ${OBJ_LIST} |
| 939 | COMMAND |
| 940 | ${PYTHON_EXECUTABLE} |
| 941 | ${GEN_KOBJ_LIST} |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 942 | --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}> |
Leandro Pereira | c200367 | 2018-04-04 13:50:32 -0700 | [diff] [blame] | 943 | --gperf-output ${OBJ_LIST} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 944 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 945 | DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 946 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 947 | ) |
| 948 | add_custom_target(obj_list DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OBJ_LIST}) |
| 949 | |
| 950 | # Use gperf to generate C code (OUTPUT_SRC_PRE) which implements a |
| 951 | # perfect hashtable based on OBJ_LIST |
| 952 | add_custom_command( |
| 953 | OUTPUT ${OUTPUT_SRC_PRE} |
| 954 | COMMAND |
| 955 | ${GPERF} |
| 956 | --output-file ${OUTPUT_SRC_PRE} |
| 957 | ${OBJ_LIST} |
Sebastian Bøe | f5758b5 | 2018-01-31 10:42:46 +0100 | [diff] [blame] | 958 | DEPENDS obj_list ${OBJ_LIST} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 959 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 960 | ) |
| 961 | add_custom_target(output_src_pre DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC_PRE}) |
| 962 | |
| 963 | # For our purposes the code/data generated by gperf is not optimal. |
| 964 | # |
| 965 | # The script PROCESS_GPERF creates a new c file OUTPUT_SRC based on |
| 966 | # OUTPUT_SRC_PRE to greatly reduce the amount of code/data generated |
| 967 | # since we know we are always working with pointer values |
| 968 | add_custom_command( |
| 969 | OUTPUT ${OUTPUT_SRC} |
| 970 | COMMAND |
Sebastian Bøe | 1b60070 | 2018-06-21 14:34:42 +0200 | [diff] [blame] | 971 | ${PYTHON_EXECUTABLE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 972 | ${PROCESS_GPERF} |
| 973 | -i ${OUTPUT_SRC_PRE} |
| 974 | -o ${OUTPUT_SRC} |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 975 | -p "struct _k_object" |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 976 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Sebastian Bøe | f5758b5 | 2018-01-31 10:42:46 +0100 | [diff] [blame] | 977 | DEPENDS output_src_pre ${OUTPUT_SRC_PRE} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 978 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 979 | ) |
| 980 | add_custom_target(output_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC}) |
| 981 | |
| 982 | # We need precise control of where generated text/data ends up in the final |
| 983 | # kernel image. Disable function/data sections and use objcopy to move |
| 984 | # generated data into special section names |
| 985 | add_library(output_lib STATIC |
| 986 | ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_SRC} |
| 987 | ) |
| 988 | |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 989 | set_source_files_properties(${OUTPUT_SRC} PROPERTIES COMPILE_FLAGS |
Andrew Boie | a514898 | 2019-03-14 17:04:11 -0700 | [diff] [blame] | 990 | "${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections") |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 991 | |
| 992 | set_source_files_properties(${OUTPUT_SRC} |
| 993 | PROPERTIES COMPILE_DEFINITIONS "${compile_definitions_interface}") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 994 | |
| 995 | # Turn off -ffunction-sections, etc. |
| 996 | # NB: Using a library instead of target_compile_options(output_lib |
| 997 | # [...]) because a library's options have precedence |
| 998 | add_library(output_lib_interface INTERFACE) |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 999 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1000 | target_link_libraries(output_lib output_lib_interface) |
| 1001 | |
Kumar Gala | 3713ea4 | 2019-03-14 11:50:08 -0500 | [diff] [blame] | 1002 | foreach(incl ${include_dir_in_interface}) |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 1003 | target_include_directories(output_lib_interface INTERFACE ${incl}) |
| 1004 | endforeach() |
| 1005 | |
Kumar Gala | 3713ea4 | 2019-03-14 11:50:08 -0500 | [diff] [blame] | 1006 | foreach(incl ${sys_include_dir_in_interface}) |
| 1007 | target_include_directories(output_lib_interface SYSTEM INTERFACE ${incl}) |
| 1008 | endforeach() |
Adithya Baglody | 4b3c7b3 | 2018-11-21 14:31:56 +0530 | [diff] [blame] | 1009 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1010 | set(OUTPUT_OBJ_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/output_lib.dir/${OUTPUT_OBJ}) |
| 1011 | |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1012 | set(obj_copy_cmd "") |
| 1013 | set(obj_copy_sections_rename |
| 1014 | .data=.kobject_data.data |
| 1015 | .text=.kobject_data.text |
| 1016 | .rodata=.kobject_data.rodata |
| 1017 | ) |
| 1018 | bintools_objcopy( |
| 1019 | RESULT_CMD_LIST obj_copy_cmd |
| 1020 | SECTION_RENAME ${obj_copy_sections_rename} |
| 1021 | FILE_INPUT ${OUTPUT_OBJ_PATH} |
| 1022 | FILE_OUTPUT ${OUTPUT_OBJ_RENAMED} |
| 1023 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1024 | add_custom_command( |
| 1025 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED} |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1026 | ${obj_copy_cmd} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1027 | DEPENDS output_lib |
| 1028 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 1029 | ) |
| 1030 | add_custom_target(output_obj_renamed DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED}) |
| 1031 | |
| 1032 | add_library(output_obj_renamed_lib STATIC IMPORTED GLOBAL) |
| 1033 | set_property( |
| 1034 | TARGET output_obj_renamed_lib |
| 1035 | PROPERTY |
| 1036 | IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_OBJ_RENAMED} |
| 1037 | ) |
| 1038 | add_dependencies( |
| 1039 | output_obj_renamed_lib |
| 1040 | output_obj_renamed |
| 1041 | ) |
| 1042 | |
| 1043 | set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES output_obj_renamed_lib) |
| 1044 | endif() |
| 1045 | |
| 1046 | # Read global variables into local variables |
| 1047 | get_property(GKOF GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES) |
| 1048 | get_property(GKSF GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES) |
| 1049 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 1050 | |
Alberto Escolar Piedras | c288241 | 2018-07-05 10:51:03 +0200 | [diff] [blame] | 1051 | get_property(CSTD GLOBAL PROPERTY CSTD) |
| 1052 | set_ifndef(CSTD c99) |
| 1053 | |
Danny Oerndrup | 6331dae | 2019-06-13 15:33:03 +0200 | [diff] [blame] | 1054 | # @Intent: Obtain compiler specific flag for specifying the c standard |
| 1055 | toolchain_cc_cstd_flag(CC_CSTD ${CSTD}) |
Alberto Escolar Piedras | c288241 | 2018-07-05 10:51:03 +0200 | [diff] [blame] | 1056 | zephyr_compile_options( |
Danny Oerndrup | 6331dae | 2019-06-13 15:33:03 +0200 | [diff] [blame] | 1057 | $<$<COMPILE_LANGUAGE:C>:${CC_CSTD}> |
Alberto Escolar Piedras | c288241 | 2018-07-05 10:51:03 +0200 | [diff] [blame] | 1058 | ) |
| 1059 | |
Mark Ruvald Pedersen | 197197a | 2019-05-03 11:02:56 +0200 | [diff] [blame] | 1060 | # @Intent: Configure linker scripts, i.e. generate linker scripts with variables substituted |
| 1061 | toolchain_ld_configure_files() |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1062 | |
Andrew Boie | 4ce652e | 2019-02-22 16:08:44 -0800 | [diff] [blame] | 1063 | if(CONFIG_USERSPACE) |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1064 | set(APP_SMEM_ALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_aligned.ld") |
| 1065 | 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] | 1066 | set(OBJ_FILE_DIR "${PROJECT_BINARY_DIR}/../") |
| 1067 | |
| 1068 | add_custom_target( |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1069 | ${APP_SMEM_ALIGNED_DEP} |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 1070 | DEPENDS |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1071 | ${APP_SMEM_ALIGNED_LD} |
| 1072 | ) |
| 1073 | |
| 1074 | add_custom_target( |
| 1075 | ${APP_SMEM_UNALIGNED_DEP} |
| 1076 | DEPENDS |
| 1077 | ${APP_SMEM_UNALIGNED_LD} |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 1078 | ) |
| 1079 | |
Andrew Boie | 4b4f773 | 2019-02-01 12:18:31 -0800 | [diff] [blame] | 1080 | if(CONFIG_NEWLIB_LIBC) |
Andrew Boie | 17ce822 | 2019-02-21 13:44:54 -0800 | [diff] [blame] | 1081 | set(NEWLIB_PART -l libc.a z_libc_partition) |
Andrew Boie | 4b4f773 | 2019-02-01 12:18:31 -0800 | [diff] [blame] | 1082 | endif() |
Ioannis Glaropoulos | d58f8be | 2019-11-15 14:07:51 +0100 | [diff] [blame] | 1083 | if(CONFIG_NEWLIB_LIBC_NANO) |
| 1084 | set(NEWLIB_PART -l libc_nano.a z_libc_partition) |
| 1085 | endif() |
Andrew Boie | e686aef | 2019-02-27 14:41:45 -0800 | [diff] [blame] | 1086 | |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 1087 | add_custom_command( |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1088 | OUTPUT ${APP_SMEM_UNALIGNED_LD} |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 1089 | COMMAND ${PYTHON_EXECUTABLE} |
| 1090 | ${ZEPHYR_BASE}/scripts/gen_app_partitions.py |
| 1091 | -d ${OBJ_FILE_DIR} |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1092 | -o ${APP_SMEM_UNALIGNED_LD} |
Torsten Rasmussen | 5a703c8 | 2019-11-05 10:24:08 +0100 | [diff] [blame] | 1093 | ${NEWLIB_PART} |
Torsten Rasmussen | 1f9723a | 2019-11-04 14:30:24 +0100 | [diff] [blame] | 1094 | $<TARGET_PROPERTY:zephyr_property_target,COMPILE_OPTIONS> |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 1095 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 1096 | DEPENDS |
| 1097 | kernel |
| 1098 | ${ZEPHYR_LIBS_PROPERTY} |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 1099 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ |
Torsten Rasmussen | 1f9723a | 2019-11-04 14:30:24 +0100 | [diff] [blame] | 1100 | COMMAND_EXPAND_LISTS |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1101 | COMMENT "Generating app_smem_unaligned linker section" |
| 1102 | ) |
| 1103 | |
Mark Ruvald Pedersen | 4c81197 | 2019-04-29 17:16:54 +0200 | [diff] [blame] | 1104 | configure_linker_script( |
Mark Ruvald Pedersen | 1073fba | 2019-04-29 20:27:23 +0200 | [diff] [blame] | 1105 | linker_app_smem_unaligned.cmd |
Mark Ruvald Pedersen | fbcea17 | 2019-04-29 20:35:12 +0200 | [diff] [blame] | 1106 | "-DLINKER_APP_SMEM_UNALIGNED" |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1107 | ${CODE_RELOCATION_DEP} |
| 1108 | ${APP_SMEM_UNALIGNED_DEP} |
| 1109 | ${APP_SMEM_UNALIGNED_LD} |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 1110 | zephyr_generated_headers |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1111 | ) |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1112 | |
| 1113 | add_custom_target( |
| 1114 | linker_app_smem_unaligned_script |
| 1115 | DEPENDS |
| 1116 | linker_app_smem_unaligned.cmd |
| 1117 | ) |
| 1118 | |
| 1119 | set_property(TARGET |
| 1120 | linker_app_smem_unaligned_script |
| 1121 | PROPERTY INCLUDE_DIRECTORIES |
| 1122 | ${ZEPHYR_INCLUDE_DIRS} |
| 1123 | ) |
| 1124 | |
| 1125 | set(APP_SMEM_UNALIGNED_LIB app_smem_unaligned_output_obj_renamed_lib) |
| 1126 | add_executable( app_smem_unaligned_prebuilt misc/empty_file.c) |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1127 | toolchain_ld_link_elf( |
| 1128 | TARGET_ELF app_smem_unaligned_prebuilt |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1129 | OUTPUT_MAP ${PROJECT_BINARY_DIR}/app_smem_unaligned_prebuilt.map |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1130 | LIBRARIES_PRE_SCRIPT "" |
| 1131 | LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker_app_smem_unaligned.cmd |
| 1132 | LIBRARIES_POST_SCRIPT "" |
| 1133 | DEPENDENCIES ${CODE_RELOCATION_DEP} |
| 1134 | ) |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1135 | 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] | 1136 | 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] | 1137 | |
| 1138 | add_custom_command( |
| 1139 | OUTPUT ${APP_SMEM_ALIGNED_LD} |
| 1140 | COMMAND ${PYTHON_EXECUTABLE} |
| 1141 | ${ZEPHYR_BASE}/scripts/gen_app_partitions.py |
| 1142 | -e $<TARGET_FILE:app_smem_unaligned_prebuilt> |
| 1143 | -o ${APP_SMEM_ALIGNED_LD} |
Torsten Rasmussen | 5a703c8 | 2019-11-05 10:24:08 +0100 | [diff] [blame] | 1144 | ${NEWLIB_PART} |
Torsten Rasmussen | 1f9723a | 2019-11-04 14:30:24 +0100 | [diff] [blame] | 1145 | $<TARGET_PROPERTY:zephyr_property_target,COMPILE_OPTIONS> |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1146 | $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> |
| 1147 | DEPENDS |
| 1148 | kernel |
| 1149 | ${ZEPHYR_LIBS_PROPERTY} |
| 1150 | app_smem_unaligned_prebuilt |
| 1151 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/ |
Torsten Rasmussen | 1f9723a | 2019-11-04 14:30:24 +0100 | [diff] [blame] | 1152 | COMMAND_EXPAND_LISTS |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1153 | COMMENT "Generating app_smem_aligned linker section" |
Adithya Baglody | 50950eb | 2018-12-20 15:47:42 +0530 | [diff] [blame] | 1154 | ) |
| 1155 | endif() |
| 1156 | |
Andrew Boie | 41f6011 | 2019-01-31 15:53:24 -0800 | [diff] [blame] | 1157 | if(CONFIG_USERSPACE AND CONFIG_ARM) |
Mark Ruvald Pedersen | 4c81197 | 2019-04-29 17:16:54 +0200 | [diff] [blame] | 1158 | configure_linker_script( |
Mark Ruvald Pedersen | 1073fba | 2019-04-29 20:27:23 +0200 | [diff] [blame] | 1159 | linker_priv_stacks.cmd |
Mark Ruvald Pedersen | fbcea17 | 2019-04-29 20:35:12 +0200 | [diff] [blame] | 1160 | "" |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 1161 | ${CODE_RELOCATION_DEP} |
Daniel Leung | 212ec9a | 2019-03-10 14:20:21 -0700 | [diff] [blame] | 1162 | ${APP_SMEM_ALIGNED_DEP} |
| 1163 | ${APP_SMEM_ALIGNED_LD} |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 1164 | zephyr_generated_headers |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 1165 | ) |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1166 | |
| 1167 | add_custom_target( |
| 1168 | linker_priv_stacks_script |
| 1169 | DEPENDS |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1170 | linker_priv_stacks.cmd |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1171 | ) |
| 1172 | |
| 1173 | set_property(TARGET |
| 1174 | linker_priv_stacks_script |
| 1175 | PROPERTY INCLUDE_DIRECTORIES |
| 1176 | ${ZEPHYR_INCLUDE_DIRS} |
| 1177 | ) |
| 1178 | |
| 1179 | set(PRIV_STACK_LIB priv_stacks_output_obj_renamed_lib) |
| 1180 | add_executable( priv_stacks_prebuilt misc/empty_file.c) |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1181 | toolchain_ld_link_elf( |
| 1182 | TARGET_ELF priv_stacks_prebuilt |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1183 | OUTPUT_MAP ${PROJECT_BINARY_DIR}/priv_stacks_prebuilt.map |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1184 | LIBRARIES_PRE_SCRIPT "" |
| 1185 | LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd |
| 1186 | LIBRARIES_POST_SCRIPT "" |
| 1187 | DEPENDENCIES ${CODE_RELOCATION_DEP} |
| 1188 | ) |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1189 | set_property(TARGET priv_stacks_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_priv_stacks.cmd) |
Mark Ruvald Pedersen | 85af280 | 2019-04-29 14:49:33 +0200 | [diff] [blame] | 1190 | add_dependencies( priv_stacks_prebuilt linker_priv_stacks_script ${OFFSETS_LIB}) |
Wayne Ren | 5a0ba2f | 2018-02-12 19:17:04 +0800 | [diff] [blame] | 1191 | endif() |
Chunlin Han | 18560a0 | 2018-02-01 01:19:49 -0600 | [diff] [blame] | 1192 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1193 | # 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] | 1194 | add_executable( ${ZEPHYR_PREBUILT_EXECUTABLE} misc/empty_file.c) |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1195 | toolchain_ld_link_elf( |
| 1196 | TARGET_ELF ${ZEPHYR_PREBUILT_EXECUTABLE} |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1197 | OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_PREBUILT_EXECUTABLE}.map |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1198 | LIBRARIES_PRE_SCRIPT "" |
| 1199 | LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker.cmd |
| 1200 | LIBRARIES_POST_SCRIPT ${PRIV_STACK_LIB} |
| 1201 | DEPENDENCIES ${CODE_RELOCATION_DEP} |
| 1202 | ) |
Sebastian Bøe | 1526070 | 2019-01-14 16:31:02 +0100 | [diff] [blame] | 1203 | set_property(TARGET ${ZEPHYR_PREBUILT_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker.cmd) |
Mark Ruvald Pedersen | 85af280 | 2019-04-29 14:49:33 +0200 | [diff] [blame] | 1204 | add_dependencies( ${ZEPHYR_PREBUILT_EXECUTABLE} ${PRIV_STACK_DEP} ${LINKER_SCRIPT_TARGET} ${OFFSETS_LIB}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1205 | |
Alberto Escolar Piedras | 76f76441 | 2017-10-03 16:31:55 +0200 | [diff] [blame] | 1206 | |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1207 | set(generated_kernel_files ${GKSF} ${GKOF}) |
| 1208 | if(NOT generated_kernel_files) |
| 1209 | # Use the prebuilt elf as the final elf since we don't have a |
| 1210 | # generation stage. |
| 1211 | set(logical_target_for_zephyr_elf ${ZEPHYR_PREBUILT_EXECUTABLE}) |
| 1212 | else() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1213 | # 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] | 1214 | # first pass (LINKER_SCRIPT), but this time with a different output |
| 1215 | # file and preprocessed with the define LINKER_PASS2. |
Mark Ruvald Pedersen | 4c81197 | 2019-04-29 17:16:54 +0200 | [diff] [blame] | 1216 | configure_linker_script( |
Mark Ruvald Pedersen | 1073fba | 2019-04-29 20:27:23 +0200 | [diff] [blame] | 1217 | linker_pass_final.cmd |
Mark Ruvald Pedersen | fbcea17 | 2019-04-29 20:35:12 +0200 | [diff] [blame] | 1218 | "-DLINKER_PASS2" |
Sebastian Bøe | 2a96312 | 2019-02-08 15:49:57 +0100 | [diff] [blame] | 1219 | ${PRIV_STACK_DEP} |
| 1220 | ${CODE_RELOCATION_DEP} |
| 1221 | ${ZEPHYR_PREBUILT_EXECUTABLE} |
Sebastian Bøe | fdac7b3 | 2020-01-23 15:39:17 +0100 | [diff] [blame] | 1222 | zephyr_generated_headers |
Sebastian Bøe | 7a6afcd | 2019-02-08 15:39:37 +0100 | [diff] [blame] | 1223 | ) |
Andy Gross | e8860fe | 2018-02-01 01:12:32 -0600 | [diff] [blame] | 1224 | |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 1225 | set(LINKER_PASS_FINAL_SCRIPT_TARGET linker_pass_final_script_target) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1226 | add_custom_target( |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 1227 | ${LINKER_PASS_FINAL_SCRIPT_TARGET} |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1228 | DEPENDS |
Andy Gross | 1f0ff06 | 2018-01-25 11:07:03 -0600 | [diff] [blame] | 1229 | linker_pass_final.cmd |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1230 | ) |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 1231 | set_property(TARGET |
Sebastian Bøe | 1b86fb9 | 2019-01-14 16:39:33 +0100 | [diff] [blame] | 1232 | ${LINKER_PASS_FINAL_SCRIPT_TARGET} |
Sebastian Bøe | b1ab501 | 2017-12-14 13:03:23 +0100 | [diff] [blame] | 1233 | PROPERTY INCLUDE_DIRECTORIES |
| 1234 | ${ZEPHYR_INCLUDE_DIRS} |
| 1235 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1236 | |
Mark Ruvald Pedersen | 37d4947 | 2019-05-07 15:20:20 +0200 | [diff] [blame] | 1237 | add_executable( ${ZEPHYR_FINAL_EXECUTABLE} misc/empty_file.c ${GKSF}) |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1238 | toolchain_ld_link_elf( |
| 1239 | TARGET_ELF ${ZEPHYR_FINAL_EXECUTABLE} |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1240 | OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_FINAL_EXECUTABLE}.map |
Mark Ruvald Pedersen | 4052bac | 2019-05-07 16:32:36 +0200 | [diff] [blame] | 1241 | LIBRARIES_PRE_SCRIPT ${GKOF} |
| 1242 | LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker_pass_final.cmd |
| 1243 | LIBRARIES_POST_SCRIPT "" |
| 1244 | DEPENDENCIES ${CODE_RELOCATION_DEP} |
| 1245 | ) |
Mark Ruvald Pedersen | 37d4947 | 2019-05-07 15:20:20 +0200 | [diff] [blame] | 1246 | set_property(TARGET ${ZEPHYR_FINAL_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_pass_final.cmd) |
| 1247 | add_dependencies( ${ZEPHYR_FINAL_EXECUTABLE} ${PRIV_STACK_DEP} ${LINKER_PASS_FINAL_SCRIPT_TARGET}) |
| 1248 | |
| 1249 | # Use the pass2 elf as the final elf |
| 1250 | set(logical_target_for_zephyr_elf ${ZEPHYR_FINAL_EXECUTABLE}) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1251 | endif() |
| 1252 | |
Sebastian Bøe | 0fc3934 | 2018-10-16 13:25:04 +0200 | [diff] [blame] | 1253 | # Export the variable to the application's scope to allow the |
| 1254 | # application to know what the name of the final elf target is. |
| 1255 | set(logical_target_for_zephyr_elf ${logical_target_for_zephyr_elf} PARENT_SCOPE) |
| 1256 | |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1257 | # 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] | 1258 | # 1. it doesn't depend on the number of passes above and the |
| 1259 | # post_build_commands below can always find it no matter which is it; |
| 1260 | # 2. it can be defined in Kconfig |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1261 | set_target_properties(${logical_target_for_zephyr_elf} PROPERTIES OUTPUT_NAME ${KERNEL_NAME}) |
| 1262 | |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1263 | set(post_build_commands "") |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1264 | set(post_build_byproducts "") |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1265 | |
Marc Herbert | 0370c9b | 2019-06-13 16:15:44 -0700 | [diff] [blame] | 1266 | list(APPEND |
| 1267 | post_build_commands |
| 1268 | COMMAND |
| 1269 | cmake -E rename ${logical_target_for_zephyr_elf}.map ${KERNEL_MAP_NAME} |
| 1270 | ) |
| 1271 | |
Håkon Øye Amundsen | c086b93 | 2018-11-26 09:47:16 +0000 | [diff] [blame] | 1272 | if(NOT CONFIG_BUILD_NO_GAP_FILL) |
| 1273 | # Use ';' as separator to get proper space in resulting command. |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1274 | set(GAP_FILL "0xff") |
Håkon Øye Amundsen | c086b93 | 2018-11-26 09:47:16 +0000 | [diff] [blame] | 1275 | endif() |
| 1276 | |
Danny Oerndrup | c41e712 | 2019-07-18 15:16:39 +0200 | [diff] [blame] | 1277 | if(CONFIG_OUTPUT_PRINT_MEMORY_USAGE) |
| 1278 | # @Intent: Use the toolchain bintools method for printing memory usage |
| 1279 | set(memUsageCmd "") |
| 1280 | set(memUsageByProd "") |
| 1281 | bintools_print_mem_usage( |
| 1282 | RESULT_CMD_LIST memUsageCmd |
| 1283 | RESULT_BYPROD_LIST memUsageByProd |
| 1284 | ) |
| 1285 | list(APPEND |
| 1286 | post_build_commands |
| 1287 | ${memUsageCmd} |
| 1288 | ) |
| 1289 | list(APPEND |
| 1290 | post_build_byproducts |
| 1291 | ${memUsageByProd} |
| 1292 | ) |
| 1293 | endif() |
| 1294 | |
Kumar Gala | d541913 | 2019-08-13 13:44:20 -0500 | [diff] [blame] | 1295 | if(CONFIG_BUILD_OUTPUT_HEX OR BOARD_FLASH_RUNNER STREQUAL openocd) |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1296 | set(out_hex_cmd "") |
| 1297 | set(out_hex_byprod "") |
| 1298 | set(out_hex_sections_remove |
| 1299 | .comment |
| 1300 | COMMON |
| 1301 | .eh_frame |
| 1302 | ) |
| 1303 | bintools_objcopy( |
| 1304 | RESULT_CMD_LIST out_hex_cmd |
| 1305 | RESULT_BYPROD_LIST out_hex_byprod |
| 1306 | STRIP_ALL |
| 1307 | GAP_FILL ${GAP_FILL} |
| 1308 | TARGET_OUTPUT "ihex" |
| 1309 | SECTION_REMOVE ${out_hex_sections_remove} |
| 1310 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1311 | FILE_OUTPUT ${KERNEL_HEX_NAME} |
| 1312 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1313 | list(APPEND |
| 1314 | post_build_commands |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1315 | ${out_hex_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1316 | ) |
| 1317 | list(APPEND |
| 1318 | post_build_byproducts |
| 1319 | ${KERNEL_HEX_NAME} |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1320 | ${out_hex_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1321 | ) |
| 1322 | endif() |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1323 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1324 | if(CONFIG_BUILD_OUTPUT_BIN) |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1325 | set(out_bin_cmd "") |
| 1326 | set(out_bin_byprod "") |
| 1327 | set(out_bin_sections_remove |
| 1328 | .comment |
| 1329 | COMMON |
| 1330 | .eh_frame |
| 1331 | ) |
| 1332 | bintools_objcopy( |
| 1333 | RESULT_CMD_LIST out_bin_cmd |
| 1334 | RESULT_BYPROD_LIST out_bin_byprod |
| 1335 | STRIP_ALL |
| 1336 | GAP_FILL ${GAP_FILL} |
| 1337 | TARGET_OUTPUT "binary" |
| 1338 | SECTION_REMOVE ${out_bin_sections_remove} |
| 1339 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1340 | FILE_OUTPUT ${KERNEL_BIN_NAME} |
| 1341 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1342 | list(APPEND |
| 1343 | post_build_commands |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1344 | ${out_bin_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1345 | ) |
| 1346 | list(APPEND |
| 1347 | post_build_byproducts |
| 1348 | ${KERNEL_BIN_NAME} |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1349 | ${out_bin_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1350 | ) |
| 1351 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1352 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1353 | if(CONFIG_BUILD_OUTPUT_S19) |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1354 | set(out_S19_cmd "") |
| 1355 | set(out_S19_byprod "") |
| 1356 | bintools_objcopy( |
| 1357 | RESULT_CMD_LIST out_S19_cmd |
| 1358 | RESULT_BYPROD_LIST out_S19_byprod |
| 1359 | GAP_FILL ${GAP_FILL} |
| 1360 | TARGET_OUTPUT "srec" |
| 1361 | SREC_LEN 1 |
| 1362 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1363 | FILE_OUTPUT ${KERNEL_S19_NAME} |
| 1364 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1365 | list(APPEND |
| 1366 | post_build_commands |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1367 | ${out_S19_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1368 | ) |
| 1369 | list(APPEND |
| 1370 | post_build_byproducts |
| 1371 | ${KERNEL_S19_NAME} |
Danny Oerndrup | 51634cd | 2019-08-01 07:56:45 +0200 | [diff] [blame] | 1372 | ${out_S19_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1373 | ) |
| 1374 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1375 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1376 | if(CONFIG_OUTPUT_DISASSEMBLY) |
Danny Oerndrup | 0760a53 | 2019-08-01 08:01:39 +0200 | [diff] [blame] | 1377 | set(out_disassembly_cmd "") |
| 1378 | set(out_disassembly_byprod "") |
| 1379 | bintools_objdump( |
| 1380 | RESULT_CMD_LIST out_disassembly_cmd |
| 1381 | RESULT_BYPROD_LIST out_disassembly_byprod |
| 1382 | DISASSEMBLE_SOURCE |
| 1383 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1384 | FILE_OUTPUT ${KERNEL_LST_NAME} |
| 1385 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1386 | list(APPEND |
| 1387 | post_build_commands |
Danny Oerndrup | 0760a53 | 2019-08-01 08:01:39 +0200 | [diff] [blame] | 1388 | ${out_disassembly_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1389 | ) |
| 1390 | list(APPEND |
| 1391 | post_build_byproducts |
| 1392 | ${KERNEL_LST_NAME} |
Danny Oerndrup | 0760a53 | 2019-08-01 08:01:39 +0200 | [diff] [blame] | 1393 | ${out_disassembly_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1394 | ) |
| 1395 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1396 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1397 | if(CONFIG_OUTPUT_STAT) |
Danny Oerndrup | 919df01 | 2019-08-01 08:04:12 +0200 | [diff] [blame] | 1398 | set(out_stat_cmd "") |
| 1399 | set(out_stat_byprod "") |
| 1400 | bintools_readelf( |
| 1401 | RESULT_CMD_LIST out_stat_cmd |
| 1402 | RESULT_BYPROD_LIST out_stat_byprod |
| 1403 | HEADERS |
| 1404 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1405 | FILE_OUTPUT ${KERNEL_STAT_NAME} |
| 1406 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1407 | list(APPEND |
| 1408 | post_build_commands |
Danny Oerndrup | 919df01 | 2019-08-01 08:04:12 +0200 | [diff] [blame] | 1409 | ${out_stat_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1410 | ) |
| 1411 | list(APPEND |
| 1412 | post_build_byproducts |
| 1413 | ${KERNEL_STAT_NAME} |
Danny Oerndrup | 919df01 | 2019-08-01 08:04:12 +0200 | [diff] [blame] | 1414 | ${out_stat_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1415 | ) |
| 1416 | endif() |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1417 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1418 | if(CONFIG_BUILD_OUTPUT_STRIPPED) |
Danny Oerndrup | 9336e3e | 2019-08-01 08:06:54 +0200 | [diff] [blame] | 1419 | set(out_stripped_cmd "") |
| 1420 | set(out_stripped_byprod "") |
| 1421 | bintools_strip( |
| 1422 | RESULT_CMD_LIST out_stripped_cmd |
| 1423 | RESULT_BYPROD_LIST out_stripped_byprod |
| 1424 | STRIP_ALL |
| 1425 | FILE_INPUT ${KERNEL_ELF_NAME} |
| 1426 | FILE_OUTPUT ${KERNEL_STRIP_NAME} |
| 1427 | ) |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1428 | list(APPEND |
| 1429 | post_build_commands |
Danny Oerndrup | 9336e3e | 2019-08-01 08:06:54 +0200 | [diff] [blame] | 1430 | ${out_stripped_cmd} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1431 | ) |
| 1432 | list(APPEND |
| 1433 | post_build_byproducts |
| 1434 | ${KERNEL_STRIP_NAME} |
Danny Oerndrup | 9336e3e | 2019-08-01 08:06:54 +0200 | [diff] [blame] | 1435 | ${out_stripped_byprod} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1436 | ) |
| 1437 | endif() |
| 1438 | |
| 1439 | if(CONFIG_BUILD_OUTPUT_EXE) |
| 1440 | list(APPEND |
| 1441 | post_build_commands |
| 1442 | COMMAND |
| 1443 | ${CMAKE_COMMAND} -E copy ${KERNEL_ELF_NAME} ${KERNEL_EXE_NAME} |
| 1444 | ) |
| 1445 | list(APPEND |
| 1446 | post_build_byproducts |
| 1447 | ${KERNEL_EXE_NAME} |
| 1448 | ) |
| 1449 | endif() |
Anas Nashif | 4592ff2 | 2017-11-23 07:54:26 -0500 | [diff] [blame] | 1450 | |
Rajavardhan Gundi | ecdea1c | 2019-01-25 11:53:13 +0530 | [diff] [blame] | 1451 | get_property(extra_post_build_commands |
| 1452 | GLOBAL PROPERTY |
| 1453 | extra_post_build_commands |
| 1454 | ) |
| 1455 | |
| 1456 | list(APPEND |
| 1457 | post_build_commands |
| 1458 | ${extra_post_build_commands} |
| 1459 | ) |
| 1460 | |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1461 | get_property(extra_post_build_byproducts |
| 1462 | GLOBAL PROPERTY |
| 1463 | extra_post_build_byproducts |
| 1464 | ) |
| 1465 | |
| 1466 | list(APPEND |
| 1467 | post_build_byproducts |
| 1468 | ${extra_post_build_byproducts} |
| 1469 | ) |
| 1470 | |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1471 | # Add post_build_commands to post-process the final .elf file produced by |
| 1472 | # either the ZEPHYR_PREBUILT_EXECUTABLE or the KERNEL_ELF executable |
| 1473 | # targets above. |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1474 | add_custom_command( |
| 1475 | TARGET ${logical_target_for_zephyr_elf} |
| 1476 | POST_BUILD |
Sebastian Bøe | e51ce4d | 2017-11-20 15:37:59 +0100 | [diff] [blame] | 1477 | ${post_build_commands} |
Sebastian Bøe | f483e5b | 2019-05-10 10:06:32 +0200 | [diff] [blame] | 1478 | BYPRODUCTS |
| 1479 | ${post_build_byproducts} |
Marc Herbert | 498b494 | 2019-04-16 23:30:52 -0700 | [diff] [blame] | 1480 | COMMENT "Generating files from ${KERNEL_ELF_NAME} for board: ${BOARD}" |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1481 | # NB: COMMENT only works for some CMake-Generators |
Rajavardhan Gundi | ecdea1c | 2019-01-25 11:53:13 +0530 | [diff] [blame] | 1482 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1483 | |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1484 | # To populate with hex files to merge, do the following: |
| 1485 | # set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE ${my_local_list}) |
| 1486 | # Note that the zephyr.hex file will not be included automatically. |
| 1487 | get_property(HEX_FILES_TO_MERGE GLOBAL PROPERTY HEX_FILES_TO_MERGE) |
| 1488 | if(HEX_FILES_TO_MERGE) |
| 1489 | # Merge in out-of-tree hex files. |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1490 | set(MERGED_HEX_NAME merged.hex) |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1491 | |
| 1492 | add_custom_command( |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1493 | OUTPUT ${MERGED_HEX_NAME} |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1494 | COMMAND |
| 1495 | ${PYTHON_EXECUTABLE} |
| 1496 | ${ZEPHYR_BASE}/scripts/mergehex.py |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1497 | -o ${MERGED_HEX_NAME} |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1498 | ${HEX_FILES_TO_MERGE} |
| 1499 | DEPENDS ${HEX_FILES_TO_MERGE} ${logical_target_for_zephyr_elf} |
| 1500 | ) |
| 1501 | |
Håkon Øye Amundsen | 2a5a02e | 2018-12-05 08:32:32 +0000 | [diff] [blame] | 1502 | add_custom_target(mergehex ALL DEPENDS ${MERGED_HEX_NAME}) |
Håkon Øye Amundsen | 0da5d24 | 2018-12-05 09:15:40 +0000 | [diff] [blame] | 1503 | list(APPEND FLASH_DEPS mergehex) |
Håkon Øye Amundsen | c9a2a5e | 2020-01-03 08:25:03 +0000 | [diff] [blame] | 1504 | |
| 1505 | message(VERBOSE "Merging hex files: ${HEX_FILES_TO_MERGE}") |
Håkon Øye Amundsen | 81c6662 | 2018-10-30 07:39:13 +0000 | [diff] [blame] | 1506 | endif() |
| 1507 | |
Anas Nashif | c15d3c9 | 2017-11-21 18:54:55 -0500 | [diff] [blame] | 1508 | if(EMU_PLATFORM) |
Carles Cufi | 7d764b3 | 2018-01-11 15:46:44 +0100 | [diff] [blame] | 1509 | include(${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake) |
Anas Nashif | fd276ae | 2017-12-21 16:45:45 -0500 | [diff] [blame] | 1510 | else() |
| 1511 | add_custom_target(run |
| 1512 | COMMAND |
| 1513 | ${CMAKE_COMMAND} -E echo |
| 1514 | "===================================================" |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 1515 | "Emulation/Simulation not supported with this board." |
Anas Nashif | fd276ae | 2017-12-21 16:45:45 -0500 | [diff] [blame] | 1516 | "===================================================" |
| 1517 | ) |
Anas Nashif | c15d3c9 | 2017-11-21 18:54:55 -0500 | [diff] [blame] | 1518 | endif() |
| 1519 | |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1520 | add_subdirectory(cmake/flash) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1521 | add_subdirectory(cmake/usage) |
| 1522 | add_subdirectory(cmake/reports) |
| 1523 | |
Sebastian Bøe | d3a8fd4 | 2019-10-17 14:25:34 +0200 | [diff] [blame] | 1524 | add_subdirectory_ifdef( |
| 1525 | CONFIG_MAKEFILE_EXPORTS |
| 1526 | cmake/makefile_exports |
| 1527 | ) |
| 1528 | |
Marc Herbert | 8372310 | 2019-06-17 13:26:11 -0700 | [diff] [blame] | 1529 | if(NOT CONFIG_TEST) |
Andrew Boie | 411686f | 2018-05-24 13:18:36 -0700 | [diff] [blame] | 1530 | if(CONFIG_ASSERT AND (NOT CONFIG_FORCE_NO_ASSERT)) |
Sebastian Bøe | fa8f9d4 | 2019-12-06 12:54:53 +0100 | [diff] [blame] | 1531 | message(WARNING "__ASSERT() statements are globally ENABLED") |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1532 | endif() |
Marc Herbert | 8372310 | 2019-06-17 13:26:11 -0700 | [diff] [blame] | 1533 | endif() |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1534 | |
Vincent Wan | a2bc514 | 2020-01-09 14:20:44 -0800 | [diff] [blame] | 1535 | if(CONFIG_BOARD_DEPRECATED_RELEASE) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1536 | message(WARNING " |
| 1537 | WARNING: The board '${BOARD}' is deprecated and will be |
Vincent Wan | a2bc514 | 2020-01-09 14:20:44 -0800 | [diff] [blame] | 1538 | removed in version ${CONFIG_BOARD_DEPRECATED_RELEASE}" |
Mark Ruvald Pedersen | 0efad5f | 2018-12-19 10:40:57 +0100 | [diff] [blame] | 1539 | ) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 1540 | endif() |
Paul Sokolovsky | 1c6a7d7 | 2019-06-06 21:12:14 +0300 | [diff] [blame] | 1541 | |
Vincent Wan | 180b4df | 2020-01-08 17:10:51 -0800 | [diff] [blame] | 1542 | if(CONFIG_SOC_DEPRECATED_RELEASE) |
| 1543 | message(WARNING " |
| 1544 | WARNING: The SoC '${SOC_NAME}' is deprecated and will be |
| 1545 | removed in version ${CONFIG_SOC_DEPRECATED_RELEASE}" |
| 1546 | ) |
| 1547 | endif() |
| 1548 | |
Sebastian Bøe | e50e12d | 2019-08-29 16:19:32 +0200 | [diff] [blame] | 1549 | # In CMake projects, 'CMAKE_BUILD_TYPE' usually determines the |
| 1550 | # optimization flag, but in Zephyr it is determined through |
| 1551 | # Kconfig. Here we give a warning when there is a mismatch between the |
| 1552 | # two in case the user is not aware of this. |
| 1553 | set(build_types None Debug Release RelWithDebInfo MinSizeRel) |
| 1554 | |
| 1555 | if((CMAKE_BUILD_TYPE IN_LIST build_types) AND (NOT NO_BUILD_TYPE_WARNING)) |
| 1556 | string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_uppercase) |
| 1557 | |
Jack Dähn | e41bdcd | 2019-11-15 19:01:39 +0100 | [diff] [blame] | 1558 | 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] | 1559 | message(WARNING " |
| 1560 | The CMake build type was set to '${CMAKE_BUILD_TYPE}', but the optimization flag was set to '${OPTIMIZATION_FLAG}'. |
| 1561 | This may be intentional and the warning can be turned off by setting the CMake variable 'NO_BUILD_TYPE_WARNING'" |
| 1562 | ) |
| 1563 | endif() |
| 1564 | endif() |
| 1565 | |
Paul Sokolovsky | 1c6a7d7 | 2019-06-06 21:12:14 +0300 | [diff] [blame] | 1566 | # @Intent: Set compiler specific flags for standard C includes |
| 1567 | # Done at the very end, so any other system includes which may |
| 1568 | # be added by Zephyr components were first in list. |
| 1569 | toolchain_cc_nostdinc() |