xref: /aosp_15_r20/external/webrtc/third_party/abseil-cpp/absl.gni (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1# Copyright 2020 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# This file contains the definition of the template absl_source_set which
6# should be the only type of target needed in abseil's BUILD.gn files.
7# This template will correctly set "configs" and "public_configs" in order
8# to correctly compile abseil in Chromium.
9#
10# Usage:
11# Most of the times its usage will be similar to the example below but all
12# the arguments avilable in source_set are also available for absl_source_set.
13#
14#  absl_source_set("foo") {
15#    sources = [ "foo.cc" ]
16#    public = [ "foo.h" ]
17#    deps = [ ":bar" ]
18#  }
19
20import("//build_overrides/build.gni")
21
22template("absl_source_set") {
23  source_set(target_name) {
24    forward_variables_from(invoker, "*")
25    configs -= [ "//build/config/compiler:chromium_code" ]
26    configs += [
27      "//build/config/compiler:no_chromium_code",
28      "//build/config/compiler:prevent_unsafe_narrowing",
29      "//third_party/abseil-cpp:absl_default_cflags_cc",
30      "//third_party/abseil-cpp:absl_define_config",
31    ]
32
33    if (is_component_build) {
34      defines = [ "ABSL_BUILD_DLL" ]
35      if (!is_win) {
36        configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
37        configs += [ "//build/config/gcc:symbol_visibility_default" ]
38      }
39    }
40
41    if (!defined(public_configs)) {
42      public_configs = []
43    }
44    public_configs += [ "//third_party/abseil-cpp:absl_include_config" ]
45
46    if (!defined(visibility)) {
47      # Within Chromium builds, restrict direct visibility of Abseil sources, so
48      # users must depend on //third_party/abseil-cpp:absl. This prevents use of
49      # banned targets like absl/types:any. A few targets require exceptions.
50      # TODO(crbug.com/1096380): Consider replacing build_with_chromium with
51      # is_component_build for a narrower, more accurate condition.
52      if (build_with_chromium) {
53        visibility = [
54          # Abseil itself.
55          "//third_party/abseil-cpp/*",
56
57          # GTest.  It unconditionally #includes any.h if pretty-print support
58          # for absl types is enabled.
59          "//third_party/googletest/*",
60
61          # WebRTC binary to run PSNR and SSIM video quality analysis. It
62          # statically links absl and it is used by "browser_tests" when
63          # is_component_build=false but it cannot depend on the absl
64          # component because it uses absl/flags.
65          "//third_party/webrtc/rtc_tools:frame_analyzer",
66
67          # WebRTC binaries used by //:chromium_builder_asan. They both
68          # statically link absl (because they depend on absl/flags) and are
69          # used by Chromium only when is_component_build=false.
70          "//third_party/webrtc/rtc_tools:rtp_generator",
71          "//third_party/webrtc/rtc_tools:video_replay",
72
73          # Not used by Chromium directly.
74          "//chromecast/internal/*",
75          "//libassistant/*",
76        ]
77      } else {
78        visibility = [ "*" ]
79      }
80    }
81  }
82}
83
84template("absl_test") {
85  source_set(target_name) {
86    forward_variables_from(invoker, "*")
87    testonly = true
88    configs -= [ "//build/config/compiler:chromium_code" ]
89    configs += [
90      "//build/config/compiler:no_chromium_code",
91      "//third_party/abseil-cpp:absl_default_cflags_cc",
92      "//third_party/abseil-cpp:absl_define_config",
93      "//third_party/abseil-cpp:absl_test_config",
94    ]
95
96    if (!defined(public_configs)) {
97      public_configs = []
98    }
99    public_configs += [ "//third_party/abseil-cpp:absl_include_config" ]
100
101    visibility = [ "//third_party/abseil-cpp/:*" ]
102    deps += [
103      "//third_party/googletest:gmock",
104      "//third_party/googletest:gtest",
105    ]
106  }
107}
108