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