Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 1 | # Copyright (C) 2009 Werner Dittman |
| 2 | # |
| 3 | # This file is free software; as a special exception the author gives |
| 4 | # unlimited permission to copy and/or distribute it, with or without |
| 5 | # modifications, as long as this notice is preserved. |
| 6 | # |
| 7 | # This program is distributed in the hope that it will be useful, but |
| 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the |
| 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 10 | # |
| 11 | cmake_minimum_required(VERSION 2.6) |
| 12 | |
| 13 | PROJECT(libzrtpcpp) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 14 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 15 | SET(CPACK_PACKAGE_VERSION_MAJOR 4) |
| 16 | SET(CPACK_PACKAGE_VERSION_MINOR 0) |
| 17 | SET(CPACK_PACKAGE_VERSION_PATCH 0) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 18 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 19 | set (VERSION 4.0.0) |
| 20 | set (SOVERSION 4) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 21 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 22 | # Define supported command line parameters. |
| 23 | # |
| 24 | # Example to build the tivi client: cmake -DTIVI=true .. |
| 25 | # Without any options cmake generates libzrtpcpp for use with GNU ccRTP |
| 26 | # |
| 27 | option(CCRTP "Build library to use with GNU ccRTP." OFF) |
| 28 | option(CORE_LIB "Build core library only, no spcific client support." OFF) |
| 29 | option(CRYPTO_STANDALONE "Use embedded crypto and big number modules." ON) |
| 30 | option(TIVI "Build library for the tivi client, implies '-DCRYPTO_STNDALONE=true'." OFF) |
| 31 | option(SQLITE "Use SQLite DB as backend for ZRTP cache." OFF) |
| 32 | |
| 33 | option(ANDROID "Generate Android makefiles (Android.mk)" ON) |
| 34 | option(JAVA "Generate Java support files (requires JDK and SWIG)" OFF) |
| 35 | |
| 36 | |
| 37 | # **** Check what and how to build **** |
| 38 | # |
| 39 | if (CCRTP AND TIVI) |
| 40 | MESSAGE(FATAL_ERROR "Cannot build more than one client at once. Use different build directories.") |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 41 | endif() |
| 42 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 43 | if (CCRTP) |
| 44 | set (PACKAGE libzrtpcpp) |
| 45 | set(zrtplibName zrtpcpp) |
| 46 | elseif (TIVI) |
| 47 | set (PACKAGE libzrtptivi) |
| 48 | set(zrtplibName zrtptivi) |
| 49 | set(CRYPTO_STANDALONE true) |
| 50 | set(SQLITE true) |
| 51 | elseif (CORE_LIB) |
| 52 | set (PACKAGE libzrtpcore) |
| 53 | set(zrtplibName zrtpcppcore) |
| 54 | else() |
| 55 | MESSAGE(WARNING "No client defined, building for GNU ccRTP.") |
| 56 | set (PACKAGE libzrtpcpp) |
| 57 | set(CCRTP true) |
| 58 | set(zrtplibName zrtpcpp) |
| 59 | endif() |
| 60 | |
| 61 | |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 62 | if(MSVC60) |
| 63 | set(BUILD_STATIC ON CACHE BOOL "static linking only" FORCE) |
| 64 | MARK_AS_ADVANCED(BUILD_STATIC) |
| 65 | else() |
| 66 | option(BUILD_STATIC "Set to OFF to build shared libraries" OFF) |
| 67 | endif() |
| 68 | |
| 69 | # set to true for debug and trace during CMakeLists development |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 70 | # set(CMAKE_VERBOSE_MAKEFILE TRUE) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 71 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 72 | execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_COMMIT) |
| 73 | STRING(REGEX REPLACE "(\r?\n)+$" "" GIT_COMMIT "${GIT_COMMIT}") |
| 74 | |
| 75 | MESSAGE( STATUS "Configuring GNU ${PROJECT_NAME} ${VERSION} for ${PACKAGE}, commit: ${GIT_COMMIT} ...") |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 76 | |
| 77 | # include most of the fine stuff we need |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 78 | include(FindPkgConfig) |
| 79 | include(CheckLibraryExists) |
| 80 | include(CheckIncludeFiles) |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 81 | include(CheckFunctionExists) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 82 | |
| 83 | if (NOT LIB_SUFFIX) |
| 84 | set(LIBDIRNAME "lib") |
| 85 | # this caused problems in debian where it has to always be lib.... |
| 86 | if (NOT EXISTS /etc/debian_version) |
| 87 | if ( "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" ) |
| 88 | set(LIBDIRNAME "lib64") |
| 89 | endif() |
| 90 | endif() |
| 91 | else() |
| 92 | set(LIBDIRNAME "lib${LIB_SUFFIX}") |
| 93 | endif() |
| 94 | |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 95 | check_include_files(stdlib.h HAVE_STDLIB_H) |
| 96 | check_include_files(string.h HAVE_STRING_H) |
| 97 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 98 | if (NOT CRYPTO_STANDALONE) |
| 99 | pkg_check_modules(OPENSSL libcrypto>=0.9.8) |
| 100 | if (OPENSSL_FOUND) |
| 101 | set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENSSL_INCLUDE_DIRS}) #update include files search directory |
| 102 | check_include_files(openssl/bn.h HAVE_OPENSSL_BN_H) |
| 103 | check_include_files(openssl/aes.h HAVE_OPENSSL_AES_H) |
| 104 | check_include_files(openssl/sha.h HAVE_OPENSSL_SHA_H) |
| 105 | check_library_exists(crypto EVP_CipherInit_ex "${OPENSSL_LIBDIR}" HAVE_SSL_CRYPT) #use search lib directory from pkg-config |
| 106 | set(LIBS ${LIBS} -lcrypto) |
| 107 | set(CRYPTOBACKEND "libcrypto >= 0.9.8") |
| 108 | set(BUILD_REQ "libopenssl-devel >= 0.9.8") |
| 109 | set(PACKAGE_REQ "libopenssl >= 0.9.8") |
| 110 | include_directories(${OPENSSL_INCLUDE_DIRS}) #update includes directory from pkg-config |
| 111 | else() |
| 112 | message(FATAL_ERROR "No crypto library found") |
| 113 | endif() |
| 114 | else() |
| 115 | # For crypto standalone mode we need to configure the bnlib. In a first step |
| 116 | # without the tests and demos. |
| 117 | check_include_files(stdint.h HAVE_STDINT_H) |
| 118 | check_include_files(stdint.h HAVE_ASSERT_H) |
| 119 | check_include_files(limits.h HAVE_LIMITS_H) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 120 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 121 | check_function_exists(memmove HAVE_MEMMOVE) |
| 122 | check_function_exists(memcpy HAVE_MEMCPY) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 123 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 124 | # TODO: check if we compile the tests for bnlib |
| 125 | # |
| 126 | # check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) |
| 127 | # check_function_exists(getrusage HAVE_GETRUSAGE) |
| 128 | # check_function_exists(clock HAVE_CLOCK) |
| 129 | # check_function_exists(time HAVE_TIME) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 130 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 131 | # Check if Solaris-style gethrvtime() is available |
| 132 | # check_function_exists(gethrvtime HAVE_GETHRVTIME) |
| 133 | # |
| 134 | # until here |
| 135 | |
| 136 | # necessary and required modules checked, ready to generate config.h |
| 137 | configure_file(${CMAKE_SOURCE_DIR}/bnlib/bnconfig.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/bnconfig.h) |
| 138 | endif() |
| 139 | |
| 140 | if (SQLITE) |
| 141 | pkg_check_modules(SQLITE3 sqlite3>=3.7) |
| 142 | if (SQLITE3_FOUND) |
| 143 | check_include_files(sqlite3.h HAVE_SQLITE_H) |
| 144 | set(LIBS ${LIBS} -lsqlite3) |
| 145 | else() |
| 146 | message(FATAL_ERROR "SQLite3 library not found") |
| 147 | endif() |
| 148 | endif() |
| 149 | |
| 150 | # necessary and required modules checked, ready to generate config.h in top-level build directory |
| 151 | configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 152 | |
| 153 | add_definitions(-g -O2 -fno-strict-aliasing) |
| 154 | if(CMAKE_COMPILER_IS_GNUCXX) |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 155 | # add_definitions(-Wno-long-long -Wno-char-subscripts) |
| 156 | # add_definitions(-Wall -ansi -pedantic) |
| 157 | # add_definitions(-Wall -pedantic) |
| 158 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -std=c99") |
| 159 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -std=c++11") |
| 160 | add_definitions(-DNEW_STDCPP) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 161 | endif() |
| 162 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 163 | include_directories(BEFORE ${CMAKE_BINARY_DIR}) |
| 164 | include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/zrtp) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 165 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 166 | if(CRYPTO_STANDALONE) |
| 167 | add_definitions(-DSUPPORT_NON_NIST) |
| 168 | include_directories (${CMAKE_SOURCE_DIR}/bnlib) |
| 169 | endif() |
| 170 | |
| 171 | if (NOT CCRTP) |
| 172 | set (sdes_src ${CMAKE_SOURCE_DIR}/zrtp/ZrtpSdesStream.cpp) |
| 173 | endif() |
| 174 | |
| 175 | # **** The following source files a common for all clients **** |
| 176 | # |
| 177 | set(zrtp_src_no_cache |
| 178 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpCallbackWrapper.cpp |
| 179 | ${CMAKE_SOURCE_DIR}/zrtp/ZRtp.cpp |
| 180 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpCrc32.cpp |
| 181 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketCommit.cpp |
| 182 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketConf2Ack.cpp |
| 183 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketConfirm.cpp |
| 184 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketDHPart.cpp |
| 185 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketGoClear.cpp |
| 186 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketClearAck.cpp |
| 187 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketHelloAck.cpp |
| 188 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketHello.cpp |
| 189 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketError.cpp |
| 190 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketErrorAck.cpp |
| 191 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketPingAck.cpp |
| 192 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketPing.cpp |
| 193 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketSASrelay.cpp |
| 194 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpPacketRelayAck.cpp |
| 195 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpStateClass.cpp |
| 196 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpTextData.cpp |
| 197 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpConfigure.cpp |
| 198 | ${CMAKE_SOURCE_DIR}/zrtp/ZrtpCWrapper.cpp |
| 199 | ${CMAKE_SOURCE_DIR}/zrtp/Base32.cpp |
| 200 | ${CMAKE_SOURCE_DIR}/zrtp/zrtpB64Encode.c |
| 201 | ${CMAKE_SOURCE_DIR}/zrtp/zrtpB64Decode.c |
| 202 | ${CMAKE_SOURCE_DIR}/common/osSpecifics.c ${sdes_src}) |
| 203 | |
| 204 | set(bnlib_src |
| 205 | ${CMAKE_SOURCE_DIR}/bnlib/bn00.c |
| 206 | ${CMAKE_SOURCE_DIR}/bnlib/lbn00.c |
| 207 | ${CMAKE_SOURCE_DIR}/bnlib/bn.c |
| 208 | ${CMAKE_SOURCE_DIR}/bnlib/lbnmem.c |
| 209 | ${CMAKE_SOURCE_DIR}/bnlib/sieve.c |
| 210 | ${CMAKE_SOURCE_DIR}/bnlib/prime.c |
| 211 | ${CMAKE_SOURCE_DIR}/bnlib/bnprint.c |
| 212 | ${CMAKE_SOURCE_DIR}/bnlib/jacobi.c |
| 213 | ${CMAKE_SOURCE_DIR}/bnlib/germain.c |
| 214 | ${CMAKE_SOURCE_DIR}/bnlib/ec/ec.c |
| 215 | ${CMAKE_SOURCE_DIR}/bnlib/ec/ecdh.c |
| 216 | ${CMAKE_SOURCE_DIR}/bnlib/ec/curve25519-donna.c) |
| 217 | |
| 218 | set(zrtp_skein_src |
| 219 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/skeinMac256.cpp |
| 220 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/skein256.cpp |
| 221 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/skeinMac384.cpp |
| 222 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/skein384.cpp) |
| 223 | |
| 224 | set(zrtp_crypto_src |
| 225 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/zrtpDH.cpp |
| 226 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/hmac256.cpp |
| 227 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/sha256.cpp |
| 228 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/hmac384.cpp |
| 229 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/sha384.cpp |
| 230 | |
| 231 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/aesCFB.cpp |
| 232 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/twoCFB.cpp |
| 233 | ${CMAKE_SOURCE_DIR}/zrtp/crypto/sha2.c) |
| 234 | |
| 235 | if (NOT SQLITE) |
| 236 | set(zrtp_src ${zrtp_src_no_cache} |
| 237 | ${CMAKE_SOURCE_DIR}/zrtp/ZIDCacheFile.cpp |
| 238 | ${CMAKE_SOURCE_DIR}/zrtp/ZIDRecordFile.cpp) |
| 239 | else() |
| 240 | set(zrtp_src ${zrtp_src_no_cache} |
| 241 | ${CMAKE_SOURCE_DIR}/zrtp/ZIDCacheDb.cpp |
| 242 | ${CMAKE_SOURCE_DIR}/zrtp/ZIDRecordDb.cpp |
| 243 | ${CMAKE_SOURCE_DIR}/zrtp/zrtpCacheSqliteBackend.c) |
| 244 | |
| 245 | endif() |
| 246 | |
| 247 | if (CCRTP) |
| 248 | add_subdirectory(clients/ccrtp) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 249 | add_subdirectory(demo) |
| 250 | endif() |
| 251 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 252 | if (TIVI) |
| 253 | add_subdirectory(clients/tivi) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 254 | endif() |
| 255 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 256 | if (CORE_LIB) |
| 257 | add_subdirectory(clients/no_client) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 258 | endif() |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 259 | |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 260 | ##very usefull for macosx, specially when using gtkosx bundler |
| 261 | if(APPLE) |
| 262 | if (NOT CMAKE_INSTALL_NAME_DIR) |
| 263 | set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "CMAKE_INSTALL_NAME_DIR set for macosx" ) |
| 264 | endif (NOT CMAKE_INSTALL_NAME_DIR) |
| 265 | endif(APPLE) |