Skip to content

Commit cfd435f

Browse files
committed
CMake: generate response file before adding mbed-targets
1 parent ce61c8a commit cfd435f

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

CMakeLists.txt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ target_compile_definitions(mbed-core
7272
${MBED_CONFIG_DEFINITIONS}
7373
)
7474

75+
# We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
76+
# script, because of path length limitations on Windows. We set the response file and bind the path
77+
# to a global property here. The MBED_TARGET being built queries this global property when it sets
78+
# the linker script.
79+
#
80+
# We must set this global property before the targets subdirectory is added to the project. This is
81+
# required because the MBED_TARGET depends on the response file. If the path to the response file
82+
# is not defined when the target requests it the config definitions will not be passed to CPP.
83+
#
84+
# TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
85+
# using response files or global properties.
86+
mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH)
87+
set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH})
88+
7589
# Add compile definitions for backward compatibility with the toolchain
7690
# supported. New source files should instead check for __GNUC__ and __clang__
7791
# for the GCC_ARM and ARM toolchains respectively.
@@ -144,15 +158,6 @@ endif()
144158
# Note, this function will be removed in the next revisions
145159
#
146160
function(mbed_configure_app_target target)
147-
# We need to generate a "response file" to pass to the C preprocessor because of path length
148-
# limitations on Windows. We set the response file and bind the path to a global property here.
149-
# We query this global property when we set the linker script for the MBED_TARGET being built.
150-
#
151-
# TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
152-
# using global properties.
153-
mbed_generate_options_for_linker(${target} LINKER_PREPROCESS_DEFINITIONS)
154-
set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${LINKER_PREPROCESS_DEFINITIONS})
155-
156161
# Gcc Arm requires memap to be set with app name, equally to ARMClang
157162
# TODO: move this to toolchain and set properly
158163
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")

tools/cmake/toolchain.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# Generate a file containing compile definitions
5-
function(mbed_generate_options_for_linker target definitions_file)
5+
function(mbed_generate_options_for_linker target output_response_file_path)
66
set(_compile_definitions
7-
"$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>"
7+
"$<TARGET_PROPERTY:${target},INTERFACE_COMPILE_DEFINITIONS>"
88
)
99

1010
# Remove macro definitions that contain spaces as the lack of escape sequences and quotation marks
@@ -20,7 +20,7 @@ function(mbed_generate_options_for_linker target definitions_file)
2020
"$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions}, -D>>"
2121
)
2222
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n")
23-
set(${definitions_file} @${CMAKE_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)
23+
set(${output_response_file_path} @${CMAKE_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)
2424
endfunction()
2525
# Set the system processor depending on the CPU core type
2626
if (MBED_CPU_CORE STREQUAL Cortex-A9)

0 commit comments

Comments
 (0)