CMakeLists.txt 7.35 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)
Ronan's avatar
Ronan committed
24
project(oRTP VERSION 1.0.2)
25

26

27 28 29 30
set(ORTP_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
set(ORTP_MINOR_VERSION ${PROJECT_VERSION_MINOR})
set(ORTP_MICRO_VERSION ${PROJECT_VERSION_PATCH})
set(ORTP_VERSION ${PROJECT_VERSION})
31
set(ORTP_SO_VERSION "13") # incremented on January 10, 2017
32 33


34 35
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
36
option(ENABLE_DOC "Enable documentation generation with Doxygen." YES)
37 38
option(ENABLE_NTP_TIMESTAMP "Turn on NTP timestamping on packet reception." NO)
option(ENABLE_PERF "Disable costly features to reduce cpu consumtion and increase performance." NO)
39
option(ENABLE_STRICT "Build with strict compile options." YES)
40
option(ENABLE_TESTS "Enable compilation of test programs." NO)
41
option(ENABLE_DEBUG_LOGS "Turn on or off debug level logs." NO)
42
set(WITH_THREAD_STACK_SIZE "0" CACHE STRING "Set thread stack size (0 is the OS default).")
43 44 45 46


include(CheckIncludeFile)
include(CheckFunctionExists)
47
include(GNUInstallDirs)
48
include(CheckCSourceCompiles)
jehan's avatar
jehan committed
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

55
set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
56
if(MSVC)
57
	list(APPEND CMAKE_REQUIRED_INCLUDES "${MSVC_INCLUDE_DIR}")
58 59 60
endif()

find_package(Threads)
61
find_library(LIBM NAMES m)
62

63 64 65
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
66
	find_package(BcToolbox 0.2.0 REQUIRED)
67 68
endif()

69 70
check_include_file(sys/uio.h HAVE_SYS_UIO_H)
check_include_file(sys/audio.h HAVE_SYS_AUDIO_H)
71 72 73
if(NOT ANDROID)
	check_include_file(sys/shm.h HAVE_SYS_SHM_H)
endif()
74 75 76 77 78 79 80 81 82
check_c_source_compiles("#include <stdatomic.h>
int main(int argc, char *argv[]) {
atomic_int currrent_ref;
atomic_init(&currrent_ref, 1);
atomic_int previous_ref = atomic_fetch_sub_explicit(&currrent_ref, 1, memory_order_release);
return 0;
}"
        HAVE_STDATOMIC_H)

83
check_function_exists(arc4random HAVE_ARC4RANDOM)
84 85
check_symbol_exists(recvmsg "sys/socket.h" HAVE_RECVMSG)
check_symbol_exists(sendmsg "sys/socket.h" HAVE_SENDMSG)
86 87 88 89 90 91

include(TestBigEndian)
test_big_endian(WORDS_BIGENDIAN)
if(WORDS_BIGENDIAN)
	set(ORTP_BIGENDIAN 1)
endif()
92

93

94 95 96
include_directories(
	include/
	src/
97
	${CMAKE_CURRENT_BINARY_DIR}
98
)
99
if(MSVC)
100
	include_directories(${MSVC_INCLUDE_DIR})
101 102 103
endif()


104
set(ORTP_CPPFLAGS ${BCTOOLBOX_CPPFLAGS})
105
if(ENABLE_STATIC)
106
	list(APPEND ORTP_CPPFLAGS "-DORTP_STATIC")
107
endif()
108 109 110 111 112
if(ENABLE_PERF)
	set(PERF 1)
endif()
if(ENABLE_NTP_TIMESTAMP)
	set(ORTP_TIMESTAMP 1)
113
	list(APPEND ORTP_CPPFLAGS "-DORTP_TIMESTAMP")
114
endif()
115
if(ENABLE_DEBUG_LOGS)
116 117 118 119 120
	set(ORTP_DEBUG_MODE 1)
endif()
if(CMAKE_USE_PTHREADS_INIT)
	set(ORTP_DEFAULT_THREAD_STACK_SIZE ${WITH_THREAD_STACK_SIZE})
endif()
121
if(APPLE)
Ghislain MARY's avatar
Ghislain MARY committed
122
	set(__APPLE_USE_RFC_3542 1)
123
endif()
124 125 126
if(ORTP_CPPFLAGS)
	add_definitions(${ORTP_CPPFLAGS})
endif()
127
set(POSIXTIMER_INTERVAL 10000)
128
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ortp-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/ortp-config.h)
129
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/ortp-config.h PROPERTIES GENERATED ON)
130
add_definitions(-DHAVE_CONFIG_H)
131 132 133

set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
134 135 136 137 138
if(MSVC)
	if(ENABLE_STRICT)
		list(APPEND STRICT_OPTIONS_CPP "/WX")
	endif()
else()
139
	list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized")
140
	list(APPEND STRICT_OPTIONS_C "-Wdeclaration-after-statement" "-Wstrict-prototypes" "-Wno-error=strict-prototypes")
141
	if(CMAKE_C_COMPILER_ID MATCHES "Clang")
142
		list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments" "-Wno-array-bounds")
143 144
	endif()
	if(APPLE)
145
		list(APPEND STRICT_OPTIONS_CPP "-Wno-error=unknown-warning-option" "-Qunused-arguments" "-Wno-tautological-compare" "-Wno-unused-function" "-Wno-array-bounds")
146 147
	endif()
	if(ENABLE_STRICT)
148
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wno-unused-parameter" "-Wno-missing-field-initializers" "-fno-strict-aliasing")
149 150
	endif()
endif()
151 152 153 154 155 156
if(STRICT_OPTIONS_CPP)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
endif()
if(STRICT_OPTIONS_C)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()
157

158 159 160 161 162 163 164 165

if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "ORTP")
endif()


166 167
add_subdirectory(include)
add_subdirectory(src)
168

169

170 171 172 173 174 175 176 177 178 179 180 181 182 183
if(ENABLE_DOC)
	find_package(Doxygen)
	if(DOXYGEN_FOUND)
		set(srcdir ${CMAKE_CURRENT_SOURCE_DIR})
		configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ortp.doxygen.in ${CMAKE_CURRENT_BINARY_DIR}/ortp.doxygen)
		file(GLOB DOC_INPUT_FILES
			include/ortp/[^.]*.h
			src/[^.]*.h
			src/[^.]*.c
		)
		add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/doc/html/index.html"
			COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/ortp.doxygen
			DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ortp.doxygen ${DOC_INPUT_FILES}
		)
184
		add_custom_target(ortp-html-doc ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/doc/html/index.html")
185
		install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doc/html"
jehan's avatar
jehan committed
186
			DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/ortp-${ORTP_VERSION}")
187
	endif()
188
endif()
189 190 191 192 193 194 195 196 197 198 199 200




set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${prefix}/bin)
set(libdir ${prefix}/lib)
set(includedir ${prefix}/include)
set(ORTP_PKGCONFIG_VERSION "${ORTP_VERSION}")
set(ORTPDEPS_LIBS )

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ortp.pc.in ${CMAKE_CURRENT_BINARY_DIR}/ortp.pc)
201
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ortp.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
202

203 204 205 206

add_subdirectory(build)


207 208 209 210 211 212
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	"${CMAKE_CURRENT_BINARY_DIR}/ORTPConfigVersion.cmake"
	VERSION ${ORTP_VERSION}
	COMPATIBILITY AnyNewerVersion
)
213
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
214 215
	FILE "${CMAKE_CURRENT_BINARY_DIR}/ORTPTargets.cmake"
)
216
configure_file(ORTPConfig.cmake.in
217
	"${CMAKE_CURRENT_BINARY_DIR}/ORTPConfig.cmake"
218
	@ONLY
219 220
)

221
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
222
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
223
	FILE ORTPTargets.cmake
224
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
225 226
)
install(FILES
227
	"${CMAKE_CURRENT_BINARY_DIR}/ORTPConfig.cmake"
228
	"${CMAKE_CURRENT_BINARY_DIR}/ORTPConfigVersion.cmake"
229
	DESTINATION ${CONFIG_PACKAGE_LOCATION}
230
)
231
install(FILES 	"${CMAKE_CURRENT_SOURCE_DIR}/README.md" 
jehan's avatar
jehan committed
232 233 234 235
	"${CMAKE_CURRENT_SOURCE_DIR}/ChangeLog" 
	"${CMAKE_CURRENT_SOURCE_DIR}/COPYING" 
	"${CMAKE_CURRENT_SOURCE_DIR}/AUTHORS" 
	DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/ortp-${ORTP_VERSION}")
236 237