blob: 752e29f2bbb217436420f133c7fabe419758c351 [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001# 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#
11cmake_minimum_required(VERSION 2.6)
12
13PROJECT(libzrtpcpp)
Alexandre Lision51140e12013-12-02 10:54:09 -050014
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050015SET(CPACK_PACKAGE_VERSION_MAJOR 4)
16SET(CPACK_PACKAGE_VERSION_MINOR 0)
17SET(CPACK_PACKAGE_VERSION_PATCH 0)
Alexandre Lision51140e12013-12-02 10:54:09 -050018
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050019set (VERSION 4.0.0)
20set (SOVERSION 4)
Alexandre Lision51140e12013-12-02 10:54:09 -050021
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050022# 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#
27option(CCRTP "Build library to use with GNU ccRTP." OFF)
28option(CORE_LIB "Build core library only, no spcific client support." OFF)
29option(CRYPTO_STANDALONE "Use embedded crypto and big number modules." ON)
30option(TIVI "Build library for the tivi client, implies '-DCRYPTO_STNDALONE=true'." OFF)
31option(SQLITE "Use SQLite DB as backend for ZRTP cache." OFF)
32
33option(ANDROID "Generate Android makefiles (Android.mk)" ON)
34option(JAVA "Generate Java support files (requires JDK and SWIG)" OFF)
35
36
37# **** Check what and how to build ****
38#
39if (CCRTP AND TIVI)
40 MESSAGE(FATAL_ERROR "Cannot build more than one client at once. Use different build directories.")
Alexandre Lision51140e12013-12-02 10:54:09 -050041endif()
42
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050043if (CCRTP)
44 set (PACKAGE libzrtpcpp)
45 set(zrtplibName zrtpcpp)
46elseif (TIVI)
47 set (PACKAGE libzrtptivi)
48 set(zrtplibName zrtptivi)
49 set(CRYPTO_STANDALONE true)
50 set(SQLITE true)
51elseif (CORE_LIB)
52 set (PACKAGE libzrtpcore)
53 set(zrtplibName zrtpcppcore)
54else()
55 MESSAGE(WARNING "No client defined, building for GNU ccRTP.")
56 set (PACKAGE libzrtpcpp)
57 set(CCRTP true)
58 set(zrtplibName zrtpcpp)
59endif()
60
61
Alexandre Lision51140e12013-12-02 10:54:09 -050062if(MSVC60)
63 set(BUILD_STATIC ON CACHE BOOL "static linking only" FORCE)
64 MARK_AS_ADVANCED(BUILD_STATIC)
65else()
66 option(BUILD_STATIC "Set to OFF to build shared libraries" OFF)
67endif()
68
69# set to true for debug and trace during CMakeLists development
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050070# set(CMAKE_VERBOSE_MAKEFILE TRUE)
Alexandre Lision51140e12013-12-02 10:54:09 -050071
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050072execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_COMMIT)
73STRING(REGEX REPLACE "(\r?\n)+$" "" GIT_COMMIT "${GIT_COMMIT}")
74
75MESSAGE( STATUS "Configuring GNU ${PROJECT_NAME} ${VERSION} for ${PACKAGE}, commit: ${GIT_COMMIT} ...")
Alexandre Lision51140e12013-12-02 10:54:09 -050076
77# include most of the fine stuff we need
Alexandre Lision51140e12013-12-02 10:54:09 -050078include(FindPkgConfig)
79include(CheckLibraryExists)
80include(CheckIncludeFiles)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050081include(CheckFunctionExists)
Alexandre Lision51140e12013-12-02 10:54:09 -050082
83if (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()
91else()
92 set(LIBDIRNAME "lib${LIB_SUFFIX}")
93endif()
94
Alexandre Lision51140e12013-12-02 10:54:09 -050095check_include_files(stdlib.h HAVE_STDLIB_H)
96check_include_files(string.h HAVE_STRING_H)
97
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050098if (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()
114else()
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 Lision51140e12013-12-02 10:54:09 -0500120
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500121 check_function_exists(memmove HAVE_MEMMOVE)
122 check_function_exists(memcpy HAVE_MEMCPY)
Alexandre Lision51140e12013-12-02 10:54:09 -0500123
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500124 # 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 Lision51140e12013-12-02 10:54:09 -0500130
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500131 # 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)
138endif()
139
140if (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()
148endif()
149
150# necessary and required modules checked, ready to generate config.h in top-level build directory
151configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
Alexandre Lision51140e12013-12-02 10:54:09 -0500152
153add_definitions(-g -O2 -fno-strict-aliasing)
154if(CMAKE_COMPILER_IS_GNUCXX)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500155# 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 Lision51140e12013-12-02 10:54:09 -0500161endif()
162
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500163include_directories(BEFORE ${CMAKE_BINARY_DIR})
164include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/zrtp)
Alexandre Lision51140e12013-12-02 10:54:09 -0500165
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500166if(CRYPTO_STANDALONE)
167 add_definitions(-DSUPPORT_NON_NIST)
168 include_directories (${CMAKE_SOURCE_DIR}/bnlib)
169endif()
170
171if (NOT CCRTP)
172 set (sdes_src ${CMAKE_SOURCE_DIR}/zrtp/ZrtpSdesStream.cpp)
173endif()
174
175# **** The following source files a common for all clients ****
176#
177set(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
204set(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
218set(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
224set(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
235if (NOT SQLITE)
236 set(zrtp_src ${zrtp_src_no_cache}
237 ${CMAKE_SOURCE_DIR}/zrtp/ZIDCacheFile.cpp
238 ${CMAKE_SOURCE_DIR}/zrtp/ZIDRecordFile.cpp)
239else()
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
245endif()
246
247if (CCRTP)
248 add_subdirectory(clients/ccrtp)
Alexandre Lision51140e12013-12-02 10:54:09 -0500249 add_subdirectory(demo)
250endif()
251
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500252if (TIVI)
253 add_subdirectory(clients/tivi)
Alexandre Lision51140e12013-12-02 10:54:09 -0500254endif()
255
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500256if (CORE_LIB)
257 add_subdirectory(clients/no_client)
Alexandre Lision51140e12013-12-02 10:54:09 -0500258endif()
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500259
Alexandre Lision51140e12013-12-02 10:54:09 -0500260##very usefull for macosx, specially when using gtkosx bundler
261if(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)
265endif(APPLE)