1# 2# Arm SCP/MCP Software 3# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. 4# 5# SPDX-License-Identifier: BSD-3-Clause 6# 7 8include_guard() 9 10include(SCPPreprocessSource) 11 12# .rst: 13# 14# .. command:: scp_target_linker_script 15# 16# Add a linker script to a target. 17# 18# .. cmake:: scp_target_linker_script(<target> <source>) 19# 20# This macro preprocesses a linker script ``<source>`` for the target 21# ``<target>``. The include directories and compile definitions given to the 22# preprocessor are given by the ``INCLUDE_DIRECTORIES` and 23# ``COMPILE_DEFINITIONS`` properties of the target. 24macro(scp_target_linker_script target source) 25 set(subtarget "${target}-lds") 26 set(output "${CMAKE_CURRENT_BINARY_DIR}/${target}.ld") 27 28 scp_preprocess_source(${subtarget} "${source}" "${output}") 29 30 set_target_properties( 31 ${subtarget} 32 PROPERTIES 33 INCLUDE_DIRECTORIES 34 "$<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>" 35 COMPILE_DEFINITIONS 36 "$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>" 37 COMPILE_OPTIONS "$<TARGET_PROPERTY:${target},COMPILE_OPTIONS>") 38 39 # 40 # Add the linker script to the dependencies of the target. 41 # 42 43 add_dependencies(${target} ${subtarget}) 44 45 set_target_properties(${target} 46 PROPERTIES INTERFACE_LINK_DEPENDS "${output}") 47 48 if(CMAKE_C_COMPILER_ID STREQUAL "ARMClang") 49 target_link_options(${target} PUBLIC "LINKER:--scatter" 50 "LINKER:${output}") 51 else() 52 target_link_options(${target} PUBLIC "LINKER:-T" "LINKER:${output}") 53 endif() 54endmacro() 55