diff --git a/CMake/curl-config.in.cmake b/CMake/curl-config.in.cmake index cd0d9bbe83..f4e17d29b3 100644 --- a/CMake/curl-config.in.cmake +++ b/CMake/curl-config.in.cmake @@ -39,6 +39,7 @@ if("@USE_OPENSSL@") else() find_dependency(OpenSSL) endif() + # Define lib duplicate to fixup lib order for GCC binutils ld in static builds if(TARGET OpenSSL::Crypto AND NOT TARGET CURL::OpenSSL_Crypto) add_library(CURL::OpenSSL_Crypto INTERFACE IMPORTED) get_target_property(_curl_libname OpenSSL::Crypto LOCATION) @@ -47,6 +48,7 @@ if("@USE_OPENSSL@") endif() if("@HAVE_LIBZ@") find_dependency(ZLIB "@ZLIB_VERSION_MAJOR@") + # Define lib duplicate to fixup lib order for GCC binutils ld in static builds if(TARGET ZLIB::ZLIB AND NOT TARGET CURL::ZLIB) add_library(CURL::ZLIB INTERFACE IMPORTED) get_target_property(_curl_libname ZLIB::ZLIB LOCATION) @@ -148,6 +150,7 @@ endif() set(CMAKE_MODULE_PATH ${_curl_cmake_module_path_save}) +# Define lib duplicate to fixup lib order for GCC binutils ld in static builds if(WIN32 AND NOT TARGET CURL::win32_winsock) add_library(CURL::win32_winsock INTERFACE IMPORTED) set_target_properties(CURL::win32_winsock PROPERTIES INTERFACE_LINK_LIBRARIES "ws2_32") diff --git a/CMakeLists.txt b/CMakeLists.txt index 8827deac2c..4b0389212e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1812,24 +1812,24 @@ endif() # list on the linker command-line for some reason. This makes them appear # before dependencies detected via curl's custom Find modules, and breaks # linkers sensitive to lib order. There must be a better solution to this. -if(CMAKE_C_COMPILER_ID STREQUAL "GNU") - if(USE_OPENSSL AND TARGET OpenSSL::Crypto) - add_library(CURL::OpenSSL_Crypto INTERFACE IMPORTED) - get_target_property(_curl_libname OpenSSL::Crypto LOCATION) - set_target_properties(CURL::OpenSSL_Crypto PROPERTIES INTERFACE_LINK_LIBRARIES "${_curl_libname}") - list(APPEND CURL_LIBS CURL::OpenSSL_Crypto) - endif() - if(HAVE_LIBZ AND TARGET ZLIB::ZLIB) - add_library(CURL::ZLIB INTERFACE IMPORTED) - get_target_property(_curl_libname ZLIB::ZLIB LOCATION) - set_target_properties(CURL::ZLIB PROPERTIES INTERFACE_LINK_LIBRARIES "${_curl_libname}") - list(APPEND CURL_LIBS CURL::ZLIB) - endif() - if(WIN32) - add_library(CURL::win32_winsock INTERFACE IMPORTED) - set_target_properties(CURL::win32_winsock PROPERTIES INTERFACE_LINK_LIBRARIES "ws2_32") - list(APPEND CURL_LIBS CURL::win32_winsock) - endif() +# Enable the workaround for all compilers, to make it available when using GCC +# to consume libcurl, regardless of the compiler used to build libcurl itself. +if(USE_OPENSSL AND TARGET OpenSSL::Crypto) + add_library(CURL::OpenSSL_Crypto INTERFACE IMPORTED) + get_target_property(_curl_libname OpenSSL::Crypto LOCATION) + set_target_properties(CURL::OpenSSL_Crypto PROPERTIES INTERFACE_LINK_LIBRARIES "${_curl_libname}") + list(APPEND CURL_LIBS CURL::OpenSSL_Crypto) +endif() +if(HAVE_LIBZ AND TARGET ZLIB::ZLIB) + add_library(CURL::ZLIB INTERFACE IMPORTED) + get_target_property(_curl_libname ZLIB::ZLIB LOCATION) + set_target_properties(CURL::ZLIB PROPERTIES INTERFACE_LINK_LIBRARIES "${_curl_libname}") + list(APPEND CURL_LIBS CURL::ZLIB) +endif() +if(WIN32) + add_library(CURL::win32_winsock INTERFACE IMPORTED) + set_target_properties(CURL::win32_winsock PROPERTIES INTERFACE_LINK_LIBRARIES "ws2_32") + list(APPEND CURL_LIBS CURL::win32_winsock) endif() if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") # MSVC but exclude clang-cl