blob: b6e3e3a2d14664b9479f5e0cab3585f7261ef1ee [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>
48 $<$<AND:$<COMPILE_LANGUAGE:C>,$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>>:-mfpu=none>
49 $<$<AND:$<COMPILE_LANGUAGE:ASM>,$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>>:--fpu=none>
50 $<$<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
Raef Coles9ec67e62020-07-10 09:40:35 +010081 $<$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>:--fpu=softvfp>
82 )
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
95 if (DEFINED TFM_SYSTEM_FP)
96 if(NOT TFM_SYSTEM_FP)
97 string(APPEND CMAKE_SYSTEM_PROCESSOR "+nofp")
98 endif()
99 endif()
100
101 if (DEFINED TFM_SYSTEM_DSP)
102 if(NOT TFM_SYSTEM_DSP)
103 string(APPEND CMAKE_SYSTEM_PROCESSOR "+nodsp")
104 endif()
105 endif()
106
107 string(REGEX REPLACE "\\+nodsp" ".no_dsp" CMAKE_ASM_CPU_FLAG "${CMAKE_SYSTEM_PROCESSOR}")
108 else()
109 set(CMAKE_ASM_CPU_FLAG ${TFM_SYSTEM_ARCHITECTURE})
110
111 # Armasm uses different syntax than armclang for architecture targets
112 string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
113 string(REGEX REPLACE "\\armv" "" CMAKE_ASM_CPU_FLAG "${CMAKE_ASM_CPU_FLAG}")
114
115 # Modifiers are additive instead of subtractive (.fp Vs .no_fp)
116 if (TFM_SYSTEM_DSP)
117 string(APPEND CMAKE_ASM_CPU_FLAG ".dsp")
118 else()
119 if (TFM_SYSTEM_MVE)
120 string(APPEND CMAKE_ASM_CPU_FLAG ".mve")
121 endif()
122
123 if (TFM_SYSTEM_FP)
124 string(APPEND CMAKE_ASM_CPU_FLAG ".fp")
125 endif()
126 endif()
127 endif()
128
129 # CMAKE_SYSTEM_ARCH is an ARMCLANG CMAKE internal variable, used to set
130 # compile and linker flags up until CMake 3.21 where CMP0123 was introduced:
131 # https://cmake.org/cmake/help/latest/policy/CMP0123.html
132 # This behavior is overwritten by setting CMAKE_C_FLAGS in
133 # tfm_toolchain_reload_compiler.
134 # Another use of this variable is to statisfy a requirement for ARMCLANG to
135 # set either the target CPU or the Architecture. This variable needs to be
136 # set to allow targeting architectures without a specific CPU.
137 set(CMAKE_SYSTEM_ARCH ${TFM_SYSTEM_ARCHITECTURE})
Raef Coles69817322020-10-19 14:14:14 +0100138
139 set(CMAKE_C_COMPILER_TARGET arm-${CROSS_COMPILE})
140 set(CMAKE_ASM_COMPILER_TARGET arm-${CROSS_COMPILE})
Raef Coles9ec67e62020-07-10 09:40:35 +0100141
Raef Coles8db4ddf2020-11-19 09:35:37 +0000142 if (DEFINED TFM_SYSTEM_MVE)
143 if(NOT TFM_SYSTEM_MVE)
Gabor Abonyi866571c2021-10-07 13:56:19 +0200144 string(APPEND CMAKE_SYSTEM_ARCH "+nomve")
Raef Coles8db4ddf2020-11-19 09:35:37 +0000145 endif()
146 endif()
147
148 if (DEFINED TFM_SYSTEM_FP)
149 if(NOT TFM_SYSTEM_FP)
Gabor Abonyi866571c2021-10-07 13:56:19 +0200150 string(APPEND CMAKE_SYSTEM_ARCH "+nofp")
Raef Coles8db4ddf2020-11-19 09:35:37 +0000151 endif()
152 endif()
153
Raef Coles9ec67e62020-07-10 09:40:35 +0100154 if (DEFINED TFM_SYSTEM_DSP)
Raef Coles69817322020-10-19 14:14:14 +0100155 if(NOT TFM_SYSTEM_DSP)
Gabor Abonyi866571c2021-10-07 13:56:19 +0200156 string(APPEND CMAKE_SYSTEM_ARCH "+nodsp")
Raef Coles9ec67e62020-07-10 09:40:35 +0100157 endif()
Raef Coles8db4ddf2020-11-19 09:35:37 +0000158 endif()
Raef Coles69817322020-10-19 14:14:14 +0100159
Raef Colesd853fa52020-11-06 14:20:12 +0000160 # Cmake's ARMClang support has several issues with compiler validation. To
161 # avoid these, we set the list of supported -mcpu and -march variables to
162 # the ones we intend to use so that the validation will never fail.
Raef Coles69817322020-10-19 14:14:14 +0100163 include(Compiler/ARMClang)
Raef Colesd853fa52020-11-06 14:20:12 +0000164 set(CMAKE_C_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
Gabor Abonyi866571c2021-10-07 13:56:19 +0200165 set(CMAKE_C_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
Raef Colesd853fa52020-11-06 14:20:12 +0000166 set(CMAKE_ASM_COMPILER_PROCESSOR_LIST ${CMAKE_SYSTEM_PROCESSOR})
Gabor Abonyi866571c2021-10-07 13:56:19 +0200167 set(CMAKE_ASM_COMPILER_ARCH_LIST ${CMAKE_SYSTEM_ARCH})
Raef Coles69817322020-10-19 14:14:14 +0100168endmacro()
169
170macro(tfm_toolchain_reload_compiler)
171 tfm_toolchain_set_processor_arch()
172 tfm_toolchain_reset_compiler_flags()
173 tfm_toolchain_reset_linker_flags()
Raef Coles9ec67e62020-07-10 09:40:35 +0100174
175 unset(CMAKE_C_FLAGS_INIT)
176 unset(CMAKE_C_LINK_FLAGS)
177 unset(CMAKE_ASM_FLAGS_INIT)
178 unset(CMAKE_ASM_LINK_FLAGS)
Raef Colesfef2e0c2020-10-22 11:42:19 +0100179 unset(__mcpu_flag_set)
180 unset(__march_flag_set)
Raef Coles9ec67e62020-07-10 09:40:35 +0100181
Raef Coles69817322020-10-19 14:14:14 +0100182 include(Compiler/ARMClang)
Raef Coles9ec67e62020-07-10 09:40:35 +0100183 __compiler_armclang(C)
David Hu7075e312021-11-22 18:13:16 +0800184 include(Compiler/ARMCC-ASM)
Raef Coles69817322020-10-19 14:14:14 +0100185 __compiler_armcc(ASM)
Raef Coles9ec67e62020-07-10 09:40:35 +0100186
David Hufb4a8b72022-01-13 16:46:02 +0800187 if (CMAKE_C_COMPILER_VERSION VERSION_LESS 6.10.1)
188 message(FATAL_ERROR "Please select newer Arm compiler version starting from 6.10.1.")
189 endif()
190
191 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.15)
Lingkai Donga1352282022-02-21 12:10:29 +0000192 message(WARNING "Armclang starting from v6.15 may cause MemManage fault."
David Hufb4a8b72022-01-13 16:46:02 +0800193 " The root cause is still under analysis by Armclang."
194 " Please use lower Armclang versions instead.")
195 endif()
196
Raef Colesd853fa52020-11-06 14:20:12 +0000197 # Cmake's armclang support will set either mcpu or march, but march gives
198 # better code size so we manually set it.
Gabor Abonyi866571c2021-10-07 13:56:19 +0200199 set(CMAKE_C_FLAGS "-march=${CMAKE_SYSTEM_ARCH}")
Raef Coles9ec67e62020-07-10 09:40:35 +0100200 set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT})
201
Gabor Abonyi866571c2021-10-07 13:56:19 +0200202 if (DEFINED TFM_SYSTEM_PROCESSOR)
203 set(CMAKE_C_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
204 set(CMAKE_ASM_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
205 # But armlink doesn't support this +dsp syntax
206 string(REGEX REPLACE "\\+nodsp" "" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
207 string(REGEX REPLACE "\\+nodsp" "" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
208 # And uses different syntax for +nofp
209 string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
210 string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
Raef Coles69817322020-10-19 14:14:14 +0100211
Gabor Abonyi866571c2021-10-07 13:56:19 +0200212 string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
213 string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
214 endif()
Raef Coles8db4ddf2020-11-19 09:35:37 +0000215
Raef Coles69817322020-10-19 14:14:14 +0100216 # Workaround for issues with --depend-single-line with armasm and Ninja
217 if (CMAKE_GENERATOR STREQUAL "Ninja")
218 set( CMAKE_DEPFILE_FLAGS_ASM "--depend=<OBJECT>.d")
219 endif()
Raef Colesd29c7f72020-11-05 14:12:06 +0000220
221 set(CMAKE_C_FLAGS_MINSIZEREL "-Oz -DNDEBUG")
Raef Coles9ec67e62020-07-10 09:40:35 +0100222endmacro()
223
Raef Coles69817322020-10-19 14:14:14 +0100224# Configure environment for the compiler setup run by cmake at the first
225# `project` call in <tfm_root>/CMakeLists.txt. After this mandatory setup is
226# done, all further compiler setup is done via tfm_toolchain_reload_compiler()
227tfm_toolchain_set_processor_arch()
228tfm_toolchain_reset_compiler_flags()
229tfm_toolchain_reset_linker_flags()
230
Raef Coles9ec67e62020-07-10 09:40:35 +0100231# Behaviour for handling scatter files is so wildly divergent between compilers
232# that this macro is required.
233macro(target_add_scatter_file target)
234 target_link_options(${target}
235 PRIVATE
236 --scatter=$<TARGET_OBJECTS:${target}_scatter>
237 )
238
Raef Coles9ec67e62020-07-10 09:40:35 +0100239 add_library(${target}_scatter OBJECT)
240 foreach(scatter_file ${ARGN})
241 target_sources(${target}_scatter
242 PRIVATE
243 ${scatter_file}
244 )
245 # Cmake cannot use generator expressions in the
246 # set_source_file_properties command, so instead we just parse the regex
247 # for the filename and set the property on all files, regardless of if
248 # the generator expression would evaluate to true or not.
249 string(REGEX REPLACE ".*>:(.*)>$" "\\1" SCATTER_FILE_PATH "${scatter_file}")
250 set_source_files_properties(${SCATTER_FILE_PATH}
251 PROPERTIES
252 LANGUAGE C
253 )
254 endforeach()
255
Anton Komlev1a103552022-02-11 15:40:26 +0000256 add_dependencies(${target}
257 ${target}_scatter
258 )
259
260 set_target_properties(${target} PROPERTIES LINK_DEPENDS $<TARGET_OBJECTS:${target}_scatter>)
261
Raef Coles9ec67e62020-07-10 09:40:35 +0100262 target_link_libraries(${target}_scatter
263 platform_region_defs
264 psa_interface
265 tfm_partition_defs
266 )
267
268 target_compile_options(${target}_scatter
269 PRIVATE
270 -E
271 -xc
272 )
273endmacro()
274
275macro(add_convert_to_bin_target target)
276 get_target_property(bin_dir ${target} RUNTIME_OUTPUT_DIRECTORY)
277
278 add_custom_target(${target}_bin
279 SOURCES ${bin_dir}/${target}.bin
280 )
281 add_custom_command(OUTPUT ${bin_dir}/${target}.bin
282 DEPENDS ${target}
283 COMMAND fromelf
284 --bincombined $<TARGET_FILE:${target}>
285 --output=${bin_dir}/${target}.bin
286 )
287
288 add_custom_target(${target}_elf
289 SOURCES ${bin_dir}/${target}.elf
290 )
291 add_custom_command(OUTPUT ${bin_dir}/${target}.elf
292 DEPENDS ${target}
293 COMMAND fromelf
294 --elf $<TARGET_FILE:${target}>
295 --output=${bin_dir}/${target}.elf
296 )
297
298 add_custom_target(${target}_hex
299 SOURCES ${bin_dir}/${target}.hex
300 )
301 add_custom_command(OUTPUT ${bin_dir}/${target}.hex
302 DEPENDS ${target}
303 COMMAND fromelf
304 --i32combined $<TARGET_FILE:${target}>
305 --output=${bin_dir}/${target}.hex
306 )
307
308 add_custom_target(${target}_binaries
309 ALL
310 DEPENDS ${target}_bin
311 DEPENDS ${target}_elf
312 DEPENDS ${target}_hex
313 )
314endmacro()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000315
Raef Coles4351ec22021-04-26 09:20:50 +0100316macro(target_share_symbols target symbol_name_file)
317 get_target_property(TARGET_TYPE ${target} TYPE)
318 if (NOT TARGET_TYPE STREQUAL "EXECUTABLE")
319 message(FATAL_ERROR "${target} is not an executable. Symbols cannot be shared from libraries.")
320 endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000321
Raef Coles4351ec22021-04-26 09:20:50 +0100322 FILE(STRINGS ${symbol_name_file} KEEP_SYMBOL_LIST
323 LENGTH_MINIMUM 1
324 )
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000325
Raef Coles4351ec22021-04-26 09:20:50 +0100326 # strip all the symbols except those proveded as arguments. Long inline
327 # python scripts aren't ideal, but this is both portable and possibly easier
328 # to maintain than trying to filter files at build time in cmake.
329 add_custom_command(TARGET ${target}
330 POST_BUILD
331 VERBATIM
332 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 +0000333
Raef Coles4351ec22021-04-26 09:20:50 +0100334 # Force the target to not remove the symbols if they're unused. Not
335 # currently possible on GNU, has to be part of the linker script.
336 list(TRANSFORM KEEP_SYMBOL_LIST PREPEND --keep=)
337 target_link_options(${target}
338 PRIVATE
339 ${KEEP_SYMBOL_LIST}
340 )
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000341
Raef Coles4351ec22021-04-26 09:20:50 +0100342 # Ask armclang to produce a symdefs file that will
343 target_link_options(${target}
344 PRIVATE
345 --symdefs=$<TARGET_FILE_DIR:${target}>/${target}_shared_symbols.txt
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000346 )
347endmacro()
348
Raef Coles4351ec22021-04-26 09:20:50 +0100349macro(target_link_shared_code target)
350 get_target_property(TARGET_SOURCE_DIR ${target} SOURCE_DIR)
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000351
Raef Coles4351ec22021-04-26 09:20:50 +0100352 foreach(symbol_provider ${ARGN})
353 if (TARGET ${symbol_provider})
354 get_target_property(SYMBOL_PROVIDER_TYPE ${symbol_provider} TYPE)
355 if (NOT SYMBOL_PROVIDER_TYPE STREQUAL "EXECUTABLE")
356 message(FATAL_ERROR "${symbol_provider} is not an executable. Symbols cannot be shared from libraries.")
357 endif()
358 endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000359
Raef Coles4351ec22021-04-26 09:20:50 +0100360 add_dependencies(${target} ${symbol_provider})
361 # Some cmake functions don't allow generator expressions, so get the
362 # property as a backup. If the symbol provider hasn't been created yet,
363 # then use the output dir of the target.
364 if (TARGET ${symbol_provider})
365 get_target_property(SYMBOL_PROVIDER_OUTPUT_DIR ${symbol_provider} RUNTIME_OUTPUT_DIRECTORY)
366 else()
367 get_target_property(SYMBOL_PROVIDER_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY)
368 endif()
369 # Set these properties so that cmake will allow us to use a source file
370 # that doesn't exist at cmake-time, but we guarantee will exist at
371 # compile-time.
372 set_source_files_properties(${SYMBOL_PROVIDER_OUTPUT_DIR}/${symbol_provider}_shared_symbols.txt
373 DIRECTORY ${TARGET_SOURCE_DIR}
374 PROPERTIES
375 EXTERNAL_OBJECT true
376 GENERATED true
377 )
378 target_sources(${target}
379 PRIVATE
380 $<TARGET_FILE_DIR:${symbol_provider}>/${symbol_provider}_shared_symbols.txt
381 )
382 endforeach()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000383endmacro()
384
Raef Coles4351ec22021-04-26 09:20:50 +0100385macro(target_strip_symbols target)
386 set(SYMBOL_LIST "${ARGN}")
387 list(TRANSFORM SYMBOL_LIST PREPEND --strip-symbol=)
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000388
Raef Coles4351ec22021-04-26 09:20:50 +0100389 # 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 POST_BUILD
394 COMMAND ${CROSS_COMPILE}-objcopy
395 ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
396 )
397endmacro()
398
399macro(target_strip_symbols_from_dependency target dependency)
400 set(SYMBOL_LIST "${ARGN}")
401 list(TRANSFORM SYMBOL_LIST PREPEND --strip-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 PRE_LINK
408 COMMAND ${CROSS_COMPILE}-objcopy
409 ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
410 )
411endmacro()
412
413macro(target_weaken_symbols target)
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 POST_BUILD
422 COMMAND ${CROSS_COMPILE}-objcopy
423 ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
424 )
425endmacro()
426
427macro(target_weaken_symbols_from_dependency target dependency)
428 set(SYMBOL_LIST "${ARGN}")
429 list(TRANSFORM SYMBOL_LIST PREPEND --weaken-symbol=)
430
431 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
432 # armclang this isn't necessarily true.
433 add_custom_command(
434 TARGET ${target}
435 PRE_LINK
436 COMMAND ${CROSS_COMPILE}-objcopy
437 ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000438 )
439endmacro()