mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-31 00:03:08 +03:00
cmake: tidy up syntax, minor improvements
- make internal variables underscore-lowercase. - unfold lines. - fold lines setting header directories. - fix indent. - drop interim variable `EXAMPLES`. - initialize some variables before populating them. - clear a variable after use. - add `libssh2_dumpvars()` function for debugging. - allow to override default `CMAKE_UNITY_BUILD_BATCH_SIZE`. - bump up default `CMAKE_UNITY_BUILD_BATCH_SIZE` to 0 (was 32). - tidy up option descriptions. Closes #1446
This commit is contained in:
@ -52,31 +52,33 @@ include(CheckNonblockingSocketSupport)
|
||||
|
||||
project(libssh2 C)
|
||||
|
||||
set(CMAKE_UNITY_BUILD_BATCH_SIZE 32)
|
||||
function(libssh2_dumpvars) # Dump all defined variables with their values
|
||||
message("::group::CMake Variable Dump")
|
||||
get_cmake_property(_vars VARIABLES)
|
||||
foreach(_var ${_vars})
|
||||
message("${_var} = ${${_var}}")
|
||||
endforeach()
|
||||
message("::endgroup::")
|
||||
endfunction()
|
||||
|
||||
option(BUILD_STATIC_LIBS "Build Static Libraries" ON)
|
||||
add_feature_info("Static library" BUILD_STATIC_LIBS
|
||||
"creating libssh2 static library")
|
||||
if(NOT DEFINED CMAKE_UNITY_BUILD_BATCH_SIZE)
|
||||
set(CMAKE_UNITY_BUILD_BATCH_SIZE 0)
|
||||
endif()
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build Shared Libraries" ON)
|
||||
add_feature_info("Shared library" BUILD_SHARED_LIBS
|
||||
"creating libssh2 shared library (.so/.dll)")
|
||||
option(BUILD_STATIC_LIBS "Build static libraries" ON)
|
||||
add_feature_info("Static library" BUILD_STATIC_LIBS "creating libssh2 static library")
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
|
||||
add_feature_info("Shared library" BUILD_SHARED_LIBS "creating libssh2 shared library (.so/.dll)")
|
||||
|
||||
# Parse version
|
||||
|
||||
file(READ "${PROJECT_SOURCE_DIR}/include/libssh2.h" _HEADER_CONTENTS)
|
||||
string(
|
||||
REGEX REPLACE ".*#define LIBSSH2_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
|
||||
LIBSSH2_VERSION "${_HEADER_CONTENTS}")
|
||||
string(
|
||||
REGEX REPLACE ".*#define LIBSSH2_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1"
|
||||
LIBSSH2_VERSION_MAJOR "${_HEADER_CONTENTS}")
|
||||
string(
|
||||
REGEX REPLACE ".*#define LIBSSH2_VERSION_MINOR[ \t]+([0-9]+).*" "\\1"
|
||||
LIBSSH2_VERSION_MINOR "${_HEADER_CONTENTS}")
|
||||
string(
|
||||
REGEX REPLACE ".*#define LIBSSH2_VERSION_PATCH[ \t]+([0-9]+).*" "\\1"
|
||||
LIBSSH2_VERSION_PATCH "${_HEADER_CONTENTS}")
|
||||
file(READ "${PROJECT_SOURCE_DIR}/include/libssh2.h" _header_contents)
|
||||
string(REGEX REPLACE ".*#define LIBSSH2_VERSION[ \t]+\"([^\"]+)\".*" "\\1" LIBSSH2_VERSION "${_header_contents}")
|
||||
string(REGEX REPLACE ".*#define LIBSSH2_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" LIBSSH2_VERSION_MAJOR "${_header_contents}")
|
||||
string(REGEX REPLACE ".*#define LIBSSH2_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" LIBSSH2_VERSION_MINOR "${_header_contents}")
|
||||
string(REGEX REPLACE ".*#define LIBSSH2_VERSION_PATCH[ \t]+([0-9]+).*" "\\1" LIBSSH2_VERSION_PATCH "${_header_contents}")
|
||||
unset(_header_contents)
|
||||
|
||||
if(NOT LIBSSH2_VERSION OR
|
||||
NOT LIBSSH2_VERSION_MAJOR MATCHES "^[0-9]+$" OR
|
||||
@ -128,7 +130,7 @@ endif()
|
||||
|
||||
# Symbol hiding
|
||||
|
||||
option(HIDE_SYMBOLS "Set to ON to hide all libssh2 symbols that are not officially external" ON)
|
||||
option(HIDE_SYMBOLS "Hide all libssh2 symbols that are not officially external" ON)
|
||||
mark_as_advanced(HIDE_SYMBOLS)
|
||||
if(HIDE_SYMBOLS)
|
||||
set(LIB_SHARED_DEFINITIONS "LIBSSH2_EXPORTS")
|
||||
@ -152,7 +154,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
else()
|
||||
set(DEBUG_LOGGING_DEFAULT OFF)
|
||||
endif()
|
||||
option(ENABLE_DEBUG_LOGGING "log execution with debug trace" ${DEBUG_LOGGING_DEFAULT})
|
||||
option(ENABLE_DEBUG_LOGGING "Log execution with debug trace" ${DEBUG_LOGGING_DEFAULT})
|
||||
add_feature_info(Logging ENABLE_DEBUG_LOGGING "Logging of execution with debug trace")
|
||||
if(ENABLE_DEBUG_LOGGING)
|
||||
# Must be visible to the library and tests using internals
|
||||
@ -282,20 +284,19 @@ configure_file("src/libssh2_config_cmake.h.in"
|
||||
|
||||
## Cryptography backend choice
|
||||
|
||||
set(CRYPTO_BACKEND "" CACHE STRING
|
||||
"The backend to use for cryptography: OpenSSL, wolfSSL, Libgcrypt,
|
||||
WinCNG, mbedTLS, or empty to try any available")
|
||||
set(CRYPTO_BACKEND "" CACHE
|
||||
STRING "The backend to use for cryptography: OpenSSL, wolfSSL, Libgcrypt, WinCNG, mbedTLS, or empty to try any available")
|
||||
|
||||
# If the crypto backend was given, rather than searching for the first
|
||||
# we are able to find, the find_package commands must abort configuration
|
||||
# and report to the user.
|
||||
if(CRYPTO_BACKEND)
|
||||
set(SPECIFIC_CRYPTO_REQUIREMENT "REQUIRED")
|
||||
set(_specific_crypto_requirement "REQUIRED")
|
||||
endif()
|
||||
|
||||
if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
|
||||
|
||||
find_package(OpenSSL ${SPECIFIC_CRYPTO_REQUIREMENT})
|
||||
find_package(OpenSSL ${_specific_crypto_requirement})
|
||||
|
||||
if(OPENSSL_FOUND)
|
||||
set(CRYPTO_BACKEND "OpenSSL")
|
||||
@ -340,7 +341,7 @@ endif()
|
||||
|
||||
if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND)
|
||||
|
||||
find_package(WolfSSL ${SPECIFIC_CRYPTO_REQUIREMENT})
|
||||
find_package(WolfSSL ${_specific_crypto_requirement})
|
||||
|
||||
if(WOLFSSL_FOUND)
|
||||
set(CRYPTO_BACKEND "wolfSSL")
|
||||
@ -367,7 +368,7 @@ endif()
|
||||
|
||||
if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND)
|
||||
|
||||
find_package(Libgcrypt ${SPECIFIC_CRYPTO_REQUIREMENT})
|
||||
find_package(Libgcrypt ${_specific_crypto_requirement})
|
||||
|
||||
if(LIBGCRYPT_FOUND)
|
||||
set(CRYPTO_BACKEND "Libgcrypt")
|
||||
@ -381,7 +382,7 @@ endif()
|
||||
|
||||
if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND)
|
||||
|
||||
find_package(MbedTLS ${SPECIFIC_CRYPTO_REQUIREMENT})
|
||||
find_package(MbedTLS ${_specific_crypto_requirement})
|
||||
|
||||
if(MBEDTLS_FOUND)
|
||||
set(CRYPTO_BACKEND "mbedTLS")
|
||||
@ -404,7 +405,7 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND)
|
||||
list(APPEND LIBRARIES "crypt32" "bcrypt")
|
||||
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lcrypt32" "-lbcrypt")
|
||||
|
||||
option(ENABLE_ECDSA_WINCNG "WinCNG ECDSA support (requires Windows 10 or later)" OFF)
|
||||
option(ENABLE_ECDSA_WINCNG "Enable WinCNG ECDSA support (requires Windows 10 or later)" OFF)
|
||||
add_feature_info(WinCNG ENABLE_ECDSA_WINCNG "WinCNG ECDSA support")
|
||||
if(ENABLE_ECDSA_WINCNG)
|
||||
add_definitions("-DLIBSSH2_ECDSA_WINCNG")
|
||||
@ -414,7 +415,7 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--subsystem,windows:10")
|
||||
endif()
|
||||
endif()
|
||||
elseif(SPECIFIC_CRYPTO_REQUIREMENT STREQUAL "REQUIRED")
|
||||
elseif(_specific_crypto_requirement STREQUAL "REQUIRED")
|
||||
message(FATAL_ERROR "WinCNG not available")
|
||||
endif()
|
||||
endif()
|
||||
@ -422,14 +423,14 @@ endif()
|
||||
# Global functions
|
||||
|
||||
# Convert GNU Make assignments into CMake ones.
|
||||
function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
|
||||
file(READ ${INPUT_FILE} MAKEFILE_INC_CMAKE)
|
||||
function(transform_makefile_inc _input_file _output_file)
|
||||
file(READ ${_input_file} _makefile_inc_cmake)
|
||||
|
||||
string(REGEX REPLACE "\\\\\n" "" MAKEFILE_INC_CMAKE ${MAKEFILE_INC_CMAKE})
|
||||
string(REGEX REPLACE "([A-Za-z_]+) *= *([^\n]*)" "set(\\1 \\2)" MAKEFILE_INC_CMAKE ${MAKEFILE_INC_CMAKE})
|
||||
string(REGEX REPLACE "\\\\\n" "" _makefile_inc_cmake ${_makefile_inc_cmake})
|
||||
string(REGEX REPLACE "([A-Za-z_]+) *= *([^\n]*)" "set(\\1 \\2)" _makefile_inc_cmake ${_makefile_inc_cmake})
|
||||
|
||||
file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_CMAKE})
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${INPUT_FILE}")
|
||||
file(WRITE ${_output_file} ${_makefile_inc_cmake})
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_input_file}")
|
||||
endfunction()
|
||||
|
||||
#
|
||||
|
@ -60,21 +60,19 @@
|
||||
include(CheckFunctionExists)
|
||||
include(CheckLibraryExists)
|
||||
|
||||
function(check_function_exists_may_need_library function variable)
|
||||
function(check_function_exists_may_need_library _function _variable)
|
||||
|
||||
check_function_exists(${function} ${variable})
|
||||
check_function_exists(${_function} ${_variable})
|
||||
|
||||
if(NOT ${variable})
|
||||
foreach(lib IN LISTS ARGN)
|
||||
string(TOUPPER ${lib} UP_LIB)
|
||||
if(NOT ${_variable})
|
||||
foreach(_lib IN LISTS ARGN)
|
||||
string(TOUPPER ${_lib} _up_lib)
|
||||
# Use new variable to prevent cache from previous step shortcircuiting
|
||||
# new test
|
||||
check_library_exists(${lib} ${function} "" HAVE_${function}_IN_${lib})
|
||||
if(HAVE_${function}_IN_${lib})
|
||||
set(${variable} 1 CACHE INTERNAL
|
||||
"Function ${function} found in library ${lib}")
|
||||
set(NEED_LIB_${UP_LIB} 1 CACHE INTERNAL
|
||||
"Need to link ${lib}")
|
||||
check_library_exists(${_lib} ${_function} "" HAVE_${_function}_IN_${_lib})
|
||||
if(HAVE_${_function}_IN_${_lib})
|
||||
set(${_variable} 1 CACHE INTERNAL "Function ${_function} found in library ${_lib}")
|
||||
set(NEED_LIB_${_up_lib} 1 CACHE INTERNAL "Need to link ${_lib}")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
@ -41,8 +41,7 @@ function(add_target_to_copy_dependencies)
|
||||
set(options)
|
||||
set(oneValueArgs TARGET)
|
||||
set(multiValueArgs DEPENDENCIES BEFORE_TARGETS)
|
||||
cmake_parse_arguments(COPY
|
||||
"${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
cmake_parse_arguments(COPY "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT COPY_DEPENDENCIES)
|
||||
return()
|
||||
@ -52,20 +51,18 @@ function(add_target_to_copy_dependencies)
|
||||
# parallel builds trying to kick off the commands at the same time
|
||||
add_custom_target(${COPY_TARGET})
|
||||
|
||||
foreach(target IN LISTS COPY_BEFORE_TARGETS)
|
||||
add_dependencies(${target} ${COPY_TARGET})
|
||||
foreach(_target IN LISTS COPY_BEFORE_TARGETS)
|
||||
add_dependencies(${_target} ${COPY_TARGET})
|
||||
endforeach()
|
||||
|
||||
foreach(dependency IN LISTS COPY_DEPENDENCIES)
|
||||
foreach(_dependency IN LISTS COPY_DEPENDENCIES)
|
||||
add_custom_command(
|
||||
TARGET ${COPY_TARGET}
|
||||
DEPENDS ${dependency}
|
||||
DEPENDS ${_dependency}
|
||||
# Make directory first otherwise file is copied in place of
|
||||
# directory instead of into it
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy ${dependency} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy ${_dependency} "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
|
||||
VERBATIM)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
@ -43,18 +43,19 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES})
|
||||
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
||||
# Get 'noinst_PROGRAMS' variable
|
||||
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
||||
set(EXAMPLES ${noinst_PROGRAMS})
|
||||
|
||||
foreach(example IN LISTS EXAMPLES)
|
||||
add_executable(${example} "${example}.c")
|
||||
list(APPEND EXAMPLE_TARGETS ${example})
|
||||
foreach(_example IN LISTS noinst_PROGRAMS)
|
||||
add_executable(${_example} "${_example}.c")
|
||||
list(APPEND _example_targets ${_example})
|
||||
# to find generated header
|
||||
target_include_directories(${example} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" "../src")
|
||||
target_link_libraries(${example} ${LIB_SELECTED} ${LIBRARIES})
|
||||
set_target_properties(${example} PROPERTIES UNITY_BUILD OFF)
|
||||
target_include_directories(${_example} PRIVATE
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/../src"
|
||||
"../src")
|
||||
target_link_libraries(${_example} ${LIB_SELECTED} ${LIBRARIES})
|
||||
set_target_properties(${_example} PROPERTIES UNITY_BUILD OFF)
|
||||
endforeach()
|
||||
|
||||
add_target_to_copy_dependencies(
|
||||
TARGET copy_example_dependencies
|
||||
DEPENDENCIES ${RUNTIME_DEPENDENCIES}
|
||||
BEFORE_TARGETS ${EXAMPLE_TARGETS})
|
||||
BEFORE_TARGETS ${_example_targets})
|
||||
|
@ -36,8 +36,8 @@
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
set(LIBSSH2_SOVERSION 1)
|
||||
set(LIBSSH2_LIBVERSION 1.0.1)
|
||||
set(_libssh2_soversion 1)
|
||||
set(_libssh2_libversion 1.0.1)
|
||||
|
||||
if(CRYPTO_BACKEND)
|
||||
list(APPEND PRIVATE_COMPILE_DEFINITIONS ${CRYPTO_BACKEND_DEFINE})
|
||||
@ -49,9 +49,11 @@ endif()
|
||||
|
||||
## Options
|
||||
|
||||
unset(_libssh2_definitions)
|
||||
|
||||
option(CLEAR_MEMORY "Enable clearing of memory before being freed" ON)
|
||||
if(NOT CLEAR_MEMORY)
|
||||
list(APPEND libssh2_DEFINITIONS "LIBSSH2_NO_CLEAR_MEMORY")
|
||||
list(APPEND _libssh2_definitions "LIBSSH2_NO_CLEAR_MEMORY")
|
||||
endif()
|
||||
|
||||
option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression" OFF)
|
||||
@ -65,7 +67,7 @@ if(ENABLE_ZLIB_COMPRESSION)
|
||||
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lz")
|
||||
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "zlib")
|
||||
if(ZLIB_FOUND)
|
||||
list(APPEND libssh2_DEFINITIONS "LIBSSH2_HAVE_ZLIB")
|
||||
list(APPEND _libssh2_definitions "LIBSSH2_HAVE_ZLIB")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@ -89,7 +91,7 @@ include(GNUInstallDirs)
|
||||
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
||||
# Get 'CSOURCES' and 'HHEADERS' variables
|
||||
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
||||
set(SOURCES ${CSOURCES} ${HHEADERS})
|
||||
set(_sources ${CSOURCES} ${HHEADERS})
|
||||
|
||||
## Library definition
|
||||
|
||||
@ -103,40 +105,48 @@ if(WIN32 AND BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS AND
|
||||
set(STATIC_LIB_SUFFIX "_static")
|
||||
endif()
|
||||
|
||||
unset(_libssh2_export)
|
||||
|
||||
# we want it to be called libssh2 on all platforms
|
||||
if(BUILD_STATIC_LIBS)
|
||||
list(APPEND libssh2_export ${LIB_STATIC})
|
||||
add_library(${LIB_STATIC} STATIC ${SOURCES})
|
||||
list(APPEND _libssh2_export ${LIB_STATIC})
|
||||
add_library(${LIB_STATIC} STATIC ${_sources})
|
||||
add_library(${PROJECT_NAME}::${LIB_STATIC} ALIAS ${LIB_STATIC})
|
||||
target_compile_definitions(${LIB_STATIC} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS})
|
||||
target_compile_definitions(${LIB_STATIC} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${_libssh2_definitions})
|
||||
target_link_libraries(${LIB_STATIC} PRIVATE ${LIBRARIES})
|
||||
set_target_properties(${LIB_STATIC} PROPERTIES
|
||||
PREFIX "" OUTPUT_NAME "libssh2" SOVERSION "${LIBSSH2_SOVERSION}" VERSION "${LIBSSH2_LIBVERSION}"
|
||||
PREFIX "" OUTPUT_NAME "libssh2" SOVERSION "${_libssh2_soversion}" VERSION "${_libssh2_libversion}"
|
||||
SUFFIX "${STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
|
||||
target_include_directories(${LIB_STATIC}
|
||||
PRIVATE "${PROJECT_SOURCE_DIR}/include" ${libssh2_INCLUDE_DIRS} ${PRIVATE_INCLUDE_DIRECTORIES}
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/include"
|
||||
${libssh2_INCLUDE_DIRS}
|
||||
${PRIVATE_INCLUDE_DIRECTORIES}
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
endif()
|
||||
if(BUILD_SHARED_LIBS)
|
||||
list(APPEND libssh2_export ${LIB_SHARED})
|
||||
add_library(${LIB_SHARED} SHARED ${SOURCES})
|
||||
list(APPEND _libssh2_export ${LIB_SHARED})
|
||||
add_library(${LIB_SHARED} SHARED ${_sources})
|
||||
add_library(${PROJECT_NAME}::${LIB_SHARED} ALIAS ${LIB_SHARED})
|
||||
if(WIN32)
|
||||
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES "libssh2.rc")
|
||||
endif()
|
||||
target_compile_definitions(${LIB_SHARED} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS} ${LIB_SHARED_DEFINITIONS})
|
||||
target_compile_definitions(${LIB_SHARED} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${_libssh2_definitions} ${LIB_SHARED_DEFINITIONS})
|
||||
target_compile_options(${LIB_SHARED} PRIVATE ${LIB_SHARED_C_FLAGS})
|
||||
target_link_libraries(${LIB_SHARED} PRIVATE ${LIBRARIES})
|
||||
set_target_properties(${LIB_SHARED} PROPERTIES
|
||||
PREFIX "" OUTPUT_NAME "libssh2" SOVERSION "${LIBSSH2_SOVERSION}" VERSION "${LIBSSH2_LIBVERSION}"
|
||||
PREFIX "" OUTPUT_NAME "libssh2" SOVERSION "${_libssh2_soversion}" VERSION "${_libssh2_libversion}"
|
||||
IMPORT_PREFIX "" IMPORT_SUFFIX "${IMPORT_LIB_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX}"
|
||||
POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
target_include_directories(${LIB_SHARED}
|
||||
PRIVATE "${PROJECT_SOURCE_DIR}/include" ${libssh2_INCLUDE_DIRS} ${PRIVATE_INCLUDE_DIRECTORIES}
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/include"
|
||||
${libssh2_INCLUDE_DIRS}
|
||||
${PRIVATE_INCLUDE_DIRECTORIES}
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
@ -182,7 +192,7 @@ install(EXPORT "${PROJECT_NAME}-targets"
|
||||
|
||||
## During build, register directly from build tree
|
||||
# create libssh2-targets.cmake
|
||||
export(TARGETS ${libssh2_export} NAMESPACE "${PROJECT_NAME}::" FILE "${PROJECT_NAME}-targets.cmake")
|
||||
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 with dependencies
|
||||
|
@ -50,9 +50,9 @@ list(APPEND STANDALONE_TESTS ${STANDALONE_TESTS_STATIC})
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
find_program(GCOV_PATH "gcov")
|
||||
if(GCOV_PATH)
|
||||
set(GCOV_CFLAGS "-g" "--coverage")
|
||||
set(_gcov_cflags "-g" "--coverage")
|
||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
|
||||
set(GCOV_CFLAGS "${GCOV_CFLAGS} -fprofile-abs-path")
|
||||
set(_gcov_cflags "${_gcov_cflags} -fprofile-abs-path")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@ -72,67 +72,75 @@ 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_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};")
|
||||
set(LIB_FOR_TESTS ${LIB_SELECTED})
|
||||
foreach(_test IN LISTS DOCKER_TESTS STANDALONE_TESTS SSHD_TESTS)
|
||||
if(NOT ";${DOCKER_TESTS_STATIC};${STANDALONE_TESTS_STATIC};" MATCHES ";${_test};")
|
||||
set(_lib_for_tests ${LIB_SELECTED})
|
||||
elseif(TARGET ${LIB_STATIC})
|
||||
set(LIB_FOR_TESTS ${LIB_STATIC})
|
||||
set(_lib_for_tests ${LIB_STATIC})
|
||||
else()
|
||||
unset(LIB_FOR_TESTS)
|
||||
message(STATUS "Skip test requiring static libssh2 lib: ${test}")
|
||||
unset(_lib_for_tests)
|
||||
message(STATUS "Skip test requiring static libssh2 lib: ${_test}")
|
||||
endif()
|
||||
|
||||
# We support the same target as both Docker and SSHD test. Build those just once.
|
||||
# Skip building tests that require the static lib when the static lib is disabled.
|
||||
if(NOT TARGET ${test} AND LIB_FOR_TESTS)
|
||||
add_executable(${test} "${test}.c")
|
||||
target_compile_definitions(${test} PRIVATE "${CRYPTO_BACKEND_DEFINE}")
|
||||
target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" "../src" "../include" "${CRYPTO_BACKEND_INCLUDE_DIR}")
|
||||
set_target_properties(${test} PROPERTIES UNITY_BUILD OFF)
|
||||
if(NOT TARGET ${_test} AND _lib_for_tests)
|
||||
add_executable(${_test} "${_test}.c")
|
||||
target_compile_definitions(${_test} PRIVATE "${CRYPTO_BACKEND_DEFINE}")
|
||||
target_include_directories(${_test} PRIVATE
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/../src"
|
||||
"../src"
|
||||
"../include"
|
||||
"${CRYPTO_BACKEND_INCLUDE_DIR}")
|
||||
set_target_properties(${_test} PROPERTIES UNITY_BUILD OFF)
|
||||
|
||||
# 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} runner ${LIB_FOR_TESTS} ${LIBRARIES} "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} runner ${_lib_for_tests} ${LIBRARIES} "gcov")
|
||||
else()
|
||||
target_link_libraries(${test} runner ${LIB_FOR_TESTS} ${LIBRARIES})
|
||||
target_link_libraries(${_test} runner ${_lib_for_tests} ${LIBRARIES})
|
||||
endif()
|
||||
|
||||
list(APPEND TEST_TARGETS ${test})
|
||||
list(APPEND TEST_TARGETS ${_test})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
option(RUN_DOCKER_TESTS "Run tests requiring Docker" ON)
|
||||
|
||||
if(RUN_DOCKER_TESTS)
|
||||
foreach(test IN LISTS DOCKER_TESTS)
|
||||
if(TARGET ${test})
|
||||
add_test(NAME ${test} COMMAND "$<TARGET_FILE:${test}>")
|
||||
set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
foreach(_test IN LISTS DOCKER_TESTS)
|
||||
if(TARGET ${_test})
|
||||
add_test(NAME ${_test} COMMAND "$<TARGET_FILE:${_test}>")
|
||||
set_property(TEST ${_test} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
foreach(test IN LISTS STANDALONE_TESTS)
|
||||
if(TARGET ${test})
|
||||
add_test(NAME ${test} COMMAND "$<TARGET_FILE:${test}>")
|
||||
set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
foreach(_test IN LISTS STANDALONE_TESTS)
|
||||
if(TARGET ${_test})
|
||||
add_test(NAME ${_test} COMMAND "$<TARGET_FILE:${_test}>")
|
||||
set_property(TEST ${_test} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(RUN_SSHD_TESTS AND SSHD_EXECUTABLE)
|
||||
unset(sshd_test_targets)
|
||||
foreach(test IN LISTS SSHD_TESTS)
|
||||
if(TARGET ${test})
|
||||
set(sshd_test_targets "${sshd_test_targets} $<TARGET_FILE:${test}>")
|
||||
unset(_sshd_test_targets)
|
||||
foreach(_test IN LISTS SSHD_TESTS)
|
||||
if(TARGET ${_test})
|
||||
set(_sshd_test_targets "${_sshd_test_targets} $<TARGET_FILE:${_test}>")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(sshd_test_targets)
|
||||
add_test(NAME test_sshd COMMAND ${SH_EXECUTABLE} -c "${CMAKE_CURRENT_SOURCE_DIR}/test_sshd.test ${sshd_test_targets}")
|
||||
if(_sshd_test_targets)
|
||||
add_test(NAME test_sshd COMMAND ${SH_EXECUTABLE} -c "${CMAKE_CURRENT_SOURCE_DIR}/test_sshd.test ${_sshd_test_targets}")
|
||||
set_property(TEST test_sshd APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set_property(TEST test_sshd APPEND PROPERTY ENVIRONMENT "SSHD=${SSHD_EXECUTABLE}")
|
||||
endif()
|
||||
@ -140,17 +148,17 @@ endif()
|
||||
|
||||
if(RUN_DOCKER_TESTS)
|
||||
# CRYPT/MAC algo tests
|
||||
file(READ "test_read_algos.txt" ALGO_TESTS)
|
||||
string(REGEX REPLACE "\\\n" ";" ALGO_TESTS ${ALGO_TESTS})
|
||||
foreach(test IN LISTS ALGO_TESTS)
|
||||
if(test)
|
||||
set(testname "test_read-${test}")
|
||||
add_test(NAME ${testname} COMMAND "$<TARGET_FILE:test_read>")
|
||||
set_property(TEST ${testname} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
if(test MATCHES "mac-")
|
||||
set_property(TEST ${testname} APPEND PROPERTY ENVIRONMENT "FIXTURE_TEST_MAC=${test}")
|
||||
file(READ "test_read_algos.txt" _algo_tests)
|
||||
string(REGEX REPLACE "\\\n" ";" _algo_tests ${_algo_tests})
|
||||
foreach(_test IN LISTS _algo_tests)
|
||||
if(_test)
|
||||
set(_testname "test_read-${_test}")
|
||||
add_test(NAME ${_testname} COMMAND "$<TARGET_FILE:test_read>")
|
||||
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
if(_test MATCHES "mac-")
|
||||
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT "FIXTURE_TEST_MAC=${_test}")
|
||||
else()
|
||||
set_property(TEST ${testname} APPEND PROPERTY ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}")
|
||||
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT "FIXTURE_TEST_CRYPT=${_test}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
Reference in New Issue
Block a user