From d4ee3bd8452e180aa57a7e18dc1a482f87f6ebb6 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Tue, 31 Aug 2021 11:14:42 +0100 Subject: [PATCH] CMake: Fix escaping of quotes in response file We put macros in a response file compile_time_defs.txt and pass it to the compiler. Adding a pair of single quotes around each -D flag ensures macro values are quoted correctly. For example, * String * target_compile_definitions(): either FOO="BAR" or FOO=\"BAR\" * response file: '-DFOO="BAR"' * actual definition: #define FOO "BAR" * Array of integers * target_compile_definitions(): FOO={1, 2, 3} * response file: '-DFOO={1, 2, 3}' * actual definition: #define FOO {1, 2, 3} --- tools/cmake/mbed_toolchain.cmake | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tools/cmake/mbed_toolchain.cmake b/tools/cmake/mbed_toolchain.cmake index 139828921ba..0ec168a0880 100644 --- a/tools/cmake/mbed_toolchain.cmake +++ b/tools/cmake/mbed_toolchain.cmake @@ -7,17 +7,9 @@ function(mbed_generate_options_for_linker target output_response_file_path) "$" ) - # 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. + # Append -D to all macros and quote them as we pass these as response file to cxx compiler set(_compile_definitions - "$" - ) - - # Append -D to all macros as we pass these as response file to cxx compiler - set(_compile_definitions - "$<$:-D$>" + "$<$:'-D$'>" ) file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n") set(${output_response_file_path} @${CMAKE_CURRENT_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)