|
| 1 | +project(libssh C) |
| 2 | + |
| 3 | +# Required cmake version |
| 4 | +cmake_minimum_required(VERSION 2.8.5) |
| 5 | + |
| 6 | +# global needed variables |
| 7 | +set(APPLICATION_NAME ${PROJECT_NAME}) |
| 8 | + |
| 9 | +set(APPLICATION_VERSION_MAJOR "0") |
| 10 | +set(APPLICATION_VERSION_MINOR "7") |
| 11 | +set(APPLICATION_VERSION_PATCH "90") |
| 12 | + |
| 13 | +set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}") |
| 14 | + |
| 15 | +# SOVERSION scheme: CURRENT.AGE.REVISION |
| 16 | +# If there was an incompatible interface change: |
| 17 | +# Increment CURRENT. Set AGE and REVISION to 0 |
| 18 | +# If there was a compatible interface change: |
| 19 | +# Increment AGE. Set REVISION to 0 |
| 20 | +# If the source code was changed, but there were no interface changes: |
| 21 | +# Increment REVISION. |
| 22 | +set(LIBRARY_VERSION "4.5.0") |
| 23 | +set(LIBRARY_SOVERSION "4") |
| 24 | + |
| 25 | +# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked |
| 26 | +set(CMAKE_MODULE_PATH |
| 27 | + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules |
| 28 | +) |
| 29 | + |
| 30 | +# add definitions |
| 31 | +include(DefineCMakeDefaults) |
| 32 | +include(DefinePlatformDefaults) |
| 33 | +include(DefineCompilerFlags) |
| 34 | +include(DefineInstallationPaths) |
| 35 | +include(DefineOptions.cmake) |
| 36 | +include(CPackConfig.cmake) |
| 37 | + |
| 38 | +# disallow in-source build |
| 39 | +include(MacroEnsureOutOfSourceBuild) |
| 40 | +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.") |
| 41 | + |
| 42 | +# search for libraries |
| 43 | +if (WITH_ZLIB) |
| 44 | + find_package(ZLIB REQUIRED) |
| 45 | +endif (WITH_ZLIB) |
| 46 | + |
| 47 | +if (WITH_GCRYPT) |
| 48 | + find_package(GCrypt 1.5.0 REQUIRED) |
| 49 | + if (NOT GCRYPT_FOUND) |
| 50 | + message(FATAL_ERROR "Could not find GCrypt") |
| 51 | + endif (NOT GCRYPT_FOUND) |
| 52 | +elseif(WITH_MBEDTLS) |
| 53 | + find_package(MbedTLS REQUIRED) |
| 54 | + if (NOT MBEDTLS_FOUND) |
| 55 | + message(FATAL_ERROR "Could not find mbedTLS") |
| 56 | + endif (NOT MBEDTLS_FOUND) |
| 57 | +else (WITH_GCRYPT) |
| 58 | + find_package(OpenSSL) |
| 59 | + if (NOT OPENSSL_FOUND) |
| 60 | + find_package(GCrypt) |
| 61 | + if (NOT GCRYPT_FOUND) |
| 62 | + find_package(MbedTLS) |
| 63 | + if (NOT MBEDTLS_FOUND) |
| 64 | + message(FATAL_ERROR "Could not find OpenSSL, GCrypt or mbedTLS") |
| 65 | + endif (NOT MBEDTLS_FOUND) |
| 66 | + endif (NOT GCRYPT_FOUND) |
| 67 | + endif (NOT OPENSSL_FOUND) |
| 68 | +endif(WITH_GCRYPT) |
| 69 | + |
| 70 | +# Find out if we have threading available |
| 71 | +set(CMAKE_THREAD_PREFER_PTHREADS ON) |
| 72 | +find_package(Threads) |
| 73 | + |
| 74 | +if (WITH_GSSAPI) |
| 75 | + find_package(GSSAPI) |
| 76 | +endif (WITH_GSSAPI) |
| 77 | + |
| 78 | +if (WITH_NACL) |
| 79 | + find_package(NaCl) |
| 80 | + if (NOT NACL_FOUND) |
| 81 | + set(WITH_NACL OFF) |
| 82 | + endif (NOT NACL_FOUND) |
| 83 | +endif (WITH_NACL) |
| 84 | + |
| 85 | +if (BSD OR SOLARIS OR OSX) |
| 86 | + find_package(Argp) |
| 87 | +endif (BSD OR SOLARIS OR OSX) |
| 88 | + |
| 89 | +# config.h checks |
| 90 | +include(ConfigureChecks.cmake) |
| 91 | +configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) |
| 92 | + |
| 93 | +# check subdirectories |
| 94 | +add_subdirectory(doc) |
| 95 | +add_subdirectory(include) |
| 96 | +add_subdirectory(src) |
| 97 | + |
| 98 | +# pkg-config file |
| 99 | +if (UNIX) |
| 100 | +configure_file(libssh.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libssh.pc) |
| 101 | +install( |
| 102 | + FILES |
| 103 | + ${CMAKE_CURRENT_BINARY_DIR}/libssh.pc |
| 104 | + ${CMAKE_CURRENT_BINARY_DIR}/libssh_threads.pc |
| 105 | + DESTINATION |
| 106 | + ${LIB_INSTALL_DIR}/pkgconfig |
| 107 | + COMPONENT |
| 108 | + pkgconfig |
| 109 | +) |
| 110 | + |
| 111 | + if (LIBSSH_THREADS) |
| 112 | + configure_file(libssh_threads.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libssh_threads.pc) |
| 113 | + install( |
| 114 | + FILES |
| 115 | + ${CMAKE_CURRENT_BINARY_DIR}/libssh.pc |
| 116 | + ${CMAKE_CURRENT_BINARY_DIR}/libssh_threads.pc |
| 117 | + DESTINATION |
| 118 | + ${LIB_INSTALL_DIR}/pkgconfig |
| 119 | + COMPONENT |
| 120 | + pkgconfig |
| 121 | + ) |
| 122 | + endif (LIBSSH_THREADS) |
| 123 | +endif (UNIX) |
| 124 | + |
| 125 | +# cmake config files |
| 126 | +set(LIBSSH_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}ssh${CMAKE_SHARED_LIBRARY_SUFFIX}) |
| 127 | +set(LIBSSH_THREADS_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}ssh${CMAKE_SHARED_LIBRARY_SUFFIX}) |
| 128 | + |
| 129 | +configure_file(${PROJECT_NAME}-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake @ONLY) |
| 130 | +configure_file(${PROJECT_NAME}-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake @ONLY) |
| 131 | +install( |
| 132 | + FILES |
| 133 | + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake |
| 134 | + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake |
| 135 | + DESTINATION |
| 136 | + ${CMAKE_INSTALL_DIR}/${PROJECT_NAME} |
| 137 | + COMPONENT |
| 138 | + devel |
| 139 | +) |
| 140 | + |
| 141 | + |
| 142 | +# in tree build settings |
| 143 | +configure_file(libssh-build-tree-settings.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libssh-build-tree-settings.cmake @ONLY) |
| 144 | + |
| 145 | +if (WITH_EXAMPLES) |
| 146 | + add_subdirectory(examples) |
| 147 | +endif (WITH_EXAMPLES) |
| 148 | + |
| 149 | +if (WITH_TESTING) |
| 150 | + find_package(CMocka REQUIRED) |
| 151 | + include(AddCMockaTest) |
| 152 | + add_subdirectory(tests) |
| 153 | +endif (WITH_TESTING) |
| 154 | + |
| 155 | + |
| 156 | +message(STATUS "********************************************") |
| 157 | +message(STATUS "********** ${PROJECT_NAME} build options : **********") |
| 158 | + |
| 159 | +message(STATUS "zlib support: ${WITH_ZLIB}") |
| 160 | +message(STATUS "libgcrypt support: ${WITH_GCRYPT}") |
| 161 | +message(STATUS "libmbedTLS support: ${WITH_MBEDTLS}") |
| 162 | +message(STATUS "libnacl support: ${WITH_NACL}") |
| 163 | +message(STATUS "SSH-1 support: ${WITH_SSH1}") |
| 164 | +message(STATUS "SFTP support: ${WITH_SFTP}") |
| 165 | +message(STATUS "Server support : ${WITH_SERVER}") |
| 166 | +message(STATUS "GSSAPI support : ${WITH_GSSAPI}") |
| 167 | +message(STATUS "Pcap debugging support : ${WITH_PCAP}") |
| 168 | +message(STATUS "With static library: ${WITH_STATIC_LIB}") |
| 169 | +message(STATUS "Unit testing: ${WITH_TESTING}") |
| 170 | +message(STATUS "Client code Unit testing: ${WITH_CLIENT_TESTING}") |
| 171 | +if (WITH_INTERNAL_DOC) |
| 172 | + message(STATUS "Internal documentation generation") |
| 173 | +else (WITH_INTERNAL_DOC) |
| 174 | + message(STATUS "Public API documentation generation") |
| 175 | +endif (WITH_INTERNAL_DOC) |
| 176 | +message(STATUS "Benchmarks: ${WITH_BENCHMARKS}") |
| 177 | +message(STATUS "********************************************") |
| 178 | + |
0 commit comments