CMakeLists.txt 5.02 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
#
############################################################################

cmake_minimum_required(VERSION 3.0)
Ronan's avatar
Ronan committed
25
project(BELCARD VERSION 1.0.2 LANGUAGES C CXX)
26 27 28

set(BELCARD_SO_VERSION "1")

29 30
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
31
option(ENABLE_STRICT "Build with strict compile options." YES)
32
option(ENABLE_TOOLS "Enable compilation of tools." YES)
33 34 35 36 37
option(ENABLE_UNIT_TESTS "Enable compilation of unit tests." YES)


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

38 39 40 41 42
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()

43
include(GNUInstallDirs)
44 45 46 47 48 49
include(CheckSymbolExists)
include(CMakePushCheckState)

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

50 51 52 53 54
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	include("${EP_belr_CONFIG_DIR}/BelrConfig.cmake")
else()
	find_package(Belr REQUIRED)
endif()
55

56 57 58 59
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(BcToolbox_FIND_COMPONENTS tester)
	include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
60
	find_package(BcToolbox 0.0.3 REQUIRED OPTIONAL_COMPONENTS tester)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
endif()

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()

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
79
add_definitions("-DHAVE_CONFIG_H")
80

81 82 83
set(BELCARD_CPPFLAGS ${BCTOOLBOX_CPPFLAGS} ${BELR_CPPFLAGS})
if(ENABLE_STATIC)
	list(APPEND BELCARD_CPPFLAGS "-DBELCARD_STATIC")
84
endif()
85
if(BELCARD_CPPFLAGS)
Ghislain MARY's avatar
Ghislain MARY committed
86
	list(REMOVE_DUPLICATES BELCARD_CPPFLAGS)
87 88 89
	add_definitions(${BELCARD_CPPFLAGS})
endif()
add_definitions("-DBELCARD_EXPORTS")
90

91 92
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
93
set(STRICT_OPTIONS_CXX )
94
set(STRICT_OPTIONS_OBJC )
95 96
if(MSVC)
	if(ENABLE_STRICT)
Ghislain MARY's avatar
Ghislain MARY committed
97
		list(APPEND STRICT_OPTIONS_CPP "/WX")
98 99
	endif()
else()
François Grisez's avatar
François Grisez committed
100
	list(APPEND STRICT_OPTIONS_CXX "-std=c++11")
101 102
	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")
103
	if(CMAKE_C_COMPILER_ID MATCHES "Clang")
104 105 106 107
		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")
108
		list(APPEND STRICT_OPTIONS_CXX "-stdlib=libc++")
109 110
	endif()
	if(ENABLE_STRICT)
111
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wno-unused-parameter" "-fno-strict-aliasing")
112 113 114 115 116 117 118 119 120
	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
121 122 123 124 125 126
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "belcard")
endif()

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

include(CMakePackageConfigHelpers)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BelcardTargets.cmake"
)
140 141 142
configure_file(cmake/BelcardConfig.cmake.in
	"${CMAKE_CURRENT_BINARY_DIR}/BelcardConfig.cmake"
	@ONLY
Sylvain Berfini's avatar
Sylvain Berfini committed
143
)
144
set(ConfigPackageLocation share/Belcard/cmake)
Sylvain Berfini's avatar
Sylvain Berfini committed
145 146 147 148 149
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE BelcardTargets.cmake
	DESTINATION ${ConfigPackageLocation}
)
install(FILES
150 151
	"${CMAKE_CURRENT_BINARY_DIR}/BelcardConfig.cmake"
	DESTINATION ${ConfigPackageLocation}
152
)
153 154


jehan's avatar
jehan committed
155
add_subdirectory(build)