From bd1d00a4b3c365517bf1b428da4c418312078892 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 14 Jan 2026 20:50:14 +0100 Subject: [PATCH] cmake: avoid setting custom property on built-in interface targets In some cases `ZLIB::ZLIB` and/or `OpenSSL::Crypto` may be aliases, which prevents setting a libssh2-specific property (.pc module name) in them: ``` CMake Error at [...]/src/CMakeLists.txt:... (set_target_properties): set_target_properties can not be used on an ALIAS target. ``` This can happen when doing "superbuilds" with classic zlib or zlib-ng, which define `ZLIB::ZLIB` on their own, but as an alias, unlike CMake does with the canonical `ZLIB::ZLIB` 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 libssh2's internal build logic. A side-effect of this change is that `zlib` is now present in libssh2.pc when zlib is an indirect dependency via a crypto backend (OpenSSL or wolfSSL). Before this patch it only appeared there when enabling zlib explicitly for libssh2. Ref: https://github.com/curl/curl/pull/20316 Follow-up to df0563a85732fd9a33bbb116d8c07ca18ba6af38 #1535 Closes #1789 --- CMakeLists.txt | 1 - src/CMakeLists.txt | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c711f50..84eed967 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -424,7 +424,6 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND) set(CRYPTO_BACKEND "OpenSSL") set(CRYPTO_BACKEND_DEFINE "LIBSSH2_OPENSSL") list(APPEND LIBSSH2_LIBS OpenSSL::Crypto) - set_target_properties(OpenSSL::Crypto PROPERTIES INTERFACE_LIBSSH2_PC_MODULES "libcrypto") if(WIN32) # Statically linking to OpenSSL requires crypt32 for some Windows APIs. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d5821c94..de98d0a7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,7 +60,6 @@ if(ENABLE_ZLIB_COMPRESSION) find_package(ZLIB REQUIRED) list(APPEND LIBSSH2_LIBS ZLIB::ZLIB) - set_target_properties(ZLIB::ZLIB PROPERTIES INTERFACE_LIBSSH2_PC_MODULES "zlib") list(APPEND _libssh2_definitions "LIBSSH2_HAVE_ZLIB") endif() @@ -283,7 +282,13 @@ if(NOT LIBSSH2_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_LIBSSH2_PC_MODULES) + if(_lib STREQUAL OpenSSL::Crypto) + set(_modules "libcrypto") + elseif(_lib STREQUAL ZLIB::ZLIB) + set(_modules "zlib") + else() + get_target_property(_modules "${_lib}" INTERFACE_LIBSSH2_PC_MODULES) + endif() if(_modules) list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "${_modules}") endif()