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) |
| 14 | set (VERSION 2.3.4) |
| 15 | set (PACKAGE libzrtpcpp) |
| 16 | set (SOVERSION ${VERSION}) |
| 17 | STRING(REGEX REPLACE "[.].*$" "" SOVERSION ${SOVERSION}) |
| 18 | |
| 19 | SET(CPACK_PACKAGE_VERSION_MAJOR ${SOVERSION}) |
| 20 | SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION}) |
| 21 | SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION}) |
| 22 | STRING(REGEX REPLACE "[.][0-9]*$" "" CPACK_PACKAGE_VERSION_MINOR ${VERSION}) |
| 23 | STRING(REGEX REPLACE ".*[.]" "" CPACK_PACKAGE_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}) |
| 24 | STRING(REGEX REPLACE ".*[.]" "" CPACK_PACKAGE_VERSION_PATCH ${VERSION}) |
| 25 | |
| 26 | if(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 | ) |
| 43 | endif() |
| 44 | |
| 45 | if(MSVC60) |
| 46 | set(BUILD_STATIC ON CACHE BOOL "static linking only" FORCE) |
| 47 | MARK_AS_ADVANCED(BUILD_STATIC) |
| 48 | else() |
| 49 | option(BUILD_STATIC "Set to OFF to build shared libraries" OFF) |
| 50 | endif() |
| 51 | |
| 52 | # set to true for debug and trace during CMakeLists development |
| 53 | set(CMAKE_VERBOSE_MAKEFILE FALSE) |
| 54 | |
| 55 | MESSAGE( STATUS "Configuring GNU ${PROJECT_NAME} ${VERSION}...") |
| 56 | |
| 57 | # include most of the fine stuff we need |
| 58 | include(cmake/Modules/FindGcryptConfig.cmake) |
| 59 | include(FindPkgConfig) |
| 60 | include(CheckLibraryExists) |
| 61 | include(CheckIncludeFiles) |
| 62 | include(cmake/Modules/AutoArgs.cmake) |
| 63 | |
| 64 | if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME}) |
| 65 | include(cmake/Modules/GeneratePackage.cmake) |
| 66 | |
| 67 | GENERATE_PACKAGING(${PACKAGE} ${VERSION}) |
| 68 | endif() |
| 69 | |
| 70 | # check the -Denable-ccrtp setting, defaults to true |
| 71 | enable_arg(ccrtp true "Enable GNU ccRTP support for GNU ZRTP") |
| 72 | args_help() |
| 73 | |
| 74 | if (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() |
| 82 | else() |
| 83 | set(LIBDIRNAME "lib${LIB_SUFFIX}") |
| 84 | endif() |
| 85 | |
| 86 | # setup the Thread include and lib |
| 87 | find_package(Threads) |
| 88 | if(CMAKE_HAVE_PTHREAD_H) |
| 89 | set(HAVE_PTHREAD_H TRUE) |
| 90 | endif() |
| 91 | set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT}) |
| 92 | |
| 93 | # define the name of the lib. zrtpcppcore does not include the ccRTP stuff. |
| 94 | set(zrtplib zrtpcppcore) |
| 95 | if(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) |
| 107 | endif() |
| 108 | |
| 109 | # now get info about crypto libraries |
| 110 | pkg_check_modules(OPENSSL libcrypto>=0.9.8) |
| 111 | if (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 |
| 123 | endif() |
| 124 | |
| 125 | if(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() |
| 134 | endif() |
| 135 | |
| 136 | if(NOT OPENSSL_FOUND AND NOT GCRYPT_FOUND) |
| 137 | message(FATAL_ERROR "No crypto library found") |
| 138 | endif() |
| 139 | |
| 140 | check_include_files(stdlib.h HAVE_STDLIB_H) |
| 141 | check_include_files(string.h HAVE_STRING_H) |
| 142 | |
| 143 | # necessary and required modules checked, ready to generate config.h |
| 144 | configure_file(libzrtpcpp-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/libzrtpcpp-config.h) |
| 145 | include_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 |
| 149 | set(prefix ${CMAKE_INSTALL_PREFIX}) |
| 150 | set(exec_prefix ${prefix}/bin) |
| 151 | set(libdir ${prefix}/${LIBDIRNAME}) |
| 152 | set(includedir ${prefix}/include) |
| 153 | set(PACKAGE pkgconfig) |
| 154 | configure_file(libzrtpcpp.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/lib${zrtplib}.pc @ONLY) |
| 155 | |
| 156 | configure_file(libzrtpcpp.spec.cmake ${CMAKE_CURRENT_BINARY_DIR}/libzrtpcpp.spec @ONLY) |
| 157 | |
| 158 | #to make sure includes are first taken from those directory |
| 159 | include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src) |
| 160 | |
| 161 | add_definitions(-g -O2 -fno-strict-aliasing) |
| 162 | if(CMAKE_COMPILER_IS_GNUCXX) |
| 163 | add_definitions(-Wno-long-long -Wno-char-subscripts) |
| 164 | add_definitions(-Wall -pedantic) |
| 165 | add_definitions(-DNEW_STDCPP) |
| 166 | endif() |
| 167 | |
| 168 | add_subdirectory(src) |
| 169 | |
| 170 | if (enable_ccrtp) |
| 171 | add_subdirectory(demo) |
| 172 | endif() |
| 173 | |
| 174 | if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/package/) |
| 175 | MESSAGE(STATUS "package dir not found") |
| 176 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/package/) |
| 177 | endif() |
| 178 | |
| 179 | ########### install files ############### |
| 180 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${zrtplib}.pc DESTINATION ${LIBDIRNAME}/pkgconfig) |
| 181 | |
| 182 | if(${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 | |
| 192 | endif() |
| 193 | ##very usefull for macosx, specially when using gtkosx bundler |
| 194 | if(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) |
| 198 | endif(APPLE) |
| 199 | |
| 200 | |