CMakeLists.txt 6.42 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 2.8.12)
Ghislain MARY's avatar
Ghislain MARY committed
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.3.1")
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_SERVER_SOCKETS "Enable server sockets" ON)
38 39 40 41 42 43 44 45 46 47
option(ENABLE_STATIC "Build static library (default is shared library)." OFF)
option(ENABLE_TLS "Enable TLS support" ON)
option(ENABLE_TUNNEL "Enable tunnel support" OFF)
option(ENABLE_TESTS "Enable compilation of tests" ON)


include(CheckIncludeFile)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
48 49

set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
Ghislain MARY's avatar
Ghislain MARY committed
50
if(MSVC)
51
	list(APPEND CMAKE_REQUIRED_INCLUDES ${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
52
endif()
Ghislain MARY's avatar
Ghislain MARY committed
53
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

check_include_file("dlfcn.h" HAVE_DLFCN_H)
check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("memory.h" HAVE_MEMORY_H)
check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("stdlib.h" HAVE_STDLIB_H)
check_include_file("strings.h" HAVE_STRINGS_H)
check_include_file("string.h" HAVE_STRING_H)
check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
check_include_file("unistd.h" HAVE_UNISTD_H)

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

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)
if(NOT "${HAVE_RES_NDESTROY}" STREQUAL "" AND NOT "${HAVE_RES_GETSERVERS}" STREQUAL "")
	set(HAVE_RESINIT 1)
Ghislain MARY's avatar
Ghislain MARY committed
79
endif()
80

81 82
find_package(Threads)

Ghislain MARY's avatar
Ghislain MARY committed
83
find_package(Antlr3 REQUIRED)
Ghislain MARY's avatar
Ghislain MARY committed
84 85
if(ANTLR3C_FOUND)
	cmake_push_check_state(RESET)
86
	set(CMAKE_REQUIRED_INCLUDES ${ANTLR3C_INCLUDE_DIRS})
Ghislain MARY's avatar
Ghislain MARY committed
87 88 89 90
	set(CMAKE_REQUIRED_LIBRARIES ${ANTLR3C_LIBRARIES})
	check_symbol_exists("antlr3StringStreamNew" "antlr3.h" HAVE_ANTLR_STRING_STREAM_NEW)
	cmake_pop_check_state()
endif()
91

92
if(ENABLE_TLS)
Ghislain MARY's avatar
Ghislain MARY committed
93
	find_package(PolarSSL REQUIRED)
94 95
	if(POLARSSL_FOUND)
		set(HAVE_POLARSSL 1)
Ghislain MARY's avatar
Ghislain MARY committed
96 97
	endif()
endif()
98 99 100 101 102 103 104 105 106 107
if(ENABLE_TUNNEL)
	find_package(Tunnel)
	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)
108 109 110 111 112
	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)
Ghislain MARY's avatar
Ghislain MARY committed
113
	else()
114 115
		message(WARNING "Could not find cunit framework, tests will not be compiled.")
		set(ENABLE_TESTS OFF CACHE BOOL "Enable compilation of tests" FORCE)
Ghislain MARY's avatar
Ghislain MARY committed
116 117
	endif()
endif()
118 119 120 121 122


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


123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
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")
if(CUNIT_FOUND)
	set(REQUIRES_PRIVATE "${REQUIRES_PRIVATE} cunit")
endif()
if(HAVE_POLARSSL)
	get_filename_component(polarssl_library_path "${POLARSSL_LIBRARIES}" PATH)
	set(LIBS_PRIVATE "${LIBS_PRIVATE} -L${polarssl_library_path} -lpolarssl")
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)


146
include_directories(
147 148 149
	include
 	src
	${CMAKE_CURRENT_BINARY_DIR}
150
	${CMAKE_CURRENT_BINARY_DIR}/src
151
)
Ghislain MARY's avatar
Ghislain MARY committed
152
if(MSVC)
153
	include_directories(${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
154
endif()
155

156 157 158
add_definitions(-DHAVE_CONFIG_H)
if(NOT MSVC)
	add_definitions(-Wall -Wno-error=unknown-pragmas)
Ghislain MARY's avatar
Ghislain MARY committed
159
	if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
160
		add_definitions(-Werror -Wno-error=unknown-warning-option -Qunused-arguments -Wno-tautological-compare)
Ghislain MARY's avatar
Ghislain MARY committed
161
	elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
162 163
		add_definitions(-Werror -Wno-error=pragmas)
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
164
endif()
165
if(APPLE)
166
	set(LINK_FLAGS "${LINK_FLAGS} -framework CoreFoundation -framework CFNetwork")
Ghislain MARY's avatar
Ghislain MARY committed
167
endif()
168
if(WIN32)
169 170 171 172
	add_definitions(
		-DBELLESIP_EXPORTS
		-DBELLESIP_INTERNAL_EXPORTS
	)
Ghislain MARY's avatar
Ghislain MARY committed
173
endif()
174

175

176 177
add_subdirectory(include)
add_subdirectory(src)
178

179

180
if(ENABLE_TESTS)
181 182
	enable_testing()
	add_subdirectory(tester)
Ghislain MARY's avatar
Ghislain MARY committed
183
endif()
184 185 186 187 188 189 190 191 192 193 194 195


include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfigVersion.cmake"
	VERSION ${PACKAGE_VERSION}
	COMPATIBILITY AnyNewerVersion
)
export(EXPORT BelleSIPTargets
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BelleSIPTargets.cmake"
	NAMESPACE BelledonneCommunications::
)
Ghislain MARY's avatar
Ghislain MARY committed
196
configure_file(cmake/BelleSIPConfig.cmake.in
197
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfig.cmake"
Ghislain MARY's avatar
Ghislain MARY committed
198
	@ONLY
199 200 201 202 203 204 205 206 207
)

set(ConfigPackageLocation lib/cmake/BelleSIP)
install(EXPORT BelleSIPTargets
	FILE BelleSIPTargets.cmake
	NAMESPACE BelledonneCommunications::
	DESTINATION ${ConfigPackageLocation}
)
install(FILES
Ghislain MARY's avatar
Ghislain MARY committed
208
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfig.cmake"
209 210 211
	"${CMAKE_CURRENT_BINARY_DIR}/BelleSIPConfigVersion.cmake"
	DESTINATION ${ConfigPackageLocation}
)