Repository navigation
Conversation
|
The fallout mentioned in #1534 (comment) doesn't replicate in CI, presumably because it's on Linux where the dependency is at a default, system, location. While in my env it requires the (edit: The issue is limited to static consumption.) The rest looks about fine. It's basically moving the Find module custom result variables into (mostly) standardized target properties. This makes it possible to let CMake apply these properties automatically to targets. It allows to set custom properties, which I used for the |
|
Wrt #1534 (comment): On target names and namespaces: On |
|
I tried looking at how to export them, but so far no results. Probably the next is peeking into the source code. I don't have high hopes. It's sad because otherwise the concept makes dep handling on the whole more organized. My impression is that CMake's concept of lib deps is rooted from Windows, and this abstraction doesn't work well elsewhere. |
|
Extended integration tests to macOS, where the issue replicates. An old thread complaining about this: https://cmake.org/pipermail/cmake/2017-August/066086.html Found this policy describing something close to what we experience here: It needs to be set by the consumer project: if(POLICY CMP0099) # new in CMake 3.17, defaults to OLD
cmake_policy(SET CMP0099 NEW)
endif()or opt-in via Also it turns out I'll now push a terrible manual workaround to fill in for |
|
I tend to consider the namespace pollution issue unresolvable. CMake is a hot mess of namespace pollution. Avoiding it fully seems In theory As a fan of namespacing, I'm calling defeat here. Instead of inflicting Other than that, do what's reasonably possible, without going overboard. |
INTERFACE in Find modulesINTERFACE
To avoid cmake warning:
```
CMake Warning:
Manually-specified variables were not used by the project:
ENABLE_ECDSA_WINCNG
```
https://github.com/libssh2/libssh2/actions/runs/13126062299/job/36622533686?pr=1535#step:3:88
Follow-up to 3f98bfb #1368
Cherry-picked from #1535
Make sure to keep any previously added settings. For good measure; this hasn't been an issue with libssh2 builds yet. Cherry-picked from #1535
daf870c to
c7ec656
Compare
|
With the changes made after my last comment, that is, moving module I plan to merge this soon. |
Add support for `INTERFACE` targets when assembling libssh2.pc input variables.
For old CMake the workaround was moved to Find modules in commit: Find: add link directories workaround for CMake 3.12 and older
- 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
Closes #1571
- 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
The `libssh2.pc` generator logic automatically adds `-lws2_32` while parsing `LIBSSH2_LIBS`, which contains this lib already. Then discard the duplicate. This change introduces a change in the position of `ws2_32` within the lib list. This order might in cases by significant, but: - libssh2 no longer links against `libssl`, which was the library also referencing `ws2_32` and breaking picky binutils `ld` linker when not passed in strict dependency order. Ref: c84745e libssh2#1128 - since switching to INTERFACE targets, cmake messes up the lib order anyway, adding `OpenSSL:Crypto` last, instead of `ws2_32`. This did not seem to cause an issue so far. Ref: df0563a libssh2#1535 Ref: 33b6d5f libssh2#827 Ref: 31fb886 libssh2#811
The `libssh2.pc` generator logic automatically adds `-lws2_32` while parsing `LIBSSH2_LIBS`, which contains this lib already. Then discard the duplicate. This patch introduces a change in the position of `ws2_32` within the lib list advertised via `libssh2.pc` for static builds. This order might in cases by significant, but: - libssh2 no longer links against `libssl`, which was the library also referencing `ws2_32` and breaking picky binutils `ld` linker when not passed in strict dependency order. Ref: c84745e #1128 - since switching to INTERFACE targets, cmake messes up the lib order anyway, adding `OpenSSL:Crypto` last, instead of `ws2_32`. This did not seem to cause an issue so far. Ref: df0563a #1535 For these reasons it seems unlikely this position change could break Windows OpenSSL static gcc/ld builds relying on `libssh2.pc` for their lib list. It least no more than it was before this patch. Turns out these theories don't stand in practice and the order is broken possibly by introducing INTERFACE targets, with or without this patch. `libcrypto` (tested with LibreSSL) is in fact depending on `ws2_32`, and the `bcrypt` dependency is also causing breakage with picky binutils ld. I may try addressing it in a separate PR. Ref: 33b6d5f #827 Ref: 31fb886 #811 Closes #1619
- Reworking the `Libs.private` collector logic for INTERFACE targets, broke the original lib order. Fix it by going back a single loop to retain order. Follow-up to df0563a #1535 - Implement the above with one change: move implicit CMake libs to the end of the list (was: the beginning). I expect these to be libs that any custom libs may depend on, like system libs, C runtime, compiler runtime lib. Follow-up to c87f129 #1466 Closes #1623
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
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 Closes #1789
move dependency properties (libs, libdirs, C flags, header dirs,
pkg-config module names) from global lists to imported target
INTERFACEproperties. Rework FInd modules to return their resultslike this and update the libssh2 build process to use it. It makes
Find modules re-usable from the cmake-config script by libssh2
consumers, to integrate with libssh2 dependencies.
define libssh2 dependencies as "imported targets" by the name:
libssh2::<depname>, e.g.libssh2::libgcrypt.cmake-config: add fall-back logic for CMake without
CMP0099 (v3.17 2020-03-20) to set lib directories.
generate
libssh2.pcbased on imported target properties (instead ofglobal lists).
add target property dump debug function.
ci/GHA: also test cmake integration on macOS.
Follow-up to 96d7f40 #1534
w/o ws https://github.com/libssh2/libssh2/pull/1535/files?w=1
Continuing #1534 from:
#1534 (comment)
-I, not-isystem) (when detected viapkg-config)libssh2::<DependencyName>.libssh2.pc.It can now be extracted from target props (TODO: OpenSSL, ZLIB).