1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-08-08 19:02:07 +03:00
Commit Graph

13 Commits

Author SHA1 Message Date
Viktor Szakats
ac80041852 cmake: IMPORTED target improvements and fixes
- 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 a0d8529b08 #1571
Follow-up to df0563a857 #1535

Closes #1581
2025-04-27 13:46:30 +02:00
Viktor Szakats
a8dd5090d6 cmake: avoid 'target is imported but not globally visible' when consuming libcurl with old cmake
Fixes:
```
CMake Error at bld-libssh2/_pkg/lib/cmake/libssh2/libssh2-config.cmake:35 (add_library):
  add_library cannot create ALIAS target "libssh2::libssh2" because target
  "libssh2::libssh2_shared" is imported but not globally visible.
Call Stack (most recent call first):
  CMakeLists.txt:27 (find_package)

CMake Error at bld-libssh2/_pkg/lib/cmake/libssh2/libssh2-config.cmake:40 (add_library):
  add_library cannot create ALIAS target "Libssh2::libssh2" because target
  "libssh2::libssh2_shared" is imported but not globally visible.
Call Stack (most recent call first):
  CMakeLists.txt:27 (find_package)
```

tests/cmake reproducer (requires #1581):
```shell
export CMAKE_CONSUMER=/path/to/CMake-3.12.0/bin/cmake
./test.sh find_package
```

I don't understand what this error says, why it happens in certain CMake
versions, and why a workaround is necessary for what seems like
a standard export/consume configuration. This patch is based on internet
suggestions and other projects ending up with this workaround.

Ref: https://github.com/curl/curl/pull/16973
Ref: https://github.com/curl/curl/pull/17140
Cherry-picked from #1581
Closes #1587
2025-04-25 16:44:55 +02:00
Viktor Szakats
117b02b442 cmake: fix libssh2-config.cmake for cmake <3.15
Replace `list(PREPEND ...)` for compatibility with CMake < 3.15.

Ref: https://cmake.org/cmake/help/latest/command/list.html#prepend

Follow-up to 82b09f9b3a #1322
Cherry-picked from #1581
Closes #1586
2025-04-25 16:44:55 +02:00
Viktor Szakats
df0563a857 cmake: make Find modules use INTERFACE
- move dependency properties (libs, libdirs, C flags, header dirs,
  pkg-config module names) from global lists to imported target
  `INTERFACE` properties. Rework FInd modules to return their results
  like 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.pc` based on imported target properties (instead of
  global lists).

- add target property dump debug function.

- ci/GHA: also test cmake integration on macOS.

Follow-up to 96d7f404e7 #1534

Closes #1535
2025-03-19 18:31:19 +01:00
Viktor Szakats
96d7f404e7 cmake: make libssh2-config work with all TLS-backends
CMake:

- Find*: set `<modulename>_FOUND` for compatibility when found via
  `pkg-config`. E.g. `MbedTLS_FOUND`.
  `find_package_handle_standard_args()` sets both `<MODULENAME>_FOUND`
  and `<Modulename>_FOUND` when detecting the dependency. Some CMake
  code relies on this and 3rd-party code may rely on it too. Make sure
  to set the latter variant when detecting the dependency via
  `pkg-config`, where we don't call
  `find_package_handle_standard_args()`.

  CMake sets these variable to `TRUE` (not `ON` or `1`). Replicate this
  for compatibility.

- libssh2-config.cmake: inherit default `LIBSSH2_USE_PKGCONFIG`.
  Follow-up to a3aa6b4ca8 #1525

- document variables consumed by `libssh2-config.cmake.in`.

- `libssh2-config.cmake`: fix to link to non-OpenSSL crypto backends.
  This is most likely not how this is supposed to be done, but better
  than failing.
  What's the canonical way to do this, and how OpenSSL and zlib does it
  is yet to be figured out.

- use `ZLIB::ZLIB` to reference zlib.
- use `IN ITEMS` where missed.
- harmonize variable dump output formats.

CMake `find_package` integration tests:

- extend to all crypto backends (was: OpenSSL).
- show libssh2 variables set by `find_package()`.
- stop building examples and tests for the consumed package.
  For performance.
- enable zlib, for coverage.
- be verbose when building the test targets.

ci/GHA:

- add packaged mbedTLS (2.x) build to Linux matrix.
- alphasort some tests.

Follow-up to d9c2e550ca #1460
Follow-up to 82b09f9b3a #1322

Closes #1534
2025-02-04 00:39:38 +01:00
Viktor Szakats
d9c2e550ca cmake: prefer find_dependency() in libssh2-config.cmake
CMake manual suggest using `find_dependency()` (over  `find_package()`)
in `config.cmake` scripts.

Ref: https://cmake.org/cmake/help/latest/module/CMakeFindDependencyMacro.html

Closes #1460
2024-09-28 11:41:48 +02:00
Viktor Szakats
570de0f23f cmake: rename mbedTLS and wolfSSL Find modules
To match the curl ones.

Cherry-picked from #1445
2024-08-18 12:57:04 +02:00
Jiwoo Park
82b09f9b3a cmake: use the imported target of FindOpenSSL module (#1322)
* Use the imported target of FindOpenSSL module
* Build libssh2 before test runner
* Use find_package() in the CMake config file
* Use find_dependency() rather than find_package()
* Install CMake module files and use them in the config file
* Use elseif() to choose the crypto backend
2024-03-28 23:30:20 +01:00
Viktor Szakats
932d6a3277 cmake: fix multiple include of libssh2 package
Also extend our integration test double inclusion. It will still not
catch this case, because that requires
`cmake_minimum_required(VERSION 3.18)` or higher.

Fixes:
```
CMake Error at .../lib/cmake/libssh2/libssh2-config.cmake:8 (add_library):
  add_library cannot create ALIAS target "libssh2::libssh2" because another
  target with the same name already exists.
Call Stack (most recent call first):
  CMakeLists.txt:24 (find_package)

CMake Error at .../lib/cmake/libssh2/libssh2-config.cmake:13 (add_library):
  add_library cannot create ALIAS target "Libssh2::libssh2" because another
  target with the same name already exists.
Call Stack (most recent call first):
  CMakeLists.txt:24 (find_package)
```

Test to reproduce:
```cmake
cmake_minimum_required(VERSION 3.18)  # must be 3.18 or higher

project(test)

find_package(libssh2 CONFIG)
find_package(libssh2 CONFIG)  # fails

add_executable(test main.c)
target_link_libraries(test libssh2::libssh2)
```

Ref: https://cmake.org/cmake/help/latest/release/3.18.html#other-changes
Ref: https://cmake.org/cmake/help/v3.18/policy/CMP0107.html

Assisted-by: Kai Pastor
Assisted-by: Harry Mallon
Ref: https://github.com/curl/curl/pull/11913

Closes #1216
2023-11-09 22:38:07 +00:00
Viktor Szakats
5453fc8035 cmake: add LIB_NAME variable
It holds the name `libssh2`. Mainly to document its uses, and also
syncing up with the same variable in libcurl.

Closes #1159
2023-08-13 10:20:57 +00:00
Viktor Szakats
c705ff3f37 cmake: add one missed PROJECT_NAME variable
Follow-up to 72fd25958a

Closes #1158
2023-08-11 23:09:52 +00:00
Viktor Szakats
72fd25958a cmake: replace libssh2 literals with PROJECT_NAME variable
Where applicable.

This also makes it more obvious which `libssh2` uses were referring
to the project itself.

Closes #1152
2023-08-09 15:47:49 +00:00
Viktor Szakats
2da13c13e1 cmake: re-add Libssh2:libssh2 for compatibiliy + lowercase namespace
- add `libssh2:libssh2` target that selects the shared lib if built,
  otherwise the static one.

- re-add `Libssh2:libssh2` target for compatibility with v1.10.0 and
  earlier. This is an alias for `libssh2:libssh2`.

- keep `libssh2:libssh2_shared` and `libssh2_libssh2_static` targets.

- allow using `find_package(libssh2)` in dependents as an alternative
  to `find_package(Libssh2)`.

Co-authored-by: Radek Brich
Suggested-by: Haowei Hsu

Fixes #1103
Fixes #731
Closes #1104
2023-06-25 19:14:18 +00:00