Skip to content

Commit

Permalink
[FIXUP] Evaluate flags set in depends _after_ config-specific flags
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Sep 2, 2023
1 parent 482e844 commit 1a1dda5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
17 changes: 13 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<$<COMPILE_LANGUAGE:C>:${DEPENDS_C_COMPILER_FLAGS}>")
target_compile_options(core INTERFACE "$<$<COMPILE_LANGUAGE:CXX>:${DEPENDS_CXX_COMPILER_FLAGS}>")
if(DEPENDS_ALLOW_HOST_PACKAGES)
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_SYSTEM_PREFIX_PATH}")
endif()
endif()

include(AddThreadsIfNeeded)
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 7 additions & 18 deletions depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@)
Expand All @@ -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")
Expand Down

0 comments on commit 1a1dda5

Please sign in to comment.