Skip to content

Commit d4ee3bd

Browse files
committed
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}
1 parent be31d50 commit d4ee3bd

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

tools/cmake/mbed_toolchain.cmake

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@ function(mbed_generate_options_for_linker target output_response_file_path)
77
"$<TARGET_PROPERTY:${target},INTERFACE_COMPILE_DEFINITIONS>"
88
)
99

10-
# Remove macro definitions that contain spaces as the lack of escape sequences and quotation marks
11-
# in the macro when retrieved using generator expressions causes linker errors.
12-
# This includes string macros, array macros, and macros with operations.
13-
# TODO CMake: Add escape sequences and quotation marks where necessary instead of removing these macros.
10+
# Append -D to all macros and quote them as we pass these as response file to cxx compiler
1411
set(_compile_definitions
15-
"$<FILTER:${_compile_definitions},EXCLUDE, +>"
16-
)
17-
18-
# Append -D to all macros as we pass these as response file to cxx compiler
19-
set(_compile_definitions
20-
"$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions}, -D>>"
12+
"$<$<BOOL:${_compile_definitions}>:'-D$<JOIN:${_compile_definitions},' '-D>'>"
2113
)
2214
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n")
2315
set(${output_response_file_path} @${CMAKE_CURRENT_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)

0 commit comments

Comments
 (0)