CMakeLists.txt 5.05 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) 2015  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)
Ronan's avatar
Ronan committed
24
project(BELR VERSION 0.1.3 LANGUAGES C CXX)
25 26 27

set(BELR_SO_VERSION "1")

28 29
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
30
option(ENABLE_STRICT "Build with strict compile options." YES)
31
option(ENABLE_TOOLS "Turn on or off compilation of tools." YES)
Simon Morlat's avatar
Simon Morlat committed
32
option(ENABLE_UNIT_TESTS "Enable compilation of unit tests." YES)
33

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

36 37 38 39 40
if(NOT CPACK_GENERATOR AND 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
include(GNUInstallDirs)
42 43
include(CheckSymbolExists)
include(CMakePushCheckState)
44
include(CheckCXXCompilerFlag)
45 46 47 48

# find_package should be invoked here to check for libraries - however do NOT
# call include_directories here (see below)

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

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
if(UNIX AND NOT APPLE)
	include(CheckIncludeFiles)
	check_include_files(libudev.h HAVE_LIBUDEV_H)
endif()

include_directories(
	include/
	src/
	${CMAKE_CURRENT_BINARY_DIR}
)
if(MSVC)
	include_directories(${MSVC_INCLUDE_DIR})
endif()

set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
72
set(STRICT_OPTIONS_CXX )
73
set(STRICT_OPTIONS_OBJC )
74 75 76 77 78
if(MSVC)
	if(ENABLE_STRICT)
		list(APPEND STRICT_OPTIONS_CPP "/WX")
	endif()
else()
79
	list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized" "-Wno-error=deprecated-declarations")
80
	list(APPEND STRICT_OPTIONS_C "-Wdeclaration-after-statement" "-Wstrict-prototypes" "-Wno-error=strict-prototypes")
81
	list(APPEND STRICT_OPTIONS_CXX "-std=c++11")
82
	if(CMAKE_C_COMPILER_ID MATCHES "Clang")
83 84 85 86
		list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments" "-Wno-array-bounds")
	endif()
	if(APPLE)
		list(APPEND STRICT_OPTIONS_CPP "-Wno-error=unknown-warning-option" "-Qunused-arguments" "-Wno-tautological-compare" "-Wno-unused-function" "-Wno-array-bounds")
87
		list(APPEND STRICT_OPTIONS_CXX "-stdlib=libc++")
88 89
	endif()
	if(ENABLE_STRICT)
Simon Morlat's avatar
Simon Morlat committed
90
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wno-unused-parameter" "-fno-strict-aliasing")
91 92 93 94 95

		CHECK_CXX_COMPILER_FLAG("-Wsuggest-override" SUGGEST_OVERRIDE)
		if(SUGGEST_OVERRIDE)
			list(APPEND STRICT_OPTIONS_CPP "-Wsuggest-override -Werror=suggest-override")
		endif()
96 97 98 99 100 101 102 103 104
	endif()
endif()
if(STRICT_OPTIONS_CPP)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
endif()
if(STRICT_OPTIONS_C)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()

105 106 107 108 109
set(BELR_CPPFLAGS ${BCTOOLBOX_CPPFLAGS})
if(ENABLE_STATIC)
	list(APPEND BELR_CPPFLAGS "-DBELR_STATIC")
endif()
if(BELR_CPPFLAGS)
Ghislain MARY's avatar
Ghislain MARY committed
110
	list(REMOVE_DUPLICATES BELR_CPPFLAGS)
111 112 113 114
	add_definitions(${BELR_CPPFLAGS})
endif()
add_definitions("-DBELR_EXPORTS")

Sylvain Berfini's avatar
Sylvain Berfini committed
115 116 117 118 119 120
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "belr")
endif()

121 122 123 124 125
set(BELR_GRAMMARS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/belr/grammars")
set(BELR_GRAMMARS_RELATIVE_DIR "${CMAKE_INSTALL_DATADIR}/belr/grammars")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)

126
add_subdirectory(include)
Sylvain Berfini's avatar
Sylvain Berfini committed
127
add_subdirectory(src)
Simon Morlat's avatar
Simon Morlat committed
128 129 130
if(ENABLE_UNIT_TESTS AND BCTOOLBOX_TESTER_FOUND)
	add_subdirectory(tester)
endif()
131 132 133
if(ENABLE_TOOLS)
	add_subdirectory(tools)
endif()
Sylvain Berfini's avatar
Sylvain Berfini committed
134 135 136 137 138

include(CMakePackageConfigHelpers)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BelrTargets.cmake"
)
139 140 141
configure_file(cmake/BelrConfig.cmake.in
	"${CMAKE_CURRENT_BINARY_DIR}/BelrConfig.cmake"
	@ONLY
Sylvain Berfini's avatar
Sylvain Berfini committed
142
)
143
set(ConfigPackageLocation share/Belr/cmake)
Sylvain Berfini's avatar
Sylvain Berfini committed
144 145 146 147 148
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE BelrTargets.cmake
	DESTINATION ${ConfigPackageLocation}
)
install(FILES
149 150
	"${CMAKE_CURRENT_BINARY_DIR}/BelrConfig.cmake"
	DESTINATION ${ConfigPackageLocation}
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
151
)
152

jehan's avatar
jehan committed
153
add_subdirectory(build)