blob: 403a9c1a752a26bbfa5fd2e74aa79bc596c6509c [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 Coles69817322020-10-19 14:14:14 +01009# Don't load this file if it is specified as a cmake toolchain file
10if(NOT TFM_TOOLCHAIN_FILE)
11 message(DEPRECATION "SETTING CMAKE_TOOLCHAIN_FILE is deprecated. It has been replaced with TFM_TOOLCHAIN_FILE.")
12 return()
13endif()
Raef Coles6e8f83d2020-09-28 10:44:06 +010014
Raef Coles9ec67e62020-07-10 09:40:35 +010015SET(CMAKE_SYSTEM_NAME Generic)
Raef Coles9ec67e62020-07-10 09:40:35 +010016
17set(CMAKE_C_COMPILER armclang)
Raef Coles69817322020-10-19 14:14:14 +010018set(CMAKE_ASM_COMPILER armasm)
Raef Coles9ec67e62020-07-10 09:40:35 +010019
20set(LINKER_VENEER_OUTPUT_FLAG --import_cmse_lib_out=)
Raef Coles69817322020-10-19 14:14:14 +010021set(COMPILER_CMSE_FLAG $<$<COMPILE_LANGUAGE:C>:-mcmse>)
Raef Coles9ec67e62020-07-10 09:40:35 +010022
23# This variable name is a bit of a misnomer. The file it is set to is included
24# at a particular step in the compiler initialisation. It is used here to
25# configure the extensions for object files. Despite the name, it also works
26# with the Ninja generator.
27set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_LIST_DIR}/cmake/set_extensions.cmake)
28
Raef Coles69817322020-10-19 14:14:14 +010029macro(tfm_toolchain_reset_compiler_flags)
Raef Coles9ec67e62020-07-10 09:40:35 +010030 set_property(DIRECTORY PROPERTY COMPILE_OPTIONS "")
Raef Coles69817322020-10-19 14:14:14 +010031
32 add_compile_options(
33 $<$<COMPILE_LANGUAGE:C>:-Wno-ignored-optimization-argument>
34 $<$<COMPILE_LANGUAGE:C>:-Wno-unused-command-line-argument>
35 $<$<COMPILE_LANGUAGE:C>:-Wall>
36 # Don't error when the MBEDTLS_NULL_ENTROPY warning is shown
37 $<$<COMPILE_LANGUAGE:C>:-Wno-error=cpp>
38 $<$<COMPILE_LANGUAGE:C>:-c>
39 $<$<COMPILE_LANGUAGE:C>:-fdata-sections>
40 $<$<COMPILE_LANGUAGE:C>:-ffunction-sections>
41 $<$<COMPILE_LANGUAGE:C>:-fno-builtin>
42 $<$<COMPILE_LANGUAGE:C>:-fshort-enums>
43 $<$<COMPILE_LANGUAGE:C>:-fshort-wchar>
44 $<$<COMPILE_LANGUAGE:C>:-funsigned-char>
45 $<$<COMPILE_LANGUAGE:C>:-masm=auto>
46 $<$<COMPILE_LANGUAGE:C>:-nostdlib>
47 $<$<COMPILE_LANGUAGE:C>:-std=c99>
Xinyu Zhanga8b6b692022-06-06 10:50:28 +080048 $<$<COMPILE_LANGUAGE:C>:-mfpu=none>
49 $<$<COMPILE_LANGUAGE:ASM>:--fpu=none>
Raef Coles69817322020-10-19 14:14:14 +010050 $<$<COMPILE_LANGUAGE:ASM>:--cpu=${CMAKE_ASM_CPU_FLAG}>
Sebastian Bøeb73f1762021-10-28 14:23:13 +020051 $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${TFM_DEBUG_SYMBOLS}>>:-g>
Raef Coles69817322020-10-19 14:14:14 +010052 )
53endmacro()
54
Kevin Pengc32279d2022-02-10 11:11:55 +080055if(CONFIG_TFM_MEMORY_USAGE_QUIET)
Jimmy Brisson1f9b7c82021-12-14 10:53:36 -060056 set(MEMORY_USAGE_FLAG "")
57else()
58 set(MEMORY_USAGE_FLAG --info=summarysizes,sizes,totals,unused,veneers)
59endif()
60
Raef Coles69817322020-10-19 14:14:14 +010061macro(tfm_toolchain_reset_linker_flags)
Raef Coles9ec67e62020-07-10 09:40:35 +010062 set_property(DIRECTORY PROPERTY LINK_OPTIONS "")
Raef Coles69817322020-10-19 14:14:14 +010063
Raef Coles9ec67e62020-07-10 09:40:35 +010064 add_link_options(
Jimmy Brisson1f9b7c82021-12-14 10:53:36 -060065 ${MEMORY_USAGE_FLAG}
Raef Coles9ec67e62020-07-10 09:40:35 +010066 --strict
67 --symbols
68 --xref
Shawn Shan95fb8762021-06-25 16:48:40 +080069 $<$<AND:$<VERSION_GREATER:${TFM_ISOLATION_LEVEL},1>,$<STREQUAL:"${TEST_PSA_API}","IPC">>:--no-merge>
Raef Coles9ec67e62020-07-10 09:40:35 +010070 # Suppress link warnings that are consistant (and therefore hopefully
71 # harmless)
72 # https://developer.arm.com/documentation/100074/0608/linker-errors-and-warnings/list-of-the-armlink-error-and-warning-messages
73 # Empty region description
74 --diag_suppress=6312
75 # Ns section matches pattern
76 --diag_suppress=6314
77 # Duplicate input files
78 --diag_suppress=6304
Xinyu Zhang5b095db2021-06-04 15:17:26 +080079 # Pattern only matches removed unused sections.
80 --diag_suppress=6329
Xinyu Zhanga8b6b692022-06-06 10:50:28 +080081 --fpu=softvfp
Raef Coles9ec67e62020-07-10 09:40:35 +010082 )
Raef Coles69817322020-10-19 14:14:14 +010083endmacro()
Raef Coles9ec67e62020-07-10 09:40:35 +010084
Raef Coles69817322020-10-19 14:14:14 +010085macro(tfm_toolchain_set_processor_arch)
Gabor Abonyi866571c2021-10-07 13:56:19 +020086 if (DEFINED TFM_SYSTEM_PROCESSOR)
87 set(CMAKE_SYSTEM_PROCESSOR ${TFM_SYSTEM_PROCESSOR})
88
89 if (DEFINED TFM_SYSTEM_MVE)
90 if(NOT TFM_SYSTEM_MVE)
91 string(APPEND CMAKE_SYSTEM_PROCESSOR "+nomve")
92 endif()
93 endif()
94
Gabor Abonyi866571c2021-10-07 13:56:19 +020095 if (DEFINED TFM_SYSTEM_DSP)
96 if(NOT TFM_SYSTEM_DSP)
97 string(APPEND CMAKE_SYSTEM_PROCESSOR "+nodsp")
98 endif()
99 endif()
100
101 string(REGEX REPLACE "\\+nodsp" ".no_dsp" CMAKE_ASM_CPU_FLAG "${CMAKE_SYSTEM_PROCESSOR}")
102 else()
103 set(CMAKE_ASM_CPU_FLAG ${TFM_SYSTEM_ARCHITECTURE})
104
105 # Armasm uses different syntax than armclang for architecture targets
106 string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
107 string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
108
109 # Modifiers are additive instead of subtractive (.fp Vs .no_fp)
110 if (TFM_SYSTEM_DSP)
111 string(APPEND CMAKE_ASM_CPU_FLAG ".dsp")
112 else()
113 if (TFM_SYSTEM_MVE)
114 string(APPEND CMAKE_ASM_CPU_FLAG ".mve")
115 endif()
Gabor Abonyi866571c2021-10-07 13:56:19 +0200116 endif()
117 endif()
118
119 # CMAKE_SYSTEM_ARCH is an ARMCLANG CMAKE internal variable, used to set
120 # compile and linker flags up until CMake 3.21 where CMP0123 was introduced:
121 # https://cmake.org/cmake/help/latest/policy/CMP0123.html
122 # This behavior is overwritten by setting CMAKE_C_FLAGS in
123 # tfm_toolchain_reload_compiler.
124 # Another use of this variable is to statisfy a requirement for ARMCLANG to
125 # set either the target CPU or the Architecture. This variable needs to be
126 # set to allow targeting architectures without a specific CPU.
127 set(CMAKE_SYSTEM_ARCH ${TFM_SYSTEM_ARCHITECTURE})
Raef Coles69817322020-10-19 14:14:14 +0100128
129 set(CMAKE_C_COMPILER_TARGET arm-${CROSS_COMPILE})
130 set(CMAKE_ASM_COMPILER_TARGET arm-${CROSS_COMPILE})
Raef Coles9ec67e62020-07-10 09:40:35 +0100131
Raef Coles8db4ddf2020-11-19 09:35:37 +0000132 if (DEFINED TFM_SYSTEM_MVE)
133 if(NOT TFM_SYSTEM_MVE)
Gabor Abonyi866571c2021-10-07 13:56:19 +0200134 string(APPEND CMAKE_SYSTEM_ARCH "+nomve")
Raef Coles8db4ddf2020-11-19 09:35:37 +0000135 endif()
136 endif()
137
Raef Coles9ec67e62020-07-10 09:40:35 +0100138 if (DEFINED TFM_SYSTEM_DSP)
Raef Coles69817322020-10-19 14:14:14 +0100139 if(NOT TFM_SYSTEM_DSP)
Gabor Abonyi866571c2021-10-07 13:56:19 +0200140 string(APPEND CMAKE_SYSTEM_ARCH "+nodsp")
Raef Coles9ec67e62020-07-10 09:40:35 +0100141 endif()
Raef Coles8db4ddf2020-11-19 09:35:37 +0000142 endif()
Raef Coles69817322020-10-19 14:14:14 +0100143
Raef Colesd853fa52020-11-06 14:20:12 +0000144 # Cmake's ARMClang support has several issues with compiler validation. To
145 # avoid these, we set the list of supported -mcpu and -march variables to
146 # the ones we intend to use so that the validation will never fail.
Raef Coles69817322020-10-19 14:14:14 +0100147 include(Compiler/ARMClang)
Raef Colesd853fa52020-11-06 14:20:12 +0000148 set(CMAKE_C_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
Gabor Abonyi866571c2021-10-07 13:56:19 +0200149 set(CMAKE_C_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
Raef Colesd853fa52020-11-06 14:20:12 +0000150 set(CMAKE_ASM_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
Gabor Abonyi866571c2021-10-07 13:56:19 +0200151 set(CMAKE_ASM_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
Raef Coles69817322020-10-19 14:14:14 +0100152endmacro()
153
154macro(tfm_toolchain_reload_compiler)
155 tfm_toolchain_set_processor_arch()
156 tfm_toolchain_reset_compiler_flags()
157 tfm_toolchain_reset_linker_flags()
Raef Coles9ec67e62020-07-10 09:40:35 +0100158
159 unset(CMAKE_C_FLAGS_INIT)
160 unset(CMAKE_C_LINK_FLAGS)
161 unset(CMAKE_ASM_FLAGS_INIT)
162 unset(CMAKE_ASM_LINK_FLAGS)
Raef Colesfef2e0c2020-10-22 11:42:19 +0100163 unset(__mcpu_flag_set)
164 unset(__march_flag_set)
Raef Coles9ec67e62020-07-10 09:40:35 +0100165
Raef Coles69817322020-10-19 14:14:14 +0100166 include(Compiler/ARMClang)
Raef Coles9ec67e62020-07-10 09:40:35 +0100167 __compiler_armclang(C)
David Hu7075e312021-11-22 18:13:16 +0800168 include(Compiler/ARMCC-ASM)
Raef Coles69817322020-10-19 14:14:14 +0100169 __compiler_armcc(ASM)
Raef Coles9ec67e62020-07-10 09:40:35 +0100170
David Hufb4a8b72022-01-13 16:46:02 +0800171 if (CMAKE_C_COMPILER_VERSION VERSION_LESS 6.10.1)
172 message(FATAL_ERROR "Please select newer Arm compiler version starting from 6.10.1.")
173 endif()
174
David Hu9dd91b52022-04-06 17:00:56 +0800175 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.15 AND
176 CMAKE_C_COMPILER_VERSION VERSION_LESS 6.18)
David Hue5f56682022-04-06 17:17:11 +0800177 message(FATAL_ERROR "Armclang 6.15~6.17 may cause MemManage fault."
178 " This defect has been fixed since Armclang 6.18."
179 " See [SDCOMP-59788] in Armclang 6.18 release note for details."
180 " Please use other Armclang versions instead.")
David Hufb4a8b72022-01-13 16:46:02 +0800181 endif()
182
Raef Coles9ec67e62020-07-10 09:40:35 +0100183 set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT})
184
Gabor Abonyi866571c2021-10-07 13:56:19 +0200185 if (DEFINED TFM_SYSTEM_PROCESSOR)
Dávid Házie50f0a92022-07-06 14:46:01 +0200186 set(CMAKE_C_FLAGS "-mcpu=${CMAKE_SYSTEM_PROCESSOR}")
Gabor Abonyi866571c2021-10-07 13:56:19 +0200187 set(CMAKE_C_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
188 set(CMAKE_ASM_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
189 # But armlink doesn't support this +dsp syntax
190 string(REGEX REPLACE "\\+nodsp" "" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
191 string(REGEX REPLACE "\\+nodsp" "" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
192 # And uses different syntax for +nofp
193 string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
194 string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
Raef Coles69817322020-10-19 14:14:14 +0100195
Gabor Abonyi866571c2021-10-07 13:56:19 +0200196 string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
197 string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
Dávid Házie50f0a92022-07-06 14:46:01 +0200198 else()
199 set(CMAKE_C_FLAGS "-march=${CMAKE_SYSTEM_ARCH}")
Gabor Abonyi866571c2021-10-07 13:56:19 +0200200 endif()
Raef Coles8db4ddf2020-11-19 09:35:37 +0000201
Raef Coles69817322020-10-19 14:14:14 +0100202 # Workaround for issues with --depend-single-line with armasm and Ninja
203 if (CMAKE_GENERATOR STREQUAL "Ninja")
204 set( CMAKE_DEPFILE_FLAGS_ASM "--depend=<OBJECT>.d")
205 endif()
Raef Colesd29c7f72020-11-05 14:12:06 +0000206
207 set(CMAKE_C_FLAGS_MINSIZEREL "-Oz -DNDEBUG")
Raef Coles9ec67e62020-07-10 09:40:35 +0100208endmacro()
209
Raef Coles69817322020-10-19 14:14:14 +0100210# Configure environment for the compiler setup run by cmake at the first
211# `project` call in <tfm_root>/CMakeLists.txt. After this mandatory setup is
212# done, all further compiler setup is done via tfm_toolchain_reload_compiler()
213tfm_toolchain_set_processor_arch()
214tfm_toolchain_reset_compiler_flags()
215tfm_toolchain_reset_linker_flags()
216
Raef Coles9ec67e62020-07-10 09:40:35 +0100217# Behaviour for handling scatter files is so wildly divergent between compilers
218# that this macro is required.
219macro(target_add_scatter_file target)
220 target_link_options(${target}
221 PRIVATE
222 --scatter=$<TARGET_OBJECTS:${target}_scatter>
223 )
224
Raef Coles9ec67e62020-07-10 09:40:35 +0100225 add_library(${target}_scatter OBJECT)
226 foreach(scatter_file ${ARGN})
227 target_sources(${target}_scatter
228 PRIVATE
229 ${scatter_file}
230 )
231 # Cmake cannot use generator expressions in the
232 # set_source_file_properties command, so instead we just parse the regex
233 # for the filename and set the property on all files, regardless of if
234 # the generator expression would evaluate to true or not.
235 string(REGEX REPLACE ".*>:(.*)>$" "\\1" SCATTER_FILE_PATH "${scatter_file}")
236 set_source_files_properties(${SCATTER_FILE_PATH}
237 PROPERTIES
238 LANGUAGE C
239 )
240 endforeach()
241
Anton Komlev1a103552022-02-11 15:40:26 +0000242 add_dependencies(${target}
243 ${target}_scatter
244 )
245
246 set_target_properties(${target} PROPERTIES LINK_DEPENDS $<TARGET_OBJECTS:${target}_scatter>)
247
Raef Coles9ec67e62020-07-10 09:40:35 +0100248 target_link_libraries(${target}_scatter
249 platform_region_defs
250 psa_interface
251 tfm_partition_defs
252 )
253
254 target_compile_options(${target}_scatter
255 PRIVATE
256 -E
257 -xc
258 )
259endmacro()
260
261macro(add_convert_to_bin_target target)
262 get_target_property(bin_dir ${target} RUNTIME_OUTPUT_DIRECTORY)
263
264 add_custom_target(${target}_bin
265 SOURCES ${bin_dir}/${target}.bin
266 )
267 add_custom_command(OUTPUT ${bin_dir}/${target}.bin
268 DEPENDS ${target}
269 COMMAND fromelf
270 --bincombined $<TARGET_FILE:${target}>
271 --output=${bin_dir}/${target}.bin
272 )
273
274 add_custom_target(${target}_elf
275 SOURCES ${bin_dir}/${target}.elf
276 )
277 add_custom_command(OUTPUT ${bin_dir}/${target}.elf
278 DEPENDS ${target}
279 COMMAND fromelf
280 --elf $<TARGET_FILE:${target}>
281 --output=${bin_dir}/${target}.elf
282 )
283
284 add_custom_target(${target}_hex
285 SOURCES ${bin_dir}/${target}.hex
286 )
287 add_custom_command(OUTPUT ${bin_dir}/${target}.hex
288 DEPENDS ${target}
289 COMMAND fromelf
290 --i32combined $<TARGET_FILE:${target}>
291 --output=${bin_dir}/${target}.hex
292 )
293
294 add_custom_target(${target}_binaries
295 ALL
296 DEPENDS ${target}_bin
297 DEPENDS ${target}_elf
298 DEPENDS ${target}_hex
299 )
300endmacro()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000301
Raef Coles4351ec22021-04-26 09:20:50 +0100302macro(target_share_symbols target symbol_name_file)
303 get_target_property(TARGET_TYPE ${target} TYPE)
304 if (NOT TARGET_TYPE STREQUAL "EXECUTABLE")
305 message(FATAL_ERROR "${target} is not an executable. Symbols cannot be shared from libraries.")
306 endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000307
Raef Coles4351ec22021-04-26 09:20:50 +0100308 FILE(STRINGS ${symbol_name_file} KEEP_SYMBOL_LIST
309 LENGTH_MINIMUM 1
310 )
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000311
Raef Coles4351ec22021-04-26 09:20:50 +0100312 # strip all the symbols except those proveded as arguments. Long inline
313 # python scripts aren't ideal, but this is both portable and possibly easier
314 # to maintain than trying to filter files at build time in cmake.
315 add_custom_command(TARGET ${target}
316 POST_BUILD
317 VERBATIM
318 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 +0000319
Raef Coles4351ec22021-04-26 09:20:50 +0100320 # Force the target to not remove the symbols if they're unused. Not
321 # currently possible on GNU, has to be part of the linker script.
322 list(TRANSFORM KEEP_SYMBOL_LIST PREPEND --keep=)
323 target_link_options(${target}
324 PRIVATE
325 ${KEEP_SYMBOL_LIST}
326 )
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000327
Raef Coles4351ec22021-04-26 09:20:50 +0100328 # Ask armclang to produce a symdefs file that will
329 target_link_options(${target}
330 PRIVATE
331 --symdefs=$<TARGET_FILE_DIR:${target}>/${target}_shared_symbols.txt
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000332 )
333endmacro()
334
Raef Coles4351ec22021-04-26 09:20:50 +0100335macro(target_link_shared_code target)
336 get_target_property(TARGET_SOURCE_DIR ${target} SOURCE_DIR)
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000337
Raef Coles4351ec22021-04-26 09:20:50 +0100338 foreach(symbol_provider ${ARGN})
339 if (TARGET ${symbol_provider})
340 get_target_property(SYMBOL_PROVIDER_TYPE ${symbol_provider} TYPE)
341 if (NOT SYMBOL_PROVIDER_TYPE STREQUAL "EXECUTABLE")
342 message(FATAL_ERROR "${symbol_provider} is not an executable. Symbols cannot be shared from libraries.")
343 endif()
344 endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000345
Raef Coles4351ec22021-04-26 09:20:50 +0100346 add_dependencies(${target} ${symbol_provider})
347 # Some cmake functions don't allow generator expressions, so get the
348 # property as a backup. If the symbol provider hasn't been created yet,
349 # then use the output dir of the target.
350 if (TARGET ${symbol_provider})
351 get_target_property(SYMBOL_PROVIDER_OUTPUT_DIR ${symbol_provider} RUNTIME_OUTPUT_DIRECTORY)
352 else()
353 get_target_property(SYMBOL_PROVIDER_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY)
354 endif()
355 # Set these properties so that cmake will allow us to use a source file
356 # that doesn't exist at cmake-time, but we guarantee will exist at
357 # compile-time.
358 set_source_files_properties(${SYMBOL_PROVIDER_OUTPUT_DIR}/${symbol_provider}_shared_symbols.txt
359 DIRECTORY ${TARGET_SOURCE_DIR}
360 PROPERTIES
361 EXTERNAL_OBJECT true
362 GENERATED true
363 )
364 target_sources(${target}
365 PRIVATE
366 $<TARGET_FILE_DIR:${symbol_provider}>/${symbol_provider}_shared_symbols.txt
367 )
368 endforeach()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000369endmacro()
370
Raef Coles4351ec22021-04-26 09:20:50 +0100371macro(target_strip_symbols target)
372 set(SYMBOL_LIST "${ARGN}")
373 list(TRANSFORM SYMBOL_LIST PREPEND --strip-symbol=)
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000374
Raef Coles4351ec22021-04-26 09:20:50 +0100375 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
376 # armclang this isn't necessarily true.
377 add_custom_command(
378 TARGET ${target}
379 POST_BUILD
380 COMMAND ${CROSS_COMPILE}-objcopy
381 ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
382 )
383endmacro()
384
385macro(target_strip_symbols_from_dependency target dependency)
386 set(SYMBOL_LIST "${ARGN}")
387 list(TRANSFORM SYMBOL_LIST PREPEND --strip-symbol=)
388
389 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
390 # armclang this isn't necessarily true.
391 add_custom_command(
392 TARGET ${target}
393 PRE_LINK
394 COMMAND ${CROSS_COMPILE}-objcopy
395 ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
396 )
397endmacro()
398
399macro(target_weaken_symbols target)
400 set(SYMBOL_LIST "${ARGN}")
401 list(TRANSFORM SYMBOL_LIST PREPEND --weaken-symbol=)
402
403 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
404 # armclang this isn't necessarily true.
405 add_custom_command(
406 TARGET ${target}
407 POST_BUILD
408 COMMAND ${CROSS_COMPILE}-objcopy
409 ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
410 )
411endmacro()
412
413macro(target_weaken_symbols_from_dependency target dependency)
414 set(SYMBOL_LIST "${ARGN}")
415 list(TRANSFORM SYMBOL_LIST PREPEND --weaken-symbol=)
416
417 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
418 # armclang this isn't necessarily true.
419 add_custom_command(
420 TARGET ${target}
421 PRE_LINK
422 COMMAND ${CROSS_COMPILE}-objcopy
423 ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000424 )
425endmacro()