mirror of
https://github.com/libssh2/libssh2.git
synced 2026-10-24 03:48:58 +03:00
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
This commit is contained in:
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
@@ -192,6 +192,13 @@ jobs:
|
||||
if: ${{ !contains(matrix.image, 'windows') }} # MSYS2 wolfSSL package not built with the OpenSSL compatibility option
|
||||
run: ./tests/cmake/test.sh find_package -DCRYPTO_BACKEND=wolfSSL
|
||||
|
||||
- name: 'via find_package (PREFER_CONFIG=ON)'
|
||||
if: ${{ contains(matrix.image, 'windows') }}
|
||||
run: |
|
||||
export TEST_CMAKE_FLAGS_PROVIDER='-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON'
|
||||
export TEST_CMAKE_FLAGS_CONSUMER="${TEST_CMAKE_FLAGS_PROVIDER}"
|
||||
./tests/cmake/test.sh find_package -DCRYPTO_BACKEND=mbedTLS
|
||||
|
||||
- name: 'via ExternalProject (old cmake)'
|
||||
if: ${{ contains(matrix.image, 'ubuntu') }}
|
||||
run: |
|
||||
|
||||
@@ -439,7 +439,7 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
|
||||
endif()
|
||||
|
||||
if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND)
|
||||
find_package(WolfSSL ${_specific_crypto_requirement})
|
||||
find_package(WolfSSL MODULE ${_specific_crypto_requirement})
|
||||
if(WOLFSSL_FOUND)
|
||||
if(WOLFSSL_VERSION VERSION_LESS 5.4.0)
|
||||
message(FATAL_ERROR "wolfSSL 5.4.0 or greater required")
|
||||
@@ -456,7 +456,7 @@ if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND)
|
||||
endif()
|
||||
|
||||
if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND)
|
||||
find_package(Libgcrypt ${_specific_crypto_requirement})
|
||||
find_package(Libgcrypt MODULE ${_specific_crypto_requirement})
|
||||
if(LIBGCRYPT_FOUND)
|
||||
set(CRYPTO_BACKEND "Libgcrypt")
|
||||
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_LIBGCRYPT")
|
||||
@@ -465,7 +465,7 @@ if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND)
|
||||
endif()
|
||||
|
||||
if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND)
|
||||
find_package(MbedTLS ${_specific_crypto_requirement})
|
||||
find_package(MbedTLS MODULE ${_specific_crypto_requirement})
|
||||
if(MBEDTLS_FOUND)
|
||||
if(MBEDTLS_VERSION VERSION_LESS 3.1.0)
|
||||
message(FATAL_ERROR "mbedTLS 3.1.0 or greater required")
|
||||
|
||||
@@ -18,13 +18,13 @@ set(_libssh2_libs "")
|
||||
if("@CRYPTO_BACKEND@" STREQUAL "OpenSSL")
|
||||
find_dependency(OpenSSL)
|
||||
elseif("@CRYPTO_BACKEND@" STREQUAL "wolfSSL")
|
||||
find_dependency(WolfSSL)
|
||||
find_dependency(WolfSSL MODULE)
|
||||
list(APPEND _libssh2_libs libssh2::wolfssl)
|
||||
elseif("@CRYPTO_BACKEND@" STREQUAL "Libgcrypt")
|
||||
find_dependency(Libgcrypt)
|
||||
find_dependency(Libgcrypt MODULE)
|
||||
list(APPEND _libssh2_libs libssh2::libgcrypt)
|
||||
elseif("@CRYPTO_BACKEND@" STREQUAL "mbedTLS")
|
||||
find_dependency(MbedTLS)
|
||||
find_dependency(MbedTLS MODULE)
|
||||
list(APPEND _libssh2_libs libssh2::mbedcrypto)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -74,13 +74,13 @@ if [ "${mode}" = 'all' ] || [ "${mode}" = 'find_package' ]; then
|
||||
bldp='bld-libssh2'
|
||||
prefix="${PWD}/${bldp}/_pkg"
|
||||
rm -rf "${bldp}"
|
||||
"${cmake_provider}" -B "${bldp}" -S "${src}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} "$@" \
|
||||
"${cmake_provider}" -B "${bldp}" -S "${src}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} ${TEST_CMAKE_FLAGS_PROVIDER:-} "$@" \
|
||||
-DCMAKE_INSTALL_PREFIX="${prefix}"
|
||||
"${cmake_provider}" --build "${bldp}" --verbose
|
||||
"${cmake_provider}" --install "${bldp}"
|
||||
bldc='bld-find_package'
|
||||
rm -rf "${bldc}"
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} \
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} ${TEST_CMAKE_FLAGS_CONSUMER:-} \
|
||||
-DTEST_INTEGRATION_MODE=find_package \
|
||||
-DCMAKE_PREFIX_PATH="${prefix}/lib/cmake/libssh2"
|
||||
"${cmake_consumer}" --build "${bldc}" --verbose
|
||||
|
||||
Reference in New Issue
Block a user