cmake: simplify LINK_ONLY imported target extraction

Suggested-by: Kai Pastor
Ref: https://github.com/curl/curl/pull/21654#discussion_r3425296606
Follow-up to 3c597ced16 #21654

Closes #22063
This commit is contained in:
Viktor Szakats 2026-06-17 13:50:52 +02:00
parent e8b76773af
commit 174cafb3e6
No known key found for this signature in database

View file

@ -267,10 +267,8 @@ macro(curl_collect_target_link_options _target)
get_target_property(_val ${_target} INTERFACE_LINK_LIBRARIES)
if(_val)
foreach(_lib IN LISTS _val)
# E.g. via libssh2: "$<LINK_ONLY:OpenSSL::Crypto>"
if(_lib MATCHES "LINK_ONLY:")
string(REGEX MATCH "([A-Za-z0-9_-]+::[A-Za-z0-9_-]+)" _lib "${_lib}") # Extract imported target name
endif()
# Extract imported target name from e.g. "$<LINK_ONLY:OpenSSL::Crypto>" set by libssh2
string(REGEX REPLACE "^\\\$<LINK_ONLY:(.*)>\$" "\\1" _lib "${_lib}")
if(TARGET "${_lib}")
curl_collect_target_link_options(${_lib})
else()