blob: 847717c74e4aba156960e7856be113176736dde7 [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 Lisione24852d2014-02-04 13:13:02 -050015SET(CPACK_PACKAGE_VERSION_MAJOR 2)
16SET(CPACK_PACKAGE_VERSION_MINOR 3)
17SET(CPACK_PACKAGE_VERSION_PATCH 0)
Alexandre Lision51140e12013-12-02 10:54:09 -050018
Alexandre Lisione24852d2014-02-04 13:13:02 -050019set (VERSION 2.3.0)
20set (SOVERSION 2)
21set (PACKAGE libzrtpcpp)
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050022
Alexandre Lision51140e12013-12-02 10:54:09 -050023if(MSVC60)
24 set(BUILD_STATIC ON CACHE BOOL "static linking only" FORCE)
25 MARK_AS_ADVANCED(BUILD_STATIC)
26else()
27 option(BUILD_STATIC "Set to OFF to build shared libraries" OFF)
28endif()
29
30# set to true for debug and trace during CMakeLists development
Alexandre Lisione24852d2014-02-04 13:13:02 -050031set(CMAKE_VERBOSE_MAKEFILE FALSE)
Alexandre Lision51140e12013-12-02 10:54:09 -050032
Alexandre Lisione24852d2014-02-04 13:13:02 -050033MESSAGE( STATUS "Configuring GNU ${PROJECT_NAME} ${VERSION}...")
Alexandre Lision51140e12013-12-02 10:54:09 -050034
35# include most of the fine stuff we need
Alexandre Lisione24852d2014-02-04 13:13:02 -050036include(cmake/Modules/FindGcryptConfig.cmake)
Alexandre Lision51140e12013-12-02 10:54:09 -050037include(FindPkgConfig)
38include(CheckLibraryExists)
39include(CheckIncludeFiles)
Alexandre Lisione24852d2014-02-04 13:13:02 -050040include(cmake/Modules/AutoArgs.cmake)
41
42if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME})
43 include(cmake/Modules/GeneratePackage.cmake)
44
45 GENERATE_PACKAGING(${PACKAGE} ${VERSION})
46endif()
47
48# check the -Denable-ccrtp setting, defaults to true
49enable_arg(ccrtp true "Enable GNU ccRTP support for GNU ZRTP")
50args_help()
Alexandre Lision51140e12013-12-02 10:54:09 -050051
52if (NOT LIB_SUFFIX)
53 set(LIBDIRNAME "lib")
54 # this caused problems in debian where it has to always be lib....
55 if (NOT EXISTS /etc/debian_version)
56 if ( "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" )
57 set(LIBDIRNAME "lib64")
58 endif()
59 endif()
60else()
61 set(LIBDIRNAME "lib${LIB_SUFFIX}")
62endif()
63
Alexandre Lisione24852d2014-02-04 13:13:02 -050064# setup the Thread include and lib
65find_package(Threads)
66if(CMAKE_HAVE_PTHREAD_H)
67 set(HAVE_PTHREAD_H TRUE)
68endif()
69set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
70
71# define the name of the lib. zrtpcppcore does not include the ccRTP stuff.
72set(zrtplib zrtpcppcore)
73if(enable_ccrtp)
74 if (USES_CCRTP_INCLUDE_DIRS)
75 message(STATUS " Using local commoncpp dependency")
76 else()
77 find_package(PkgConfig)
78 pkg_check_modules(USES_CCRTP libccrtp>=2.0.0)
79 endif()
80 include_directories(${USES_CCRTP_INCLUDE_DIRS})
81 link_directories(${USES_CRTP_LIBRARY_DIRS})
82 add_definitions(${USES_CCRTP_CFLAGS})
83 set (LIBS ${LIBS} ${USES_CCRTP_LDFLAGS} ${USES_CCRTP_LIBRARIES})
84 set(zrtplib zrtpcpp)
85endif()
86
87# now get info about crypto libraries
88gcr_check(GCRYPT gcrypt)
89#if(GCRYPT_FOUND)
90# check_include_files(gcrypt.h HAVE_GCRYPT_H)
91# set(LIBS ${LIBS} ${GCRYPT_LIBRARIES})
92# set(BUILD_REQ "libgcrypt-devel")
93# set(CRYPTOBACKEND="")
94# set(PACKAGE_REQ "libgcrypt")
95#else()
96 pkg_check_modules(OPENSSL libcrypto>=0.9.8)
97 if (OPENSSL_FOUND)
98 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENSSL_INCLUDE_DIRS}) #update include files search directory
99 check_include_files(openssl/bn.h HAVE_OPENSSL_BN_H)
100 check_include_files(openssl/aes.h HAVE_OPENSSL_AES_H)
101 check_include_files(openssl/sha.h HAVE_OPENSSL_SHA_H)
102 check_library_exists(crypto EVP_CipherInit_ex "${OPENSSL_LIBDIR}" HAVE_SSL_CRYPT) #use search lib directory from pkg-config
103 set(LIBS ${LIBS} -lcrypto)
104 set(CRYPTOBACKEND "libcrypto >= 0.9.8")
105 set(BUILD_REQ "libopenssl-devel >= 0.9.8")
106 set(PACKAGE_REQ "libopenssl >= 0.9.8")
107 include_directories(${OPENSSL_INCLUDE_DIRS}) #update includes directory from pkg-config
108 else()
109 message(FATAL_ERROR "No crypto library found")
110 endif()
111#endif()
112
Alexandre Lision51140e12013-12-02 10:54:09 -0500113check_include_files(stdlib.h HAVE_STDLIB_H)
114check_include_files(string.h HAVE_STRING_H)
115
Alexandre Lisione24852d2014-02-04 13:13:02 -0500116# necessary and required modules checked, ready to generate config.h
117configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
Alexandre Lision51140e12013-12-02 10:54:09 -0500118
Alexandre Lisione24852d2014-02-04 13:13:02 -0500119# the following set(...) commands are only to have backward
120# compatibility with autoconf stuff to generate the pc file
121set(prefix ${CMAKE_INSTALL_PREFIX})
122set(exec_prefix ${prefix}/bin)
123set(libdir ${prefix}/${LIBDIRNAME})
124set(includedir ${prefix}/include)
125set(PACKAGE pkgconfig)
126configure_file(libzrtpcpp.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/lib${zrtplib}.pc @ONLY)
Alexandre Lision51140e12013-12-02 10:54:09 -0500127
Alexandre Lisione24852d2014-02-04 13:13:02 -0500128configure_file(libzrtpcpp.spec.cmake ${CMAKE_CURRENT_BINARY_DIR}/libzrtpcpp.spec @ONLY)
Alexandre Lision51140e12013-12-02 10:54:09 -0500129
Alexandre Lisione24852d2014-02-04 13:13:02 -0500130#to make sure includes are first taken from those directory
131include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src)
Alexandre Lision51140e12013-12-02 10:54:09 -0500132
133add_definitions(-g -O2 -fno-strict-aliasing)
134if(CMAKE_COMPILER_IS_GNUCXX)
Alexandre Lisione24852d2014-02-04 13:13:02 -0500135 add_definitions(-Wno-long-long -Wno-char-subscripts)
136 add_definitions(-Wall -ansi -pedantic)
137 add_definitions(-DNEW_STDCPP)
Alexandre Lision51140e12013-12-02 10:54:09 -0500138endif()
139
Alexandre Lisione24852d2014-02-04 13:13:02 -0500140add_subdirectory(src)
Alexandre Lision907ed2e2014-02-04 10:33:09 -0500141
Alexandre Lisione24852d2014-02-04 13:13:02 -0500142if (enable_ccrtp)
Alexandre Lision51140e12013-12-02 10:54:09 -0500143 add_subdirectory(demo)
144endif()
145
Alexandre Lisione24852d2014-02-04 13:13:02 -0500146if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/package/)
147 MESSAGE(STATUS "package dir not found")
148 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/package/)
Alexandre Lision51140e12013-12-02 10:54:09 -0500149endif()
150
Alexandre Lisione24852d2014-02-04 13:13:02 -0500151########### install files ###############
152install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${zrtplib}.pc DESTINATION ${LIBDIRNAME}/pkgconfig)
Alexandre Lision907ed2e2014-02-04 10:33:09 -0500153
Alexandre Lisione24852d2014-02-04 13:13:02 -0500154if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME})
155
156 ########### Add uninstall target ###############
157 configure_file(
158 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
159 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
160 IMMEDIATE @ONLY)
161 add_custom_target(uninstall
162 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
163
164endif()
Alexandre Lision51140e12013-12-02 10:54:09 -0500165##very usefull for macosx, specially when using gtkosx bundler
166if(APPLE)
167 if (NOT CMAKE_INSTALL_NAME_DIR)
168 set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "CMAKE_INSTALL_NAME_DIR set for macosx" )
169 endif (NOT CMAKE_INSTALL_NAME_DIR)
170endif(APPLE)