From 0793c98027edcf289cfe951879369a94cf64d323 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 6 Mar 2026 15:43:59 +0100 Subject: [PATCH] cmake: rework binutils ld hack to not read `LOCATION` property Instead hook up the upstream target name as-is to the local wrapper target. To: - make the hack work regardless of how the upstream target was created. - make it work the same way in `curl-config.cmake`. Before this patch it had no guard for `IMPORTED` targets even though `find_dependencies()` is not guaranteed to create the target expected if it already existed and was potentially created differently. Depends-on: #20840 Follow-up to 4f1646ef8a9ae3052ee3e13a09c418de9ec85819 #20486 #20419 Closes #20839 --- CMake/curl-config.in.cmake | 6 ++---- CMakeLists.txt | 20 ++++++-------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/CMake/curl-config.in.cmake b/CMake/curl-config.in.cmake index 4e7c29fff6..4d7d0fd1ed 100644 --- a/CMake/curl-config.in.cmake +++ b/CMake/curl-config.in.cmake @@ -42,8 +42,7 @@ if("@USE_OPENSSL@") # 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) - set_target_properties(CURL::OpenSSL_Crypto PROPERTIES INTERFACE_LINK_LIBRARIES "${_curl_libname}") + set_target_properties(CURL::OpenSSL_Crypto PROPERTIES INTERFACE_LINK_LIBRARIES OpenSSL::Crypto) endif() endif() if("@HAVE_LIBZ@") @@ -51,8 +50,7 @@ if("@HAVE_LIBZ@") # 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) - set_target_properties(CURL::ZLIB PROPERTIES INTERFACE_LINK_LIBRARIES "${_curl_libname}") + set_target_properties(CURL::ZLIB PROPERTIES INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) endif() endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 64c8895eef..eed9d6bbbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1843,22 +1843,14 @@ endif() # to consume libcurl, regardless of the compiler used to build libcurl itself. if(CMAKE_C_COMPILER_ID STREQUAL "GNU") if(USE_OPENSSL AND TARGET 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() + add_library(CURL::OpenSSL_Crypto INTERFACE IMPORTED) + set_target_properties(CURL::OpenSSL_Crypto PROPERTIES INTERFACE_LINK_LIBRARIES OpenSSL::Crypto) + list(APPEND CURL_LIBS CURL::OpenSSL_Crypto) endif() if(HAVE_LIBZ AND TARGET ZLIB::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() + add_library(CURL::ZLIB INTERFACE IMPORTED) + set_target_properties(CURL::ZLIB PROPERTIES INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) + list(APPEND CURL_LIBS CURL::ZLIB) endif() if(WIN32) add_library(CURL::win32_winsock INTERFACE IMPORTED)