blob: 5f94c1792164cf078b6262150a007417adee9f30 [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
Gabor Toth4d414112021-11-10 17:44:50 +010089 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")
Gabor Abonyi866571c2021-10-07 13:56:19 +020092 endif()
93
Gabor Abonyi866571c2021-10-07 13:56:19 +020094 if (DEFINED TFM_SYSTEM_DSP)
95 if(NOT TFM_SYSTEM_DSP)
96 string(APPEND CMAKE_SYSTEM_PROCESSOR "+nodsp")
97 endif()
98 endif()
99
100 string(REGEX REPLACE "\\+nodsp" ".no_dsp" CMAKE_ASM_CPU_FLAG "${CMAKE_SYSTEM_PROCESSOR}")
101 else()
102 set(CMAKE_ASM_CPU_FLAG ${TFM_SYSTEM_ARCHITECTURE})
103
104 # Armasm uses different syntax than armclang for architecture targets
105 string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
106 string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
107
108 # Modifiers are additive instead of subtractive (.fp Vs .no_fp)
109 if (TFM_SYSTEM_DSP)
110 string(APPEND CMAKE_ASM_CPU_FLAG ".dsp")
Gabor Abonyi866571c2021-10-07 13:56:19 +0200111 endif()
112 endif()
113
114 # CMAKE_SYSTEM_ARCH is an ARMCLANG CMAKE internal variable, used to set
115 # compile and linker flags up until CMake 3.21 where CMP0123 was introduced:
116 # https://cmake.org/cmake/help/latest/policy/CMP0123.html
117 # This behavior is overwritten by setting CMAKE_C_FLAGS in
118 # tfm_toolchain_reload_compiler.
119 # Another use of this variable is to statisfy a requirement for ARMCLANG to
120 # set either the target CPU or the Architecture. This variable needs to be
121 # set to allow targeting architectures without a specific CPU.
122 set(CMAKE_SYSTEM_ARCH ${TFM_SYSTEM_ARCHITECTURE})
Raef Coles69817322020-10-19 14:14:14 +0100123
124 set(CMAKE_C_COMPILER_TARGET arm-${CROSS_COMPILE})
125 set(CMAKE_ASM_COMPILER_TARGET arm-${CROSS_COMPILE})
Raef Coles9ec67e62020-07-10 09:40:35 +0100126
Gabor Toth4d414112021-11-10 17:44:50 +0100127 # MVE is currently not supported in case of armclang
128 if (TFM_SYSTEM_ARCHITECTURE STREQUAL "armv8.1-m.main")
129 string(APPEND CMAKE_SYSTEM_ARCH "+nomve")
Raef Coles8db4ddf2020-11-19 09:35:37 +0000130 endif()
131
Raef Coles9ec67e62020-07-10 09:40:35 +0100132 if (DEFINED TFM_SYSTEM_DSP)
Raef Coles69817322020-10-19 14:14:14 +0100133 if(NOT TFM_SYSTEM_DSP)
Gabor Abonyi866571c2021-10-07 13:56:19 +0200134 string(APPEND CMAKE_SYSTEM_ARCH "+nodsp")
Raef Coles9ec67e62020-07-10 09:40:35 +0100135 endif()
Raef Coles8db4ddf2020-11-19 09:35:37 +0000136 endif()
Raef Coles69817322020-10-19 14:14:14 +0100137
Raef Colesd853fa52020-11-06 14:20:12 +0000138 # Cmake's ARMClang support has several issues with compiler validation. To
139 # avoid these, we set the list of supported -mcpu and -march variables to
140 # the ones we intend to use so that the validation will never fail.
Raef Coles69817322020-10-19 14:14:14 +0100141 include(Compiler/ARMClang)
Raef Colesd853fa52020-11-06 14:20:12 +0000142 set(CMAKE_C_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
Gabor Abonyi866571c2021-10-07 13:56:19 +0200143 set(CMAKE_C_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
Raef Colesd853fa52020-11-06 14:20:12 +0000144 set(CMAKE_ASM_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
Gabor Abonyi866571c2021-10-07 13:56:19 +0200145 set(CMAKE_ASM_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
Raef Coles69817322020-10-19 14:14:14 +0100146endmacro()
147
148macro(tfm_toolchain_reload_compiler)
149 tfm_toolchain_set_processor_arch()
150 tfm_toolchain_reset_compiler_flags()
151 tfm_toolchain_reset_linker_flags()
Raef Coles9ec67e62020-07-10 09:40:35 +0100152
153 unset(CMAKE_C_FLAGS_INIT)
154 unset(CMAKE_C_LINK_FLAGS)
155 unset(CMAKE_ASM_FLAGS_INIT)
156 unset(CMAKE_ASM_LINK_FLAGS)
Raef Colesfef2e0c2020-10-22 11:42:19 +0100157 unset(__mcpu_flag_set)
158 unset(__march_flag_set)
Raef Coles9ec67e62020-07-10 09:40:35 +0100159
Raef Coles69817322020-10-19 14:14:14 +0100160 include(Compiler/ARMClang)
Raef Coles9ec67e62020-07-10 09:40:35 +0100161 __compiler_armclang(C)
David Hu7075e312021-11-22 18:13:16 +0800162 include(Compiler/ARMCC-ASM)
Raef Coles69817322020-10-19 14:14:14 +0100163 __compiler_armcc(ASM)
Raef Coles9ec67e62020-07-10 09:40:35 +0100164
David Hufb4a8b72022-01-13 16:46:02 +0800165 if (CMAKE_C_COMPILER_VERSION VERSION_LESS 6.10.1)
166 message(FATAL_ERROR "Please select newer Arm compiler version starting from 6.10.1.")
167 endif()
168
David Hu9dd91b52022-04-06 17:00:56 +0800169 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.15 AND
170 CMAKE_C_COMPILER_VERSION VERSION_LESS 6.18)
David Hue5f56682022-04-06 17:17:11 +0800171 message(FATAL_ERROR "Armclang 6.15~6.17 may cause MemManage fault."
172 " This defect has been fixed since Armclang 6.18."
173 " See [SDCOMP-59788] in Armclang 6.18 release note for details."
174 " Please use other Armclang versions instead.")
David Hufb4a8b72022-01-13 16:46:02 +0800175 endif()
176
Raef Coles9ec67e62020-07-10 09:40:35 +0100177 set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT})
178
Gabor Abonyi866571c2021-10-07 13:56:19 +0200179 if (DEFINED TFM_SYSTEM_PROCESSOR)
Dávid Házie50f0a92022-07-06 14:46:01 +0200180 set(CMAKE_C_FLAGS "-mcpu=${CMAKE_SYSTEM_PROCESSOR}")
Gabor Abonyi866571c2021-10-07 13:56:19 +0200181 set(CMAKE_C_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
182 set(CMAKE_ASM_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
183 # But armlink doesn't support this +dsp syntax
184 string(REGEX REPLACE "\\+nodsp" "" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
185 string(REGEX REPLACE "\\+nodsp" "" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
186 # And uses different syntax for +nofp
187 string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
188 string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
Raef Coles69817322020-10-19 14:14:14 +0100189
Gabor Abonyi866571c2021-10-07 13:56:19 +0200190 string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
191 string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
Dávid Házie50f0a92022-07-06 14:46:01 +0200192 else()
193 set(CMAKE_C_FLAGS "-march=${CMAKE_SYSTEM_ARCH}")
Gabor Abonyi866571c2021-10-07 13:56:19 +0200194 endif()
Raef Coles8db4ddf2020-11-19 09:35:37 +0000195
Raef Coles69817322020-10-19 14:14:14 +0100196 # Workaround for issues with --depend-single-line with armasm and Ninja
197 if (CMAKE_GENERATOR STREQUAL "Ninja")
198 set( CMAKE_DEPFILE_FLAGS_ASM "--depend=<OBJECT>.d")
199 endif()
Raef Colesd29c7f72020-11-05 14:12:06 +0000200
201 set(CMAKE_C_FLAGS_MINSIZEREL "-Oz -DNDEBUG")
Raef Coles9ec67e62020-07-10 09:40:35 +0100202endmacro()
203
Raef Coles69817322020-10-19 14:14:14 +0100204# Configure environment for the compiler setup run by cmake at the first
205# `project` call in <tfm_root>/CMakeLists.txt. After this mandatory setup is
206# done, all further compiler setup is done via tfm_toolchain_reload_compiler()
207tfm_toolchain_set_processor_arch()
208tfm_toolchain_reset_compiler_flags()
209tfm_toolchain_reset_linker_flags()
210
Raef Coles9ec67e62020-07-10 09:40:35 +0100211# Behaviour for handling scatter files is so wildly divergent between compilers
212# that this macro is required.
213macro(target_add_scatter_file target)
214 target_link_options(${target}
215 PRIVATE
216 --scatter=$<TARGET_OBJECTS:${target}_scatter>
217 )
218
Raef Coles9ec67e62020-07-10 09:40:35 +0100219 add_library(${target}_scatter OBJECT)
220 foreach(scatter_file ${ARGN})
221 target_sources(${target}_scatter
222 PRIVATE
223 ${scatter_file}
224 )
225 # Cmake cannot use generator expressions in the
226 # set_source_file_properties command, so instead we just parse the regex
227 # for the filename and set the property on all files, regardless of if
228 # the generator expression would evaluate to true or not.
229 string(REGEX REPLACE ".*>:(.*)>$" "\\1" SCATTER_FILE_PATH "${scatter_file}")
230 set_source_files_properties(${SCATTER_FILE_PATH}
231 PROPERTIES
232 LANGUAGE C
233 )
234 endforeach()
235
Anton Komlev1a103552022-02-11 15:40:26 +0000236 add_dependencies(${target}
237 ${target}_scatter
238 )
239
240 set_target_properties(${target} PROPERTIES LINK_DEPENDS $<TARGET_OBJECTS:${target}_scatter>)
241
Raef Coles9ec67e62020-07-10 09:40:35 +0100242 target_link_libraries(${target}_scatter
243 platform_region_defs
244 psa_interface
245 tfm_partition_defs
246 )
247
248 target_compile_options(${target}_scatter
249 PRIVATE
250 -E
251 -xc
252 )
253endmacro()
254
255macro(add_convert_to_bin_target target)
256 get_target_property(bin_dir ${target} RUNTIME_OUTPUT_DIRECTORY)
257
258 add_custom_target(${target}_bin
259 SOURCES ${bin_dir}/${target}.bin
260 )
261 add_custom_command(OUTPUT ${bin_dir}/${target}.bin
262 DEPENDS ${target}
263 COMMAND fromelf
264 --bincombined $<TARGET_FILE:${target}>
265 --output=${bin_dir}/${target}.bin
266 )
267
268 add_custom_target(${target}_elf
269 SOURCES ${bin_dir}/${target}.elf
270 )
271 add_custom_command(OUTPUT ${bin_dir}/${target}.elf
272 DEPENDS ${target}
273 COMMAND fromelf
274 --elf $<TARGET_FILE:${target}>
275 --output=${bin_dir}/${target}.elf
276 )
277
278 add_custom_target(${target}_hex
279 SOURCES ${bin_dir}/${target}.hex
280 )
281 add_custom_command(OUTPUT ${bin_dir}/${target}.hex
282 DEPENDS ${target}
283 COMMAND fromelf
284 --i32combined $<TARGET_FILE:${target}>
285 --output=${bin_dir}/${target}.hex
286 )
287
288 add_custom_target(${target}_binaries
289 ALL
290 DEPENDS ${target}_bin
291 DEPENDS ${target}_elf
292 DEPENDS ${target}_hex
293 )
294endmacro()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000295
Raef Coles4351ec22021-04-26 09:20:50 +0100296macro(target_share_symbols target symbol_name_file)
297 get_target_property(TARGET_TYPE ${target} TYPE)
298 if (NOT TARGET_TYPE STREQUAL "EXECUTABLE")
299 message(FATAL_ERROR "${target} is not an executable. Symbols cannot be shared from libraries.")
300 endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000301
Raef Coles4351ec22021-04-26 09:20:50 +0100302 FILE(STRINGS ${symbol_name_file} KEEP_SYMBOL_LIST
303 LENGTH_MINIMUM 1
304 )
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000305
Raef Coles4351ec22021-04-26 09:20:50 +0100306 # strip all the symbols except those proveded as arguments. Long inline
307 # python scripts aren't ideal, but this is both portable and possibly easier
308 # to maintain than trying to filter files at build time in cmake.
309 add_custom_command(TARGET ${target}
310 POST_BUILD
311 VERBATIM
312 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 +0000313
Raef Coles4351ec22021-04-26 09:20:50 +0100314 # Force the target to not remove the symbols if they're unused. Not
315 # currently possible on GNU, has to be part of the linker script.
316 list(TRANSFORM KEEP_SYMBOL_LIST PREPEND --keep=)
317 target_link_options(${target}
318 PRIVATE
319 ${KEEP_SYMBOL_LIST}
320 )
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000321
Raef Coles4351ec22021-04-26 09:20:50 +0100322 # Ask armclang to produce a symdefs file that will
323 target_link_options(${target}
324 PRIVATE
325 --symdefs=$<TARGET_FILE_DIR:${target}>/${target}_shared_symbols.txt
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000326 )
327endmacro()
328
Raef Coles4351ec22021-04-26 09:20:50 +0100329macro(target_link_shared_code target)
330 get_target_property(TARGET_SOURCE_DIR ${target} SOURCE_DIR)
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000331
Raef Coles4351ec22021-04-26 09:20:50 +0100332 foreach(symbol_provider ${ARGN})
333 if (TARGET ${symbol_provider})
334 get_target_property(SYMBOL_PROVIDER_TYPE ${symbol_provider} TYPE)
335 if (NOT SYMBOL_PROVIDER_TYPE STREQUAL "EXECUTABLE")
336 message(FATAL_ERROR "${symbol_provider} is not an executable. Symbols cannot be shared from libraries.")
337 endif()
338 endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000339
Raef Coles4351ec22021-04-26 09:20:50 +0100340 add_dependencies(${target} ${symbol_provider})
341 # Some cmake functions don't allow generator expressions, so get the
342 # property as a backup. If the symbol provider hasn't been created yet,
343 # then use the output dir of the target.
344 if (TARGET ${symbol_provider})
345 get_target_property(SYMBOL_PROVIDER_OUTPUT_DIR ${symbol_provider} RUNTIME_OUTPUT_DIRECTORY)
346 else()
347 get_target_property(SYMBOL_PROVIDER_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY)
348 endif()
349 # Set these properties so that cmake will allow us to use a source file
350 # that doesn't exist at cmake-time, but we guarantee will exist at
351 # compile-time.
352 set_source_files_properties(${SYMBOL_PROVIDER_OUTPUT_DIR}/${symbol_provider}_shared_symbols.txt
353 DIRECTORY ${TARGET_SOURCE_DIR}
354 PROPERTIES
355 EXTERNAL_OBJECT true
356 GENERATED true
357 )
358 target_sources(${target}
359 PRIVATE
360 $<TARGET_FILE_DIR:${symbol_provider}>/${symbol_provider}_shared_symbols.txt
361 )
362 endforeach()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000363endmacro()
364
Raef Coles4351ec22021-04-26 09:20:50 +0100365macro(target_strip_symbols target)
366 set(SYMBOL_LIST "${ARGN}")
367 list(TRANSFORM SYMBOL_LIST PREPEND --strip-symbol=)
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000368
Raef Coles4351ec22021-04-26 09:20:50 +0100369 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
370 # armclang this isn't necessarily true.
371 add_custom_command(
372 TARGET ${target}
373 POST_BUILD
374 COMMAND ${CROSS_COMPILE}-objcopy
375 ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
376 )
377endmacro()
378
379macro(target_strip_symbols_from_dependency target dependency)
380 set(SYMBOL_LIST "${ARGN}")
381 list(TRANSFORM SYMBOL_LIST PREPEND --strip-symbol=)
382
383 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
384 # armclang this isn't necessarily true.
385 add_custom_command(
386 TARGET ${target}
387 PRE_LINK
388 COMMAND ${CROSS_COMPILE}-objcopy
389 ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
390 )
391endmacro()
392
393macro(target_weaken_symbols target)
394 set(SYMBOL_LIST "${ARGN}")
395 list(TRANSFORM SYMBOL_LIST PREPEND --weaken-symbol=)
396
397 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
398 # armclang this isn't necessarily true.
399 add_custom_command(
400 TARGET ${target}
401 POST_BUILD
402 COMMAND ${CROSS_COMPILE}-objcopy
403 ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
404 )
405endmacro()
406
407macro(target_weaken_symbols_from_dependency target dependency)
408 set(SYMBOL_LIST "${ARGN}")
409 list(TRANSFORM SYMBOL_LIST PREPEND --weaken-symbol=)
410
411 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
412 # armclang this isn't necessarily true.
413 add_custom_command(
414 TARGET ${target}
415 PRE_LINK
416 COMMAND ${CROSS_COMPILE}-objcopy
417 ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000418 )
419endmacro()