CMakeLists.txt 4.67 KB
Newer Older
1 2
############################################################################
# CMakeLists.txt
3
# Copyright (C) 2010-2019  Belledonne Communications, Grenoble France
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#
############################################################################
#
# 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.1)
24

25
project(bzrtp VERSION 4.3.0 LANGUAGES C CXX)
26

27 28
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
johan's avatar
johan committed
29
option(ENABLE_ZIDCACHE "Turn on compilation of ZID cache, request sqlite" YES)
30
option(ENABLE_STRICT "Build with strict compile options." YES)
31
option(ENABLE_TESTS "Enable compilation of unit tests." NO)
32
option(ENABLE_EXPORTEDKEY_V1_0_RETROCOMPATIBILITY "Enable support for Limev1 with older version of bzrtp(before v1.06)" YES)
33
option(ENABLE_PACKAGE_SOURCE "Create 'package_source' target for source archive making (CMake >= 3.11)" OFF)
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
find_package(bctoolbox 0.0.3 REQUIRED OPTIONAL_COMPONENTS tester CONFIG)
johan's avatar
johan committed
53

johan's avatar
johan committed
54 55
if(ENABLE_ZIDCACHE)
	find_package(Sqlite3 REQUIRED)
56 57
	# Also check if we have libxml2, as we need it for migration purpose
	find_package(XML2)
58 59 60 61 62 63
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")

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

79 80 81 82 83
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
84
	list(REMOVE_DUPLICATES BZRTP_CPPFLAGS)
85 86 87
	add_definitions(${BZRTP_CPPFLAGS})
endif()

88 89 90 91 92
include_directories(
	include
	${CMAKE_CURRENT_BINARY_DIR}
)

Ghislain MARY's avatar
Ghislain MARY committed
93
if(MSVC)
94
	include_directories(${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
95
endif()
96

Ghislain MARY's avatar
Ghislain MARY committed
97 98
if(ENABLE_ZIDCACHE)
	add_definitions("-DZIDCACHE_ENABLED")
99 100 101
	if(XML2_FOUND)
		add_definitions("-DHAVE_LIBXML2")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
102 103
endif()

104 105 106
if (ENABLE_EXPORTEDKEY_V1_0_RETROCOMPATIBILITY)
	add_definitions("-DSUPPORT_EXPORTEDKEY_V010000")
endif()
107

108
set(EXPORT_TARGETS_NAME "bzrtp")
109

110 111
add_subdirectory(include)
add_subdirectory(src)
112
if(ENABLE_TESTS)
113 114 115
	enable_testing()
	add_subdirectory(test)
endif()
116

117 118

include(CMakePackageConfigHelpers)
119 120
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")

121
write_basic_package_version_file(
122
	"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}ConfigVersion.cmake"
123
	VERSION ${PROJECT_VERSION}
124 125
	COMPATIBILITY AnyNewerVersion
)
126
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
127
	FILE "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Targets.cmake"
128
)
129 130 131 132 133

configure_package_config_file(cmake/BZRTPConfig.cmake.in
	"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
	INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION}
	NO_SET_AND_CHECK_MACRO
134 135
)

136
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
137
	FILE ${EXPORT_TARGETS_NAME}Targets.cmake
138
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
139 140
)
install(FILES
141 142
	"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}ConfigVersion.cmake"
143
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
144
)
145

146 147 148
if (ENABLE_PACKAGE_SOURCE)
	add_subdirectory(build)
endif()