CMakeLists.txt 5.37 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)
25
project(BELCARD VERSION 1.0.1 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
endif()

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

include_directories(
	include/
	src/
	${BELR_INCLUDE_DIRS}
72
	${BCTOOLBOX_INCLUDE_DIRS}
73 74 75 76 77 78 79 80
	${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
81
add_definitions("-DHAVE_CONFIG_H")
82

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

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

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

include(CMakePackageConfigHelpers)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BelcardTargets.cmake"
)
142 143 144
configure_file(cmake/BelcardConfig.cmake.in
	"${CMAKE_CURRENT_BINARY_DIR}/BelcardConfig.cmake"
	@ONLY
Sylvain Berfini's avatar
Sylvain Berfini committed
145
)
146
set(ConfigPackageLocation share/Belcard/cmake)
Sylvain Berfini's avatar
Sylvain Berfini committed
147 148 149 150 151
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE BelcardTargets.cmake
	DESTINATION ${ConfigPackageLocation}
)
install(FILES
152 153
	"${CMAKE_CURRENT_BINARY_DIR}/BelcardConfig.cmake"
	DESTINATION ${ConfigPackageLocation}
154
)
155 156 157 158 159 160 161 162 163 164 165 166 167


# CPack settings
set(CPACK_PACKAGE_NAME "belcard")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_SOURCE_IGNORE_FILES
        "^${CMAKE_BINARY_DIR}"
        "/\\\\..+"
)

include(CPack)