CMakeLists.txt 7.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
############################################################################
# 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
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 21
#
############################################################################
22

23
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR) # 3.2.0 required for target_compile_features support on gcc 4.4+ (centos6)
24

25
project(flexisip LANGUAGES C CXX)
26 27 28 29 30

include(CMakePushCheckState)
include(CMakeDependentOption)
include(CheckSymbolExists)
include(CheckFunctionExists)
31
include(FeatureSummary)
32
include(CheckCXXSourceCompiles)
33
include(GNUInstallDirs)
34

35
option(ENABLE_STRICT "Pass strict flags to the compiler" YES)
36
option(ENABLE_DATEHANDLER "Build DateHandler module" NO)
Simon Morlat's avatar
Simon Morlat committed
37
option(ENABLE_PDFDOC "Build pdf documentation" NO)
38
option(ENABLE_MONOTONIC_CLOCK_REGISTRATIONS "Enable monotonic clock for registrations" NO)
39
option(ENABLE_PRESENCE "Build presence support" NO)
Erwan Croze's avatar
Erwan Croze committed
40
option(ENABLE_CONFERENCE "Build conference support" NO)
41 42
option(ENABLE_PROTOBUF "Build with protobuf support" NO)
option(ENABLE_REDIS "Build with Redis support" NO)
43
option(ENABLE_SNMP "Build with SNMP support" NO)
44 45 46
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)
47
option(ENABLE_MDNS "Build multicast DNS support" NO)
48
option(ENABLE_EXTERNAL_AUTH_PLUGIN "Enable ExternalAuth plugin support" NO)
49
option(ENABLE_JWE_AUTH_PLUGIN "Enable JweAuth plugin support" NO)
50
option(ENABLE_UNIT_TESTS "Enable flexisip unit tests (low level tests)" ON)
51

52 53
cmake_dependent_option(ENABLE_SPECIFIC_FEATURES "Enable mediarelay specific features" OFF "ENABLE_TRANSCODER" OFF)

Erwan Croze's avatar
Erwan Croze committed
54 55
find_package(Threads)

jehan's avatar
jehan committed
56
if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
57 58
	set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
	message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
jehan's avatar
jehan committed
59
endif()
60

jehan's avatar
jehan committed
61
set(SYSCONF_INSTALL_DIR ${CMAKE_INSTALL_FULL_SYSCONFDIR} CACHE STRING "Config directory, the place where flexisip expects its flexisip.conf file to reside" )
62 63


jehan's avatar
jehan committed
64
set(CONFIG_DIR ${SYSCONF_INSTALL_DIR}/flexisip)
65 66 67 68 69 70 71 72 73
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()

74

75
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
76 77

# Required packages
78
find_package(SofiaSipUa 1.13.11 REQUIRED) #find_package only allow numbers
79 80 81
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	include("${EP_ortp_CONFIG_DIR}/ORTPConfig.cmake")
else()
82
	find_package(ortp 0.21 REQUIRED)
83
endif()
84

85 86
find_package(bctoolbox 0.0.3 REQUIRED)
find_package(belr REQUIRED)
87

Ghislain MARY's avatar
Ghislain MARY committed
88
find_package(LibXsd)
89 90 91

check_function_exists(arc4random HAVE_ARC4RANDOM)
find_file(HAVE_SYS_PRCTL_H NAMES sys/prctl.h)
92

93 94 95 96 97 98 99
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
	if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
		message(STATUS "GCC version < 4.7: use MONOTONIC clock")
		add_definitions(-DUSE_MONOTONIC_CLOCK)
	else()
		message(STATUS "GCC version ${CMAKE_CXX_COMPILER_VERSION} should have steady_clock")
	endif()
100
endif()
101

102 103
set(CMAKE_REQUIRED_LIBRARIES)

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
# Options
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_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)
133
	find_package(Hiredis REQUIRED)
134
	if(NOT HIREDIS_ASYNC_ENABLED)
135
		message(FATAL_ERROR "Hiredis needs support for async commands")
136 137 138 139
	endif()
endif()

if(ENABLE_PROTOBUF)
Erwan Croze's avatar
Erwan Croze committed
140
	find_package(Protobuf REQUIRED)
141 142 143 144 145 146 147 148 149
	# 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()

Simon Morlat's avatar
Simon Morlat committed
150
if(ENABLE_PDFDOC)
151 152 153
	FIND_PROGRAM_REQUIRED(PDFLATEX_PROG pdflatex)
endif()

154
if(ENABLE_PRESENCE OR ENABLE_MDNS)
155 156 157 158 159
		# disable Presence on gcc < 4.7 because c++11 is not supported well before
		if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
				message(WARNING "Disable Presence because GCC is too old")
				set(ENABLE_PRESENCE OFF)
		endif()
160

161 162 163 164 165
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
		include("${EP_bellesip_CONFIG_DIR}/BelleSIPConfig.cmake")
	else()
		find_package(BelleSIP 1.2.4 REQUIRED)
	endif()
166 167
endif()

Erwan Croze's avatar
Erwan Croze committed
168 169
if(ENABLE_CONFERENCE)
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
170
		include("${EP_bellesip_CONFIG_DIR}/BelleSIPConfig.cmake")
Erwan Croze's avatar
Erwan Croze committed
171 172 173
		include("${EP_linphone_CONFIG_DIR}/LinphoneConfig.cmake")
		include("${EP_linphone_CONFIG_DIR}/wrappers/cpp/LinphoneCxxConfig.cmake")
	else ()
174
		find_package(BelleSIP 1.2.4 REQUIRED)
175 176
		find_package(Linphone REQUIRED)
		find_package(LinphoneCxx REQUIRED)
Erwan Croze's avatar
Erwan Croze committed
177 178 179
	endif()
endif()

180 181
if(ENABLE_SOCI)
	find_package(Soci REQUIRED COMPONENTS mysql)
Ghislain MARY's avatar
Ghislain MARY committed
182
	find_path(SOCI_MYSQL_INCLUDES NAMES mysql.h PATH_SUFFIXES mysql HINTS $ENV{MYSQL_DIR}/include /usr/include/mariadb /usr/local/include)
183 184
endif()

185 186 187 188 189 190 191 192 193 194 195

find_path(MSGPACK_INCLUDE_DIRS NAMES msgpack.hpp HINTS /usr/local/include)
if(MSGPACK_INCLUDE_DIRS)
	message(STATUS "MSGPACK found")
	add_definitions("-DENABLE_MSGPACK")
	set(ENABLE_MSGPACK 1)
else()
	message(STATUS "MSGPACK not found")
endif()


196
find_package(OpenSSL 0.9.8 REQUIRED)
197

198
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
199 200

include_directories(
201 202 203
	include/
	src/
	src/plugin
204 205 206
	${CMAKE_CURRENT_BINARY_DIR}
	${CMAKE_CURRENT_BINARY_DIR}/src/
	${ORTP_INCLUDE_DIRS}
207
	${SOFIASIPUA_INCLUDE_DIRS}
208 209
)

210 211
set(BELR_GRAMMARS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/belr/grammars")

212 213
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)
214
add_definitions("-DHAVE_CONFIG_H")
215

216 217
bc_init_compilation_flags(CPP_BUILD_FLAGS C_BUILD_FLAGS CXX_BUILD_FLAGS ENABLE_STRICT)

218
add_subdirectory(include)
219
add_subdirectory(src)
jehan's avatar
jehan committed
220
add_subdirectory(scripts)
Nicolas Michon's avatar
Nicolas Michon committed
221
add_subdirectory(share)
222

223 224 225 226
if(ENABLE_UNIT_TESTS)
	add_subdirectory(tester)
endif()

227
# Packaging
jehan's avatar
jehan committed
228
add_subdirectory(build)