diff --git a/CMakeLists.txt b/CMakeLists.txt index 542296336635c..59b1d16d67132 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,8 +153,13 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") try_append_linker_flag(core "-Wl,-headerpad_max_install_names") endif() -if(CMAKE_CROSSCOMPILING AND DEPENDS_ALLOW_HOST_PACKAGES) - list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_SYSTEM_PREFIX_PATH}") +if(CMAKE_CROSSCOMPILING) + target_compile_definitions(core INTERFACE ${DEPENDS_COMPILE_DEFINITIONS}) + target_compile_options(core INTERFACE "$<$:${DEPENDS_C_COMPILER_FLAGS}>") + target_compile_options(core INTERFACE "$<$:${DEPENDS_CXX_COMPILER_FLAGS}>") + if(DEPENDS_ALLOW_HOST_PACKAGES) + list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_SYSTEM_PREFIX_PATH}") + endif() endif() include(AddThreadsIfNeeded) @@ -229,9 +234,13 @@ 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_target_property(common_compile_options core INTERFACE_COMPILE_OPTIONS) if(common_compile_options) list(JOIN common_compile_options " " common_compile_options) 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")