blob: f90f94aaed65f0807f5e8f05b507a79a2df59d56 [file] [log] [blame]
Raef Coles9ec67e62020-07-10 09:40:35 +01001#-------------------------------------------------------------------------------
David Hufb4a8b72022-01-13 16:46:02 +08002# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
Raef Coles9ec67e62020-07-10 09:40:35 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
Raef Coles9ec67e62020-07-10 09:40:35 +01007cmake_minimum_required(VERSION 3.15)
8
Raef Coles9ec67e62020-07-10 09:40:35 +01009SET(CMAKE_SYSTEM_NAME Generic)
Raef Coles9ec67e62020-07-10 09:40:35 +010010
11set(CMAKE_C_COMPILER armclang)
Raef Coles69817322020-10-19 14:14:14 +010012set(CMAKE_ASM_COMPILER armasm)
Raef Coles9ec67e62020-07-10 09:40:35 +010013
14set(LINKER_VENEER_OUTPUT_FLAG --import_cmse_lib_out=)
Raef Coles69817322020-10-19 14:14:14 +010015set(COMPILER_CMSE_FLAG $<$<COMPILE_LANGUAGE:C>:-mcmse>)
Raef Coles9ec67e62020-07-10 09:40:35 +010016
17# This variable name is a bit of a misnomer. The file it is set to is included
18# at a particular step in the compiler initialisation. It is used here to
19# configure the extensions for object files. Despite the name, it also works
20# with the Ninja generator.
21set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_LIST_DIR}/cmake/set_extensions.cmake)
22
Raef Coles69817322020-10-19 14:14:14 +010023macro(tfm_toolchain_reset_compiler_flags)
Raef Coles9ec67e62020-07-10 09:40:35 +010024 set_property(DIRECTORY PROPERTY COMPILE_OPTIONS "")
Raef Coles69817322020-10-19 14:14:14 +010025
26 add_compile_options(
27 $<$<COMPILE_LANGUAGE:C>:-Wno-ignored-optimization-argument>
28 $<$<COMPILE_LANGUAGE:C>:-Wno-unused-command-line-argument>
29 $<$<COMPILE_LANGUAGE:C>:-Wall>
30 # Don't error when the MBEDTLS_NULL_ENTROPY warning is shown
31 $<$<COMPILE_LANGUAGE:C>:-Wno-error=cpp>
32 $<$<COMPILE_LANGUAGE:C>:-c>
33 $<$<COMPILE_LANGUAGE:C>:-fdata-sections>
34 $<$<COMPILE_LANGUAGE:C>:-ffunction-sections>
35 $<$<COMPILE_LANGUAGE:C>:-fno-builtin>
36 $<$<COMPILE_LANGUAGE:C>:-fshort-enums>
37 $<$<COMPILE_LANGUAGE:C>:-fshort-wchar>
38 $<$<COMPILE_LANGUAGE:C>:-funsigned-char>
39 $<$<COMPILE_LANGUAGE:C>:-masm=auto>
40 $<$<COMPILE_LANGUAGE:C>:-nostdlib>
41 $<$<COMPILE_LANGUAGE:C>:-std=c99>
Xinyu Zhanga8b6b692022-06-06 10:50:28 +080042 $<$<COMPILE_LANGUAGE:C>:-mfpu=none>
43 $<$<COMPILE_LANGUAGE:ASM>:--fpu=none>
Raef Coles69817322020-10-19 14:14:14 +010044 $<$<COMPILE_LANGUAGE:ASM>:--cpu=${CMAKE_ASM_CPU_FLAG}>
Sebastian Bøeb73f1762021-10-28 14:23:13 +020045 $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${TFM_DEBUG_SYMBOLS}>>:-g>
Raef Coles69817322020-10-19 14:14:14 +010046 )
47endmacro()
48
Kevin Pengc32279d2022-02-10 11:11:55 +080049if(CONFIG_TFM_MEMORY_USAGE_QUIET)
Jimmy Brisson1f9b7c82021-12-14 10:53:36 -060050 set(MEMORY_USAGE_FLAG "")
51else()
52 set(MEMORY_USAGE_FLAG --info=summarysizes,sizes,totals,unused,veneers)
53endif()
54
Raef Coles69817322020-10-19 14:14:14 +010055macro(tfm_toolchain_reset_linker_flags)
Raef Coles9ec67e62020-07-10 09:40:35 +010056 set_property(DIRECTORY PROPERTY LINK_OPTIONS "")
Raef Coles69817322020-10-19 14:14:14 +010057
Raef Coles9ec67e62020-07-10 09:40:35 +010058 add_link_options(
Jimmy Brisson1f9b7c82021-12-14 10:53:36 -060059 ${MEMORY_USAGE_FLAG}
Raef Coles9ec67e62020-07-10 09:40:35 +010060 --strict
61 --symbols
62 --xref
Shawn Shan95fb8762021-06-25 16:48:40 +080063 $<$<AND:$<VERSION_GREATER:${TFM_ISOLATION_LEVEL},1>,$<STREQUAL:"${TEST_PSA_API}","IPC">>:--no-merge>
Raef Coles9ec67e62020-07-10 09:40:35 +010064 # Suppress link warnings that are consistant (and therefore hopefully
65 # harmless)
66 # https://developer.arm.com/documentation/100074/0608/linker-errors-and-warnings/list-of-the-armlink-error-and-warning-messages
67 # Empty region description
68 --diag_suppress=6312
69 # Ns section matches pattern
70 --diag_suppress=6314
71 # Duplicate input files
72 --diag_suppress=6304
Xinyu Zhang5b095db2021-06-04 15:17:26 +080073 # Pattern only matches removed unused sections.
74 --diag_suppress=6329
Xinyu Zhanga8b6b692022-06-06 10:50:28 +080075 --fpu=softvfp
Raef Coles9ec67e62020-07-10 09:40:35 +010076 )
Raef Coles69817322020-10-19 14:14:14 +010077endmacro()
Raef Coles9ec67e62020-07-10 09:40:35 +010078
Raef Coles69817322020-10-19 14:14:14 +010079macro(tfm_toolchain_set_processor_arch)
Gabor Abonyi866571c2021-10-07 13:56:19 +020080 if (DEFINED TFM_SYSTEM_PROCESSOR)
81 set(CMAKE_SYSTEM_PROCESSOR ${TFM_SYSTEM_PROCESSOR})
82
Gabor Toth4d414112021-11-10 17:44:50 +010083 if (TFM_SYSTEM_ARCHITECTURE STREQUAL "armv8.1-m.main")
84 message(WARNING "MVE is not yet supported using ARMCLANG")
85 string(APPEND CMAKE_SYSTEM_PROCESSOR "+nomve")
Gabor Abonyi866571c2021-10-07 13:56:19 +020086 endif()
87
Gabor Abonyi866571c2021-10-07 13:56:19 +020088 if (DEFINED TFM_SYSTEM_DSP)
89 if(NOT TFM_SYSTEM_DSP)
90 string(APPEND CMAKE_SYSTEM_PROCESSOR "+nodsp")
91 endif()
92 endif()
93
94 string(REGEX REPLACE "\\+nodsp" ".no_dsp" CMAKE_ASM_CPU_FLAG "${CMAKE_SYSTEM_PROCESSOR}")
95 else()
96 set(CMAKE_ASM_CPU_FLAG ${TFM_SYSTEM_ARCHITECTURE})
97
98 # Armasm uses different syntax than armclang for architecture targets
99 string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
100 string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
101
102 # Modifiers are additive instead of subtractive (.fp Vs .no_fp)
103 if (TFM_SYSTEM_DSP)
104 string(APPEND CMAKE_ASM_CPU_FLAG ".dsp")
Gabor Abonyi866571c2021-10-07 13:56:19 +0200105 endif()
106 endif()
107
108 # CMAKE_SYSTEM_ARCH is an ARMCLANG CMAKE internal variable, used to set
109 # compile and linker flags up until CMake 3.21 where CMP0123 was introduced:
110 # https://cmake.org/cmake/help/latest/policy/CMP0123.html
111 # This behavior is overwritten by setting CMAKE_C_FLAGS in
112 # tfm_toolchain_reload_compiler.
113 # Another use of this variable is to statisfy a requirement for ARMCLANG to
114 # set either the target CPU or the Architecture. This variable needs to be
115 # set to allow targeting architectures without a specific CPU.
116 set(CMAKE_SYSTEM_ARCH ${TFM_SYSTEM_ARCHITECTURE})
Raef Coles69817322020-10-19 14:14:14 +0100117
118 set(CMAKE_C_COMPILER_TARGET arm-${CROSS_COMPILE})
119 set(CMAKE_ASM_COMPILER_TARGET arm-${CROSS_COMPILE})
Raef Coles9ec67e62020-07-10 09:40:35 +0100120
Gabor Toth4d414112021-11-10 17:44:50 +0100121 # MVE is currently not supported in case of armclang
122 if (TFM_SYSTEM_ARCHITECTURE STREQUAL "armv8.1-m.main")
123 string(APPEND CMAKE_SYSTEM_ARCH "+nomve")
Raef Coles8db4ddf2020-11-19 09:35:37 +0000124 endif()
125
Raef Coles9ec67e62020-07-10 09:40:35 +0100126 if (DEFINED TFM_SYSTEM_DSP)
Raef Coles69817322020-10-19 14:14:14 +0100127 if(NOT TFM_SYSTEM_DSP)
Gabor Abonyi866571c2021-10-07 13:56:19 +0200128 string(APPEND CMAKE_SYSTEM_ARCH "+nodsp")
Raef Coles9ec67e62020-07-10 09:40:35 +0100129 endif()
Raef Coles8db4ddf2020-11-19 09:35:37 +0000130 endif()
Raef Coles69817322020-10-19 14:14:14 +0100131
Raef Colesd853fa52020-11-06 14:20:12 +0000132 # Cmake's ARMClang support has several issues with compiler validation. To
133 # avoid these, we set the list of supported -mcpu and -march variables to
134 # the ones we intend to use so that the validation will never fail.
Raef Coles69817322020-10-19 14:14:14 +0100135 include(Compiler/ARMClang)
Raef Colesd853fa52020-11-06 14:20:12 +0000136 set(CMAKE_C_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
Gabor Abonyi866571c2021-10-07 13:56:19 +0200137 set(CMAKE_C_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
Raef Colesd853fa52020-11-06 14:20:12 +0000138 set(CMAKE_ASM_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
Gabor Abonyi866571c2021-10-07 13:56:19 +0200139 set(CMAKE_ASM_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
Raef Coles69817322020-10-19 14:14:14 +0100140endmacro()
141
142macro(tfm_toolchain_reload_compiler)
143 tfm_toolchain_set_processor_arch()
144 tfm_toolchain_reset_compiler_flags()
145 tfm_toolchain_reset_linker_flags()
Raef Coles9ec67e62020-07-10 09:40:35 +0100146
147 unset(CMAKE_C_FLAGS_INIT)
148 unset(CMAKE_C_LINK_FLAGS)
149 unset(CMAKE_ASM_FLAGS_INIT)
150 unset(CMAKE_ASM_LINK_FLAGS)
Raef Colesfef2e0c2020-10-22 11:42:19 +0100151 unset(__mcpu_flag_set)
152 unset(__march_flag_set)
Raef Coles9ec67e62020-07-10 09:40:35 +0100153
Raef Coles69817322020-10-19 14:14:14 +0100154 include(Compiler/ARMClang)
Raef Coles9ec67e62020-07-10 09:40:35 +0100155 __compiler_armclang(C)
David Hu7075e312021-11-22 18:13:16 +0800156 include(Compiler/ARMCC-ASM)
Raef Coles69817322020-10-19 14:14:14 +0100157 __compiler_armcc(ASM)
Raef Coles9ec67e62020-07-10 09:40:35 +0100158
David Hufb4a8b72022-01-13 16:46:02 +0800159 if (CMAKE_C_COMPILER_VERSION VERSION_LESS 6.10.1)
160 message(FATAL_ERROR "Please select newer Arm compiler version starting from 6.10.1.")
161 endif()
162
David Hu9dd91b52022-04-06 17:00:56 +0800163 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.15 AND
164 CMAKE_C_COMPILER_VERSION VERSION_LESS 6.18)
David Hue5f56682022-04-06 17:17:11 +0800165 message(FATAL_ERROR "Armclang 6.15~6.17 may cause MemManage fault."
166 " This defect has been fixed since Armclang 6.18."
167 " See [SDCOMP-59788] in Armclang 6.18 release note for details."
168 " Please use other Armclang versions instead.")
David Hufb4a8b72022-01-13 16:46:02 +0800169 endif()
170
Raef Coles9ec67e62020-07-10 09:40:35 +0100171 set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT})
172
Gabor Abonyi866571c2021-10-07 13:56:19 +0200173 if (DEFINED TFM_SYSTEM_PROCESSOR)
Dávid Házie50f0a92022-07-06 14:46:01 +0200174 set(CMAKE_C_FLAGS "-mcpu=${CMAKE_SYSTEM_PROCESSOR}")
Gabor Abonyi866571c2021-10-07 13:56:19 +0200175 set(CMAKE_C_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
176 set(CMAKE_ASM_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
177 # But armlink doesn't support this +dsp syntax
178 string(REGEX REPLACE "\\+nodsp" "" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
179 string(REGEX REPLACE "\\+nodsp" "" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
180 # And uses different syntax for +nofp
181 string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
182 string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
Raef Coles69817322020-10-19 14:14:14 +0100183
Gabor Abonyi866571c2021-10-07 13:56:19 +0200184 string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
185 string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
Dávid Házie50f0a92022-07-06 14:46:01 +0200186 else()
187 set(CMAKE_C_FLAGS "-march=${CMAKE_SYSTEM_ARCH}")
Gabor Abonyi866571c2021-10-07 13:56:19 +0200188 endif()
Raef Coles8db4ddf2020-11-19 09:35:37 +0000189
Raef Coles69817322020-10-19 14:14:14 +0100190 # Workaround for issues with --depend-single-line with armasm and Ninja
191 if (CMAKE_GENERATOR STREQUAL "Ninja")
192 set( CMAKE_DEPFILE_FLAGS_ASM "--depend=<OBJECT>.d")
193 endif()
Raef Colesd29c7f72020-11-05 14:12:06 +0000194
195 set(CMAKE_C_FLAGS_MINSIZEREL "-Oz -DNDEBUG")
Raef Coles9ec67e62020-07-10 09:40:35 +0100196endmacro()
197
Raef Coles69817322020-10-19 14:14:14 +0100198# Configure environment for the compiler setup run by cmake at the first
199# `project` call in <tfm_root>/CMakeLists.txt. After this mandatory setup is
200# done, all further compiler setup is done via tfm_toolchain_reload_compiler()
201tfm_toolchain_set_processor_arch()
202tfm_toolchain_reset_compiler_flags()
203tfm_toolchain_reset_linker_flags()
204
Raef Coles9ec67e62020-07-10 09:40:35 +0100205# Behaviour for handling scatter files is so wildly divergent between compilers
206# that this macro is required.
207macro(target_add_scatter_file target)
208 target_link_options(${target}
209 PRIVATE
210 --scatter=$<TARGET_OBJECTS:${target}_scatter>
211 )
212
Raef Coles9ec67e62020-07-10 09:40:35 +0100213 add_library(${target}_scatter OBJECT)
214 foreach(scatter_file ${ARGN})
215 target_sources(${target}_scatter
216 PRIVATE
217 ${scatter_file}
218 )
219 # Cmake cannot use generator expressions in the
220 # set_source_file_properties command, so instead we just parse the regex
221 # for the filename and set the property on all files, regardless of if
222 # the generator expression would evaluate to true or not.
223 string(REGEX REPLACE ".*>:(.*)>$" "\\1" SCATTER_FILE_PATH "${scatter_file}")
224 set_source_files_properties(${SCATTER_FILE_PATH}
225 PROPERTIES
226 LANGUAGE C
227 )
228 endforeach()
229
Anton Komlev1a103552022-02-11 15:40:26 +0000230 add_dependencies(${target}
231 ${target}_scatter
232 )
233
234 set_target_properties(${target} PROPERTIES LINK_DEPENDS $<TARGET_OBJECTS:${target}_scatter>)
235
Raef Coles9ec67e62020-07-10 09:40:35 +0100236 target_link_libraries(${target}_scatter
237 platform_region_defs
238 psa_interface
239 tfm_partition_defs
240 )
241
242 target_compile_options(${target}_scatter
243 PRIVATE
244 -E
245 -xc
246 )
247endmacro()
248
249macro(add_convert_to_bin_target target)
250 get_target_property(bin_dir ${target} RUNTIME_OUTPUT_DIRECTORY)
251
252 add_custom_target(${target}_bin
253 SOURCES ${bin_dir}/${target}.bin
254 )
255 add_custom_command(OUTPUT ${bin_dir}/${target}.bin
256 DEPENDS ${target}
257 COMMAND fromelf
258 --bincombined $<TARGET_FILE:${target}>
259 --output=${bin_dir}/${target}.bin
260 )
261
262 add_custom_target(${target}_elf
263 SOURCES ${bin_dir}/${target}.elf
264 )
265 add_custom_command(OUTPUT ${bin_dir}/${target}.elf
266 DEPENDS ${target}
267 COMMAND fromelf
268 --elf $<TARGET_FILE:${target}>
269 --output=${bin_dir}/${target}.elf
270 )
271
272 add_custom_target(${target}_hex
273 SOURCES ${bin_dir}/${target}.hex
274 )
275 add_custom_command(OUTPUT ${bin_dir}/${target}.hex
276 DEPENDS ${target}
277 COMMAND fromelf
278 --i32combined $<TARGET_FILE:${target}>
279 --output=${bin_dir}/${target}.hex
280 )
281
282 add_custom_target(${target}_binaries
283 ALL
284 DEPENDS ${target}_bin
285 DEPENDS ${target}_elf
286 DEPENDS ${target}_hex
287 )
288endmacro()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000289
Raef Coles4351ec22021-04-26 09:20:50 +0100290macro(target_share_symbols target symbol_name_file)
291 get_target_property(TARGET_TYPE ${target} TYPE)
292 if (NOT TARGET_TYPE STREQUAL "EXECUTABLE")
293 message(FATAL_ERROR "${target} is not an executable. Symbols cannot be shared from libraries.")
294 endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000295
Raef Coles4351ec22021-04-26 09:20:50 +0100296 FILE(STRINGS ${symbol_name_file} KEEP_SYMBOL_LIST
297 LENGTH_MINIMUM 1
298 )
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000299
Raef Coles4351ec22021-04-26 09:20:50 +0100300 # strip all the symbols except those proveded as arguments. Long inline
301 # python scripts aren't ideal, but this is both portable and possibly easier
302 # to maintain than trying to filter files at build time in cmake.
303 add_custom_command(TARGET ${target}
304 POST_BUILD
305 VERBATIM
306 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}_shared_symbols.txt ${KEEP_SYMBOL_LIST})
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000307
Raef Coles4351ec22021-04-26 09:20:50 +0100308 # Force the target to not remove the symbols if they're unused. Not
309 # currently possible on GNU, has to be part of the linker script.
310 list(TRANSFORM KEEP_SYMBOL_LIST PREPEND --keep=)
311 target_link_options(${target}
312 PRIVATE
313 ${KEEP_SYMBOL_LIST}
314 )
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000315
Raef Coles4351ec22021-04-26 09:20:50 +0100316 # Ask armclang to produce a symdefs file that will
317 target_link_options(${target}
318 PRIVATE
319 --symdefs=$<TARGET_FILE_DIR:${target}>/${target}_shared_symbols.txt
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000320 )
321endmacro()
322
Raef Coles4351ec22021-04-26 09:20:50 +0100323macro(target_link_shared_code target)
324 get_target_property(TARGET_SOURCE_DIR ${target} SOURCE_DIR)
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000325
Raef Coles4351ec22021-04-26 09:20:50 +0100326 foreach(symbol_provider ${ARGN})
327 if (TARGET ${symbol_provider})
328 get_target_property(SYMBOL_PROVIDER_TYPE ${symbol_provider} TYPE)
329 if (NOT SYMBOL_PROVIDER_TYPE STREQUAL "EXECUTABLE")
330 message(FATAL_ERROR "${symbol_provider} is not an executable. Symbols cannot be shared from libraries.")
331 endif()
332 endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000333
Raef Coles4351ec22021-04-26 09:20:50 +0100334 add_dependencies(${target} ${symbol_provider})
335 # Some cmake functions don't allow generator expressions, so get the
336 # property as a backup. If the symbol provider hasn't been created yet,
337 # then use the output dir of the target.
338 if (TARGET ${symbol_provider})
339 get_target_property(SYMBOL_PROVIDER_OUTPUT_DIR ${symbol_provider} RUNTIME_OUTPUT_DIRECTORY)
340 else()
341 get_target_property(SYMBOL_PROVIDER_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY)
342 endif()
343 # Set these properties so that cmake will allow us to use a source file
344 # that doesn't exist at cmake-time, but we guarantee will exist at
345 # compile-time.
346 set_source_files_properties(${SYMBOL_PROVIDER_OUTPUT_DIR}/${symbol_provider}_shared_symbols.txt
347 DIRECTORY ${TARGET_SOURCE_DIR}
348 PROPERTIES
349 EXTERNAL_OBJECT true
350 GENERATED true
351 )
352 target_sources(${target}
353 PRIVATE
354 $<TARGET_FILE_DIR:${symbol_provider}>/${symbol_provider}_shared_symbols.txt
355 )
356 endforeach()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000357endmacro()
358
Raef Coles4351ec22021-04-26 09:20:50 +0100359macro(target_strip_symbols target)
360 set(SYMBOL_LIST "${ARGN}")
361 list(TRANSFORM SYMBOL_LIST PREPEND --strip-symbol=)
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000362
Raef Coles4351ec22021-04-26 09:20:50 +0100363 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
364 # armclang this isn't necessarily true.
365 add_custom_command(
366 TARGET ${target}
367 POST_BUILD
368 COMMAND ${CROSS_COMPILE}-objcopy
369 ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
370 )
371endmacro()
372
373macro(target_strip_symbols_from_dependency target dependency)
374 set(SYMBOL_LIST "${ARGN}")
375 list(TRANSFORM SYMBOL_LIST PREPEND --strip-symbol=)
376
377 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
378 # armclang this isn't necessarily true.
379 add_custom_command(
380 TARGET ${target}
381 PRE_LINK
382 COMMAND ${CROSS_COMPILE}-objcopy
383 ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
384 )
385endmacro()
386
387macro(target_weaken_symbols target)
388 set(SYMBOL_LIST "${ARGN}")
389 list(TRANSFORM SYMBOL_LIST PREPEND --weaken-symbol=)
390
391 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
392 # armclang this isn't necessarily true.
393 add_custom_command(
394 TARGET ${target}
395 POST_BUILD
396 COMMAND ${CROSS_COMPILE}-objcopy
397 ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
398 )
399endmacro()
400
401macro(target_weaken_symbols_from_dependency target dependency)
402 set(SYMBOL_LIST "${ARGN}")
403 list(TRANSFORM SYMBOL_LIST PREPEND --weaken-symbol=)
404
405 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
406 # armclang this isn't necessarily true.
407 add_custom_command(
408 TARGET ${target}
409 PRE_LINK
410 COMMAND ${CROSS_COMPILE}-objcopy
411 ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000412 )
413endmacro()