CMakeLists.txt 8.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
############################################################################
# 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
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
############################################################################

Ghislain MARY's avatar
Ghislain MARY committed
23
cmake_minimum_required(VERSION 3.0)
24
project(belle-sip VERSION 1.4.2 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_SERVER_SOCKETS "Enable server sockets" ON)
41
option(ENABLE_STRICT "Build with strict compile options." YES)
42 43 44 45
option(ENABLE_TUNNEL "Enable tunnel support" OFF)
option(ENABLE_TESTS "Enable compilation of tests" ON)


46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
macro(apply_compile_flags SOURCE_FILES)
	if(${SOURCE_FILES})
		set(options "")
		foreach(a ${ARGV})
			if(STRICT_OPTIONS_${a})
				string(REPLACE ";" " " options_${a} "${STRICT_OPTIONS_${a}}")
				set(options "${options} ${options_${a}}")
			endif()
		endforeach()
		if(options)
			set_source_files_properties(${${SOURCE_FILES}} PROPERTIES COMPILE_FLAGS "${options}")
		endif()
	endif()
endmacro()


62 63 64
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
65
include(CMakePushCheckState)
66 67 68 69 70 71
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()
72 73

set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
Ghislain MARY's avatar
Ghislain MARY committed
74
if(MSVC)
75
	list(APPEND CMAKE_REQUIRED_INCLUDES ${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
76
endif()
Ghislain MARY's avatar
Ghislain MARY committed
77
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
78 79 80 81

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

82
cmake_push_check_state(RESET)
83 84 85 86 87 88 89 90
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)
91
if(HAVE_RES_NDESTROY AND HAVE_RES_GETSERVERS)
92
	set(HAVE_RESINIT 1)
Ghislain MARY's avatar
Ghislain MARY committed
93
endif()
94
cmake_pop_check_state()
95

96 97
find_package(Threads)

Ghislain MARY's avatar
Ghislain MARY committed
98
find_package(Zlib)
Ghislain MARY's avatar
Ghislain MARY committed
99
find_package(Antlr3 REQUIRED)
100 101 102 103 104
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES ${ANTLR3C_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${ANTLR3C_LIBRARIES})
check_symbol_exists("antlr3StringStreamNew" "antlr3.h" HAVE_ANTLR_STRING_STREAM_NEW)
cmake_pop_check_state()
105

106 107 108
if(ENABLE_RTP_MAP_ALWAYS_IN_SDP)
	set(BELLE_SDP_FORCE_RTP_MAP 1)
endif()
109

jehan's avatar
jehan committed
110
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
111
	set(BcToolbox_FIND_COMPONENTS tester)
jehan's avatar
jehan committed
112 113
	include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
114
	find_package(BcToolbox REQUIRED OPTIONAL_COMPONENTS tester)
jehan's avatar
jehan committed
115
endif()
116

117
if(ENABLE_TUNNEL)
118 119 120 121 122
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
		include("${EP_tunnel_CONFIG_DIR}/TunnelConfig.cmake")
	else()
		find_package(Tunnel)
	endif()
123 124 125 126 127 128 129
	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
130 131 132
if(ZLIB_FOUND)
	set(HAVE_ZLIB 1)
endif()
133 134 135 136 137


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


138 139 140 141 142 143
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${prefix}/bin)
set(libdir ${prefix}/lib)
set(includedir ${prefix}/include)
get_filename_component(antlr3c_library_path "${ANTLR3C_LIBRARIES}" PATH)
set(LIBS_PRIVATE "-L${antlr3c_library_path} -lantlr3c")
144 145
get_filename_component(bctoolbox_library_path "${BCTOOLBOX_LIBRARIES}" PATH)
set(LIBS_PRIVATE "${LIBS_PRIVATE} -L${bctoolbox_library_path} -lbctoolbox")
146
set(REQUIRES_PRIVATE "")
Ghislain MARY's avatar
Ghislain MARY committed
147 148 149
if(ZLIB_FOUND)
	set(REQUIRES_PRIVATE "${REQUIRES_PRIVATE} z")
endif()
150 151 152 153 154 155 156
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)
157
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/belle-sip.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
158 159


160
include_directories(
161
	include
162
	src
163
	${CMAKE_CURRENT_BINARY_DIR}
164
	${CMAKE_CURRENT_BINARY_DIR}/src
165
	${BCTOOLBOX_CORE_INCLUDE_DIRS}
166
)
167 168 169
if(TUNNEL_FOUND)
	include_directories(${TUNNEL_INCLUDE_DIRS})
endif()
Ghislain MARY's avatar
Ghislain MARY committed
170 171 172
if(ZLIB_FOUND)
	include_directories(${ZLIB_INCLUDE_DIRS})
endif()
Ghislain MARY's avatar
Ghislain MARY committed
173
if(MSVC)
174
	include_directories(${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
175
endif()
176

177 178 179
add_definitions("-DHAVE_CONFIG_H")
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
180
set(STRICT_OPTIONS_OBJC "-fmodules")
181
if(NOT MSVC)
182
	list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized" "-Wno-error=deprecated-declarations")
Ghislain MARY's avatar
Ghislain MARY committed
183
	if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
184
		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
185
	elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
186
		list(APPEND STRICT_OPTIONS_CPP "-Wno-error=pragmas")
187
	endif()
188 189 190 191 192
	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)
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wno-error=unknown-pragmas" "-Wuninitialized" "-fno-strict-aliasing")
193
		list(APPEND STRICT_OPTIONS_C "-Wdeclaration-after-statement" "-Wstrict-prototypes" "-Wno-error=strict-prototypes")
194
	endif()
195 196
endif()
if(STRICT_OPTIONS_CPP)
197
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
198 199 200
endif()
if(STRICT_OPTIONS_C)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
Ghislain MARY's avatar
Ghislain MARY committed
201
endif()
202
set(LINK_FLAGS )
203
if(APPLE)
204 205 206 207
	list(APPEND LINK_FLAGS "-framework Foundation")
	if(IOS)
		list(APPEND LINK_FLAGS "-framework CoreFoundation" "-framework CFNetwork" "-framework UIKit")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
208
endif()
209
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
210
if(WIN32)
211 212 213 214
	add_definitions(
		-DBELLESIP_EXPORTS
		-DBELLESIP_INTERNAL_EXPORTS
	)
Ghislain MARY's avatar
Ghislain MARY committed
215
endif()
216
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
217 218 219
	add_definitions(
		-DHAVE_COMPILER_TLS
		-DUSE_FIXED_NAMESERVERS
220
		-DUSE_GETADDRINFO_FALLBACK
221 222
	)
endif()
223

224

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


232 233
add_subdirectory(include)
add_subdirectory(src)
234

235

236
if(ENABLE_TESTS AND BCTOOLBOX_TESTER_FOUND)
237 238
	enable_testing()
	add_subdirectory(tester)
Ghislain MARY's avatar
Ghislain MARY committed
239
endif()
240 241 242 243 244 245 246 247


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

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