blob: e3b604ac17466340016cb607baf9e704483f2df2 [file] [log] [blame]
Kristofer Jonsson43ce4912020-11-20 09:42:53 +01001#
2# Copyright (c) 2020 Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: Apache-2.0
5#
6# Licensed under the Apache License, Version 2.0 (the License); you may
7# not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an AS IS BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19function(ethosu_link_options target scope)
20 cmake_parse_arguments(ARG "" "LINK_FILE" "" ${ARGN})
21
22 if (CMAKE_CXX_COMPILER_ID STREQUAL "ARMClang")
23 set(LINK_FILE_OUT ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_LINK_FILE}.scatter)
24 set(LINK_FILE_OPTION "--scatter")
25
26 elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
27 set(LINK_FILE ${ARG_LINK_FILE}.ld)
28 set(LINK_FILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/${LINK_FILE})
29 set(LINK_FILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/${LINK_FILE})
30 set(LINK_FILE_OPTION "-T")
31
32 set(prop "$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>")
33 add_custom_command(
34 OUTPUT ${LINK_FILE_OUT}
35 DEPENDS ${LINK_FILE_IN}
36 BYPRODUCTS ${LINK_FILE_OUT}
37 COMMAND ${CMAKE_C_COMPILER} -E -x c -P -o ${LINK_FILE_OUT} ${LINK_FILE_IN}
38 COMMAND_EXPAND_LISTS "$<$<BOOL:${prop}>:-D$<JOIN:${prop},;-D>>"
39 COMMENT "Preprocessing and generating linker script"
40 VERBATIM)
41 add_custom_target(${target}-linker-script
42 DEPENDS ${LINK_FILE_OUT}
43 VERBATIM)
44 add_dependencies(${target} ${target}-linker-script)
45 endif()
46
47 target_link_options(${target} ${scope} ${LINK_FILE_OPTION} ${LINK_FILE_OUT})
48 set_target_properties(${target} PROPERTIES LINK_DEPENDS ${LINK_FILE_OUT})
49endfunction()