blob: e4086222d6162bf4c0abe2413ec0dbc1ac8d54da [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
David Hu9dd91b52022-04-06 17:00:56 +0800191 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.15 AND
192 CMAKE_C_COMPILER_VERSION VERSION_LESS 6.18)
193 message(WARNING "Armclang 6.15~6.17 may cause MemManage fault."
194 " This defect has been fixed since Armclang 6.18."
195 " See [SDCOMP-59788] in Armclang 6.18 release note for details."
196 " Please use other Armclang versions instead.")
David Hufb4a8b72022-01-13 16:46:02 +0800197 endif()
198
Raef Colesd853fa52020-11-06 14:20:12 +0000199 # Cmake's armclang support will set either mcpu or march, but march gives
200 # better code size so we manually set it.
Gabor Abonyi866571c2021-10-07 13:56:19 +0200201 set(CMAKE_C_FLAGS "-march=${CMAKE_SYSTEM_ARCH}")
Raef Coles9ec67e62020-07-10 09:40:35 +0100202 set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT})
203
Gabor Abonyi866571c2021-10-07 13:56:19 +0200204 if (DEFINED TFM_SYSTEM_PROCESSOR)
205 set(CMAKE_C_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
206 set(CMAKE_ASM_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
207 # But armlink doesn't support this +dsp syntax
208 string(REGEX REPLACE "\\+nodsp" "" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
209 string(REGEX REPLACE "\\+nodsp" "" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
210 # And uses different syntax for +nofp
211 string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
212 string(REGEX REPLACE "\\+nofp" ".no_fp" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
Raef Coles69817322020-10-19 14:14:14 +0100213
Gabor Abonyi866571c2021-10-07 13:56:19 +0200214 string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
215 string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
216 endif()
Raef Coles8db4ddf2020-11-19 09:35:37 +0000217
Raef Coles69817322020-10-19 14:14:14 +0100218 # Workaround for issues with --depend-single-line with armasm and Ninja
219 if (CMAKE_GENERATOR STREQUAL "Ninja")
220 set( CMAKE_DEPFILE_FLAGS_ASM "--depend=<OBJECT>.d")
221 endif()
Raef Colesd29c7f72020-11-05 14:12:06 +0000222
223 set(CMAKE_C_FLAGS_MINSIZEREL "-Oz -DNDEBUG")
Raef Coles9ec67e62020-07-10 09:40:35 +0100224endmacro()
225
Raef Coles69817322020-10-19 14:14:14 +0100226# Configure environment for the compiler setup run by cmake at the first
227# `project` call in <tfm_root>/CMakeLists.txt. After this mandatory setup is
228# done, all further compiler setup is done via tfm_toolchain_reload_compiler()
229tfm_toolchain_set_processor_arch()
230tfm_toolchain_reset_compiler_flags()
231tfm_toolchain_reset_linker_flags()
232
Raef Coles9ec67e62020-07-10 09:40:35 +0100233# Behaviour for handling scatter files is so wildly divergent between compilers
234# that this macro is required.
235macro(target_add_scatter_file target)
236 target_link_options(${target}
237 PRIVATE
238 --scatter=$<TARGET_OBJECTS:${target}_scatter>
239 )
240
Raef Coles9ec67e62020-07-10 09:40:35 +0100241 add_library(${target}_scatter OBJECT)
242 foreach(scatter_file ${ARGN})
243 target_sources(${target}_scatter
244 PRIVATE
245 ${scatter_file}
246 )
247 # Cmake cannot use generator expressions in the
248 # set_source_file_properties command, so instead we just parse the regex
249 # for the filename and set the property on all files, regardless of if
250 # the generator expression would evaluate to true or not.
251 string(REGEX REPLACE ".*>:(.*)>$" "\\1" SCATTER_FILE_PATH "${scatter_file}")
252 set_source_files_properties(${SCATTER_FILE_PATH}
253 PROPERTIES
254 LANGUAGE C
255 )
256 endforeach()
257
Anton Komlev1a103552022-02-11 15:40:26 +0000258 add_dependencies(${target}
259 ${target}_scatter
260 )
261
262 set_target_properties(${target} PROPERTIES LINK_DEPENDS $<TARGET_OBJECTS:${target}_scatter>)
263
Raef Coles9ec67e62020-07-10 09:40:35 +0100264 target_link_libraries(${target}_scatter
265 platform_region_defs
266 psa_interface
267 tfm_partition_defs
268 )
269
270 target_compile_options(${target}_scatter
271 PRIVATE
272 -E
273 -xc
274 )
275endmacro()
276
277macro(add_convert_to_bin_target target)
278 get_target_property(bin_dir ${target} RUNTIME_OUTPUT_DIRECTORY)
279
280 add_custom_target(${target}_bin
281 SOURCES ${bin_dir}/${target}.bin
282 )
283 add_custom_command(OUTPUT ${bin_dir}/${target}.bin
284 DEPENDS ${target}
285 COMMAND fromelf
286 --bincombined $<TARGET_FILE:${target}>
287 --output=${bin_dir}/${target}.bin
288 )
289
290 add_custom_target(${target}_elf
291 SOURCES ${bin_dir}/${target}.elf
292 )
293 add_custom_command(OUTPUT ${bin_dir}/${target}.elf
294 DEPENDS ${target}
295 COMMAND fromelf
296 --elf $<TARGET_FILE:${target}>
297 --output=${bin_dir}/${target}.elf
298 )
299
300 add_custom_target(${target}_hex
301 SOURCES ${bin_dir}/${target}.hex
302 )
303 add_custom_command(OUTPUT ${bin_dir}/${target}.hex
304 DEPENDS ${target}
305 COMMAND fromelf
306 --i32combined $<TARGET_FILE:${target}>
307 --output=${bin_dir}/${target}.hex
308 )
309
310 add_custom_target(${target}_binaries
311 ALL
312 DEPENDS ${target}_bin
313 DEPENDS ${target}_elf
314 DEPENDS ${target}_hex
315 )
316endmacro()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000317
Raef Coles4351ec22021-04-26 09:20:50 +0100318macro(target_share_symbols target symbol_name_file)
319 get_target_property(TARGET_TYPE ${target} TYPE)
320 if (NOT TARGET_TYPE STREQUAL "EXECUTABLE")
321 message(FATAL_ERROR "${target} is not an executable. Symbols cannot be shared from libraries.")
322 endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000323
Raef Coles4351ec22021-04-26 09:20:50 +0100324 FILE(STRINGS ${symbol_name_file} KEEP_SYMBOL_LIST
325 LENGTH_MINIMUM 1
326 )
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000327
Raef Coles4351ec22021-04-26 09:20:50 +0100328 # strip all the symbols except those proveded as arguments. Long inline
329 # python scripts aren't ideal, but this is both portable and possibly easier
330 # to maintain than trying to filter files at build time in cmake.
331 add_custom_command(TARGET ${target}
332 POST_BUILD
333 VERBATIM
334 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 +0000335
Raef Coles4351ec22021-04-26 09:20:50 +0100336 # Force the target to not remove the symbols if they're unused. Not
337 # currently possible on GNU, has to be part of the linker script.
338 list(TRANSFORM KEEP_SYMBOL_LIST PREPEND --keep=)
339 target_link_options(${target}
340 PRIVATE
341 ${KEEP_SYMBOL_LIST}
342 )
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000343
Raef Coles4351ec22021-04-26 09:20:50 +0100344 # Ask armclang to produce a symdefs file that will
345 target_link_options(${target}
346 PRIVATE
347 --symdefs=$<TARGET_FILE_DIR:${target}>/${target}_shared_symbols.txt
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000348 )
349endmacro()
350
Raef Coles4351ec22021-04-26 09:20:50 +0100351macro(target_link_shared_code target)
352 get_target_property(TARGET_SOURCE_DIR ${target} SOURCE_DIR)
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000353
Raef Coles4351ec22021-04-26 09:20:50 +0100354 foreach(symbol_provider ${ARGN})
355 if (TARGET ${symbol_provider})
356 get_target_property(SYMBOL_PROVIDER_TYPE ${symbol_provider} TYPE)
357 if (NOT SYMBOL_PROVIDER_TYPE STREQUAL "EXECUTABLE")
358 message(FATAL_ERROR "${symbol_provider} is not an executable. Symbols cannot be shared from libraries.")
359 endif()
360 endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000361
Raef Coles4351ec22021-04-26 09:20:50 +0100362 add_dependencies(${target} ${symbol_provider})
363 # Some cmake functions don't allow generator expressions, so get the
364 # property as a backup. If the symbol provider hasn't been created yet,
365 # then use the output dir of the target.
366 if (TARGET ${symbol_provider})
367 get_target_property(SYMBOL_PROVIDER_OUTPUT_DIR ${symbol_provider} RUNTIME_OUTPUT_DIRECTORY)
368 else()
369 get_target_property(SYMBOL_PROVIDER_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY)
370 endif()
371 # Set these properties so that cmake will allow us to use a source file
372 # that doesn't exist at cmake-time, but we guarantee will exist at
373 # compile-time.
374 set_source_files_properties(${SYMBOL_PROVIDER_OUTPUT_DIR}/${symbol_provider}_shared_symbols.txt
375 DIRECTORY ${TARGET_SOURCE_DIR}
376 PROPERTIES
377 EXTERNAL_OBJECT true
378 GENERATED true
379 )
380 target_sources(${target}
381 PRIVATE
382 $<TARGET_FILE_DIR:${symbol_provider}>/${symbol_provider}_shared_symbols.txt
383 )
384 endforeach()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000385endmacro()
386
Raef Coles4351ec22021-04-26 09:20:50 +0100387macro(target_strip_symbols target)
388 set(SYMBOL_LIST "${ARGN}")
389 list(TRANSFORM SYMBOL_LIST PREPEND --strip-symbol=)
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000390
Raef Coles4351ec22021-04-26 09:20:50 +0100391 # 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_strip_symbols_from_dependency target dependency)
402 set(SYMBOL_LIST "${ARGN}")
403 list(TRANSFORM SYMBOL_LIST PREPEND --strip-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}>
412 )
413endmacro()
414
415macro(target_weaken_symbols target)
416 set(SYMBOL_LIST "${ARGN}")
417 list(TRANSFORM SYMBOL_LIST PREPEND --weaken-symbol=)
418
419 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
420 # armclang this isn't necessarily true.
421 add_custom_command(
422 TARGET ${target}
423 POST_BUILD
424 COMMAND ${CROSS_COMPILE}-objcopy
425 ARGS $<TARGET_FILE:${target}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${target}>
426 )
427endmacro()
428
429macro(target_weaken_symbols_from_dependency target dependency)
430 set(SYMBOL_LIST "${ARGN}")
431 list(TRANSFORM SYMBOL_LIST PREPEND --weaken-symbol=)
432
433 # TODO we assume that arm-none-eabi-objcopy is available - since we're using
434 # armclang this isn't necessarily true.
435 add_custom_command(
436 TARGET ${target}
437 PRE_LINK
438 COMMAND ${CROSS_COMPILE}-objcopy
439 ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000440 )
441endmacro()