1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-01-27 00:18:12 +03:00

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 df0563a857 #1535

Closes #1789
This commit is contained in:
Viktor Szakats
2026-01-14 20:50:14 +01:00
parent fb6fcaa2e2
commit bd1d00a4b3
2 changed files with 7 additions and 3 deletions

View File

@@ -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.

View File

@@ -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()