1# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/chrome_build.gni")
6import("//build/config/jumbo.gni")
7import("//third_party/blink/renderer/config.gni")
8
9blink_core_output_dir = "$root_gen_dir/third_party/blink/renderer/core"
10
11# This file sets core_config_add and core_config_remove lists of configs to
12# modify the default lists of configs set in the build as appropriate for core
13# targets. This avoids duplicating logic across many targets.
14core_config_add = [
15  "//build/config/compiler:wexit_time_destructors",
16  "//third_party/blink/renderer:config",
17  "//third_party/blink/renderer:non_test_config",
18  "//third_party/blink/renderer/core:config",
19]
20core_config_remove = []
21
22# Compute the optimization level. The GYP code sets "optimize: max" which sets
23# speed-over-size optimization for official builds on Windows only. The GN's
24# build optimize_max config applies this optimization on all platforms, so
25# compute how to modify the config list to duplicate the GYP behavior.
26# TODO revisit this behavior, as the Windows-specific part seems suspicious.
27if (is_win && is_official_build) {
28  core_config_remove += [ "//build/config/compiler:default_optimization" ]
29  core_config_add += [ "//build/config/compiler:optimize_max" ]
30} else {
31  core_config_remove += [ "//build/config/compiler:default_optimization" ]
32  core_config_add += blink_optimization_config
33}
34
35core_config_remove += [ "//build/config/compiler:default_symbols" ]
36core_config_add += blink_symbols_config
37
38# Use this to generate a static library or source set that gets linked into
39# "core". This will either be a source_set (component build), or a static
40# library.
41#
42# Special values (all unlisted values are forwarded to the underlying library):
43#
44#   configs
45#      Normal meaning. The set_defaults call below will make the default value
46#      of configs in the calling code take into account the core_config_add and
47#      core_config_remove lists above. So you don't need to manually take these
48#      into account: just modify the configs as normal for target-specific
49#      overrides (or don't touch it).
50#
51#   deps
52#      Normal meaning but "core:prerequisites" target is always added. Callers
53#      shouldn't list prerequisites as a dependency.
54#
55#   visibility
56#      Normal meaning if defined. If undefined, defaults to everything in core.
57template("blink_core_sources") {
58  if (is_component_build) {
59    target_type = "jumbo_source_set"
60  } else {
61    target_type = "jumbo_static_library"
62  }
63  target(target_type, target_name) {
64    # The visibility will get overridden by forward_variables_from below if the
65    # invoker defined it.
66    visibility = [ "//third_party/blink/renderer/core/*" ]
67
68    deps = [ "//third_party/blink/renderer/core:prerequisites" ]
69    if (defined(invoker.deps)) {
70      deps += invoker.deps
71    }
72
73    public_deps = [ "//third_party/blink/renderer/core:all_generators" ]
74    if (defined(invoker.public_deps)) {
75      public_deps += invoker.public_deps
76    }
77
78    # Take everything else not handled above from the invoker.
79    forward_variables_from(invoker,
80                           "*",
81                           [
82                             "deps",
83                             "public_deps",
84                           ])
85  }
86}
87set_defaults("blink_core_sources") {
88  # This sets the default list of configs when the blink_core_sources target
89  # is defined. The default_compiler_configs comes from BUILDCONFIG.gn and
90  # is the list normally applied to static libraries and source sets.
91  configs = default_compiler_configs - core_config_remove + core_config_add
92  configs += [ "//third_party/blink/renderer/core:blink_core_pch" ]
93}
94
95template("blink_core_tests") {
96  jumbo_source_set(target_name) {
97    # The visibility will get overridden by forward_variables_from below if the
98    # invoker defined it.
99    visibility = [ "//third_party/blink/renderer/core/*" ]
100    testonly = true
101
102    deps = [
103      "//testing/gmock",
104      "//testing/gtest",
105      "//third_party/blink/renderer/core",
106    ]
107    if (defined(invoker.deps)) {
108      deps += invoker.deps
109    }
110
111    # Take everything else not handled above from the invoker.
112    forward_variables_from(invoker, "*", [ "deps" ])
113  }
114}
115set_defaults("blink_core_tests") {
116  configs = default_compiler_configs
117  configs += [
118    "//third_party/blink/renderer:config",
119    "//third_party/blink/renderer/core:blink_core_pch",
120    "//third_party/blink/renderer:inside_blink",
121  ]
122}
123