blob: 430f5e74f44c3034782c0186e888322d2af9adac [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 Lisionddd731e2014-01-31 11:50:08 -050014set (PACKAGE libzrtpcpp)
15set (VERSION 3.0.0)
16set (SOVERSION ${VERSION})
17STRING(REGEX REPLACE "[.].*$" "" SOVERSION ${SOVERSION})
Alexandre Lision51140e12013-12-02 10:54:09 -050018
Alexandre Lisionddd731e2014-01-31 11:50:08 -050019SET(CPACK_PACKAGE_VERSION_MAJOR ${SOVERSION})
20SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION})
21SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION})
22STRING(REGEX REPLACE "[.][0-9]*$" "" CPACK_PACKAGE_VERSION_MINOR ${VERSION})
23STRING(REGEX REPLACE ".*[.]" "" CPACK_PACKAGE_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR})
24STRING(REGEX REPLACE ".*[.]" "" CPACK_PACKAGE_VERSION_PATCH ${VERSION})
Alexandre Lision51140e12013-12-02 10:54:09 -050025
Alexandre Lisionddd731e2014-01-31 11:50:08 -050026include(cmake/Modules/AutoArgs.cmake)
27include(cmake/Modules/FindGcryptConfig.cmake)
Alexandre Lision51140e12013-12-02 10:54:09 -050028
Alexandre Lisionddd731e2014-01-31 11:50:08 -050029# Define supported -Denable-* command line parameters.
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050030#
Alexandre Lisionddd731e2014-01-31 11:50:08 -050031# Example to build the tivi client: cmake -Denable-tivi=true ..
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050032# Without any options cmake generates libzrtpcpp for use with GNU ccRTP
33#
Alexandre Lisionddd731e2014-01-31 11:50:08 -050034enable_arg(ccrtp false "Build library to use with GNU ccRTP.")
35enable_arg(crypto_standalone false "Use embedded crypto and big number modules.")
36enable_arg(tivi false "Build library for the tivi client, implies '-Denable-crypto_standalone=true'.")
37enable_arg(sqlite false "Use SQLite DB as backend for ZRTP cache.")
38args_help()
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050039
40# **** Check what and how to build ****
41#
Alexandre Lisionddd731e2014-01-31 11:50:08 -050042if (enable_ccrtp AND enable_tivi)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050043 MESSAGE(FATAL_ERROR "Cannot build more than one client at once. Use different build directories.")
Alexandre Lision51140e12013-12-02 10:54:09 -050044endif()
45
Alexandre Lisionddd731e2014-01-31 11:50:08 -050046if (enable_ccrtp)
47 if (USES_CCRTP_INCLUDE_DIRS)
48 message(STATUS " Using local commoncpp dependency")
49 else()
50 find_package(PkgConfig)
51 pkg_check_modules(USES_CCRTP libccrtp>=2.0.0)
52 endif()
53 include_directories(${USES_CCRTP_INCLUDE_DIRS})
54 link_directories(${USES_CRTP_LIBRARY_DIRS})
55 add_definitions(${USES_CCRTP_CFLAGS})
56 set (LIBS ${LIBS} ${USES_CCRTP_LDFLAGS} ${USES_CCRTP_LIBRARIES})
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050057 set (PACKAGE libzrtpcpp)
58 set(zrtplibName zrtpcpp)
Alexandre Lisionddd731e2014-01-31 11:50:08 -050059elseif (enable_tivi)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050060 set (PACKAGE libzrtptivi)
61 set(zrtplibName zrtptivi)
Alexandre Lisionddd731e2014-01-31 11:50:08 -050062 set (enable_crypto_standalone true)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050063else()
64 MESSAGE(WARNING "No client defined, building for GNU ccRTP.")
65 set (PACKAGE libzrtpcpp)
Alexandre Lisionddd731e2014-01-31 11:50:08 -050066 set(enable_ccrtp true)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050067 set(zrtplibName zrtpcpp)
68endif()
69
Alexandre Lisionddd731e2014-01-31 11:50:08 -050070if (enable_crypto_standalone)
71 set(CRYPTO_STANDALONE TRUE)
72endif()
73
74if(CMAKE_GENERATOR MATCHES "Unix Makefiles")
75 add_custom_target(cleandist
76 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
77 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}[-_]*.gz"
78 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}_*.dsc"
79 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}-*.rpm"
80 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/*${PACKAGE}*[-_]*.deb"
81 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}-*.zip"
82 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/*${PACKAGE}*.changes"
83 )
84
85 add_custom_target(dist
86 DEPENDS cleandist
87 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
88 COMMAND git archive --format tar --output="${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}-${VERSION}.tar" --prefix="${PACKAGE}-${VERSION}/" HEAD
89 COMMAND gzip "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}-${VERSION}.tar"
90 )
91endif()
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050092
Alexandre Lision51140e12013-12-02 10:54:09 -050093if(MSVC60)
94 set(BUILD_STATIC ON CACHE BOOL "static linking only" FORCE)
95 MARK_AS_ADVANCED(BUILD_STATIC)
96else()
97 option(BUILD_STATIC "Set to OFF to build shared libraries" OFF)
98endif()
99
100# set to true for debug and trace during CMakeLists development
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500101# set(CMAKE_VERBOSE_MAKEFILE TRUE)
Alexandre Lision51140e12013-12-02 10:54:09 -0500102
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500103MESSAGE( STATUS "Configuring GNU ${PROJECT_NAME} ${VERSION} for ${PACKAGE}...")
Alexandre Lision51140e12013-12-02 10:54:09 -0500104
105# include most of the fine stuff we need
Alexandre Lision51140e12013-12-02 10:54:09 -0500106include(FindPkgConfig)
107include(CheckLibraryExists)
108include(CheckIncludeFiles)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500109include(CheckFunctionExists)
Alexandre Lision51140e12013-12-02 10:54:09 -0500110
111if (NOT LIB_SUFFIX)
112 set(LIBDIRNAME "lib")
113 # this caused problems in debian where it has to always be lib....
114 if (NOT EXISTS /etc/debian_version)
115 if ( "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" )
116 set(LIBDIRNAME "lib64")
117 endif()
118 endif()
119else()
120 set(LIBDIRNAME "lib${LIB_SUFFIX}")
121endif()
122
Alexandre Lision51140e12013-12-02 10:54:09 -0500123check_include_files(stdlib.h HAVE_STDLIB_H)
124check_include_files(string.h HAVE_STRING_H)
125
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500126if (NOT enable_crypto_standalone)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500127 pkg_check_modules(OPENSSL libcrypto>=0.9.8)
128 if (OPENSSL_FOUND)
129 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENSSL_INCLUDE_DIRS}) #update include files search directory
130 check_include_files(openssl/bn.h HAVE_OPENSSL_BN_H)
131 check_include_files(openssl/aes.h HAVE_OPENSSL_AES_H)
132 check_include_files(openssl/sha.h HAVE_OPENSSL_SHA_H)
133 check_library_exists(crypto EVP_CipherInit_ex "${OPENSSL_LIBDIR}" HAVE_SSL_CRYPT) #use search lib directory from pkg-config
134 set(LIBS ${LIBS} -lcrypto)
135 set(CRYPTOBACKEND "libcrypto >= 0.9.8")
136 set(BUILD_REQ "libopenssl-devel >= 0.9.8")
137 set(PACKAGE_REQ "libopenssl >= 0.9.8")
138 include_directories(${OPENSSL_INCLUDE_DIRS}) #update includes directory from pkg-config
139 else()
140 message(FATAL_ERROR "No crypto library found")
141 endif()
142else()
143 # For crypto standalone mode we need to configure the bnlib. In a first step
144 # without the tests and demos.
145 check_include_files(stdint.h HAVE_STDINT_H)
146 check_include_files(stdint.h HAVE_ASSERT_H)
147 check_include_files(limits.h HAVE_LIMITS_H)
Alexandre Lision51140e12013-12-02 10:54:09 -0500148
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500149 check_function_exists(memmove HAVE_MEMMOVE)
150 check_function_exists(memcpy HAVE_MEMCPY)
Alexandre Lision51140e12013-12-02 10:54:09 -0500151
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500152 # TODO: check if we compile the tests for bnlib
153 #
154 # check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
155 # check_function_exists(getrusage HAVE_GETRUSAGE)
156 # check_function_exists(clock HAVE_CLOCK)
157 # check_function_exists(time HAVE_TIME)
Alexandre Lision51140e12013-12-02 10:54:09 -0500158
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500159 # Check if Solaris-style gethrvtime() is available
160 # check_function_exists(gethrvtime HAVE_GETHRVTIME)
161 #
162 # until here
163
164 # necessary and required modules checked, ready to generate config.h
165 configure_file(${CMAKE_SOURCE_DIR}/bnlib/bnconfig.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/bnconfig.h)
166endif()
167
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500168if (enable_sqlite)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500169 pkg_check_modules(SQLITE3 sqlite3>=3.7)
170 if (SQLITE3_FOUND)
171 check_include_files(sqlite3.h HAVE_SQLITE_H)
172 set(LIBS ${LIBS} -lsqlite3)
173 else()
174 message(FATAL_ERROR "SQLite3 library not found")
175 endif()
176endif()
177
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500178# now get info about crypto libraries
179gcr_check(GCRYPT gcrypt)
180#if(GCRYPT_FOUND)
181# check_include_files(gcrypt.h HAVE_GCRYPT_H)
182# set(LIBS ${LIBS} ${GCRYPT_LIBRARIES})
183# set(BUILD_REQ "libgcrypt-devel")
184# set(CRYPTOBACKEND="")
185# set(PACKAGE_REQ "libgcrypt")
186#else()
187 pkg_check_modules(OPENSSL libcrypto>=0.9.8)
188 if (OPENSSL_FOUND)
189 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENSSL_INCLUDE_DIRS}) #update include files search directory
190 check_include_files(openssl/bn.h HAVE_OPENSSL_BN_H)
191 check_include_files(openssl/aes.h HAVE_OPENSSL_AES_H)
192 check_include_files(openssl/sha.h HAVE_OPENSSL_SHA_H)
193 check_library_exists(crypto EVP_CipherInit_ex "${OPENSSL_LIBDIR}" HAVE_SSL_CRYPT) #use search lib directory from pkg-config
194 set(LIBS ${LIBS} -lcrypto)
195 set(CRYPTOBACKEND "libcrypto >= 0.9.8")
196 set(BUILD_REQ "libopenssl-devel >= 0.9.8")
197 set(PACKAGE_REQ "libopenssl >= 0.9.8")
198 include_directories(${OPENSSL_INCLUDE_DIRS}) #update includes directory from pkg-config
199 else()
200 message(FATAL_ERROR "No crypto library found")
201 endif()
202#endif()
203
204check_include_files(stdlib.h HAVE_STDLIB_H)
205check_include_files(string.h HAVE_STRING_H)
206
207# necessary and required modules checked, ready to generate config.h
208configure_file(libzrtpcpp-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/libzrtpcpp-config.h)
209include_directories(${CMAKE_CURRENT_BINARY_DIR})
210
211# the following set(...) commands are only to have backward
212# compatibility with autoconf stuff to generate the pc file
213set(prefix ${CMAKE_INSTALL_PREFIX})
214set(exec_prefix ${prefix}/bin)
215set(libdir ${prefix}/${LIBDIRNAME})
216set(includedir ${prefix}/include)
217set(PACKAGE pkgconfig)
218configure_file(libzrtpcpp.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libzrtpcpp.pc @ONLY)
219
220configure_file(libzrtpcpp.spec.cmake ${CMAKE_CURRENT_BINARY_DIR}/libzrtpcpp.spec @ONLY)
221
222#to make sure includes are first taken from those directory
223include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src)
Alexandre Lision51140e12013-12-02 10:54:09 -0500224
225add_definitions(-g -O2 -fno-strict-aliasing)
226if(CMAKE_COMPILER_IS_GNUCXX)
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500227 add_definitions(-Wno-long-long -Wno-char-subscripts)
228 add_definitions(-Wall -pedantic)
229 add_definitions(-DNEW_STDCPP)
Alexandre Lision51140e12013-12-02 10:54:09 -0500230endif()
231
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500232include_directories(BEFORE ${CMAKE_BINARY_DIR})
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500233include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/zrtp)
234if(enable_standalone)
235 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/bnlib)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500236endif()
237
238# **** The following source files a common for all clients ****
239#
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500240if (NOT enable_ccrtp)
241 set (sdes_src ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpSdesStream.cpp)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500242endif()
243
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500244set(zrtp_src_no_cache
245 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpCallbackWrapper.cpp
246 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZRtp.cpp
247 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpCrc32.cpp
248 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketCommit.cpp
249 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketConf2Ack.cpp
250 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketConfirm.cpp
251 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketDHPart.cpp
252 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketGoClear.cpp
253 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketClearAck.cpp
254 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketHelloAck.cpp
255 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketHello.cpp
256 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketError.cpp
257 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketErrorAck.cpp
258 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketPingAck.cpp
259 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketPing.cpp
260 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketSASrelay.cpp
261 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpPacketRelayAck.cpp
262 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpStateClass.cpp
263 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpTextData.cpp
264 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpConfigure.cpp
265 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZrtpCWrapper.cpp
266 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/Base32.cpp
267 ${CMAKE_CURRENT_SOURCE_DIR}/common/osSpecifics.c ${sdes_src})
268
269set(bnlib_src
270 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/bn00.c
271 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/lbn00.c
272 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/bn.c
273 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/lbnmem.c
274 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/sieve.c
275 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/prime.c
276 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/bnprint.c
277 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/jacobi.c
278 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/germain.c
279 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/ec/ec.c
280 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/ec/ecdh.c
281 ${CMAKE_CURRENT_SOURCE_DIR}/bnlib/bnprint.c)
282
283set(zrtp_crypto_src
284 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/crypto/zrtpDH.cpp
285 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/crypto/hmac256.cpp
286 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/crypto/sha256.cpp
287 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/crypto/hmac384.cpp
288 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/crypto/sha384.cpp
289 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/crypto/aesCFB.cpp
290 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/crypto/twoCFB.cpp
291 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/crypto/sha2.c)
292
293if (NOT enable_sqlite)
294 set(zrtp_src ${zrtp_src_no_cache}
295 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZIDCacheFile.cpp
296 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZIDRecordFile.cpp)
297else()
298 set(zrtp_src ${zrtp_src_no_cache}
299 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZIDCacheDb.cpp
300 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/ZIDRecordDb.cpp
301 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/zrtpB64Encode.c
302 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/zrtpB64Decode.c
303 ${CMAKE_CURRENT_SOURCE_DIR}/zrtp/zrtpCacheSqliteBackend.c)
304endif()
305
306if (enable_ccrtp)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500307 add_subdirectory(clients/ccrtp)
Alexandre Lision51140e12013-12-02 10:54:09 -0500308 add_subdirectory(demo)
309endif()
310
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500311if (enable_tivi)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500312 add_subdirectory(clients/tivi)
Alexandre Lision51140e12013-12-02 10:54:09 -0500313endif()
314
Alexandre Lision51140e12013-12-02 10:54:09 -0500315##very usefull for macosx, specially when using gtkosx bundler
316if(APPLE)
317 if (NOT CMAKE_INSTALL_NAME_DIR)
318 set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "CMAKE_INSTALL_NAME_DIR set for macosx" )
319 endif (NOT CMAKE_INSTALL_NAME_DIR)
320endif(APPLE)
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500321
322