mirror of
https://github.com/libssh2/libssh2.git
synced 2025-12-24 19:37:49 +03:00
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
This commit is contained in:
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
@@ -50,15 +50,25 @@ jobs:
|
||||
run: ./ci/spellcheck.sh
|
||||
|
||||
build_integration:
|
||||
name: 'integration'
|
||||
runs-on: ubuntu-latest
|
||||
name: 'integration on ${{ matrix.image }}'
|
||||
runs-on: ${{ matrix.image }}
|
||||
timeout-minutes: 5
|
||||
env:
|
||||
CC: clang
|
||||
MAKEFLAGS: -j5
|
||||
CMAKE_GENERATOR: Ninja
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
image: [ubuntu-latest, macos-latest]
|
||||
steps:
|
||||
- name: 'install prereqs'
|
||||
run: sudo apt-get -o Dpkg::Use-Pty=0 install libgcrypt-dev libssl-dev libmbedtls-dev libwolfssl-dev
|
||||
- name: 'install packages'
|
||||
run: |
|
||||
if [[ '${{ matrix.image }}' = *'ubuntu'* ]]; then
|
||||
sudo apt-get -o Dpkg::Use-Pty=0 install ninja-build libgcrypt-dev libssl-dev libmbedtls-dev libwolfssl-dev
|
||||
else
|
||||
brew install ninja libgcrypt openssl mbedtls wolfssl
|
||||
fi
|
||||
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
@@ -52,6 +52,34 @@ include(CheckNonblockingSocketSupport)
|
||||
|
||||
project(libssh2 C)
|
||||
|
||||
function(libssh2_dumptargetprops _target) # Dump all target properties
|
||||
if(TARGET "${_target}")
|
||||
execute_process(COMMAND "${CMAKE_COMMAND}" "--help-property-list" OUTPUT_VARIABLE _cmake_property_list)
|
||||
string(REPLACE "\n" ";" _cmake_property_list "${_cmake_property_list}")
|
||||
list(REMOVE_DUPLICATES _cmake_property_list)
|
||||
list(REMOVE_ITEM _cmake_property_list "")
|
||||
list(APPEND _cmake_property_list "LIBSSH2_PC_MODULES")
|
||||
foreach(_prop IN LISTS _cmake_property_list)
|
||||
if(_prop MATCHES "<CONFIG>")
|
||||
foreach(_config IN ITEMS "DEBUG" "RELEASE" "MINSIZEREL" "RELWITHDEBINFO")
|
||||
string(REPLACE "<CONFIG>" "${_config}" _propconfig "${_prop}")
|
||||
get_property(_is_set TARGET "${_target}" PROPERTY "${_propconfig}" SET)
|
||||
if(_is_set)
|
||||
get_target_property(_val "${_target}" "${_propconfig}")
|
||||
message("${_target}.${_propconfig} = '${_val}'")
|
||||
endif()
|
||||
endforeach()
|
||||
else()
|
||||
get_property(_is_set TARGET "${_target}" PROPERTY "${_prop}" SET)
|
||||
if(_is_set)
|
||||
get_target_property(_val "${_target}" "${_prop}")
|
||||
message("${_target}.${_prop} = '${_val}'")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(libssh2_dumpvars) # Dump all defined variables with their values
|
||||
message("::group::CMake Variable Dump")
|
||||
get_cmake_property(_vars VARIABLES)
|
||||
@@ -153,8 +181,6 @@ include(PickyWarnings)
|
||||
|
||||
set(LIBSSH2_LIBS_SOCKET "")
|
||||
set(LIBSSH2_LIBS "")
|
||||
set(LIBSSH2_LIBDIRS "")
|
||||
set(LIBSSH2_PC_REQUIRES_PRIVATE "")
|
||||
|
||||
# Add socket libraries
|
||||
if(WIN32)
|
||||
@@ -371,15 +397,12 @@ if(CRYPTO_BACKEND)
|
||||
endif()
|
||||
|
||||
if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
|
||||
|
||||
find_package(OpenSSL ${_specific_crypto_requirement})
|
||||
|
||||
find_package(OpenSSL ${_specific_crypto_requirement} COMPONENTS Crypto)
|
||||
if(OPENSSL_FOUND)
|
||||
set(CRYPTO_BACKEND "OpenSSL")
|
||||
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_OPENSSL")
|
||||
set(CRYPTO_BACKEND_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})
|
||||
list(APPEND LIBSSH2_LIBS OpenSSL::Crypto)
|
||||
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "libcrypto")
|
||||
set_target_properties(OpenSSL::Crypto PROPERTIES LIBSSH2_PC_MODULES "libcrypto")
|
||||
|
||||
if(WIN32)
|
||||
# Statically linking to OpenSSL requires crypt32 for some Windows APIs.
|
||||
@@ -412,24 +435,11 @@ 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})
|
||||
|
||||
if(WOLFSSL_FOUND)
|
||||
set(CRYPTO_BACKEND "wolfSSL")
|
||||
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WOLFSSL")
|
||||
set(CRYPTO_BACKEND_INCLUDE_DIR ${WOLFSSL_INCLUDE_DIRS})
|
||||
list(APPEND LIBSSH2_LIBS ${WOLFSSL_LIBRARIES})
|
||||
list(APPEND LIBSSH2_LIBDIRS ${WOLFSSL_LIBRARY_DIRS})
|
||||
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE ${WOLFSSL_PC_REQUIRES})
|
||||
link_directories(${WOLFSSL_LIBRARY_DIRS})
|
||||
if(WOLFSSL_CFLAGS)
|
||||
string(APPEND CMAKE_C_FLAGS " ${WOLFSSL_CFLAGS}")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND LIBSSH2_LIBS "crypt32")
|
||||
endif()
|
||||
list(APPEND LIBSSH2_LIBS libssh2::wolfssl)
|
||||
|
||||
find_package(ZLIB)
|
||||
if(ZLIB_FOUND)
|
||||
@@ -439,38 +449,20 @@ 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})
|
||||
|
||||
if(LIBGCRYPT_FOUND)
|
||||
set(CRYPTO_BACKEND "Libgcrypt")
|
||||
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_LIBGCRYPT")
|
||||
set(CRYPTO_BACKEND_INCLUDE_DIR ${LIBGCRYPT_INCLUDE_DIRS})
|
||||
list(APPEND LIBSSH2_LIBS ${LIBGCRYPT_LIBRARIES})
|
||||
list(APPEND LIBSSH2_LIBDIRS ${LIBGCRYPT_LIBRARY_DIRS})
|
||||
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE ${LIBGCRYPT_PC_REQUIRES})
|
||||
link_directories(${LIBGCRYPT_LIBRARY_DIRS})
|
||||
if(LIBGCRYPT_CFLAGS)
|
||||
string(APPEND CMAKE_C_FLAGS " ${LIBGCRYPT_CFLAGS}")
|
||||
endif()
|
||||
list(APPEND LIBSSH2_LIBS libssh2::libgcrypt)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND)
|
||||
|
||||
find_package(MbedTLS ${_specific_crypto_requirement})
|
||||
|
||||
if(MBEDTLS_FOUND)
|
||||
set(CRYPTO_BACKEND "mbedTLS")
|
||||
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_MBEDTLS")
|
||||
set(CRYPTO_BACKEND_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIRS})
|
||||
list(APPEND LIBSSH2_LIBS ${MBEDTLS_LIBRARIES})
|
||||
list(APPEND LIBSSH2_LIBDIRS ${MBEDTLS_LIBRARY_DIRS})
|
||||
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE ${MBEDTLS_PC_REQUIRES})
|
||||
link_directories(${MBEDTLS_LIBRARY_DIRS})
|
||||
if(MBEDTLS_CFLAGS)
|
||||
string(APPEND CMAKE_C_FLAGS " ${MBEDTLS_CFLAGS}")
|
||||
endif()
|
||||
list(APPEND LIBSSH2_LIBS libssh2::mbedcrypto)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -480,7 +472,6 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND)
|
||||
if(WIN32)
|
||||
set(CRYPTO_BACKEND "WinCNG")
|
||||
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WINCNG")
|
||||
set(CRYPTO_BACKEND_INCLUDE_DIR "")
|
||||
list(APPEND LIBSSH2_LIBS "crypt32" "bcrypt")
|
||||
|
||||
option(ENABLE_ECDSA_WINCNG "Enable WinCNG ECDSA support (requires Windows 10 or later)" OFF)
|
||||
|
||||
@@ -9,29 +9,27 @@
|
||||
# - `LIBGCRYPT_INCLUDE_DIR`: The Libgcrypt include directory.
|
||||
# - `LIBGCRYPT_LIBRARY`: Path to `libgcrypt` library.
|
||||
#
|
||||
# Result variables:
|
||||
# Defines:
|
||||
#
|
||||
# - `LIBGCRYPT_FOUND`: System has Libgcrypt.
|
||||
# - `LIBGCRYPT_INCLUDE_DIRS`: The Libgcrypt include directories.
|
||||
# - `LIBGCRYPT_LIBRARIES`: The Libgcrypt library names.
|
||||
# - `LIBGCRYPT_LIBRARY_DIRS`: The Libgcrypt library directories.
|
||||
# - `LIBGCRYPT_PC_REQUIRES`: The Libgcrypt pkg-config packages.
|
||||
# - `LIBGCRYPT_CFLAGS`: Required compiler flags.
|
||||
# - `LIBGCRYPT_VERSION`: Version of Libgcrypt.
|
||||
# - `libssh2::libgcrypt`: libgcrypt library target.
|
||||
|
||||
set(LIBGCRYPT_PC_REQUIRES "libgcrypt")
|
||||
set(_libgcrypt_pc_requires "libgcrypt")
|
||||
|
||||
if(LIBSSH2_USE_PKGCONFIG AND
|
||||
NOT DEFINED LIBGCRYPT_INCLUDE_DIR AND
|
||||
NOT DEFINED LIBGCRYPT_LIBRARY)
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(LIBGCRYPT ${LIBGCRYPT_PC_REQUIRES})
|
||||
pkg_check_modules(_libgcrypt ${_libgcrypt_pc_requires})
|
||||
endif()
|
||||
|
||||
if(LIBGCRYPT_FOUND)
|
||||
if(_libgcrypt_FOUND)
|
||||
set(Libgcrypt_FOUND TRUE)
|
||||
string(REPLACE ";" " " LIBGCRYPT_CFLAGS "${LIBGCRYPT_CFLAGS}")
|
||||
message(STATUS "Found Libgcrypt (via pkg-config): ${LIBGCRYPT_INCLUDE_DIRS} (found version \"${LIBGCRYPT_VERSION}\")")
|
||||
set(LIBGCRYPT_FOUND TRUE)
|
||||
set(LIBGCRYPT_VERSION ${_libgcrypt_VERSION})
|
||||
string(REPLACE ";" " " _libgcrypt_CFLAGS "${_libgcrypt_CFLAGS}")
|
||||
message(STATUS "Found Libgcrypt (via pkg-config): ${_libgcrypt_INCLUDE_DIRS} (found version \"${LIBGCRYPT_VERSION}\")")
|
||||
else()
|
||||
find_path(LIBGCRYPT_INCLUDE_DIR NAMES "gcrypt.h")
|
||||
find_library(LIBGCRYPT_LIBRARY NAMES "gcrypt" "libgcrypt")
|
||||
@@ -56,9 +54,26 @@ else()
|
||||
)
|
||||
|
||||
if(LIBGCRYPT_FOUND)
|
||||
set(LIBGCRYPT_INCLUDE_DIRS ${LIBGCRYPT_INCLUDE_DIR})
|
||||
set(LIBGCRYPT_LIBRARIES ${LIBGCRYPT_LIBRARY})
|
||||
set(_libgcrypt_INCLUDE_DIRS ${LIBGCRYPT_INCLUDE_DIR})
|
||||
set(_libgcrypt_LIBRARIES ${LIBGCRYPT_LIBRARY})
|
||||
endif()
|
||||
|
||||
mark_as_advanced(LIBGCRYPT_INCLUDE_DIR LIBGCRYPT_LIBRARY)
|
||||
endif()
|
||||
|
||||
if(LIBGCRYPT_FOUND)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.13)
|
||||
link_directories(${_libgcrypt_LIBRARY_DIRS})
|
||||
endif()
|
||||
|
||||
if(NOT TARGET libssh2::libgcrypt)
|
||||
add_library(libssh2::libgcrypt INTERFACE IMPORTED)
|
||||
set_target_properties(libssh2::libgcrypt PROPERTIES
|
||||
VERSION "${LIBGRCYPT_VERSION}"
|
||||
LIBSSH2_PC_MODULES "${_libgcrypt_pc_requires}"
|
||||
INTERFACE_COMPILE_OPTIONS "${_libgcrypt_CFLAGS}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_libgcrypt_INCLUDE_DIRS}"
|
||||
INTERFACE_LINK_DIRECTORIES "${_libgcrypt_LIBRARY_DIRS}"
|
||||
INTERFACE_LINK_LIBRARIES "${_libgcrypt_LIBRARIES}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -9,31 +9,29 @@
|
||||
# - `MBEDTLS_INCLUDE_DIR`: The mbedTLS include directory.
|
||||
# - `MBEDCRYPTO_LIBRARY`: Path to `mbedcrypto` library.
|
||||
#
|
||||
# Result variables:
|
||||
# Defines:
|
||||
#
|
||||
# - `MBEDTLS_FOUND`: System has mbedTLS.
|
||||
# - `MBEDTLS_INCLUDE_DIRS`: The mbedTLS include directories.
|
||||
# - `MBEDTLS_LIBRARIES`: The mbedTLS library names.
|
||||
# - `MBEDTLS_LIBRARY_DIRS`: The mbedTLS library directories.
|
||||
# - `MBEDTLS_PC_REQUIRES`: The mbedTLS pkg-config packages.
|
||||
# - `MBEDTLS_CFLAGS`: Required compiler flags.
|
||||
# - `MBEDTLS_VERSION`: Version of mbedTLS.
|
||||
# - `libssh2::mbedcrypto`: mbedcrypto library target.
|
||||
|
||||
set(MBEDTLS_PC_REQUIRES "mbedcrypto")
|
||||
set(_mbedtls_pc_requires "mbedcrypto")
|
||||
|
||||
if(LIBSSH2_USE_PKGCONFIG AND
|
||||
NOT DEFINED MBEDTLS_INCLUDE_DIR AND
|
||||
NOT DEFINED MBEDCRYPTO_LIBRARY)
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(MBEDTLS ${MBEDTLS_PC_REQUIRES})
|
||||
pkg_check_modules(_mbedtls ${_mbedtls_pc_requires})
|
||||
endif()
|
||||
|
||||
if(MBEDTLS_FOUND)
|
||||
if(_mbedtls_FOUND)
|
||||
set(MbedTLS_FOUND TRUE)
|
||||
string(REPLACE ";" " " MBEDTLS_CFLAGS "${MBEDTLS_CFLAGS}")
|
||||
message(STATUS "Found MbedTLS (via pkg-config): ${MBEDTLS_INCLUDE_DIRS} (found version \"${MBEDTLS_VERSION}\")")
|
||||
set(MBEDTLS_FOUND TRUE)
|
||||
set(MBEDTLS_VERSION ${_mbedtls_VERSION})
|
||||
string(REPLACE ";" " " _mbedtls_CFLAGS "${_mbedtls_CFLAGS}")
|
||||
message(STATUS "Found MbedTLS (via pkg-config): ${_mbedtls_INCLUDE_DIRS} (found version \"${MBEDTLS_VERSION}\")")
|
||||
else()
|
||||
set(MBEDTLS_PC_REQUIRES "")
|
||||
set(_mbedtls_pc_requires "")
|
||||
|
||||
find_path(MBEDTLS_INCLUDE_DIR NAMES "mbedtls/version.h")
|
||||
find_library(MBEDCRYPTO_LIBRARY NAMES "mbedcrypto" "libmbedcrypto")
|
||||
@@ -68,9 +66,26 @@ else()
|
||||
)
|
||||
|
||||
if(MBEDTLS_FOUND)
|
||||
set(MBEDTLS_INCLUDE_DIRS ${MBEDTLS_INCLUDE_DIR})
|
||||
set(MBEDTLS_LIBRARIES ${MBEDCRYPTO_LIBRARY})
|
||||
set(_mbedtls_INCLUDE_DIRS ${MBEDTLS_INCLUDE_DIR})
|
||||
set(_mbedtls_LIBRARIES ${MBEDCRYPTO_LIBRARY})
|
||||
endif()
|
||||
|
||||
mark_as_advanced(MBEDTLS_INCLUDE_DIR MBEDCRYPTO_LIBRARY)
|
||||
endif()
|
||||
|
||||
if(MBEDTLS_FOUND)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.13)
|
||||
link_directories(${_mbedtls_LIBRARY_DIRS})
|
||||
endif()
|
||||
|
||||
if(NOT TARGET libssh2::mbedcrypto)
|
||||
add_library(libssh2::mbedcrypto INTERFACE IMPORTED)
|
||||
set_target_properties(libssh2::mbedcrypto PROPERTIES
|
||||
VERSION "${MBEDTLS_VERSION}"
|
||||
LIBSSH2_PC_MODULES "${_mbedtls_pc_requires}"
|
||||
INTERFACE_COMPILE_OPTIONS "${_mbedtls_CFLAGS}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_mbedtls_INCLUDE_DIRS}"
|
||||
INTERFACE_LINK_DIRECTORIES "${_mbedtls_LIBRARY_DIRS}"
|
||||
INTERFACE_LINK_LIBRARIES "${_mbedtls_LIBRARIES}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -9,29 +9,27 @@
|
||||
# - `WOLFSSL_INCLUDE_DIR`: The wolfSSL include directory.
|
||||
# - `WOLFSSL_LIBRARY`: Path to `wolfssl` library.
|
||||
#
|
||||
# Result variables:
|
||||
# Defines:
|
||||
#
|
||||
# - `WOLFSSL_FOUND`: System has wolfSSL.
|
||||
# - `WOLFSSL_INCLUDE_DIRS`: The wolfSSL include directories.
|
||||
# - `WOLFSSL_LIBRARIES`: The wolfSSL library names.
|
||||
# - `WOLFSSL_LIBRARY_DIRS`: The wolfSSL library directories.
|
||||
# - `WOLFSSL_PC_REQUIRES`: The wolfSSL pkg-config packages.
|
||||
# - `WOLFSSL_CFLAGS`: Required compiler flags.
|
||||
# - `WOLFSSL_VERSION`: Version of wolfSSL.
|
||||
# - `libssh2::wolfssl`: wolfssl library target.
|
||||
|
||||
set(WOLFSSL_PC_REQUIRES "wolfssl")
|
||||
set(_wolfssl_pc_requires "wolfssl")
|
||||
|
||||
if(LIBSSH2_USE_PKGCONFIG AND
|
||||
NOT DEFINED WOLFSSL_INCLUDE_DIR AND
|
||||
NOT DEFINED WOLFSSL_LIBRARY)
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(WOLFSSL ${WOLFSSL_PC_REQUIRES})
|
||||
pkg_check_modules(_wolfssl ${_wolfssl_pc_requires})
|
||||
endif()
|
||||
|
||||
if(WOLFSSL_FOUND)
|
||||
if(_wolfssl_FOUND)
|
||||
set(WolfSSL_FOUND TRUE)
|
||||
string(REPLACE ";" " " WOLFSSL_CFLAGS "${WOLFSSL_CFLAGS}")
|
||||
message(STATUS "Found WolfSSL (via pkg-config): ${WOLFSSL_INCLUDE_DIRS} (found version \"${WOLFSSL_VERSION}\")")
|
||||
set(WOLFSSL_FOUND TRUE)
|
||||
set(WOLFSSL_VERSION ${_wolfssl_VERSION})
|
||||
string(REPLACE ";" " " _wolfssl_CFLAGS "${_wolfssl_CFLAGS}")
|
||||
message(STATUS "Found WolfSSL (via pkg-config): ${_wolfssl_INCLUDE_DIRS} (found version \"${WOLFSSL_VERSION}\")")
|
||||
else()
|
||||
find_path(WOLFSSL_INCLUDE_DIR NAMES "wolfssl/options.h")
|
||||
find_library(WOLFSSL_LIBRARY NAMES "wolfssl")
|
||||
@@ -56,9 +54,30 @@ else()
|
||||
)
|
||||
|
||||
if(WOLFSSL_FOUND)
|
||||
set(WOLFSSL_INCLUDE_DIRS ${WOLFSSL_INCLUDE_DIR})
|
||||
set(WOLFSSL_LIBRARIES ${WOLFSSL_LIBRARY})
|
||||
set(_wolfssl_INCLUDE_DIRS ${WOLFSSL_INCLUDE_DIR})
|
||||
set(_wolfssl_LIBRARIES ${WOLFSSL_LIBRARY})
|
||||
endif()
|
||||
|
||||
mark_as_advanced(WOLFSSL_INCLUDE_DIR WOLFSSL_LIBRARY)
|
||||
endif()
|
||||
|
||||
if(WOLFSSL_FOUND)
|
||||
if(WIN32)
|
||||
list(APPEND _wolfssl_LIBRARIES "crypt32")
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.13)
|
||||
link_directories(${_wolfssl_LIBRARY_DIRS})
|
||||
endif()
|
||||
|
||||
if(NOT TARGET libssh2::wolfssl)
|
||||
add_library(libssh2::wolfssl INTERFACE IMPORTED)
|
||||
set_target_properties(libssh2::wolfssl PROPERTIES
|
||||
VERSION "${WOLFSSL_VERSION}"
|
||||
LIBSSH2_PC_MODULES "${_wolfssl_pc_requires}"
|
||||
INTERFACE_COMPILE_OPTIONS "${_wolfssl_CFLAGS}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_wolfssl_INCLUDE_DIRS}"
|
||||
INTERFACE_LINK_DIRECTORIES "${_wolfssl_LIBRARY_DIRS}"
|
||||
INTERFACE_LINK_LIBRARIES "${_wolfssl_LIBRARIES}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -6,29 +6,18 @@ option(LIBSSH2_USE_PKGCONFIG "Enable pkg-config to detect @PROJECT_NAME@ depende
|
||||
include(CMakeFindDependencyMacro)
|
||||
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
set(_libdirs "")
|
||||
set(_libs "")
|
||||
|
||||
set(_lib "")
|
||||
if("@CRYPTO_BACKEND@" STREQUAL "OpenSSL")
|
||||
find_dependency(OpenSSL)
|
||||
elseif("@CRYPTO_BACKEND@" STREQUAL "wolfSSL")
|
||||
find_dependency(WolfSSL)
|
||||
if(WOLFSSL_FOUND)
|
||||
list(APPEND _libdirs ${WOLFSSL_LIBRARY_DIRS})
|
||||
list(APPEND _libs ${WOLFSSL_LIBRARIES})
|
||||
endif()
|
||||
set(_lib libssh2::wolfssl)
|
||||
elseif("@CRYPTO_BACKEND@" STREQUAL "Libgcrypt")
|
||||
find_dependency(Libgcrypt)
|
||||
if(LIBGCRYPT_FOUND)
|
||||
list(APPEND _libdirs ${LIBGCRYPT_LIBRARY_DIRS})
|
||||
list(APPEND _libs ${LIBGCRYPT_LIBRARIES})
|
||||
endif()
|
||||
set(_lib libssh2::libgcrypt)
|
||||
elseif("@CRYPTO_BACKEND@" STREQUAL "mbedTLS")
|
||||
find_dependency(MbedTLS)
|
||||
if(MBEDTLS_FOUND)
|
||||
list(APPEND _libdirs ${MBEDTLS_LIBRARY_DIRS})
|
||||
list(APPEND _libs ${MBEDTLS_LIBRARIES})
|
||||
endif()
|
||||
set(_lib libssh2::mbedcrypto)
|
||||
endif()
|
||||
|
||||
if(@ZLIB_FOUND@)
|
||||
@@ -47,17 +36,18 @@ if(NOT TARGET Libssh2::@LIB_NAME@)
|
||||
add_library(Libssh2::@LIB_NAME@ ALIAS @PROJECT_NAME@::@LIB_SELECTED@)
|
||||
endif()
|
||||
|
||||
foreach(_target IN ITEMS @PROJECT_NAME@::@LIB_SHARED@ @PROJECT_NAME@::@LIB_STATIC@)
|
||||
if(TARGET "${_target}")
|
||||
if(_libdirs)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.13)
|
||||
set_target_properties("${_target}" PROPERTIES INTERFACE_LINK_DIRECTORIES "${_libdirs}")
|
||||
else()
|
||||
cmake_policy(GET CMP0099 _has_CMP0099) # https://cmake.org/cmake/help/latest/policy/CMP0099.html
|
||||
if(NOT _has_CMP0099 AND _lib)
|
||||
message(STATUS "libssh2: CMP0099 not detected, resorting to workaround.")
|
||||
# CMake before CMP0099 (CMake 3.17 2020-03-20) did not endorse the concept of libdirs and lib names.
|
||||
# It expected libs to have an absolute filename. As a workaround, manually apply dependency libdirs
|
||||
# to the libssh2 target, for CMake consumers without this policy set.
|
||||
get_target_property(_libdirs "${_lib}" INTERFACE_LINK_DIRECTORIES)
|
||||
if(_libdirs)
|
||||
foreach(_target IN ITEMS @PROJECT_NAME@::@LIB_SHARED@ @PROJECT_NAME@::@LIB_STATIC@)
|
||||
if(TARGET "${_target}")
|
||||
target_link_directories("${_target}" INTERFACE ${_libdirs})
|
||||
endif()
|
||||
endif()
|
||||
if(_libs)
|
||||
target_link_libraries("${_target}" INTERFACE ${_libs})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
@@ -61,12 +61,10 @@ if(ENABLE_ZLIB_COMPRESSION)
|
||||
find_package(ZLIB REQUIRED)
|
||||
|
||||
list(APPEND LIBSSH2_LIBS ZLIB::ZLIB)
|
||||
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "zlib")
|
||||
set_target_properties(ZLIB::ZLIB PROPERTIES LIBSSH2_PC_MODULES "zlib")
|
||||
list(APPEND _libssh2_definitions "LIBSSH2_HAVE_ZLIB")
|
||||
endif()
|
||||
|
||||
include_directories(SYSTEM ${CRYPTO_BACKEND_INCLUDE_DIR})
|
||||
|
||||
list(APPEND LIBSSH2_LIBS ${LIBSSH2_LIBS_SOCKET})
|
||||
|
||||
if(MSVC)
|
||||
@@ -229,7 +227,41 @@ foreach(_libdir IN LISTS CMAKE_SYSTEM_PREFIX_PATH)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(_libdir IN LISTS LIBSSH2_LIBDIRS)
|
||||
set(_explicit_libs "")
|
||||
set(_explicit_libdirs "")
|
||||
set(LIBSSH2_PC_REQUIRES_PRIVATE "")
|
||||
foreach(_lib IN LISTS LIBSSH2_LIBS)
|
||||
if(TARGET "${_lib}")
|
||||
get_target_property(_imported "${_lib}" IMPORTED)
|
||||
if(NOT _imported)
|
||||
# Reading the LOCATION property on non-imported target will error out.
|
||||
# Assume the user will not need this information in the .pc file.
|
||||
continue()
|
||||
endif()
|
||||
get_target_property(_libname "${_lib}" LOCATION)
|
||||
if(_libname)
|
||||
list(APPEND _explicit_libs "${_libname}")
|
||||
else()
|
||||
get_target_property(_libs "${_lib}" INTERFACE_LINK_LIBRARIES)
|
||||
if(_libs)
|
||||
list(APPEND _explicit_libs "${_libs}")
|
||||
endif()
|
||||
get_target_property(_libdirs "${_lib}" INTERFACE_LINK_DIRECTORIES)
|
||||
if(_libdirs)
|
||||
list(APPEND _explicit_libdirs "${_libdirs}")
|
||||
endif()
|
||||
endif()
|
||||
if(NOT _libname AND NOT _libs AND NOT _libdirs)
|
||||
message(WARNING "Bad lib in library list: ${_lib}")
|
||||
endif()
|
||||
get_target_property(_modules "${_lib}" LIBSSH2_PC_MODULES)
|
||||
if(_modules)
|
||||
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "${_modules}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(_libdir IN LISTS _explicit_libdirs)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.20)
|
||||
cmake_path(SET _libdir NORMALIZE "${_libdir}")
|
||||
endif()
|
||||
@@ -244,21 +276,7 @@ if(NOT MINGW AND NOT UNIX)
|
||||
set(_implicit_libs "${CMAKE_C_IMPLICIT_LINK_LIBRARIES}")
|
||||
endif()
|
||||
|
||||
foreach(_lib IN LISTS _implicit_libs LIBSSH2_LIBS)
|
||||
if(TARGET "${_lib}")
|
||||
set(_libname "${_lib}")
|
||||
get_target_property(_imported "${_libname}" IMPORTED)
|
||||
if(NOT _imported)
|
||||
# Reading the LOCATION property on non-imported target will error out.
|
||||
# Assume the user will not need this information in the .pc file.
|
||||
continue()
|
||||
endif()
|
||||
get_target_property(_lib "${_libname}" LOCATION)
|
||||
if(NOT _lib)
|
||||
message(WARNING "Bad lib in library list: ${_libname}")
|
||||
continue()
|
||||
endif()
|
||||
endif()
|
||||
foreach(_lib IN LISTS _implicit_libs _explicit_libs)
|
||||
if(_lib MATCHES "^-")
|
||||
list(APPEND _ldflags "${_lib}")
|
||||
elseif(_lib MATCHES "/")
|
||||
@@ -285,6 +303,7 @@ foreach(_lib IN LISTS _implicit_libs LIBSSH2_LIBS)
|
||||
endforeach()
|
||||
|
||||
if(LIBSSH2_PC_REQUIRES_PRIVATE)
|
||||
list(REMOVE_DUPLICATES LIBSSH2_PC_REQUIRES_PRIVATE)
|
||||
string(REPLACE ";" "," LIBSSH2_PC_REQUIRES_PRIVATE "${LIBSSH2_PC_REQUIRES_PRIVATE}")
|
||||
endif()
|
||||
if(LIBSSH2_PC_LIBS_PRIVATE)
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
|
||||
include(CopyRuntimeDependencies)
|
||||
|
||||
include_directories(SYSTEM ${CRYPTO_BACKEND_INCLUDE_DIR})
|
||||
|
||||
list(APPEND LIBSSH2_LIBS ${LIBSSH2_LIBS_SOCKET})
|
||||
|
||||
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
||||
@@ -78,7 +76,7 @@ target_include_directories(runner PRIVATE
|
||||
"${PROJECT_BINARY_DIR}/src"
|
||||
"${PROJECT_SOURCE_DIR}/src"
|
||||
"${PROJECT_SOURCE_DIR}/include")
|
||||
target_link_libraries(runner PRIVATE libssh2)
|
||||
target_link_libraries(runner PRIVATE libssh2 ${LIBSSH2_LIBS})
|
||||
|
||||
foreach(_test IN LISTS DOCKER_TESTS STANDALONE_TESTS SSHD_TESTS)
|
||||
if(NOT ";${DOCKER_TESTS_STATIC};${STANDALONE_TESTS_STATIC};" MATCHES ";${_test};")
|
||||
@@ -100,12 +98,12 @@ foreach(_test IN LISTS DOCKER_TESTS STANDALONE_TESTS SSHD_TESTS)
|
||||
"${PROJECT_SOURCE_DIR}/src"
|
||||
"${PROJECT_SOURCE_DIR}/include")
|
||||
set_target_properties(${_test} PROPERTIES UNITY_BUILD OFF)
|
||||
target_link_libraries(${_test} runner ${_lib_for_tests} ${LIBSSH2_LIBS})
|
||||
target_link_libraries(${_test} PRIVATE runner ${_lib_for_tests} ${LIBSSH2_LIBS})
|
||||
|
||||
# build a single test with gcov
|
||||
if(GCOV_PATH AND _test STREQUAL "test_auth_keyboard_info_request" AND TARGET ${LIB_STATIC})
|
||||
target_compile_options(${_test} BEFORE PRIVATE ${_gcov_cflags})
|
||||
target_link_libraries(${_test} "gcov")
|
||||
target_link_libraries(${_test} PRIVATE "gcov")
|
||||
endif()
|
||||
|
||||
list(APPEND TEST_TARGETS ${_test})
|
||||
|
||||
Reference in New Issue
Block a user