1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-17 04:22:32 +03:00
Commit Graph

15 Commits

Author SHA1 Message Date
Viktor Szakats
3969991b68 cmake: small tidy-ups
- say "Absolute path" for include and library paths in Find modules.
- flatten an if tree.
- fix a typo in comment.

Closes #1732
2025-10-21 01:09:36 +02:00
Viktor Szakats
3ae5ae3248 cmake: whitespace in Find modules [ci skip]
Cherry-picked from #1581
2025-04-25 15:04:58 +02:00
Viktor Szakats
a0d8529b08 cmake: fix target interfaces for old CMake versions
- 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 df0563a857 #1535

Closes #1571
2025-04-14 02:13:37 +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
a3aa6b4ca8 cmake: misc improvements, add LIBSSH2_USE_PKGCONFIG option
- show platform flags (via curl).
- add `LIBSSH2_USE_PKGCONFIG` option to control whether to use
  `pkg-config` to find dependencies.
- set `.pc` names withing the Find modules.
- add `mbedcrypto` to `libssh2.pc` only when detected via `pkg-config`.
  Workaround for older mbedtls versions and non-CMake mbedTLS builds
  (as of mbedTLS 3.6.2) that don't emit an `mbedcrypto.pc` file.
- set header paths relative to the project root (tidy-up).
- use `-isystem` for crypto backend and zlib header paths.
  To match autotools.
- sync header path order with autotools.
- rename local variables to underscore-lowercase.
- minor tidy-ups.

Cherry-picked from #1484
Closes #1525
2025-01-30 23:36:39 +01:00
Viktor Szakats
d4e43c7b69 cmake/Find*: clear package version after pkg-config detection
`pkg_check_modules()` seems to leave `<PACKAGE>_VERSION` defined with an
empty value, if the package is not found.

When the package is also not found in the fallback branch,
`find_package_handle_standard_args()` logs and error message. In this
message it includes the bogus empty value as: `(found version "")`:
```
  Could NOT find Libgcrypt (missing: LIBGCRYPT_INCLUDE_DIR LIBGCRYPT_LIBRARY)
  (found version "")
```

Clear the version number to avoid the confusion:
```
  Could NOT find Libgcrypt (missing: LIBGCRYPT_INCLUDE_DIR LIBGCRYPT_LIBRARY)
```

Seen with CMake v3.30.3 and 3.30.5.

Closes #1479
2024-10-28 11:35:41 +01:00
Viktor Szakats
efad5f9076 cmake: decorate comments in Find modules
Make them Markdown-like and make them pass spellcheckers better.

Closes #1477
2024-10-28 11:35:40 +01:00
Viktor Szakats
45064137ac cmake: sync and improve Find modules, add pkg-config native detection
- sync code between Find modules.
- wolfssl: replace `pkg-config` hints with native detection.
- libgcrypt, mbedtls: add `pkg-config`-based native detection.
- libgcrypt: add version detection.
- limit `pkg-config` use for `UNIX`, vcpkg, and non-cross MinGW builds,
  and builds with no manual customization via `*_INCLUDE_DIR` or
  `*_LIBRARY`.
- replace and sync Find module header comments.
- ci: delete manual mbedTLS config that's now redundant.

Based on similar work done in curl.

Second attempt at #1420
Closes #1445
2024-10-05 20:59:27 +02:00
Viktor Szakats
a0310699f5 cmake: sync formatting in cmake/Find* modules 2024-07-03 22:27:18 +02:00
Viktor Szakats
8788bb90a8 cmake: style tidy-up (more)
Follow-up to 3fa5282d62 #1166
Closes #1365
2024-04-14 01:52:11 +00:00
Daniel Stenberg
f6aa31f48f provide SPDX identifiers
- All files have prominent copyright and SPDX identifier
- If not embedded in the file, in the .reuse/dep5 file
- All used licenses are in LICENSES/ (not shipped in tarballs)
- A new REUSE CI job verify that all files are OK

Assisted-by: Viktor Szakats

Closes #1084
2023-06-07 08:18:55 +02:00
Viktor Szakats
187d89bb07 copyright: remove years from copyright headers
Also:
- uppercase `(C)`.
- add missing 'All rights reserved.' lines.
- drop duplicate 'Author' lines.
- add copyright headers where missing.
- enable copyright header check in checksrc.

Reasons for deleting years (copied as-is from curl):
- they are mostly pointless in all major jurisdictions
- many big corporations and projects already don't use them
- saves us from pointless churn
- git keeps history for us
- the year range is kept in COPYING

Closes #1082
2023-06-04 19:19:16 +00:00
Viktor Szakats
31fb8860db build: more fixes and tidy-up (mostly for Windows)
- cmake: always link `ws2_32` on Windows. Also add it to `libssh2.pc`.

   Fixes #745

- agent: fix gcc compiler warning:
   `src/agent.c:296:35: warning: 'snprintf' output truncated before the last format character [-Wformat-truncation=]`

- autotools: fix `EVP_aes_128_ctr` detection with binutils `ld`

   The prerequisite for a successful detection is setting
   `LIBS=-lbcrypt` if the chosen openssl-compatible library requires
   it, e.g. libressl, or quictls/openssl built with
   `-DUSE_BCRYPTGENRANDOM`.

   With llvm `lld`, detection works out of the box. With binutils `ld`,
   it does not. The reason is `ld`s world-famous pickiness with lib
   order.

   To fix it, we pass all custom libs before and after the TLS libs.
   This ugly hack makes `ld` happy and detection succeed.

- agent: fix Windows-specific warning:
  `src/agent.c:318:10: warning: implicit conversion loses integer precision: 'LRESULT' (aka 'long long') to 'int' [-Wshorten-64-to-32]`

- src: fix llvm/clang compiler warning:
  `src/libssh2_priv.h:987:28: warning: variadic macros are a C99 feature [-Wvariadic-macros]`

- src: support `inline` with `__GNUC__` (llvm/clang and gcc), fixing:
  ```
  src/libssh2_priv.h:990:8: warning: extension used [-Wlanguage-extension-token]
  static inline void
         ^
  ```

- blowfish: support `inline` keyword with MSVC.

   Also switch to `__inline__` (from `__inline`) for `__GNUC__`:
     https://gcc.gnu.org/onlinedocs/gcc/Inline.html
     https://clang.llvm.org/docs/UsersManual.html#differences-between-various-standard-modes

- example/test: fix MSVC compiler warnings:

  - `example\direct_tcpip.c(209): warning C4244: 'function': conversion from 'unsigned int' to 'u_short', possible loss of data`
  - `tests\session_fixture.c(96): warning C4013: 'getcwd' undefined; assuming extern returning int`
  - `tests\session_fixture.c(100): warning C4013: 'chdir' undefined; assuming extern returning int`

- delete unused macros:
  - `HAVE_SOCKET`
  - `HAVE_INET_ADDR`
  - `NEED_LIB_NSL`
  - `NEED_LIB_SOCKET`
  - `HAVE_NTSTATUS_H`
  - `HAVE_NTDEF_H`

- build: delete stale zlib/openssl version numbers from path defaults.

- cmake: convert tabs to spaces, add newline at EOFs.

Closes #811
2023-03-07 15:14:22 +00:00
Alexander Lamaison
6bf8983368 CMake build system.
Tested:
 - Windows:
    - Visual C++ 2005/2008/2010/2012/2013/MinGW-w64
    - static/shared
    - 32/64-bit
    - OpenSSL/WinCNG
    - Without zlib
 - Linux:
    - GCC 4.6.3/Clang 3.4
    - static/shared
    - 32/64-bit
    - OpenSSL/Libgcrypt
    - With/Without zlib
 - MacOS X
    - AppleClang 6.0.0
    - static
    - 64-bit
    - OpenSSL
    - Without zlib

Conflicts:
	README
2015-03-12 22:48:38 +00:00