forked from node-webrtc/node-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
578 lines (503 loc) · 16.3 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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
cmake_minimum_required(VERSION 3.12)
project(node-webrtc)
include(ExternalProject)
find_package(Git REQUIRED)
find_package(Threads REQUIRED)
find_program(iwyu_path OPTIONAL NAMES include-what-you-use iwyu)
find_program(clang_tidy_path OPTIONAL NAMES clang-tidy)
# depot_tools
# -----------------------------------------------------------------------------
ExternalProject_Add(
project_depot_tools
GIT_REPOSITORY https://chromium.googlesource.com/chromium/tools/depot_tools.git
GIT_TAG 650096367cd9900e499052c49179b33b68fa1ac9
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_unexpected.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
# -----------------------------------------------------------------------------
set(WEBRTC_REVISION branch-heads/4500)
list(APPEND GN_GEN_ARGS
rtc_build_examples=false
rtc_use_x11=false
rtc_enable_protobuf=false
rtc_use_gtk=false
rtc_include_pulse_audio=false
rtc_include_tests=false
)
if ("$ENV{TARGET_ARCH}" STREQUAL "arm")
list(APPEND GN_GEN_ARGS
target_os="linux"
target_cpu="arm"
rtc_build_tools=true
treat_warnings_as_errors=false
fatal_linker_warnings=false
)
elseif ("$ENV{TARGET_ARCH}" STREQUAL "arm64")
if(NOT APPLE)
list(APPEND GN_GEN_ARGS
target_os="linux"
)
endif()
list(APPEND GN_GEN_ARGS
target_cpu="arm64"
rtc_build_tools=true
treat_warnings_as_errors=false
fatal_linker_warnings=false
)
else()
list(APPEND GN_GEN_ARGS
rtc_build_tools=false
)
endif()
if (WIN32)
list(APPEND GN_GEN_ARGS is_clang=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}
${libwebrtc_binary_dir}/obj/libwebrtc.a
${libwebrtc_binary_dir}/obj/pc/libpeerconnection.a
)
if (NOT APPLE)
list(APPEND byproducts ${libc++abi_objects})
endif()
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")
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
# -----------------------------------------------------------------------------
set(MODULE wrtc)
include(${CMAKE_SOURCE_DIR}/NodeJS.cmake)
if(DEFINED ENV{npm_config_runtime})
if($ENV{npm_config_runtime} STREQUAL "electron")
if(NOT DEFINED ENV{npm_config_target})
message(FATAL_ERROR "npm_config_target must be defined for electron build")
endif()
list(APPEND nodejs_init_args "VERSION" v$ENV{npm_config_target})
if(NOT DEFINED ENV{npm_config_disturl})
message(FATAL_ERROR "npm_config_disturl must be defined for electron build")
endif()
list(APPEND nodejs_init_args "URL" $ENV{npm_config_disturl})
if($ENV{npm_config_target} STRLESS "4")
list(APPEND nodejs_init_args "NAME" "iojs")
endif()
endif()
endif()
nodejs_init(${nodejs_init_args})
file(GLOB_RECURSE MODULE_SRC src/*.cc src/*.h)
add_nodejs_module(${MODULE} ${MODULE_SRC})
set_property(TARGET ${MODULE} PROPERTY CXX_STANDARD 14)
if(NOT iwyu_path STREQUAL "iwyu_path-NOTFOUND")
set_property(TARGET ${MODULE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path} -Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/.iwyu.imp)
endif()
if(NOT clang_tidy_path STREQUAL "clang_tidy_path-NOTFOUND")
set_property(TARGET ${MODULE} PROPERTY CXX_CLANG_TIDY ${clang_tidy_path})
endif()
set(node_addon_api_dir ${CMAKE_SOURCE_DIR}/node_modules/node-addon-api)
# 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
${node_addon_api_dir}/..
${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
)
target_compile_definitions(${MODULE} PRIVATE
-DNAPI_VERSION=3
-DUSE_BUILTIN_SW_CODECS
)
if(WIN32)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /GR-")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /GR- -D_HAS_ITERATOR_DEBUGGING=0")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /FORCE:UNRESOLVED")
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
)
else()
# 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 Linux and macOS, we statically link the same libc++ and
# libc++abi libraries that libwebrtc builds against.
target_link_libraries(${MODULE} PRIVATE
-lc
-lm
libc++
)
if(NOT APPLE)
target_link_libraries(${MODULE} PRIVATE
libc++abi
)
endif()
target_compile_options(${MODULE} PRIVATE
-fno-rtti
-fvisibility=hidden
-nostdinc++
-nodefaultlibs
-Wall
-Wextra
-Wno-missing-field-initializers
-Wno-uninitialized
-Wno-unused-local-typedefs
-Wno-unused-variable
-Wno-suggest-override
-Wpedantic
)
if(APPLE) # actually should be if(clang), but there is no such flag
target_compile_options(${MODULE} PRIVATE
-Wno-missing-prototypes
)
endif()
target_compile_definitions(${MODULE} PRIVATE
-D_LIBCPP_ABI_UNSTABLE
-DWEBRTC_POSIX=1
)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${MODULE} PRIVATE
-g
)
target_compile_definitions(${MODULE} PRIVATE
-DDEBUG
)
endif()
if(APPLE)
target_link_libraries(${MODULE} PRIVATE
"-framework AppKit"
"-framework AVFoundation"
)
if ("$ENV{TARGET_ARCH}" STREQUAL "arm64")
target_compile_options(${MODULE} PRIVATE
-arch arm64
)
target_link_options(${MODULE} PRIVATE
-arch arm64
)
endif()
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
-D_LIBCPP_ABI_UNSTABLE
-DWEBRTC_MAC
-DWEBRTC_IOS
)
else()
target_compile_definitions(${MODULE} PRIVATE
-DWEBRTC_LINUX
)
target_compile_options(${MODULE} PRIVATE
-fpermissive
)
if ("$ENV{TARGET_ARCH}" STREQUAL "arm" OR "$ENV{TARGET_ARCH}" STREQUAL "arm64")
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR "$ENV{TARGET_ARCH}")
set(tools $ENV{ARM_TOOLS_PATH})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
if ("$ENV{TARGET_ARCH}" STREQUAL "arm")
set(CMAKE_SYSROOT ${libwebrtc_source_dir}/src/build/linux/debian_sid_arm-sysroot)
target_compile_options(${MODULE} PRIVATE
-march=armv7-a
-mfloat-abi=hard
-mtune=generic-armv7-a
-mfpu=neon
)
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)
else()
set(CMAKE_SYSROOT ${libwebrtc_source_dir}/src/build/linux/debian_sid_arm64-sysroot)
set(CMAKE_C_COMPILER ${tools}/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/aarch64-linux-gnu-g++)
endif()
else()
target_compile_options(${MODULE} PRIVATE
-B${libwebrtc_source_dir}/src/third_party/binutils/Linux_x64/Release/bin
--sysroot=${libwebrtc_source_dir}/src/build/linux/debian_sid_amd64-sysroot
)
endif()
endif()
endif()
# astyle
# -----------------------------------------------------------------------------
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND ASTYLE_CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}")
ExternalProject_Add(
astyle
GIT_REPOSITORY https://github.com/Bareflank/astyle.git
GIT_TAG v1.2
GIT_SHALLOW true
CMAKE_ARGS ${ASTYLE_CMAKE_ARGS}
PREFIX ${CMAKE_BINARY_DIR}/external/astyle/prefix
TMP_DIR ${CMAKE_BINARY_DIR}/external/astyle/tmp
STAMP_DIR ${CMAKE_BINARY_DIR}/external/astyle/stamp
DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/external/astyle/download
SOURCE_DIR ${CMAKE_BINARY_DIR}/external/astyle/src
BINARY_DIR ${CMAKE_BINARY_DIR}/external/astyle/build
)
list(APPEND ASTYLE_ARGS
--style=google
--lineend=linux
--suffix=none
--pad-oper
--unpad-paren
--align-pointer=type
--align-reference=type
--indent-preproc-define
--indent-switches
--indent-col1-comments
--keep-one-line-statements
--keep-one-line-blocks
--pad-header
--convert-tabs
--min-conditional-indent=0
--indent=spaces=2
--indent-continuation=2
--indent-after-parens
--close-templates
--add-brackets
--break-after-logical
${MODULE_SRC}
)
if(NOT WIN32 STREQUAL "1")
add_custom_target(
format
COMMAND ${CMAKE_BINARY_DIR}/bin/astyle ${ASTYLE_ARGS}
COMMENT "running astyle"
)
else()
add_custom_target(
format
COMMAND ${CMAKE_BINARY_DIR}/bin/astyle.exe ${ASTYLE_ARGS}
COMMENT "running astyle"
)
endif()
endif()