1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-01-06 14:21:57 +03:00

cmake: style tidy up

- quote text literals to improve readability.
  (exceptions: `FILES` items, `add_subdirectory` names, `find_package`
  names, literal target names, version numbers, 0/1, built-in CMake
  values and CMake keywords, list items in `cmake/max_warnings.cmake`)
- quote standalone variables that could break syntax on empty values.
- replace `libssh2_SOURCE_DIR` with `PROJECT_SOURCE_DIR`.
- add missing mode to `message()` call.
- `TRUE`/`FALSE` → `ON`/`OFF`.
- add missing default value `OFF` to `option()` for clarity.
- unfold some lines.
- `INSTALL_CMAKE.md` fixes and updates. Show defaults.

Closes #1166
This commit is contained in:
Viktor Szakats
2023-08-10 12:38:24 +00:00
parent 186c1d6394
commit 3fa5282d62
6 changed files with 118 additions and 127 deletions

View File

@@ -64,7 +64,7 @@ add_feature_info("Shared library" BUILD_SHARED_LIBS
# Parse version
file(READ ${PROJECT_SOURCE_DIR}/include/libssh2.h _HEADER_CONTENTS)
file(READ "${PROJECT_SOURCE_DIR}/include/libssh2.h" _HEADER_CONTENTS)
string(
REGEX REPLACE ".*#define LIBSSH2_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
LIBSSH2_VERSION "${_HEADER_CONTENTS}")
@@ -82,10 +82,7 @@ if(NOT LIBSSH2_VERSION OR
NOT LIBSSH2_VERSION_MAJOR MATCHES "^[0-9]+$" OR
NOT LIBSSH2_VERSION_MINOR MATCHES "^[0-9]+$" OR
NOT LIBSSH2_VERSION_PATCH MATCHES "^[0-9]+$")
message(
FATAL_ERROR
"Unable to parse version from"
"${PROJECT_SOURCE_DIR}/include/libssh2.h")
message(FATAL_ERROR "Unable to parse version from ${PROJECT_SOURCE_DIR}/include/libssh2.h")
endif()
include(GNUInstallDirs)
@@ -99,15 +96,15 @@ include(max_warnings)
# Add socket libraries
if(WIN32)
list(APPEND SOCKET_LIBRARIES ws2_32)
list(APPEND SOCKET_LIBRARIES "ws2_32")
else()
check_function_exists_may_need_library(socket HAVE_SOCKET socket)
check_function_exists_may_need_library("socket" HAVE_SOCKET "socket")
if(NEED_LIB_SOCKET)
list(APPEND SOCKET_LIBRARIES socket)
list(APPEND SOCKET_LIBRARIES "socket")
endif()
check_function_exists_may_need_library(inet_addr HAVE_INET_ADDR nsl)
check_function_exists_may_need_library("inet_addr" HAVE_INET_ADDR "nsl")
if(NEED_LIB_NSL)
list(APPEND SOCKET_LIBRARIES nsl)
list(APPEND SOCKET_LIBRARIES "nsl")
endif()
endif()
@@ -134,15 +131,15 @@ endif()
option(HIDE_SYMBOLS "Set to ON to hide all libssh2 symbols that are not officially external" ON)
mark_as_advanced(HIDE_SYMBOLS)
if(HIDE_SYMBOLS)
set(LIB_SHARED_DEFINITIONS LIBSSH2_EXPORTS)
set(LIB_SHARED_DEFINITIONS "LIBSSH2_EXPORTS")
if(WIN32)
elseif((CMAKE_C_COMPILER_ID MATCHES "Clang") OR
(CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0) OR
(CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1))
set(LIB_SHARED_C_FLAGS -fvisibility=hidden)
set(LIB_SHARED_C_FLAGS "-fvisibility=hidden")
set(LIBSSH2_API "__attribute__ ((__visibility__ (\"default\")))")
elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
set(LIB_SHARED_C_FLAGS -xldscope=hidden)
set(LIB_SHARED_C_FLAGS "-xldscope=hidden")
set(LIBSSH2_API "__global")
endif()
endif()
@@ -155,13 +152,12 @@ 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
add_definitions(-DLIBSSH2DEBUG)
add_definitions("-DLIBSSH2DEBUG")
endif()
# Auto-detection
@@ -196,20 +192,20 @@ if(WIN32)
endif()
## Platform checks
check_include_files(inttypes.h HAVE_INTTYPES_H)
check_include_files("inttypes.h" HAVE_INTTYPES_H)
if(NOT MSVC)
check_include_files(unistd.h HAVE_UNISTD_H)
check_include_files(sys/time.h HAVE_SYS_TIME_H)
check_include_files(sys/param.h HAVE_SYS_PARAM_H) # tests
check_include_files("unistd.h" HAVE_UNISTD_H)
check_include_files("sys/time.h" HAVE_SYS_TIME_H)
check_include_files("sys/param.h" HAVE_SYS_PARAM_H) # tests
endif()
if(NOT WIN32)
check_include_files(sys/select.h HAVE_SYS_SELECT_H)
check_include_files(sys/uio.h HAVE_SYS_UIO_H)
check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H)
check_include_files(sys/un.h HAVE_SYS_UN_H)
check_include_files(arpa/inet.h HAVE_ARPA_INET_H) # example and tests
check_include_files(netinet/in.h HAVE_NETINET_IN_H) # example and tests
check_include_files("sys/select.h" HAVE_SYS_SELECT_H)
check_include_files("sys/uio.h" HAVE_SYS_UIO_H)
check_include_files("sys/socket.h" HAVE_SYS_SOCKET_H)
check_include_files("sys/ioctl.h" HAVE_SYS_IOCTL_H)
check_include_files("sys/un.h" HAVE_SYS_UN_H)
check_include_files("arpa/inet.h" HAVE_ARPA_INET_H) # example and tests
check_include_files("netinet/in.h" HAVE_NETINET_IN_H) # example and tests
endif()
# CMake uses C syntax in check_symbol_exists() that generates a warning with
@@ -221,20 +217,20 @@ if(MSVC AND ENABLE_WERROR)
endif()
if(HAVE_SYS_TIME_H)
check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
check_symbol_exists("gettimeofday" "sys/time.h" HAVE_GETTIMEOFDAY)
else()
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY)
endif()
check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
check_symbol_exists("strtoll" "stdlib.h" HAVE_STRTOLL)
if(NOT HAVE_STRTOLL)
# Try _strtoi64() if strtoll() is not available
check_symbol_exists(_strtoi64 stdlib.h HAVE_STRTOI64)
check_symbol_exists("_strtoi64" "stdlib.h" HAVE_STRTOI64)
endif()
check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
check_symbol_exists("snprintf" "stdio.h" HAVE_SNPRINTF)
if(NOT WIN32)
check_symbol_exists(explicit_bzero string.h HAVE_EXPLICIT_BZERO)
check_symbol_exists(explicit_memset string.h HAVE_EXPLICIT_MEMSET)
check_symbol_exists(memset_s string.h HAVE_MEMSET_S)
check_symbol_exists("explicit_bzero" "string.h" HAVE_EXPLICIT_BZERO)
check_symbol_exists("explicit_memset" "string.h" HAVE_EXPLICIT_MEMSET)
check_symbol_exists("memset_s" "string.h" HAVE_MEMSET_S)
endif()
if(MSVC AND ENABLE_WERROR)
@@ -254,14 +250,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
# not being able to poll on some files (like anything in /dev)
# not having reliable timeout support
# inconsistent return of POLLHUP where other implementations give POLLIN
message("poll use is disabled on this platform")
message(STATUS "poll use is disabled on this platform")
elseif(NOT WIN32)
check_function_exists(poll HAVE_POLL)
check_function_exists("poll" HAVE_POLL)
endif()
if(WIN32)
set(HAVE_SELECT 1)
else()
check_function_exists(select HAVE_SELECT)
check_function_exists("select" HAVE_SELECT)
endif()
# Non-blocking socket support tests. Use a separate, yet unset variable
@@ -276,17 +272,14 @@ endif()
# Config file
add_definitions(-DHAVE_CONFIG_H)
add_definitions("-DHAVE_CONFIG_H")
configure_file(src/libssh2_config_cmake.h.in
${CMAKE_CURRENT_BINARY_DIR}/src/libssh2_config.h)
configure_file("src/libssh2_config_cmake.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/src/libssh2_config.h")
## Cryptography backend choice
set(CRYPTO_BACKEND
""
CACHE
STRING
set(CRYPTO_BACKEND "" CACHE STRING
"The backend to use for cryptography: OpenSSL, wolfSSL, Libgcrypt,
WinCNG, mbedTLS, or empty to try any available")
@@ -306,39 +299,38 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_OPENSSL")
set(CRYPTO_BACKEND_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})
list(APPEND LIBRARIES ${OPENSSL_LIBRARIES})
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lcrypto)
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE libcrypto)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lcrypto")
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "libcrypto")
if(WIN32)
# Statically linking to OpenSSL requires crypt32 for some Windows APIs.
# This should really be handled by FindOpenSSL.cmake.
list(APPEND LIBRARIES crypt32 bcrypt)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lcrypt32 -lbcrypt)
list(APPEND LIBRARIES "crypt32" "bcrypt")
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lcrypt32" "-lbcrypt")
#set(CMAKE_FIND_DEBUG_MODE TRUE)
#set(CMAKE_FIND_DEBUG_MODE ON)
find_file(DLL_LIBCRYPTO
NAMES crypto.dll
libcrypto-1_1.dll libcrypto-1_1-x64.dll
libcrypto-3.dll libcrypto-3-x64.dll
NAMES "crypto.dll"
"libcrypto-1_1.dll" "libcrypto-1_1-x64.dll"
"libcrypto-3.dll" "libcrypto-3-x64.dll"
HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS}
PATH_SUFFIXES bin NO_DEFAULT_PATH)
PATH_SUFFIXES "bin" NO_DEFAULT_PATH)
if(DLL_LIBCRYPTO)
list(APPEND _RUNTIME_DEPENDENCIES ${DLL_LIBCRYPTO})
message(STATUS "Found libcrypto DLL: ${DLL_LIBCRYPTO}")
else()
message(WARNING
"Unable to find OpenSSL libcrypto DLL, executables may not run")
message(WARNING "Unable to find OpenSSL libcrypto DLL, executables may not run")
endif()
#set(CMAKE_FIND_DEBUG_MODE FALSE)
#set(CMAKE_FIND_DEBUG_MODE OFF)
endif()
find_package(ZLIB)
if(ZLIB_FOUND)
list(APPEND LIBRARIES ${ZLIB_LIBRARIES})
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lz)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lz")
endif()
endif()
endif()
@@ -350,14 +342,14 @@ if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND)
if(WOLFSSL_FOUND)
set(CRYPTO_BACKEND "wolfSSL")
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WOLFSSL")
set(CRYPTO_BACKEND_INCLUDE_DIR ${WOLFSSL_INCLUDE_DIR} ${WOLFSSL_INCLUDE_DIR}/wolfssl)
set(CRYPTO_BACKEND_INCLUDE_DIR ${WOLFSSL_INCLUDE_DIR} "${WOLFSSL_INCLUDE_DIR}/wolfssl")
list(APPEND LIBRARIES ${WOLFSSL_LIBRARIES})
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lwolfssl)
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE wolfssl)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lwolfssl")
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "wolfssl")
if(WIN32)
list(APPEND LIBRARIES crypt32)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lcrypt32)
list(APPEND LIBRARIES "crypt32")
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lcrypt32")
endif()
find_package(ZLIB)
@@ -365,7 +357,7 @@ if(CRYPTO_BACKEND STREQUAL "wolfSSL" OR NOT CRYPTO_BACKEND)
if(ZLIB_FOUND)
list(APPEND CRYPTO_BACKEND_INCLUDE_DIR ${ZLIB_INCLUDE_DIR}) # Public wolfSSL headers require zlib headers
list(APPEND LIBRARIES ${ZLIB_LIBRARIES})
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lz)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lz")
endif()
endif()
endif()
@@ -379,8 +371,8 @@ if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND)
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_LIBGCRYPT")
set(CRYPTO_BACKEND_INCLUDE_DIR ${LIBGCRYPT_INCLUDE_DIRS})
list(APPEND LIBRARIES ${LIBGCRYPT_LIBRARIES})
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lgcrypt)
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE libgcrypt)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lgcrypt")
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "libgcrypt")
endif()
endif()
@@ -393,7 +385,7 @@ if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND)
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_MBEDTLS")
set(CRYPTO_BACKEND_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIR})
list(APPEND LIBRARIES ${MBEDTLS_LIBRARIES})
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lmbedcrypto)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lmbedcrypto")
link_directories(${MBEDTLS_LIBRARY_DIR})
endif()
endif()
@@ -406,8 +398,8 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND)
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WINCNG")
set(CRYPTO_BACKEND_INCLUDE_DIR "")
list(APPEND LIBRARIES crypt32 bcrypt)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lcrypt32 -lbcrypt)
list(APPEND LIBRARIES "crypt32" "bcrypt")
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lcrypt32" "-lbcrypt")
elseif(SPECIFIC_CRYPTO_REQUIREMENT STREQUAL "REQUIRED")
message(FATAL_ERROR "WinCNG not available")
endif()
@@ -441,9 +433,7 @@ endif()
option(LINT "Check style while building" OFF)
if(LINT)
add_custom_target(lint ALL
./ci/checksrc.sh
WORKING_DIRECTORY ${libssh2_SOURCE_DIR})
add_custom_target(lint ALL "./ci/checksrc.sh" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
if(BUILD_STATIC_LIBS)
add_dependencies(${LIB_STATIC} lint)
else()

View File

@@ -38,7 +38,7 @@
transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake")
# Get 'dist_man_MANS' variable
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake)
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake")
include(GNUInstallDirs)
install(FILES ${dist_man_MANS} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
install(FILES ${dist_man_MANS} DESTINATION "${CMAKE_INSTALL_MANDIR}/man3")

View File

@@ -51,19 +51,18 @@ The following options are available:
* `LINT=ON`
Enables running the source code linter when building. Can be `ON` or `OFF`.
Enables running the source code linter when building.
Can be `ON` or `OFF`. Default: `OFF`
* `BUILD_STATIC_LIBS=ON`
* `BUILD_STATIC_LIBS=OFF`
Determines whether to build a libssh2 static library.
Can be `ON` or `OFF`.
Can be `ON` or `OFF`. Default: `ON`
* `BUILD_SHARED_LIBS=OFF`
Determines whether to build a libssh2 shared library (.dll/.so).
Can be `ON` or `OFF`.
If enabled, the optional static lib is also built with PIC enabled.
Can be `ON` or `OFF`. Default: `ON`
* `CRYPTO_BACKEND=`
@@ -75,18 +74,20 @@ The following options are available:
CMake will attempt to locate the libraries automatically. See [2]
for more information.
* `ENABLE_ZLIB_COMPRESSION=OFF`
* `ENABLE_ZLIB_COMPRESSION=ON`
Will use zlib (https://zlib.net/) for payload compression. Can
be `ON` or `OFF`.
Use zlib (https://zlib.net/) for payload compression.
Can be `ON` or `OFF`. Default: `OFF`
* `ENABLE_DEBUG_LOGGING=ON` in Debug, `=OFF` in Release
* `ENABLE_DEBUG_LOGGING=ON`
Will enable the libssh2_trace() function for showing debug traces.
Enable the libssh2_trace() function for showing debug traces.
Can be `ON` or `OFF`. Default: `OFF` in Release, `ON` in `Debug`
* `CLEAR_MEMORY=ON`
* `CLEAR_MEMORY=OFF`
Securely zero memory before freeing it (if the backend supports this).
Disable secure zero memory before freeing it (not recommended).
Can be `ON` or `OFF`. Default: `ON`
Build tools
-----------

View File

@@ -42,16 +42,16 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES})
transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake")
# Get 'noinst_PROGRAMS' variable
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake)
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake")
set(EXAMPLES ${noinst_PROGRAMS})
foreach(example ${EXAMPLES})
add_executable(${example} ${example}.c)
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_include_directories(${example} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" "../src")
target_link_libraries(${example} ${LIB_SELECTED} ${LIBRARIES})
set_target_properties(${example} PROPERTIES UNITY_BUILD FALSE)
set_target_properties(${example} PROPERTIES UNITY_BUILD OFF)
endforeach()
add_target_to_copy_dependencies(

View File

@@ -50,10 +50,10 @@ endif()
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")
option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression" OFF)
add_feature_info(Compression ENABLE_ZLIB_COMPRESSION
"using zlib for compression")
if(ENABLE_ZLIB_COMPRESSION)
@@ -61,17 +61,17 @@ if(ENABLE_ZLIB_COMPRESSION)
list(APPEND libssh2_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
list(APPEND LIBRARIES ${ZLIB_LIBRARIES})
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lz)
list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE zlib)
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()
list(APPEND LIBRARIES ${SOCKET_LIBRARIES})
if(WIN32)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE -lws2_32)
list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lws2_32")
endif()
# to find generated header
@@ -87,7 +87,7 @@ endif()
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)
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
set(SOURCES ${CSOURCES} ${HHEADERS})
## Library definition
@@ -109,7 +109,7 @@ if(BUILD_STATIC_LIBS)
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}
@@ -122,13 +122,13 @@ if(BUILD_SHARED_LIBS)
list(APPEND libssh2_export ${LIB_SHARED})
add_library(${LIB_SHARED} SHARED ${SOURCES})
if(WIN32)
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES libssh2.rc)
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_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)
@@ -142,21 +142,21 @@ endif()
## Installation
install(FILES
${PROJECT_SOURCE_DIR}/include/libssh2.h
${PROJECT_SOURCE_DIR}/include/libssh2_publickey.h
${PROJECT_SOURCE_DIR}/include/libssh2_sftp.h
"${PROJECT_SOURCE_DIR}/include/libssh2.h"
"${PROJECT_SOURCE_DIR}/include/libssh2_publickey.h"
"${PROJECT_SOURCE_DIR}/include/libssh2_sftp.h"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(BUILD_STATIC_LIBS)
install(TARGETS ${LIB_STATIC}
EXPORT ${PROJECT_NAME}-targets
EXPORT "${PROJECT_NAME}-targets"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if(BUILD_SHARED_LIBS)
install(TARGETS ${LIB_SHARED}
EXPORT ${PROJECT_NAME}-targets
EXPORT "${PROJECT_NAME}-targets"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
@@ -170,20 +170,20 @@ set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL
# Package config
## During package installation, install libssh2-targets.cmake
install(EXPORT ${PROJECT_NAME}-targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
install(EXPORT "${PROJECT_NAME}-targets"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
## 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
configure_file(${PROJECT_SOURCE_DIR}/cmake/libssh2-config.cmake.in ${PROJECT_NAME}-config.cmake @ONLY)
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
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
## Export a .pc file for client projects not using CMaek
if(LIBSSH2_PC_REQUIRES_PRIVATE)
@@ -205,18 +205,18 @@ set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
configure_file(${PROJECT_SOURCE_DIR}/libssh2.pc.in libssh2.pc @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/libssh2.pc.in" "libssh2.pc" @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libssh2.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
FILES "${CMAKE_CURRENT_BINARY_DIR}/libssh2.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
#
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
VERSION "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}"
COMPATIBILITY SameMajorVersion)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

View File

@@ -43,14 +43,14 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES})
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
# Get 'DOCKER_TESTS', 'DOCKER_TESTS_STATIC', 'STANDALONE_TESTS', 'STANDALONE_TESTS_STATIC', 'SSHD_TESTS',
# 'librunner_la_SOURCES' variables
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
list(APPEND DOCKER_TESTS ${DOCKER_TESTS_STATIC})
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")
endif()
@@ -72,7 +72,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_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" "../src" "../include" "${CRYPTO_BACKEND_INCLUDE_DIR}")
foreach(test ${DOCKER_TESTS} ${STANDALONE_TESTS} ${SSHD_TESTS})
if(NOT ";${DOCKER_TESTS_STATIC};${STANDALONE_TESTS_STATIC};" MATCHES ";${test};")
@@ -87,15 +87,15 @@ foreach(test ${DOCKER_TESTS} ${STANDALONE_TESTS} ${SSHD_TESTS})
# 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)
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 FALSE)
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)
target_link_libraries(${test} runner ${LIB_FOR_TESTS} ${LIBRARIES} "gcov")
else()
target_link_libraries(${test} runner ${LIB_FOR_TESTS} ${LIBRARIES})
endif()
@@ -142,7 +142,7 @@ if(RUN_DOCKER_TESTS)
file(READ "test_read_algos.txt" ALGO_TESTS)
string(REGEX REPLACE "\\\n" ";" ALGO_TESTS ${ALGO_TESTS})
foreach(test ${ALGO_TESTS})
set(testname test_read-${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-")