cmake: avoid setting custom property on built-in interface targets

In some cases `ZLIB::ZLIB` and/or `OpenSSL::SSL` may be aliases, which
prevents setting a curl-specific property (.pc module name) in them:
```
CMake Error at [...]/curl/CMakeLists.txt:910 (set_target_properties):
  set_target_properties can not be used on an ALIAS target.
```

Fix by special-casing these built-in targets and manually converting
them to .pc module names, without using the targets themselves
to carry this information throughout curl's internal build logic.

Reported-by: Tomáš Malý
Fixes #20313
Follow-up to 16f073ef49 #16973
Closes #20316
This commit is contained in:
Viktor Szakats
2026-01-14 13:04:18 +01:00
parent 2b12dbc116
commit 6437bd79ae

View File

@@ -767,7 +767,6 @@ if(CURL_USE_OPENSSL)
# Depend on OpenSSL via imported targets. This allows our dependents to
# get our dependencies transitively.
list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
set_target_properties(OpenSSL::SSL PROPERTIES INTERFACE_LIBCURL_PC_MODULES "openssl")
if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "openssl")
set(_valid_default_ssl_backend TRUE)
@@ -907,7 +906,6 @@ if(ZLIB_FOUND)
# Depend on ZLIB via imported targets. This allows our dependents to
# get our dependencies transitively.
list(APPEND CURL_LIBS ZLIB::ZLIB)
set_target_properties(ZLIB::ZLIB PROPERTIES INTERFACE_LIBCURL_PC_MODULES "zlib")
endif()
set(HAVE_BROTLI OFF)
@@ -2154,7 +2152,13 @@ if(NOT CURL_DISABLE_INSTALL)
if(NOT _libname AND NOT _libs AND NOT _libdirs)
message(WARNING "Bad lib in library list: ${_lib}")
endif()
get_target_property(_modules "${_lib}" INTERFACE_LIBCURL_PC_MODULES)
if(_lib STREQUAL OpenSSL::SSL)
set(_modules "openssl")
elseif(_lib STREQUAL ZLIB::ZLIB)
set(_modules "zlib")
else()
get_target_property(_modules "${_lib}" INTERFACE_LIBCURL_PC_MODULES)
endif()
if(_modules)
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "${_modules}")
endif()