From 93f8b26ddfadc07a2e2a1d3b6b8a169557e1691f Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 19 Jul 2023 15:35:23 +0100 Subject: [PATCH] [FIXUP] Evaluate flags set in depends _after_ config-specific flags --- CMakeLists.txt | 22 ++++++++++++++++------ depends/toolchain.cmake.in | 25 +++++++------------------ 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 209931d70d57e..d789f8bc5cc18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,8 +136,13 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") add_link_options(${macos_linker_flags}) endif() -if(CMAKE_CROSSCOMPILING AND DEPENDS_ALLOW_HOST_PACKAGES) - list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_SYSTEM_PREFIX_PATH}") +if(CMAKE_CROSSCOMPILING) + add_definitions(${DEPENDS_COMPILE_DEFINITIONS}) + add_compile_options("$<$:${DEPENDS_C_COMPILER_FLAGS}>") + add_compile_options("$<$:${DEPENDS_CXX_COMPILER_FLAGS}>") + if(DEPENDS_ALLOW_HOST_PACKAGES) + list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_SYSTEM_PREFIX_PATH}") + endif() endif() include(AddThreadsIfNeeded) @@ -212,14 +217,19 @@ get_directory_property(definitions COMPILE_DEFINITIONS) string(REPLACE ";" " " definitions "${definitions}") message("Preprocessor defined macros ........... ${definitions}") message("C compiler ............................ ${CMAKE_C_COMPILER}") -message("CFLAGS ................................ ${CMAKE_C_FLAGS}") +list(JOIN DEPENDS_C_COMPILER_FLAGS " " depends_c_flags) +string(STRIP "${CMAKE_C_FLAGS} ${depends_c_flags}" combined_c_flags) +message("CFLAGS ................................ ${combined_c_flags}") message("C++ compiler .......................... ${CMAKE_CXX_COMPILER}") -message("CXXFLAGS .............................. ${CMAKE_CXX_FLAGS}") +list(JOIN DEPENDS_CXX_COMPILER_FLAGS " " depends_cxx_flags) +string(STRIP "${CMAKE_CXX_FLAGS} ${depends_cxx_flags}" combined_cxx_flags) +message("CXXFLAGS .............................. ${combined_cxx_flags}") get_directory_property(common_compile_options COMPILE_OPTIONS) -string(REPLACE ";" " " common_compile_options "${common_compile_options}") +list(JOIN common_compile_options " " common_compile_options) +string(GENEX_STRIP "${common_compile_options}" common_compile_options) message("Common compile options ................ ${common_compile_options}") get_directory_property(common_link_options LINK_OPTIONS) -string(REPLACE ";" " " common_link_options "${common_link_options}") +list(JOIN common_link_options " " common_link_options) message("Common link options ................... ${common_link_options}") message("Linker flags for executables .......... ${CMAKE_EXE_LINKER_FLAGS}") message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}") diff --git a/depends/toolchain.cmake.in b/depends/toolchain.cmake.in index c64ac90e8fc9c..55896cc95c19b 100644 --- a/depends/toolchain.cmake.in +++ b/depends/toolchain.cmake.in @@ -37,11 +37,10 @@ if(NOT CMAKE_C_COMPILER) if(CMAKE_VERSION VERSION_LESS 3.19) set(DEPENDS_C_COMPILER_FLAGS ${CMAKE_C_COMPILER}) list(REMOVE_AT DEPENDS_C_COMPILER_FLAGS 0) - string(REPLACE ";" " " DEPENDS_C_COMPILER_FLAGS "${DEPENDS_C_COMPILER_FLAGS}") list(GET CMAKE_C_COMPILER 0 CMAKE_C_COMPILER) endif() + list(APPEND DEPENDS_C_COMPILER_FLAGS @CFLAGS@) endif() -set(CMAKE_C_FLAGS_INIT "${DEPENDS_C_COMPILER_FLAGS} @CPPFLAGS@ @CFLAGS@") if(NOT CMAKE_CXX_COMPILER) set(DEPENDS_CXX_COMPILER_WITH_LAUNCHER @CXX@) @@ -52,26 +51,16 @@ if(NOT CMAKE_CXX_COMPILER) if(CMAKE_VERSION VERSION_LESS 3.19) set(DEPENDS_CXX_COMPILER_FLAGS ${CMAKE_CXX_COMPILER}) list(REMOVE_AT DEPENDS_CXX_COMPILER_FLAGS 0) - string(REPLACE ";" " " DEPENDS_CXX_COMPILER_FLAGS "${DEPENDS_CXX_COMPILER_FLAGS}") list(GET CMAKE_CXX_COMPILER 0 CMAKE_CXX_COMPILER) endif() -endif() -set(CMAKE_CXX_FLAGS_INIT "${DEPENDS_CXX_COMPILER_FLAGS} @CPPFLAGS@ @CXXFLAGS@") + list(APPEND DEPENDS_CXX_COMPILER_FLAGS @CXXFLAGS@) -if(NOT CMAKE_OBJCXX_COMPILER) - set(DEPENDS_OBJCXX_COMPILER_WITH_LAUNCHER @CXX@) - split_compiler_launcher(DEPENDS_OBJCXX_COMPILER_WITH_LAUNCHER CMAKE_OBJCXX_COMPILER_LAUNCHER CMAKE_OBJCXX_COMPILER) - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21) - set(CMAKE_OBJCXX_LINKER_LAUNCHER ${CMAKE_OBJCXX_COMPILER_LAUNCHER}) - endif() - if(CMAKE_VERSION VERSION_LESS 3.19) - set(DEPENDS_OBJCXX_COMPILER_FLAGS ${CMAKE_OBJCXX_COMPILER}) - list(REMOVE_AT DEPENDS_OBJCXX_COMPILER_FLAGS 0) - string(REPLACE ";" " " DEPENDS_OBJCXX_COMPILER_FLAGS "${DEPENDS_OBJCXX_COMPILER_FLAGS}") - list(GET CMAKE_OBJCXX_COMPILER 0 CMAKE_OBJCXX_COMPILER) - endif() + set(CMAKE_OBJCXX_COMPILER ${CMAKE_CXX_COMPILER}) + set(CMAKE_OBJCXX_COMPILER_LAUNCHER ${CMAKE_CXX_COMPILER_LAUNCHER}) + set(CMAKE_OBJCXX_LINKER_LAUNCHER ${CMAKE_CXX_LINKER_LAUNCHER}) endif() -set(CMAKE_OBJCXX_FLAGS_INIT "${DEPENDS_OBJCXX_COMPILER_FLAGS} @CPPFLAGS@ @CXXFLAGS@") + +set(DEPENDS_COMPILE_DEFINITIONS @CPPFLAGS@) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(CMAKE_EXE_LINKER_FLAGS_INIT "-static")