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 | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 15 | SET(CPACK_PACKAGE_VERSION_MAJOR 2) |
| 16 | SET(CPACK_PACKAGE_VERSION_MINOR 3) |
| 17 | SET(CPACK_PACKAGE_VERSION_PATCH 0) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 18 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 19 | set (VERSION 2.3.0) |
| 20 | set (SOVERSION 2) |
| 21 | set (PACKAGE libzrtpcpp) |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 22 | |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 23 | if(MSVC60) |
| 24 | set(BUILD_STATIC ON CACHE BOOL "static linking only" FORCE) |
| 25 | MARK_AS_ADVANCED(BUILD_STATIC) |
| 26 | else() |
| 27 | option(BUILD_STATIC "Set to OFF to build shared libraries" OFF) |
| 28 | endif() |
| 29 | |
| 30 | # set to true for debug and trace during CMakeLists development |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 31 | set(CMAKE_VERBOSE_MAKEFILE FALSE) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 32 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 33 | MESSAGE( STATUS "Configuring GNU ${PROJECT_NAME} ${VERSION}...") |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 34 | |
| 35 | # include most of the fine stuff we need |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 36 | include(cmake/Modules/FindGcryptConfig.cmake) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 37 | include(FindPkgConfig) |
| 38 | include(CheckLibraryExists) |
| 39 | include(CheckIncludeFiles) |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 40 | include(cmake/Modules/AutoArgs.cmake) |
| 41 | |
| 42 | if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME}) |
| 43 | include(cmake/Modules/GeneratePackage.cmake) |
| 44 | |
| 45 | GENERATE_PACKAGING(${PACKAGE} ${VERSION}) |
| 46 | endif() |
| 47 | |
| 48 | # check the -Denable-ccrtp setting, defaults to true |
| 49 | enable_arg(ccrtp true "Enable GNU ccRTP support for GNU ZRTP") |
| 50 | args_help() |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 51 | |
| 52 | if (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() |
| 60 | else() |
| 61 | set(LIBDIRNAME "lib${LIB_SUFFIX}") |
| 62 | endif() |
| 63 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 64 | # setup the Thread include and lib |
| 65 | find_package(Threads) |
| 66 | if(CMAKE_HAVE_PTHREAD_H) |
| 67 | set(HAVE_PTHREAD_H TRUE) |
| 68 | endif() |
| 69 | set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT}) |
| 70 | |
| 71 | # define the name of the lib. zrtpcppcore does not include the ccRTP stuff. |
| 72 | set(zrtplib zrtpcppcore) |
| 73 | if(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) |
| 85 | endif() |
| 86 | |
| 87 | # now get info about crypto libraries |
| 88 | gcr_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 Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 113 | check_include_files(stdlib.h HAVE_STDLIB_H) |
| 114 | check_include_files(string.h HAVE_STRING_H) |
| 115 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 116 | # necessary and required modules checked, ready to generate config.h |
| 117 | configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 118 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 119 | # the following set(...) commands are only to have backward |
| 120 | # compatibility with autoconf stuff to generate the pc file |
| 121 | set(prefix ${CMAKE_INSTALL_PREFIX}) |
| 122 | set(exec_prefix ${prefix}/bin) |
| 123 | set(libdir ${prefix}/${LIBDIRNAME}) |
| 124 | set(includedir ${prefix}/include) |
| 125 | set(PACKAGE pkgconfig) |
| 126 | configure_file(libzrtpcpp.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/lib${zrtplib}.pc @ONLY) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 127 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 128 | configure_file(libzrtpcpp.spec.cmake ${CMAKE_CURRENT_BINARY_DIR}/libzrtpcpp.spec @ONLY) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 129 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 130 | #to make sure includes are first taken from those directory |
| 131 | include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 132 | |
| 133 | add_definitions(-g -O2 -fno-strict-aliasing) |
| 134 | if(CMAKE_COMPILER_IS_GNUCXX) |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 135 | add_definitions(-Wno-long-long -Wno-char-subscripts) |
| 136 | add_definitions(-Wall -ansi -pedantic) |
| 137 | add_definitions(-DNEW_STDCPP) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 138 | endif() |
| 139 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 140 | add_subdirectory(src) |
Alexandre Lision | 907ed2e | 2014-02-04 10:33:09 -0500 | [diff] [blame] | 141 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 142 | if (enable_ccrtp) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 143 | add_subdirectory(demo) |
| 144 | endif() |
| 145 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 146 | if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/package/) |
| 147 | MESSAGE(STATUS "package dir not found") |
| 148 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/package/) |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 149 | endif() |
| 150 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 151 | ########### install files ############### |
| 152 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${zrtplib}.pc DESTINATION ${LIBDIRNAME}/pkgconfig) |
Alexandre Lision | 907ed2e | 2014-02-04 10:33:09 -0500 | [diff] [blame] | 153 | |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 154 | if(${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 | |
| 164 | endif() |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 165 | ##very usefull for macosx, specially when using gtkosx bundler |
| 166 | if(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) |
| 170 | endif(APPLE) |