blob: 399e776e230c39d85e02bec469fc6bd991003f32 [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)
14set (VERSION 2.3.4)
15set (PACKAGE libzrtpcpp)
16set (SOVERSION ${VERSION})
17STRING(REGEX REPLACE "[.].*$" "" SOVERSION ${SOVERSION})
18
19SET(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})
25
26if(CMAKE_GENERATOR MATCHES "Unix Makefiles")
27 add_custom_target(cleandist
28 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
29 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}[-_]*.gz"
30 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}_*.dsc"
31 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}-*.rpm"
32 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}[-_]*.deb"
33 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}[-_]*.changes"
34 COMMAND rm -f "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}-*.zip"
35 )
36
37 add_custom_target(dist
38 DEPENDS cleandist
39 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
40 COMMAND git archive --format tar --output="${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}-${VERSION}.tar" --prefix="${PACKAGE}-${VERSION}/" HEAD
41 COMMAND gzip "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}-${VERSION}.tar"
42 )
43endif()
44
45if(MSVC60)
46 set(BUILD_STATIC ON CACHE BOOL "static linking only" FORCE)
47 MARK_AS_ADVANCED(BUILD_STATIC)
48else()
49 option(BUILD_STATIC "Set to OFF to build shared libraries" OFF)
50endif()
51
52# set to true for debug and trace during CMakeLists development
53set(CMAKE_VERBOSE_MAKEFILE FALSE)
54
55MESSAGE( STATUS "Configuring GNU ${PROJECT_NAME} ${VERSION}...")
56
57# include most of the fine stuff we need
58include(cmake/Modules/FindGcryptConfig.cmake)
59include(FindPkgConfig)
60include(CheckLibraryExists)
61include(CheckIncludeFiles)
62include(cmake/Modules/AutoArgs.cmake)
63
64if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME})
65 include(cmake/Modules/GeneratePackage.cmake)
66
67 GENERATE_PACKAGING(${PACKAGE} ${VERSION})
68endif()
69
70# check the -Denable-ccrtp setting, defaults to true
71enable_arg(ccrtp true "Enable GNU ccRTP support for GNU ZRTP")
72args_help()
73
74if (NOT LIB_SUFFIX)
75 set(LIBDIRNAME "lib")
76 # this caused problems in debian where it has to always be lib....
77 if (NOT EXISTS /etc/debian_version)
78 if ( "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" )
79 set(LIBDIRNAME "lib64")
80 endif()
81 endif()
82else()
83 set(LIBDIRNAME "lib${LIB_SUFFIX}")
84endif()
85
86# setup the Thread include and lib
87find_package(Threads)
88if(CMAKE_HAVE_PTHREAD_H)
89 set(HAVE_PTHREAD_H TRUE)
90endif()
91set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
92
93# define the name of the lib. zrtpcppcore does not include the ccRTP stuff.
94set(zrtplib zrtpcppcore)
95if(enable_ccrtp)
96 if (USES_CCRTP_INCLUDE_DIRS)
97 message(STATUS " Using local commoncpp dependency")
98 else()
99 find_package(PkgConfig)
100 pkg_check_modules(USES_CCRTP libccrtp>=2.0.0)
101 endif()
102 include_directories(${USES_CCRTP_INCLUDE_DIRS})
103 link_directories(${USES_CRTP_LIBRARY_DIRS})
104 add_definitions(${USES_CCRTP_CFLAGS})
105 set (LIBS ${LIBS} ${USES_CCRTP_LDFLAGS} ${USES_CCRTP_LIBRARIES})
106 set(zrtplib zrtpcpp)
107endif()
108
109# now get info about crypto libraries
110pkg_check_modules(OPENSSL libcrypto>=0.9.8)
111if (OPENSSL_FOUND)
112 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENSSL_INCLUDE_DIRS}) #update include files search directory
113 check_include_files(openssl/bn.h HAVE_OPENSSL_BN_H)
114 check_include_files(openssl/aes.h HAVE_OPENSSL_AES_H)
115 check_include_files(openssl/sha.h HAVE_OPENSSL_SHA_H)
116 check_include_files(openssl/ec.h HAVE_OPENSSL_EC_H)
117 check_library_exists(crypto EVP_CipherInit_ex "${OPENSSL_LIBDIR}" HAVE_SSL_CRYPT) #use search lib directory from pkg-config
118 set(LIBS ${LIBS} -lcrypto)
119 set(CRYPTOBACKEND "libcrypto >= 0.9.8")
120 set(BUILD_REQ "libopenssl-devel >= 0.9.8")
121 set(PACKAGE_REQ "libopenssl >= 0.9.8")
122 include_directories(${OPENSSL_INCLUDE_DIRS}) #update includes directory from pkg-config
123endif()
124
125if(NOT HAVE_OPENSSL_EC_H)
126 gcr_check(GCRYPT gcrypt)
127 if(GCRYPT_FOUND)
128 check_include_files(gcrypt.h HAVE_GCRYPT_H)
129 set(LIBS ${LIBS} ${GCRYPT_LIBRARIES})
130 set(BUILD_REQ "libgcrypt-devel")
131 set(CRYPTOBACKEND="")
132 set(PACKAGE_REQ "libgcrypt")
133 endif()
134endif()
135
136if(NOT OPENSSL_FOUND AND NOT GCRYPT_FOUND)
137 message(FATAL_ERROR "No crypto library found")
138endif()
139
140check_include_files(stdlib.h HAVE_STDLIB_H)
141check_include_files(string.h HAVE_STRING_H)
142
143# necessary and required modules checked, ready to generate config.h
144configure_file(libzrtpcpp-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/libzrtpcpp-config.h)
145include_directories(${CMAKE_CURRENT_BINARY_DIR})
146
147# the following set(...) commands are only to have backward
148# compatibility with autoconf stuff to generate the pc file
149set(prefix ${CMAKE_INSTALL_PREFIX})
150set(exec_prefix ${prefix}/bin)
151set(libdir ${prefix}/${LIBDIRNAME})
152set(includedir ${prefix}/include)
153set(PACKAGE pkgconfig)
154configure_file(libzrtpcpp.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/lib${zrtplib}.pc @ONLY)
155
156configure_file(libzrtpcpp.spec.cmake ${CMAKE_CURRENT_BINARY_DIR}/libzrtpcpp.spec @ONLY)
157
158#to make sure includes are first taken from those directory
159include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src)
160
161add_definitions(-g -O2 -fno-strict-aliasing)
162if(CMAKE_COMPILER_IS_GNUCXX)
163 add_definitions(-Wno-long-long -Wno-char-subscripts)
164 add_definitions(-Wall -pedantic)
165 add_definitions(-DNEW_STDCPP)
166endif()
167
168add_subdirectory(src)
169
170if (enable_ccrtp)
171 add_subdirectory(demo)
172endif()
173
174if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/package/)
175 MESSAGE(STATUS "package dir not found")
176 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/package/)
177endif()
178
179########### install files ###############
180install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${zrtplib}.pc DESTINATION ${LIBDIRNAME}/pkgconfig)
181
182if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME})
183
184 ########### Add uninstall target ###############
185 configure_file(
186 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
187 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
188 IMMEDIATE @ONLY)
189 add_custom_target(uninstall
190 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
191
192endif()
193##very usefull for macosx, specially when using gtkosx bundler
194if(APPLE)
195 if (NOT CMAKE_INSTALL_NAME_DIR)
196 set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "CMAKE_INSTALL_NAME_DIR set for macosx" )
197 endif (NOT CMAKE_INSTALL_NAME_DIR)
198endif(APPLE)
199
200