1 # Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 # Use of this source code is governed by a BSD-style license
4 # that can be found in the LICENSE file in the root of the source
5 # tree. An additional intellectual property rights grant can be found
6 # in the file PATENTS. All contributing project authors may
7 # be found in the AUTHORS file in the root of the source tree.
9 # This is the root build file for GN. GN will start processing by loading this
10 # file, and recursively load all dependencies until all dependencies are either
11 # resolved or known not to exist (which will cause the build to fail). So if
12 # you add a new build file, there must be some path of dependencies from this
13 # file to your new one or GN won't know about it.
15 # Use of visibility = clauses:
16 # The default visibility for all rtc_ targets is equivalent to "//*", or
17 # "all targets in webrtc can depend on this, nothing outside can".
19 # When overriding, the choices are:
20 # - visibility = [ "*" ] - public. Stuff outside webrtc can use this.
21 # - visibility = [ ":*" ] - directory private.
22 # As a general guideline, only targets in api/ should have public visibility.
24 import("//build/config/linux/pkg_config.gni")
25 import("//build/config/sanitizers/sanitizers.gni")
26 import("//third_party/google_benchmark/buildconfig.gni")
28 if (rtc_enable_protobuf) {
29 import("//third_party/protobuf/proto_library.gni")
32 import("//build/config/android/config.gni")
33 import("//build/config/android/rules.gni")
36 if (!build_with_chromium && !build_with_mozilla) {
37 # This target should (transitively) cause everything to be built; if you run
38 # 'ninja default' and then 'ninja all', the second build should do no work.
42 if (rtc_build_examples) {
43 deps += [ "examples" ]
45 if (rtc_build_tools) {
46 deps += [ "rtc_tools" ]
48 if (rtc_include_tests) {
51 ":video_engine_tests",
53 ":webrtc_nonparallel_tests",
55 "common_audio:common_audio_unittests",
56 "common_video:common_video_unittests",
57 "examples:examples_unittests",
58 "media:rtc_media_unittests",
59 "modules:modules_tests",
60 "modules:modules_unittests",
61 "modules/audio_coding:audio_coding_tests",
62 "modules/audio_processing:audio_processing_tests",
63 "modules/remote_bitrate_estimator:rtp_to_text",
64 "modules/rtp_rtcp:test_packet_masks_metrics",
65 "modules/video_capture:video_capture_internal_impl",
66 "net/dcsctp:dcsctp_unittests",
67 "pc:peerconnection_unittests",
68 "pc:rtc_pc_unittests",
69 "pc:slow_peer_connection_unittests",
71 "rtc_tools:rtp_generator",
72 "rtc_tools:video_replay",
73 "stats:rtc_stats_unittests",
74 "system_wrappers:system_wrappers_unittests",
76 "video:screenshare_loopback",
78 "video:video_loopback",
81 # Do not build :webrtc_lib_link_test because lld complains on some OS
82 # (e.g. when target_os = "mac") when is_asan=true. For more details,
83 # see bugs.webrtc.org/11027#c5.
84 deps += [ ":webrtc_lib_link_test" ]
88 "examples:apprtcmobile_tests",
89 "sdk:sdk_framework_unittests",
95 "examples:android_examples_junit_tests",
96 "sdk/android:android_instrumentation_test_apk",
97 "sdk/android:android_sdk_junit_tests",
100 deps += [ "modules/video_capture:video_capture_tests" ]
102 if (rtc_enable_protobuf) {
104 "audio:low_bandwidth_audio_perf_test",
105 "logging:rtc_event_log_rtp_dump",
106 "tools_webrtc/perf:webrtc_dashboard_upload",
110 if (target_os == "android") {
111 deps += [ "tools_webrtc:binary_version_check" ]
116 # Abseil Flags by default doesn't register command line flags on mobile
117 # platforms, WebRTC tests requires them (e.g. on simualtors) so this
118 # config will be applied to testonly targets globally (see webrtc.gni).
119 config("absl_flags_configs") {
120 defines = [ "ABSL_FLAGS_STRIP_NAMES=0" ]
123 config("library_impl_config") {
124 # Build targets that contain WebRTC implementation need this macro to
125 # be defined in order to correctly export symbols when is_component_build
127 # For more info see: rtc_base/build/rtc_export.h.
128 defines = [ "WEBRTC_LIBRARY_IMPL" ]
131 # Contains the defines and includes in common.gypi that are duplicated both as
132 # target_defaults and direct_dependent_settings.
133 config("common_inherited_config") {
138 if (rtc_dlog_always_on) {
139 defines += [ "DLOG_ALWAYS_ON" ]
142 if (rtc_enable_symbol_export || is_component_build) {
143 defines += [ "WEBRTC_ENABLE_SYMBOL_EXPORT" ]
145 if (rtc_enable_objc_symbol_export) {
146 defines += [ "WEBRTC_ENABLE_OBJC_SYMBOL_EXPORT" ]
149 if (build_with_mozilla) {
150 defines += [ "WEBRTC_MOZILLA_BUILD" ]
153 if (!rtc_builtin_ssl_root_certificates) {
154 defines += [ "WEBRTC_EXCLUDE_BUILT_IN_SSL_ROOT_CERTS" ]
157 if (rtc_disable_check_msg) {
158 defines += [ "RTC_DISABLE_CHECK_MSG" ]
161 if (rtc_enable_avx2) {
162 defines += [ "WEBRTC_ENABLE_AVX2" ]
165 if (rtc_enable_win_wgc) {
166 defines += [ "RTC_ENABLE_WIN_WGC" ]
169 # Some tests need to declare their own trace event handlers. If this define is
170 # not set, the first time TRACE_EVENT_* is called it will store the return
171 # value for the current handler in an static variable, so that subsequent
172 # changes to the handler for that TRACE_EVENT_* will be ignored.
173 # So when tests are included, we set this define, making it possible to use
174 # different event handlers in different tests.
175 if (rtc_include_tests) {
176 defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=1" ]
178 defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=0" ]
180 if (build_with_chromium) {
181 defines += [ "WEBRTC_CHROMIUM_BUILD" ]
183 # The overrides must be included first as that is the mechanism for
184 # selecting the override headers in Chromium.
185 "../webrtc_overrides",
187 # Allow includes to be prefixed with webrtc/ in case it is not an
188 # immediate subdirectory of the top-level.
191 # Just like the root WebRTC directory is added to include path, the
192 # corresponding directory tree with generated files needs to be added too.
193 # Note: this path does not change depending on the current target, e.g.
194 # it is always "//gen/third_party/webrtc" when building with Chromium.
195 # See also: http://cs.chromium.org/?q=%5C"default_include_dirs
196 # https://gn.googlesource.com/gn/+/master/docs/reference.md#target_gen_dir
200 if (is_posix || is_fuchsia) {
201 defines += [ "WEBRTC_POSIX" ]
209 if (is_linux || is_chromeos) {
210 defines += [ "WEBRTC_LINUX" ]
213 defines += [ "WEBRTC_BSD" ]
216 defines += [ "WEBRTC_MAC" ]
219 defines += [ "WEBRTC_FUCHSIA" ]
222 defines += [ "WEBRTC_WIN" ]
230 if (build_with_mozilla) {
231 defines += [ "WEBRTC_ANDROID_OPENSLES" ]
235 defines += [ "CHROMEOS" ]
238 if (rtc_sanitize_coverage != "") {
239 assert(is_clang, "sanitizer coverage requires clang")
240 cflags += [ "-fsanitize-coverage=${rtc_sanitize_coverage}" ]
241 ldflags += [ "-fsanitize-coverage=${rtc_sanitize_coverage}" ]
245 cflags += [ "-fsanitize=float-cast-overflow" ]
249 # TODO(bugs.webrtc.org/9693): Remove the possibility to suppress this warning
250 # as soon as WebRTC compiles without it.
251 config("no_global_constructors") {
253 cflags = [ "-Wno-global-constructors" ]
257 config("rtc_prod_config") {
258 # Ideally, WebRTC production code (but not test code) should have these flags.
261 "-Wexit-time-destructors",
262 "-Wglobal-constructors",
267 config("common_config") {
274 if (rtc_enable_protobuf) {
275 defines += [ "WEBRTC_ENABLE_PROTOBUF=1" ]
277 defines += [ "WEBRTC_ENABLE_PROTOBUF=0" ]
280 if (rtc_include_internal_audio_device) {
281 defines += [ "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE" ]
284 if (rtc_libvpx_build_vp9) {
285 defines += [ "RTC_ENABLE_VP9" ]
288 if (rtc_include_dav1d_in_internal_decoder_factory) {
289 defines += [ "RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY" ]
292 if (rtc_enable_sctp) {
293 defines += [ "WEBRTC_HAVE_SCTP" ]
296 if (rtc_enable_external_auth) {
297 defines += [ "ENABLE_EXTERNAL_AUTH" ]
301 defines += [ "WEBRTC_USE_H264" ]
304 if (rtc_use_absl_mutex) {
305 defines += [ "WEBRTC_ABSL_MUTEX" ]
308 if (rtc_disable_logging) {
309 defines += [ "RTC_DISABLE_LOGGING" ]
312 if (rtc_disable_trace_events) {
313 defines += [ "RTC_DISABLE_TRACE_EVENTS" ]
316 if (rtc_disable_metrics) {
317 defines += [ "RTC_DISABLE_METRICS" ]
320 if (rtc_exclude_transient_suppressor) {
321 defines += [ "WEBRTC_EXCLUDE_TRANSIENT_SUPPRESSOR" ]
324 if (rtc_exclude_audio_processing_module) {
325 defines += [ "WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE" ]
330 # TODO(webrtc:13219): Fix -Wshadow instances and enable.
333 # See https://reviews.llvm.org/D56731 for details about this
335 "-Wctad-maybe-unsupported",
339 if (build_with_chromium) {
341 # NOTICE: Since common_inherited_config is used in public_configs for our
342 # targets, there's no point including the defines in that config here.
343 # TODO(kjellander): Cleanup unused ones and move defines closer to the
344 # source when webrtc:4256 is completed.
346 "LOGGING_INSIDE_WEBRTC",
349 if (is_posix || is_fuchsia) {
351 # TODO(bugs.webrtc.org/9029): enable commented compiler flags.
352 # Some of these flags should also be added to cflags_objc.
354 # "-Wextra", (used when building C++ but not when building C)
355 # "-Wmissing-prototypes", (C/Obj-C only)
356 # "-Wmissing-declarations", (ensure this is always used C/C++, etc..)
357 "-Wstrict-prototypes",
359 # "-Wpointer-arith", (ensure this is always used C/C++, etc..)
360 # "-Wbad-function-cast", (C/Obj-C only)
361 # "-Wnested-externs", (C/Obj-C only)
363 cflags_objc += [ "-Wstrict-prototypes" ]
365 "-Wnon-virtual-dtor",
367 # This is enabled for clang; enable for gcc as well.
368 "-Woverloaded-virtual",
373 cflags += [ "-Wc++11-narrowing" ]
376 # Compiling with the Fuchsia SDK results in Wundef errors
377 # TODO(bugs.fuchsia.dev/100722): Remove from (!is_fuchsia) branch when
378 # Fuchsia build errors are fixed.
379 cflags += [ "-Wundef" ]
383 # Flags NaCl (Clang 3.7) do not recognize.
384 cflags += [ "-Wunused-lambda-capture" ]
388 if (is_win && !is_clang) {
389 # MSVC warning suppressions (needed to use Abseil).
390 # TODO(bugs.webrtc.org/9274): Remove these warnings as soon as MSVC allows
391 # external headers warning suppression (or fix them upstream).
392 cflags += [ "/wd4702" ] # unreachable code
394 # MSVC 2019 warning suppressions for C++17 compiling
396 [ "/wd5041" ] # out-of-line definition for constexpr static data
397 # member is not needed and is deprecated in C++17
401 if (target_cpu == "arm64") {
402 defines += [ "WEBRTC_ARCH_ARM64" ]
403 defines += [ "WEBRTC_HAS_NEON" ]
406 if (target_cpu == "arm") {
407 defines += [ "WEBRTC_ARCH_ARM" ]
408 if (arm_version >= 7) {
409 defines += [ "WEBRTC_ARCH_ARM_V7" ]
411 defines += [ "WEBRTC_HAS_NEON" ]
416 if (target_cpu == "mipsel") {
417 defines += [ "MIPS32_LE" ]
418 if (mips_float_abi == "hard") {
419 defines += [ "MIPS_FPU_LE" ]
421 if (mips_arch_variant == "r2") {
422 defines += [ "MIPS32_R2_LE" ]
424 if (mips_dsp_rev == 1) {
425 defines += [ "MIPS_DSP_R1_LE" ]
426 } else if (mips_dsp_rev == 2) {
434 if (is_android && !is_clang) {
435 # The Android NDK doesn"t provide optimized versions of these
436 # functions. Ensure they are disabled for all compilers.
445 if (use_fuzzing_engine && optimize_for_fuzzing) {
446 # Used in Chromium's overrides to disable logging
447 defines += [ "WEBRTC_UNSAFE_FUZZER_MODE" ]
450 if (!build_with_chromium && rtc_win_undef_unicode) {
459 config("common_objc") {
460 frameworks = [ "Foundation.framework" ]
464 if (!build_with_chromium) {
465 # Target to build all the WebRTC production code.
466 rtc_static_library("webrtc") {
467 # Only the root target and the test should depend on this.
470 "//:webrtc_lib_link_test",
474 complete_static_lib = true
475 suppressed_configs += [ "//build/config/compiler:thin_archive" ]
479 "api:create_peerconnection_factory",
480 "api:libjingle_peerconnection_api",
484 "api/rtc_event_log:rtc_event_log_factory",
486 "api/task_queue:default_task_queue_factory",
492 "logging:rtc_event_log_api",
495 "modules/video_capture:video_capture_internal_impl",
497 "pc:libjingle_peerconnection",
503 if (build_with_mozilla) {
505 "api:create_peerconnection_factory",
509 "api/rtc_event_log:rtc_event_log_factory",
511 "api/task_queue:default_task_queue_factory",
513 "logging:rtc_event_log_api",
515 "pc:libjingle_peerconnection",
521 if (rtc_include_builtin_audio_codecs) {
523 "api/audio_codecs:builtin_audio_decoder_factory",
524 "api/audio_codecs:builtin_audio_encoder_factory",
528 if (rtc_include_builtin_video_codecs) {
530 "api/video_codecs:builtin_video_decoder_factory",
531 "api/video_codecs:builtin_video_encoder_factory",
535 if (build_with_mozilla) {
537 "api/video:video_frame",
538 "api/video:video_rtp_headers",
539 "test:rtp_test_utils",
551 if (build_with_mozilla && is_mac) {
552 deps += [ "sdk:videocapture_objc" ]
555 if (rtc_enable_protobuf) {
556 deps += [ "logging:rtc_event_log_proto" ]
560 if (rtc_include_tests && !is_asan) {
561 rtc_executable("webrtc_lib_link_test") {
564 # This target is used for checking to link, so do not check dependencies
566 check_includes = false # no-presubmit-check TODO(bugs.webrtc.org/12785)
568 sources = [ "webrtc_lib_link_test.cc" ]
570 # NOTE: Don't add deps here. If this test fails to link, it means you
571 # need to add stuff to the webrtc static lib target above.
578 if (use_libfuzzer || use_afl) {
579 # This target is only here for gn to discover fuzzer build targets under
580 # webrtc/test/fuzzers/.
581 group("webrtc_fuzzers_dummy") {
583 deps = [ "test/fuzzers:webrtc_fuzzer_main" ]
587 if (rtc_include_tests && !build_with_chromium) {
588 rtc_test("rtc_unittests") {
592 "api:compile_all_headers",
593 "api:rtc_api_unittests",
594 "api/audio/test:audio_api_unittests",
595 "api/audio_codecs/test:audio_codecs_api_unittests",
596 "api/numerics:numerics_unittests",
597 "api/task_queue:pending_task_safety_flag_unittests",
598 "api/test/metrics:metrics_unittests",
599 "api/transport:stun_unittest",
600 "api/video/test:rtc_api_video_unittests",
601 "api/video_codecs/test:video_codecs_api_unittests",
602 "api/voip:compile_all_headers",
603 "call:fake_network_pipe_unittests",
604 "p2p:libstunprober_unittests",
605 "p2p:rtc_p2p_unittests",
606 "rtc_base:callback_list_unittests",
607 "rtc_base:rtc_base_approved_unittests",
608 "rtc_base:rtc_base_unittests",
609 "rtc_base:rtc_json_unittests",
610 "rtc_base:rtc_numerics_unittests",
611 "rtc_base:rtc_operations_chain_unittests",
612 "rtc_base:rtc_task_queue_unittests",
613 "rtc_base:sigslot_unittest",
614 "rtc_base:untyped_function_unittest",
615 "rtc_base:weak_ptr_unittests",
616 "rtc_base/experiments:experiments_unittests",
617 "rtc_base/system:file_wrapper_unittests",
618 "rtc_base/task_utils:repeating_task_unittests",
619 "rtc_base/units:units_unittests",
621 "test:rtp_test_utils",
623 "test/network:network_emulation_unittests",
626 if (rtc_enable_protobuf) {
627 deps += [ "logging:rtc_event_log_tests" ]
631 # Do not use Chromium's launcher. native_unittests defines its own JNI_OnLoad.
632 use_default_launcher = false
635 "sdk/android:native_unittests",
636 "sdk/android:native_unittests_java",
637 "//testing/android/native_test:native_test_support",
643 if (enable_google_benchmarks) {
644 rtc_test("benchmarks") {
647 "rtc_base/synchronization:mutex_benchmark",
648 "test:benchmark_main",
653 # TODO(pbos): Rename test suite, this is no longer "just" for video targets.
654 video_engine_tests_resources = [
655 "resources/foreman_cif_short.yuv",
656 "resources/voice_engine/audio_long16.pcm",
660 bundle_data("video_engine_tests_bundle_data") {
662 sources = video_engine_tests_resources
663 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
667 rtc_test("video_engine_tests") {
672 # TODO(eladalon): call_tests aren't actually video-specific, so we
673 # should move them to a more appropriate test suite.
675 "call/adaptation:resource_adaptation_tests",
678 "test:video_test_common",
680 "video/adaptation:video_adaptation_tests",
682 data = video_engine_tests_resources
684 use_default_launcher = false
686 "//build/android/gtest_apk:native_test_instrumentation_test_runner_java",
687 "//testing/android/native_test:native_test_java",
688 "//testing/android/native_test:native_test_support",
693 deps += [ ":video_engine_tests_bundle_data" ]
697 webrtc_perf_tests_resources = [
698 "resources/ConferenceMotion_1280_720_50.yuv",
699 "resources/audio_coding/speech_mono_16kHz.pcm",
700 "resources/audio_coding/speech_mono_32_48kHz.pcm",
701 "resources/audio_coding/testfile32kHz.pcm",
702 "resources/difficult_photo_1850_1110.yuv",
703 "resources/foreman_cif.yuv",
704 "resources/paris_qcif.yuv",
705 "resources/photo_1850_1110.yuv",
706 "resources/presentation_1850_1110.yuv",
707 "resources/voice_engine/audio_long16.pcm",
708 "resources/web_screenshot_1850_1110.yuv",
712 bundle_data("webrtc_perf_tests_bundle_data") {
714 sources = webrtc_perf_tests_resources
715 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
719 rtc_test("webrtc_perf_tests") {
722 "audio:audio_perf_tests",
723 "call:call_perf_tests",
724 "modules/audio_coding:audio_coding_perf_tests",
725 "modules/audio_processing:audio_processing_perf_tests",
726 "pc:peerconnection_perf_tests",
728 "video:video_full_stack_tests",
729 "video:video_pc_full_stack_tests",
732 data = webrtc_perf_tests_resources
734 use_default_launcher = false
736 "//build/android/gtest_apk:native_test_instrumentation_test_runner_java",
737 "//testing/android/native_test:native_test_java",
738 "//testing/android/native_test:native_test_support",
743 deps += [ ":webrtc_perf_tests_bundle_data" ]
747 rtc_test("webrtc_nonparallel_tests") {
749 deps = [ "rtc_base:rtc_base_nonparallel_tests" ]
751 deps += [ "//testing/android/native_test:native_test_support" ]
756 rtc_test("voip_unittests") {
759 "api/voip:compile_all_headers",
760 "api/voip:voip_engine_factory_unittests",
761 "audio/voip/test:audio_channel_unittests",
762 "audio/voip/test:audio_egress_unittests",
763 "audio/voip/test:audio_ingress_unittests",
764 "audio/voip/test:voip_core_unittests",
770 # Build target for standalone dcsctp
771 rtc_static_library("dcsctp") {
772 # Only the root target should depend on this.
773 visibility = [ "//:default" ]
775 complete_static_lib = true
776 suppressed_configs += [ "//build/config/compiler:thin_archive" ]
779 "net/dcsctp/public:factory",
780 "net/dcsctp/public:socket",
781 "net/dcsctp/public:types",
782 "net/dcsctp/socket:dcsctp_socket",
783 "net/dcsctp/timer:task_queue_timeout",
789 # Here is one empty dummy target for each poison type (needed because
790 # "being poisonous with poison type foo" is implemented as "depends on
793 # The set of poison_* targets needs to be kept in sync with the
794 # `all_poison_types` list in webrtc.gni.
796 group("poison_audio_codecs") {
799 group("poison_default_task_queue") {
802 group("poison_default_echo_detector") {
805 group("poison_rtc_json") {
808 group("poison_software_video_codecs") {