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