mirror of
https://github.com/libssh2/libssh2.git
synced 2025-10-26 02:17:35 +03:00
- 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
54 lines
1.9 KiB
CMake
54 lines
1.9 KiB
CMake
# Copyright (C) The libssh2 project and its contributors.
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
option(LIBSSH2_USE_PKGCONFIG "Enable pkg-config to detect @PROJECT_NAME@ dependencies. Default: @LIBSSH2_USE_PKGCONFIG@" "@LIBSSH2_USE_PKGCONFIG@")
|
|
|
|
include(CMakeFindDependencyMacro)
|
|
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
|
|
|
|
set(_lib "")
|
|
if("@CRYPTO_BACKEND@" STREQUAL "OpenSSL")
|
|
find_dependency(OpenSSL)
|
|
elseif("@CRYPTO_BACKEND@" STREQUAL "wolfSSL")
|
|
find_dependency(WolfSSL)
|
|
set(_lib libssh2::wolfssl)
|
|
elseif("@CRYPTO_BACKEND@" STREQUAL "Libgcrypt")
|
|
find_dependency(Libgcrypt)
|
|
set(_lib libssh2::libgcrypt)
|
|
elseif("@CRYPTO_BACKEND@" STREQUAL "mbedTLS")
|
|
find_dependency(MbedTLS)
|
|
set(_lib libssh2::mbedcrypto)
|
|
endif()
|
|
|
|
if(@ZLIB_FOUND@)
|
|
find_dependency(ZLIB)
|
|
endif()
|
|
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
|
|
|
|
# Alias for either shared or static library
|
|
if(NOT TARGET @PROJECT_NAME@::@LIB_NAME@)
|
|
add_library(@PROJECT_NAME@::@LIB_NAME@ ALIAS @PROJECT_NAME@::@LIB_SELECTED@)
|
|
endif()
|
|
|
|
# Compatibility alias
|
|
if(NOT TARGET Libssh2::@LIB_NAME@)
|
|
add_library(Libssh2::@LIB_NAME@ ALIAS @PROJECT_NAME@::@LIB_SELECTED@)
|
|
endif()
|
|
|
|
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()
|
|
endforeach()
|
|
endif()
|
|
endif()
|