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 22declare_args() { 23 absl_build_tests = build_with_chromium 24} 25 26template("absl_source_set") { 27 source_set(target_name) { 28 if (defined(invoker.testonly) && invoker.testonly && !absl_build_tests) { 29 not_needed(invoker, "*") 30 } else { 31 forward_variables_from(invoker, "*") 32 configs -= [ "//build/config/compiler:chromium_code" ] 33 configs += [ 34 "//build/config/compiler:no_chromium_code", 35 "//build/config/compiler:prevent_unsafe_narrowing", 36 "//third_party/abseil-cpp:absl_default_cflags_cc", 37 "//third_party/abseil-cpp:absl_define_config", 38 ] 39 40 if (!defined(defines)) { 41 defines = [] 42 } 43 if (is_component_build) { 44 defines += [ "ABSL_BUILD_DLL" ] 45 if (!is_win && current_os != "aix") { 46 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ] 47 configs += [ "//build/config/gcc:symbol_visibility_default" ] 48 } 49 } 50 51 if (!defined(public_configs)) { 52 public_configs = [] 53 } 54 public_configs += [ "//third_party/abseil-cpp:absl_include_config" ] 55 56 if (!defined(visibility)) { 57 # Within Chromium builds, restrict direct visibility of Abseil sources, so 58 # users must depend on //third_party/abseil-cpp:absl. This prevents use of 59 # banned targets like absl/types:any. A few targets require exceptions. 60 if (build_with_chromium) { 61 visibility = [ 62 # Abseil itself. 63 "//third_party/abseil-cpp/*", 64 65 # GTest. It unconditionally #includes any.h if pretty-print support 66 # for absl types is enabled. 67 "//third_party/googletest/*", 68 ] 69 70 if (!is_component_build) { 71 visibility += [ 72 # Not used by Chromium directly. 73 "//chromecast/internal/*", 74 "//libassistant/*", 75 ] 76 } 77 } else { 78 visibility = [ "*" ] 79 } 80 } 81 } 82 } 83} 84 85template("absl_test") { 86 source_set(target_name) { 87 if (!absl_build_tests) { 88 not_needed(invoker, "*") 89 } else { 90 forward_variables_from(invoker, "*") 91 testonly = true 92 configs -= [ "//build/config/compiler:chromium_code" ] 93 configs += [ 94 "//build/config/compiler:no_chromium_code", 95 "//third_party/abseil-cpp:absl_default_cflags_cc", 96 "//third_party/abseil-cpp:absl_define_config", 97 "//third_party/abseil-cpp:absl_test_config", 98 ] 99 100 if (!defined(public_configs)) { 101 public_configs = [] 102 } 103 public_configs += [ "//third_party/abseil-cpp:absl_include_config" ] 104 105 visibility = [ "//third_party/abseil-cpp/:*" ] 106 deps += [ 107 "//third_party/googletest:gmock", 108 "//third_party/googletest:gtest", 109 ] 110 } 111 } 112} 113