CMakeLists.txt 7.76 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
############################################################################
# CMakeLists.txt
# Copyright (C) 2016  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.
jehan's avatar
jehan committed
20 21
#
############################################################################
22

23
cmake_minimum_required(VERSION 2.8.12)
24
set(CMAKE_MACOSX_RPATH ON) # Before cmake 3.0.0, MACOSX_RPATH was not set to ON by default - however this is no good reason to not enable it by default
25

26

27 28 29
project(bctoolbox)

set(BCTOOLBOX_VERSION_MAJOR 0)
Benjamin REIS's avatar
Benjamin REIS committed
30
set(BCTOOLBOX_VERSION_MINOR 5)
François Grisez's avatar
François Grisez committed
31
set(BCTOOLBOX_VERSION_PATCH 1)
32
set(BCTOOLBOX_SO_VERSION 1)
François Grisez's avatar
François Grisez committed
33
set(BCTOOLBOXTESTER_SO_VERSION 1)
34

35 36 37 38 39 40
set(BCTOOLBOX_VERSION "${BCTOOLBOX_VERSION_MAJOR}.${BCTOOLBOX_VERSION_MINOR}.${BCTOOLBOX_VERSION_PATCH}")
set(PROJECT_VERSION_MAJOR ${BCTOOLBOX_VERSION_MAJOR})
set(PROJECT_VERSION_MINOR ${BCTOOLBOX_VERSION_MINOR})
set(PROJECT_VERSION_PATCH ${BCTOOLBOX_VERSION_PATCH})
set(PROJECT_VERSION "${BCTOOLBOX_VERSION}")

Ghislain MARY's avatar
Ghislain MARY committed
41

42 43
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
jehan's avatar
jehan committed
44
option(ENABLE_POLARSSL "Enable polarssl support" ON)
jehan's avatar
jehan committed
45
option(ENABLE_MBEDTLS "Enable mabedtls support" ON)
46
option(ENABLE_STRICT "Pass strict flags to the compiler" ON)
47 48
option(ENABLE_TESTS_COMPONENT "Enable compilation of tests helper library" ON)
option(ENABLE_TESTS "Enable compilation of tests" ON)
jehan's avatar
jehan committed
49

Ghislain MARY's avatar
Ghislain MARY committed
50

jehan's avatar
jehan committed
51 52 53 54
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
include(CMakePushCheckState)
55
include(GNUInstallDirs)
56
include(cmake/BcToolboxCMakeUtils.cmake)
jehan's avatar
jehan committed
57

58 59
add_subdirectory(build)

jehan's avatar
jehan committed
60 61
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

62
if(NOT CPACK_GENERATOR AND NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
Ghislain MARY's avatar
Ghislain MARY committed
63
	set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
Ghislain MARY's avatar
Ghislain MARY committed
64
	message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
65 66
endif()

67
if(ENABLE_MBEDTLS)
68
	find_package(MbedTLS)
69
	if(MBEDTLS_FOUND)
Ghislain MARY's avatar
Ghislain MARY committed
70
		message(STATUS "Using mbedTLS")
71
	endif()
72 73 74 75
endif()
if(ENABLE_POLARSSL AND NOT MBEDTLS_FOUND)
	find_package(PolarSSL REQUIRED)
	if(POLARSSL_FOUND)
Ghislain MARY's avatar
Ghislain MARY committed
76
		message(STATUS "Using polarSSL")
77 78 79
		if(CTR_DRBG_FREE)
			set(HAVE_CTR_DRGB_FREE 1)
		endif()
80 81
	endif()
endif()
jehan's avatar
jehan committed
82

83
if(HAVE_SSL_GET_DTLS_SRTP_PROTECTION_PROFILE)
Ghislain MARY's avatar
Ghislain MARY committed
84
	message(STATUS "DTLS SRTP available")
johan's avatar
johan committed
85 86
	set(HAVE_DTLS_SRTP 1)
else()
Ghislain MARY's avatar
Ghislain MARY committed
87
	message(STATUS "DTLS SRTP not available")
johan's avatar
johan committed
88 89
endif()

90
if(MBEDTLS_FOUND)
johan's avatar
johan committed
91
	get_filename_component(mbedtls_library_path "${MBEDTLS_LIBRARIES}" PATH)
jehan's avatar
jehan committed
92 93
	string(REPLACE ";" " " MBEDTLS_LIBRARIES_STR "${MBEDTLS_LIBRARIES}")
	set(LIBS_PRIVATE "${LIBS_PRIVATE} ${MBEDTLS_LIBRARIES_STR}")
94 95
endif()
if(POLARSSL_FOUND)
johan's avatar
johan committed
96 97 98 99
	get_filename_component(polarssl_library_path "${POLARSSL_LIBRARIES}" PATH)
	set(LIBS_PRIVATE "${LIBS_PRIVATE} -L${polarssl_library_path} -lpolarssl")
endif()

100
if(ENABLE_TESTS_COMPONENT)
101
	find_package(BcUnit REQUIRED)
102
	cmake_push_check_state(RESET)
103 104 105 106 107
	list(APPEND CMAKE_REQUIRED_INCLUDES ${BCUNIT_INCLUDE_DIRS})
	list(APPEND CMAKE_REQUIRED_LIBRARIES ${BCUNIT_LIBRARIES})
	check_symbol_exists("CU_get_suite" "BCUnit/BCUnit.h" HAVE_CU_GET_SUITE)
	check_symbol_exists("CU_curses_run_tests" "BCUnit/BCUnit.h" HAVE_CU_CURSES)
	check_symbol_exists("CU_set_trace_handler" "BCUnit/Util.h" HAVE_CU_SET_TRACE_HANDLER)
108
	cmake_pop_check_state()
109
	set(TESTER_REQUIRES_PRIVATE "bcunit")
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
110 111
endif()

jehan's avatar
jehan committed
112
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bctoolbox.pc.in ${CMAKE_CURRENT_BINARY_DIR}/bctoolbox.pc)
113
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bctoolbox.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
jehan's avatar
jehan committed
114

115
if(ENABLE_TESTS_COMPONENT AND BCUNIT_FOUND)
116 117 118
	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bctoolbox-tester.pc.in ${CMAKE_CURRENT_BINARY_DIR}/bctoolbox-tester.pc)
	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bctoolbox-tester.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
jehan's avatar
jehan committed
119

jehan's avatar
jehan committed
120 121
find_package(Threads REQUIRED)

jehan's avatar
jehan committed
122 123 124
include_directories(
	include
	src
johan's avatar
johan committed
125
	${CMAKE_CURRENT_BINARY_DIR}
jehan's avatar
jehan committed
126
)
johan's avatar
johan committed
127

128 129 130 131 132 133
set(BCTOOLBOX_CPPFLAGS )
if(ENABLE_STATIC)
	set(BCTBX_STATIC 1)
	list(APPEND BCTOOLBOX_CPPFLAGS "-DBCTBX_STATIC")
endif()

johan's avatar
johan committed
134 135 136 137
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")

jehan's avatar
jehan committed
138 139
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
140 141 142 143 144
if(CMAKE_VERSION VERSION_LESS 3.1 AND NOT APPLE AND NOT MSVC)
	set(STRICT_OPTIONS_CXX "-std=c++11")
else()
	set(STRICT_OPTIONS_CXX )
endif()
145 146 147 148 149
if(MSVC)
	if(ENABLE_STRICT)
		list(APPEND STRICT_OPTIONS_CPP "/WX")
	endif()
else()
jehan's avatar
jehan committed
150 151 152 153 154 155 156 157 158 159
	list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized")
	if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
		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")
	elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
		list(APPEND STRICT_OPTIONS_CPP "-Wno-error=pragmas")
	endif()
	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)
160 161
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wno-unused-parameter" "-Wno-error=unknown-pragmas" "-Wuninitialized" "-Wno-missing-field-initializers" "-fno-strict-aliasing")
		list(APPEND STRICT_OPTIONS_C "-Werror" "-Wdeclaration-after-statement" "-Wstrict-prototypes")
jehan's avatar
jehan committed
162 163 164 165
	endif()
endif()
if(STRICT_OPTIONS_CPP)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
166
	string(REPLACE ";" " " STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP}")
jehan's avatar
jehan committed
167 168 169
endif()
if(STRICT_OPTIONS_C)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
170
	string(REPLACE ";" " " STRICT_OPTIONS_C "${STRICT_OPTIONS_C}")
jehan's avatar
jehan committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
endif()
set(LINK_FLAGS )
if(APPLE)
	list(APPEND LINK_FLAGS "-framework Foundation")
	if(IOS)
		list(APPEND LINK_FLAGS "-framework CoreFoundation" "-framework CFNetwork" "-framework UIKit")
	endif()
endif()
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")

if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "BcToolbox")
endif()

jehan's avatar
jehan committed
187
check_library_exists("rt" "clock_gettime" "" HAVE_LIBRT)
jehan's avatar
jehan committed
188
check_library_exists("dl" "dladdr" "" HAVE_LIBDL)
189
check_include_file("execinfo.h" HAVE_EXECINFO)
jehan's avatar
jehan committed
190 191 192

add_subdirectory(include)
add_subdirectory(src)
193
if(ENABLE_TESTS AND ENABLE_TESTS_COMPONENT AND BCUNIT_FOUND)
194 195
	add_subdirectory(tester)
endif()
jehan's avatar
jehan committed
196 197 198 199

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfigVersion.cmake"
200
	VERSION ${PROJECT_VERSION}
jehan's avatar
jehan committed
201 202 203 204 205 206
	COMPATIBILITY AnyNewerVersion
)
configure_file(cmake/BcToolboxConfig.cmake.in
	"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfig.cmake"
	@ONLY
)
207
configure_file(cmake/BcToolboxCMakeUtils.cmake "${CMAKE_CURRENT_BINARY_DIR}/BcToolboxCMakeUtils.cmake" COPYONLY)
jehan's avatar
jehan committed
208

Ghislain MARY's avatar
Ghislain MARY committed
209
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
jehan's avatar
jehan committed
210 211
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE BcToolboxTargets.cmake
Ghislain MARY's avatar
Ghislain MARY committed
212
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
jehan's avatar
jehan committed
213 214 215 216
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfig.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfigVersion.cmake"
217
	"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxCMakeUtils.cmake"
Ghislain MARY's avatar
Ghislain MARY committed
218
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
jehan's avatar
jehan committed
219
)