]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: enable binutils ld workaround for all toolchains at build-time
authorViktor Szakats <commit@vsz.me>
Sun, 25 Jan 2026 19:54:55 +0000 (20:54 +0100)
committerViktor Szakats <commit@vsz.me>
Sun, 25 Jan 2026 21:37:56 +0000 (22:37 +0100)
To make it available for GCC if used when consuming libcurl.

Also add comment to `curl-config.cmake` explaining why these odd targets
are defined there.

Bug: https://github.com/curl/curl/pull/20382#discussion_r2716660108
Follow-up to 3e841630ece59c04e26058a761302f38370fd0cc #20427
Follow-up to ef3101d1819928a7799309a16cc531818778e5c7 #20382
Follow-up to 16f073ef49f94412000218c9f6ad04e3fd7e4d01 #16973

Closes #20434

CMake/curl-config.in.cmake
CMakeLists.txt

index cd0d9bbe83c0d97bf320f74ccb74cee7dd2d608e..f4e17d29b32520c4d4f342f6e04aa186260cbef0 100644 (file)
@@ -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")
index 8827deac2c817fc6d6a56d979462f47f877952de..4b0389212ed9d2ceabe77ac35ba67fd372f9cf0f 100644 (file)
@@ -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