CMakeLists.txt 3.59 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 C)
François Grisez's avatar
François Grisez committed
25
set(BZRTP_VERSION 1.0.2)
26 27


28
option(ENABLE_STATIC "Build static library (default is shared library)." NO)
29
option(ENABLE_TESTS "Enable compilation of unit tests." NO)
30 31


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

34
set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
Ghislain MARY's avatar
Ghislain MARY committed
35
if(MSVC)
36
	list(APPEND CMAKE_REQUIRED_INCLUDES ${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
37 38
endif()

39 40
include(CheckLibraryExists)
check_library_exists("m" "sqrt" "" HAVE_SQRT)
41
if(ENABLE_TESTS)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
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()
find_package(PolarSSL REQUIRED)
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")


include_directories(
	include
	${CMAKE_CURRENT_BINARY_DIR}
Ghislain MARY's avatar
Ghislain MARY committed
67
	${POLARSSL_INCLUDE_DIRS}
68 69
)

Ghislain MARY's avatar
Ghislain MARY committed
70 71 72 73 74 75 76 77 78 79
set(LIBS ${POLARSSL_LIBRARIES})
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)
80
	include_directories(${MSVC_INCLUDE_DIR})
Ghislain MARY's avatar
Ghislain MARY committed
81
endif()
82 83


84 85 86 87 88 89 90
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "BZRTP")
endif()


91 92
add_subdirectory(include)
add_subdirectory(src)
93
if(ENABLE_TESTS)
94 95 96
	enable_testing()
	add_subdirectory(test)
endif()
97

98 99 100 101 102 103 104

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
	VERSION ${BZRTP_VERSION}
	COMPATIBILITY AnyNewerVersion
)
105
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
106 107 108 109 110 111 112 113
	FILE "${CMAKE_CURRENT_BINARY_DIR}/BZRTPTargets.cmake"
)
configure_file(cmake/BZRTPConfig.cmake
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake"
	COPYONLY
)

set(ConfigPackageLocation lib/cmake/BZRTP)
114
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
115 116 117 118 119 120 121
	FILE BZRTPTargets.cmake
	DESTINATION ${ConfigPackageLocation}
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfig.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/BZRTPConfigVersion.cmake"
	DESTINATION ${ConfigPackageLocation}
122
)
123