Skip to content

Commit d283e69

Browse files
0xc0170hugueskamba
authored andcommitted
CMake: fix for Gcc Arm preprocessing linker file
A linker script needs symbols (stack size, app size, etc). They are basic values or defines. Not any array like or string like macros. We should filter these, as they are not valid anyway. The other option to fix this would be to fix all the macros but I dont think it is needed as these config values won't be used in the linker script anyway. Not allowed in ld files macros with spaces, like MACRO={0, 2, 3} or MACRO=(4 * 2000).
1 parent c82e8c2 commit d283e69

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ endfunction()
112112
function(mbed_set_mbed_target_linker_script target)
113113
get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
114114
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
115-
mbed_generate_gcc_options_for_linker(${target} _linker_preprocess_definitions _linker_preprocess_options)
115+
mbed_generate_gcc_options_for_linker(${target} _linker_preprocess_definitions)
116116
set(CMAKE_PRE_BUILD_COMMAND
117-
COMMAND "arm-none-eabi-cpp" -E -P
118-
${_linker_preprocess_options} ${_linker_preprocess_definitions}
117+
COMMAND "arm-none-eabi-cpp" ${_linker_preprocess_definitions} -x assembler-with-cpp -E -Wp,-P
119118
${mbed_target_linker_script} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld
120119

121120
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}

tools/cmake/toolchains/GCC_ARM.cmake

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,26 @@ function(mbed_set_toolchain_options target)
6666
)
6767
endfunction()
6868

69-
# GCC ARM requires preprecessing linker script, execute generators to get definitions needed for
70-
# this step - linker options and compile definitions
71-
function(mbed_generate_gcc_options_for_linker target definitions_file linker_options_file)
69+
# Generate a file containing compile definitions
70+
function(mbed_generate_gcc_options_for_linker target definitions_file)
7271
set(_compile_definitions
7372
"$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>"
7473
)
7574

76-
set(_linker_options
77-
"$<TARGET_PROPERTY:${target},LINK_OPTIONS>"
75+
# Remove macro definitions that contain spaces as the lack of escape sequences and quotation marks
76+
# in the macro when retrieved using generator expressions causes linker errors.
77+
# This includes string macros, array macros, and macros with operations.
78+
# TODO CMake: Add escape sequences and quotation marks where necessary instead of removing these macros.
79+
set(_compile_definitions
80+
"$<FILTER:${_compile_definitions},EXCLUDE, +>"
7881
)
7982

83+
# Append -D to all macros as we pass these as response file to cxx compiler
8084
set(_compile_definitions
8185
"$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions}, -D>>"
8286
)
8387
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n")
84-
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/linker_options.txt" CONTENT "${_linker_options}\n")
85-
set(definitions_file @${CMAKE_BINARY_DIR}/compile_time_defs.txt)
86-
set(linker_options_file @${CMAKE_BINARY_DIR}/linker_options.txt)
88+
set(${definitions_file} @${CMAKE_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)
8789
endfunction()
8890

8991
# Configure the toolchain to select the selected C library

0 commit comments

Comments
 (0)