1# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
2#
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.
8
9import("//build/config/linux/pkg_config.gni")
10import("//build/config/sanitizers/sanitizers.gni")
11import("webrtc.gni")
12if (!build_with_mozilla) {
13  import("//third_party/protobuf/proto_library.gni")
14}
15if (is_android) {
16  import("//build/config/android/config.gni")
17  import("//build/config/android/rules.gni")
18}
19
20if (!build_with_chromium && !build_with_mozilla) {
21  group("default") {
22    testonly = true
23    deps = [
24      ":webrtc",
25      "examples",
26      "rtc_tools",
27    ]
28    if (rtc_include_tests) {
29      deps += [ ":webrtc_tests" ]
30    }
31  }
32}
33
34# Contains the defines and includes in common.gypi that are duplicated both as
35# target_defaults and direct_dependent_settings.
36config("common_inherited_config") {
37  defines = []
38  cflags = []
39  ldflags = []
40  if (build_with_mozilla) {
41    defines += [ "WEBRTC_MOZILLA_BUILD" ]
42  }
43
44  # Some tests need to declare their own trace event handlers. If this define is
45  # not set, the first time TRACE_EVENT_* is called it will store the return
46  # value for the current handler in an static variable, so that subsequent
47  # changes to the handler for that TRACE_EVENT_* will be ignored.
48  # So when tests are included, we set this define, making it possible to use
49  # different event handlers in different tests.
50  if (rtc_include_tests) {
51    defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=1" ]
52  } else {
53    defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=0" ]
54  }
55  if (build_with_chromium) {
56    defines += [
57      # TODO(kjellander): Cleanup unused ones and move defines closer to
58      # the source when webrtc:4256 is completed.
59      "FEATURE_ENABLE_VOICEMAIL",
60      "GTEST_RELATIVE_PATH",
61      "WEBRTC_CHROMIUM_BUILD",
62    ]
63    include_dirs = [
64      # The overrides must be included first as that is the mechanism for
65      # selecting the override headers in Chromium.
66      "../webrtc_overrides",
67
68      # Allow includes to be prefixed with webrtc/ in case it is not an
69      # immediate subdirectory of the top-level.
70      ".",
71    ]
72  }
73  if (is_posix) {
74    defines += [ "WEBRTC_POSIX" ]
75  }
76  if (is_ios) {
77    defines += [
78      "WEBRTC_MAC",
79      "WEBRTC_IOS",
80    ]
81  }
82  if (is_linux) {
83    defines += [ "WEBRTC_LINUX" ]
84  }
85  if (is_bsd) {
86    defines += [ "WEBRTC_BSD" ]
87  }
88  if (is_mac) {
89    defines += [ "WEBRTC_MAC" ]
90  }
91  if (is_win) {
92    defines += [
93      "WEBRTC_WIN",
94      "_CRT_SECURE_NO_WARNINGS",  # Suppress warnings about _vsnprinf
95    ]
96  }
97  if (is_android) {
98    defines += [
99      "WEBRTC_LINUX",
100      "WEBRTC_ANDROID",
101    ]
102
103    if (build_with_mozilla) {
104      defines += [ "WEBRTC_ANDROID_OPENSLES" ]
105    }
106  }
107  if (is_chromeos) {
108    defines += [ "CHROMEOS" ]
109  }
110
111  if (rtc_sanitize_coverage != "") {
112    assert(is_clang, "sanitizer coverage requires clang")
113    cflags += [ "-fsanitize-coverage=${rtc_sanitize_coverage}" ]
114    ldflags += [ "-fsanitize-coverage=${rtc_sanitize_coverage}" ]
115  }
116
117  if (is_ubsan) {
118    cflags += [ "-fsanitize=float-cast-overflow" ]
119  }
120
121  # TODO(GYP): Support these in GN.
122  # if (is_bsd) {
123  #   defines += [ "BSD" ]
124  # }
125  # if (is_openbsd) {
126  #   defines += [ "OPENBSD" ]
127  # }
128  # if (is_freebsd) {
129  #   defines += [ "FREEBSD" ]
130  # }
131}
132
133config("common_config") {
134  cflags = []
135  cflags_cc = []
136  defines = []
137
138  if (rtc_enable_protobuf) {
139    defines += [ "WEBRTC_ENABLE_PROTOBUF=1" ]
140  } else {
141    defines += [ "WEBRTC_ENABLE_PROTOBUF=0" ]
142  }
143
144  if (rtc_restrict_logging) {
145    defines += [ "WEBRTC_RESTRICT_LOGGING" ]
146  }
147
148  if (rtc_include_internal_audio_device) {
149    defines += [ "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE" ]
150  }
151
152  if (!rtc_libvpx_build_vp9) {
153    defines += [ "RTC_DISABLE_VP9" ]
154  }
155
156  if (rtc_enable_sctp) {
157    defines += [ "HAVE_SCTP" ]
158  }
159
160  if (rtc_enable_external_auth) {
161    defines += [ "ENABLE_EXTERNAL_AUTH" ]
162  }
163
164  if (build_with_chromium) {
165    defines += [
166      # NOTICE: Since common_inherited_config is used in public_configs for our
167      # targets, there's no point including the defines in that config here.
168      # TODO(kjellander): Cleanup unused ones and move defines closer to the
169      # source when webrtc:4256 is completed.
170      "HAVE_WEBRTC_VIDEO",
171      "HAVE_WEBRTC_VOICE",
172      "LOGGING_INSIDE_WEBRTC",
173      "USE_WEBRTC_DEV_BRANCH",
174    ]
175  } else {
176    if (is_posix) {
177      # Enable more warnings: -Wextra is currently disabled in Chromium.
178      cflags = [
179        "-Wextra",
180
181        # Repeat some flags that get overridden by -Wextra.
182        "-Wno-unused-parameter",
183        "-Wno-missing-field-initializers",
184        "-Wno-strict-overflow",
185      ]
186      cflags_cc = [
187        "-Wnon-virtual-dtor",
188
189        # This is enabled for clang; enable for gcc as well.
190        "-Woverloaded-virtual",
191      ]
192    }
193
194    if (is_clang) {
195      cflags += [
196        "-Wc++11-narrowing",
197        "-Wimplicit-fallthrough",
198        "-Wthread-safety",
199        "-Winconsistent-missing-override",
200        "-Wundef",
201      ]
202
203      # use_xcode_clang only refers to the iOS toolchain, host binaries use
204      # chromium's clang always.
205      if (!is_nacl &&
206          (!use_xcode_clang || current_toolchain == host_toolchain)) {
207        # Flags NaCl (Clang 3.7) and Xcode 7.3 (Clang clang-703.0.31) do not
208        # recognize.
209        cflags += [ "-Wunused-lambda-capture" ]
210      }
211    }
212  }
213
214  if (current_cpu == "arm64") {
215    defines += [ "WEBRTC_ARCH_ARM64" ]
216    defines += [ "WEBRTC_HAS_NEON" ]
217  }
218
219  if (current_cpu == "arm") {
220    defines += [ "WEBRTC_ARCH_ARM" ]
221    if (arm_version >= 7) {
222      defines += [ "WEBRTC_ARCH_ARM_V7" ]
223      if (arm_use_neon) {
224        defines += [ "WEBRTC_HAS_NEON" ]
225      }
226    }
227  }
228
229  if (current_cpu == "mipsel") {
230    defines += [ "MIPS32_LE" ]
231    if (mips_float_abi == "hard") {
232      defines += [ "MIPS_FPU_LE" ]
233    }
234    if (mips_arch_variant == "r2") {
235      defines += [ "MIPS32_R2_LE" ]
236    }
237    if (mips_dsp_rev == 1) {
238      defines += [ "MIPS_DSP_R1_LE" ]
239    } else if (mips_dsp_rev == 2) {
240      defines += [
241        "MIPS_DSP_R1_LE",
242        "MIPS_DSP_R2_LE",
243      ]
244    }
245  }
246
247  if (is_android && !is_clang) {
248    # The Android NDK doesn"t provide optimized versions of these
249    # functions. Ensure they are disabled for all compilers.
250    cflags += [
251      "-fno-builtin-cos",
252      "-fno-builtin-sin",
253      "-fno-builtin-cosf",
254      "-fno-builtin-sinf",
255    ]
256  }
257
258  if (use_libfuzzer || use_drfuzz || use_afl) {
259    # Used in Chromium's overrides to disable logging
260    defines += [ "WEBRTC_UNSAFE_FUZZER_MODE" ]
261  }
262}
263
264config("common_objc") {
265  libs = [ "Foundation.framework" ]
266}
267
268if (!build_with_chromium) {
269  # Target to build all the WebRTC production code.
270  rtc_static_library("webrtc") {
271    # Only the root target should depend on this.
272    visibility = [ "//:default" ]
273
274    sources = []
275    complete_static_lib = true
276    defines = []
277
278    deps = [
279      ":webrtc_common",
280      "api:transport_api",
281      "audio",
282      "call",
283      "common_audio",
284      "common_video",
285      "media",
286      "modules",
287      "modules/video_capture:video_capture_internal_impl",
288      "rtc_base",
289      "system_wrappers:system_wrappers_default",
290      "video",
291      "voice_engine",
292    ]
293
294    if (build_with_mozilla) {
295      deps += [
296        "api:base_peerconnection_api",
297        "api:video_frame_api",
298        "system_wrappers:field_trial_default",
299        "system_wrappers:metrics_default",
300      ]
301    } else {
302      deps += [
303        "api",
304        "logging",
305        "ortc",
306        "p2p",
307        "pc",
308        "sdk",
309        "stats",
310      ]
311    }
312
313    if (rtc_enable_protobuf) {
314      defines += [ "ENABLE_RTC_EVENT_LOG" ]
315      deps += [ "logging:rtc_event_log_proto" ]
316    }
317  }
318
319  if (rtc_include_tests) {
320    # Target to build all the WebRTC tests (but not examples or tools).
321    # Executable in order to get a target that links all WebRTC code.
322    rtc_executable("webrtc_tests") {
323      testonly = true
324
325      # Only the root target should depend on this.
326      visibility = [ "//:default" ]
327
328      deps = [
329        ":rtc_unittests",
330        ":video_engine_tests",
331        ":webrtc_nonparallel_tests",
332        ":webrtc_perf_tests",
333        "common_audio:common_audio_unittests",
334        "common_video:common_video_unittests",
335        "media:rtc_media_unittests",
336        "modules:modules_tests",
337        "modules:modules_unittests",
338        "modules/audio_coding:audio_coding_tests",
339        "modules/audio_processing:audio_processing_tests",
340        "modules/remote_bitrate_estimator:bwe_simulations_tests",
341        "modules/rtp_rtcp:test_packet_masks_metrics",
342        "modules/video_capture:video_capture_internal_impl",
343        "ortc:ortc_unittests",
344        "pc:peerconnection_unittests",
345        "pc:rtc_pc_unittests",
346        "rtc_base:rtc_base_tests_utils",
347        "stats:rtc_stats_unittests",
348        "system_wrappers:system_wrappers_unittests",
349        "test",
350        "video:screenshare_loopback",
351        "video:video_loopback",
352        "voice_engine:voice_engine_unittests",
353      ]
354      if (is_android) {
355        deps += [
356          ":android_junit_tests",
357          "sdk/android:libjingle_peerconnection_android_unittest",
358        ]
359      } else {
360        deps += [ "modules/video_capture:video_capture_tests" ]
361      }
362      if (rtc_enable_protobuf) {
363        deps += [
364          "audio:low_bandwidth_audio_test",
365          "logging:rtc_event_log2rtp_dump",
366        ]
367      }
368    }
369  }
370}
371
372rtc_static_library("webrtc_common") {
373  # TODO(mbonadei): Remove (bugs.webrtc.org/7745)
374  # Enabling GN check triggers cyclic dependency error:
375  # :webrtc_common ->
376  # api:video_frame_api ->
377  # system_wrappers:system_wrappers ->
378  # webrtc_common
379  check_includes = false
380  sources = [
381    "common_types.cc",
382    "common_types.h",
383    "typedefs.h",
384  ]
385
386  if (!build_with_chromium && is_clang) {
387    # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
388    suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
389  }
390}
391
392if (use_libfuzzer || use_drfuzz || use_afl) {
393  # This target is only here for gn to discover fuzzer build targets under
394  # webrtc/test/fuzzers/.
395  group("webrtc_fuzzers_dummy") {
396    testonly = true
397    deps = [
398      "test/fuzzers:webrtc_fuzzer_main",
399    ]
400  }
401}
402
403if (rtc_include_tests) {
404  config("rtc_unittests_config") {
405    # GN orders flags on a target before flags from configs. The default config
406    # adds -Wall, and this flag have to be after -Wall -- so they need to
407    # come from a config and can"t be on the target directly.
408    if (is_clang) {
409      cflags = [
410        "-Wno-sign-compare",
411        "-Wno-unused-const-variable",
412      ]
413    }
414  }
415
416  rtc_test("rtc_unittests") {
417    testonly = true
418
419    deps = [
420      ":webrtc_common",
421      "api:rtc_api_unittests",
422      "api/audio_codecs/test:audio_codecs_api_unittests",
423      "p2p:libstunprober_unittests",
424      "p2p:rtc_p2p_unittests",
425      "rtc_base:rtc_base_approved_unittests",
426      "rtc_base:rtc_base_tests_main",
427      "rtc_base:rtc_base_tests_utils",
428      "rtc_base:rtc_base_unittests",
429      "rtc_base:rtc_numerics_unittests",
430      "rtc_base:rtc_task_queue_unittests",
431      "rtc_base:sequenced_task_checker_unittests",
432      "rtc_base:weak_ptr_unittests",
433      "system_wrappers:metrics_default",
434    ]
435
436    if (rtc_enable_protobuf) {
437      deps += [ "logging:rtc_event_log_tests" ]
438    }
439
440    if (is_android) {
441      deps += [ "//testing/android/native_test:native_test_support" ]
442      shard_timeout = 900
443    }
444
445    if (is_ios || is_mac) {
446      deps += [ "sdk:sdk_unittests_objc" ]
447    }
448  }
449
450  # TODO(pbos): Rename test suite, this is no longer "just" for video targets.
451  video_engine_tests_resources = [
452    "resources/foreman_cif_short.yuv",
453    "resources/voice_engine/audio_long16.pcm",
454  ]
455
456  if (is_ios) {
457    bundle_data("video_engine_tests_bundle_data") {
458      testonly = true
459      sources = video_engine_tests_resources
460      outputs = [
461        "{{bundle_resources_dir}}/{{source_file_part}}",
462      ]
463    }
464  }
465
466  rtc_test("video_engine_tests") {
467    testonly = true
468    deps = [
469      "audio:audio_tests",
470
471      # TODO(eladalon): call_tests aren't actually video-specific, so we
472      # should move them to a more appropriate test suite.
473      "call:call_tests",
474      "modules/video_capture",
475      "rtc_base:rtc_base_tests_utils",
476      "test:test_common",
477      "test:test_main",
478      "test:video_test_common",
479      "video:video_tests",
480    ]
481    data = video_engine_tests_resources
482    if (!build_with_chromium && is_clang) {
483      # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
484      suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
485    }
486    if (is_android) {
487      deps += [ "//testing/android/native_test:native_test_native_code" ]
488      shard_timeout = 900
489    }
490    if (is_ios) {
491      deps += [ ":video_engine_tests_bundle_data" ]
492    }
493  }
494
495  webrtc_perf_tests_resources = [
496    "resources/audio_coding/speech_mono_16kHz.pcm",
497    "resources/audio_coding/speech_mono_32_48kHz.pcm",
498    "resources/audio_coding/testfile32kHz.pcm",
499    "resources/ConferenceMotion_1280_720_50.yuv",
500    "resources/difficult_photo_1850_1110.yuv",
501    "resources/foreman_cif.yuv",
502    "resources/google-wifi-3mbps.rx",
503    "resources/paris_qcif.yuv",
504    "resources/photo_1850_1110.yuv",
505    "resources/presentation_1850_1110.yuv",
506    "resources/verizon4g-downlink.rx",
507    "resources/voice_engine/audio_long16.pcm",
508    "resources/web_screenshot_1850_1110.yuv",
509  ]
510
511  if (is_ios) {
512    bundle_data("webrtc_perf_tests_bundle_data") {
513      testonly = true
514      sources = webrtc_perf_tests_resources
515      outputs = [
516        "{{bundle_resources_dir}}/{{source_file_part}}",
517      ]
518    }
519  }
520
521  rtc_test("webrtc_perf_tests") {
522    testonly = true
523    configs += [ ":rtc_unittests_config" ]
524
525    deps = [
526      "audio:audio_perf_tests",
527      "call:call_perf_tests",
528      "modules/audio_coding:audio_coding_perf_tests",
529      "modules/audio_processing:audio_processing_perf_tests",
530      "modules/remote_bitrate_estimator:remote_bitrate_estimator_perf_tests",
531      "test:test_main",
532      "video:video_full_stack_tests",
533    ]
534
535    data = webrtc_perf_tests_resources
536    if (is_android) {
537      deps += [ "//testing/android/native_test:native_test_native_code" ]
538      shard_timeout = 2700
539    }
540    if (is_ios) {
541      deps += [ ":webrtc_perf_tests_bundle_data" ]
542    }
543  }
544
545  rtc_test("webrtc_nonparallel_tests") {
546    testonly = true
547    deps = [
548      "rtc_base:rtc_base_nonparallel_tests",
549    ]
550    if (is_android) {
551      deps += [ "//testing/android/native_test:native_test_support" ]
552      shard_timeout = 900
553    }
554  }
555
556  if (is_android) {
557    junit_binary("android_junit_tests") {
558      java_files = [
559        "examples/androidjunit/src/org/appspot/apprtc/BluetoothManagerTest.java",
560        "examples/androidjunit/src/org/appspot/apprtc/DirectRTCClientTest.java",
561        "examples/androidjunit/src/org/appspot/apprtc/TCPChannelClientTest.java",
562        "sdk/android/tests/src/org/webrtc/CameraEnumerationTest.java",
563      ]
564
565      deps = [
566        "examples:AppRTCMobile_javalib",
567        "sdk/android:libjingle_peerconnection_java",
568        "//base:base_java_test_support",
569      ]
570    }
571  }
572}
573