Skip to content

cmake: fix target interfaces for old CMake versions - #1571

Closed
vszakats wants to merge 7 commits into
libssh2:masterfrom
vszakats:cm-iface-refix-for-old
Closed

vszakats wants to merge 7 commits into
libssh2:masterfrom
vszakats:cm-iface-refix-for-old

Conversation

@vszakats

@vszakats vszakats commented Apr 6, 2025 •

Copy link
Copy Markdown
Member
  • drop VERSION target property for cmake <3.19 compatibility
    CMake Error at CMake/Find*.cmake:90 (set_target_properties):
      INTERFACE_LIBRARY targets may only have whitelisted properties.
      The property "VERSION" is not allowed.
    
  • move custom target property to the INTERFACE_ namespace
    for cmake <3.19 compatibility. (To avoid same error as above)
  • fix forwarding multiple CFLAGS, when detected via pkg-config.
  • restore support for -framework and raw libs when processing
    the internal lib list for generating libssh2.pc. For good measure,
    at the moment libssh2 doesn't depend on a Framework.
  • limit libssh2_dumptargetprops() to cmake 3.19+. It doesn't work with
    older versions.

Issues found while applying this change to curl. They did not surface in
libssh2 CI.

Follow-up to df0563a #1535

@vszakats vszakats added the build label Apr 6, 2025
@vszakats
vszakats marked this pull request as draft April 6, 2025 11:46
cmake 3.7 (_may_ be 3.11 or lower) does not accept it

```
-- Found Libpsl: /usr/local/include (found version "0.21.5")
CMake Error at CMake/FindLibpsl.cmake:90 (set_target_properties):
  INTERFACE_LIBRARY targets may only have whitelisted properties.  The
  property "VERSION" is not allowed.
Call Stack (most recent call first):
  CMakeLists.txt:1252 (find_package)
```
This reverts commit d6487d6.

Ah, needs more work, also to be done in PowerShell, so I'm passing.
@vszakats vszakats changed the title cmake: target interfaces and old CMake versions cmake: fix target interfaces for old CMake versions Apr 10, 2025
@vszakats
vszakats force-pushed the cm-iface-refix-for-old branch from d6487d6 to c9d884d Compare April 10, 2025 12:44
@vszakats
vszakats marked this pull request as ready for review April 10, 2025 12:47
@vszakats vszakats closed this in a0d8529 Apr 14, 2025
@vszakats
vszakats deleted the cm-iface-refix-for-old branch April 14, 2025 00:14
vszakats added a commit that referenced this pull request Apr 27, 2025
- fix `add_subdirectory` builds for old CMake versions.
- libssh2-config.cmake: fix to set CMP0099 for CMake 3.17+ only.
- libssh2-config.cmake: generalize code to support any number of deps.
  (mainly to sync with curl.)
- libssh2-config.cmake: bind dependencies to the static libssh2 only.

Follow-up to a0d8529 #1571
Follow-up to df0563a #1535

Closes #1581
vszakats added a commit to curl/curl that referenced this pull request Nov 29, 2025
Rework the way curl's custom Find modules advertise their properties.

Before this patch, Find modules returned detected dependency properties
(header dirs, libs, libdirs, C flags, etc.) via global variables. curl's
main `CMakeLists.txt` copied their values into global lists, which it
later applied to targets. This solution worked internally, but it was
unsuited for the public, distributed `CURLConfig.cmake` and publishing
curl's Find modules with it, due to polluting the namespace of consumer
projects. It's also impractical to apply the many individual variables
to every targets depending on libcurl.

To allow using Find modules in consumer projects, this patch makes them
define as imported interface targets, named `CURL::<dependency>`. Then
store dependency information as target properties. It avoids namespace
pollution and makes the dependency information apply automatically
to all targets using `CURL::libcurl_static`.

Find modules continue to return `*_FOUND` and `*_VERSION` variables.

For dependencies detected via `pkg-config`, CMake 3.16+ is recommended.
Older CMake versions have a varying degree of support for
propagating/handling library directories. This may cause issues in envs
where dependencies reside in non-system locations and detected via
`pkg-config` (e.g. macOS + Homebrew). Use `CURL_USE_PKGCONFIG=OFF`
to fix these issues. Or upgrade to newer CMake, or link libcurl
dynamically.

Also:
- re-enable `pkg-config` for old cmake `find_library()` integration
  tests.
- make `curlinfo` build after these changes.
- distribute local Find modules.
- export the raw list of lib dependencies via `CURL_LIBRARIES_PRIVATE`.
- `CURLconfig.cmake`: use curl's Find modules to detect dependencies in
  the consumer env.
- add custom property to target property debug function.
- the curl build process no longer modifies `CMAKE_C_FLAGS`.
  Follow-up to e865420 #17047

Ref: #14930
Ref: libssh2/libssh2#1535
Ref: libssh2/libssh2#1571
Ref: libssh2/libssh2#1581
Ref: libssh2/libssh2#1623

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant