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

23
cmake_minimum_required(VERSION 3.0)
24
project(BELLESIP C CXX)
25

26 27 28

set(PACKAGE "belle-sip")
set(PACKAGE_NAME "${PACKAGE}")
Ghislain MARY's avatar
Ghislain MARY committed
29
set(PACKAGE_VERSION "1.4.2")
30 31 32 33 34 35 36
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "jehan.monnier@linphone.org")
set(PACKAGE_TARNAME "belle-sip")
set(PACKAGE_URL "")
set(VERSION "${PACKAGE_VERSION}")


37
option(ENABLE_RTP_MAP_ALWAYS_IN_SDP "Always include rtpmap in SDP." OFF)
38
option(ENABLE_SERVER_SOCKETS "Enable server sockets" ON)
39
option(ENABLE_STATIC "Build static library (default is shared library)." OFF)
40
option(ENABLE_STRICT "Build with strict compile options." YES)
41 42 43 44
option(ENABLE_TUNNEL "Enable tunnel support" OFF)
option(ENABLE_TESTS "Enable compilation of tests" ON)


45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
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()


61 62 63
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
64
include(CMakePushCheckState)
65 66

set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
67
if(MSVC)
68
	list(APPEND CMAKE_REQUIRED_INCLUDES ${MSVC_INCLUDE_DIR})
69
endif()
70
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
71 72 73 74

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

75
cmake_push_check_state(RESET)
76 77 78 79 80 81 82 83
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)
84
if(HAVE_RES_NDESTROY AND HAVE_RES_GETSERVERS)
85
	set(HAVE_RESINIT 1)
86
endif()
87
cmake_pop_check_state()
88

89 90
find_package(Threads)

91
find_package(Antlr3 REQUIRED)
92 93 94 95 96
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()
97

98 99 100
if(ENABLE_RTP_MAP_ALWAYS_IN_SDP)
	set(BELLE_SDP_FORCE_RTP_MAP 1)
endif()
101 102 103

find_package(BcToolBox REQUIRED)

104
if(ENABLE_TUNNEL)
105 106 107 108 109
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
		include("${EP_tunnel_CONFIG_DIR}/TunnelConfig.cmake")
	else()
		find_package(Tunnel)
	endif()
110 111 112 113 114 115 116 117
	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()
if(ENABLE_TESTS)
118 119 120 121 122
	find_package(CUnit)
	if(CUNIT_FOUND)
		check_library_exists(${CUNIT_LIBRARIES} "CU_add_suite" "" HAVE_CU_ADD_SUITE)
		check_library_exists(${CUNIT_LIBRARIES} "CU_get_suite" "" HAVE_CU_GET_SUITE)
		check_library_exists(${CUNIT_LIBRARIES} "CU_curses_run_tests" "" HAVE_CU_CURSES)
123
	else()
124 125
		message(WARNING "Could not find cunit framework, tests will not be compiled.")
		set(ENABLE_TESTS OFF CACHE BOOL "Enable compilation of tests" FORCE)
126 127
	endif()
endif()
128 129 130 131 132


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


133 134 135 136 137 138
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")
139 140
get_filename_component(bctoolbox_library_path "${BCTOOLBOX_LIBRARIES}" PATH)
set(LIBS_PRIVATE "${LIBS_PRIVATE} -L${bctoolbox_library_path} -lbctoolbox")
141 142 143 144 145 146 147 148 149 150 151 152 153
if(CUNIT_FOUND)
	set(REQUIRES_PRIVATE "${REQUIRES_PRIVATE} cunit")
endif()
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)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/belle-sip.pc DESTINATION lib/pkgconfig)


154
include_directories(
155
	include
156
	src
157
	${CMAKE_CURRENT_BINARY_DIR}
158
	${CMAKE_CURRENT_BINARY_DIR}/src
159
	${BCTOOLBOX_INCLUDE_DIRS}
160
)
161 162 163 164 165 166
if(TUNNEL_FOUND)
	include_directories(${TUNNEL_INCLUDE_DIRS})
endif()
if(CUNIT_FOUND)
	include_directories(${CUNIT_INCLUDE_DIRS})
endif()
167
if(MSVC)
168
	include_directories(${MSVC_INCLUDE_DIR})
169
endif()
170

171 172 173
add_definitions("-DHAVE_CONFIG_H")
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
174
set(STRICT_OPTIONS_OBJC "-fmodules")
175
if(NOT MSVC)
176
	list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized")
Ghislain MARY's avatar
Ghislain MARY committed
177
	if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
178
		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
179
	elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
180
		list(APPEND STRICT_OPTIONS_CPP "-Wno-error=pragmas")
181
	endif()
182 183 184 185 186
	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")
187
		list(APPEND STRICT_OPTIONS_C "-Wdeclaration-after-statement" "-Wstrict-prototypes" "-Wno-error=strict-prototypes")
188
	endif()
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
if(WIN32)
205 206 207 208
	add_definitions(
		-DBELLESIP_EXPORTS
		-DBELLESIP_INTERNAL_EXPORTS
	)
209
endif()
Ghislain MARY's avatar
Ghislain MARY committed
210
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone")
211 212 213 214 215
	add_definitions(
		-DHAVE_COMPILER_TLS
		-DUSE_FIXED_NAMESERVERS
	)
endif()
216

217

218 219 220 221 222 223 224
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "BelleSIP")
endif()


225 226
add_subdirectory(include)
add_subdirectory(src)
227

228

229
if(ENABLE_TESTS)
230 231
	enable_testing()
	add_subdirectory(tester)
232
endif()
233 234 235 236 237 238 239 240


include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfigVersion.cmake"
	VERSION ${PACKAGE_VERSION}
	COMPATIBILITY AnyNewerVersion
)
241
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
242 243
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BelleSIPTargets.cmake"
)
244
configure_file(cmake/BelleSIPConfig.cmake.in
245
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfig.cmake"
246
	@ONLY
247 248 249
)

set(ConfigPackageLocation lib/cmake/BelleSIP)
250
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
251 252 253 254
	FILE BelleSIPTargets.cmake
	DESTINATION ${ConfigPackageLocation}
)
install(FILES
255
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfig.cmake"
256 257 258
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfigVersion.cmake"
	DESTINATION ${ConfigPackageLocation}
)