mirror of
https://github.com/libssh2/libssh2.git
synced 2025-08-10 06:23:02 +03:00
cmake: IMPORTED
target improvements and fixes
- fix `add_subdirectory` builds for old CMake versions. - libssh2-config.cmake: fix to set CMP0099 for CMake 3.17+ only. - libssh2-config.cmake: generalize code to support any number of deps. (mainly to sync with curl.) - libssh2-config.cmake: bind dependencies to the static libssh2 only. Follow-up toa0d8529b08
#1571 Follow-up todf0563a857
#1535 Closes #1581
This commit is contained in:
@@ -6,18 +6,18 @@ option(LIBSSH2_USE_PKGCONFIG "Enable pkg-config to detect @PROJECT_NAME@ depende
|
|||||||
include(CMakeFindDependencyMacro)
|
include(CMakeFindDependencyMacro)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH})
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH})
|
||||||
|
|
||||||
set(_lib "")
|
set(_libs "")
|
||||||
if("@CRYPTO_BACKEND@" STREQUAL "OpenSSL")
|
if("@CRYPTO_BACKEND@" STREQUAL "OpenSSL")
|
||||||
find_dependency(OpenSSL)
|
find_dependency(OpenSSL)
|
||||||
elseif("@CRYPTO_BACKEND@" STREQUAL "wolfSSL")
|
elseif("@CRYPTO_BACKEND@" STREQUAL "wolfSSL")
|
||||||
find_dependency(WolfSSL)
|
find_dependency(WolfSSL)
|
||||||
set(_lib libssh2::wolfssl)
|
list(APPEND _libs libssh2::wolfssl)
|
||||||
elseif("@CRYPTO_BACKEND@" STREQUAL "Libgcrypt")
|
elseif("@CRYPTO_BACKEND@" STREQUAL "Libgcrypt")
|
||||||
find_dependency(Libgcrypt)
|
find_dependency(Libgcrypt)
|
||||||
set(_lib libssh2::libgcrypt)
|
list(APPEND _libs libssh2::libgcrypt)
|
||||||
elseif("@CRYPTO_BACKEND@" STREQUAL "mbedTLS")
|
elseif("@CRYPTO_BACKEND@" STREQUAL "mbedTLS")
|
||||||
find_dependency(MbedTLS)
|
find_dependency(MbedTLS)
|
||||||
set(_lib libssh2::mbedcrypto)
|
list(APPEND _libs libssh2::mbedcrypto)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(@ZLIB_FOUND@)
|
if(@ZLIB_FOUND@)
|
||||||
@@ -40,18 +40,23 @@ if(NOT TARGET Libssh2::@LIB_NAME@)
|
|||||||
add_library(Libssh2::@LIB_NAME@ ALIAS @PROJECT_NAME@::@LIB_SELECTED@)
|
add_library(Libssh2::@LIB_NAME@ ALIAS @PROJECT_NAME@::@LIB_SELECTED@)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
cmake_policy(GET CMP0099 _has_CMP0099) # https://cmake.org/cmake/help/latest/policy/CMP0099.html
|
if(TARGET @PROJECT_NAME@::@LIB_STATIC@)
|
||||||
if(NOT _has_CMP0099 AND _lib)
|
# CMake before CMP0099 (CMake 3.17 2020-03-20) did not propagate libdirs to
|
||||||
message(STATUS "libssh2: CMP0099 not detected, resorting to workaround.")
|
# targets. It expected libs to have an absolute filename. As a workaround,
|
||||||
# CMake before CMP0099 (CMake 3.17 2020-03-20) did not endorse the concept of libdirs and lib names.
|
# manually apply dependency libdirs, for CMake consumers without this policy.
|
||||||
# It expected libs to have an absolute filename. As a workaround, manually apply dependency libdirs
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
|
||||||
# to the libssh2 target, for CMake consumers without this policy set.
|
cmake_policy(GET CMP0099 _has_CMP0099) # https://cmake.org/cmake/help/latest/policy/CMP0099.html
|
||||||
get_target_property(_libdirs "${_lib}" INTERFACE_LINK_DIRECTORIES)
|
endif()
|
||||||
if(_libdirs)
|
if(NOT _has_CMP0099 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND _libs)
|
||||||
foreach(_target IN ITEMS @PROJECT_NAME@::@LIB_SHARED@ @PROJECT_NAME@::@LIB_STATIC@)
|
set(_libdirs "")
|
||||||
if(TARGET "${_target}")
|
foreach(_lib IN LISTS _libs)
|
||||||
target_link_directories("${_target}" INTERFACE ${_libdirs})
|
get_target_property(_libdir "${_lib}" INTERFACE_LINK_DIRECTORIES)
|
||||||
|
if(_libdir)
|
||||||
|
list(APPEND _libdirs "${_libdir}")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
if(_libdirs)
|
||||||
|
target_link_directories(@PROJECT_NAME@::@LIB_STATIC@ INTERFACE ${_libdirs})
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
@@ -127,6 +127,27 @@ if(BUILD_STATIC_LIBS OR BUILD_STATIC_FOR_TESTS)
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
||||||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||||
|
|
||||||
|
# CMake before CMP0099 (CMake 3.17 2020-03-20) did not propagate libdirs to
|
||||||
|
# targets. It expected libs to have an absolute filename. As a workaround,
|
||||||
|
# manually apply dependency libdirs, for CMake consumers without this policy.
|
||||||
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
|
||||||
|
cmake_policy(GET CMP0099 _has_CMP0099) # https://cmake.org/cmake/help/latest/policy/CMP0099.html
|
||||||
|
endif()
|
||||||
|
if(NOT _has_CMP0099 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND LIBSSH2_LIBS)
|
||||||
|
set(_libdirs "")
|
||||||
|
foreach(_lib IN LISTS LIBSSH2_LIBS)
|
||||||
|
if(TARGET "${_lib}")
|
||||||
|
get_target_property(_libdir "${_lib}" INTERFACE_LINK_DIRECTORIES)
|
||||||
|
if(_libdir)
|
||||||
|
list(APPEND _libdirs "${_libdir}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
if(_libdirs)
|
||||||
|
target_link_directories(${LIB_STATIC} INTERFACE ${_libdirs})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
list(APPEND _libssh2_export ${LIB_SHARED})
|
list(APPEND _libssh2_export ${LIB_SHARED})
|
||||||
|
Reference in New Issue
Block a user