CMakeLists.txt 9.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
############################################################################
# CMakeLists.txt
# Copyright (C) 2014  Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
############################################################################
22

23 24 25 26
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)

project(flexisip C CXX)

27 28
set(FLEXISIP_MAJOR_VERSION "1")
set(FLEXISIP_MINOR_VERSION "0")
Simon Morlat's avatar
Simon Morlat committed
29
set(FLEXISIP_MICRO_VERSION "9")
30 31 32 33 34 35
set(FLEXISIP_VERSION "${FLEXISIP_MAJOR_VERSION}.${FLEXISIP_MINOR_VERSION}.${FLEXISIP_MICRO_VERSION}")

include(CMakePushCheckState)
include(CMakeDependentOption)
include(CheckSymbolExists)
include(CheckFunctionExists)
36
include(FeatureSummary)
37
include(CheckCXXSourceCompiles)
38

39 40 41 42 43 44 45
option(ENABLE_BOOSTLOG "Build boost log support" YES)
option(ENABLE_DATEHANDLER "Build DateHandler module" NO)
option(ENABLE_DOC "Build documentation" YES)
option(ENABLE_MONOTONIC_CLOCK_REGISTRATIONS "Enable monotonic clock for registrations" NO)
option(ENABLE_ODB "Build ODB database ORM" YES)
option(ENABLE_ODB_MYSQL "Build ODB MySQL database driver" YES)
option(ENABLE_ODBC "Build ODBC support for database connection" YES)
46
option(ENABLE_PRESENCE "Build presence support" NO)
47 48 49
option(ENABLE_PROTOBUF "Build with protobuf support" NO)
option(ENABLE_PUSHNOTIFICATION "Build with remote push notification support" YES)
option(ENABLE_REDIS "Build with Redis support" NO)
50
option(ENABLE_SNMP "Build with SNMP support" YES)
51 52 53
option(ENABLE_SOCI "Build with SOCI support" YES)
option(ENABLE_STATIC "Build static library (default is shared library)." NO)
option(ENABLE_TRANSCODER "Build transcoder support" YES)
54 55
cmake_dependent_option(ENABLE_SPECIFIC_FEATURES "Enable mediarelay specific features" OFF "ENABLE_TRANSCODER" OFF)

56 57

if(APPLE)
58 59 60
set(XSDCXX_DEFAULT_ROOT_PATH "/usr/local")
else ()
set(XSDCXX_DEFAULT_ROOT_PATH "/usr")
61
endif()
62

63 64 65 66
set(XSDCXX_ROOT_PATH ${XSDCXX_DEFAULT_ROOT_PATH}  CACHE STRING "Path of where the bin/xsdcxx executable will be found. Comes from http://www.codesynthesis.com/products/xsd/download.xhtml. On mac use 'brew install xsd'")
set(SYSCONFIGROOT "" CACHE STRING "Config directory, the place where flexisip expects its flexisip.conf file to reside" )


67 68 69 70 71 72 73 74 75 76
set(CONFIG_DIR ${SYSCONFIGROOT}/etc)
message(STATUS "Config dir: ${CONFIG_DIR}")

function(FIND_PROGRAM_REQUIRED varname progname)
	find_program(${varname} NAMES "${progname}")
	if(NOT ${varname})
		message(FATAL_ERROR "Program '${progname}' is required but could not be found")
	endif()
endfunction()

77

78
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
79 80 81

# Required packages
find_package(SofiaSipUa REQUIRED)
82 83 84 85 86
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	include("${EP_ortp_CONFIG_DIR}/ORTPConfig.cmake")
else()
	find_package(ORTP 0.21 REQUIRED)
endif()
87 88


89
find_program(XSDCXX_PROG NAMES "xsdcxx" "xsd"
90
	HINTS ${XSDCXX_ROOT_PATH}/bin
91 92 93
	NO_DEFAULT_PATH
)
if(XSDCXX_PROG)
94 95
	set(ENABLE_XSD 1)
	message(STATUS "XSD found at ${XSDCXX_PROG}, enabling XSD")
96
	# TODO: check XSD is the correct executable
97 98 99 100
	find_library(XERCES_LIBS NAMES xerces-c)
	if(NOT XERCES_LIBS)
		message(FATAL_ERROR "Failed to find the Xerces library.")
	endif()
101 102 103 104
	find_path(XERCES_INCLUDE_DIRS NAMES xercesc/util/XercesDefs.hpp)
	if(NOT XERCES_INCLUDE_DIRS)
		message(FATAL_ERROR "Failed to find the Xerces includes.")
	endif()
105 106 107
else()
	set(ENABLE_XSD 0)
	message(STATUS "Program 'xsdcxx' could not be found in ${XSDCXX_ROOT_PATH}/bin, disabling XSD features")
108 109 110 111
endif()

check_function_exists(arc4random HAVE_ARC4RANDOM)
find_file(HAVE_SYS_PRCTL_H NAMES sys/prctl.h)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
check_cxx_source_compiles(
	"#include <chrono>
	using namespace ::std;
	using namespace chrono;
	steady_clock::time_point test;
	int main() { return 0;}
	"
	HAS_STEADY_CLOCK
)
set(CMAKE_REQUIRED_LIBRARIES)

if(HAS_STEADY_CLOCK)
	message(STATUS "System has steady clock.")
else()
	message(STATUS "System doesn't have steady clock. Use monotonic instead.")
    add_definitions(-DUSE_MONOTONIC_CLOCK)
endif()
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

# Options
if(ENABLE_ODB)
	if(ENABLE_ODB_MYSQL)
		find_package(odb REQUIRED COMPONENTS mysql)
	else()
		find_package(odb REQUIRED)
	endif()
	if(NOT ODB_FOUND)
		message(FATAL_ERROR "ODB not found")
	endif()
	include(${ODB_USE_FILE})
endif()

if(ENABLE_SNMP)
	# todo: Not quite ready
	FIND_PROGRAM_REQUIRED(NET_SNMP_PROG net-snmp-config)
	find_path(NET_SNMP_INCLUDE_DIRS NAMES net-snmp/net-snmp-config.h)
	if(NOT NET_SNMP_INCLUDE_DIRS)
		message(FATAL_ERROR "SNMP header files not found")
	endif()

	execute_process(COMMAND "${NET_SNMP_PROG}" "--agent-libs" OUTPUT_VARIABLE NET_SNMP_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

if(ENABLE_ODBC)
155
	FIND_PROGRAM_REQUIRED(ODBC_PROG odbc_config)
156 157 158 159 160 161 162 163
	execute_process(COMMAND "${ODBC_PROG}" "--libs" OUTPUT_VARIABLE ODBC_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)
	execute_process(COMMAND "${ODBC_PROG}" "--cflags" OUTPUT_VARIABLE ODBC_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
	execute_process(COMMAND "${ODBC_PROG}" "--include-prefix" OUTPUT_VARIABLE ODBC_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE)
	execute_process(COMMAND "${ODBC_PROG}" "--lib-prefix" OUTPUT_VARIABLE ODBC_LIBRARY_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
	message(STATUS "ODBC libraries: ${ODBC_LIBRARIES}")
	message(STATUS "ODBC headers: ${ODBC_CFLAGS}")

	# check SQL headers
164
	find_path(ODBC_SQL_HEADERS NAMES sql.h sqlext.h sqltypes.h mysql/mysql.h PATHS ODBC_INCLUDE_DIRS)
165 166 167
	if(NOT ODBC_SQL_HEADERS)
		message(FATAL_ERROR "ODBC Mysql headers not found.")
	else()
168
		message(STATUS "ODBC Mysql ${ODBC_SQL_HEADERS}")
169 170 171 172
	endif()

	# check that odbc_config gives us a correct library path
	find_library(ODBC_LIB_FOUND NAMES odbc PATHS ODBC_LIBRARY_DIR)
173
	if(NOT ODBC_LIB_FOUND)
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
		message(FATAL_ERROR "ODBC library not found.")
	endif()
endif()

if(ENABLE_TRANSCODER)
	find_package(Mediastreamer2 2.9.0 REQUIRED)
endif()

if(ENABLE_SPECIFIC_FEATURES)
	set(MEDIARELAY_SPECIFIC_FEATURES_ENABLED ON)
endif()

if(ENABLE_MONOTONIC_CLOCK_REGISTRATIONS)
	set(MONOTONIC_CLOCK_REGISTRATIONS ON)
endif()

if(ENABLE_DATEHANDLER)
	set(HAVE_DATEHANDLER ON)
endif()

if(ENABLE_REDIS)
195
	find_path(HIREDIS_INCLUDE_DIRS NAMES hiredis/hiredis.h)
196 197 198 199 200 201 202 203 204 205 206 207 208
	find_library(HIREDIS_LIBRARIES NAMES hiredis)
	if(NOT HIREDIS_INCLUDE_DIRS)
		message(FATAL_ERROR "hiredis headers not found")
	endif()
	if(NOT HIREDIS_LIBRARIES)
		message(FATAL_ERROR "hiredis library not found")
	endif()

	# check that the async mode is supported
	cmake_push_check_state(RESET)
	list(APPEND CMAKE_REQUIRED_INCLUDES ${HIREDIS_INCLUDE_DIRS})
	list(APPEND CMAKE_REQUIRED_LIBRARIES ${HIREDIS_LIBRARIES})
	check_symbol_exists("redisAsyncCommand" "hiredis/async.h" HIREDIS_ASYNC_ENABLED)
209
	cmake_pop_check_state()
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
	if(NOT HIREDIS_ASYNC_ENABLED)
		message(FATAL_ERROR "Hiredis needs support for Async commands.")
	endif()
endif()

if(ENABLE_PROTOBUF)
	find_package(protobuf REQUIRED)
	# package finder for protobuf does not exit on REQUIRED..
	if(NOT PROTOBUF_FOUND)
		message(FATAL_ERROR "Protobuf not found and is required")
	endif()
	if(NOT PROTOBUF_PROTOC_EXECUTABLE)
		message(FATAL_ERROR "Protobuf 'protoc' executable not found and is required")
	endif()
endif()

if(ENABLE_DOC)
	FIND_PROGRAM_REQUIRED(PDFLATEX_PROG pdflatex)
endif()

if(ENABLE_PRESENCE)
231 232 233 234 235
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
		include("${EP_bellesip_CONFIG_DIR}/BelleSIPConfig.cmake")
	else()
		find_package(BelleSIP 1.2.4 REQUIRED)
	endif()
236 237
endif()

238 239 240 241 242
if(ENABLE_SOCI)
	find_package(Soci REQUIRED COMPONENTS mysql)
	find_path(SOCI_MYSQL_INCLUDES NAMES mysql.h PATH_SUFFIXES mysql)
endif()

243 244 245 246 247 248
# Boost checks
set(BOOST_COMPONENTS )
if(ENABLE_BOOSTLOG)
	list(APPEND BOOST_COMPONENTS log regex system thread)
endif()
if(ENABLE_PUSHNOTIFICATION)
249
	find_package(OpenSSL 0.9.8 REQUIRED)
250 251
	list(APPEND BOOST_COMPONENTS system)
endif()
252 253 254
if(BOOST_COMPONENTS)
	find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
endif()
255

256
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
257 258 259 260 261

include_directories(
	src/
	${CMAKE_CURRENT_BINARY_DIR}
	${CMAKE_CURRENT_BINARY_DIR}/src/
262
	${SOFIASIPUA_INCLUDE_DIRS}
263 264 265 266 267
	${ORTP_INCLUDE_DIRS}
)

configure_file(${PROJECT_SOURCE_DIR}/cmake/flexisip-config.h.in ${PROJECT_BINARY_DIR}/flexisip-config.h)
set_source_files_properties(${PROJECT_BINARY_DIR}/flexisip-config.h PROPERTIES GENERATED ON)
268
add_definitions("-DHAVE_CONFIG_H")
269 270 271 272 273 274 275 276 277 278 279 280

add_subdirectory(src)

# Packaging

set(CPACK_GENERATOR TGZ;DEB;RPM)
set(CPACK_PACKAGE_VERSION_MAJOR ${FLEXISIP_MAJOR_VERSION})
set(CPACK_PACKAGE_VERSION_MINOR ${FLEXISIP_MINOR_VERSION})
set(CPACK_PACKAGE_VERSION_PATCH ${FLEXISIP_MICRO_VERSION})
set(CPACK_PACKAGE_VERSION ${FLEXISIP_VERSION})
set(CPACK_PACKAGE_CONTACT info@belledonne-communications.com)

281
include(CPack)