| 1 |
############################################################################ |
| 2 |
# Copyright (c) 2010-2023 Belledonne Communications SARL. |
| 3 |
# |
| 4 |
# This file is part of oRTP |
| 5 |
# (see https://gitlab.linphone.org/BC/public/ortp). |
| 6 |
# |
| 7 |
############################################################################ |
| 8 |
# |
| 9 |
# This program is free software: you can redistribute it and/or modify |
| 10 |
# it under the terms of the GNU Affero General Public License as |
| 11 |
# published by the Free Software Foundation, either version 3 of the |
| 12 |
# License, or (at your option) any later version. |
| 13 |
# |
| 14 |
# This program is distributed in the hope that it will be useful, |
| 15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
# GNU Affero General Public License for more details. |
| 18 |
# |
| 19 |
# You should have received a copy of the GNU Affero General Public License |
| 20 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
############################################################################ |
| 22 |
|
| 23 |
cmake_minimum_required(VERSION 3.22) |
| 24 |
|
| 25 |
project(Ortp VERSION 5.3.0) |
| 26 |
|
| 27 |
|
| 28 |
set(ORTP_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}) |
| 29 |
set(ORTP_MINOR_VERSION ${PROJECT_VERSION_MINOR}) |
| 30 |
set(ORTP_MICRO_VERSION ${PROJECT_VERSION_PATCH}) |
| 31 |
set(ORTP_VERSION ${PROJECT_VERSION}) |
| 32 |
set(ORTP_SO_VERSION "15") # incremented for 4.4.0 version. |
| 33 |
set(ORTP_DOC_VERSION "${ORTP_VERSION_MAJOR}.${ORTP_VERSION_MINOR}") |
| 34 |
|
| 35 |
|
| 36 |
option(ENABLE_DOC "Enable documentation generation with Doxygen." YES) |
| 37 |
option(ENABLE_NTP_TIMESTAMP "Turn on NTP timestamping on packet reception." NO) |
| 38 |
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_UNIT_TESTS "Enable compilation of unit tests." YES) |
| 42 |
option(ENABLE_DEBUG_LOGS "Turn on or off debug level logs." NO) |
| 43 |
option(ENABLE_PACKAGE_SOURCE "Create 'package_source' target for source archive making" OFF) |
| 44 |
set(WITH_THREAD_STACK_SIZE "0" CACHE STRING "Set thread stack size (0 is the OS default).") |
| 45 |
|
| 46 |
|
| 47 |
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") |
| 48 |
|
| 49 |
|
| 50 |
include(CheckIncludeFile) |
| 51 |
include(CheckFunctionExists) |
| 52 |
include(GNUInstallDirs) |
| 53 |
include(CheckCSourceCompiles) |
| 54 |
include(CheckCXXSourceCompiles) |
| 55 |
include(CheckSymbolExists) |
| 56 |
|
| 57 |
if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX) |
| 58 |
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) |
| 59 |
message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}") |
| 60 |
endif() |
| 61 |
|
| 62 |
find_package(Threads) |
| 63 |
find_library(LIBM NAMES m) |
| 64 |
|
| 65 |
find_package(BCToolbox 5.3.0 REQUIRED) |
| 66 |
|
| 67 |
check_include_file(sys/uio.h HAVE_SYS_UIO_H) |
| 68 |
check_include_file(sys/audio.h HAVE_SYS_AUDIO_H) |
| 69 |
if(NOT ANDROID) |
| 70 |
check_include_file(sys/shm.h HAVE_SYS_SHM_H) |
| 71 |
endif() |
| 72 |
|
| 73 |
set (CMAKE_CXX_STANDARD 17) |
| 74 |
|
| 75 |
set(CMAKE_CXX_FLAGS_BAK "${CMAKE_CXX_FLAGS}") |
| 76 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")# need this for check_cxx_source_compiles because CMAKE_CXX_STANDARD doesn't work. |
| 77 |
check_cxx_source_compiles("#include <atomic> |
| 78 |
using namespace std; |
| 79 |
int main(int argc, char *argv[]) { |
| 80 |
atomic_int current_ref; |
| 81 |
atomic_init(¤t_ref, 1); |
| 82 |
atomic_int previous_ref(atomic_fetch_sub_explicit(¤t_ref, 1, memory_order_release)); |
| 83 |
return 0; |
| 84 |
}" |
| 85 |
HAVE_ATOMIC) |
| 86 |
if(NOT HAVE_ATOMIC) |
| 87 |
message(FATAL_ERROR "Atomic(C++) libraries have not been found for ORTP.") |
| 88 |
endif() |
| 89 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BAK}") |
| 90 |
|
| 91 |
check_function_exists(arc4random HAVE_ARC4RANDOM) |
| 92 |
check_symbol_exists(recvmsg "sys/socket.h" HAVE_RECVMSG) |
| 93 |
check_symbol_exists(sendmsg "sys/socket.h" HAVE_SENDMSG) |
| 94 |
|
| 95 |
include(TestBigEndian) |
| 96 |
test_big_endian(WORDS_BIGENDIAN) |
| 97 |
if(WORDS_BIGENDIAN) |
| 98 |
set(ORTP_BIGENDIAN 1) |
| 99 |
endif() |
| 100 |
|
| 101 |
|
| 102 |
include_directories( |
| 103 |
include/ |
| 104 |
src/ |
| 105 |
${PROJECT_BINARY_DIR} |
| 106 |
) |
| 107 |
|
| 108 |
|
| 109 |
set(ORTP_CPPFLAGS) |
| 110 |
if(NOT BUILD_SHARED_LIBS) |
| 111 |
list(APPEND ORTP_CPPFLAGS "-DORTP_STATIC") |
| 112 |
endif() |
| 113 |
if(ENABLE_PERF) |
| 114 |
set(PERF 1) |
| 115 |
endif() |
| 116 |
if(ENABLE_NTP_TIMESTAMP) |
| 117 |
set(ORTP_TIMESTAMP 1) |
| 118 |
list(APPEND ORTP_CPPFLAGS "-DORTP_TIMESTAMP") |
| 119 |
endif() |
| 120 |
if(ENABLE_DEBUG_LOGS) |
| 121 |
set(ORTP_DEBUG_MODE 1) |
| 122 |
endif() |
| 123 |
if(CMAKE_USE_PTHREADS_INIT) |
| 124 |
set(ORTP_DEFAULT_THREAD_STACK_SIZE ${WITH_THREAD_STACK_SIZE}) |
| 125 |
endif() |
| 126 |
if(APPLE) |
| 127 |
set(__APPLE_USE_RFC_3542 1) |
| 128 |
endif() |
| 129 |
if(ORTP_CPPFLAGS) |
| 130 |
add_definitions(${ORTP_CPPFLAGS}) |
| 131 |
endif() |
| 132 |
set(POSIXTIMER_INTERVAL 10000) |
| 133 |
configure_file(${PROJECT_SOURCE_DIR}/ortp-config.h.cmake ${PROJECT_BINARY_DIR}/ortp-config.h) |
| 134 |
set_source_files_properties(${PROJECT_BINARY_DIR}/ortp-config.h PROPERTIES GENERATED ON) |
| 135 |
add_compile_definitions("HAVE_CONFIG_H") |
| 136 |
|
| 137 |
# Enable stdint.h limit macros on C++ files. (Windows only.) |
| 138 |
if(MSVC) |
| 139 |
add_compile_definitions("__STDC_LIMIT_MACROS") |
| 140 |
endif() |
| 141 |
|
| 142 |
set(STRICT_OPTIONS_CPP ) |
| 143 |
set(STRICT_OPTIONS_C ) |
| 144 |
if(MSVC) |
| 145 |
if(ENABLE_STRICT) |
| 146 |
list(APPEND STRICT_OPTIONS_CPP "/WX") |
| 147 |
endif() |
| 148 |
add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
| 149 |
else() |
| 150 |
list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized") |
| 151 |
list(APPEND STRICT_OPTIONS_C "-Wdeclaration-after-statement" "-Wstrict-prototypes" "-Wno-error=strict-prototypes") |
| 152 |
if(CMAKE_C_COMPILER_ID MATCHES "Clang") |
| 153 |
list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments" "-Wno-array-bounds") |
| 154 |
endif() |
| 155 |
if(APPLE) |
| 156 |
list(APPEND STRICT_OPTIONS_CPP "-Wno-error=unknown-warning-option" "-Qunused-arguments" "-Wno-tautological-compare" "-Wno-unused-function" "-Wno-array-bounds") |
| 157 |
endif() |
| 158 |
if(ENABLE_STRICT) |
| 159 |
list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wunused-parameter" "-Wno-missing-field-initializers" "-fno-strict-aliasing") |
| 160 |
endif() |
| 161 |
endif() |
| 162 |
if(STRICT_OPTIONS_CPP) |
| 163 |
list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP) |
| 164 |
endif() |
| 165 |
if(STRICT_OPTIONS_C) |
| 166 |
list(REMOVE_DUPLICATES STRICT_OPTIONS_C) |
| 167 |
endif() |
| 168 |
|
| 169 |
add_subdirectory(include) |
| 170 |
add_subdirectory(src) |
| 171 |
if(ENABLE_UNIT_TESTS AND NOT WIN32) |
| 172 |
add_subdirectory(tester) |
| 173 |
endif() |
| 174 |
|
| 175 |
if(ENABLE_DOC) |
| 176 |
find_package(Doxygen) |
| 177 |
if(DOXYGEN_FOUND) |
| 178 |
set(DOXYGEN_INPUT "") |
| 179 |
file(GLOB DOC_INPUT_FILES |
| 180 |
"${PROJECT_SOURCE_DIR}/include/ortp/[^.]*.h" |
| 181 |
"${PROJECT_SOURCE_DIR}/src/[^.]*.h" |
| 182 |
"${PROJECT_SOURCE_DIR}/src/[^.]*.c" |
| 183 |
) |
| 184 |
foreach (INPUT_FILE ${DOC_INPUT_FILES}) |
| 185 |
string(CONCAT DOXYGEN_INPUT ${DOXYGEN_INPUT} " \"${INPUT_FILE}\"") |
| 186 |
endforeach () |
| 187 |
configure_file(${PROJECT_SOURCE_DIR}/ortp.doxygen.in ${PROJECT_BINARY_DIR}/ortp.doxygen) |
| 188 |
add_custom_command(OUTPUT "${PROJECT_BINARY_DIR}/doc/html/index.html" |
| 189 |
COMMAND "${DOXYGEN_EXECUTABLE}" "${PROJECT_BINARY_DIR}/ortp.doxygen" |
| 190 |
DEPENDS "${PROJECT_BINARY_DIR}/ortp.doxygen" ${DOC_INPUT_FILES} |
| 191 |
) |
| 192 |
add_custom_target(ortp-html-doc ALL DEPENDS "${PROJECT_BINARY_DIR}/doc/html/index.html") |
| 193 |
install(DIRECTORY "${PROJECT_BINARY_DIR}/doc/html" |
| 194 |
DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/ortp-${ORTP_VERSION}") |
| 195 |
endif() |
| 196 |
endif() |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
set(prefix ${CMAKE_INSTALL_PREFIX}) |
| 201 |
set(exec_prefix ${prefix}/bin) |
| 202 |
set(libdir ${prefix}/lib) |
| 203 |
set(includedir ${prefix}/include) |
| 204 |
set(ORTP_PKGCONFIG_VERSION "${ORTP_VERSION}") |
| 205 |
set(ORTPDEPS_LIBS ) |
| 206 |
|
| 207 |
configure_file(${PROJECT_SOURCE_DIR}/ortp.pc.in ${PROJECT_BINARY_DIR}/ortp.pc) |
| 208 |
install(FILES ${PROJECT_BINARY_DIR}/ortp.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 209 |
|
| 210 |
if (ENABLE_PACKAGE_SOURCE) |
| 211 |
add_subdirectory(build) |
| 212 |
endif() |
| 213 |
|
| 214 |
include(CMakePackageConfigHelpers) |
| 215 |
set(CMAKE_MODULES_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake") |
| 216 |
configure_package_config_file("cmake/${PROJECT_NAME}Config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" |
| 217 |
INSTALL_DESTINATION "${CMAKE_MODULES_INSTALL_DIR}" |
| 218 |
NO_SET_AND_CHECK_MACRO |
| 219 |
) |
| 220 |
write_basic_package_version_file("${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" |
| 221 |
VERSION ${PROJECT_VERSION} |
| 222 |
COMPATIBILITY AnyNewerVersion |
| 223 |
) |
| 224 |
install(FILES |
| 225 |
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" |
| 226 |
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" |
| 227 |
DESTINATION ${CMAKE_MODULES_INSTALL_DIR} |
| 228 |
) |
| 229 |
|
| 230 |
install(EXPORT ${PROJECT_NAME}Targets |
| 231 |
FILE "${PROJECT_NAME}Targets.cmake" |
| 232 |
DESTINATION ${CMAKE_MODULES_INSTALL_DIR} |
| 233 |
) |
| 234 |
|
| 235 |
install(FILES "${PROJECT_SOURCE_DIR}/README.md" |
| 236 |
"${PROJECT_SOURCE_DIR}/CHANGELOG.md" |
| 237 |
"${PROJECT_SOURCE_DIR}/LICENSE.txt" |
| 238 |
"${PROJECT_SOURCE_DIR}/AUTHORS.md" |
| 239 |
DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/ortp-${ORTP_VERSION}" |
| 240 |
) |