CMakeLists.txt 4.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
############################################################################
# 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
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
############################################################################

23
cmake_minimum_required(VERSION 3.0)
24
project(bzrtp VERSION 1.0.3 LANGUAGES C)
25 26


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


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


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

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

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

61
include(GNUInstallDirs)
62 63
include(CheckLibraryExists)
check_library_exists("m" "sqrt" "" HAVE_SQRT)
64
if(ENABLE_TESTS)
65 66 67 68 69 70 71 72 73 74
find_package(CUnit)
	if(CUNIT_FOUND)
		check_library_exists(${CUNIT_LIBRARIES} "CU_add_suite" "" HAVE_CU_ADD_SUITE)
		check_library_exists(${CUNIT_LIBRARIES} "CU_get_suite" "" HAVE_CU_GET_SUITE)
		check_library_exists(${CUNIT_LIBRARIES} "CU_curses_run_tests" "" HAVE_CU_CURSES)
	else()
		message(WARNING "Could not find cunit framework, tests will not be compiled.")
		set(ENABLE_TESTS OFF CACHE BOOL "Enable compilation of tests" FORCE)
	endif()
endif()
johan's avatar
johan committed
75

76 77 78
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
79
	find_package(BcToolbox REQUIRED)
80
endif()
johan's avatar
johan committed
81

82 83 84 85 86 87 88 89 90 91
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")

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
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()

107 108 109 110 111 112 113
include_directories(
	include
	${CMAKE_CURRENT_BINARY_DIR}
	${BCTOOLBOX_INCLUDE_DIRS}
)

set(LIBS ${BCTOOLBOX_LIBRARIES})
114

Ghislain MARY's avatar
Ghislain MARY committed
115 116 117 118 119 120 121 122 123
if(CUNIT_FOUND)
	include_directories(${CUNIT_INCLUDE_DIRS})
	list(APPEND LIBS ${CUNIT_LIBRARIES})
endif()
if(XML2_FOUND)
	include_directories(${XML2_INCLUDE_DIRS})
	list(APPEND LIBS ${XML2_LIBRARIES})
endif()
if(MSVC)
124
	include_directories(${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
125
endif()
126 127


128 129 130 131 132 133 134
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "BZRTP")
endif()


135 136
add_subdirectory(include)
add_subdirectory(src)
137
if(ENABLE_TESTS)
138 139 140
	enable_testing()
	add_subdirectory(test)
endif()
141

142 143 144 145

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
146
	VERSION ${PROJECT_VERSION}
147 148
	COMPATIBILITY AnyNewerVersion
)
149
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
150 151 152 153 154 155 156
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BZRTPTargets.cmake"
)
configure_file(cmake/BZRTPConfig.cmake
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake"
	COPYONLY
)

157
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
158
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
159
	FILE BZRTPTargets.cmake
160
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
161 162 163 164
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
165
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
166
)