Skip to content

Commit 214291b

Browse files
authored
Merge pull request ARMmbed#13930 from LDong-Arm/arm_compiler_macros
CMake: pass macros to ARM toolchain linker
2 parents 5026287 + 9bf6aff commit 214291b

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ endfunction()
132132
#
133133
function(mbed_set_mbed_target_linker_script target)
134134
get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
135+
mbed_generate_options_for_linker(${target} _linker_preprocess_definitions)
135136
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
136-
mbed_generate_gcc_options_for_linker(${target} _linker_preprocess_definitions)
137137
set(CMAKE_PRE_BUILD_COMMAND
138138
COMMAND "arm-none-eabi-cpp" ${_linker_preprocess_definitions} -x assembler-with-cpp -E -Wp,-P
139139
${mbed_target_linker_script} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld
@@ -146,6 +146,7 @@ function(mbed_set_mbed_target_linker_script target)
146146
target_link_options(mbed-core
147147
INTERFACE
148148
"--scatter=${mbed_target_linker_script}"
149+
"--predefine=${_linker_preprocess_definitions}"
149150
)
150151
endif()
151152
add_custom_command(

tools/cmake/toolchain.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
# Generate a file containing compile definitions
5+
function(mbed_generate_options_for_linker target definitions_file)
6+
set(_compile_definitions
7+
"$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>"
8+
)
9+
10+
# Remove macro definitions that contain spaces as the lack of escape sequences and quotation marks
11+
# in the macro when retrieved using generator expressions causes linker errors.
12+
# This includes string macros, array macros, and macros with operations.
13+
# TODO CMake: Add escape sequences and quotation marks where necessary instead of removing these macros.
14+
set(_compile_definitions
15+
"$<FILTER:${_compile_definitions},EXCLUDE, +>"
16+
)
17+
18+
# Append -D to all macros as we pass these as response file to cxx compiler
19+
set(_compile_definitions
20+
"$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions}, -D>>"
21+
)
22+
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n")
23+
set(${definitions_file} @${CMAKE_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)
24+
endfunction()
425
# Set the system processor depending on the CPU core type
526
if (MBED_CPU_CORE STREQUAL Cortex-A9)
627
set(CMAKE_SYSTEM_PROCESSOR cortex-a9)

tools/cmake/toolchains/GCC_ARM.cmake

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,6 @@ function(mbed_set_toolchain_options target)
5858
)
5959
endfunction()
6060

61-
# Generate a file containing compile definitions
62-
function(mbed_generate_gcc_options_for_linker target definitions_file)
63-
set(_compile_definitions
64-
"$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>"
65-
)
66-
67-
# Remove macro definitions that contain spaces as the lack of escape sequences and quotation marks
68-
# in the macro when retrieved using generator expressions causes linker errors.
69-
# This includes string macros, array macros, and macros with operations.
70-
# TODO CMake: Add escape sequences and quotation marks where necessary instead of removing these macros.
71-
set(_compile_definitions
72-
"$<FILTER:${_compile_definitions},EXCLUDE, +>"
73-
)
74-
75-
# Append -D to all macros as we pass these as response file to cxx compiler
76-
set(_compile_definitions
77-
"$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions}, -D>>"
78-
)
79-
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n")
80-
set(${definitions_file} @${CMAKE_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)
81-
endfunction()
82-
8361
# Configure the toolchain to select the selected C library
8462
function(mbed_set_c_lib target lib_type)
8563
if (${lib_type} STREQUAL "small")

0 commit comments

Comments
 (0)