CMakeLists.txt 5.25 KB
Newer Older
1

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
############################################################################
# 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
20
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 22 23 24 25 26
#
############################################################################

cmake_minimum_required(VERSION 3.0)
project(BELCARD C CXX)

27
set(BELCARD_MAJOR_VERSION "1")
28
set(BELCARD_MINOR_VERSION "0")
29
set(BELCARD_MICRO_VERSION "0")
30 31 32
set(BELCARD_VERSION "${BELCARD_MAJOR_VERSION}.${BELCARD_MINOR_VERSION}.${BELCARD_MICRO_VERSION}")
set(BELCARD_SO_VERSION "1")

33 34
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
35
option(ENABLE_STRICT "Build with strict compile options." YES)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
option(ENABLE_UNIT_TESTS "Enable compilation of unit tests." YES)

macro(apply_compile_flags SOURCE_FILES)
	if(${SOURCE_FILES})
		set(options "")
		foreach(a ${ARGV})
			if(STRICT_OPTIONS_${a})
				string(REPLACE ";" " " options_${a} "${STRICT_OPTIONS_${a}}")
				set(options "${options} ${options_${a}}")
			endif()
		endforeach()
		if(options)
			set_source_files_properties(${${SOURCE_FILES}} PROPERTIES COMPILE_FLAGS "${options}")
		endif()
	endif()
endmacro()


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

56 57 58 59 60
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()

61
include(GNUInstallDirs)
62 63 64 65 66 67
include(CheckSymbolExists)
include(CMakePushCheckState)

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

68 69 70 71 72
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	include("${EP_belr_CONFIG_DIR}/BelrConfig.cmake")
else()
	find_package(Belr REQUIRED)
endif()
73

74 75 76 77
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(BcToolbox_FIND_COMPONENTS tester)
	include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
78
	find_package(BcToolbox 0.0.3 REQUIRED OPTIONAL_COMPONENTS tester)
79 80 81 82 83 84 85 86 87 88 89
endif()

if(UNIX AND NOT APPLE)
	include(CheckIncludeFiles)
	check_include_files(libudev.h HAVE_LIBUDEV_H)
endif()

include_directories(
	include/
	src/
	${BELR_INCLUDE_DIRS}
90
	${BCTOOLBOX_INCLUDE_DIRS}
91 92 93 94 95 96 97 98
	${CMAKE_CURRENT_BINARY_DIR}
)
if(MSVC)
	include_directories(${MSVC_INCLUDE_DIR})
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)
Sylvain Berfini's avatar
Sylvain Berfini committed
99
add_definitions("-DHAVE_CONFIG_H")
100 101 102

set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
103
set(STRICT_OPTIONS_CXX )
104
set(STRICT_OPTIONS_OBJC )
105 106
if(MSVC)
	if(ENABLE_STRICT)
Ghislain MARY's avatar
Ghislain MARY committed
107
		list(APPEND STRICT_OPTIONS_CPP "/WX")
108 109
	endif()
else()
François Grisez's avatar
François Grisez committed
110
	list(APPEND STRICT_OPTIONS_CXX "-std=c++11")
111 112 113 114 115 116 117
	list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized" "-Wno-error=deprecated-declarations")
	list(APPEND STRICT_OPTIONS_C "-Wdeclaration-after-statement" "-Wstrict-prototypes" "-Wno-error=strict-prototypes")
	if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
		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")
118
		list(APPEND STRICT_OPTIONS_CXX "-stdlib=libc++")
119 120
	endif()
	if(ENABLE_STRICT)
121
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wno-unused-parameter" "-fno-strict-aliasing")
122 123 124 125 126 127 128 129 130
	endif()
endif()
if(STRICT_OPTIONS_CPP)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
endif()
if(STRICT_OPTIONS_C)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()

Sylvain Berfini's avatar
Sylvain Berfini committed
131 132 133 134 135 136
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "belcard")
endif()

137 138
add_subdirectory(include)
add_subdirectory(src)
139 140
if(ENABLE_UNIT_TESTS AND BCTOOLBOX_TESTER_FOUND)
	add_subdirectory(tester)
Sylvain Berfini's avatar
Sylvain Berfini committed
141
endif()
142
add_subdirectory(tools)
Sylvain Berfini's avatar
Sylvain Berfini committed
143 144 145 146 147

include(CMakePackageConfigHelpers)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BelcardTargets.cmake"
)
148 149 150
configure_file(cmake/BelcardConfig.cmake.in
	"${CMAKE_CURRENT_BINARY_DIR}/BelcardConfig.cmake"
	@ONLY
Sylvain Berfini's avatar
Sylvain Berfini committed
151
)
152
set(ConfigPackageLocation share/Belcard/cmake)
Sylvain Berfini's avatar
Sylvain Berfini committed
153 154 155 156 157
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE BelcardTargets.cmake
	DESTINATION ${ConfigPackageLocation}
)
install(FILES
158 159
	"${CMAKE_CURRENT_BINARY_DIR}/BelcardConfig.cmake"
	DESTINATION ${ConfigPackageLocation}
160
)