From: Viktor Szakats Date: Sat, 31 Jan 2026 20:15:51 +0000 (+0100) Subject: cmake: skip binutils ld hack if zlib/openssl target is not `IMPORTED` X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f1646ef8a9ae3052ee3e13a09c418de9ec85819;p=thirdparty%2Fcurl.git cmake: skip binutils ld hack if zlib/openssl target is not `IMPORTED` 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ff6ce4b5b..bd30a00f8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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)