CMakeLists.txt 5.79 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 19 20 21 22 23 24 25 26
############################################################################
# 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
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
############################################################################

cmake_minimum_required(VERSION 3.0)
project(BCTOOLBOX C CXX)

set(PACKAGE "bctoolbox")
jehan's avatar
jehan committed
27 28 29 30 31 32
set(PACKAGE_NAME ${PACKAGE})
set(PACKAGE_VERSION_MAJOR "0")
set(PACKAGE_VERSION_MINOR "0")
set(PACKAGE_VERSION_PATCH "1")
set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}")
set(PACKAGE_STRING "${PACKAGE_NAME}-${PACKAGE_VERSION}")
jehan's avatar
jehan committed
33 34 35 36 37
set(PACKAGE_BUGREPORT "jehan.monnier@linphone.org")
set(PACKAGE_TARNAME "bctoolbox")
set(PACKAGE_URL "")
set(VERSION "${PACKAGE_VERSION}")

Ghislain MARY's avatar
Ghislain MARY committed
38
option(ENABLE_STATIC "Build static library (default is shared library)." NO)
jehan's avatar
jehan committed
39
option(ENABLE_POLARSSL "Enable polarssl support" ON)
jehan's avatar
jehan committed
40
option(ENABLE_MBEDTLS "Enable mabedtls support" ON)
jehan's avatar
jehan committed
41 42 43 44 45 46 47 48

include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
include(CMakePushCheckState)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

49
if(ENABLE_MBEDTLS)
50
	find_package(MbedTLS)
51
	if(MBEDTLS_FOUND)
52 53
		message("Use mbedTLS")
	endif()
54 55 56 57
endif()
if(ENABLE_POLARSSL AND NOT MBEDTLS_FOUND)
	find_package(PolarSSL REQUIRED)
	if(POLARSSL_FOUND)
58 59 60
		message("Use polarSSL")
	endif()
endif()
jehan's avatar
jehan committed
61

62
if(HAVE_SSL_GET_DTLS_SRTP_PROTECTION_PROFILE)
johan's avatar
johan committed
63 64 65 66 67 68
	message("DTLS SRTP available")
	set(HAVE_DTLS_SRTP 1)
else()
	message("DTLS SRTP not available")
endif()

jehan's avatar
jehan committed
69 70 71 72 73
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${prefix}/bin)
set(libdir ${prefix}/lib)
set(includedir ${prefix}/include)

74
if(MBEDTLS_FOUND)
johan's avatar
johan committed
75 76
	get_filename_component(mbedtls_library_path "${MBEDTLS_LIBRARIES}" PATH)
	set(LIBS_PRIVATE "${LIBS_PRIVATE} -L${mbedlts_library_path}")
77 78
endif()
if(POLARSSL_FOUND)
johan's avatar
johan committed
79 80 81 82
	get_filename_component(polarssl_library_path "${POLARSSL_LIBRARIES}" PATH)
	set(LIBS_PRIVATE "${LIBS_PRIVATE} -L${polarssl_library_path} -lpolarssl")
endif()

jehan's avatar
jehan committed
83 84 85 86 87 88 89
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bctoolbox.pc.in ${CMAKE_CURRENT_BINARY_DIR}/bctoolbox.pc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bctoolbox.pc DESTINATION lib/pkgconfig)


include_directories(
	include
	src
johan's avatar
johan committed
90
	${CMAKE_CURRENT_BINARY_DIR}
jehan's avatar
jehan committed
91
)
johan's avatar
johan committed
92

93
if(MBEDTLS_FOUND)
johan's avatar
johan committed
94
	include_directories(${MBEDTLS_INCLUDE_DIRS})
95 96
endif()
if(POLARSSL_FOUND)
johan's avatar
johan committed
97 98 99
	include_directories(${POLARSSL_INCLUDE_DIRS})
endif()

johan's avatar
johan committed
100 101 102 103
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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
if(NOT MSVC)
	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)
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wno-error=unknown-pragmas" "-Wuninitialized" "-fno-strict-aliasing")
		list(APPEND STRICT_OPTIONS_C "-Wdeclaration-after-statement" "-Wstrict-prototypes" "-Wno-error=strict-prototypes")
	endif()
endif()
if(STRICT_OPTIONS_CPP)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
endif()
if(STRICT_OPTIONS_C)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
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(WIN32)
	add_definitions(
		-DBCTOOLBOX_EXPORTS
		-DBCTOOLBOX_INTERNAL_EXPORTS
	)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone")
	add_definitions(
		-DHAVE_COMPILER_TLS
	)
endif()


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

add_compile_options(${STRICT_OPTIONS_CPP} ${STRICT_OPTIONS_C})


add_subdirectory(include)
add_subdirectory(src)
jehan's avatar
jehan committed
159
add_subdirectory(build)
jehan's avatar
jehan committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfigVersion.cmake"
	VERSION ${PACKAGE_VERSION}
	COMPATIBILITY AnyNewerVersion
)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BcToolboxTargets.cmake"
)
configure_file(cmake/BcToolboxConfig.cmake.in
	"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfig.cmake"
	@ONLY
)

set(ConfigPackageLocation lib/cmake/BcToolbox)
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE BcToolboxTargets.cmake
	DESTINATION ${ConfigPackageLocation}
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfig.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/BcToolboxConfigVersion.cmake"
	DESTINATION ${ConfigPackageLocation}
)
Ghislain MARY's avatar
Ghislain MARY committed
185