CMakeLists.txt 4.39 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) 2014  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)
24 25

project(bzrtp VERSION 1.0.4 LANGUAGES C CXX)
26 27


28 29
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
30
option(ENABLE_STRICT "Build with strict compile options." YES)
31
option(ENABLE_TESTS "Enable compilation of unit tests." NO)
32 33


34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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()


50 51 52 53 54
if(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()

55
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Ghislain MARY's avatar
Ghislain MARY committed
56

57
set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
Ghislain MARY's avatar
Ghislain MARY committed
58
if(MSVC)
59
	list(APPEND CMAKE_REQUIRED_INCLUDES ${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
60 61
endif()

62
include(GNUInstallDirs)
63 64
include(CheckLibraryExists)
check_library_exists("m" "sqrt" "" HAVE_SQRT)
johan's avatar
johan committed
65

66
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
67
	set(BcToolbox_FIND_COMPONENTS tester)
68 69
	include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
70
	find_package(BcToolbox 0.0.3 REQUIRED OPTIONAL_COMPONENTS tester)
71
endif()
johan's avatar
johan committed
72

73 74 75 76 77 78 79 80 81 82
find_package(XML2)

if(XML2_FOUND)
	set(HAVE_LIBXML2 1)
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)
add_definitions("-DHAVE_CONFIG_H")

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
set(STRICT_OPTIONS_CPP )
if(NOT MSVC)
	list(APPEND STRICT_OPTIONS_CPP "-Wall")
	if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
		list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments")
	endif()
	if(ENABLE_STRICT)
		list(APPEND STRICT_OPTIONS_CPP "-Werror")
	endif()
endif()
if(STRICT_OPTIONS_CPP)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
	string(REPLACE ";" " " STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP}")
endif()

98 99 100
include_directories(
	include
	${CMAKE_CURRENT_BINARY_DIR}
101
	${BCTOOLBOX_CORE_INCLUDE_DIRS}
102 103
)

104
set(LIBS ${BCTOOLBOX_CORE_LIBRARIES})
105

Ghislain MARY's avatar
Ghislain MARY committed
106 107 108 109 110
if(XML2_FOUND)
	include_directories(${XML2_INCLUDE_DIRS})
	list(APPEND LIBS ${XML2_LIBRARIES})
endif()
if(MSVC)
111
	include_directories(${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
112
endif()
113 114


115 116 117 118 119 120 121
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "BZRTP")
endif()


122 123
add_subdirectory(include)
add_subdirectory(src)
124
if(ENABLE_TESTS AND BCTOOLBOX_TESTER_FOUND)
125 126 127
	enable_testing()
	add_subdirectory(test)
endif()
128

129 130 131 132

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
133
	VERSION ${PROJECT_VERSION}
134 135
	COMPATIBILITY AnyNewerVersion
)
136
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
137 138
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BZRTPTargets.cmake"
)
139
configure_file(cmake/BZRTPConfig.cmake.in
140
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake"
141
	@ONLY
142 143
)

144
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
145
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
146
	FILE BZRTPTargets.cmake
147
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
148 149 150 151
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
152
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
153
)