Skip to content

cmake: misc improvements, add LIBSSH2_USE_PKGCONFIG option - #1525

Closed
vszakats wants to merge 14 commits into
libssh2:masterfrom
vszakats:2-cm-misc
Closed

vszakats wants to merge 14 commits into
libssh2:masterfrom
vszakats:2-cm-misc

Conversation

@vszakats

@vszakats vszakats commented Jan 30, 2025 •

Copy link
Copy Markdown
Member
  • 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

Cleaner compiler command-lines, with absolute header paths.
Workaround for older mbedtls versions and non-cmake mbedtls builds
(as of mbedTLS 3.6.2) that don't emit an mbedcrypto.pc file.
Also update defaults for Android and Apple devices
This reverts commit e893b91.

It's used by wolfssl's wolfcrypto library, but there wasn't any
report missing this library.
@vszakats vszakats added the build label Jan 30, 2025
@vszakats vszakats closed this in a3aa6b4 Jan 30, 2025
@vszakats
vszakats deleted the 2-cm-misc branch January 30, 2025 22:37
vszakats added a commit that referenced this pull request Feb 3, 2025
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 a3aa6b4 #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 d9c2e55 #1460
Follow-up to 82b09f9 #1322

Closes #1534
vszakats added a commit to vszakats/libssh2 that referenced this pull request Apr 27, 2025
vszakats added a commit to vszakats/libssh2 that referenced this pull request Apr 27, 2025
vszakats added a commit to vszakats/libssh2 that referenced this pull request Apr 27, 2025
vszakats added a commit to vszakats/libssh2 that referenced this pull request Apr 27, 2025
vszakats added a commit to vszakats/libssh2 that referenced this pull request Apr 28, 2025
vszakats added a commit to vszakats/libssh2 that referenced this pull request May 6, 2025
vszakats added a commit that referenced this pull request May 7, 2025
- cmake: sync `-ftree-vrp` behavior with autotools.
- build: enable `-Wjump-misses-init` for GCC 4.5+.
  Credits-to: Marcel Raad
- packet: fix `-Wjump-misses-init` warnings.
  ```
  src/packet.c: In function ‘_libssh2_packet_add’:
  src/packet.c:671:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:920:31: note: ‘want_reply’ declared here
  src/packet.c:671:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:919:26: note: ‘len’ declared here
  src/packet.c:669:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:1121:31: note: ‘want_reply’ declared here
  src/packet.c:669:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:1120:26: note: ‘len’ declared here
  src/packet.c:669:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:1119:26: note: ‘channel’ declared here
  ```
- build: enable gcc-12/13+, clang-10+ picky warnings
- acinclude.m4: sync formatting/comments with curl.
- autotools: fix `-Wtrampolines` picky warning for gcc 4.x versions.
  Follow-up to 854cfa8 #1524
- cmake: enable `-Wall` for MSVC when `PICKY_COMPILER=ON`.
- MSVC: fix `-Wall` warnings.
  Seen on VS2015. Not seen on VS2022. Unknown for other versions.
  ```
  tests\test_simple.c(60): warning C4777: 'fprintf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type 'std::size_t'
  tests\test_simple.c(60): warning C4777: 'fprintf' : format string '%.*s' requires an argument of type 'int', but variadic argument 2 has type 'std::size_t'
  ```
- mbedtls: stop silencing warnings in 3rd-party header.
  Follow-up to a3aa6b4 #1525
- cmake: stop deleting `-W<n>` from `CMAKE_C_FLAGS` (MSVC)
  1. `CMAKE_C_FLAGS` may apply to other projects, and deleting/altering it
     may be unexpected.
  2. We pass `-W4`/`-Wall` internally now, which do override custom
     `-W<n>` options as tested with VS2008 and newer VS generators.

Closes #1588
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