CMakeLists.txt 13.3 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
#
############################################################################

Ghislain MARY's avatar
Ghislain MARY committed
23
cmake_minimum_required(VERSION 3.0)
Ronan's avatar
Ronan committed
24
project(linphone VERSION 3.12.0 LANGUAGES C CXX)
25

26

27 28 29 30
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})
31
set(LINPHONE_SO_VERSION "9")
32

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

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

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

43
option(ENABLE_CONSOLE_UI "Turn on or off compilation of console interface." YES)
Ronan's avatar
Ronan committed
44
option(ENABLE_CSHARP_WRAPPER "Build the C# wrapper for Liblinphone." OFF)
45
option(ENABLE_JAVA_WRAPPER "Build the Java wrapper for Liblinphone." OFF)
Ronan's avatar
Ronan committed
46
option(ENABLE_CXX_WRAPPER "Build the C++ wrapper for Liblinphone." YES)
47
option(ENABLE_DAEMON "Enable the linphone daemon interface." YES)
Ronan's avatar
Ronan committed
48 49
option(ENABLE_DATE "Use build date in internal version number." NO)
option(ENABLE_DEBUG_LOGS "Turn on or off debug level logs." NO)
50
option(ENABLE_DOC "Enable API documentation generation." NO)
Ronan's avatar
Ronan committed
51
option(ENABLE_JAVADOC "Add a target to generate documentation for Java API" NO)
52 53
option(ENABLE_LDAP "Enable LDAP support." NO)
option(ENABLE_RELATIVE_PREFIX "Find resources relatively to the installation directory." NO)
Ronan's avatar
Ronan committed
54
option(ENABLE_SQLITE_STORAGE "Turn on compilation sqlite storage, for messages, contacts, history" YES)
55
option(ENABLE_STRICT "Build with strict compile options." YES)
56
option(ENABLE_TOOLS "Turn on or off compilation of tools." YES)
57 58 59
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
60
option(ENABLE_UPDATE_CHECK "Enable update check." NO)
Ronan's avatar
Ronan committed
61
option(ENABLE_VCARD "Turn on compilation of vcard4 support." YES)
62
option(ENABLE_VIDEO "Build with video support." YES)
Ronan's avatar
Ronan committed
63 64 65

cmake_dependent_option(ENABLE_LIME "Enable Instant Messaging Encryption." YES "ENABLE_SQLITE_STORAGE" NO)
cmake_dependent_option(ENABLE_NOTIFY "Enable libnotify support." YES "ENABLE_GTK_UI;NOT APPLE" NO)
66
cmake_dependent_option(ENABLE_ASSISTANT "Turn on assistant compiling." YES "ENABLE_GTK_UI" NO)
67

68
set(CMAKE_CXX_STANDARD 11)
69
set(CMAKE_CXX_EXTENSIONS NO)
70

71 72 73
if(NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE "Release")
endif()
74 75
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
	add_definitions("-DDEBUG")
76
endif()
77

78 79 80 81 82
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
83 84 85
if(WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
	list(APPEND LINPHONE_LIBS_FOR_TOOLS "Ws2_32")
endif()
86

87
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
88

89
include(CheckSymbolExists)
90
include(CMakePushCheckState)
91
include(GNUInstallDirs)
92
include(CheckCXXCompilerFlag)
93 94 95 96 97

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

99
set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
100
if(MSVC)
101
	list(APPEND CMAKE_REQUIRED_INCLUDES "${MSVC_INCLUDE_DIR}")
102 103
endif()

104 105 106
# find_package should be invoked here to check for libraries - however do NOT
# call include_directories here (see below)

107 108 109 110 111 112 113 114 115 116 117 118 119 120
if (ENABLE_VCARD)
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
		include("${EP_belcard_CONFIG_DIR}/BelcardConfig.cmake")
	else()
		find_package(Belcard)
	endif()
	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()

121 122 123
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	include("${EP_bellesip_CONFIG_DIR}/BelleSIPConfig.cmake")
	include("${EP_ms2_CONFIG_DIR}/Mediastreamer2Config.cmake")
124
	include("${EP_ortp_CONFIG_DIR}/ORTPConfig.cmake")
125
	set(BcToolbox_FIND_COMPONENTS tester)
jehan's avatar
jehan committed
126
	include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
Ronan's avatar
Ronan committed
127
	include("${EP_belr_CONFIG_DIR}/BelrConfig.cmake")
128 129 130
else()
	find_package(BelleSIP REQUIRED)
	find_package(Mediastreamer2 REQUIRED)
131
	find_package(ORTP REQUIRED)
132
	find_package(BcToolbox 0.0.3 REQUIRED OPTIONAL_COMPONENTS tester)
Ronan's avatar
Ronan committed
133
	find_package(Belr REQUIRED)
134
endif()
135
find_package(XML2 REQUIRED)
136
find_package(LibXsd REQUIRED)
Benjamin REIS's avatar
Benjamin REIS committed
137
find_package(Soci)
138
find_package(ZLIB)
139
if(ENABLE_TUNNEL)
140 141 142 143 144
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
		include("${EP_tunnel_CONFIG_DIR}/TunnelConfig.cmake")
	else()
		find_package(Tunnel)
	endif()
145 146
	if(NOT TUNNEL_FOUND)
		message(WARNING "Could not find the tunnel library!")
147 148 149
		set(ENABLE_TUNNEL OFF CACHE BOOL "Enable tunnel support." FORCE)
	endif()
endif()
150
if(ENABLE_SQLITE_STORAGE)
151
	find_package(Sqlite3 REQUIRED)
152
endif()
153 154 155 156 157 158 159
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)
160 161
	endif()
endif()
162 163 164
if(ENABLE_ASSISTANT)
	set(BUILD_WIZARD 1)
endif()
165 166
if(ENABLE_LIME)
	#bzrtp is only required for LIME
johan's avatar
johan committed
167 168 169
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
		include("${EP_bzrtp_CONFIG_DIR}/BZRTPConfig.cmake")
	else()
170
		find_package(BZRTP REQUIRED)
johan's avatar
johan committed
171
	endif()
172
	set(HAVE_LIME 1)
173
endif()
174
if(ENABLE_CXX_WRAPPER OR ENABLE_CSHARP_WRAPPER OR ENABLE_JAVA_WRAPPER OR ENABLE_DOC)
175
	find_package(PythonInterp REQUIRED)
176 177 178 179 180 181 182
	check_python_module(pystache)
	check_python_module(six)
	if(ENABLE_DOC)
		check_python_module(sphinx)
		check_python_module(javasphinx)
		check_python_module(sphinx_csharp)
	endif()
183
endif()
184

185 186 187 188
if(UNIX AND NOT APPLE)
	include(CheckIncludeFiles)
	check_include_files(libudev.h HAVE_LIBUDEV_H)
endif()
189

Ghislain MARY's avatar
Ghislain MARY committed
190 191 192 193 194 195 196 197 198 199 200 201 202
if(MSVC AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
	find_library(LIBGCC NAMES gcc)
	find_library(LIBMINGWEX NAMES mingwex)
endif()

if(NOT WIN32)
	find_package(Iconv QUIET)
endif()
if(ANDROID)
	find_package(CpuFeatures REQUIRED)
	find_package(Support REQUIRED)
endif()

203 204
set(LINPHONE_LDFLAGS "${BELLESIP_LDFLAGS} ${MEDIASTREAMER2_LDFLAGS}")
if(BELCARD_FOUND AND APPLE)
205
	set(LINPHONE_LDFLAGS "${LINPHONE_LDFLAGS} -stdlib=libc++")
206 207
endif()

208 209
# 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)
210
include_directories(
211
	${CMAKE_CURRENT_BINARY_DIR}
212
	${CMAKE_CURRENT_BINARY_DIR}/coreapi/
213 214 215
	coreapi/
	include/
	src/
216 217
)
set(LINPHONE_INCLUDE_DIRS
218
	${BELLESIP_INCLUDE_DIRS}
219
	${MEDIASTREAMER2_INCLUDE_DIRS}
220
	${BCTOOLBOX_CORE_INCLUDE_DIRS}
Ronan's avatar
Ronan committed
221
	${BELR_INCLUDE_DIRS}
222
)
johan's avatar
johan committed
223 224 225
if (BZRTP_FOUND)
	list(APPEND LINPHONE_INCLUDE_DIRS ${BZRTP_INCLUDE_DIRS})
endif()
Ghislain MARY's avatar
Ghislain MARY committed
226 227 228
if(ANDROID)
	include_directories(${CMAKE_CURRENT_BINARY_DIR}/java)
endif()
229
if(ENABLE_TUNNEL)
230
	list(APPEND LINPHONE_INCLUDE_DIRS ${TUNNEL_INCLUDE_DIRS})
231
endif()
232
if (ENABLE_VCARD)
233
	list(APPEND LINPHONE_INCLUDE_DIRS ${BELCARD_INCLUDE_DIRS})
234
endif()
235

236
list(APPEND LINPHONE_INCLUDE_DIRS ${XML2_INCLUDE_DIRS})
237

238
if(ZLIB_FOUND)
239
	list(APPEND LINPHONE_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
240 241
	set(HAVE_ZLIB 1)
endif()
242
if(SQLITE3_FOUND)
243
	list(APPEND LINPHONE_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIRS})
244
	if(ENABLE_SQLITE_STORAGE)
245
		add_definitions("-DSQLITE_STORAGE_ENABLED")
246
	endif()
247
endif()
248 249
if(INTL_FOUND)
	set(HAVE_INTL 1)
250
	list(APPEND LINPHONE_INCLUDE_DIRS ${INTL_INCLUDE_DIRS})
251
endif()
252
if(MSVC)
253
	include_directories(${MSVC_INCLUDE_DIR})
254 255
endif()

Ronan's avatar
Ronan committed
256
set(LINPHONE_CPPFLAGS ${BELCARD_CPPFLAGS} ${BELLESIP_CPPFLAGS} ${MEDIASTREAMER2_CPPFLAGS} ${BCTOOLBOX_CPPFLAGS} ${BELR_CPPFLAGS})
257 258
if(ENABLE_STATIC)
	list(APPEND LINPHONE_CPPFLAGS "-DLINPHONE_STATIC")
259 260
endif()
if(LINPHONE_CPPFLAGS)
Ghislain MARY's avatar
Ghislain MARY committed
261
	list(REMOVE_DUPLICATES LINPHONE_CPPFLAGS)
262 263
	add_definitions(${LINPHONE_CPPFLAGS})
endif()
264

265
if(ENABLE_DEBUG_LOGS)
266
	add_definitions("-DDEBUG_LOGS")
267
endif()
268

269 270 271 272 273
# Enable stdint.h limit macros on C++ files. (Windows only.)
if(MSVC)
	add_definitions("-D__STDC_LIMIT_MACROS")
endif()

274 275
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
François Grisez's avatar
François Grisez committed
276
set(STRICT_OPTIONS_CXX )
277
set(STRICT_OPTIONS_OBJC )
278 279
if(MSVC)
	list(APPEND STRICT_OPTIONS_CPP "/wd4995") # Disable "name was marked as #pragma deprecated" warnings
280
	list(APPEND STRICT_OPTIONS_CPP "/wd4996") # Disable deprecated function warnings
281 282 283 284
	if(ENABLE_STRICT)
		list(APPEND STRICT_OPTIONS_CPP "/WX")
	endif()
else()
Ronan's avatar
Ronan committed
285 286 287 288 289 290 291 292 293 294 295 296
	list(APPEND STRICT_OPTIONS_CPP
		"-Wall"
		"-Wcast-align"
		"-Wconversion"
		"-Werror=return-type"
		"-Wfloat-equal"
		"-Winit-self"
		"-Wno-error=deprecated-declarations"
		"-Wpointer-arith"
		"-Wuninitialized"
		"-Wunused"
	)
297
	list(APPEND STRICT_OPTIONS_CXX
298
		"-Wnon-virtual-dtor"
299 300
		"-Woverloaded-virtual"
	)
301 302
	CHECK_CXX_COMPILER_FLAG("-Wsuggest-override" SUGGEST_OVERRIDE)
	if (SUGGEST_OVERRIDE)
303
		list(APPEND STRICT_OPTIONS_CXX "-Wsuggest-override" "-Wno-error=suggest-override" )
304
	endif ()
305
	list(APPEND STRICT_OPTIONS_C "-Wstrict-prototypes" "-Werror=strict-prototypes")
306 307 308
	if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
		list(APPEND STRICT_OPTIONS_C "-fno-inline-small-functions")
	endif()
309
	if(CMAKE_C_COMPILER_ID MATCHES "Clang")
310
		list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments" "-Wno-array-bounds")
311
	endif()
312
	if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
313 314
		list(APPEND STRICT_OPTIONS_CXX "-x c++")
	endif()
315
	if(APPLE)
316 317 318
		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
319 320
		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")
321 322
	endif()
endif()
323 324 325 326 327 328
if(STRICT_OPTIONS_CPP)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
endif()
if(STRICT_OPTIONS_C)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()
329

330
set(GETTEXT_PACKAGE "linphone")
331
if(ENABLE_RELATIVE_PREFIX)
332
	set(LINPHONE_DATA_DIR ".")
333
else()
334
	set(LINPHONE_DATA_DIR "${CMAKE_INSTALL_PREFIX}")
335
endif()
336
set(LINPHONE_PLUGINS_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_LIBDIR}/liblinphone/plugins")
337 338 339
if(WIN32)
	set(LINPHONE_CONFIG_DIR "Linphone")
endif()
340 341
set(PACKAGE_LOCALE_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}/locale")
set(PACKAGE_DATA_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}")
342
set(PACKAGE_GRAMMAR_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}/belr/grammars")
343
set(PACKAGE_SOUND_DIR "${LINPHONE_DATA_DIR}/${CMAKE_INSTALL_DATADIR}/sounds/linphone")
Ghislain MARY's avatar
Ghislain MARY committed
344 345
set(PACKAGE_RING_DIR "${PACKAGE_SOUND_DIR}/rings")
set(PACKAGE_FREEDESKTOP_DIR "${PACKAGE_DATA_DIR}/applications")
346 347 348 349 350
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)


351 352 353 354 355
if(ENABLE_VIDEO)
	add_definitions(-DVIDEO_ENABLED)
endif()


356 357 358 359 360 361
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "Linphone")
endif()

362
add_subdirectory(include)
363
add_subdirectory(java)
364 365 366
if(ENABLE_JAVA_WRAPPER)
	add_subdirectory(wrappers/java)
endif()
367
add_subdirectory(coreapi)
Ghislain MARY's avatar
Ghislain MARY committed
368
add_subdirectory(src)
369
add_subdirectory(share)
370 371 372
if(ENABLE_CONSOLE_UI)
	add_subdirectory(console)
endif()
373 374 375
if(ENABLE_DAEMON)
	add_subdirectory(daemon)
endif()
376 377 378
if(ENABLE_TOOLS)
	add_subdirectory(tools)
endif()
379
if(ENABLE_UNIT_TESTS AND BCTOOLBOX_TESTER_FOUND)
380 381
	add_subdirectory(tester)
endif()
382
if(ENABLE_CXX_WRAPPER)
383 384
	add_subdirectory(wrappers/cpp)
endif()
385 386 387
if(ENABLE_CSHARP_WRAPPER)
	add_subdirectory(wrappers/csharp)
endif()
388

389 390 391 392 393 394
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfigVersion.cmake"
	VERSION ${LINPHONE_VERSION}
	COMPATIBILITY AnyNewerVersion
)
395
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
396 397 398 399 400 401
	FILE "${CMAKE_CURRENT_BINARY_DIR}/LinphoneTargets.cmake"
)
configure_file(cmake/LinphoneConfig.cmake.in
	"${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfig.cmake"
	@ONLY
)
402

403
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/Linphone/cmake")
404
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
405
	FILE LinphoneTargets.cmake
406
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
407 408 409 410
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfig.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/LinphoneConfigVersion.cmake"
411
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
412
)
413

jehan's avatar
jehan committed
414
add_subdirectory(build)