• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2013 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
5import("//build/config/c++/c++.gni")
6import("//build/config/cast.gni")
7import("//build/config/chrome_build.gni")
8import("//build/config/dcheck_always_on.gni")
9import("//build/config/features.gni")
10
11# Subprojects need to override arguments in {mac,ios}_sdk_overrides.gni in their
12# .gn config, but those arguments are only used on macOS. Including
13# mac_sdk_overrides.gni insures that this doesn't trigger an unused argument
14# warning.
15import("//build/config/ios/ios_sdk_overrides.gni")
16import("//build/config/mac/mac_sdk_overrides.gni")
17
18import("//build/config/pch.gni")
19import("//build/config/rust.gni")
20import("//build/config/sanitizers/sanitizers.gni")
21import("//build/config/ui.gni")
22import("//build/toolchain/goma.gni")
23if (is_android) {
24  import("//build/config/android/abi.gni")
25}
26
27# ==============================================
28#   PLEASE DO NOT ADD MORE THINGS TO THIS LIST
29# ==============================================
30#
31# Legacy feature defines applied to all targets.
32#
33# These are applied to every single compile in the build and most of them are
34# only relevant to a few files. This bloats command lines and causes
35# unnecessary recompiles when flags are flipped.
36#
37# To pass defines to source code from the build, use the buildflag system which
38# will write headers containing the defines you need. This isolates the define
39# and means its definition can participate in the build graph, only recompiling
40# things when it actually changes.
41#
42# See //build/buildflag_header.gni for instructions on generating headers.
43#
44# This will also allow you to scope your build flag to a BUILD.gn file (or a
45# .gni file if you need it from more than one place) rather than making global
46# flags. See //build/config/BUILDCONFIG.gn for advice on where to define
47# build flags.
48config("feature_flags") {
49  defines = []
50  if (dcheck_always_on) {
51    defines += [ "DCHECK_ALWAYS_ON=1" ]
52  }
53  if (use_udev) {
54    # TODO(brettw) should probably be "=1".
55    defines += [ "USE_UDEV" ]
56  }
57  if (use_aura) {
58    defines += [ "USE_AURA=1" ]
59  }
60  if (use_glib) {
61    defines += [ "USE_GLIB=1" ]
62  }
63  if (use_ozone && !is_android) {
64    # Chrome code should check BUILDFLAG(IS_OZONE) instead of
65    # defined(USE_OZONE).
66    #
67    # Note that some Chrome OS builds unconditionally set |use_ozone| to true,
68    # but they also build some targets with the Android toolchain. This ensures
69    # that Android targets still build with USE_OZONE=0 in such cases.
70    #
71    # TODO(crbug.com/837032): Maybe this can be cleaned up if we can avoid
72    # setting use_ozone globally.
73    defines += [ "USE_OZONE=1" ]
74  }
75  if (is_asan || is_hwasan || is_lsan || is_tsan || is_msan) {
76    defines += [ "MEMORY_TOOL_REPLACES_ALLOCATOR" ]
77  }
78  if (is_asan) {
79    defines += [ "ADDRESS_SANITIZER" ]
80  }
81  if (is_lsan) {
82    defines += [ "LEAK_SANITIZER" ]
83  }
84  if (is_tsan) {
85    defines += [
86      "THREAD_SANITIZER",
87      "DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1",
88    ]
89  }
90  if (is_msan) {
91    defines += [ "MEMORY_SANITIZER" ]
92  }
93  if (is_ubsan || is_ubsan_vptr || is_ubsan_security) {
94    defines += [ "UNDEFINED_SANITIZER" ]
95  }
96  if (is_official_build) {
97    defines += [ "OFFICIAL_BUILD" ]
98  }
99
100  # ==============================================
101  #   PLEASE DO NOT ADD MORE THINGS TO THIS LIST
102  # ==============================================
103  #
104  # See the comment at the top.
105}
106
107# Debug/release ----------------------------------------------------------------
108
109config("debug") {
110  defines = [
111    "_DEBUG",
112    "DYNAMIC_ANNOTATIONS_ENABLED=1",
113  ]
114
115  if (is_nacl) {
116    defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ]
117  }
118
119  if (is_win) {
120    if (!enable_iterator_debugging && !use_custom_libcxx) {
121      # Iterator debugging is enabled by default by the compiler on debug
122      # builds, and we have to tell it to turn it off.
123      defines += [ "_HAS_ITERATOR_DEBUGGING=0" ]
124    }
125  } else if ((is_linux || is_chromeos) && current_cpu == "x64" &&
126             enable_iterator_debugging) {
127    # Enable libstdc++ debugging facilities to help catch problems early, see
128    # http://crbug.com/65151 .
129    # TODO(phajdan.jr): Should we enable this for all of POSIX?
130    defines += [ "_GLIBCXX_DEBUG=1" ]
131  }
132}
133
134config("release") {
135  defines = [ "NDEBUG" ]
136
137  # Sanitizers.
138  if (is_tsan) {
139    defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=1" ]
140  } else {
141    defines += [ "NVALGRIND" ]
142    if (!is_nacl) {
143      # NaCl always enables dynamic annotations. Currently this value is set to
144      # 1 for all .nexes.
145      defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=0" ]
146    }
147  }
148
149  if (is_ios) {
150    # Disable NSAssert and GTMDevAssert (from Google Toolbox for Mac). This
151    # follows XCode's default behavior for Release builds.
152    defines += [ "NS_BLOCK_ASSERTIONS=1" ]
153  }
154}
155
156# Default libraries ------------------------------------------------------------
157
158# This config defines the default libraries applied to all targets.
159config("default_libs") {
160  if (is_win) {
161    # TODO(brettw) this list of defaults should probably be smaller, and
162    # instead the targets that use the less common ones (e.g. wininet or
163    # winspool) should include those explicitly.
164    libs = [
165      "advapi32.lib",
166      "comdlg32.lib",
167      "dbghelp.lib",
168      "dnsapi.lib",
169      "gdi32.lib",
170      "msimg32.lib",
171      "odbc32.lib",
172      "odbccp32.lib",
173      "oleaut32.lib",
174      "shell32.lib",
175      "shlwapi.lib",
176      "user32.lib",
177      "usp10.lib",
178      "uuid.lib",
179      "version.lib",
180      "wininet.lib",
181      "winmm.lib",
182      "winspool.lib",
183      "ws2_32.lib",
184
185      # Please don't add more stuff here. We should actually be making this
186      # list smaller, since all common things should be covered. If you need
187      # some extra libraries, please just add a libs = [ "foo.lib" ] to your
188      # target that needs it.
189    ]
190    if (current_os == "winuwp") {
191      # These libraries are needed for Windows UWP (i.e. store apps).
192      libs += [
193        "dloadhelper.lib",
194        "WindowsApp.lib",
195      ]
196    } else {
197      # These libraries are not compatible with Windows UWP (i.e. store apps.)
198      libs += [
199        "delayimp.lib",
200        "kernel32.lib",
201        "ole32.lib",
202      ]
203    }
204  } else if (is_android) {
205    libs = [
206      "dl",
207      "m",
208    ]
209  } else if (is_mac) {
210    # Targets should choose to explicitly link frameworks they require. Since
211    # linking can have run-time side effects, nothing should be listed here.
212    libs = []
213  } else if (is_ios) {
214    # Targets should choose to explicitly link frameworks they require. Since
215    # linking can have run-time side effects, nothing should be listed here.
216    libs = []
217  } else if (is_linux || is_chromeos) {
218    libs = [
219      "dl",
220      "pthread",
221      "rt",
222    ]
223  }
224}
225
226group("common_deps") {
227  visibility = [
228    ":executable_deps",
229    ":loadable_module_deps",
230    ":shared_library_deps",
231  ]
232
233  # WARNING: This group is a dependency of **every executable and shared
234  # library**.  Please be careful adding new dependencies here.
235  public_deps = []
236
237  if (using_sanitizer) {
238    public_deps += [ "//build/config/sanitizers:deps" ]
239  }
240
241  if (use_custom_libcxx) {
242    public_deps += [ "//buildtools/third_party/libc++" ]
243  }
244
245  if (use_afl) {
246    public_deps += [ "//third_party/afl" ]
247  }
248
249  if (is_android && use_order_profiling) {
250    public_deps += [ "//base/android/orderfile:orderfile_instrumentation" ]
251  }
252
253  if (is_fuchsia) {
254    public_deps +=
255        [ "//third_party/fuchsia-gn-sdk/src/config:runtime_library_group" ]
256    if (is_asan) {
257      public_deps += [ "//build/config/fuchsia:asan_runtime_library" ]
258    }
259  }
260
261  if (is_win) {
262    # The CRT runtime is dynamically linked in component builds and needs to
263    # be present on bots that run exes or load DLLs. This also includes
264    # debugging DLLs in all builds.
265    data_deps = [ "//build/win:runtime_libs" ]
266  }
267}
268
269# Only the executable template in BUILDCONFIG.gn should reference this.
270group("executable_deps") {
271  if (!toolchain_for_rust_host_build_tools) {
272    public_deps = [ ":common_deps" ]
273    if (export_libcxxabi_from_executables) {
274      public_deps += [ "//buildtools/third_party/libc++abi" ]
275    }
276    public_configs = [ "//build/config/sanitizers:link_executable" ]
277  }
278}
279
280# Only the loadable_module template in BUILDCONFIG.gn should reference this.
281group("loadable_module_deps") {
282  if (!toolchain_for_rust_host_build_tools) {
283    public_deps = [ ":common_deps" ]
284
285    public_configs = [ "//build/config/sanitizers:link_shared_library" ]
286  }
287}
288
289# Only the shared_library template in BUILDCONFIG.gn should reference this.
290group("shared_library_deps") {
291  if (!toolchain_for_rust_host_build_tools) {
292    public_deps = [ ":common_deps" ]
293
294    public_configs = [ "//build/config/sanitizers:link_shared_library" ]
295  }
296}
297
298# Executable configs -----------------------------------------------------------
299
300# Windows linker setup for EXEs and DLLs.
301if (is_win) {
302  _windows_linker_configs = [
303    "//build/config/win:sdk_link",
304    "//build/config/win:common_linker_setup",
305  ]
306}
307
308# This config defines the configs applied to all executables.
309config("executable_config") {
310  configs = []
311
312  if (is_win) {
313    configs += _windows_linker_configs
314  } else if (is_mac) {
315    configs += [ "//build/config/mac:mac_dynamic_flags" ]
316  } else if (is_ios) {
317    configs += [
318      "//build/config/ios:ios_dynamic_flags",
319      "//build/config/ios:ios_executable_flags",
320    ]
321  } else if (is_linux || is_chromeos || is_android || current_os == "aix") {
322    configs += [ "//build/config/gcc:executable_config" ]
323    if (is_castos || is_cast_android) {
324      configs += [ "//build/config/chromecast:executable_config" ]
325    }
326  }
327
328  # If we're using the prebuilt instrumented libraries with the sanitizers, we
329  # need to add ldflags to every binary to make sure they are picked up.
330  if (prebuilt_instrumented_libraries_available) {
331    configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ]
332  }
333  if (use_locally_built_instrumented_libraries) {
334    configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ]
335  }
336}
337
338# Shared library configs -------------------------------------------------------
339
340# This config defines the configs applied to all shared libraries.
341config("shared_library_config") {
342  configs = []
343
344  if (is_win) {
345    configs += _windows_linker_configs
346  } else if (is_mac) {
347    configs += [ "//build/config/mac:mac_dynamic_flags" ]
348  } else if (is_ios) {
349    configs += [
350      "//build/config/ios:ios_dynamic_flags",
351      "//build/config/ios:ios_shared_library_flags",
352    ]
353  } else if (is_castos || is_cast_android) {
354    configs += [ "//build/config/chromecast:shared_library_config" ]
355  } else if (is_linux || is_chromeos || current_os == "aix") {
356    configs += [ "//build/config/gcc:shared_library_config" ]
357  }
358
359  # If we're using the prebuilt instrumented libraries with the sanitizers, we
360  # need to add ldflags to every binary to make sure they are picked up.
361  if (prebuilt_instrumented_libraries_available) {
362    configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ]
363  }
364  if (use_locally_built_instrumented_libraries) {
365    configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ]
366  }
367}
368
369# Add this config to your target to enable precompiled headers.
370#
371# Precompiled headers are done on a per-target basis. If you have just a couple
372# of files, the time it takes to precompile (~2 seconds) can actually be longer
373# than the time saved. On a Z620, a 100 file target compiles about 2 seconds
374# faster with precompiled headers, with greater savings for larger targets.
375#
376# Recommend precompiled headers for targets with more than 50 .cc files.
377config("precompiled_headers") {
378  if (enable_precompiled_headers) {
379    if (is_win) {
380      # This is a string rather than a file GN knows about. It has to match
381      # exactly what's in the /FI flag below, and what might appear in the
382      # source code in quotes for an #include directive.
383      precompiled_header = "build/precompile.h"
384
385      # This is a file that GN will compile with the above header. It will be
386      # implicitly added to the sources (potentially multiple times, with one
387      # variant for each language used in the target).
388      precompiled_source = "//build/precompile.cc"
389
390      # Force include the header.
391      cflags = [ "/FI$precompiled_header" ]
392    } else if (is_mac || is_linux) {
393      precompiled_source = "//build/precompile.h"
394    }
395  }
396}
397
398# Add this config to link steps in order to compress debug sections. This is
399# especially useful on 32-bit architectures in order to keep file sizes under
400# 4gb.
401config("compress_debug_sections") {
402  ldflags = [ "-gz" ]
403}
404