xref: /aosp_15_r20/external/angle/build/config/BUILD.gn (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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}
276
277group("common_deps") {
278  visibility = [
279    ":executable_deps",
280    ":loadable_module_deps",
281    ":shared_library_deps",
282  ]
283
284  # WARNING: This group is a dependency of **every executable and shared
285  # library**.  Please be careful adding new dependencies here.
286  public_deps = [ ":common_deps_without_libcxx" ]
287
288  if (use_custom_libcxx) {
289    public_deps += [ "//buildtools/third_party/libc++" ]
290  }
291}
292
293# Only the executable template in BUILDCONFIG.gn should reference this.
294group("executable_deps") {
295  if (!toolchain_for_rust_host_build_tools) {
296    public_deps = [ ":common_deps" ]
297    if (export_libcxxabi_from_executables) {
298      public_deps += [ "//buildtools/third_party/libc++abi" ]
299    }
300  }
301}
302
303# Only the loadable_module template in BUILDCONFIG.gn should reference this.
304group("loadable_module_deps") {
305  if (!toolchain_for_rust_host_build_tools) {
306    public_deps = [ ":common_deps" ]
307  }
308}
309
310# Only the shared_library template in BUILDCONFIG.gn should reference this.
311group("shared_library_deps") {
312  if (!toolchain_for_rust_host_build_tools) {
313    public_deps = [ ":common_deps" ]
314  }
315}
316
317# Executable configs -----------------------------------------------------------
318
319# Windows linker setup for EXEs and DLLs.
320if (is_win) {
321  _windows_linker_configs = [
322    "//build/config/win:sdk_link",
323    "//build/config/win:common_linker_setup",
324  ]
325}
326
327# This config defines the configs applied to all executables.
328config("executable_config") {
329  configs = []
330
331  if (is_win) {
332    configs += _windows_linker_configs
333  } else if (is_mac) {
334    configs += [ "//build/config/mac:mac_dynamic_flags" ]
335  } else if (is_ios) {
336    configs += [
337      "//build/config/ios:ios_dynamic_flags",
338      "//build/config/ios:ios_executable_flags",
339    ]
340  } else if (is_linux || is_chromeos || is_android || current_os == "aix") {
341    configs += [ "//build/config/gcc:executable_config" ]
342    if (is_castos || is_cast_android) {
343      configs += [ "//build/config/chromecast:executable_config" ]
344    }
345  }
346
347  # If we're using the prebuilt instrumented libraries with the sanitizers, we
348  # need to add ldflags to every binary to make sure they are picked up.
349  if (prebuilt_instrumented_libraries_available) {
350    configs += [ "//third_party/instrumented_libs:prebuilt_ldflags" ]
351  }
352  if (use_locally_built_instrumented_libraries) {
353    configs += [ "//third_party/instrumented_libs:locally_built_ldflags" ]
354  }
355}
356
357# Shared library configs -------------------------------------------------------
358
359# This config defines the configs applied to all shared libraries.
360config("shared_library_config") {
361  configs = []
362
363  if (is_win) {
364    configs += _windows_linker_configs
365  } else if (is_mac) {
366    configs += [ "//build/config/mac:mac_dynamic_flags" ]
367  } else if (is_ios) {
368    configs += [
369      "//build/config/ios:ios_dynamic_flags",
370      "//build/config/ios:ios_shared_library_flags",
371    ]
372  } else if (is_castos || is_cast_android) {
373    configs += [ "//build/config/chromecast:shared_library_config" ]
374  } else if (is_linux || is_chromeos || current_os == "aix") {
375    configs += [ "//build/config/gcc:shared_library_config" ]
376  }
377
378  # If we're using the prebuilt instrumented libraries with the sanitizers, we
379  # need to add ldflags to every binary to make sure they are picked up.
380  if (prebuilt_instrumented_libraries_available) {
381    configs += [ "//third_party/instrumented_libs:prebuilt_ldflags" ]
382  }
383  if (use_locally_built_instrumented_libraries) {
384    configs += [ "//third_party/instrumented_libs:locally_built_ldflags" ]
385  }
386}
387
388# Add this config to your target to enable precompiled headers.
389#
390# Precompiled headers are done on a per-target basis. If you have just a couple
391# of files, the time it takes to precompile (~2 seconds) can actually be longer
392# than the time saved. On a Z620, a 100 file target compiles about 2 seconds
393# faster with precompiled headers, with greater savings for larger targets.
394#
395# Recommend precompiled headers for targets with more than 50 .cc files.
396config("precompiled_headers") {
397  if (enable_precompiled_headers) {
398    if (is_win) {
399      # This is a string rather than a file GN knows about. It has to match
400      # exactly what's in the /FI flag below, and what might appear in the
401      # source code in quotes for an #include directive.
402      precompiled_header = "build/precompile.h"
403
404      # This is a file that GN will compile with the above header. It will be
405      # implicitly added to the sources (potentially multiple times, with one
406      # variant for each language used in the target).
407      precompiled_source = "//build/precompile.cc"
408
409      # Force include the header.
410      cflags = [ "/FI$precompiled_header" ]
411    } else if (is_mac || is_linux) {
412      precompiled_source = "//build/precompile.h"
413    }
414  }
415}
416
417# Add this config to link steps in order to compress debug sections. This is
418# especially useful on 32-bit architectures in order to keep file sizes under
419# 4gb.
420config("compress_debug_sections") {
421  ldflags = [ "-gz" ]
422}
423