1#-------------------------------------------------------------------------------
2# Copyright (c) 2020-2024, Arm Limited. All rights reserved.
3# Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
4# or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
5#
6# SPDX-License-Identifier: BSD-3-Clause
7#
8#-------------------------------------------------------------------------------
9cmake_minimum_required(VERSION 3.21)
10
11SET(CMAKE_SYSTEM_NAME Generic)
12
13set(CMAKE_C_COMPILER armclang)
14set(CMAKE_CXX_COMPILER armclang)
15set(CMAKE_ASM_COMPILER armasm)
16
17set(LINKER_VENEER_OUTPUT_FLAG --import_cmse_lib_out=)
18set(COMPILER_CMSE_FLAG $<$<COMPILE_LANGUAGE:C>:-mcmse>)
19
20# This variable name is a bit of a misnomer. The file it is set to is included
21# at a particular step in the compiler initialisation. It is used here to
22# configure the extensions for object files. Despite the name, it also works
23# with the Ninja generator.
24set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_LIST_DIR}/cmake/set_extensions.cmake)
25
26if(NOT DEFINED CMAKE_OBJCOPY)
27    set(CMAKE_OBJCOPY ${CROSS_COMPILE}-objcopy CACHE FILEPATH "Path to objcopy")
28endif()
29
30macro(tfm_toolchain_reset_compiler_flags)
31    set_property(DIRECTORY PROPERTY COMPILE_OPTIONS "")
32
33    add_compile_options(
34        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wno-ignored-optimization-argument>
35        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wno-unused-command-line-argument>
36        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wall>
37        # Don't error when the MBEDTLS_NULL_ENTROPY warning is shown
38        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wno-error=cpp>
39        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-c>
40        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fdata-sections>
41        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-ffunction-sections>
42        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fno-builtin>
43        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fshort-enums>
44        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fshort-wchar>
45        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-funsigned-char>
46        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-masm=auto>
47        $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-nostdlib>
48        $<$<COMPILE_LANGUAGE:C>:-std=c99>
49        $<$<COMPILE_LANGUAGE:CXX>:-std=c++11>
50        $<$<COMPILE_LANGUAGE:ASM>:--cpu=${CMAKE_ASM_CPU_FLAG}>
51        $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${TFM_DEBUG_SYMBOLS}>>:-g>
52        $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<BOOL:${TFM_DEBUG_SYMBOLS}>>:-g>
53    )
54endmacro()
55
56if(CONFIG_TFM_MEMORY_USAGE_QUIET)
57    set(MEMORY_USAGE_FLAG "")
58else()
59    set(MEMORY_USAGE_FLAG --info=summarysizes,sizes,totals,unused,veneers)
60endif()
61
62macro(tfm_toolchain_reset_linker_flags)
63    set_property(DIRECTORY PROPERTY LINK_OPTIONS "")
64
65    add_link_options(
66        ${MEMORY_USAGE_FLAG}
67        --strict
68        --symbols
69        --xref
70        $<$<AND:$<VERSION_GREATER:${TFM_ISOLATION_LEVEL},1>,$<STREQUAL:"${TEST_PSA_API}","IPC">>:--no-merge>
71        # Suppress link warnings that are consistant (and therefore hopefully
72        # harmless)
73        # https://developer.arm.com/documentation/100074/0608/linker-errors-and-warnings/list-of-the-armlink-error-and-warning-messages
74        # Empty region description
75        --diag_suppress=6312
76        # Ns section matches pattern
77        --diag_suppress=6314
78        # Duplicate input files
79        --diag_suppress=6304
80        # Pattern only matches removed unused sections.
81        --diag_suppress=6329
82    )
83endmacro()
84
85macro(tfm_toolchain_set_processor_arch)
86    if (DEFINED TFM_SYSTEM_PROCESSOR)
87        set(CMAKE_SYSTEM_PROCESSOR       ${TFM_SYSTEM_PROCESSOR})
88
89        if (TFM_SYSTEM_ARCHITECTURE STREQUAL "armv8.1-m.main")
90            message(WARNING "MVE is not yet supported using ARMCLANG")
91            string(APPEND CMAKE_SYSTEM_PROCESSOR "+nomve")
92        endif()
93
94        if (DEFINED TFM_SYSTEM_DSP)
95            if(NOT TFM_SYSTEM_DSP)
96                string(APPEND CMAKE_SYSTEM_PROCESSOR "+nodsp")
97            endif()
98        endif()
99
100        # ARMCLANG specifies that '+nofp' is available on following M-profile cpus:
101        # 'cortex-m4', 'cortex-m7', 'cortex-m33', 'cortex-m35p', 'cortex-m55' and 'cortex-m85'.
102        # Build fails if other M-profile cpu, such as 'cortex-m23', is added with '+nofp'.
103        # Explicitly list those cpu to align with ARMCLANG description.
104        if (NOT CONFIG_TFM_FLOAT_ABI STREQUAL "hard" AND
105            (TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m4"
106            OR TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m7"
107            OR TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m33"
108            OR TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m35p"
109            OR TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m55"
110            OR TFM_SYSTEM_PROCESSOR STREQUAL "cortex-m85"))
111                string(APPEND CMAKE_SYSTEM_PROCESSOR "+nofp")
112        endif()
113
114        string(REGEX REPLACE "\\+nodsp" ".no_dsp" CMAKE_ASM_CPU_FLAG "${CMAKE_SYSTEM_PROCESSOR}")
115        string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
116        string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
117    else()
118        set(CMAKE_ASM_CPU_FLAG  ${TFM_SYSTEM_ARCHITECTURE})
119
120        # Armasm uses different syntax than armclang for architecture targets
121        string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
122        string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
123
124        # Modifiers are additive instead of subtractive (.fp Vs .no_fp)
125        if (TFM_SYSTEM_DSP)
126            string(APPEND CMAKE_ASM_CPU_FLAG ".dsp")
127        endif()
128
129        if (CONFIG_TFM_FLOAT_ABI STREQUAL "hard")
130            string(APPEND CMAKE_ASM_CPU_FLAG ".fp")
131        endif()
132    endif()
133
134    # CMAKE_SYSTEM_ARCH is an ARMCLANG CMAKE internal variable, used to set
135    # compile and linker flags up until CMake 3.21 where CMP0123 was introduced:
136    # https://cmake.org/cmake/help/latest/policy/CMP0123.html
137    # This behavior is overwritten by setting CMAKE_C_FLAGS in
138    # tfm_toolchain_reload_compiler.
139    # Another use of this variable is to statisfy a requirement for ARMCLANG to
140    # set either the target CPU or the Architecture. This variable needs to be
141    # set to allow targeting architectures without a specific CPU.
142    set(CMAKE_SYSTEM_ARCH            ${TFM_SYSTEM_ARCHITECTURE})
143
144    set(CMAKE_C_COMPILER_TARGET      arm-${CROSS_COMPILE})
145    set(CMAKE_CXX_COMPILER_TARGET    arm-${CROSS_COMPILE})
146    set(CMAKE_ASM_COMPILER_TARGET    arm-${CROSS_COMPILE})
147
148    # MVE is currently not supported in case of armclang
149    if (TFM_SYSTEM_ARCHITECTURE STREQUAL "armv8.1-m.main")
150        string(APPEND CMAKE_SYSTEM_ARCH "+nomve")
151    endif()
152
153    if (DEFINED TFM_SYSTEM_DSP)
154        if(NOT TFM_SYSTEM_DSP)
155            string(APPEND CMAKE_SYSTEM_ARCH "+nodsp")
156        endif()
157    endif()
158
159    # Cmake's ARMClang support has several issues with compiler validation. To
160    # avoid these, we set the list of supported -mcpu and -march variables to
161    # the ones we intend to use so that the validation will never fail.
162    include(Compiler/ARMClang)
163    set(CMAKE_C_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
164    set(CMAKE_C_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
165    set(CMAKE_CXX_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
166    set(CMAKE_CXX_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
167    set(CMAKE_ASM_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
168    set(CMAKE_ASM_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
169endmacro()
170
171macro(tfm_toolchain_reload_compiler)
172    tfm_toolchain_set_processor_arch()
173    tfm_toolchain_reset_compiler_flags()
174    tfm_toolchain_reset_linker_flags()
175
176    unset(CMAKE_C_FLAGS_INIT)
177    unset(CMAKE_CXX_FLAGS_INIT)
178    unset(CMAKE_C_LINK_FLAGS)
179    unset(CMAKE_ASM_FLAGS_INIT)
180    unset(CMAKE_ASM_LINK_FLAGS)
181    unset(__mcpu_flag_set)
182    unset(__march_flag_set)
183
184    include(Compiler/ARMClang)
185    __compiler_armclang(C)
186    include(Compiler/ARMCC-ASM)
187    __compiler_armcc(ASM)
188
189    if (CMAKE_C_COMPILER_VERSION VERSION_LESS 6.13)
190        message(FATAL_ERROR "Please select newer Arm compiler version starting from 6.13.")
191    endif()
192
193    if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.15 AND
194        CMAKE_C_COMPILER_VERSION VERSION_LESS 6.18)
195        message(FATAL_ERROR "Armclang 6.15~6.17 may cause MemManage fault."
196                            " This defect has been fixed since Armclang 6.18."
197                            " See [SDCOMP-59788] in Armclang 6.18 release note for details."
198                            " Please use other Armclang versions instead.")
199    endif()
200
201    set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT})
202
203    if (DEFINED TFM_SYSTEM_PROCESSOR)
204        set(CMAKE_C_FLAGS "-mcpu=${CMAKE_SYSTEM_PROCESSOR}")
205        set(CMAKE_CXX_FLAGS "-mcpu=${CMAKE_SYSTEM_PROCESSOR}")
206        set(CMAKE_C_LINK_FLAGS   "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
207        set(CMAKE_CXX_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
208        set(CMAKE_ASM_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
209        # But armlink doesn't support this +dsp syntax
210        string(REGEX REPLACE "\\+nodsp" "" CMAKE_C_LINK_FLAGS   "${CMAKE_C_LINK_FLAGS}")
211        string(REGEX REPLACE "\\+nodsp" "" CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}")
212        string(REGEX REPLACE "\\+nodsp" "" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
213        # And uses different syntax for +nofp
214        string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_C_LINK_FLAGS   "${CMAKE_C_LINK_FLAGS}")
215        string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}")
216        string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
217
218        string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_C_LINK_FLAGS   "${CMAKE_C_LINK_FLAGS}")
219        string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}")
220        string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
221    else()
222        set(CMAKE_C_FLAGS "-march=${CMAKE_SYSTEM_ARCH}")
223        set(CMAKE_CXX_FLAGS "-march=${CMAKE_SYSTEM_ARCH}")
224    endif()
225
226    set(BL2_COMPILER_CP_FLAG
227        $<$<COMPILE_LANGUAGE:C>:-mfpu=softvfp>
228        $<$<COMPILE_LANGUAGE:ASM>:--fpu=softvfp>
229    )
230    # As BL2 does not use hardware FPU, specify '--fpu=SoftVFP' explicitly to use software
231    # library functions for BL2 to override any implicit FPU option, such as '--cpu' option.
232    # Because the implicit hardware FPU option enforces BL2 to initialize FPU but hardware FPU
233    # is not actually enabled in BL2, it will cause BL2 runtime fault.
234    set(BL2_LINKER_CP_OPTION --fpu=SoftVFP)
235
236    set(BL1_COMPILER_CP_FLAG
237        $<$<COMPILE_LANGUAGE:C>:-mfpu=softvfp>
238        $<$<COMPILE_LANGUAGE:ASM>:--fpu=softvfp>
239    )
240    set(BL1_LINKER_CP_OPTION --fpu=SoftVFP)
241
242    if (CONFIG_TFM_FLOAT_ABI STREQUAL "hard")
243        set(COMPILER_CP_FLAG
244            $<$<COMPILE_LANGUAGE:C>:-mfloat-abi=hard>
245        )
246        if (CONFIG_TFM_ENABLE_FP)
247            set(COMPILER_CP_FLAG
248                $<$<COMPILE_LANGUAGE:C>:-mfpu=${CONFIG_TFM_FP_ARCH};-mfloat-abi=hard>
249                $<$<COMPILE_LANGUAGE:ASM>:--fpu=${CONFIG_TFM_FP_ARCH_ASM}>
250            )
251            # armasm and armlink have the same option "--fpu" and are both used to
252            # specify the target FPU architecture. So the supported FPU architecture
253            # names can be shared by armasm and armlink.
254            set(LINKER_CP_OPTION --fpu=${CONFIG_TFM_FP_ARCH_ASM})
255        endif()
256    else()
257        set(COMPILER_CP_FLAG
258            $<$<COMPILE_LANGUAGE:C>:-mfpu=softvfp>
259            $<$<COMPILE_LANGUAGE:ASM>:--fpu=softvfp>
260        )
261        set(LINKER_CP_OPTION --fpu=SoftVFP)
262    endif()
263
264    # Workaround for issues with --depend-single-line with armasm and Ninja
265    if (CMAKE_GENERATOR STREQUAL "Ninja")
266        set( CMAKE_DEPFILE_FLAGS_ASM "--depend=<OBJECT>.d")
267    endif()
268
269    set(CMAKE_C_FLAGS_MINSIZEREL "-Oz -DNDEBUG")
270endmacro()
271
272# Configure environment for the compiler setup run by cmake at the first
273# `project` call in <tfm_root>/CMakeLists.txt. After this mandatory setup is
274# done, all further compiler setup is done via tfm_toolchain_reload_compiler()
275tfm_toolchain_set_processor_arch()
276tfm_toolchain_reset_compiler_flags()
277tfm_toolchain_reset_linker_flags()
278
279# Behaviour for handling scatter files is so wildly divergent between compilers
280# that this macro is required.
281macro(target_add_scatter_file target)
282    target_link_options(${target}
283        PRIVATE
284        --scatter=$<TARGET_OBJECTS:${target}_scatter>
285    )
286
287    add_library(${target}_scatter OBJECT)
288    foreach(scatter_file ${ARGN})
289        target_sources(${target}_scatter
290            PRIVATE
291                ${scatter_file}
292        )
293        # Cmake cannot use generator expressions in the
294        # set_source_file_properties command, so instead we just parse the regex
295        # for the filename and set the property on all files, regardless of if
296        # the generator expression would evaluate to true or not.
297        string(REGEX REPLACE ".*>:(.*)>$" "\\1" SCATTER_FILE_PATH "${scatter_file}")
298        set_source_files_properties(${SCATTER_FILE_PATH}
299            PROPERTIES
300            LANGUAGE C
301        )
302    endforeach()
303
304    add_dependencies(${target}
305        ${target}_scatter
306    )
307
308    set_target_properties(${target} PROPERTIES LINK_DEPENDS $<TARGET_OBJECTS:${target}_scatter>)
309
310    target_link_libraries(${target}_scatter
311        platform_region_defs
312        psa_interface
313        tfm_config
314    )
315
316    target_compile_options(${target}_scatter
317        PRIVATE
318            -E
319            -xc
320    )
321endmacro()
322
323macro(add_convert_to_bin_target target)
324    get_target_property(bin_dir ${target} RUNTIME_OUTPUT_DIRECTORY)
325
326    add_custom_target(${target}_bin
327        SOURCES ${bin_dir}/${target}.bin
328    )
329    add_custom_command(OUTPUT ${bin_dir}/${target}.bin
330        DEPENDS ${target}
331        COMMAND fromelf
332            --bincombined $<TARGET_FILE:${target}>
333            --output=${bin_dir}/${target}.bin
334    )
335
336    add_custom_target(${target}_elf
337        SOURCES ${bin_dir}/${target}.elf
338    )
339    add_custom_command(OUTPUT ${bin_dir}/${target}.elf
340        DEPENDS ${target}
341        COMMAND fromelf
342            --elf $<TARGET_FILE:${target}>
343            --output=${bin_dir}/${target}.elf
344    )
345
346    add_custom_target(${target}_hex
347        SOURCES ${bin_dir}/${target}.hex
348    )
349    add_custom_command(OUTPUT ${bin_dir}/${target}.hex
350        DEPENDS ${target}
351        COMMAND fromelf
352            --i32combined $<TARGET_FILE:${target}>
353            --output=${bin_dir}/${target}.hex
354    )
355
356    add_custom_target(${target}_binaries
357        ALL
358        DEPENDS ${target}_bin
359        DEPENDS ${target}_elf
360        DEPENDS ${target}_hex
361    )
362endmacro()
363
364macro(target_share_symbols target)
365    get_target_property(TARGET_TYPE ${target} TYPE)
366    if (NOT TARGET_TYPE STREQUAL "EXECUTABLE")
367        message(FATAL_ERROR "${target} is not an executable. Symbols cannot be shared from libraries.")
368    endif()
369
370    foreach(symbol_file ${ARGN})
371        FILE(STRINGS ${symbol_file} SYMBOLS
372            LENGTH_MINIMUM 1
373        )
374        list(APPEND KEEP_SYMBOL_LIST ${SYMBOLS})
375    endforeach()
376
377
378    # strip all the symbols except those proveded as arguments. Long inline
379    # python scripts aren't ideal, but this is both portable and possibly easier
380    # to maintain than trying to filter files at build time in cmake.
381    add_custom_command(TARGET ${target}
382        POST_BUILD
383        VERBATIM
384        COMMAND python3 -c "from sys import argv; import re; f = open(argv[1], 'rt'); p = [x.replace('*', '.*') for x in argv[2:]]; l = [x for x in f.readlines() if re.search(r'(?=('+'$|'.join(p + ['SYMDEFS']) + r'))', x)]; f.close(); f = open(argv[1], 'wt'); f.writelines(l); f.close();" $<TARGET_FILE_DIR:${target}>/${target}${CODE_SHARING_OUTPUT_FILE_SUFFIX} ${KEEP_SYMBOL_LIST})
385
386    # Force the target to not remove the symbols if they're unused.
387    list(TRANSFORM KEEP_SYMBOL_LIST PREPEND --undefined=)
388    target_link_options(${target}
389        PRIVATE
390            ${KEEP_SYMBOL_LIST}
391    )
392
393    # Ask armclang to produce a symdefs file that will
394    target_link_options(${target}
395        PRIVATE
396            --symdefs=$<TARGET_FILE_DIR:${target}>/${target}${CODE_SHARING_OUTPUT_FILE_SUFFIX}
397    )
398endmacro()
399
400macro(target_link_shared_code target)
401    get_target_property(TARGET_SOURCE_DIR ${target} SOURCE_DIR)
402
403    foreach(symbol_provider ${ARGN})
404        if (TARGET ${symbol_provider})
405            get_target_property(SYMBOL_PROVIDER_TYPE ${symbol_provider} TYPE)
406            if (NOT SYMBOL_PROVIDER_TYPE STREQUAL "EXECUTABLE")
407                message(FATAL_ERROR "${symbol_provider} is not an executable. Symbols cannot be shared from libraries.")
408            endif()
409        endif()
410
411        add_dependencies(${target} ${symbol_provider})
412        target_link_options(${target} PRIVATE LINKER:$<TARGET_FILE_DIR:${symbol_provider}>/${symbol_provider}${CODE_SHARING_INPUT_FILE_SUFFIX})
413    endforeach()
414endmacro()
415
416macro(target_strip_symbols target)
417    set(SYMBOL_LIST "${ARGN}")
418    list(TRANSFORM SYMBOL_LIST PREPEND  --strip-symbol=)
419
420    # TODO we assume that arm-none-eabi-objcopy is available - since we're using
421    # armclang this isn't necessarily true.
422    add_custom_command(
423        TARGET ${target}
424        POST_BUILD
425        COMMAND ${CMAKE_OBJCOPY}
426        ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
427    )
428endmacro()
429
430macro(target_strip_symbols_from_dependency target dependency)
431    set(SYMBOL_LIST "${ARGN}")
432    list(TRANSFORM SYMBOL_LIST PREPEND  --strip-symbol=)
433
434    # TODO we assume that arm-none-eabi-objcopy is available - since we're using
435    # armclang this isn't necessarily true.
436    add_custom_command(
437        TARGET ${target}
438        PRE_LINK
439        COMMAND ${CMAKE_OBJCOPY}
440        ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
441    )
442endmacro()
443
444macro(target_weaken_symbols target)
445    set(SYMBOL_LIST "${ARGN}")
446    list(TRANSFORM SYMBOL_LIST PREPEND  --weaken-symbol=)
447
448    # TODO we assume that arm-none-eabi-objcopy is available - since we're using
449    # armclang this isn't necessarily true.
450    add_custom_command(
451        TARGET ${target}
452        POST_BUILD
453        COMMAND ${CMAKE_OBJCOPY}
454        ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
455    )
456endmacro()
457
458macro(target_weaken_symbols_from_dependency target dependency)
459    set(SYMBOL_LIST "${ARGN}")
460    list(TRANSFORM SYMBOL_LIST PREPEND  --weaken-symbol=)
461
462    # TODO we assume that arm-none-eabi-objcopy is available - since we're using
463    # armclang this isn't necessarily true.
464    add_custom_command(
465        TARGET ${target}
466        PRE_LINK
467        COMMAND ${CMAKE_OBJCOPY}
468        ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
469    )
470endmacro()
471