forked from shiguredo/momo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
812 lines (721 loc) · 26 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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
cmake_minimum_required(VERSION 3.16)
# Only interpret if() arguments as variables or keywords when unquoted.
cmake_policy(SET CMP0054 NEW)
# MSVC runtime library flags are selected by an abstraction.
cmake_policy(SET CMP0091 NEW)
set(MOMO_PACKAGE_NAME "" CACHE STRING "ビルド設定を自動化するパッケージ名")
set(TARGET_OS "" CACHE STRING "ビルド対象の動作する OS。\n有効な値は windows, macos, linux")
set(TARGET_OS_LINUX "" CACHE STRING "TARGET_OS が linux の場合の詳細な OS の情報。")
set(TARGET_ARCH "" CACHE STRING "ビルド対象の動作する CPU。\n有効な値は x86_64, arm")
set(TARGET_ARCH_ARM "" CACHE STRING "TARGET_ARCH が arm の場合の詳細な CPU の情報。\n有効な値は armv6, armv7, armv8")
set(USE_NVCODEC_ENCODER OFF CACHE BOOL "NVIDIA VIDEO CODEC SDK のハードウェアエンコーダを利用するかどうか")
set(USE_MMAL_ENCODER OFF CACHE BOOL "MMAL ハードウェアエンコーダを利用するかどうか")
set(USE_JETSON_ENCODER OFF CACHE BOOL "Jetson のハードウェアエンコーダを利用するかどうか")
set(USE_MSDK_ENCODER OFF CACHE BOOL "Intel Media SDK のハードウェアエンコーダを利用するかどうか")
set(USE_H264 OFF CACHE BOOL "H264 を利用するかどうか")
set(USE_SDL2 OFF CACHE BOOL "SDL2 による画面出力を利用するかどうか")
set(USE_LINUX_PULSE_AUDIO OFF CACHE BOOL "Linux で ALSA の代わりに PulseAudio を利用するか")
set(USE_SCREEN_CAPTURER OFF CACHE BOOL "スクリーンキャプチャラを利用するかどうか")
set(BOOST_ROOT_DIR "" CACHE PATH "Boost のインストール先ディレクトリ\n空文字だった場合はデフォルト検索パスの Boost を利用する")
set(SDL2_ROOT_DIR "" CACHE PATH "SDL2 のインストール先ディレクトリ\n空文字だった場合はデフォルト検索パスの SDL2 を利用する")
set(CLI11_ROOT_DIR "" CACHE PATH "CLI11 のインストール先ディレクトリ")
set(NVCODEC_ROOT_DIR "" CACHE PATH "NVIDIA VIDEO CODEC SDK のインストール先ディレクトリ")
set(WEBRTC_INCLUDE_DIR "" CACHE PATH "WebRTC のインクルードディレクトリ")
set(WEBRTC_LIBRARY_DIR "" CACHE PATH "WebRTC のライブラリディレクトリ")
set(WEBRTC_LIBRARY_NAME "webrtc" CACHE STRING "WebRTC のライブラリ名")
set(CLANG_ROOT "" CACHE PATH "コンパイルに利用する clang コンパイラの配置場所")
set(USE_LIBCXX OFF CACHE BOOL "libstdc++ の代わりに libc++ を使うかどうか")
set(LIBCXX_INCLUDE_DIR "" CACHE PATH "libc++ を使う場合の libc++ のインクルードディレクトリ\n空文字だった場合はデフォルト検索パスの libc++ を利用する")
set(SYSROOT "" CACHE PATH "TARGET_ARCH が arm の場合のクロスビルド用の RootFS ディレクトリ")
set(MOMO_VERSION "unspecified" CACHE STRING "Momo のバージョン")
set(MOMO_COMMIT "<commit>" CACHE STRING "Momo のコミットハッシュ")
set(WEBRTC_BUILD_VERSION "unspecified" CACHE STRING "webrtc-build のバージョン")
set(WEBRTC_READABLE_VERSION "unspecified" CACHE STRING "WebRTC の読みやすいバージョン")
set(WEBRTC_COMMIT "<commit>" CACHE STRING "WebRTC のコミットハッシュ")
if(MOMO_PACKAGE_NAME STREQUAL "windows_x86_64")
set(_INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build/windows_x86_64/_install)
set(TARGET_OS "windows")
set(TARGET_ARCH "x86_64")
set(USE_NVCODEC_ENCODER ON)
set(USE_MSDK_ENCODER ON)
set(USE_H264 ON)
set(USE_SDL2 ON)
set(USE_SCREEN_CAPTURER ON)
set(BOOST_ROOT_DIR ${_INSTALL_DIR}/boost)
set(SDL2_ROOT_DIR ${_INSTALL_DIR}/SDL2)
set(CLI11_ROOT_DIR ${_INSTALL_DIR}/CLI11)
set(WEBRTC_INCLUDE_DIR ${_INSTALL_DIR}/webrtc/include)
set(WEBRTC_LIBRARY_DIR ${_INSTALL_DIR}/webrtc/lib)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${SDL2_ROOT_DIR}/cmake)
list(APPEND CMAKE_PREFIX_PATH ${BOOST_ROOT_DIR} ${SDL2_ROOT_DIR})
elseif(MOMO_PACKAGE_NAME STREQUAL "macos_arm64")
set(_INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build/macos_arm64/_install)
set(TARGET_OS "macos")
set(TARGET_ARCH "arm64")
set(USE_H264 ON)
set(USE_SDL2 ON)
set(USE_SCREEN_CAPTURER ON)
set(BOOST_ROOT_DIR ${_INSTALL_DIR}/boost)
set(SDL2_ROOT_DIR ${_INSTALL_DIR}/SDL2)
set(CLI11_ROOT_DIR ${_INSTALL_DIR}/CLI11)
set(WEBRTC_INCLUDE_DIR ${_INSTALL_DIR}/webrtc/include)
set(WEBRTC_LIBRARY_DIR ${_INSTALL_DIR}/webrtc/lib)
set(CLANG_ROOT ${_INSTALL_DIR}/llvm/clang)
set(USE_LIBCXX ON)
set(LIBCXX_INCLUDE_DIR ${_INSTALL_DIR}/llvm/libcxx/include)
elseif(MOMO_PACKAGE_NAME STREQUAL "macos_x86_64")
set(_INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build/macos_x86_64/_install)
set(TARGET_OS "macos")
set(TARGET_ARCH "x86_64")
set(USE_H264 ON)
set(USE_SDL2 ON)
set(USE_SCREEN_CAPTURER ON)
set(BOOST_ROOT_DIR ${_INSTALL_DIR}/boost)
set(SDL2_ROOT_DIR ${_INSTALL_DIR}/SDL2)
set(CLI11_ROOT_DIR ${_INSTALL_DIR}/CLI11)
set(WEBRTC_INCLUDE_DIR ${_INSTALL_DIR}/webrtc/include)
set(WEBRTC_LIBRARY_DIR ${_INSTALL_DIR}/webrtc/lib)
set(CLANG_ROOT ${_INSTALL_DIR}/llvm/clang)
set(USE_LIBCXX ON)
set(LIBCXX_INCLUDE_DIR ${_INSTALL_DIR}/llvm/libcxx/include)
elseif(MOMO_PACKAGE_NAME STREQUAL "raspberry-pi-os_armv6")
set(TARGET_OS "linux")
set(TARGET_OS_LINUX "raspberry-pi-os")
set(TARGET_ARCH "arm")
set(TARGET_ARCH_ARM "armv6")
set(USE_MMAL_ENCODER ON)
set(USE_H264 ON)
set(BOOST_ROOT_DIR /root/boost)
set(CLI11_ROOT_DIR /root/CLI11)
set(WEBRTC_INCLUDE_DIR /root/webrtc/include)
set(WEBRTC_LIBRARY_DIR /root/webrtc/lib)
set(CLANG_ROOT /root/llvm/clang)
set(SYSROOT /root/rootfs)
set(USE_LIBCXX ON)
set(LIBCXX_INCLUDE_DIR /root/llvm/libcxx/include)
set(Boost_ARCHITECTURE 32)
elseif(MOMO_PACKAGE_NAME STREQUAL "raspberry-pi-os_armv7")
set(TARGET_OS "linux")
set(TARGET_OS_LINUX "raspberry-pi-os")
set(TARGET_ARCH "arm")
set(TARGET_ARCH_ARM "armv7")
set(USE_MMAL_ENCODER ON)
set(USE_H264 ON)
set(USE_SDL2 ON)
set(BOOST_ROOT_DIR /root/boost)
set(SDL2_ROOT_DIR /root/SDL2)
set(CLI11_ROOT_DIR /root/CLI11)
set(WEBRTC_INCLUDE_DIR /root/webrtc/include)
set(WEBRTC_LIBRARY_DIR /root/webrtc/lib)
set(CLANG_ROOT /root/llvm/clang)
set(SYSROOT /root/rootfs)
set(USE_LIBCXX ON)
set(LIBCXX_INCLUDE_DIR /root/llvm/libcxx/include)
set(Boost_ARCHITECTURE 32)
elseif(MOMO_PACKAGE_NAME STREQUAL "raspberry-pi-os_armv8")
set(TARGET_OS "linux")
set(TARGET_OS_LINUX "raspberry-pi-os")
set(TARGET_ARCH "arm")
set(TARGET_ARCH_ARM "armv8")
set(BOOST_ROOT_DIR /root/boost)
set(CLI11_ROOT_DIR /root/CLI11)
set(WEBRTC_INCLUDE_DIR /root/webrtc/include)
set(WEBRTC_LIBRARY_DIR /root/webrtc/lib)
set(CLANG_ROOT /root/llvm/clang)
set(SYSROOT /root/rootfs)
set(USE_LIBCXX ON)
set(LIBCXX_INCLUDE_DIR /root/llvm/libcxx/include)
elseif(MOMO_PACKAGE_NAME STREQUAL "ubuntu-18.04_armv8_jetson_nano")
set(TARGET_OS "linux")
set(TARGET_OS_LINUX "ubuntu-18.04")
set(TARGET_ARCH "arm")
set(TARGET_ARCH_ARM "armv8")
set(USE_JETSON_ENCODER ON)
set(USE_H264 ON)
set(USE_SDL2 ON)
set(USE_LINUX_PULSE_AUDIO ON)
set(BOOST_ROOT_DIR /root/boost)
set(CLI11_ROOT_DIR /root/CLI11)
set(SDL2_ROOT_DIR /root/SDL2)
set(WEBRTC_INCLUDE_DIR /root/webrtc/include)
set(WEBRTC_LIBRARY_DIR /root/webrtc/lib)
set(CLANG_ROOT /root/llvm/clang)
set(SYSROOT /root/rootfs)
set(USE_LIBCXX ON)
set(LIBCXX_INCLUDE_DIR /root/llvm/libcxx/include)
elseif(MOMO_PACKAGE_NAME STREQUAL "ubuntu-18.04_armv8_jetson_xavier")
set(TARGET_OS "linux")
set(TARGET_OS_LINUX "ubuntu-18.04")
set(TARGET_ARCH "arm")
set(TARGET_ARCH_ARM "armv8")
set(USE_JETSON_ENCODER ON)
set(USE_H264 ON)
set(USE_SDL2 ON)
set(USE_LINUX_PULSE_AUDIO ON)
set(BOOST_ROOT_DIR /root/boost)
set(CLI11_ROOT_DIR /root/CLI11)
set(SDL2_ROOT_DIR /root/SDL2)
set(WEBRTC_INCLUDE_DIR /root/webrtc/include)
set(WEBRTC_LIBRARY_DIR /root/webrtc/lib)
set(CLANG_ROOT /root/llvm/clang)
set(SYSROOT /root/rootfs)
set(USE_LIBCXX ON)
set(LIBCXX_INCLUDE_DIR /root/llvm/libcxx/include)
elseif(MOMO_PACKAGE_NAME STREQUAL "ubuntu-18.04_x86_64")
set(TARGET_OS "linux")
set(TARGET_OS_LINUX "ubuntu-18.04")
set(TARGET_ARCH "x86_64")
set(USE_H264 ON)
set(USE_SDL2 ON)
set(USE_NVCODEC_ENCODER ON)
set(USE_SCREEN_CAPTURER ON)
set(BOOST_ROOT_DIR /root/boost)
set(CLI11_ROOT_DIR /root/CLI11)
set(SDL2_ROOT_DIR /root/SDL2)
set(WEBRTC_INCLUDE_DIR /root/webrtc/include)
set(WEBRTC_LIBRARY_DIR /root/webrtc/lib)
# /root/llvm/clang にあるコンパイラは使わず、apt でインストールした clang-10 を利用する
set(CMAKE_C_COMPILER clang-10)
set(CMAKE_CXX_COMPILER clang++-10)
set(USE_LIBCXX ON)
set(LIBCXX_INCLUDE_DIR /root/llvm/libcxx/include)
elseif(MOMO_PACKAGE_NAME STREQUAL "ubuntu-20.04_x86_64")
set(TARGET_OS "linux")
set(TARGET_OS_LINUX "ubuntu-20.04")
set(TARGET_ARCH "x86_64")
set(USE_H264 ON)
set(USE_SDL2 ON)
set(USE_NVCODEC_ENCODER ON)
set(USE_MSDK_ENCODER ON)
set(USE_SCREEN_CAPTURER ON)
set(BOOST_ROOT_DIR /root/boost)
set(CLI11_ROOT_DIR /root/CLI11)
set(SDL2_ROOT_DIR /root/SDL2)
set(LIBVA_ROOT_DIR /root/libva)
set(MSDK_ROOT_DIR /root/msdk)
set(WEBRTC_INCLUDE_DIR /root/webrtc/include)
set(WEBRTC_LIBRARY_DIR /root/webrtc/lib)
# /root/llvm/clang にあるコンパイラは使わず、apt でインストールした clang-10 を利用する
set(CMAKE_C_COMPILER clang-10)
set(CMAKE_CXX_COMPILER clang++-10)
set(USE_LIBCXX ON)
set(LIBCXX_INCLUDE_DIR /root/llvm/libcxx/include)
else()
endif()
if (NOT "${CLANG_ROOT}" STREQUAL "")
set(CMAKE_C_COMPILER ${CLANG_ROOT}/bin/clang)
set(CMAKE_CXX_COMPILER ${CLANG_ROOT}/bin/clang++)
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if (NOT "${BOOST_ROOT_DIR}" STREQUAL "")
list(APPEND CMAKE_PREFIX_PATH ${BOOST_ROOT_DIR})
endif()
if (USE_SDL2 AND (NOT "${SDL2_ROOT_DIR}" STREQUAL ""))
list(APPEND CMAKE_MODULE_PATH ${SDL2_ROOT_DIR}/cmake)
list(APPEND CMAKE_PREFIX_PATH ${SDL2_ROOT_DIR})
endif()
# SYSROOT とかの設定
# これらの設定は project の前に行う必要がある
if (TARGET_OS STREQUAL "linux")
if (TARGET_ARCH STREQUAL "arm")
if (TARGET_ARCH_ARM STREQUAL "armv8")
set(ARCH_NAME aarch64-linux-gnu)
else()
set(ARCH_NAME arm-linux-gnueabihf)
endif()
set(CMAKE_SYSTEM_NAME Linux)
if (TARGET_ARCH_ARM STREQUAL "armv8")
set(CMAKE_SYSTEM_PROCESSOR aarch64)
else()
set(CMAKE_SYSTEM_PROCESSOR arm)
endif()
set(CMAKE_SYSROOT ${SYSROOT})
set(CMAKE_C_COMPILER_TARGET ${ARCH_NAME})
set(CMAKE_CXX_COMPILER_TARGET ${ARCH_NAME})
set(CMAKE_FIND_ROOT_PATH ${SYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
endif()
endif()
if (TARGET_OS STREQUAL "macos")
if (TARGET_ARCH STREQUAL "x86_64")
set(ARCH_NAME x86_64-apple-darwin)
else()
set(ARCH_NAME aarch64-apple-darwin)
set(CMAKE_SYSTEM_PROCESSOR arm64)
endif()
set(CMAKE_C_COMPILER_TARGET ${ARCH_NAME})
set(CMAKE_CXX_COMPILER_TARGET ${ARCH_NAME})
endif()
project(momo C CXX)
list(APPEND MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(Boost_USE_STATIC_LIBS ON)
if ("${TARGET_OS}" STREQUAL "windows")
set(Boost_USE_STATIC_RUNTIME ON)
else()
set(Boost_USE_STATIC_RUNTIME OFF)
endif()
find_package(WebRTC REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem json)
find_package(CLI11 REQUIRED)
if (USE_SDL2)
find_package(SDL2 REQUIRED)
endif()
add_executable(momo)
string(SUBSTRING "${MOMO_COMMIT}" 0 8 MOMO_COMMIT_SHORT)
string(SUBSTRING "${WEBRTC_COMMIT}" 0 8 WEBRTC_COMMIT_SHORT)
configure_file(src/momo_version.gen.h.template ${CMAKE_CURRENT_BINARY_DIR}/momo_version.gen.h)
target_include_directories(momo PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_sources(momo
PRIVATE
src/main.cpp
src/momo_version.cpp
src/util.cpp
src/watchdog.cpp
src/ssl_verifier.cpp
src/ayame/ayame_client.cpp
src/p2p/p2p_server.cpp
src/p2p/p2p_session.cpp
src/p2p/p2p_websocket_session.cpp
src/rtc/device_video_capturer.cpp
src/rtc/momo_video_decoder_factory.cpp
src/rtc/momo_video_encoder_factory.cpp
src/rtc/native_buffer.cpp
src/rtc/peer_connection_observer.cpp
src/rtc/rtc_connection.cpp
src/rtc/rtc_manager.cpp
src/rtc/rtc_ssl_verifier.cpp
src/rtc/scalable_track_source.cpp
src/serial_data_channel/serial_data_channel.cpp
src/serial_data_channel/serial_data_manager.cpp
src/sora/sora_server.cpp
src/sora/sora_session.cpp
src/sora/sora_client.cpp
src/websocket.cpp
src/metrics/metrics_server.cpp
src/metrics/metrics_session.cpp
)
target_include_directories(momo PRIVATE src)
set_target_properties(momo PROPERTIES CXX_STANDARD 17 C_STANDARD 99)
target_link_libraries(momo
PRIVATE
WebRTC::WebRTC
Boost::filesystem
Boost::json
CLI11::CLI11
)
target_compile_definitions(momo
PRIVATE
# CLI11 は C++17 でのビルドにおいて std::filesystem を利用するが、これを clang で解決するには c++fs のリンクが必要になる。
# しかし、 libwebrtc の libc++ では std::filesystem が提供されていないため下記のオプションを追加して利用しないようにする。
CLI11_HAS_FILESYSTEM=0
OPENSSL_IS_BORINGSSL
USE_NVCODEC_ENCODER=$<BOOL:${USE_NVCODEC_ENCODER}>
USE_MMAL_ENCODER=$<BOOL:${USE_MMAL_ENCODER}>
USE_JETSON_ENCODER=$<BOOL:${USE_JETSON_ENCODER}>
USE_MSDK_ENCODER=$<BOOL:${USE_MSDK_ENCODER}>
USE_H264=$<BOOL:${USE_H264}>
USE_SDL2=$<BOOL:${USE_SDL2}>
USE_LINUX_PULSE_AUDIO=$<BOOL:${USE_LINUX_PULSE_AUDIO}>
USE_SCREEN_CAPTURER=$<BOOL:${USE_SCREEN_CAPTURER}>
)
if (USE_SDL2)
target_sources(momo
PRIVATE
src/sdl_renderer/sdl_renderer.cpp
)
target_compile_definitions(momo
PRIVATE
_THREAD_SAFE
)
if ("${TARGET_OS}" STREQUAL "windows" OR "${TARGET_OS}" STREQUAL "macos")
target_link_libraries(momo
PRIVATE
SDL2::SDL2-static
SDL2::SDL2main
)
else()
if (TARGET SDL2::SDL2Config)
target_link_libraries(momo
PRIVATE
SDL2::SDL2Config
)
else()
target_link_directories(momo PRIVATE ${SDL2_LIBDIR})
target_link_libraries(momo PRIVATE SDL2)
target_include_directories(momo PRIVATE "${SYSROOT}${SDL2_INCLUDE_DIRS}")
endif()
endif()
if ("${TARGET_OS}" STREQUAL "macos")
target_link_libraries(momo
PRIVATE
iconv
"-framework Carbon"
"-framework IOKit"
"-framework ForceFeedback"
)
endif()
endif()
if (USE_LIBCXX)
target_compile_options(momo
PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>"
"$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<BOOL:LIBCXX_INCLUDE_DIR>>:-isystem${LIBCXX_INCLUDE_DIR}>"
)
endif()
if (USE_SCREEN_CAPTURER)
target_sources(momo
PRIVATE
src/rtc/screen_video_capturer.cpp
)
if (TARGET_OS STREQUAL "linux")
target_link_libraries(momo
PRIVATE
# gio-2.0
# gobject-2.0
# glib-2.0
# Xext
Xdamage
Xfixes
Xcomposite
Xrandr
)
endif()
if (TARGET_OS STREQUAL "macos")
target_link_libraries(momo
PRIVATE
"-framework IOSurface"
)
endif()
endif()
if ("${TARGET_OS}" STREQUAL "windows")
# 文字コードを utf-8 として扱うのと、シンボルテーブル数を増やす
target_compile_options(momo PRIVATE /utf-8 /bigobj)
set_target_properties(momo
PROPERTIES
# CRTライブラリを静的リンクさせる
# CMake 3.15 以上なら MSVC_RUNTIME_LIBRARY が使える
MSVC_RUNTIME_LIBRARY "MultiThreaded"
)
target_link_libraries(momo
PRIVATE
dbghelp.lib
delayimp.lib
dnsapi.lib
msimg32.lib
oleaut32.lib
psapi.lib
shell32.lib
shlwapi.lib
usp10.lib
version.lib
wininet.lib
winmm.lib
ws2_32.lib
amstrmid.lib
Strmiids.lib
crypt32.lib
dmoguids.lib
iphlpapi.lib
msdmo.lib
Secur32.lib
wmcodecdspuuid.lib
)
target_compile_definitions(momo
PRIVATE
_CONSOLE
_WIN32_WINNT=0x0A00
WEBRTC_WIN
NOMINMAX
WIN32_LEAN_AND_MEAN
UNICODE
_UNICODE
)
# NVIDIA Video Codec SDK
if (USE_NVCODEC_ENCODER)
target_sources(momo
PRIVATE
src/hwenc_nvcodec/nvcodec_h264_encoder.cpp
NvCodec/NvCodec/NvEncoder/NvEncoder.cpp
NvCodec/NvCodec/NvEncoder/NvEncoderD3D11.cpp
src/hwenc_nvcodec/nvcodec_video_decoder.cpp)
target_include_directories(momo
PRIVATE
NvCodec/include
NvCodec/NvCodec)
target_link_libraries(momo
PRIVATE
DXGI.lib
D3D11.lib
)
# enable_language(CUDA) は CUDA 用 Visual Studio Integration を利用して CUDA を検出しているが、
# CUDA ドライバがインストールできない場所では VS Integration をインストールできないため、
# enable_language(CUDA) は利用できない。
# なので(deprecated だけど)FindCUDA を利用してコンパイルする。
set(CUDA_TOOLKIT_ROOT_DIR ${_INSTALL_DIR}/cuda/nvcc)
find_package(CUDA REQUIRED)
set_source_files_properties(
src/cuda/cuda_context_cuda.cpp
NvCodec/NvCodec/NvDecoder/NvDecoder.cpp
src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
PROPERTIES
CUDA_SOURCE_PROPERTY_FORMAT OBJ
)
cuda_compile(CUDA_FILES
src/cuda/cuda_context_cuda.cpp
NvCodec/NvCodec/NvDecoder/NvDecoder.cpp
src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
OPTIONS
-Xcompiler /utf-8
-Xcompiler /I${CMAKE_CURRENT_SOURCE_DIR}/NvCodec/include
-Xcompiler /I${CMAKE_CURRENT_SOURCE_DIR}/NvCodec/NvCodec
-Xcompiler /I${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_sources(momo PRIVATE ${CUDA_FILES})
target_include_directories(momo PRIVATE ${CUDA_INCLUDE_DIRS})
target_link_libraries(momo
PRIVATE
${CUDA_TOOLKIT_ROOT_DIR}/lib/x64/cudart_static.lib
#${CUDA_LIBRARIES}
)
endif()
# Intel Media SDK
if (USE_MSDK_ENCODER)
target_sources(momo
PRIVATE
src/hwenc_msdk/msdk_session.cpp
src/hwenc_msdk/msdk_video_decoder.cpp
src/hwenc_msdk/msdk_video_encoder.cpp
)
target_include_directories(momo PRIVATE ${_INSTALL_DIR}/msdk/include)
target_link_libraries(momo
PRIVATE
${_INSTALL_DIR}/msdk/lib/libmfx.lib
)
endif()
elseif (TARGET_OS STREQUAL "macos")
target_sources(momo
PRIVATE
src/mac_helper/mac_capturer.mm
src/mac_helper/macos_version.mm
src/mac_helper/objc_codec_factory_helper.mm
)
target_compile_options(momo PRIVATE -fconstant-string-class=NSConstantString -mmacosx-version-min=11.0)
target_link_options(momo PRIVATE -ObjC)
set_target_properties(momo PROPERTIES CXX_VISIBILITY_PRESET hidden)
target_link_libraries(momo
PRIVATE
"-framework Foundation"
"-framework AVFoundation"
"-framework CoreServices"
"-framework CoreFoundation"
"-framework AudioUnit"
"-framework AudioToolbox"
"-framework CoreAudio"
"-framework CoreGraphics"
"-framework CoreMedia"
"-framework CoreVideo"
"-framework VideoToolbox"
"-framework AppKit"
"-framework Metal"
"-framework MetalKit"
"-framework OpenGL"
)
target_compile_definitions(momo
PRIVATE
WEBRTC_POSIX
WEBRTC_MAC
)
elseif (TARGET_OS STREQUAL "linux")
find_package(Threads REQUIRED)
target_sources(momo
PRIVATE
src/v4l2_video_capturer/v4l2_video_capturer.cpp
)
target_compile_definitions(momo
PRIVATE
WEBRTC_POSIX
)
# Linux 系の場合はカスタムされた libc++ を使っているためオプション追加
target_compile_definitions(momo PRIVATE _LIBCPP_ABI_UNSTABLE _LIBCPP_DISABLE_AVAILABILITY)
set_target_properties(momo PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(momo
PRIVATE
X11
# Xau
# Xdmcp
Xtst
# xcb
# plds4
Xext
# expat
dl
# nss3
# nssutil3
# plc4
# nspr4
# rt
Threads::Threads
)
# NVIDIA Video Codec SDK
if (USE_NVCODEC_ENCODER)
target_sources(momo
PRIVATE
src/cuda/cuda_context_cuda.cpp
src/hwenc_nvcodec/nvcodec_h264_encoder.cpp
src/hwenc_nvcodec/nvcodec_v4l2_capturer.cpp
src/hwenc_nvcodec/nvcodec_h264_encoder_cuda.cpp
src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
src/hwenc_nvcodec/nvcodec_video_decoder.cpp
NvCodec/NvCodec/NvDecoder/NvDecoder.cpp
NvCodec/NvCodec/NvEncoder/NvEncoder.cpp
NvCodec/NvCodec/NvEncoder/NvEncoderCuda.cpp)
target_include_directories(momo
PRIVATE
NvCodec/include
NvCodec/NvCodec
/usr/local/cuda/include)
# これらのソースは CUDA としてコンパイルする
set_source_files_properties(
src/cuda/cuda_context_cuda.cpp
src/hwenc_nvcodec/nvcodec_h264_encoder_cuda.cpp
src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
NvCodec/NvCodec/NvDecoder/NvDecoder.cpp
NvCodec/NvCodec/NvEncoder/NvEncoderCuda.cpp
PROPERTIES
COMPILE_OPTIONS "-xcuda;--cuda-gpu-arch=sm_35;-std=gnu++14"
)
target_link_directories(momo PRIVATE /usr/local/cuda/lib64)
target_link_libraries(momo PRIVATE cudart_static dl rt)
endif()
# Intel Media SDK
if (USE_MSDK_ENCODER)
find_package(MSDK REQUIRED)
target_sources(momo
PRIVATE
src/hwenc_msdk/msdk_session.cpp
src/hwenc_msdk/msdk_video_decoder.cpp
src/hwenc_msdk/msdk_video_encoder.cpp
src/hwenc_msdk/vaapi_utils_drm.cpp
src/hwenc_msdk/vaapi_utils.cpp
)
target_link_libraries(momo
PRIVATE
MSDK::MSDK)
endif()
if (TARGET_ARCH STREQUAL "arm")
if (USE_LIBCXX)
target_include_directories(momo PRIVATE ${SYSROOT}/usr/include/${ARCH_NAME})
target_link_directories(momo PRIVATE ${SYSROOT}/usr/lib/${ARCH_NAME})
endif()
if (TARGET_ARCH_ARM STREQUAL "armv8")
# Jetson の設定
if (USE_JETSON_ENCODER)
target_sources(momo
PRIVATE
src/hwenc_jetson/jetson_buffer.cpp
src/hwenc_jetson/jetson_jpeg_decoder.cpp
src/hwenc_jetson/jetson_jpeg_decoder_pool.cpp
src/hwenc_jetson/jetson_v4l2_capturer.cpp
src/hwenc_jetson/jetson_video_encoder.cpp
src/hwenc_jetson/jetson_video_decoder.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvBuffer.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvElement.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvElementProfiler.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvJpegDecoder.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvJpegEncoder.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvLogging.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvV4l2Element.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvV4l2ElementPlane.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvVideoConverter.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvVideoEncoder.cpp
${SYSROOT}/usr/src/jetson_multimedia_api/samples/common/classes/NvVideoDecoder.cpp
)
target_include_directories(momo PRIVATE ${SYSROOT}/usr/src/jetson_multimedia_api/include)
target_include_directories(momo PRIVATE ${SYSROOT}/usr/src/jetson_multimedia_api/include/libjpeg-8b)
target_link_directories(momo PRIVATE ${SYSROOT}/usr/lib/aarch64-linux-gnu/tegra)
target_link_options(momo
PRIVATE
"-Wl,-rpath-link=${SYSROOT}/lib/aarch64-linux-gnu"
"-Wl,-rpath-link=${SYSROOT}/usr/lib/aarch64-linux-gnu"
"-Wl,-rpath-link=${SYSROOT}/usr/lib/aarch64-linux-gnu/tegra"
)
target_link_libraries(momo
PRIVATE
nvv4l2
nvv4lconvert
nvbuf_utils
nvbuf_fdmap
nvddk_vic
nvddk_2d_v2
nvjpeg
nvrm
nvrm_graphics
nvos
)
endif(USE_JETSON_ENCODER)
else()
# armv6, armv7 用
if (TARGET_ARCH_ARM STREQUAL "armv6")
target_compile_options(momo PRIVATE -mfloat-abi=hard -mcpu=arm1176jzf-s -mfpu=vfp)
else()
target_compile_options(momo PRIVATE -mfloat-abi=hard -march=armv7-a -mtune=generic-armv7-a -mfpu=neon -mthumb)
endif()
if (USE_MMAL_ENCODER)
target_sources(momo
PRIVATE
src/hwenc_mmal/mmal_h264_decoder.cpp
src/hwenc_mmal/mmal_buffer.cpp
src/hwenc_mmal/mmal_h264_encoder.cpp
src/hwenc_mmal/mmal_v4l2_capturer.cpp
)
if (TARGET_OS_LINUX STREQUAL "raspberry-pi-os")
set(_VC_PATH ${SYSROOT}/opt/vc)
else()
set(_VC_PATH ${SYSROOT}/usr)
endif()
target_include_directories(momo PRIVATE ${_VC_PATH}/include)
target_compile_options(momo PRIVATE -ftree-vectorize -pipe)
target_compile_definitions(momo
PRIVATE
STANDALONE
__STDC_CONSTANT_MACROS
__STDC_LIMIT_MACROS
TARGET_POSIX
_LINUX
PIC
_REENTRANT
_LARGEFILE64_SOURCE
_FILE_OFFSET_BITS=64
_FORTIFY_SOURCE
HAVE_LIBOPENMAX=2
OMX
OMX_SKIP64BIT
USE_EXTERNAL_OMX
HAVE_LIBBCM_HOST
USE_EXTERNAL_LIBBCM_HOST
USE_VCHIQ_ARM
)
target_link_directories(momo PRIVATE ${_VC_PATH}/lib)
target_link_libraries(momo
PRIVATE
GLESv2
EGL
bcm_host
containers
vcos
vcsm
vchiq_arm
mmal
mmal_core
mmal_components
mmal_util
mmal_vc_client
m
)
endif(USE_MMAL_ENCODER)
endif(TARGET_ARCH_ARM STREQUAL "armv8")
endif(TARGET_ARCH STREQUAL "arm")
endif()