CMakeLists.txt 6.57 KB
Newer Older
1 2
############################################################################
# CMakeLists.txt
3
# Copyright (C) 2010-2020  Belledonne Communications, Grenoble France
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#
############################################################################
#
# 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
#
############################################################################
Ghislain MARY's avatar
Ghislain MARY committed
22

23 24 25 26 27 28 29 30 31 32 33
# CMake 3.13 required by some sub-projects.
cmake_minimum_required(VERSION 3.13)

# Set project version by using the Git describe
include("./linphone-sdk/bctoolbox/cmake/BcToolboxCMakeUtils.cmake")
bc_compute_full_version(FLEXISIP_FULL_VERSION)
bc_parse_full_version("${FLEXISIP_FULL_VERSION}" major minor patch)
project(flexisip VERSION "${major}.${minor}.${patch}" LANGUAGES C CXX)
unset(major)
unset(minor)
unset(patch)
34 35 36 37 38

include(CMakePushCheckState)
include(CMakeDependentOption)
include(CheckSymbolExists)
include(CheckFunctionExists)
39
include(FeatureSummary)
40
include(CheckCXXSourceCompiles)
41
include(GNUInstallDirs)
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
option(ENABLE_STRICT "Pass strict flags to the compiler" ON)
option(ENABLE_DATEHANDLER "Build DateHandler module" OFF)
option(ENABLE_PDFDOC "Build pdf documentation" OFF)
option(ENABLE_MONOTONIC_CLOCK_REGISTRATIONS "Enable monotonic clock for registrations" OFF)
option(ENABLE_PRESENCE "Build presence support" ON)
option(ENABLE_CONFERENCE "Build conference support" ON)
option(ENABLE_PROTOBUF "Build with protobuf support" ON)
option(ENABLE_REDIS "Build with Redis support" ON)
option(ENABLE_SNMP "Build with SNMP support" ON)
option(ENABLE_SOCI "Build with SOCI support" ON)
option(ENABLE_STATIC "Build static library (default is shared library)." OFF)
option(ENABLE_TRANSCODER "Build transcoder support" ON)
option(ENABLE_MDNS "Build multicast DNS support" OFF)
option(ENABLE_EXTERNAL_AUTH_PLUGIN "Enable ExternalAuth plugin support" ON)
option(ENABLE_JWE_AUTH_PLUGIN "Enable JweAuth plugin support" ON)
option(ENABLE_UNIT_TESTS "Enable flexisip unit tests (low level tests)" OFF)
set(CPACK_GENERATOR "" CACHE STRING "Generator to use for making package. Supported values: 'RPM', 'DEB'")
60

61 62
cmake_dependent_option(ENABLE_SPECIFIC_FEATURES "Enable mediarelay specific features" OFF "ENABLE_TRANSCODER" OFF)

63

64 65
# Require C++14
set(CMAKE_CXX_STANDARD 14)
66 67 68
set(CMAKE_CXX_STANDARD_REQUIRED ON)


Erwan Croze's avatar
Erwan Croze committed
69 70
find_package(Threads)

jehan's avatar
jehan committed
71
if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
72 73
	set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
	message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
jehan's avatar
jehan committed
74
endif()
75

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

jehan's avatar
jehan committed
78
set(CONFIG_DIR ${SYSCONF_INSTALL_DIR}/flexisip)
79
message(STATUS "Config dir: ${CONFIG_DIR}")
80 81 82 83
set(INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
if(ENABLE_UNIT_TESTS)
	set(TESTER_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/flexisip-tester)
endif()
84 85 86 87 88 89 90 91

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

92

Ghislain MARY's avatar
Ghislain MARY committed
93
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
94

95 96 97
include("cmake/ExternalDependencies.cmake")
include("cmake/LinphoneSDK.cmake")

98 99
# Required packages

100
find_package(LibNgHttp2 REQUIRED)
101

102
find_package(XercesC)
103 104 105

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

107 108
set(CMAKE_REQUIRED_LIBRARIES)

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

if(ENABLE_PROTOBUF)
Erwan Croze's avatar
Erwan Croze committed
141
	find_package(Protobuf REQUIRED)
142 143 144 145 146 147 148 149 150
	# 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
151
if(ENABLE_PDFDOC)
152 153 154
	FIND_PROGRAM_REQUIRED(PDFLATEX_PROG pdflatex)
endif()

155 156 157 158 159 160 161 162 163 164
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()


165
find_package(OpenSSL 0.9.8 REQUIRED)
166

167
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
168 169

include_directories(
170 171 172 173 174 175 176
	"include"
	"src"
	"src/plugin"
	"src/presence"
	"${CMAKE_CURRENT_BINARY_DIR}"
	"${CMAKE_CURRENT_BINARY_DIR}/include"
	"${CMAKE_CURRENT_BINARY_DIR}/src"
177 178
)

179 180
set(BELR_GRAMMARS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/belr/grammars")

181
configure_file(cmake/flexisip-config.h.in flexisip-config.h)
182
set_source_files_properties(${PROJECT_BINARY_DIR}/flexisip-config.h PROPERTIES GENERATED ON)
183
add_compile_definitions("HAVE_CONFIG_H")
184

185
# -Werror=varargs seems to do false positives with GCC 4.9.x
186
bc_init_compilation_flags(CPP_BUILD_FLAGS C_BUILD_FLAGS CXX_BUILD_FLAGS ENABLE_STRICT)
187 188 189
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION MATCHES "^4\\.9\\.[0-9]+$")
	list(APPEND CXX_BUILD_FLAGS "-Wno-error=varargs")
endif()
190
add_compile_options(${CPP_BUILD_FLAGS} ${CXX_BUILD_FLAGS})
191

192
add_subdirectory(include)
193
add_subdirectory(src)
jehan's avatar
jehan committed
194
add_subdirectory(scripts)
Nicolas Michon's avatar
Nicolas Michon committed
195
add_subdirectory(share)
196

197 198 199 200
if(ENABLE_UNIT_TESTS)
	add_subdirectory(tester)
endif()

201
# Packaging
202
add_subdirectory(packaging)