1# Copyright (c) 2013 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/allocator.gni")
6import("//build/config/c++/c++.gni")
7import("//build/config/coverage/coverage.gni")
8import("//build/config/features.gni")
9
10import("//build/config/sanitizers/sanitizers.gni")
11
12declare_args() {
13  # When set (the default) enables C++ iterator debugging in debug builds.
14  # Iterator debugging is always off in release builds (technically, this flag
15  # affects the "debug" config, which is always available but applied by
16  # default only in debug builds).
17  #
18  # Iterator debugging is generally useful for catching bugs. But it can
19  # introduce extra locking to check the state of an iterator against the state
20  # of the current object. For iterator- and thread-heavy code, this can
21  # significantly slow execution.
22  enable_iterator_debugging = true
23  enable_predefined_macro = false
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  # Don't use deprecated V8 APIs anywhere.
49  defines = [ "V8_DEPRECATION_WARNINGS" ]
50  if (use_udev) {
51    defines += [ "USE_UDEV" ]
52  }
53  if (is_win || is_linux) {
54    defines += [ "USE_AURA=1" ]
55  }
56  if (is_linux) {
57    defines += [
58      "USE_GLIB=1",
59      "USE_NSS_CERTS=1",
60      "USE_X11=1",
61    ]
62  }
63
64  if ((is_asan || is_lsan || is_tsan || is_msan) && using_sanitizer) {
65    defines += [
66      "MEMORY_TOOL_REPLACES_ALLOCATOR",
67      "MEMORY_SANITIZER_INITIAL_SIZE",
68    ]
69  }
70  if (is_asan && using_sanitizer) {
71    defines += [ "ADDRESS_SANITIZER" ]
72  }
73  if (is_lsan) {
74    defines += [ "LEAK_SANITIZER" ]
75  }
76  if (is_tsan) {
77    defines += [
78      "THREAD_SANITIZER",
79      "DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1",
80      "WTF_USE_DYNAMIC_ANNOTATIONS_NOIMPL=1",
81    ]
82  }
83  if (is_msan) {
84    defines += [ "MEMORY_SANITIZER" ]
85  }
86  if (is_ubsan || is_ubsan_null || is_ubsan_vptr || is_ubsan_security) {
87    defines += [ "UNDEFINED_SANITIZER" ]
88  }
89  if (use_clang_coverage) {
90    defines += [ "CLANG_COVERAGE" ]
91  }
92  if (is_official_build) {
93    defines += [ "OFFICIAL_BUILD" ]
94  }
95
96  # ==============================================
97  #   PLEASE DO NOT ADD MORE THINGS TO THIS LIST
98  # ==============================================
99  #
100  # See the comment at the top.
101}
102
103# Debug/release ----------------------------------------------------------------
104
105config("debug") {
106  defines = [
107    "DYNAMIC_ANNOTATIONS_ENABLED=1",
108    "WTF_USE_DYNAMIC_ANNOTATIONS=1",
109  ]
110
111  if (is_nacl) {
112    defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ]
113  }
114
115  if (is_win) {
116    if (!enable_iterator_debugging) {
117      # Iterator debugging is enabled by default by the compiler on debug
118      # builds, and we have to tell it to turn it off.
119      defines += [ "_HAS_ITERATOR_DEBUGGING=0" ]
120    }
121  } else if (is_linux && current_cpu == "x64" && enable_iterator_debugging) {
122    # Enable libstdc++ debugging facilities to help catch problems early, see
123    # http://crbug.com/65151 .
124    # defines += [ "_GLIBCXX_DEBUG=1" ]
125  }
126}
127
128config("release") {
129  defines = [ "NDEBUG" ]
130
131  # Sanitizers.
132  if (is_tsan) {
133    defines += [
134      "DYNAMIC_ANNOTATIONS_ENABLED=1",
135      "WTF_USE_DYNAMIC_ANNOTATIONS=1",
136    ]
137  } else {
138    defines += [ "NVALGRIND" ]
139    if (!is_nacl) {
140      # NaCl always enables dynamic annotations. Currently this value is set to
141      # 1 for all .nexes.
142      defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=0" ]
143    }
144  }
145}
146
147# Default libraries ------------------------------------------------------------
148
149# This config defines the default libraries applied to all targets.
150config("default_libs") {
151  if (is_win) {
152    libs = [
153      "advapi32.lib",
154      "comdlg32.lib",
155      "dbghelp.lib",
156      "dnsapi.lib",
157      "gdi32.lib",
158      "msimg32.lib",
159      "odbc32.lib",
160      "odbccp32.lib",
161      "oleaut32.lib",
162      "psapi.lib",
163      "shell32.lib",
164      "shlwapi.lib",
165      "user32.lib",
166      "usp10.lib",
167      "uuid.lib",
168      "version.lib",
169      "wininet.lib",
170      "winmm.lib",
171      "winspool.lib",
172      "ws2_32.lib",
173
174      # Please don't add more stuff here. We should actually be making this
175      # list smaller, since all common things should be covered. If you need
176      # some extra libraries, please just add a libs = [ "foo.lib" ] to your
177      # target that needs it.
178    ]
179    if (current_os == "winuwp") {
180      # These libraries are needed for Windows UWP (i.e. store apps).
181      libs += [
182        "dloadhelper.lib",
183        "WindowsApp.lib",
184      ]
185    } else {
186      # These libraries are not compatible with Windows UWP (i.e. store apps.)
187      libs += [
188        "delayimp.lib",
189        "kernel32.lib",
190        "ole32.lib",
191      ]
192    }
193  } else if (is_ohos) {
194    libs = [
195      "dl",
196      "m",
197    ]
198  } else if (is_mac) {
199    # Targets should choose to explicitly link frameworks they require. Since
200    # linking can have run-time side effects, nothing should be listed here.
201    libs = []
202  } else if (is_linux) {
203    libs = [
204      "dl",
205      "pthread",
206      "rt",
207    ]
208  }
209}
210
211# Only //build/config/BUILDCONFIG.gn should reference this.
212group("common_deps") {
213  public_deps = []
214
215  if (using_sanitizer) {
216    public_deps += [ "//build/config/sanitizers:deps" ]
217  }
218
219  if (use_custom_libcxx) {
220    if (is_double_framework) {
221      public_deps += [ "${asdk_libs_dir}/ndk/libcxx:libcxx" ]
222    } else {
223      public_deps += [ "//third_party/libcxx:libcxx" ]
224    }
225  }
226
227  if (use_afl) {
228    public_deps += [ "//third_party/afl" ]
229  }
230
231  if (is_ohos && use_order_profiling) {
232    public_deps += []
233  }
234
235  if (use_musl && current_toolchain != host_toolchain && !is_mingw) {
236    public_deps += [ "//third_party/musl:soft_shared_libs" ]
237  }
238
239  if (ohos_indep_compiler_enable && current_toolchain != host_toolchain) {
240    deps = [ "//build/common/ubsan:ubsan" ]
241  }
242}
243
244group("executable_deps") {
245  public_deps = [ ":common_deps" ]
246  if (export_libcxxabi_from_executables) {
247    if (!is_double_framework) {
248      public_deps += [ "//third_party/libcxxabi:libc++abi" ]
249    }
250  }
251}
252
253group("loadable_module_deps") {
254  public_deps = [ ":common_deps" ]
255}
256
257group("shared_library_deps") {
258  public_deps = [ ":common_deps" ]
259}
260
261group("rust_library_deps") {
262  public_deps = [ ":common_deps" ]
263}
264
265group("rust_proc_macro_deps") {
266  public_deps = [ ":common_deps" ]
267}
268
269group("static_library_deps") {
270  if (use_musl && current_toolchain != host_toolchain && !is_mingw) {
271    public_deps = [ "//third_party/musl:musl_headers" ]
272  }
273}
274
275group("source_set_deps") {
276  if (use_musl && current_toolchain != host_toolchain && !is_mingw) {
277    public_deps = [ "//third_party/musl:musl_headers" ]
278  }
279}
280
281# Executable configs -----------------------------------------------------------
282
283# Windows linker setup for EXEs and DLLs.
284if (is_win) {
285  _windows_linker_configs = [
286    "//build/config/win:sdk_link",
287    "//build/config/win:common_linker_setup",
288  ]
289}
290
291# This config defines the configs applied to all executables.
292config("executable_config") {
293  configs = []
294
295  if (is_win) {
296    configs += _windows_linker_configs
297
298    # Currently only turn on linker CFI for executables.
299    configs += [ "//build/config/win:cfi_linker" ]
300  } else if (is_mac) {
301    configs += [ "//build/config/mac:mac_dynamic_flags" ]
302  } else if (is_linux || is_ohos || current_os == "aix") {
303    configs += [ "//build/config/gcc:executable_ldconfig" ]
304    if (is_ohos) {
305      configs += [ "//build/config/ohos:executable_config" ]
306    } else if (is_linux) {
307      configs += [ "//build/config/linux:executable_config" ]
308    }
309  }
310
311  # If we're using the prebuilt instrumented libraries with the sanitizers, we
312  # need to add ldflags to every binary to make sure they are picked up.
313  if (prebuilt_instrumented_libraries_available) {
314    configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ]
315  }
316  if (use_locally_built_instrumented_libraries) {
317    configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ]
318  }
319  configs += [ "//build/config/sanitizers:link_executable" ]
320}
321
322# Shared library configs -------------------------------------------------------
323
324# This config defines the configs applied to all shared libraries.
325config("shared_library_config") {
326  configs = []
327
328  if (is_win) {
329    configs += _windows_linker_configs
330  } else if (is_mac) {
331    configs += [ "//build/config/mac:mac_dynamic_flags" ]
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_libraries:prebuilt_ldflags" ]
338  }
339  if (use_locally_built_instrumented_libraries) {
340    configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ]
341  }
342  configs += [ "//build/config/sanitizers:link_shared_library" ]
343}
344
345config("predefined_macro") {
346  if (enable_predefined_macro) {
347    defines = []
348    if (is_ohos) {
349      defines += [ "__OHOS__" ]
350    }
351    if (is_mac) {
352      defines += [ "__MAC__" ]
353    }
354    if (is_linux) {
355      defines += [ "__LINUX__" ]
356    }
357    if (is_nacl) {
358      defines += [ "__NACL__" ]
359    }
360    if (is_win) {
361      defines += [ "__WINDOWS__" ]
362    }
363    if (is_mingw) {
364      defines += [ "___MINGW32__" ]
365    }
366    if (is_android) {
367      defines += [ "__ANDROID__" ]
368    }
369    if (is_ios) {
370      defines += [ "__IOS__" ]
371    }
372    if (current_cpu == "x86") {
373      defines += [ "__x86_32__" ]
374    }
375    if (current_cpu == "x86_64") {
376      defines += [ "__x86_64__" ]
377    }
378    if (current_cpu == "arm") {
379      defines += [ "__arm32__" ]
380    }
381    if (current_cpu == "arm64") {
382      defines += [ "__arm64__" ]
383    }
384  }
385}
386