2018-08-21 13:07:13 +03:00
cmake_minimum_required ( VERSION 3.3.0 )
2018-08-06 17:55:37 +03:00
cmake_policy ( SET CMP0048 NEW )
2009-02-02 17:44:46 +03:00
2022-07-01 14:35:56 +03:00
# Specify search path for CMake modules to be loaded by include()
2018-09-05 16:13:26 +03:00
# and find_package()
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" )
# Add defaults for cmake
# Those need to be set before the project() call.
include ( DefineCMakeDefaults )
2018-09-05 16:14:14 +03:00
include ( DefineCompilerFlags )
2018-09-05 16:13:26 +03:00
2018-08-30 09:21:25 +03:00
project ( libssh VERSION 0.8.90 LANGUAGES C )
2009-02-02 17:44:46 +03:00
2018-08-06 17:55:37 +03:00
# global needed variable
2009-02-02 17:44:46 +03:00
set ( APPLICATION_NAME ${ PROJECT_NAME } )
2010-05-12 21:01:25 +04:00
# SOVERSION scheme: CURRENT.AGE.REVISION
2010-03-25 15:24:59 +03:00
# If there was an incompatible interface change:
# Increment CURRENT. Set AGE and REVISION to 0
2010-05-12 21:01:25 +04:00
# If there was a compatible interface change:
# Increment AGE. Set REVISION to 0
# If the source code was changed, but there were no interface changes:
# Increment REVISION.
2022-07-01 14:35:56 +03:00
set ( LIBRARY_VERSION "4.9.0" )
2010-08-19 01:18:57 +04:00
set ( LIBRARY_SOVERSION "4" )
2009-02-02 17:44:46 +03:00
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
# add definitions
2010-09-08 13:19:22 +04:00
include ( DefinePlatformDefaults )
2009-02-02 17:44:46 +03:00
include ( DefineOptions.cmake )
include ( CPackConfig.cmake )
2019-07-03 11:10:18 +03:00
include ( GNUInstallDirs )
2009-02-02 17:44:46 +03:00
2018-08-20 16:17:09 +03:00
include ( CompilerChecks.cmake )
2009-02-02 17:44:46 +03:00
# disallow in-source build
include ( MacroEnsureOutOfSourceBuild )
macro_ensure_out_of_source_build ( "${PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." )
2018-11-06 14:47:33 +03:00
# Copy library files to a lib sub-directory
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" )
2009-02-02 17:44:46 +03:00
# search for libraries
2011-09-23 10:00:25 +04:00
if ( WITH_ZLIB )
2010-06-11 12:43:02 +04:00
find_package ( ZLIB REQUIRED )
2011-09-23 10:00:25 +04:00
endif ( WITH_ZLIB )
2009-02-02 17:44:46 +03:00
2009-09-26 01:31:48 +04:00
if ( WITH_GCRYPT )
2012-02-04 23:10:04 +04:00
find_package ( GCrypt 1.5.0 REQUIRED )
2009-05-07 19:07:54 +04:00
if ( NOT GCRYPT_FOUND )
2009-09-26 01:31:48 +04:00
message ( FATAL_ERROR "Could not find GCrypt" )
2009-05-07 19:07:54 +04:00
endif ( NOT GCRYPT_FOUND )
2017-12-28 13:10:43 +03:00
elseif ( WITH_MBEDTLS )
find_package ( MbedTLS REQUIRED )
if ( NOT MBEDTLS_FOUND )
message ( FATAL_ERROR "Could not find mbedTLS" )
endif ( NOT MBEDTLS_FOUND )
2009-09-26 01:31:48 +04:00
else ( WITH_GCRYPT )
2020-12-18 15:57:30 +03:00
find_package ( OpenSSL 1.0.1 )
2020-12-10 21:30:54 +03:00
if ( OPENSSL_FOUND )
# On CMake < 3.16, OPENSSL_CRYPTO_LIBRARIES is usually a synonym for OPENSSL_CRYPTO_LIBRARY, but is not defined
# when building on Windows outside of Cygwin. We provide the synonym here, if FindOpenSSL didn't define it already.
if ( NOT DEFINED OPENSSL_CRYPTO_LIBRARIES )
set ( OPENSSL_CRYPTO_LIBRARIES ${ OPENSSL_CRYPTO_LIBRARY } )
endif ( NOT DEFINED OPENSSL_CRYPTO_LIBRARIES )
else ( OPENSSL_FOUND )
2009-09-26 01:31:48 +04:00
find_package ( GCrypt )
if ( NOT GCRYPT_FOUND )
2017-12-28 13:10:43 +03:00
find_package ( MbedTLS )
if ( NOT MBEDTLS_FOUND )
message ( FATAL_ERROR "Could not find OpenSSL, GCrypt or mbedTLS" )
endif ( NOT MBEDTLS_FOUND )
2009-09-26 01:31:48 +04:00
endif ( NOT GCRYPT_FOUND )
2020-12-11 21:52:06 +03:00
endif ( OPENSSL_FOUND )
2009-09-26 01:31:48 +04:00
endif ( WITH_GCRYPT )
2009-02-02 17:44:46 +03:00
2018-11-21 15:59:42 +03:00
if ( UNIT_TESTING )
find_package ( CMocka REQUIRED )
endif ( )
2010-09-01 17:15:17 +04:00
# Find out if we have threading available
set ( CMAKE_THREAD_PREFER_PTHREADS ON )
2018-07-02 14:03:12 +03:00
set ( THREADS_PREFER_PTHREAD_FLAG ON )
2010-09-01 17:15:17 +04:00
find_package ( Threads )
2013-07-13 17:46:23 +04:00
if ( WITH_GSSAPI )
2013-07-13 17:50:57 +04:00
find_package ( GSSAPI )
2013-07-13 17:46:23 +04:00
endif ( WITH_GSSAPI )
2013-02-21 02:14:59 +04:00
2019-12-10 20:20:55 +03:00
if ( WITH_PKCS11_URI )
find_package ( softhsm )
if ( NOT SOFTHSM_FOUND )
message ( SEND_ERROR "Could not find softhsm module!" )
endif ( NOT SOFTHSM_FOUND )
endif ( WITH_PKCS11_URI )
2013-09-22 01:32:51 +04:00
if ( WITH_NACL )
find_package ( NaCl )
if ( NOT NACL_FOUND )
set ( WITH_NACL OFF )
endif ( NOT NACL_FOUND )
endif ( WITH_NACL )
2022-06-10 13:45:41 +03:00
if ( BSD OR SOLARIS OR OSX OR CYGWIN )
2016-03-15 00:27:06 +03:00
find_package ( Argp )
2022-06-10 13:45:41 +03:00
endif ( BSD OR SOLARIS OR OSX OR CYGWIN )
2016-03-15 00:27:06 +03:00
2018-05-14 16:55:06 +03:00
# Disable symbol versioning in non UNIX platforms
if ( UNIX )
2018-08-20 19:59:57 +03:00
find_package ( ABIMap 0.3.1 )
2018-05-14 16:55:06 +03:00
else ( UNIX )
set ( WITH_SYMBOL_VERSIONING OFF )
endif ( UNIX )
2009-02-02 17:44:46 +03:00
# config.h checks
include ( ConfigureChecks.cmake )
configure_file ( config.h.cmake ${ CMAKE_CURRENT_BINARY_DIR } /config.h )
# check subdirectories
2009-02-03 13:43:45 +03:00
add_subdirectory ( doc )
2009-02-02 17:44:46 +03:00
add_subdirectory ( include )
2010-09-06 16:28:38 +04:00
add_subdirectory ( src )
2009-02-02 17:44:46 +03:00
2009-12-30 08:34:17 +03:00
# pkg-config file
2021-09-15 12:01:10 +03:00
if ( UNIX OR MINGW )
2009-12-30 08:34:17 +03:00
configure_file ( libssh.pc.cmake ${ CMAKE_CURRENT_BINARY_DIR } /libssh.pc )
install (
F I L E S
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / l i b s s h . p c
D E S T I N A T I O N
2019-07-03 11:10:18 +03:00
$ { C M A K E _ I N S T A L L _ L I B D I R } / p k g c o n f i g
2009-12-30 08:34:17 +03:00
C O M P O N E N T
p k g c o n f i g
)
2021-09-15 12:01:10 +03:00
endif ( UNIX OR MINGW )
2015-09-07 08:46:11 +03:00
2018-11-06 14:47:33 +03:00
# CMake config files
include ( CMakePackageConfigHelpers )
2014-12-17 12:38:56 +03:00
set ( LIBSSH_LIBRARY_NAME ${ CMAKE_SHARED_LIBRARY_PREFIX } ssh ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
2014-05-22 16:52:52 +04:00
2018-11-06 14:47:33 +03:00
# libssh-config-version.cmake
write_basic_package_version_file ( libssh-config-version.cmake
V E R S I O N $ { P R O J E C T _ V E R S I O N }
C O M P A T I B I L I T Y S a m e M a j o r V e r s i o n )
2013-02-12 16:31:42 +04:00
install (
F I L E S
2014-05-22 16:52:52 +04:00
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { P R O J E C T _ N A M E } - c o n f i g - v e r s i o n . c m a k e
2013-02-12 16:31:42 +04:00
D E S T I N A T I O N
2019-07-03 11:10:18 +03:00
$ { C M A K E _ I N S T A L L _ L I B D I R } / c m a k e / $ { P R O J E C T _ N A M E }
2013-02-12 16:31:42 +04:00
C O M P O N E N T
2019-07-03 11:10:18 +03:00
d e v e l )
2013-02-12 16:31:42 +04:00
2013-09-16 10:21:12 +04:00
if ( WITH_EXAMPLES )
add_subdirectory ( examples )
endif ( WITH_EXAMPLES )
2010-03-02 15:47:14 +03:00
2018-06-29 11:29:02 +03:00
if ( UNIT_TESTING )
2018-11-21 15:59:42 +03:00
include ( AddCMockaTest )
add_subdirectory ( tests )
2018-06-29 11:29:02 +03:00
endif ( UNIT_TESTING )
2010-03-02 15:47:14 +03:00
2018-05-14 16:55:06 +03:00
### SOURCE PACKAGE
if ( WITH_SYMBOL_VERSIONING AND ABIMAP_FOUND )
# Get the current ABI version from source
get_filename_component ( current_abi_path
" $ { C M A K E _ S O U R C E _ D I R } / s r c / A B I / c u r r e n t "
A B S O L U T E )
# Check if the ABI version should be updated
file ( READ ${ current_abi_path } CURRENT_ABI_CONTENT )
string ( STRIP "${CURRENT_ABI_CONTENT}" CURRENT_ABI_VERSION )
if ( LIBRARY_VERSION VERSION_GREATER CURRENT_ABI_VERSION )
set ( UPDATE_ABI TRUE )
endif ( )
if ( UPDATE_ABI )
message ( STATUS "Library version bumped to ${LIBRARY_VERSION}: Updating ABI" )
# Get the list of header files
2018-08-28 19:36:55 +03:00
get_file_list ( ${ PROJECT_NAME } _header_list
2018-05-14 16:55:06 +03:00
D I R E C T O R I E S " $ { C M A K E _ S O U R C E _ D I R } / i n c l u d e / l i b s s h "
F I L E S _ P A T T E R N S " * . h " )
# Extract the symbols marked as "LIBSSH_API" from the header files
extract_symbols ( ${ PROJECT_NAME } .symbols
2018-08-28 19:36:55 +03:00
H E A D E R S _ L I S T $ { P R O J E C T _ N A M E } _ h e a d e r _ l i s t
2018-05-14 16:55:06 +03:00
F I L T E R _ P A T T E R N " L I B S S H _ A P I "
C O P Y _ T O " $ { C M A K E _ S O U R C E _ D I R } / s r c / A B I / $ { P R O J E C T _ N A M E } - $ { L I B R A R Y _ V E R S I O N } . s y m b o l s " )
if ( WITH_ABI_BREAK )
set ( ALLOW_ABI_BREAK "BREAK_ABI" )
endif ( )
# Target we can depend on in 'make dist'
set ( _SYMBOL_TARGET "${PROJECT_NAME}.map" )
# Set the path to the current map file
set ( MAP_PATH "${CMAKE_SOURCE_DIR}/src/${_SYMBOL_TARGET}" )
# Generate the symbol version map file
generate_map_file ( ${ _SYMBOL_TARGET }
2018-08-28 19:36:55 +03:00
S Y M B O L S $ { P R O J E C T _ N A M E } . s y m b o l s
2018-05-14 16:55:06 +03:00
R E L E A S E _ N A M E _ V E R S I O N $ { P R O J E C T _ N A M E } _ $ { L I B R A R Y _ V E R S I O N }
C U R R E N T _ M A P $ { M A P _ P A T H }
C O P Y _ T O $ { M A P _ P A T H }
F I N A L
$ { A L L O W _ A B I _ B R E A K } )
# Write the current version to the source
file ( WRITE ${ current_abi_path } ${ LIBRARY_VERSION } )
endif ( UPDATE_ABI )
endif ( WITH_SYMBOL_VERSIONING AND ABIMAP_FOUND )
2021-02-05 10:14:22 +03:00
add_custom_target ( dist COMMAND ${ CMAKE_MAKE_PROGRAM } package_source DEPENDS ${ _SYMBOL_TARGET } VERBATIM )
2010-12-19 19:29:17 +03:00
2019-10-25 11:14:28 +03:00
# Link compile database for clangd
2021-02-05 10:14:22 +03:00
execute_process ( COMMAND ${ CMAKE_COMMAND } -E create_symlink
2019-10-25 11:14:28 +03:00
" $ { C M A K E _ B I N A R Y _ D I R } / c o m p i l e _ c o m m a n d s . j s o n "
" $ { C M A K E _ S O U R C E _ D I R } / c o m p i l e _ c o m m a n d s . j s o n " )
2010-03-03 01:37:49 +03:00
message ( STATUS "********************************************" )
message ( STATUS "********** ${PROJECT_NAME} build options : **********" )
2010-02-08 18:55:03 +03:00
2011-09-23 10:00:25 +04:00
message ( STATUS "zlib support: ${WITH_ZLIB}" )
2010-03-03 01:37:49 +03:00
message ( STATUS "libgcrypt support: ${WITH_GCRYPT}" )
2017-12-28 13:10:43 +03:00
message ( STATUS "libmbedTLS support: ${WITH_MBEDTLS}" )
2013-09-22 01:32:51 +04:00
message ( STATUS "libnacl support: ${WITH_NACL}" )
2010-03-03 01:37:49 +03:00
message ( STATUS "SFTP support: ${WITH_SFTP}" )
message ( STATUS "Server support : ${WITH_SERVER}" )
2013-02-21 02:14:59 +04:00
message ( STATUS "GSSAPI support : ${WITH_GSSAPI}" )
2019-02-02 18:49:05 +03:00
message ( STATUS "GEX support : ${WITH_GEX}" )
2020-04-28 12:04:59 +03:00
message ( STATUS "Support insecure none cipher and MAC : ${WITH_INSECURE_NONE}" )
2010-03-03 01:37:49 +03:00
message ( STATUS "Pcap debugging support : ${WITH_PCAP}" )
2019-11-06 11:10:09 +03:00
message ( STATUS "Build shared library: ${BUILD_SHARED_LIBS}" )
2018-06-29 11:29:02 +03:00
message ( STATUS "Unit testing: ${UNIT_TESTING}" )
2018-07-04 21:33:31 +03:00
message ( STATUS "Client code testing: ${CLIENT_TESTING}" )
2018-12-16 15:32:42 +03:00
message ( STATUS "Blowfish cipher support: ${WITH_BLOWFISH_CIPHER}" )
2019-12-10 20:19:59 +03:00
message ( STATUS "PKCS #11 URI support: ${WITH_PKCS11_URI}" )
2020-08-26 15:02:37 +03:00
message ( STATUS "DSA support: ${WITH_DSA}" )
2018-07-04 21:33:31 +03:00
set ( _SERVER_TESTING OFF )
if ( WITH_SERVER )
set ( _SERVER_TESTING ${ SERVER_TESTING } )
endif ( )
message ( STATUS "Server code testing: ${_SERVER_TESTING}" )
2010-02-08 18:55:03 +03:00
if ( WITH_INTERNAL_DOC )
2010-03-03 01:37:49 +03:00
message ( STATUS "Internal documentation generation" )
2010-02-08 18:55:03 +03:00
else ( WITH_INTERNAL_DOC )
2010-03-03 01:37:49 +03:00
message ( STATUS "Public API documentation generation" )
2010-02-08 18:55:03 +03:00
endif ( WITH_INTERNAL_DOC )
2010-12-19 19:29:17 +03:00
message ( STATUS "Benchmarks: ${WITH_BENCHMARKS}" )
2018-05-14 16:55:06 +03:00
message ( STATUS "Symbol versioning: ${WITH_SYMBOL_VERSIONING}" )
message ( STATUS "Allow ABI break: ${WITH_ABI_BREAK}" )
message ( STATUS "Release is final: ${WITH_FINAL}" )
2019-05-06 16:19:40 +03:00
message ( STATUS "Global client config: ${GLOBAL_CLIENT_CONFIG}" )
2019-03-11 17:56:06 +03:00
if ( WITH_SERVER )
message ( STATUS "Global bind config: ${GLOBAL_BIND_CONFIG}" )
endif ( )
2010-03-03 01:37:49 +03:00
message ( STATUS "********************************************" )
2010-02-08 18:55:03 +03:00