This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
forked from ultravideo/uvgRTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
271 lines (235 loc) · 8.09 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
cmake_minimum_required(VERSION 3.14)
#
# Project Configuration
#
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
include(cmake/ProjectDetails.cmake)
project(uvgrtp
VERSION ${uvgrtp_VER}
DESCRIPTION ${uvgrtp_DESCR}
HOMEPAGE_URL ${uvgrtp_URL}
LANGUAGES CXX)
include(cmake/FindDependencies.cmake)
include(cmake/Versioning.cmake)
option(DISABLE_CRYPTO "Do not build uvgRTP with crypto enabled" OFF)
add_library(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES
SOVERSION "${PROJECT_VERSION_MAJOR}"
VERSION "${LIBRARY_VERSION}"
)
set(UVGRTP_CXX_FLAGS "")
set(UVGRTP_LINKER_FLAGS "")
target_sources(${PROJECT_NAME} PRIVATE
src/clock.cc
src/crypto.cc
src/frame.cc
src/hostname.cc
src/context.cc
src/media_stream.cc
src/mingw_inet.cc
src/reception_flow.cc
src/poll.cc
src/frame_queue.cc
src/random.cc
src/rtcp.cc
src/rtcp_packets.cc
src/rtp.cc
src/session.cc
src/socket.cc
src/zrtp.cc
src/holepuncher.cc
src/formats/media.cc
src/formats/h26x.cc
src/formats/h264.cc
src/formats/h265.cc
src/formats/h266.cc
src/zrtp/zrtp_receiver.cc
src/zrtp/hello.cc
src/zrtp/hello_ack.cc
src/zrtp/commit.cc
src/zrtp/dh_kxchng.cc
src/zrtp/confirm.cc
src/zrtp/confack.cc
src/zrtp/error.cc
src/zrtp/zrtp_message.cc
src/srtp/base.cc
src/srtp/srtp.cc
src/srtp/srtcp.cc
src/wrapper_c.cc
)
source_group(src/srtp src/srtp/.*)
source_group(src/formats src/formats/.*)
source_group(src/zrtp src/zrtp/.*)
source_group(src src/.*)
source_group(include include/.*)
# Including header files so VisualStudio will list them correctly
target_sources(${PROJECT_NAME} PRIVATE
src/random.hh
src/holepuncher.hh
src/hostname.hh
src/mingw_inet.hh
src/reception_flow.hh
src/poll.hh
src/rtp.hh
src/rtcp_packets.hh
src/zrtp.hh
src/frame_queue.hh
src/formats/h26x.hh
src/formats/h264.hh
src/formats/h265.hh
src/formats/h266.hh
src/formats/media.hh
src/srtp/base.hh
src/srtp/srtcp.hh
src/srtp/srtp.hh
src/zrtp/zrtp_receiver.hh
src/zrtp/hello.hh
src/zrtp/hello_ack.hh
src/zrtp/commit.hh
src/zrtp/dh_kxchng.hh
src/zrtp/defines.hh
src/zrtp/confirm.hh
src/zrtp/confack.hh
src/zrtp/error.hh
src/zrtp/zrtp_message.hh
src/srtp/base.hh
src/srtp/srtp.hh
src/srtp/srtcp.hh
include/uvgrtp/util.hh
include/uvgrtp/clock.hh
include/uvgrtp/context.hh
include/uvgrtp/crypto.hh
include/uvgrtp/debug.hh
include/uvgrtp/frame.hh
include/uvgrtp/lib.hh
include/uvgrtp/media_stream.hh
include/uvgrtp/rtcp.hh
include/uvgrtp/session.hh
include/uvgrtp/socket.hh
include/uvgrtp/wrapper_c.hh
)
if(WIN32)
set(WINLIBS wsock32 ws2_32)
endif()
target_link_libraries(${PROJECT_NAME}
PRIVATE
Threads::Threads
${PROJECT_NAME}_version
${WINLIBS}
)
target_include_directories(${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
PUBLIC $<INSTALL_INTERFACE:include>
)
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /Zc:__cplusplus /W4)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic #[[-Werror]])
endif()
if (DISABLE_CRYPTO)
list(APPEND UVGRTP_CXX_FLAGS "-D__RTP_NO_CRYPTO__")
target_compile_definitions(${PROJECT_NAME} PRIVATE __RTP_NO_CRYPTO__)
endif()
if (UNIX)
# Try finding if pkg-config installed in the system
find_package(PkgConfig REQUIRED)
if(PkgConfig_FOUND)
list(APPEND UVGRTP_LINKER_FLAGS "-luvgrtp")
if(CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_HAVE_LIBC_PTHREAD)
list(APPEND UVGRTP_LINKER_FLAGS "-lpthread")
endif()
# Check PKG_CONFIG_PATH, if not defined, use /usr/local/lib/pkgconfig
if(NOT DEFINED ENV{PKG_CONFIG_PATH})
set(PKG_CONFIG_PATH "/usr/local/lib/pkgconfig")
message("PKG_CONFIG_PATH is not set. Setting it to ${PKG_CONFIG_PATH}")
endif(NOT DEFINED ENV{PKG_CONFIG_PATH})
# Find crypto++
if(NOT DISABLE_CRYPTO)
pkg_search_module(CRYPTOPP libcrypto++)
if(CRYPTOPP_FOUND)
list(APPEND UVGRTP_CXX_FLAGS ${CRYPTOPP_CFLAGS_OTHER})
list(APPEND UVGRTP_LINKER_FLAGS ${CRYPTOPP_LDFLAGS})
else()
message("libcrypto++ not found. Encryption will be disabled")
list(APPEND UVGRTP_CXX_FLAGS "-D__RTP_NO_CRYPTO__")
endif()
endif()
# Generate and install .pc file
string(REPLACE ";" " " UVGRTP_CXX_FLAGS "${UVGRTP_CXX_FLAGS}")
string(REPLACE ";" " " UVGRTP_LINKER_FLAGS "${UVGRTP_LINKER_FLAGS}")
configure_file("cmake/uvgrtp.pc.in" "uvgrtp.pc" @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/uvgrtp.pc DESTINATION ${PKG_CONFIG_PATH}/)
else()
message("pkg-config not found. Not generating pc file")
endif(PkgConfig_FOUND)
# Check the getrandom() function exists
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(getrandom sys/random.h HAVE_GETRANDOM)
if(HAVE_GETRANDOM)
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_GETRANDOM=1)
endif()
endif (UNIX)
add_subdirectory(test EXCLUDE_FROM_ALL)
#
# Install
#
# Define install target, install libraries and archives (static libraries) to "<prefix>/..."
include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_version EXPORT ${PROJECT_NAME}Targets
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT ${PROJECT_NAME}_Runtime
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT ${PROJECT_NAME}_Runtime
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT ${PROJECT_NAME}_Runtime)
#Copy all header files to the <prefix>/include/uvgrtp directory
file(GLOB DEPLOY_FILES_AND_DIRS "${CMAKE_SOURCE_DIR}/include/uvgrtp/*")
install(FILES ${DEPLOY_FILES_AND_DIRS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/
COMPONENT ${PROJECT_NAME}_Develop)
#Create a File representing the current library version
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)
#Create a Targets file representing exported targets (for usage within the build tree)
export(EXPORT ${PROJECT_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::
)
#Copy "cmake/uvgrtpConfig.cmake" to "${CMAKE_CURRENT_BINARY_DIR}/uvgrtp/uvgrtpConfig.cmake"
configure_file(cmake/${PROJECT_NAME}Config.cmake
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake"
COPYONLY
)
#Copy "cmake/uvgrtpMacros.cmake" to "${CMAKE_CURRENT_BINARY_DIR}/uvgrtp/uvgrtpMacros.cmake"
configure_file(cmake/${PROJECT_NAME}Macros.cmake
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Macros.cmake"
COPYONLY
)
#
# Adding target to installing cmake package
#
set(ConfigPackageLocation lib/cmake/${PROJECT_NAME})
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${ConfigPackageLocation}
)
install(FILES cmake/${PROJECT_NAME}Config.cmake cmake/${PROJECT_NAME}Macros.cmake
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
COMPONENT uvgRTPMain
)
#
# Packaging
#
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_subdirectory(packaging)
endif()