forked from node-webrtc/node-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
466 lines (396 loc) · 12.2 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0042 NEW)
macro(assign_bool var)
if (${ARGN})
set(${var} ON)
else()
set(${var} OFF)
endif()
endmacro()
assign_bool(use_custom_libcxx ${APPLE})
assign_bool(is_arm32 "y$ENV{TARGET_ARCH}" STREQUAL "yarm")
assign_bool(is_arm64 "y$ENV{TARGET_ARCH}" STREQUAL "yarm64")
if (APPLE AND ${is_arm64})
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE INTERNAL "" FORCE)
endif()
set(MODULE wrtc)
project(${MODULE})
include(ExternalProject)
find_package(Git REQUIRED)
find_package(Threads REQUIRED)
# depot_tools
# -----------------------------------------------------------------------------
ExternalProject_Add(
project_depot_tools
GIT_REPOSITORY https://chromium.googlesource.com/chromium/tools/depot_tools.git
GIT_TAG 495b23b39aaba2ca3b55dd27cadc523f1cb17ee6
PREFIX ${CMAKE_BINARY_DIR}/external/depot_tools/prefix
TMP_DIR ${CMAKE_BINARY_DIR}/external/depot_tools/tmp
STAMP_DIR ${CMAKE_BINARY_DIR}/external/depot_tools/stamp
DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/external/depot_tools/download
SOURCE_DIR ${CMAKE_BINARY_DIR}/external/depot_tools/src
BINARY_DIR ${CMAKE_BINARY_DIR}/external/depot_tools/build
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
ExternalProject_Get_Property(project_depot_tools SOURCE_DIR)
set(depot_tools_install_dir ${SOURCE_DIR})
# libc++
# -----------------------------------------------------------------------------
set(libwebrtc_binary_dir ${CMAKE_BINARY_DIR}/external/libwebrtc/build/${CMAKE_BUILD_TYPE})
set(libwebrtc_src_dir ${CMAKE_BINARY_DIR}/external/libwebrtc/download/src)
add_library(libc++ OBJECT IMPORTED)
add_dependencies(libc++ libwebrtc)
set(libc++_objects
algorithm.o
any.o
atomic.o
barrier.o
bind.o
charconv.o
chrono.o
condition_variable.o
condition_variable_destructor.o
debug.o
exception.o
functional.o
future.o
hash.o
ios.instantiations.o
ios.o
iostream.o
locale.o
memory.o
mutex.o
mutex_destructor.o
new.o
optional.o
random.o
random_shuffle.o
regex.o
shared_mutex.o
stdexcept.o
string.o
strstream.o
system_error.o
thread.o
typeinfo.o
utility.o
valarray.o
variant.o
vector.o
)
list(TRANSFORM libc++_objects PREPEND ${libwebrtc_binary_dir}/obj/buildtools/third_party/libc++/libc++/)
set_property(TARGET libc++ APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(libc++ PROPERTIES IMPORTED_OBJECTS_DEBUG "${libc++_objects}" IMPORTED_OBJECTS "${libc++_objects}")
# NOTE(mroberts): I would like this to be INTERFACE.
#
# https://gitlab.kitware.com/cmake/cmake/issues/15052
#
# target_include_directories(libc++ SYSTEM INTERFACE "${libc++_include_dir}")
# libc++abi
# -----------------------------------------------------------------------------
add_library(libc++abi OBJECT IMPORTED)
add_dependencies(libc++abi libwebrtc)
set(libc++abi_objects
abort_message.o
cxa_aux_runtime.o
cxa_default_handlers.o
cxa_demangle.o
cxa_exception.o
cxa_exception_storage.o
cxa_guard.o
cxa_handlers.o
cxa_personality.o
cxa_vector.o
cxa_virtual.o
fallback_malloc.o
private_typeinfo.o
stdlib_exception.o
stdlib_stdexcept.o
stdlib_typeinfo.o
)
list(TRANSFORM libc++abi_objects PREPEND ${libwebrtc_binary_dir}/obj/buildtools/third_party/libc++abi/libc++abi/)
set_property(TARGET libc++abi APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(libc++abi PROPERTIES IMPORTED_OBJECTS_DEBUG "${libc++abi_objects}" IMPORTED_OBJECTS "${libc++abi_objects}")
# NOTE(mroberts): I would like this to be INTERFACE.
#
# https://gitlab.kitware.com/cmake/cmake/issues/15052
#
# target_include_directories(libc++abi SYSTEM INTERFACE "${libc++abi_include_dir}")
# libwebrtc
# -----------------------------------------------------------------------------
# M87: branch-heads/4280
# M91: branch-heads/4472
# M92: branch-heads/4515
# M94: branch-heads/4606
# M98: branch-heads/4758
set(WEBRTC_REVISION branch-heads/4758)
list(APPEND GN_GEN_ARGS
rtc_build_examples=false
rtc_use_x11=false
rtc_enable_protobuf=false
rtc_include_pulse_audio=false
rtc_include_tests=false
use_lld=false
)
if (${use_custom_libcxx})
list(APPEND GN_GEN_ARGS
use_custom_libcxx=true
)
else()
list(APPEND GN_GEN_ARGS
use_custom_libcxx=false
)
endif()
if (${is_arm32})
list(APPEND GN_GEN_ARGS
target_cpu="arm"
rtc_build_tools=true
)
elseif (${is_arm64})
list(APPEND GN_GEN_ARGS
target_cpu="arm64"
rtc_build_tools=true
)
else()
list(APPEND GN_GEN_ARGS
rtc_build_tools=false
)
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND GN_GEN_ARGS is_debug=true)
else()
list(APPEND GN_GEN_ARGS is_debug=false)
endif()
string(REPLACE ";" " " GN_GEN_ARGS "${GN_GEN_ARGS}")
if(WIN32)
set(suffix bat)
set(PLATFORM windows)
else()
set(suffix sh)
if(APPLE)
set(PLATFORM darwin)
else()
set(PLATFORM linux)
endif()
endif()
if (WIN32)
set(byproducts
${libwebrtc_binary_dir}/obj/webrtc.lib
${libwebrtc_binary_dir}/obj/pc/peerconnection.lib
)
else()
set(byproducts
${libc++_objects}
${libc++abi_objects}
${libwebrtc_binary_dir}/obj/libwebrtc.a
${libwebrtc_binary_dir}/obj/pc/libpeerconnection.a
)
endif()
ExternalProject_Add(
project_libwebrtc
PREFIX ${CMAKE_BINARY_DIR}/external/libwebrtc/prefix
TMP_DIR ${CMAKE_BINARY_DIR}/external/libwebrtc/tmp
STAMP_DIR ${CMAKE_BINARY_DIR}/external/libwebrtc/stamp
DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/external/libwebrtc/download
SOURCE_DIR ${CMAKE_BINARY_DIR}/external/libwebrtc/download/src
BINARY_DIR ${CMAKE_BINARY_DIR}/external/libwebrtc/build/${CMAKE_BUILD_TYPE}
BUILD_BYPRODUCTS ${byproducts}
DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E env DEPOT_TOOLS=${depot_tools_install_dir} PLATFORM=${PLATFORM} WEBRTC_REVISION=${WEBRTC_REVISION} ${CMAKE_SOURCE_DIR}/scripts/download-webrtc.${suffix}
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env BINARY_DIR=<BINARY_DIR> DEPOT_TOOLS=${depot_tools_install_dir} GN_GEN_ARGS=${GN_GEN_ARGS} SOURCE_DIR=<SOURCE_DIR> ${CMAKE_SOURCE_DIR}/scripts/configure-webrtc.${suffix}
BUILD_COMMAND ${CMAKE_COMMAND} -E env CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} DEPOT_TOOLS=${depot_tools_install_dir} ${CMAKE_SOURCE_DIR}/scripts/build-webrtc.${suffix}
INSTALL_COMMAND ""
)
add_dependencies(project_libwebrtc project_depot_tools)
ExternalProject_Get_Property(project_libwebrtc DOWNLOAD_DIR)
set(libwebrtc_source_dir "${DOWNLOAD_DIR}")
ExternalProject_Get_Property(project_libwebrtc BINARY_DIR)
set(libwebrtc_binary_dir "${BINARY_DIR}")
add_library(libwebrtc STATIC IMPORTED)
add_dependencies(libwebrtc project_libwebrtc)
if(WIN32)
set_property(TARGET libwebrtc PROPERTY IMPORTED_LOCATION "${libwebrtc_binary_dir}/obj/webrtc.lib")
else()
set_property(TARGET libwebrtc PROPERTY IMPORTED_LOCATION "${libwebrtc_binary_dir}/obj/libwebrtc.a")
endif()
add_library(libpeerconnection STATIC IMPORTED)
add_dependencies(libpeerconnection project_libwebrtc)
if(WIN32)
set_property(TARGET libpeerconnection PROPERTY IMPORTED_LOCATION "${libwebrtc_binary_dir}/obj/pc/peerconnection.lib")
else()
set_property(TARGET libpeerconnection PROPERTY IMPORTED_LOCATION "${libwebrtc_binary_dir}/obj/pc/libpeerconnection.a")
endif()
set(libc++_include_dir
"${libwebrtc_source_dir}/src/buildtools/third_party/libc++/trunk/include"
"${libwebrtc_source_dir}/src/buildtools/third_party/libc++"
)
set(libc++abi_include_dir "${libwebrtc_source_dir}/src/buildtools/third_party/libc++abi/trunk/include")
# NOTE(mroberts): I would like this to be INTERFACE.
#
# https://gitlab.kitware.com/cmake/cmake/issues/15052
#
# target_include_directories(libwebrtc SYSTEM INTERFACE
# ${libwebrtc_source_dir}
# ${libwebrtc_source_dir}/webrtc
# ${libwebrtc_source_dir}/webrtc/third_party/abseil-cpp
# ${libwebrtc_source_dir}/webrtc/third_party/libyuv/include
# )
# catch2
# -----------------------------------------------------------------------------
ExternalProject_Add(
project_catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG a1cdff4f188170c5b0aa3d5d217b60d821f237df
PREFIX ${CMAKE_BINARY_DIR}/external/catch2/prefix
TMP_DIR ${CMAKE_BINARY_DIR}/external/catch2/tmp
STAMP_DIR ${CMAKE_BINARY_DIR}/external/catch2/stamp
DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/external/catch2/download
SOURCE_DIR ${CMAKE_BINARY_DIR}/external/catch2/src
BINARY_DIR ${CMAKE_BINARY_DIR}/external/catch2/build
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
ExternalProject_Get_Property(project_catch2 SOURCE_DIR)
set(catch2_install_dir ${SOURCE_DIR})
# node-webrtc
# -----------------------------------------------------------------------------
file(GLOB_RECURSE MODULE_SRC src/*.cc src/*.h)
add_library(${MODULE} SHARED ${MODULE_SRC} ${CMAKE_JS_SRC})
set_target_properties(${MODULE} PROPERTIES PREFIX "" SUFFIX ".node")
set_property(TARGET ${MODULE} PROPERTY CXX_STANDARD 17)
# NOTE(mroberts): Workaround for
#
# https://gitlab.kitware.com/cmake/cmake/issues/15052
#
# is to include all the header files here.
target_include_directories(${MODULE} SYSTEM PRIVATE
${CMAKE_JS_INC}
${CMAKE_SOURCE_DIR}/node_modules
${libwebrtc_source_dir}
${libwebrtc_source_dir}/webrtc
${libwebrtc_source_dir}/webrtc/third_party/abseil-cpp
${libwebrtc_source_dir}/webrtc/third_party/libyuv/include
)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_dependencies(${MODULE} project_catch2)
target_include_directories(${MODULE} SYSTEM PRIVATE
${catch2_install_dir}/single_include
)
endif()
target_include_directories(${MODULE} PRIVATE
${CMAKE_SOURCE_DIR}
)
target_link_libraries(${MODULE} PRIVATE
${CMAKE_THREAD_LIBS_INIT}
libpeerconnection
libwebrtc
${CMAKE_JS_LIB}
)
target_compile_definitions(${MODULE} PRIVATE
-DNAPI_VERSION=3
-DUSE_BUILTIN_SW_CODECS
)
if(WIN32)
set_property(TARGET ${MODULE}
PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
target_link_libraries(${MODULE} PRIVATE
dmoguids.lib
msdmo.lib
secur32.lib
winmm.lib
wmcodecdspuuid.lib
ws2_32.lib
)
target_compile_definitions(${MODULE} PRIVATE
-D_WINSOCKAPI_
-DINCL_EXTRA_HTON_FUNCTIONS
-DNOGDI
-DNOMINMAX
-DWEBRTC_WIN
"$<$<CONFIG:Debug>:-D_HAS_ITERATOR_DEBUGGING=0>"
)
else()
target_link_libraries(${MODULE} PRIVATE
-lc
-lm
)
target_compile_options(${MODULE} PRIVATE
-fno-rtti
-fvisibility=hidden
-Wall
-Wextra
-Wno-missing-field-initializers
-Wno-uninitialized
-Wno-unused-local-typedefs
-Wno-unused-variable
-Wpedantic
"$<$<CONFIG:Debug>:-g>"
)
target_compile_definitions(${MODULE} PRIVATE
-DWEBRTC_POSIX=1
"$<$<CONFIG:Debug>:-DDEBUG>"
)
if (${use_custom_libcxx})
# NOTE(mroberts): Workaround for
#
# https://gitlab.kitware.com/cmake/cmake/issues/15052
#
# is to include all the header files here.
target_include_directories(${MODULE} SYSTEM PRIVATE
${libc++_include_dir}
${libc++abi_include_dir}
)
# NOTE(mroberts): On Arm Linux and macOS, we statically link the same libc++ and
# libc++abi libraries that libwebrtc builds against.
target_link_libraries(${MODULE} PRIVATE
libc++
libc++abi
)
target_compile_options(${MODULE} PRIVATE
-nostdinc++
-nodefaultlibs
)
target_compile_definitions(${MODULE} PRIVATE
-D_LIBCPP_ABI_UNSTABLE
)
endif()
if (APPLE)
target_link_libraries(${MODULE} PRIVATE
"-framework AppKit"
"-framework AVFoundation"
)
target_compile_options(${MODULE} PRIVATE
-Weverything
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-documentation
-Wno-exit-time-destructors
-Wno-float-conversion
-Wno-global-constructors
-Wno-padded
-Wno-shadow
-Wno-shadow-field-in-constructor
-Wno-shorten-64-to-32
-Wno-sign-conversion
-Wno-thread-safety-negative
-Wno-unused-template
-Wno-weak-vtables
)
target_compile_definitions(${MODULE} PRIVATE
-DWEBRTC_MAC
-DWEBRTC_IOS
)
else()
target_compile_definitions(${MODULE} PRIVATE
-DWEBRTC_LINUX
)
target_compile_options(${MODULE} PRIVATE
-fpermissive
)
endif()
endif()