Skip to content

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

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:cmbuiltinbutalias
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:cmbuiltinbutalias

Conversation

@vszakats

@vszakats vszakats commented Jan 14, 2026 •

Copy link
Copy Markdown
Member

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: curl/curl#20316
Follow-up to df0563a #1535

In some cases `ZLIB::ZLIB` and/or `OpenSSL::Crypto` may be aliases,
which prevents setting a curl-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 curl'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: curl/curl#20316
@vszakats vszakats closed this in bd1d00a Jan 14, 2026
@vszakats
vszakats deleted the cmbuiltinbutalias branch January 14, 2026 20:28
@vszakats

vszakats commented Jan 15, 2026 •

Copy link
Copy Markdown
Member Author

Clarification to the commit message, post-merge: Contrary to what I
thought and wrote there, zlib-ng is never at fault here. Classic zlib may
be, since it does define ZLIB::ZLIB, but in this particular issue report
the incompatible definition was done in the specific project.
Ref: curl/curl#20313
curl/curl#20313 (comment) and curl/curl#20313 (comment)

The fix is still good to make this defensive and protect against projects
doing what IMO should be better be avoided. ZLIB::ZLIB (and others)
should always be the canonical target defined by CMake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant