-
Notifications
You must be signed in to change notification settings - Fork 77
/
CMakeLists.txt
384 lines (318 loc) · 13.6 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
cmake_minimum_required(VERSION 3.6.3)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
include(Utilities)
project(KinesisVideoProducerC VERSION 1.5.4 LANGUAGES C)
set(KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION 1)
set(KINESIS_VIDEO_PRODUCER_C_MINOR_VERSION 5)
set(KINESIS_VIDEO_PRODUCER_C_PATCH_VERSION 4)
set(KINESIS_VIDEO_PRODUCER_C_VERSION ${KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION}.${KINESIS_VIDEO_PRODUCER_C_MINOR_VERSION}.${KINESIS_VIDEO_PRODUCER_C_PATCH_VERSION})
include(GNUInstallDirs)
# User Flags
option(ADD_MUCLIBC "Add -muclibc c flag" OFF)
option(BUILD_STATIC "Static build" OFF)
option(BUILD_DEPENDENCIES "Whether or not to build depending libraries from source" ON)
option(USE_OPENSSL "Use openssl as crypto library" ON)
option(USE_MBEDTLS "Use mbedtls as crypto library" OFF)
option(BUILD_COMMON_LWS "Whether or not to build ProducerC libwebsockets common library" OFF)
option(BUILD_COMMON_CURL "Whether or not to build ProducerC curl common library" ON)
option(BUILD_OPENSSL_PLATFORM "If buildng OpenSSL what is the target platform" OFF)
option(LOCAL_OPENSSL_BUILD "Whether or not to use local OpenSSL build" OFF)
option(CONSTRAINED_DEVICE "Change pthread stack size" OFF)
# Developer Flags
option(BUILD_TEST "Build the testing tree." OFF)
option(CODE_COVERAGE "Enable coverage reporting" OFF)
option(COMPILER_WARNINGS "Enable all compiler warnings." OFF)
option(ADDRESS_SANITIZER "Build with AddressSanitizer." OFF)
option(MEMORY_SANITIZER "Build with MemorySanitizer." OFF)
option(THREAD_SANITIZER "Build with ThreadSanitizer." OFF)
option(UNDEFINED_BEHAVIOR_SANITIZER "Build with UndefinedBehaviorSanitizer." OFF)
option(ALIGNED_MEMORY_MODEL "Aligned memory model ONLY." OFF)
option(SET_SSL_CALLBACKS "Set SSL thread and lock callbacks." OFF)
set(TYPE_OF_LIB SHARED)
if (BUILD_STATIC)
set(TYPE_OF_LIB STATIC)
endif()
set(CMAKE_MACOSX_RPATH TRUE)
get_filename_component(ROOT "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
add_definitions(-DVERSION_STRING=\"${PROJECT_VERSION}\")
if(CONSTRAINED_DEVICE)
add_definitions(-DCONSTRAINED_DEVICE)
endif()
if(NOT KINESIS_VIDEO_PRODUCER_C_SRC)
if(DEFINED ENV{KINESIS_VIDEO_PRODUCER_C_SRC})
set(KINESIS_VIDEO_PRODUCER_C_SRC $ENV{KINESIS_VIDEO_PRODUCER_C_SRC})
else()
set(KINESIS_VIDEO_PRODUCER_C_SRC "${CMAKE_CURRENT_SOURCE_DIR}")
endif()
endif()
message(STATUS "Kinesis Video Producer path is ${KINESIS_VIDEO_PRODUCER_C_SRC}")
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting CMAKE_BUILD_TYPE to Release by default")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
if(BUILD_DEPENDENCIES)
if (NOT OPEN_SRC_INSTALL_PREFIX)
set(OPEN_SRC_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/open-source)
set(ENV{PKG_CONFIG_PATH}
"$ENV{PKG_CONFIG_PATH}:${OPEN_SRC_INSTALL_PREFIX}/lib/pkgconfig")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${OPEN_SRC_INSTALL_PREFIX})
endif()
if(NOT EXISTS ${OPEN_SRC_INSTALL_PREFIX})
file(MAKE_DIRECTORY ${OPEN_SRC_INSTALL_PREFIX})
endif()
message(STATUS "Begin building dependencies.")
set(SSL_OPTIONS USE_OPENSSL USE_MBEDTLS)
count_true(ENABLED_SSL_OPTION_COUNT
${SSL_OPTIONS})
if(ENABLED_SSL_OPTION_COUNT GREATER "1")
message(FATAL_ERROR "Only one of ${SSL_OPTIONS} can be enabled")
endif()
if(NOT LOCAL_OPENSSL_BUILD)
message(STATUS "Building non-local OpenSSL")
if(USE_OPENSSL)
set(BUILD_ARGS -DBUILD_STATIC=${BUILD_STATIC}
-DBUILD_OPENSSL_PLATFORM=${BUILD_OPENSSL_PLATFORM})
build_dependency(openssl ${BUILD_ARGS})
elseif(USE_MBEDTLS)
set(BUILD_ARGS -DBUILD_STATIC=${BUILD_STATIC} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
build_dependency(mbedtls ${BUILD_ARGS})
else()
message(FATAL_ERROR "No crypto library selected.")
endif()
endif()
if (BUILD_COMMON_LWS)
set(BUILD_ARGS -DBUILD_STATIC=${BUILD_STATIC}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DOPENSSL_DIR=${OPEN_SRC_INSTALL_PREFIX}
-DUSE_OPENSSL=${USE_OPENSSL}
-DUSE_MBEDTLS=${USE_MBEDTLS})
build_dependency(websockets ${BUILD_ARGS})
endif()
if (BUILD_COMMON_CURL)
set(BUILD_ARGS -DBUILD_STATIC=${BUILD_STATIC}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DUSE_OPENSSL=${USE_OPENSSL}
-DUSE_MBEDTLS=${USE_MBEDTLS})
build_dependency(curl ${BUILD_ARGS})
endif()
if(BUILD_TEST)
build_dependency(gtest)
endif()
message(STATUS "Finished building dependencies.")
endif()
find_package(PkgConfig REQUIRED)
############# Check system for kvspic #############
pkg_check_modules(KVSPIC libkvspicUtils)
if(KVSPIC_FOUND)
set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${KVSPIC_INCLUDE_DIRS})
link_directories(${KVSPIC_LIBRARY_DIRS})
else()
############# fetch repos that we need do add_subdirectory ############
# repos that we will build using add_subdirectory will be stored in this path
set(DEPENDENCY_DOWNLOAD_PATH ${CMAKE_CURRENT_SOURCE_DIR}/dependency)
set(BUILD_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
fetch_repo(kvspic ${BUILD_ARGS})
add_subdirectory("${DEPENDENCY_DOWNLOAD_PATH}/libkvspic/kvspic-src")
file(GLOB PIC_HEADERS "${pic_project_SOURCE_DIR}/src/*/include")
include_directories("${PIC_HEADERS}")
############# fetch repos that we need do add_subdirectory done ############
endif()
############# Check system for kvspic done #############
############# find dependent libraries ############
find_package(Threads)
set(OPEN_SRC_INCLUDE_DIRS ${LIBKVSPIC_INCLUDE_DIRS})
if(USE_OPENSSL)
find_package(OpenSSL)
if(NOT OPENSSL_FOUND AND NOT BUILD_DEPENDENCIES)
message(FATAL_ERROR "OpenSSL is not found. Make sure to export PKG_CONFIG_PATH to where OpenSSL's pc file is")
endif()
set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})
elseif(USE_MBEDTLS)
find_package(MbedTLS REQUIRED)
set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${MBEDTLS_INCLUDE_DIRS})
else()
message(FATAL_ERROR "No crypto library selected.")
endif()
if(BUILD_COMMON_CURL)
if (WIN32)
find_package(CURL REQUIRED)
set(CURL_LIBRARIES CURL::libcurl)
else()
pkg_check_modules(CURL REQUIRED libcurl)
endif()
set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS})
link_directories(${CURL_LIBRARY_DIRS})
endif()
if (BUILD_COMMON_LWS)
if (WIN32)
find_package(LIBWEBSOCKETS REQUIRED PATHS ${OPEN_SRC_INSTALL_PREFIX})
else()
pkg_check_modules(LIBWEBSOCKETS REQUIRED libwebsockets)
endif()
set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${LIBWEBSOCKETS_INCLUDE_DIRS})
link_directories(${LIBWEBSOCKETS_LIBRARY_DIRS})
endif()
############# find dependent libraries end ############
if(CMAKE_SIZEOF_VOID_P STREQUAL 4)
message(STATUS "Bitness 32 bits")
set(KINESIS_VIDEO_BUILD_BITNESS "x86")
set(KINESIS_VIDEO_BUILD_BITNESS_TYPE "Win32")
set(KINESIS_VIDEO_BUILD_BITNESS_NAME "x86")
elseif(CMAKE_SIZEOF_VOID_P STREQUAL 8)
message(STATUS "Bitness 64 bits")
set(KINESIS_VIDEO_BUILD_BITNESS "x64")
set(KINESIS_VIDEO_BUILD_BITNESS_TYPE "x64")
set(KINESIS_VIDEO_BUILD_BITNESS_NAME "x86_64")
else()
message(FATAL_ERROR "Unknown bitness")
endif()
if(${CMAKE_C_COMPILER_ID} MATCHES "GNU|Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
if(ADD_MUCLIBC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -muclibc")
endif()
if(CODE_COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()
function(enableSanitizer SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fsanitize=${SANITIZER} -fno-omit-frame-pointer" PARENT_SCOPE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fsanitize=${SANITIZER} -fno-omit-frame-pointer -fno-optimize-sibling-calls" PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${SANITIZER}" PARENT_SCOPE)
endfunction()
if(ADDRESS_SANITIZER)
enableSanitizer("address")
endif()
if(MEMORY_SANITIZER)
enableSanitizer("memory")
endif()
if(THREAD_SANITIZER)
enableSanitizer("thread")
endif()
if(UNDEFINED_BEHAVIOR_SANITIZER)
enableSanitizer("undefined")
endif()
endif()
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
endif()
file(GLOB KVS_COMMON_SOURCE_FILES_BASE "src/source/Common/*.c")
file(GLOB KVS_COMMON_SOURCE_FILES_LWS "src/source/Common/Lws/*.c")
file(GLOB KVS_COMMON_SOURCE_FILES_CURL "src/source/Common/Curl/*.c")
file(GLOB PRODUCER_C_SOURCE_FILES "src/source/*.c")
include_directories(${KINESIS_VIDEO_PRODUCER_C_SRC}/src/include)
include_directories(${OPEN_SRC_INCLUDE_DIRS})
if(ALIGNED_MEMORY_MODEL)
add_definitions(-DALIGNED_MEMORY_MODEL)
endif()
if(SET_SSL_CALLBACKS)
add_definitions(-DSET_SSL_CALLBACKS)
endif()
# use openssl by default
set(CPRODUCER_COMMON_TLS_OPTION KVS_USE_OPENSSL)
set(PRODUCER_CRYPTO_LIBRARY
OpenSSL::Crypto
OpenSSL::SSL)
if (USE_MBEDTLS)
set(CPRODUCER_COMMON_TLS_OPTION KVS_USE_MBEDTLS)
set(PRODUCER_CRYPTO_LIBRARY
MbedTLS
MbedCrypto)
endif()
install(
DIRECTORY ${KINESIS_VIDEO_PRODUCER_C_SRC}/src/include
DESTINATION .)
if(BUILD_COMMON_LWS)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/libkvsCommonLws.pc.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonLws.pc" @ONLY)
if (WIN32)
add_library(kvsCommonLws STATIC ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_LWS})
else()
add_library(kvsCommonLws ${TYPE_OF_LIB} ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_LWS})
endif()
target_compile_definitions(kvsCommonLws PRIVATE KVS_BUILD_WITH_LWS ${CPRODUCER_COMMON_TLS_OPTION})
if(NOT BUILD_STATIC)
set_target_properties(kvsCommonLws PROPERTIES VERSION ${KINESIS_VIDEO_PRODUCER_C_VERSION} SOVERSION ${KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION})
endif()
target_link_libraries(kvsCommonLws
${PRODUCER_CRYPTO_LIBRARY}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
${LIBWEBSOCKETS_LIBRARIES}
kvspicUtils)
install(
TARGETS kvsCommonLws
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonLws.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
if(BUILD_COMMON_CURL)
# producer only uses curl right now
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/libkvsCommonCurl.pc.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonCurl.pc" @ONLY)
if(BUILD_STATIC)
# Curl will enable ZLIB as part of its build if it finds
# the package. We need to therefore link it for static builds.
find_package(ZLIB)
if(ZLIB_FOUND)
list(APPEND CURL_LIBRARIES z)
endif()
endif()
if (WIN32)
add_library(kvsCommonCurl STATIC ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_CURL})
else()
add_library(kvsCommonCurl ${TYPE_OF_LIB} ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_CURL})
endif()
target_compile_definitions(kvsCommonCurl PRIVATE KVS_BUILD_WITH_CURL ${CPRODUCER_COMMON_TLS_OPTION})
if(NOT BUILD_STATIC)
set_target_properties(kvsCommonCurl PROPERTIES VERSION ${KINESIS_VIDEO_PRODUCER_C_VERSION} SOVERSION ${KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION})
endif()
target_link_libraries(kvsCommonCurl
kvspicUtils
${CURL_LIBRARIES}
${PRODUCER_CRYPTO_LIBRARY})
install(
TARGETS kvsCommonCurl
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonCurl.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/libcproducer.pc.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libcproducer.pc" @ONLY)
if (WIN32)
add_library(cproducer STATIC ${PRODUCER_C_SOURCE_FILES})
else()
add_library(cproducer ${TYPE_OF_LIB} ${PRODUCER_C_SOURCE_FILES})
endif()
if(NOT BUILD_STATIC)
set_target_properties(cproducer PROPERTIES VERSION ${KINESIS_VIDEO_PRODUCER_C_VERSION} SOVERSION ${KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION})
endif()
target_link_libraries(cproducer PUBLIC kvsCommonCurl kvspic)
install(
TARGETS cproducer
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libcproducer.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
add_executable(kvsVideoOnlyRealtimeStreamingSample ${KINESIS_VIDEO_PRODUCER_C_SRC}/samples/KvsVideoOnlyRealtimeStreamingSample.c)
target_link_libraries(kvsVideoOnlyRealtimeStreamingSample cproducer)
add_executable(kvsVideoOnlyOfflineStreamingSample ${KINESIS_VIDEO_PRODUCER_C_SRC}/samples/KvsVideoOnlyOfflineStreamingSample.c)
target_link_libraries(kvsVideoOnlyOfflineStreamingSample cproducer)
add_executable(kvsAudioVideoStreamingSample ${KINESIS_VIDEO_PRODUCER_C_SRC}/samples/KvsAudioVideoStreamingSample.c)
target_link_libraries(kvsAudioVideoStreamingSample cproducer)
add_executable(kvsAudioOnlyStreamingSample ${KINESIS_VIDEO_PRODUCER_C_SRC}/samples/KvsAudioOnlyStreamingSample.c)
target_link_libraries(kvsAudioOnlyStreamingSample cproducer)
if (BUILD_TEST)
add_subdirectory(tst)
endif()
endif()