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).
pull/13566/head
Martin Kojtal 2020-10-15 11:07:38 +01:00 committed by Hugues Kamba
parent c82e8c2337
commit d283e69c99
2 changed files with 12 additions and 11 deletions

View File

@ -112,10 +112,9 @@ endfunction()
function(mbed_set_mbed_target_linker_script target)
get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
mbed_generate_gcc_options_for_linker(${target} _linker_preprocess_definitions _linker_preprocess_options)
mbed_generate_gcc_options_for_linker(${target} _linker_preprocess_definitions)
set(CMAKE_PRE_BUILD_COMMAND
COMMAND "arm-none-eabi-cpp" -E -P
${_linker_preprocess_options} ${_linker_preprocess_definitions}
COMMAND "arm-none-eabi-cpp" ${_linker_preprocess_definitions} -x assembler-with-cpp -E -Wp,-P
${mbed_target_linker_script} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}

View File

@ -66,24 +66,26 @@ function(mbed_set_toolchain_options target)
)
endfunction()
# GCC ARM requires preprecessing linker script, execute generators to get definitions needed for
# this step - linker options and compile definitions
function(mbed_generate_gcc_options_for_linker target definitions_file linker_options_file)
# Generate a file containing compile definitions
function(mbed_generate_gcc_options_for_linker target definitions_file)
set(_compile_definitions
"$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>"
)
set(_linker_options
"$<TARGET_PROPERTY:${target},LINK_OPTIONS>"
# Remove macro definitions that contain spaces as the lack of escape sequences and quotation marks
# in the macro when retrieved using generator expressions causes linker errors.
# This includes string macros, array macros, and macros with operations.
# TODO CMake: Add escape sequences and quotation marks where necessary instead of removing these macros.
set(_compile_definitions
"$<FILTER:${_compile_definitions},EXCLUDE, +>"
)
# Append -D to all macros as we pass these as response file to cxx compiler
set(_compile_definitions
"$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions}, -D>>"
)
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n")
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/linker_options.txt" CONTENT "${_linker_options}\n")
set(definitions_file @${CMAKE_BINARY_DIR}/compile_time_defs.txt)
set(linker_options_file @${CMAKE_BINARY_DIR}/linker_options.txt)
set(${definitions_file} @${CMAKE_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)
endfunction()
# Configure the toolchain to select the selected C library