CMakeLists.txt 8.75 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 26

project(flexisip C CXX)

27 28
set(FLEXISIP_MAJOR_VERSION "1")
set(FLEXISIP_MINOR_VERSION "0")
29
set(FLEXISIP_MICRO_VERSION "13")
30
set(FLEXISIP_VERSION "${FLEXISIP_MAJOR_VERSION}.${FLEXISIP_MINOR_VERSION}.${FLEXISIP_MICRO_VERSION}")
jehan's avatar
jehan committed
31
set(PROJECT_VERSION ${FLEXISIP_VERSION})
32 33 34 35 36

include(CMakePushCheckState)
include(CMakeDependentOption)
include(CheckSymbolExists)
include(CheckFunctionExists)
37
include(FeatureSummary)
38
include(CheckCXXSourceCompiles)
39
include(GNUInstallDirs)
40

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

59 60
cmake_dependent_option(ENABLE_SPECIFIC_FEATURES "Enable mediarelay specific features" OFF "ENABLE_TRANSCODER" OFF)

Erwan Croze's avatar
Erwan Croze committed
61 62
find_package(Threads)

jehan's avatar
jehan committed
63
if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
64 65
	set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
	message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
jehan's avatar
jehan committed
66
endif()
67

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


jehan's avatar
jehan committed
71
set(CONFIG_DIR ${SYSCONF_INSTALL_DIR}/flexisip)
72 73 74 75 76 77 78 79 80
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()

81

82
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
83 84

# Required packages
85
find_package(SofiaSipUa 1.13.11 REQUIRED) #find_package only allow numbers
86 87 88 89 90
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	include("${EP_ortp_CONFIG_DIR}/ORTPConfig.cmake")
else()
	find_package(ORTP 0.21 REQUIRED)
endif()
91

92
find_package(BcToolbox 0.0.3 REQUIRED)
93
find_package(Belr REQUIRED)
94

Ghislain MARY's avatar
Ghislain MARY committed
95
find_package(LibXsd)
96 97 98

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

100 101 102 103 104 105 106
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()
107
endif()
108

109 110
set(CMAKE_REQUIRED_LIBRARIES)

111 112 113 114 115 116 117 118 119 120 121 122 123
# 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_ODBC)
124
	FIND_PROGRAM_REQUIRED(ODBC_PROG odbc_config)
125 126 127 128 129 130 131 132
	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
133
	find_path(ODBC_SQL_HEADERS NAMES sql.h sqlext.h sqltypes.h mysql/mysql.h PATHS ODBC_INCLUDE_DIRS)
134 135 136
	if(NOT ODBC_SQL_HEADERS)
		message(FATAL_ERROR "ODBC Mysql headers not found.")
	else()
137
		message(STATUS "ODBC Mysql ${ODBC_SQL_HEADERS}")
138 139 140 141
	endif()

	# check that odbc_config gives us a correct library path
	find_library(ODBC_LIB_FOUND NAMES odbc PATHS ODBC_LIBRARY_DIR)
142
	if(NOT ODBC_LIB_FOUND)
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
		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)
164
	find_package(Hiredis REQUIRED)
165
	if(NOT HIREDIS_ASYNC_ENABLED)
166
		message(FATAL_ERROR "Hiredis needs support for async commands")
167 168 169 170
	endif()
endif()

if(ENABLE_PROTOBUF)
Erwan Croze's avatar
Erwan Croze committed
171
	find_package(Protobuf REQUIRED)
172 173 174 175 176 177 178 179 180
	# 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
181
if(ENABLE_PDFDOC)
182 183 184
	FIND_PROGRAM_REQUIRED(PDFLATEX_PROG pdflatex)
endif()

185
if(ENABLE_PRESENCE OR ENABLE_MDNS)
186 187 188 189 190
		# 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()
191

192 193 194 195 196
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
		include("${EP_bellesip_CONFIG_DIR}/BelleSIPConfig.cmake")
	else()
		find_package(BelleSIP 1.2.4 REQUIRED)
	endif()
197 198
endif()

Erwan Croze's avatar
Erwan Croze committed
199 200
if(ENABLE_CONFERENCE)
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
201
		include("${EP_bellesip_CONFIG_DIR}/BelleSIPConfig.cmake")
Erwan Croze's avatar
Erwan Croze committed
202 203 204
		include("${EP_linphone_CONFIG_DIR}/LinphoneConfig.cmake")
		include("${EP_linphone_CONFIG_DIR}/wrappers/cpp/LinphoneCxxConfig.cmake")
	else ()
205
		find_package(BelleSIP 1.2.4 REQUIRED)
206 207
		find_package(Linphone REQUIRED)
		find_package(LinphoneCxx REQUIRED)
Erwan Croze's avatar
Erwan Croze committed
208 209 210
	endif()
endif()

211 212
if(ENABLE_SOCI)
	find_package(Soci REQUIRED COMPONENTS mysql)
Ghislain MARY's avatar
Ghislain MARY committed
213
	find_path(SOCI_MYSQL_INCLUDES NAMES mysql.h PATH_SUFFIXES mysql HINTS $ENV{MYSQL_DIR}/include /usr/include/mariadb /usr/local/include)
214 215
endif()

216 217 218 219 220 221 222 223 224 225 226

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()


227
find_package(OpenSSL 0.9.8 REQUIRED)
228

229
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
230 231

include_directories(
232 233 234
	include/
	src/
	src/plugin
235 236 237
	${CMAKE_CURRENT_BINARY_DIR}
	${CMAKE_CURRENT_BINARY_DIR}/src/
	${ORTP_INCLUDE_DIRS}
238
	${SOFIASIPUA_INCLUDE_DIRS}
239 240
)

241 242
set(BELR_GRAMMARS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/belr/grammars")

243 244
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)
245
add_definitions("-DHAVE_CONFIG_H")
246

247 248
bc_init_compilation_flags(CPP_BUILD_FLAGS C_BUILD_FLAGS CXX_BUILD_FLAGS ENABLE_STRICT)

249
add_subdirectory(include)
250
add_subdirectory(src)
jehan's avatar
jehan committed
251
add_subdirectory(scripts)
Nicolas Michon's avatar
Nicolas Michon committed
252
add_subdirectory(share)
253

254 255 256 257
if(ENABLE_UNIT_TESTS)
	add_subdirectory(tester)
endif()

258
# Packaging
jehan's avatar
jehan committed
259
add_subdirectory(build)