David Hu | c28b9b2 | 2023-10-14 15:33:16 +0800 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2023, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | cmake_minimum_required(VERSION 3.15) |
| 8 | |
| 9 | SET(CMAKE_SYSTEM_NAME Generic) |
| 10 | |
| 11 | set(CMAKE_C_COMPILER_FORCED TRUE) |
| 12 | set(CMAKE_CXX_COMPILER_FORCED TRUE) |
| 13 | |
| 14 | if(NOT DEFINED CROSS_COMPILE) |
| 15 | set(CROSS_COMPILE arm-none-eabi CACHE STRING "Cross-compiler prefix") |
| 16 | endif() |
| 17 | |
| 18 | set(CMAKE_C_COMPILER armclang) |
| 19 | set(CMAKE_CXX_COMPILER armclang) |
| 20 | set(CMAKE_ASM_COMPILER armasm) |
| 21 | |
| 22 | # This variable name is a bit of a misnomer. The file it is set to is included |
| 23 | # at a particular step in the compiler initialisation. It is used here to |
| 24 | # configure the extensions for object files. Despite the name, it also works |
| 25 | # with the Ninja generator. |
| 26 | #set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_LIST_DIR}/cmake/set_extensions.cmake) |
| 27 | |
| 28 | if(NOT DEFINED CMAKE_OBJCOPY) |
| 29 | set(CMAKE_OBJCOPY ${CROSS_COMPILE}-objcopy CACHE FILEPATH "Path to objcopy") |
| 30 | endif() |
| 31 | |
| 32 | # Set compiler ID explicitly as it's not detected at this moment |
| 33 | set(CMAKE_C_COMPILER_ID ARMClang) |
| 34 | |
| 35 | macro(tfm_toolchain_reset_compiler_flags) |
| 36 | set_property(DIRECTORY PROPERTY COMPILE_OPTIONS "") |
| 37 | |
| 38 | add_compile_options( |
| 39 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wno-ignored-optimization-argument> |
| 40 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wno-unused-command-line-argument> |
| 41 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wall> |
| 42 | # Don't error when the MBEDTLS_NULL_ENTROPY warning is shown |
| 43 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wno-error=cpp> |
| 44 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-c> |
| 45 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fdata-sections> |
| 46 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-ffunction-sections> |
| 47 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fno-builtin> |
| 48 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fshort-enums> |
| 49 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fshort-wchar> |
| 50 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-funsigned-char> |
| 51 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-masm=auto> |
| 52 | $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-nostdlib> |
| 53 | $<$<COMPILE_LANGUAGE:C>:-std=c99> |
| 54 | $<$<COMPILE_LANGUAGE:CXX>:-std=c++11> |
| 55 | $<$<COMPILE_LANGUAGE:ASM>:--cpu=${CMAKE_ASM_CPU_FLAG}> |
| 56 | $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${TFM_DEBUG_SYMBOLS}>>:-g> |
| 57 | $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<BOOL:${TFM_DEBUG_SYMBOLS}>>:-g> |
| 58 | ) |
| 59 | endmacro() |
| 60 | |
| 61 | macro(tfm_toolchain_reset_linker_flags) |
| 62 | set_property(DIRECTORY PROPERTY LINK_OPTIONS "") |
| 63 | |
| 64 | add_link_options( |
| 65 | --strict |
| 66 | --symbols |
| 67 | --xref |
| 68 | $<$<AND:$<VERSION_GREATER:${TFM_ISOLATION_LEVEL},1>,$<STREQUAL:"${TEST_PSA_API}","IPC">>:--no-merge> |
| 69 | # Suppress link warnings that are consistant (and therefore hopefully |
| 70 | # harmless) |
| 71 | # https://developer.arm.com/documentation/100074/0608/linker-errors-and-warnings/list-of-the-armlink-error-and-warning-messages |
| 72 | # Empty region description |
| 73 | --diag_suppress=6312 |
| 74 | # Ns section matches pattern |
| 75 | --diag_suppress=6314 |
| 76 | # Duplicate input files |
| 77 | --diag_suppress=6304 |
| 78 | # Pattern only matches removed unused sections. |
| 79 | --diag_suppress=6329 |
| 80 | ) |
| 81 | endmacro() |
| 82 | |
| 83 | macro(tfm_toolchain_set_processor_arch) |
| 84 | if (DEFINED TFM_SYSTEM_PROCESSOR) |
| 85 | set(CMAKE_SYSTEM_PROCESSOR ${TFM_SYSTEM_PROCESSOR}) |
| 86 | |
| 87 | if (TFM_SYSTEM_ARCHITECTURE STREQUAL "armv8.1-m.main") |
| 88 | message(WARNING "MVE is not yet supported using ARMCLANG") |
| 89 | string(APPEND CMAKE_SYSTEM_PROCESSOR "+nomve") |
| 90 | endif() |
| 91 | |
| 92 | if (DEFINED TFM_SYSTEM_DSP) |
| 93 | if(NOT TFM_SYSTEM_DSP) |
| 94 | string(APPEND CMAKE_SYSTEM_PROCESSOR "+nodsp") |
| 95 | endif() |
| 96 | endif() |
| 97 | |
| 98 | # ARMCLANG specifies that '+nofp' is available on following M-profile cpus: |
| 99 | # 'cortex-m4', 'cortex-m7', 'cortex-m33', 'cortex-m35p', 'cortex-m55' and 'cortex-m85'. |
| 100 | # Build fails if other M-profile cpu, such as 'cortex-m23', is added with '+nofp'. |
| 101 | # Explicitly list those cpu to align with ARMCLANG description. |
| 102 | if (NOT CONFIG_TFM_FLOAT_ABI STREQUAL "hard" AND |
| 103 | (TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m4" |
| 104 | OR TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m7" |
| 105 | OR TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m33" |
| 106 | OR TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m35p" |
| 107 | OR TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m55" |
| 108 | OR TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m85")) |
| 109 | string(APPEND CMAKE_SYSTEM_PROCESSOR "+nofp") |
| 110 | endif() |
| 111 | |
| 112 | string(REGEX REPLACE "\\+nodsp" ".no_dsp" CMAKE_ASM_CPU_FLAG "${CMAKE_SYSTEM_PROCESSOR}") |
| 113 | string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}") |
| 114 | string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}") |
| 115 | else() |
| 116 | set(CMAKE_ASM_CPU_FLAG ${TFM_SYSTEM_ARCHITECTURE}) |
| 117 | |
| 118 | # Armasm uses different syntax than armclang for architecture targets |
| 119 | string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}") |
| 120 | string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}") |
| 121 | |
| 122 | # Modifiers are additive instead of subtractive (.fp Vs .no_fp) |
| 123 | if (TFM_SYSTEM_DSP) |
| 124 | string(APPEND CMAKE_ASM_CPU_FLAG ".dsp") |
| 125 | endif() |
| 126 | |
| 127 | if (CONFIG_TFM_FLOAT_ABI STREQUAL "hard") |
| 128 | string(APPEND CMAKE_ASM_CPU_FLAG ".fp") |
| 129 | endif() |
| 130 | endif() |
| 131 | |
| 132 | # CMAKE_SYSTEM_ARCH is an ARMCLANG CMAKE internal variable, used to set |
| 133 | # compile and linker flags up until CMake 3.21 where CMP0123 was introduced: |
| 134 | # https://cmake.org/cmake/help/latest/policy/CMP0123.html |
| 135 | # This behavior is overwritten by setting CMAKE_C_FLAGS in |
| 136 | # tfm_toolchain_reload_compiler. |
| 137 | # Another use of this variable is to statisfy a requirement for ARMCLANG to |
| 138 | # set either the target CPU or the Architecture. This variable needs to be |
| 139 | # set to allow targeting architectures without a specific CPU. |
| 140 | set(CMAKE_SYSTEM_ARCH ${TFM_SYSTEM_ARCHITECTURE}) |
| 141 | |
| 142 | set(CMAKE_C_COMPILER_TARGET arm-${CROSS_COMPILE}) |
| 143 | set(CMAKE_CXX_COMPILER_TARGET arm-${CROSS_COMPILE}) |
| 144 | set(CMAKE_ASM_COMPILER_TARGET arm-${CROSS_COMPILE}) |
| 145 | |
| 146 | # MVE is currently not supported in case of armclang |
| 147 | if (TFM_SYSTEM_ARCHITECTURE STREQUAL "armv8.1-m.main") |
| 148 | string(APPEND CMAKE_SYSTEM_ARCH "+nomve") |
| 149 | endif() |
| 150 | |
| 151 | if (DEFINED TFM_SYSTEM_DSP) |
| 152 | if(NOT TFM_SYSTEM_DSP) |
| 153 | string(APPEND CMAKE_SYSTEM_ARCH "+nodsp") |
| 154 | endif() |
| 155 | endif() |
| 156 | |
| 157 | # Cmake's ARMClang support has several issues with compiler validation. To |
| 158 | # avoid these, we set the list of supported -mcpu and -march variables to |
| 159 | # the ones we intend to use so that the validation will never fail. |
| 160 | include(Compiler/ARMClang) |
| 161 | set(CMAKE_C_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR}) |
| 162 | set(CMAKE_C_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH}) |
| 163 | set(CMAKE_CXX_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR}) |
| 164 | set(CMAKE_CXX_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH}) |
| 165 | set(CMAKE_ASM_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR}) |
| 166 | set(CMAKE_ASM_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH}) |
| 167 | endmacro() |
| 168 | |
| 169 | macro(tfm_toolchain_reload_compiler) |
| 170 | tfm_toolchain_set_processor_arch() |
| 171 | tfm_toolchain_reset_compiler_flags() |
| 172 | tfm_toolchain_reset_linker_flags() |
| 173 | |
| 174 | unset(CMAKE_C_FLAGS_INIT) |
| 175 | unset(CMAKE_CXX_FLAGS_INIT) |
| 176 | unset(CMAKE_C_LINK_FLAGS) |
| 177 | unset(CMAKE_ASM_FLAGS_INIT) |
| 178 | unset(CMAKE_ASM_LINK_FLAGS) |
| 179 | unset(__mcpu_flag_set) |
| 180 | unset(__march_flag_set) |
| 181 | |
| 182 | include(Compiler/ARMClang) |
| 183 | __compiler_armclang(C) |
| 184 | include(Compiler/ARMCC-ASM) |
| 185 | __compiler_armcc(ASM) |
| 186 | |
| 187 | if (CMAKE_C_COMPILER_VERSION VERSION_LESS 6.13) |
| 188 | message(FATAL_ERROR "Please select newer Arm compiler version starting from 6.13.") |
| 189 | endif() |
| 190 | |
| 191 | if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.15 AND |
| 192 | CMAKE_C_COMPILER_VERSION VERSION_LESS 6.18) |
| 193 | message(FATAL_ERROR "Armclang 6.15~6.17 may cause MemManage fault." |
| 194 | " This defect has been fixed since Armclang 6.18." |
| 195 | " See [SDCOMP-59788] in Armclang 6.18 release note for details." |
| 196 | " Please use other Armclang versions instead.") |
| 197 | endif() |
| 198 | |
| 199 | set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT}) |
| 200 | |
| 201 | if (DEFINED TFM_SYSTEM_PROCESSOR) |
| 202 | set(CMAKE_C_FLAGS "-mcpu=${CMAKE_SYSTEM_PROCESSOR}") |
| 203 | set(CMAKE_C_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}") |
| 204 | set(CMAKE_CXX_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}") |
| 205 | set(CMAKE_ASM_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}") |
| 206 | # But armlink doesn't support this +dsp syntax |
| 207 | string(REGEX REPLACE "\\+nodsp" "" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}") |
| 208 | string(REGEX REPLACE "\\+nodsp" "" CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}") |
| 209 | string(REGEX REPLACE "\\+nodsp" "" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}") |
| 210 | # And uses different syntax for +nofp |
| 211 | string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}") |
| 212 | string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}") |
| 213 | string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}") |
| 214 | |
| 215 | string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}") |
| 216 | string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}") |
| 217 | string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}") |
| 218 | else() |
| 219 | set(CMAKE_C_FLAGS "-march=${CMAKE_SYSTEM_ARCH}") |
| 220 | set(CMAKE_CXX_FLAGS "-march=${CMAKE_SYSTEM_ARCH}") |
| 221 | endif() |
| 222 | |
Jianliang Shen | bd624ed | 2023-10-24 15:42:59 +0800 | [diff] [blame] | 223 | # This flag is used to check if toolchain has fixed VLLDM vulnerability |
| 224 | # Check command will fail if C flags consist of keyword other than cpu/arch type. |
| 225 | set(CP_CHECK_C_FLAGS ${CMAKE_C_FLAGS}) |
David Hu | c28b9b2 | 2023-10-14 15:33:16 +0800 | [diff] [blame] | 226 | |
| 227 | if (CONFIG_TFM_FLOAT_ABI STREQUAL "hard") |
Jianliang Shen | bd624ed | 2023-10-24 15:42:59 +0800 | [diff] [blame] | 228 | set(COMPILER_CP_C_FLAG "-mfloat-abi=hard") |
David Hu | c28b9b2 | 2023-10-14 15:33:16 +0800 | [diff] [blame] | 229 | if (CONFIG_TFM_ENABLE_FP) |
Jianliang Shen | bd624ed | 2023-10-24 15:42:59 +0800 | [diff] [blame] | 230 | set(COMPILER_CP_C_FLAG "-mfloat-abi=hard -mfpu=${CONFIG_TFM_FP_ARCH}") |
| 231 | set(COMPILER_CP_ASM_FLAG "--fpu=${CONFIG_TFM_FP_ARCH_ASM}") |
David Hu | c28b9b2 | 2023-10-14 15:33:16 +0800 | [diff] [blame] | 232 | # armasm and armlink have the same option "--fpu" and are both used to |
| 233 | # specify the target FPU architecture. So the supported FPU architecture |
| 234 | # names can be shared by armasm and armlink. |
Jianliang Shen | bd624ed | 2023-10-24 15:42:59 +0800 | [diff] [blame] | 235 | set(LINKER_CP_OPTION "--fpu=${CONFIG_TFM_FP_ARCH_ASM}") |
David Hu | c28b9b2 | 2023-10-14 15:33:16 +0800 | [diff] [blame] | 236 | endif() |
| 237 | else() |
Jianliang Shen | bd624ed | 2023-10-24 15:42:59 +0800 | [diff] [blame] | 238 | set(COMPILER_CP_C_FLAG "-mfpu=softvfp") |
| 239 | set(COMPILER_CP_ASM_FLAG "--fpu=softvfp") |
| 240 | set(LINKER_CP_OPTION "--fpu=SoftVFP") |
David Hu | c28b9b2 | 2023-10-14 15:33:16 +0800 | [diff] [blame] | 241 | endif() |
| 242 | |
Jianliang Shen | bd624ed | 2023-10-24 15:42:59 +0800 | [diff] [blame] | 243 | string(APPEND CMAKE_C_FLAGS " " ${COMPILER_CP_C_FLAG}) |
| 244 | string(APPEND CMAKE_ASM_FLAGS " " ${COMPILER_CP_ASM_FLAG}) |
| 245 | string(APPEND CMAKE_C_LINK_FLAGS " " ${LINKER_CP_OPTION}) |
| 246 | string(APPEND CMAKE_ASM_LINK_FLAGS " " ${LINKER_CP_OPTION}) |
| 247 | |
David Hu | c28b9b2 | 2023-10-14 15:33:16 +0800 | [diff] [blame] | 248 | # Workaround for issues with --depend-single-line with armasm and Ninja |
| 249 | if (CMAKE_GENERATOR STREQUAL "Ninja") |
| 250 | set( CMAKE_DEPFILE_FLAGS_ASM "--depend=<OBJECT>.d") |
| 251 | endif() |
| 252 | |
| 253 | set(CMAKE_C_FLAGS_MINSIZEREL "-Oz -DNDEBUG") |
| 254 | endmacro() |
| 255 | |
| 256 | # Configure environment for the compiler setup run by cmake at the first |
| 257 | # `project` call in <tfm_root>/CMakeLists.txt. After this mandatory setup is |
| 258 | # done, all further compiler setup is done via tfm_toolchain_reload_compiler() |
| 259 | tfm_toolchain_set_processor_arch() |
| 260 | tfm_toolchain_reset_compiler_flags() |
| 261 | tfm_toolchain_reset_linker_flags() |
| 262 | |
| 263 | macro(add_convert_to_bin_target target) |
| 264 | get_target_property(bin_dir ${target} RUNTIME_OUTPUT_DIRECTORY) |
| 265 | |
| 266 | add_custom_target(${target}_bin |
| 267 | SOURCES ${bin_dir}/${target}.bin |
| 268 | ) |
| 269 | add_custom_command(OUTPUT ${bin_dir}/${target}.bin |
| 270 | DEPENDS ${target} |
| 271 | COMMAND fromelf |
| 272 | --bincombined $<TARGET_FILE:${target}> |
| 273 | --output=${bin_dir}/${target}.bin |
| 274 | ) |
| 275 | |
| 276 | add_custom_target(${target}_elf |
| 277 | SOURCES ${bin_dir}/${target}.elf |
| 278 | ) |
| 279 | add_custom_command(OUTPUT ${bin_dir}/${target}.elf |
| 280 | DEPENDS ${target} |
| 281 | COMMAND fromelf |
| 282 | --elf $<TARGET_FILE:${target}> |
| 283 | --output=${bin_dir}/${target}.elf |
| 284 | ) |
| 285 | |
| 286 | add_custom_target(${target}_hex |
| 287 | SOURCES ${bin_dir}/${target}.hex |
| 288 | ) |
| 289 | add_custom_command(OUTPUT ${bin_dir}/${target}.hex |
| 290 | DEPENDS ${target} |
| 291 | COMMAND fromelf |
| 292 | --i32combined $<TARGET_FILE:${target}> |
| 293 | --output=${bin_dir}/${target}.hex |
| 294 | ) |
| 295 | |
| 296 | add_custom_target(${target}_binaries |
| 297 | ALL |
| 298 | DEPENDS ${target}_bin |
| 299 | DEPENDS ${target}_elf |
| 300 | DEPENDS ${target}_hex |
| 301 | ) |
| 302 | endmacro() |
| 303 | |
| 304 | # Specify the scatter file used to link `target`. |
| 305 | # Behaviour for handling scatter files is so wildly divergent between compilers |
| 306 | # that this macro is required. |
| 307 | # |
| 308 | # Vendor platform can set a scatter file as property INTERFACE_LINK_DEPENDS of platform_ns. |
| 309 | # `target` can fetch the scatter file from platform_ns. |
| 310 | # |
| 311 | # Alternatively, NS build can call target_add_scatter_file() with the install directory of |
| 312 | # scatter files. |
| 313 | # target_add_scatter_file(target, install_dir) |
| 314 | # |
| 315 | # target_add_scatter_file() fetch a scatter file from the install directory. |
| 316 | macro(target_add_scatter_file target) |
| 317 | |
| 318 | # Try if scatter_file is passed from platform_ns |
| 319 | get_target_property(scatter_file |
| 320 | platform_ns |
| 321 | INTERFACE_LINK_DEPENDS |
| 322 | ) |
| 323 | |
| 324 | # If scatter_file is not passed from platform_ns |
| 325 | # Try if any scatter file is exported in install directory |
| 326 | # The intall directory is passed as an optinal argument |
| 327 | if(${scatter_file} STREQUAL "scatter_file-NOTFOUND") |
| 328 | set(install_dir ${ARGN}) |
| 329 | list(LENGTH install_dir nr_install_dir) |
| 330 | |
| 331 | # If nr_install_dir == 1, search for sct file under install dir |
| 332 | if(${nr_install_dir} EQUAL 1) |
| 333 | file(GLOB scatter_file "${install_dir}/*.sct") |
| 334 | endif() |
| 335 | endif() |
| 336 | |
| 337 | if(NOT EXISTS ${scatter_file}) |
| 338 | message(FATAL_ERROR "Unable to find NS scatter file ${scatter_file}") |
| 339 | endif() |
| 340 | |
| 341 | add_library(${target}_scatter OBJECT) |
| 342 | target_sources(${target}_scatter |
| 343 | PRIVATE |
| 344 | ${scatter_file} |
| 345 | ) |
| 346 | |
| 347 | # Cmake cannot use generator expressions in the |
| 348 | # set_source_file_properties command, so instead we just parse the regex |
| 349 | # for the filename and set the property on all files, regardless of if |
| 350 | # the generator expression would evaluate to true or not. |
| 351 | string(REGEX REPLACE ".*>:(.*)>$" "\\1" SCATTER_FILE_PATH "${scatter_file}") |
| 352 | set_source_files_properties(${SCATTER_FILE_PATH} |
| 353 | PROPERTIES |
| 354 | LANGUAGE C |
| 355 | ) |
| 356 | |
| 357 | target_link_options(${target} |
| 358 | PRIVATE |
| 359 | --scatter=$<TARGET_OBJECTS:${target}_scatter> |
| 360 | ) |
| 361 | |
| 362 | target_link_libraries(${target}_scatter |
David Hu | 35aa1a5 | 2023-10-24 23:04:04 +0800 | [diff] [blame] | 363 | PRIVATE |
| 364 | platform_region_defs |
David Hu | c28b9b2 | 2023-10-14 15:33:16 +0800 | [diff] [blame] | 365 | ) |
| 366 | |
| 367 | target_compile_options(${target}_scatter |
| 368 | PRIVATE |
| 369 | -E |
| 370 | -xc |
| 371 | ) |
| 372 | |
| 373 | add_dependencies(${target} ${target}_scatter) |
| 374 | set_target_properties(${target} PROPERTIES LINK_DEPENDS $<TARGET_OBJECTS:${target}_scatter>) |
| 375 | |
| 376 | endmacro() |