CMakeLists.txt 14 KB
Newer Older
1 2
############################################################################
# CMakeLists.txt
3
# Copyright (C) 2010-2019  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 22
#
############################################################################

23
cmake_minimum_required(VERSION 3.1)
24
project(linphone VERSION 5.1.0 LANGUAGES C CXX)
25

26 27 28 29
set(LINPHONE_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
set(LINPHONE_MINOR_VERSION ${PROJECT_VERSION_MINOR})
set(LINPHONE_MICRO_VERSION ${PROJECT_VERSION_PATCH})
set(LINPHONE_VERSION ${PROJECT_VERSION})
Simon Morlat's avatar
Simon Morlat committed
30
set(LINPHONE_SO_VERSION "10") #incremented for 4.4.0 release.
31

32
file(GLOB LINPHONE_PO_FILES RELATIVE "${CMAKE_CURRENT_LIST_DIR}/po" "${CMAKE_CURRENT_LIST_DIR}/po/*.po")
33 34
string(REGEX REPLACE "([a-zA-Z_]+)\\.po" "\\1" LINPHONE_ALL_LANGS_LIST "${LINPHONE_PO_FILES}")
string(REPLACE ";" " " LINPHONE_ALL_LANGS "${LINPHONE_ALL_LANGS_LIST}")
35 36

include(CMakeDependentOption)
37
include(cmake/Tools.cmake)
38

39 40
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
Ronan's avatar
Ronan committed
41

42
option(ENABLE_ADVANCED_IM "Enable advanced instant messaging such as group chat." YES)
43
option(ENABLE_CONSOLE_UI "Turn on or off compilation of console interface." YES)
Ronan's avatar
Ronan committed
44 45
option(ENABLE_CSHARP_WRAPPER "Build the C# wrapper for Liblinphone." OFF)
option(ENABLE_CXX_WRAPPER "Build the C++ wrapper for Liblinphone." YES)
46
option(ENABLE_DB_STORAGE "Enable database storage." YES)
47
option(ENABLE_FLEXIAPI "Enable the FlexiAPI support for Liblinphone." YES)
48 49
option(ENABLE_SWIFT_WRAPPER "Build the swift wrapper sources for Liblinphone." OFF)
option(ENABLE_SWIFT_WRAPPER_COMPILATION "Compile and package the swift wrapper framework from the built sources." OFF)
50
option(ENABLE_JAZZY_DOC "Build the jazzy doc for swift module of Liblinphone." OFF)
51
option(ENABLE_DAEMON "Enable the linphone daemon interface." YES)
Ronan's avatar
Ronan committed
52 53
option(ENABLE_DATE "Use build date in internal version number." NO)
option(ENABLE_DEBUG_LOGS "Turn on or off debug level logs." NO)
54
option(ENABLE_DOC "Enable API documentation generation." NO)
55
option(ENABLE_LIME_X3DH "Enable LIMEv2 and X3DH encryption protocol." YES)
Ronan's avatar
Ronan committed
56
option(ENABLE_JAVA_WRAPPER "Build the Java wrapper for Liblinphone." OFF)
Ronan's avatar
Ronan committed
57
option(ENABLE_JAVADOC "Add a target to generate documentation for Java API" NO)
Ronan's avatar
Ronan committed
58
option(ENABLE_LIME "Enable Instant Messaging Encryption." YES)
Julien Wadel's avatar
Julien Wadel committed
59
option(ENABLE_LDAP "Enable LDAP support." NO)
60
option(ENABLE_RELATIVE_PREFIX "Find resources relatively to the installation directory." NO)
61
option(ENABLE_STRICT "Build with strict compile options." YES)
62
option(ENABLE_TOOLS "Turn on or off compilation of tools." YES)
63 64 65
option(ENABLE_TUNNEL "Turn on compilation of tunnel support." NO)
option(ENABLE_TUTORIALS "Enable compilation of tutorials." YES)
option(ENABLE_UNIT_TESTS "Enable compilation of unit tests." YES)
Ghislain MARY's avatar
Ghislain MARY committed
66
option(ENABLE_UPDATE_CHECK "Enable update check." NO)
Ronan's avatar
Ronan committed
67
option(ENABLE_VCARD "Turn on compilation of vcard4 support." YES)
68
option(ENABLE_VIDEO "Build with video support." YES)
69
option(ENABLE_ASSETS "Package sound assets." YES)
70
option(ENABLE_PACKAGE_SOURCE "Create 'package_source' target for source archive making (CMake >= 3.11)" OFF)
Ronan's avatar
Ronan committed
71

72

Ronan's avatar
Ronan committed
73
cmake_dependent_option(ENABLE_NOTIFY "Enable libnotify support." YES "ENABLE_GTK_UI;NOT APPLE" NO)
74
cmake_dependent_option(ENABLE_ASSISTANT "Turn on assistant compiling." YES "ENABLE_GTK_UI" NO)
75

Andrea Gianarda's avatar
Andrea Gianarda committed
76
set(CMAKE_CXX_STANDARD 14)
77
set(CMAKE_CXX_EXTENSIONS NO)
78

79 80 81
if(NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE "Release")
endif()
82 83
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
	add_definitions("-DDEBUG")
84
endif()
85

86 87 88 89 90
if(ENABLE_STATIC)
	set(LINPHONE_LIBS_FOR_TOOLS linphone-static)
else()
	set(LINPHONE_LIBS_FOR_TOOLS linphone)
endif()
François Grisez's avatar
François Grisez committed
91
if(WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
92
	list(APPEND LINPHONE_LIBS_FOR_TOOLS "Ws2_32" "Iphlpapi")
François Grisez's avatar
François Grisez committed
93
endif()
94

95
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
96

97
include(CheckSymbolExists)
98
include(CMakePushCheckState)
99
include(GNUInstallDirs)
100
include(CheckCXXCompilerFlag)
101

Simon Morlat's avatar
Simon Morlat committed
102 103
check_symbol_exists(getifaddrs "sys/types.h;ifaddrs.h" HAVE_GETIFADDRS)

104 105 106 107
if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
	set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
	message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
endif()
108

109
set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
110
if(MSVC)
111
	list(APPEND CMAKE_REQUIRED_INCLUDES "${MSVC_INCLUDE_DIR}")
112 113
endif()

114 115
# find_package should be invoked here to check for libraries - however do NOT
# call include_directories here (see below)
116
if (ENABLE_VCARD)
117
	find_package(belcard CONFIG)
118 119 120 121 122 123 124 125
	if(NOT BELCARD_FOUND)
		message(WARNING "Could not find the belcard library!")
		set(ENABLE_VCARD OFF CACHE BOOL "Enable vcard support." FORCE)
	else()
		add_definitions(-DVCARD_ENABLED)
	endif()
endif()

126 127 128 129 130
find_package(BelleSIP CONFIG REQUIRED)
find_package(Mediastreamer2 CONFIG REQUIRED)
find_package(ortp CONFIG REQUIRED)
find_package(bctoolbox 0.0.3 CONFIG REQUIRED OPTIONAL_COMPONENTS tester)
find_package(belr CONFIG REQUIRED)
Ronan's avatar
Ronan committed
131

132
if(ENABLE_ADVANCED_IM)
133
	find_package(XercesC REQUIRED)
134
	set(HAVE_ADVANCED_IM 1)
135 136
	set(LIBXSD_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/libxsd")
	set(XercesC_TARGET "XercesC::XercesC")
137 138
endif()

Ronan's avatar
Ronan committed
139 140 141
find_package(Sqlite3 REQUIRED)
find_package(XML2 REQUIRED)

142 143
if (ENABLE_DB_STORAGE)
	#APPLE platform does not use dlopen for soci backend
jehan's avatar
jehan committed
144
	if (APPLE OR ANDROID)
145 146 147 148 149
		find_package(Soci REQUIRED COMPONENTS sqlite3)
	else()
		find_package(Soci REQUIRED)
	endif()
	set(HAVE_DB_STORAGE 1)
150 151
endif()

152
find_package(ZLIB)
Ronan's avatar
Ronan committed
153

154
if(ENABLE_TUNNEL)
155 156 157 158 159
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
		include("${EP_tunnel_CONFIG_DIR}/TunnelConfig.cmake")
	else()
		find_package(Tunnel)
	endif()
160 161
	if(NOT TUNNEL_FOUND)
		message(WARNING "Could not find the tunnel library!")
162 163 164 165 166 167 168 169 170 171
		set(ENABLE_TUNNEL OFF CACHE BOOL "Enable tunnel support." FORCE)
	endif()
endif()
if(ENABLE_NOTIFY)
	find_package(Notify)
	if(NOTIFY_FOUND)
		set(HAVE_NOTIFY4 1)
	else()
		message(WARNING "Could not find the notify library!")
		set(ENABLE_NOTIFY OFF CACHE BOOL "Enable libnotify support." FORCE)
172 173
	endif()
endif()
174 175 176
if(ENABLE_ASSISTANT)
	set(BUILD_WIZARD 1)
endif()
177
if(ENABLE_LIME AND ENABLE_LIME_X3DH)
178
	message(WARNING "Lime V1 and V2 cannot be used simultaneously!")
179 180
endif()
if(ENABLE_LIME_X3DH)
181
	find_package(lime REQUIRED CONFIG)
182 183
	set(HAVE_LIME_X3DH TRUE)
endif()
184
if(ENABLE_LIME)
185
	#bzrtp is only required for LIME
186
	find_package(bzrtp REQUIRED CONFIG)
187
	set(HAVE_LIME 1)
188
endif()
DanmeiChen's avatar
DanmeiChen committed
189
if(ENABLE_CXX_WRAPPER OR ENABLE_CSHARP_WRAPPER OR ENABLE_JAVA_WRAPPER OR ENABLE_SWIFT_WRAPPER OR ENABLE_DOC)
190
	find_package(PythonInterp 3 REQUIRED)
191 192 193
	check_python_module(pystache)
	check_python_module(six)
	if(ENABLE_DOC)
194
		#check_python_module(swift_domain)
195
	endif()
196
endif()
Julien Wadel's avatar
Julien Wadel committed
197 198 199
if(ENABLE_LDAP)
		find_package(OpenLDAP REQUIRED)
endif()
200

201 202 203 204 205
if (ENABLE_FLEXIAPI)
	find_package(jsoncpp REQUIRED)
	set(HAVE_FLEXIAPI TRUE)
endif()

206 207 208 209
if(UNIX AND NOT APPLE)
	include(CheckIncludeFiles)
	check_include_files(libudev.h HAVE_LIBUDEV_H)
endif()
210

Ghislain MARY's avatar
Ghislain MARY committed
211 212 213 214 215
if(NOT WIN32)
	find_package(Iconv QUIET)
endif()
if(ANDROID)
	find_package(CpuFeatures REQUIRED)
216 217 218
	if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS 19)
		find_library(ANDROID_SUPPORT_LIBRARY NAMES support)
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
219 220
endif()

221 222
set(LINPHONE_LDFLAGS "${BELLESIP_LDFLAGS} ${MEDIASTREAMER2_LDFLAGS}")

223 224
# include_directories must be called only UNDER THIS LINE in order to use our
# projects submodules first (we do NOT want to have system headers in first position)
225
include_directories(
226 227 228
	coreapi
	include
	src
229
	${CMAKE_CURRENT_BINARY_DIR}
230
	${CMAKE_CURRENT_BINARY_DIR}/coreapi/
231 232
)
set(LINPHONE_INCLUDE_DIRS
233 234 235 236
 	${BELLESIP_INCLUDE_DIRS}
 	${MEDIASTREAMER2_INCLUDE_DIRS}
 	${BCTOOLBOX_CORE_INCLUDE_DIRS}
 	${BELR_INCLUDE_DIRS}
237
	${LIBXSD_INCLUDE_DIRS}
François Grisez's avatar
François Grisez committed
238
	${XercesC_INCLUDE_DIRS}
239
)
240

Ghislain MARY's avatar
Ghislain MARY committed
241 242 243
if(ANDROID)
	include_directories(${CMAKE_CURRENT_BINARY_DIR}/java)
endif()
244
if(ENABLE_TUNNEL)
245
	list(APPEND LINPHONE_INCLUDE_DIRS ${TUNNEL_INCLUDE_DIRS})
246 247
endif()

248
list(APPEND LINPHONE_INCLUDE_DIRS ${XML2_INCLUDE_DIRS})
Ronan's avatar
Ronan committed
249
list(APPEND LINPHONE_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIRS})
250

251
if(ZLIB_FOUND)
252
	list(APPEND LINPHONE_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
253 254
	set(HAVE_ZLIB 1)
endif()
255 256
if(INTL_FOUND)
	set(HAVE_INTL 1)
257
	list(APPEND LINPHONE_INCLUDE_DIRS ${INTL_INCLUDE_DIRS})
258
endif()
259
if(OPENLDAP_FOUND)
Julien Wadel's avatar
Julien Wadel committed
260 261
	list(APPEND LINPHONE_INCLUDE_DIRS ${OPENLDAP_INCLUDE_DIRS})
endif()
262
if(MSVC)
263
	include_directories(${MSVC_INCLUDE_DIR})
264 265
endif()

Ronan's avatar
Ronan committed
266
set(LINPHONE_CPPFLAGS ${BELCARD_CPPFLAGS} ${BELLESIP_CPPFLAGS} ${MEDIASTREAMER2_CPPFLAGS} ${BCTOOLBOX_CPPFLAGS} ${BELR_CPPFLAGS})
267 268
if(ENABLE_STATIC)
	list(APPEND LINPHONE_CPPFLAGS "-DLINPHONE_STATIC")
269 270
endif()
if(LINPHONE_CPPFLAGS)
Ghislain MARY's avatar
Ghislain MARY committed
271
	list(REMOVE_DUPLICATES LINPHONE_CPPFLAGS)
272 273
	add_definitions(${LINPHONE_CPPFLAGS})
endif()
274

275
if(ENABLE_DEBUG_LOGS)
276
	add_definitions("-DDEBUG_LOGS")
277
endif()
278

279 280 281 282 283
# Enable stdint.h limit macros on C++ files. (Windows only.)
if(MSVC)
	add_definitions("-D__STDC_LIMIT_MACROS")
endif()

284 285
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
François Grisez's avatar
François Grisez committed
286
set(STRICT_OPTIONS_CXX )
287
set(STRICT_OPTIONS_OBJC )
288 289
if(MSVC)
	list(APPEND STRICT_OPTIONS_CPP "/wd4995") # Disable "name was marked as #pragma deprecated" warnings
290
	list(APPEND STRICT_OPTIONS_CPP "/wd4996") # Disable deprecated function warnings
291
	list(APPEND STRICT_OPTIONS_CPP "/wd4800") # Disable warning for cast from bool_t to bool
Andrea Gianarda's avatar
Andrea Gianarda committed
292
	list(APPEND STRICT_OPTIONS_CPP "/wd4251") # Disable warning for missing dll export
293 294 295 296
	if(ENABLE_STRICT)
		list(APPEND STRICT_OPTIONS_CPP "/WX")
	endif()
else()
Ronan's avatar
Ronan committed
297 298 299 300 301 302 303 304 305 306
	list(APPEND STRICT_OPTIONS_CPP
		"-Wall"
		"-Wconversion"
		"-Werror=return-type"
		"-Winit-self"
		"-Wno-error=deprecated-declarations"
		"-Wpointer-arith"
		"-Wuninitialized"
		"-Wunused"
	)
307
	list(APPEND STRICT_OPTIONS_CXX
308
		"-Wnon-virtual-dtor"
309 310
		"-Woverloaded-virtual"
	)
311 312
	CHECK_CXX_COMPILER_FLAG("-Wsuggest-override" SUGGEST_OVERRIDE)
	if (SUGGEST_OVERRIDE)
313
		list(APPEND STRICT_OPTIONS_CXX "-Wsuggest-override" "-Wno-error=suggest-override" )
314
	endif ()
315
	list(APPEND STRICT_OPTIONS_C "-Wstrict-prototypes" "-Werror=strict-prototypes")
316 317 318
	if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
		list(APPEND STRICT_OPTIONS_C "-fno-inline-small-functions")
	endif()
319
	if(CMAKE_C_COMPILER_ID MATCHES "Clang")
320
		list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments" "-Wno-array-bounds")
321
	endif()
322
	if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
323 324
		list(APPEND STRICT_OPTIONS_CXX "-x c++")
	endif()
325
	if(APPLE)
326 327 328
		list(APPEND STRICT_OPTIONS_CPP "-Wno-error=unknown-warning-option" "-Qunused-arguments" "-Wno-tautological-compare" "-Wno-unused-function" "-Wno-array-bounds")
	endif()
	if(ENABLE_STRICT)
Simon Morlat's avatar
Simon Morlat committed
329 330
		list(APPEND STRICT_OPTIONS_C "-Werror" "-Wextra" "-Wno-unused-parameter" "-Wno-missing-field-initializers" "-fno-strict-aliasing")
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wno-unused-parameter" "-Wno-missing-field-initializers" "-fno-strict-aliasing")
331 332
	endif()
endif()
333 334 335 336 337 338
if(STRICT_OPTIONS_CPP)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
endif()
if(STRICT_OPTIONS_C)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()
339

340
set(GETTEXT_PACKAGE "liblinphone")
341
if(ENABLE_RELATIVE_PREFIX)
342
	set(LINPHONE_DATA_DIR ".")
343
else()
344
	set(LINPHONE_DATA_DIR "${CMAKE_INSTALL_PREFIX}")
345
endif()
346
set(LINPHONE_PLUGINS_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_LIBDIR}/liblinphone/plugins")
347

348 349 350
if(WIN32)
	set(LINPHONE_CONFIG_DIR "Linphone")
endif()
351

352 353
set(PACKAGE_LOCALE_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}/locale")
set(PACKAGE_DATA_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}")
354
set(PACKAGE_GRAMMAR_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}/belr/grammars")
355
set(PACKAGE_SOUND_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}/sounds/linphone")
Ghislain MARY's avatar
Ghislain MARY committed
356 357
set(PACKAGE_RING_DIR "${PACKAGE_SOUND_DIR}/rings")
set(PACKAGE_FREEDESKTOP_DIR "${PACKAGE_DATA_DIR}/applications")
358

359 360 361 362 363
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/config.h PROPERTIES GENERATED ON)
add_definitions(-DHAVE_CONFIG_H)


364 365 366 367
if(ENABLE_VIDEO)
	add_definitions(-DVIDEO_ENABLED)
endif()

368 369 370 371
if(ENABLE_LDAP)
	add_definitions(-DLDAP_ENABLED -DLDAP_LIBS_DYNAMIC)
endif()

372 373 374 375 376 377
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "Linphone")
endif()

378
add_subdirectory(include)
379 380 381
if(ENABLE_JAVA_WRAPPER)
	add_subdirectory(wrappers/java)
endif()
382
add_subdirectory(coreapi)
Ghislain MARY's avatar
Ghislain MARY committed
383
add_subdirectory(src)
384
add_subdirectory(share)
385 386 387
if(ENABLE_CONSOLE_UI)
	add_subdirectory(console)
endif()
388 389 390
if(ENABLE_DAEMON)
	add_subdirectory(daemon)
endif()
391 392 393
if(ENABLE_TOOLS)
	add_subdirectory(tools)
endif()
394
if(ENABLE_UNIT_TESTS)
395 396
	add_subdirectory(tester)
endif()
397
if(ENABLE_CXX_WRAPPER)
398 399
	add_subdirectory(wrappers/cpp)
endif()
400 401 402
if(ENABLE_CSHARP_WRAPPER)
	add_subdirectory(wrappers/csharp)
endif()
DanmeiChen's avatar
DanmeiChen committed
403 404 405
if(ENABLE_SWIFT_WRAPPER)
	add_subdirectory(wrappers/swift)
endif()
406

407
include(CMakePackageConfigHelpers)
408 409
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/Linphone/cmake")

410 411 412 413 414
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfigVersion.cmake"
	VERSION ${LINPHONE_VERSION}
	COMPATIBILITY AnyNewerVersion
)
415
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
416 417
	FILE "${CMAKE_CURRENT_BINARY_DIR}/LinphoneTargets.cmake"
)
418
configure_package_config_file(cmake/LinphoneConfig.cmake.in
419
	"${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfig.cmake"
420 421
	INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION}
	NO_SET_AND_CHECK_MACRO
422
)
423

424
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
425
	FILE LinphoneTargets.cmake
426
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
427 428 429 430
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfig.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfigVersion.cmake"
431
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
432
)
433

434 435 436
if (ENABLE_PACKAGE_SOURCE)
	add_subdirectory(build)
endif()