1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-08-10 06:23:02 +03:00

cmake: use the imported target of FindOpenSSL module (#1322)

* Use the imported target of FindOpenSSL module
* Build libssh2 before test runner
* Use find_package() in the CMake config file
* Use find_dependency() rather than find_package()
* Install CMake module files and use them in the config file
* Use elseif() to choose the crypto backend
This commit is contained in:
Jiwoo Park
2024-03-29 07:30:20 +09:00
committed by GitHub
parent 2f0efde37a
commit 82b09f9b3a
4 changed files with 25 additions and 3 deletions

View File

@@ -303,7 +303,7 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
set(CRYPTO_BACKEND "OpenSSL")
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_OPENSSL")
set(CRYPTO_BACKEND_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})
list(APPEND LIBRARIES ${OPENSSL_LIBRARIES})
list(APPEND LIBRARIES OpenSSL::SSL)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lcrypto")
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "libcrypto")

View File

@@ -1,6 +1,23 @@
# Copyright (C) The libssh2 project and its contributors.
# SPDX-License-Identifier: BSD-3-Clause
include(CMakeFindDependencyMacro)
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
if("@CRYPTO_BACKEND@" STREQUAL "OpenSSL")
find_dependency(OpenSSL)
elseif("@CRYPTO_BACKEND@" STREQUAL "wolfSSL")
find_package(wolfssl)
elseif("@CRYPTO_BACKEND@" STREQUAL "Libgcrypt")
find_package(Libgcrypt)
elseif("@CRYPTO_BACKEND@" STREQUAL "mbedTLS")
find_package(mbedTLS)
endif()
if(@ZLIB_FOUND@)
find_dependency(ZLIB)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
# Alias for either shared or static library

View File

@@ -185,10 +185,14 @@ install(EXPORT "${PROJECT_NAME}-targets"
export(TARGETS ${libssh2_export} NAMESPACE "${PROJECT_NAME}::" FILE "${PROJECT_NAME}-targets.cmake")
export(PACKAGE ${PROJECT_NAME}) # register it
# Generate libssh2-config.cmake into build tree and install it
# Generate libssh2-config.cmake into build tree and install it with dependencies
configure_file("${PROJECT_SOURCE_DIR}/cmake/libssh2-config.cmake.in" "${PROJECT_NAME}-config.cmake" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
"${PROJECT_SOURCE_DIR}/cmake/FindLibgcrypt.cmake"
"${PROJECT_SOURCE_DIR}/cmake/FindmbedTLS.cmake"
"${PROJECT_SOURCE_DIR}/cmake/Findwolfssl.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
## Export a .pc file for client projects not using CMaek

View File

@@ -73,6 +73,7 @@ endif()
add_library(runner STATIC ${librunner_la_SOURCES})
target_compile_definitions(runner PRIVATE "${CRYPTO_BACKEND_DEFINE}")
target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" "../src" "../include" "${CRYPTO_BACKEND_INCLUDE_DIR}")
target_link_libraries(runner PRIVATE libssh2)
foreach(test IN LISTS DOCKER_TESTS STANDALONE_TESTS SSHD_TESTS)
if(NOT ";${DOCKER_TESTS_STATIC};${STANDALONE_TESTS_STATIC};" MATCHES ";${test};")