From 0c7bfe93e3e991f652ca0cd3aeab7d4f16ac412f Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Thu, 11 Feb 2021 15:59:19 +0000 Subject: [PATCH] CMake: Generate response file before adding mbed-targets We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker script, because of path length limitations on Windows. We set the response file and bind the path to a global property. The MBED_TARGET being built queries this global property when it sets the linker script. We must set this global property before the targets subdirectory is added to the project. This is required because the MBED_TARGET depends on the response file. If the path to the response file is not defined when the target requests it the config definitions will not be passed to CPP. --- CMakeLists.txt | 23 ++++++++++++++--------- tools/cmake/toolchain.cmake | 6 +++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1967c3f65..bd8151bcaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,20 @@ target_compile_definitions(mbed-core ${MBED_CONFIG_DEFINITIONS} ) +# We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker +# script, because of path length limitations on Windows. We set the response file and bind the path +# to a global property here. The MBED_TARGET being built queries this global property when it sets +# the linker script. +# +# We must set this global property before the targets subdirectory is added to the project. This is +# required because the MBED_TARGET depends on the response file. If the path to the response file +# is not defined when the target requests it the config definitions will not be passed to CPP. +# +# TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without +# using response files or global properties. +mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH) +set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH}) + # Add compile definitions for backward compatibility with the toolchain # supported. New source files should instead check for __GNUC__ and __clang__ # for the GCC_ARM and ARM toolchains respectively. @@ -144,15 +158,6 @@ endif() # Note, this function will be removed in the next revisions # function(mbed_configure_app_target target) - # We need to generate a "response file" to pass to the C preprocessor because of path length - # limitations on Windows. We set the response file and bind the path to a global property here. - # We query this global property when we set the linker script for the MBED_TARGET being built. - # - # TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without - # using global properties. - mbed_generate_options_for_linker(${target} LINKER_PREPROCESS_DEFINITIONS) - set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${LINKER_PREPROCESS_DEFINITIONS}) - # Gcc Arm requires memap to be set with app name, equally to ARMClang # TODO: move this to toolchain and set properly if(MBED_TOOLCHAIN STREQUAL "GCC_ARM") diff --git a/tools/cmake/toolchain.cmake b/tools/cmake/toolchain.cmake index 2472c3d13d..92500e17ed 100644 --- a/tools/cmake/toolchain.cmake +++ b/tools/cmake/toolchain.cmake @@ -2,9 +2,9 @@ # SPDX-License-Identifier: Apache-2.0 # Generate a file containing compile definitions -function(mbed_generate_options_for_linker target definitions_file) +function(mbed_generate_options_for_linker target output_response_file_path) set(_compile_definitions - "$" + "$" ) # 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) "$<$:-D$>" ) file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n") - set(${definitions_file} @${CMAKE_CURRENT_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE) + set(${output_response_file_path} @${CMAKE_CURRENT_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE) endfunction() # Set the system processor depending on the CPU core type if (MBED_CPU_CORE STREQUAL Cortex-A9)