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