CMakeLists.txt 4.7 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

25
project(bzrtp VERSION 1.0.5 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 34


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

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

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

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

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

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

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

83 84 85 86 87
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
88
	list(REMOVE_DUPLICATES BZRTP_CPPFLAGS)
89 90 91
	add_definitions(${BZRTP_CPPFLAGS})
endif()

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

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

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

108

109 110 111 112 113 114 115
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "BZRTP")
endif()


116 117
add_subdirectory(include)
add_subdirectory(src)
118
if(ENABLE_TESTS AND BCTOOLBOX_TESTER_FOUND)
119 120 121
	enable_testing()
	add_subdirectory(test)
endif()
122

123 124 125 126

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

138
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
139
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
140
	FILE BZRTPTargets.cmake
141
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
142 143 144 145
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
146
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
147
)
148 149 150 151 152 153 154 155 156 157 158 159 160


# CPack settings
set(CPACK_PACKAGE_NAME "bzrtp")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_SOURCE_IGNORE_FILES
        "^${CMAKE_BINARY_DIR}"
        "/\\\\..+"
)

include(CPack)