mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
Merge branch 'fix/cmake_flags_passing_to_external_project_v6.0' into 'release/v6.0'
fix(build): fix passing CMAKE_<LANG>_FLAGS from ExternalProject_Add (v6.0) See merge request espressif/esp-idf!46651
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
# Remove duplicates from a string containing compilation flags
|
||||
function(remove_duplicated_flags FLAGS UNIQFLAGS)
|
||||
set(FLAGS_LIST "${FLAGS}")
|
||||
# Remove leading and trailing spaces
|
||||
string(STRIP "${FLAGS_LIST}" FLAGS_LIST)
|
||||
# Convert the given flags, as a string, into a CMake list type
|
||||
separate_arguments(FLAGS_LIST)
|
||||
# Remove all the duplicated flags
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/toolchain_flags.cmake)
|
||||
include($ENV{IDF_PATH}/tools/cmake/deduplicate_flags.cmake)
|
||||
|
||||
if(NOT CMAKE_PARENT_LIST_FILE)
|
||||
message(FATAL_ERROR "toolchain.cmake cannot be used standalone (use chip-specific toolchain file instead)")
|
||||
@@ -69,17 +70,30 @@ if(_idf_toolchain_dir STREQUAL _current_toolchain_dir)
|
||||
CXX_COMPILE_OPTIONS "${CMAKE_CXX_FLAGS}"
|
||||
ASM_COMPILE_OPTIONS "${CMAKE_ASM_FLAGS}"
|
||||
LINK_OPTIONS "${CMAKE_EXE_LINKER_FLAGS}")
|
||||
# Clear CMAKE_*_FLAGS because all flags are written to response files.
|
||||
set(CMAKE_C_FLAGS "")
|
||||
set(CMAKE_CXX_FLAGS "")
|
||||
set(CMAKE_ASM_FLAGS "")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "")
|
||||
else()
|
||||
set(IDF_TOOLCHAIN_BUILD_DIR "${_current_toolchain_dir}"
|
||||
CACHE PATH "Path to toolchain build directory containing response files and toolchain file copy" FORCE)
|
||||
endif()
|
||||
|
||||
# Merge the response file path with any existing CMAKE_*_FLAGS (e.g. from
|
||||
# ExternalProject_Add), then remove duplicates. Deduplication is needed because
|
||||
# CMake may execute this toolchain file multiple times during initialization.
|
||||
remove_duplicated_flags("@\"${IDF_TOOLCHAIN_BUILD_DIR}/cflags\" ${CMAKE_C_FLAGS}" CMAKE_C_FLAGS)
|
||||
remove_duplicated_flags("@\"${IDF_TOOLCHAIN_BUILD_DIR}/cxxflags\" ${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS)
|
||||
remove_duplicated_flags("@\"${IDF_TOOLCHAIN_BUILD_DIR}/asmflags\" ${CMAKE_ASM_FLAGS}" CMAKE_ASM_FLAGS)
|
||||
remove_duplicated_flags("@\"${IDF_TOOLCHAIN_BUILD_DIR}/ldflags\" ${CMAKE_EXE_LINKER_FLAGS}" CMAKE_EXE_LINKER_FLAGS)
|
||||
|
||||
# Configure CMake to use response files for compiler and linker flags.
|
||||
# Some compilation options enabled by IDF configuration options are not yet
|
||||
# defined at this very early CMake stage (toolchain.cmake execution). Response
|
||||
# files allow these flags to be dynamically updated during the CMake configuration
|
||||
# phase, after the options become available.
|
||||
set(CMAKE_C_FLAGS "@\"${IDF_TOOLCHAIN_BUILD_DIR}/cflags\"" CACHE STRING "C Compiler Base Flags" FORCE)
|
||||
set(CMAKE_CXX_FLAGS "@\"${IDF_TOOLCHAIN_BUILD_DIR}/cxxflags\"" CACHE STRING "C++ Compiler Base Flags" FORCE)
|
||||
set(CMAKE_ASM_FLAGS "@\"${IDF_TOOLCHAIN_BUILD_DIR}/asmflags\"" CACHE STRING "Asm Compiler Base Flags" FORCE)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "@\"${IDF_TOOLCHAIN_BUILD_DIR}/ldflags\"" CACHE STRING "Linker Base Flags" FORCE)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "C Compiler Base Flags" FORCE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "C++ Compiler Base Flags" FORCE)
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS}" CACHE STRING "Asm Compiler Base Flags" FORCE)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "Linker Base Flags" FORCE)
|
||||
|
||||
Reference in New Issue
Block a user