CMakeLists.txt 8.18 KB
Newer Older
jehan's avatar
jehan committed
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.0)
Ghislain MARY's avatar
Ghislain MARY committed
24
project(belle-sip VERSION 1.6.3 LANGUAGES C CXX)
25

26

27 28 29
set(PACKAGE "${PROJECT_NAME}")
set(PACKAGE_NAME "${PROJECT_NAME}")
set(PACKAGE_VERSION "${PROJECT_VERSION}")
30 31
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "jehan.monnier@linphone.org")
32
set(PACKAGE_TARNAME "${PROJECT_NAME}")
33 34 35 36
set(PACKAGE_URL "")
set(VERSION "${PACKAGE_VERSION}")


37 38
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
39
option(ENABLE_RTP_MAP_ALWAYS_IN_SDP "Always include rtpmap in SDP." OFF)
40
option(ENABLE_STRICT "Build with strict compile options." YES)
41 42
option(ENABLE_TUNNEL "Enable tunnel support" OFF)
option(ENABLE_TESTS "Enable compilation of tests" ON)
43
option(ENABLE_MDNS "Enable multicast DNS" OFF)
44 45 46 47 48


include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
49
include(CMakePushCheckState)
50 51 52 53 54 55
include(GNUInstallDirs)

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

set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
58
if(MSVC)
59
	list(APPEND CMAKE_REQUIRED_INCLUDES ${MSVC_INCLUDE_DIR})
60
endif()
61
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
62 63

check_library_exists("dl" "dlopen" "" HAVE_LIBDL)
64
check_library_exists("rt" "clock_gettime" "" HAVE_LIBRT)
65

66
cmake_push_check_state(RESET)
67 68 69 70 71 72 73 74
check_symbol_exists("res_ndestroy" "resolv.h" HAVE_RES_NDESTROY)
set(CMAKE_REQUIRED_LIBRARIES resolv)
check_c_source_compiles("#include <resolv.h>
int main(int argc, char *argv[]) {
res_getservers(NULL,NULL,0);
return 0;
}"
	HAVE_RES_GETSERVERS)
75
if(HAVE_RES_NDESTROY AND HAVE_RES_GETSERVERS)
76
	set(HAVE_RESINIT 1)
77
endif()
78
cmake_pop_check_state()
79

80 81
find_package(Threads)

Ghislain MARY's avatar
Ghislain MARY committed
82
find_package(Zlib)
83

84 85 86
if(ENABLE_RTP_MAP_ALWAYS_IN_SDP)
	set(BELLE_SDP_FORCE_RTP_MAP 1)
endif()
87

jehan's avatar
jehan committed
88
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
89
	set(BcToolbox_FIND_COMPONENTS tester)
jehan's avatar
jehan committed
90 91
	include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
Benjamin REIS's avatar
Benjamin REIS committed
92
	find_package(BcToolbox 0.5.0 REQUIRED OPTIONAL_COMPONENTS tester)
jehan's avatar
jehan committed
93
endif()
94

95
if(ENABLE_TUNNEL)
96 97 98 99 100
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
		include("${EP_tunnel_CONFIG_DIR}/TunnelConfig.cmake")
	else()
		find_package(Tunnel)
	endif()
101 102 103 104 105 106 107
	if(TUNNEL_FOUND)
		set(HAVE_TUNNEL 1)
	else()
		message(WARNING "Could not find the tunnel library!")
		set(ENABLE_TUNNEL OFF CACHE BOOL "Enable tunnel support" FORCE)
	endif()
endif()
Ghislain MARY's avatar
Ghislain MARY committed
108 109 110
if(ZLIB_FOUND)
	set(HAVE_ZLIB 1)
endif()
111

112 113 114 115 116 117 118
if(ENABLE_MDNS)
	find_package(DNSSD REQUIRED)
	if(DNSSD_FOUND)
		set(HAVE_MDNS 1)
	endif()
endif()

119 120 121 122

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)


123 124 125 126
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${prefix}/bin)
set(libdir ${prefix}/lib)
set(includedir ${prefix}/include)
127
get_filename_component(bctoolbox_library_path "${BCTOOLBOX_CORE_LIBRARIES}" PATH)
128
set(LIBS_PRIVATE "${LIBS_PRIVATE} -L${bctoolbox_library_path} -lbctoolbox")
Ghislain MARY's avatar
Ghislain MARY committed
129 130 131
if(ZLIB_FOUND)
	set(REQUIRES_PRIVATE "${REQUIRES_PRIVATE} z")
endif()
132 133 134 135 136 137 138
if(HAVE_LIBDL)
	set(LIBS_PRIVATE "${LIBS_PRIVATE} -ldl")
endif()
if(HAVE_LIBRT)
	set(LIBS_PRIVATE "${LIBS_PRIVATE} -lrt")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/belle-sip.pc.in ${CMAKE_CURRENT_BINARY_DIR}/belle-sip.pc)
139
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/belle-sip.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
140 141


142
include_directories(
143
	include
144
	src
145
	${CMAKE_CURRENT_BINARY_DIR}
146
	${CMAKE_CURRENT_BINARY_DIR}/src
147
	${BCTOOLBOX_CORE_INCLUDE_DIRS}
148
)
149 150 151
if(TUNNEL_FOUND)
	include_directories(${TUNNEL_INCLUDE_DIRS})
endif()
Ghislain MARY's avatar
Ghislain MARY committed
152 153 154
if(ZLIB_FOUND)
	include_directories(${ZLIB_INCLUDE_DIRS})
endif()
155 156 157
if(DNSSD_FOUND)
	include_directories(${DNSSD_INCLUDE_DIRS})
endif()
158
if(MSVC)
159
	include_directories(${MSVC_INCLUDE_DIR})
160
endif()
161

162 163 164
add_definitions("-DHAVE_CONFIG_H")
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
165
set(STRICT_OPTIONS_OBJC "-fmodules")
166 167 168 169 170 171 172
if(MSVC)
	list(APPEND STRICT_OPTIONS_CPP "/wd4068") # Disable "unknown pragma" warnings from antlr
	list(APPEND STRICT_OPTIONS_CPP "/wd4129") # Disable "unrecognized character escape sequence" warnings from antlr
	if(ENABLE_STRICT)
		list(APPEND STRICT_OPTIONS_CPP "/WX")
	endif()
else()
173
	list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized" "-Wno-error=deprecated-declarations")
174
	if(CMAKE_C_COMPILER_ID MATCHES "Clang")
175
		list(APPEND STRICT_OPTIONS_CPP "-Wno-error=unknown-warning-option" "-Qunused-arguments" "-Wno-tautological-compare" "-Wno-builtin-requires-header" "-Wno-unused-function" "-Wno-gnu-designator" "-Wno-array-bounds")
Ghislain MARY's avatar
Ghislain MARY committed
176
	elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
177
		list(APPEND STRICT_OPTIONS_C "-Werror=vla") # Forbids usage of variable length arrays since Visual Studio's compiler does not support them.
178
		list(APPEND STRICT_OPTIONS_CPP "-Wno-error=pragmas")
179
	endif()
180 181 182 183
	if(APPLE)
		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)
184
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wno-unused-parameter" "-Wno-error=unknown-pragmas" "-Wuninitialized" "-fno-strict-aliasing")
185
		list(APPEND STRICT_OPTIONS_C "-Wstrict-prototypes -Wno-missing-field-initializers" "-Wno-error=unused-result")
186
	endif()
187
	# this warning is generated by antlr so ignore it for now
188
	list(APPEND STRICT_OPTIONS_C "-Wno-strict-prototypes" "-Wno-error=sign-compare")
189 190
endif()
if(STRICT_OPTIONS_CPP)
191
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
192 193 194
endif()
if(STRICT_OPTIONS_C)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
195
endif()
196
set(LINK_FLAGS )
197
if(APPLE)
198 199 200 201
	list(APPEND LINK_FLAGS "-framework Foundation")
	if(IOS)
		list(APPEND LINK_FLAGS "-framework CoreFoundation" "-framework CFNetwork" "-framework UIKit")
	endif()
202
endif()
203
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
204 205 206 207

set(BELLESIP_CPPFLAGS ${BCTOOLBOX_CPPFLAGS})
if(ENABLE_STATIC)
	list(APPEND BELLESIP_CPPFLAGS "-DBELLESIP_STATIC")
208
endif()
209
if(BELLESIP_CPPFLAGS)
Ghislain MARY's avatar
Ghislain MARY committed
210
	list(REMOVE_DUPLICATES BELLESIP_CPPFLAGS)
211 212 213 214
	add_definitions(${BELLESIP_CPPFLAGS})
endif()
add_definitions("-DBELLESIP_EXPORTS")

215
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
216 217 218
	add_definitions(
		-DHAVE_COMPILER_TLS
		-DUSE_FIXED_NAMESERVERS
219
		-DUSE_GETADDRINFO_FALLBACK
220 221
	)
endif()
222

223

224 225 226 227 228 229 230
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "BelleSIP")
endif()


231 232
add_subdirectory(include)
add_subdirectory(src)
233

234

235
if(ENABLE_TESTS AND BCTOOLBOX_TESTER_FOUND)
236 237
	enable_testing()
	add_subdirectory(tester)
238
endif()
239 240 241 242 243 244 245 246


include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfigVersion.cmake"
	VERSION ${PACKAGE_VERSION}
	COMPATIBILITY AnyNewerVersion
)
247
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
248 249
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BelleSIPTargets.cmake"
)
250
configure_file(cmake/BelleSIPConfig.cmake.in
251
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfig.cmake"
252
	@ONLY
253 254
)

255
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/BelleSIP/cmake")
256
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
257
	FILE BelleSIPTargets.cmake
258
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
259 260
)
install(FILES
261
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfig.cmake"
262
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfigVersion.cmake"
263
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
264
)
265

jehan's avatar
jehan committed
266
add_subdirectory(build)