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

23
cmake_minimum_required(VERSION 3.0)
24

Ronan's avatar
Ronan committed
25
project(bzrtp VERSION 1.0.6 LANGUAGES C CXX)
26 27


28 29
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
johan's avatar
johan committed
30
option(ENABLE_ZIDCACHE "Turn on compilation of ZID cache, request sqlite" YES)
31
option(ENABLE_STRICT "Build with strict compile options." YES)
32
option(ENABLE_TESTS "Enable compilation of unit tests." NO)
33
option(ENABLE_EXPORTEDKEY_V1_0_RETROCOMPATIBILITY "Enable support for Limev1 with older version of bzrtp(before v1.06)" YES)
34 35


36 37 38 39 40
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()

41
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Ghislain MARY's avatar
Ghislain MARY committed
42

43
set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
Ghislain MARY's avatar
Ghislain MARY committed
44
if(MSVC)
45
	list(APPEND CMAKE_REQUIRED_INCLUDES ${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
46 47
endif()

48
include(GNUInstallDirs)
49 50
include(CheckLibraryExists)
check_library_exists("m" "sqrt" "" HAVE_SQRT)
johan's avatar
johan committed
51

52
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
53
	set(BcToolbox_FIND_COMPONENTS tester)
54 55
	include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
56
	find_package(BcToolbox 0.0.3 REQUIRED OPTIONAL_COMPONENTS tester)
57
endif()
johan's avatar
johan committed
58

johan's avatar
johan committed
59 60
if(ENABLE_ZIDCACHE)
	find_package(Sqlite3 REQUIRED)
61 62
	# Also check if we have libxml2, as we need it for migration purpose
	find_package(XML2)
63 64 65 66 67 68
endif()

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")

69 70 71
set(STRICT_OPTIONS_CPP )
if(NOT MSVC)
	list(APPEND STRICT_OPTIONS_CPP "-Wall")
72
	if(CMAKE_C_COMPILER_ID MATCHES "Clang")
73 74 75
		list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments")
	endif()
	if(ENABLE_STRICT)
76
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wno-unused-parameter" "-Wno-missing-field-initializers")
77 78 79 80 81 82 83
	endif()
endif()
if(STRICT_OPTIONS_CPP)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
	string(REPLACE ";" " " STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP}")
endif()

84 85 86 87 88
set(BZRTP_CPPFLAGS ${BCTOOLBOX_CPPFLAGS})
if(ENABLE_STATIC)
	list(APPEND BZRTP_CPPFLAGS "-DBZRTP_STATIC")
endif()
if(BZRTP_CPPFLAGS)
Ghislain MARY's avatar
Ghislain MARY committed
89
	list(REMOVE_DUPLICATES BZRTP_CPPFLAGS)
90 91 92
	add_definitions(${BZRTP_CPPFLAGS})
endif()

93 94 95 96 97
include_directories(
	include
	${CMAKE_CURRENT_BINARY_DIR}
)

Ghislain MARY's avatar
Ghislain MARY committed
98
if(MSVC)
99
	include_directories(${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
100
endif()
101

Ghislain MARY's avatar
Ghislain MARY committed
102 103
if(ENABLE_ZIDCACHE)
	add_definitions("-DZIDCACHE_ENABLED")
104 105 106
	if(XML2_FOUND)
		add_definitions("-DHAVE_LIBXML2")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
107 108
endif()

109 110 111
if (ENABLE_EXPORTEDKEY_V1_0_RETROCOMPATIBILITY)
	add_definitions("-DSUPPORT_EXPORTEDKEY_V010000")
endif()
112

113 114 115 116 117 118 119
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "BZRTP")
endif()


120 121
add_subdirectory(include)
add_subdirectory(src)
122
if(ENABLE_TESTS AND BCTOOLBOX_TESTER_FOUND)
123 124 125
	enable_testing()
	add_subdirectory(test)
endif()
126

127 128 129 130

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
131
	VERSION ${PROJECT_VERSION}
132 133
	COMPATIBILITY AnyNewerVersion
)
134
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
135 136
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BZRTPTargets.cmake"
)
137
configure_file(cmake/BZRTPConfig.cmake.in
138
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake"
139
	@ONLY
140 141
)

142
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
143
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
144
	FILE BZRTPTargets.cmake
145
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
146 147 148 149
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
150
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
151
)
152 153


jehan's avatar
jehan committed
154
add_subdirectory(build)