]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: skip binutils ld hack if zlib/openssl target is not `IMPORTED`
authorViktor Szakats <commit@vsz.me>
Sat, 31 Jan 2026 20:15:51 +0000 (21:15 +0100)
committerViktor Szakats <commit@vsz.me>
Mon, 2 Feb 2026 11:28:12 +0000 (12:28 +0100)
The binutils ld hack requires reading the targets' `LOCATION` property.
This property exists in `IMPORTED` targets. `ZLIB::ZLIB` and
`OpenSSL::Crypto` are normally `IMPORTED` targets defined by CMake's
built-in Find modules. However, in some cases (e.g. in "superbuilds"),
they may be regular targets, defined manually, without a `LOCATION`
property. To avoid a CMake warning in such case, verify if the target is
`IMPORTED` before reading this property.

This also mean that in such case the binutils/ld/gcc hack is not
enabled, and libcurl may fail linking in static mode.

https://cmake.org/cmake/help/v4.2/prop_tgt/IMPORTED.html
https://cmake.org/cmake/help/v4.2/prop_tgt/LOCATION.html

Reported-by: Tomáš Malý
Fixes #20419
Follow-up to 3e841630ece59c04e26058a761302f38370fd0cc #20427
Follow-up to 16f073ef49f94412000218c9f6ad04e3fd7e4d01 #16973

Closes #20486

CMakeLists.txt

index 4ff6ce4b5b856babaaa7163f736986eb3af870f4..bd30a00f8e2b89eb4cd6fe08e88f736f15d42d4b 100644 (file)
@@ -1817,16 +1817,22 @@ 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)
+  get_target_property(_curl_imported OpenSSL::Crypto IMPORTED)
+  if(_curl_imported)
+    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()
 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)
+  get_target_property(_curl_imported ZLIB::ZLIB IMPORTED)
+  if(_curl_imported)
+    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()
 endif()
 if(WIN32)
   add_library(CURL::win32_winsock INTERFACE IMPORTED)