xref: /aosp_15_r20/external/cronet/build/config/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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
226_toolchain_marker_name =
227    "toolchain_marker_" + get_label_info(current_toolchain, "name")
228group(_toolchain_marker_name) {
229  # Can be used as an assert_no_deps target (assert_no_deps ignores toolchains).
230}
231
232group("common_deps") {
233  visibility = [
234    ":executable_deps",
235    ":loadable_module_deps",
236    ":shared_library_deps",
237  ]
238
239  # WARNING: This group is a dependency of **every executable and shared
240  # library**.  Please be careful adding new dependencies here.
241  public_deps = [ ":$_toolchain_marker_name" ]
242
243  if (using_sanitizer) {
244    public_deps += [ "//build/config/sanitizers:deps" ]
245  }
246
247  if (use_custom_libcxx) {
248    public_deps += [ "//buildtools/third_party/libc++" ]
249  }
250
251  if (use_afl) {
252    public_deps += [ "//third_party/afl" ]
253  }
254
255  if (is_android && use_order_profiling) {
256    public_deps += [ "//base/android/orderfile:orderfile_instrumentation" ]
257  }
258
259  if (is_fuchsia) {
260    public_deps +=
261        [ "//third_party/fuchsia-gn-sdk/src/config:runtime_library_group" ]
262    if (is_asan) {
263      public_deps += [ "//build/config/fuchsia:asan_runtime_library" ]
264    }
265  }
266
267  if (is_win) {
268    # The CRT runtime is dynamically linked in component builds and needs to
269    # be present on bots that run exes or load DLLs. This also includes
270    # debugging DLLs in all builds.
271    data_deps = [ "//build/win:runtime_libs" ]
272  }
273}
274
275# Only the executable template in BUILDCONFIG.gn should reference this.
276group("executable_deps") {
277  if (!toolchain_for_rust_host_build_tools) {
278    public_deps = [ ":common_deps" ]
279    if (export_libcxxabi_from_executables) {
280      public_deps += [ "//buildtools/third_party/libc++abi" ]
281    }
282    public_configs = [ "//build/config/sanitizers:link_executable" ]
283  }
284}
285
286# Only the loadable_module template in BUILDCONFIG.gn should reference this.
287group("loadable_module_deps") {
288  if (!toolchain_for_rust_host_build_tools) {
289    public_deps = [ ":common_deps" ]
290
291    public_configs = [ "//build/config/sanitizers:link_shared_library" ]
292  }
293}
294
295# Only the shared_library template in BUILDCONFIG.gn should reference this.
296group("shared_library_deps") {
297  if (!toolchain_for_rust_host_build_tools) {
298    public_deps = [ ":common_deps" ]
299
300    public_configs = [ "//build/config/sanitizers:link_shared_library" ]
301  }
302}
303
304# Executable configs -----------------------------------------------------------
305
306# Windows linker setup for EXEs and DLLs.
307if (is_win) {
308  _windows_linker_configs = [
309    "//build/config/win:sdk_link",
310    "//build/config/win:common_linker_setup",
311  ]
312}
313
314# This config defines the configs applied to all executables.
315config("executable_config") {
316  configs = []
317
318  if (is_win) {
319    configs += _windows_linker_configs
320  } else if (is_mac) {
321    configs += [ "//build/config/mac:mac_dynamic_flags" ]
322  } else if (is_ios) {
323    configs += [
324      "//build/config/ios:ios_dynamic_flags",
325      "//build/config/ios:ios_executable_flags",
326    ]
327  } else if (is_linux || is_chromeos || is_android || current_os == "aix") {
328    configs += [ "//build/config/gcc:executable_config" ]
329    if (is_castos || is_cast_android) {
330      configs += [ "//build/config/chromecast:executable_config" ]
331    }
332  }
333
334  # If we're using the prebuilt instrumented libraries with the sanitizers, we
335  # need to add ldflags to every binary to make sure they are picked up.
336  if (prebuilt_instrumented_libraries_available) {
337    configs += [ "//third_party/instrumented_libs:prebuilt_ldflags" ]
338  }
339  if (use_locally_built_instrumented_libraries) {
340    configs += [ "//third_party/instrumented_libs:locally_built_ldflags" ]
341  }
342}
343
344# Shared library configs -------------------------------------------------------
345
346# This config defines the configs applied to all shared libraries.
347config("shared_library_config") {
348  configs = []
349
350  if (is_win) {
351    configs += _windows_linker_configs
352  } else if (is_mac) {
353    configs += [ "//build/config/mac:mac_dynamic_flags" ]
354  } else if (is_ios) {
355    configs += [
356      "//build/config/ios:ios_dynamic_flags",
357      "//build/config/ios:ios_shared_library_flags",
358    ]
359  } else if (is_castos || is_cast_android) {
360    configs += [ "//build/config/chromecast:shared_library_config" ]
361  } else if (is_linux || is_chromeos || current_os == "aix") {
362    configs += [ "//build/config/gcc:shared_library_config" ]
363  }
364
365  # If we're using the prebuilt instrumented libraries with the sanitizers, we
366  # need to add ldflags to every binary to make sure they are picked up.
367  if (prebuilt_instrumented_libraries_available) {
368    configs += [ "//third_party/instrumented_libs:prebuilt_ldflags" ]
369  }
370  if (use_locally_built_instrumented_libraries) {
371    configs += [ "//third_party/instrumented_libs:locally_built_ldflags" ]
372  }
373}
374
375# Add this config to your target to enable precompiled headers.
376#
377# Precompiled headers are done on a per-target basis. If you have just a couple
378# of files, the time it takes to precompile (~2 seconds) can actually be longer
379# than the time saved. On a Z620, a 100 file target compiles about 2 seconds
380# faster with precompiled headers, with greater savings for larger targets.
381#
382# Recommend precompiled headers for targets with more than 50 .cc files.
383config("precompiled_headers") {
384  if (enable_precompiled_headers) {
385    if (is_win) {
386      # This is a string rather than a file GN knows about. It has to match
387      # exactly what's in the /FI flag below, and what might appear in the
388      # source code in quotes for an #include directive.
389      precompiled_header = "build/precompile.h"
390
391      # This is a file that GN will compile with the above header. It will be
392      # implicitly added to the sources (potentially multiple times, with one
393      # variant for each language used in the target).
394      precompiled_source = "//build/precompile.cc"
395
396      # Force include the header.
397      cflags = [ "/FI$precompiled_header" ]
398    } else if (is_mac || is_linux) {
399      precompiled_source = "//build/precompile.h"
400    }
401  }
402}
403
404# Add this config to link steps in order to compress debug sections. This is
405# especially useful on 32-bit architectures in order to keep file sizes under
406# 4gb.
407config("compress_debug_sections") {
408  ldflags = [ "-gz" ]
409}
410