1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00
Commit Graph

31 Commits

Author SHA1 Message Date
Viktor Szakats
c7541acd4b tests/cmake: suppress stderr in if expression
Silencing, seen with MSYS2 shell:
```
+ ln -s ../.. libssh2
ln: failed to create symbolic link 'libssh2': Too many levels of symbolic links
+ rm -rf libssh2
```
Ref: https://github.com/libssh2/libssh2/actions/runs/36978012817/job/110745989451#step:15:40

Closes #2642
2026-10-02 11:11:29 +02:00
Viktor Szakats
532ba6dcb7 tidy-up: miscellaneous
- cipher-chachapoly: replace magic number, drop {}.
- cipher-chachapoly: simplify.
- tests/cmake/test: constify.

Closes #2526
2026-08-14 02:07:18 +02:00
Viktor Szakats
3f718eaa90 tidy-up: comment and formatting fixes
Closes #2525
2026-08-14 01:58:59 +02:00
Viktor Szakats
6bf392f627 build: make examples a separate target, add quick-build for cmake
- cmake: do not build examples automatically. This makes the
  `BUILD_EXAMPLES=OFF` option redundant.
- cmake: build all examples with target `libssh2-examples`.
- cmake: build-test all examples with target `libssh2-examples-build`.
  To save linking them 23 times in CI.
- autotools: add root `examples` build target to build examples.
- CI: build examples in a separate step.
  (for autotools, make them not build in the main build step by
  configuring with `--disable-examples-build`)

To make the build more transparent, scale better, be faster in CI, also
syncing with curl.

Slight downsides after this patch:
- cmake and autotools have different default behavior for building
  examples.
- cmake needs an extra step to build examples. (an explicit option is
  planned to restore the old behavior.)

Also:
- sync BSD matrix build-tool naming with rest of jobs.

Closes #2276
2026-07-12 16:27:58 +02:00
Viktor Szakats
f2ec1f2f34 scripts: minor fixes and improvements
- pass `--` before passing input files.
- scripts/maketgz: robustify `rm` invocations.
- prefer `$(pwd)` or `$PWD`.
- tests/cmake/test.sh: dump configs to CI log.
- tests/gen_keys.sh: fix to skip DSA if missing.
- replace openssl with `base` and `*sum` tools.
- tests/ossfuzz/ossfuzz.sh: fix to add a space before `-j`.

Closes #2265
2026-07-09 14:47:52 +02:00
Viktor Szakats
86dcc0ae40 cmake: add CMake Config-based dependency detection for mbedTLS, wolfSSL
After limiting `find_package()`/`find_dependency()` calls to libssh2
local Find modules via the `MODULES` keyword, it became possible to
detect dependencies via CMake Configs from within those local Find
modules, by calling `find_package()` again with the `CONFIG` keyword.
This patch implements this. Then maps detection results to the result
variables and libssh2-specific imported targets the rest of the build
expects.

This adds CMake Configs as an alternative to the existing `pkg-config`
and `find_path()`/`find_library()` auto-detection methods.

Enabled by default for MSVC, outside vcpkg and when not cross-building.
To enable for other cases, or override the default, you can use
`-DLIBSSH2_USE_CMAKECONFIG=ON` or `OFF`.

When enabled, Config detection happens after `pkg-config` and before
`find_path()`/`find_library()`. Using CMake's built-in options, you may
also manually point to the absolute directory holding Config files:

`MbedTLS_DIR`, `wolfssl_DIR`

E.g. `-DMbedTLS_DIR=/path/to/mbedtls/lib/cmake/MbedTLS`

mbedTLS needs to be built with CMake for this to work. wolfSSL 5.9.0+
also supports it when it was built with autotools.

Experimental.

Refs:
8fce3e17e6
https://github.com/curl/curl/pull/20814
a56ab9dbc8
https://github.com/curl/curl/pull/21098

Follow-up to dd5f3fff39 #2262

Closes #2264
2026-07-09 14:47:52 +02:00
Viktor Szakats
dd5f3fff39 cmake: fix building with CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
By forcing local Find module invocations into `MODULE` mode. To avoid
accidentally picking up such a dependency via CMake Config-based
detection, which does not provide the expected imported target and make
the build fail.

It also prepares the scripts to alllow CMake Config support in local
Find modules.

Also:
- add reproducer in CI.
- allow custom options in CMake integration test script.

Refs:
91e06fde1b
https://github.com/curl/curl/pull/20784
https://github.com/curl/curl/issues/20729

Closes #2262
2026-07-09 12:23:54 +02:00
Viktor Szakats
2673970d2a version: add libssh2_build_options()
Returning for example (without newlines):
```
crypto:LibreSSL MD5:off MD5-PEM:off RIPEMD160:off DSA:off
RSA:on RSA-SHA1:on ECDSA:on ED25519:on ML-KEM:off
AES-CTR:on AES-CBC:on BLOWFISH:off RC4:off CAST:off
3DES:off zlib:on clear-memory:on debug-logging:on
```

To allow library users to find out these details, and add a searchable
static string to binaries with this information.

Possible values for `crypto`: `AWS-LC`, `BoringSSL`, `Libgcrypt`,
`LibreSSL`, `mbedTLS`, `OpenSSL`, `OpenSSL/1.1.1`, `OS400QC3`, `WinCNG`,
`wolfSSL`.

Also:
- replace manual translation of crypto engine enum to name in CMake
  integration test snippet with the new API.

Fixes #2161

Closes #2178
2026-07-03 16:12:22 +02:00
Viktor Szakats
509eac8b96 checksrc: extend to ossfuzz, reduce scope of exceptions
Replace a few calls in tests to reduce exceptions.

Closes #1998
2026-06-08 17:14:59 +02:00
Viktor Szakats
ac7b9b214a cmake: drop support for CMake 3.17 and older
Require CMake 3.18 (2020-07-15) or newer, up from 3.7 (2016-11-11) prior
to this patch.

This requirement also applies to the distributed `libssh2-config.cmake`.

To allow dropping compatibility code maintained for old versions, and to
use features which were unpractical in separate code paths. Also to make
testing, documentation and development easier, and builds faster due
CMake performance improvements over time.

CMake offers pre-built binaries for major platforms. They work without
an install step, just by unpacking and pointing the cmake command to
them. Making upgrades easy in many cases:
https://cmake.org/download/
https://cmake.org/files/
https://github.com/Kitware/CMake/releases

CMake 3.18 brings these feature as generally available when building or
consuming curl/libcurl:

LTO support, improved performance, `pkg-config` and interface target
support, `OBJECT` target (for faster libcurl builds), modern invocation
with `-S`/`-B` options, better support for custom linker options,
FetchContent, `--verbose` and `--install` options, `CMAKE_GENERATOR`
env, last but not least unity mode and Ninja generator.

Ref: https://github.com/curl/curl/discussions/18704

Closes #1839
2026-04-10 21:59:24 +02:00
Viktor Szakats
714fa876ee cmake: make the ExternalProject test work
By micromanaging the project dependency and its inclusion into the test
project. It feels like an awkward construct, but perhaps better than
nothing.

It's also fragile because it's a static build with no assistance from
the external project (curl in this case). Mitigated in test by disabling
all dependencies and some features.

Since there is no special core cmake logic to be tested here, in CI
the test is tested really. To keep CI jobs at minimum, only add 3 of
them, taking 26s in total. (All 6 would take 203s.)

Follow-up to 77df767784 #1589

Closes #1637
2025-08-07 10:38:18 +02:00
Viktor Szakats
694b9d964b cmake: add linter, fix issues
Ref: https://cmake-format.readthedocs.io/en/latest/cmake-lint.html
Ref: https://github.com/cheshirekow/cmake_format

Closes #1610
2025-06-11 07:09:10 +02:00
Viktor Szakats
f522f10c2f cmake: test integration with old cmake (v3.11.4 2018-03-28)
It was an exercise to run old cmake versions in CI and in the test suite.

It also revealed that 3.7.2 2017-01-13 is too old to consume libssh2 via
`find_package()` due to:
```
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.
Call Stack (most recent call first):
  CMakeLists.txt:27 (find_package)
```
The mitigation for this issue requires 3.11.

Also:
- rename a few existing envs to use the `TEST_` prefix.
- make the `find_package` test provider stage verbose.

Closes #1591
2025-05-08 15:05:07 +02:00
Viktor Szakats
4e78006c2b cmake: fix copy-paste typo in integration tests for old cmake
Follow-up to 77df767784 #1589

Closes #1592
2025-04-28 15:04:28 +02:00
Viktor Szakats
77df767784 cmake: extend integration tests
- ci/GHA: add cmake integration tests for Windows.
- ci/GHA: test `add_subdirectory` with Libgcrypt.
- make them run faster with prefill, unity, Ninja, omitting curl tool.
- add support for any build configuration.
- add old-cmake support with auto-detection.
- auto-detect Ninja.
- run consumer test apps to see if they work.
  Also show the cryptography backend.
- add support for Windows.
- make it more verbose.
- re-add `ExternalProject` cmake consumer test. It's broken.
- tidy up terminology.

Cherry-picked from #1581

Closes #1589
2025-04-27 13:46:30 +02:00
Viktor Szakats
8ea6ae7213 cmake: add comment to inegration test
To show which command is requiring a specific cmake version.

Follow-up to 7d5a4c7651 #1529
2025-03-19 12:08:32 +01:00
Viktor Szakats
669b51a076 cmake: prefer CMAKE_INSTALL_PREFIX over --prefix (in tests)
Closes #1542
2025-02-17 18:43:49 +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
7d5a4c7651 cmake: split integration tests into steps
Closes #1529
2025-01-31 04:19:25 +01:00
Viktor Szakats
1612807b9f cmake: make integration tests generator-agnostic, use GIT_SHALLOW
Closes #1523
2025-01-29 14:02:48 +01:00
Viktor Szakats
717c083653 cmake: bump policy_max, add FATAL_ERROR for old cmake versions
Closes #1510
2025-01-29 13:02:40 +01:00
Viktor Szakats
8011f9017b tests: delete CMake ExternalProject integration test
For no reason it broke when trying to silence a CMake deprecation
warning in #1510. Then when tested locally, it did not work either with
or without the patch in #1510.

I'm not sure, but existing implementation may have worked by accident
by re-using leftovers from the preceding two integration tests.

After spending a days trying to fix this, I declare defeat. If such
amount of time of testing, reading documentation, blog posts, variable
traces, logs, bug reports is not enough to make this work, or even
to understand how this should work, this seems like a lost cause.

CMake makes it impossible to cleanly query the properties of a target,
which would be essential for debugging. There are rough workarounds
with years of iteration, and those still don't work to this day:
https://stackoverflow.com/questions/32183975/how-to-print-all-the-properties-of-a-target-in-cmake

Copy-pasting an incantation from a blog post that made this work:
https://inhzus.io/posts/2023-12-01-cmake-external-project/
almost made it work, except that it had a workaround for a 10-year old
pending bug, another workaround for Ninja which required CMake 3.29,
with settings hard-wired, and explicitly configured in weird ways. But,
it still missed to pass the libssh2 library to the test target and
failed to link.

Then tried to pass the libssh2 lib the "usual" way via:
```
target_link_libraries(test PRIVATE libssh2)
```

That also did not work because CMake decided that the external libssh2
target is of "UTILITY" type, and errored with:
```
CMake Error at CMakeLists.txt:39 (target_link_libraries):
  Target "libssh2" of type UTILITY may not be linked into another target.
  One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.
```

This type property is read-only, and documentation has no mention of it,
or how to set it whatsoever:
https://cmake.org/cmake/help/latest/module/ExternalProject.html

libssh2's `docs/INSTALL_CMAKE.md` mentions ExternalProject as a way to
use libssh2. Added there with the initial CMake commit. We should
probably delete it from there.

This consumption method has a single mention in public issues:
https://github.com/libssh2/libssh2/issues/1116

Closes #1522
2025-01-29 12:45:07 +01:00
Viktor Szakats
389d70bfeb cmake: tidy up -j make option in integration tests (#1509) 2025-01-04 23:24:51 +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
fc00bdd7f1 cmake: simplify showing CMake version
Move it to `CMakeLists.txt`. Drop `cmake --version` commands.

Credit to the `zlib-ng` project for the idea:
61e181c8ae/CMakeLists.txt (L7)

Closes #1203
2023-10-07 16:56:32 +00:00
Viktor Szakats
2cd2f40e37 tests: show cmake version used in integration tests
Closes #1201
2023-10-07 11:02:23 +00:00
Viktor Szakats
4a64ca1430 cmake: tidy-up foreach() syntax
Use `IN LISTS` and `IN ITEMS`. This appears to be the preferred way
within CMake's own source code and possibly improves readability.

Fixup a side-effect of `IN LISTS`, where it retains empty values at
the end of the list, as opposed to the syntax used before, which
dropped it. In our case this happened with lines read from a text
file via `file(READ)`.

https://cmake.org/cmake/help/v3.7/command/foreach.html

Closes #1180
2023-08-28 22:57:02 +00:00
Viktor Szakats
a20572e9af cmake: also test for libssh2_VERSION
Cherry-picked from #1175
2023-08-23 10:54:23 +00:00
Viktor Szakats
e61987a3bf tests: formatting and tidy-ups
- Dockerfile: use standard sep with `sed`
- Dockerfile: use single quotes in shell command
- appveyor.yml: use long-form option with `choco`
- tests/cmake: add language to test project
- reuse.yml: fix indentation
  ```
  $ yamllint reuse.yml
  reuse.yml
    [...]
    11:5      error    wrong indentation: expected 6 but found 4  (indentation)
    15:5      error    wrong indentation: expected 6 but found 4  (indentation)
    [...]
    27:5      error    wrong indentation: expected 6 but found 4  (indentation)
  ```

Cherry-picked from #1175
2023-08-23 10:53:53 +00:00
Viktor Szakats
aeaefaf6cc cmake: add ExternalProject integration test
- via `ExternalProject_Add()`:
  https://cmake.org/cmake/help/latest/module/ExternalProject.html
  (as documented in `docs/INSTALL_CMAKE.md`)

- also make `FetchContent` fetch from local repo instead of live master.

Closes #1171
2023-08-18 09:47:09 +00:00
Viktor Szakats
8715c3d51b cmake: add integration tests
Add a small project to test dependent/downstream CMake build using
libssh2. Also added to the GHA CI, and you can also run it locally with
`tests/cmake/test.sh`.

Test three methods of integrating libssh2 into a project:
- via `find_package()`:
  https://cmake.org/cmake/help/latest/command/find_package.html
- via `add_subdirectory()`:
  https://cmake.org/cmake/help/latest/command/add_subdirectory.html
- via `FetchContent`:
  https://cmake.org/cmake/help/latest/module/FetchContent.html

Closes #1170
2023-08-17 09:01:08 +00:00