From d283e69c9941953b1ce22a0b02ad4729c1c70a45 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Thu, 15 Oct 2020 11:07:38 +0100 Subject: [PATCH] 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). --- CMakeLists.txt | 5 ++--- tools/cmake/toolchains/GCC_ARM.cmake | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 63e3e59a98..ec1375e17f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} diff --git a/tools/cmake/toolchains/GCC_ARM.cmake b/tools/cmake/toolchains/GCC_ARM.cmake index e35dcf866d..632c4153b8 100644 --- a/tools/cmake/toolchains/GCC_ARM.cmake +++ b/tools/cmake/toolchains/GCC_ARM.cmake @@ -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 "$" ) - set(_linker_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 + "$" ) + # Append -D to all macros as we pass these as response file to cxx compiler set(_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