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 (is_ohos && ohos_indep_compiler_enable &&
240      current_toolchain != host_toolchain) {
241    deps = [ "//build/common/ubsan:ubsan" ]
242  }
243}
244
245group("executable_deps") {
246  public_deps = [ ":common_deps" ]
247  if (export_libcxxabi_from_executables) {
248    if (!is_double_framework) {
249      public_deps += [ "//third_party/libcxxabi:libc++abi" ]
250    }
251  }
252}
253
254group("loadable_module_deps") {
255  public_deps = [ ":common_deps" ]
256}
257
258group("shared_library_deps") {
259  public_deps = [ ":common_deps" ]
260}
261
262group("rust_library_deps") {
263  public_deps = [ ":common_deps" ]
264}
265
266group("rust_proc_macro_deps") {
267  public_deps = [ ":common_deps" ]
268}
269
270group("static_library_deps") {
271  if (use_musl && current_toolchain != host_toolchain && !is_mingw) {
272    public_deps = [ "//third_party/musl:musl_headers" ]
273  }
274}
275
276group("source_set_deps") {
277  if (use_musl && current_toolchain != host_toolchain && !is_mingw) {
278    public_deps = [ "//third_party/musl:musl_headers" ]
279  }
280}
281
282# Executable configs -----------------------------------------------------------
283
284# Windows linker setup for EXEs and DLLs.
285if (is_win) {
286  _windows_linker_configs = [
287    "//build/config/win:sdk_link",
288    "//build/config/win:common_linker_setup",
289  ]
290}
291
292# This config defines the configs applied to all executables.
293config("executable_config") {
294  configs = []
295
296  if (is_win) {
297    configs += _windows_linker_configs
298
299    # Currently only turn on linker CFI for executables.
300    configs += [ "//build/config/win:cfi_linker" ]
301  } else if (is_mac) {
302    configs += [ "//build/config/mac:mac_dynamic_flags" ]
303  } else if (is_linux || is_ohos || current_os == "aix") {
304    configs += [ "//build/config/gcc:executable_ldconfig" ]
305    if (is_ohos) {
306      configs += [ "//build/config/ohos:executable_config" ]
307    } else if (is_linux) {
308      configs += [ "//build/config/linux:executable_config" ]
309    }
310  }
311
312  # If we're using the prebuilt instrumented libraries with the sanitizers, we
313  # need to add ldflags to every binary to make sure they are picked up.
314  if (prebuilt_instrumented_libraries_available) {
315    configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ]
316  }
317  if (use_locally_built_instrumented_libraries) {
318    configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ]
319  }
320  configs += [ "//build/config/sanitizers:link_executable" ]
321}
322
323# Shared library configs -------------------------------------------------------
324
325# This config defines the configs applied to all shared libraries.
326config("shared_library_config") {
327  configs = []
328
329  if (is_win) {
330    configs += _windows_linker_configs
331  } else if (is_mac) {
332    configs += [ "//build/config/mac:mac_dynamic_flags" ]
333  }
334
335  # If we're using the prebuilt instrumented libraries with the sanitizers, we
336  # need to add ldflags to every binary to make sure they are picked up.
337  if (prebuilt_instrumented_libraries_available) {
338    configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ]
339  }
340  if (use_locally_built_instrumented_libraries) {
341    configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ]
342  }
343  configs += [ "//build/config/sanitizers:link_shared_library" ]
344}
345
346config("predefined_macro") {
347  if (enable_predefined_macro) {
348    defines = []
349    if (is_ohos) {
350      defines += [ "__OHOS__" ]
351    }
352    if (is_mac) {
353      defines += [ "__MAC__" ]
354    }
355    if (is_linux) {
356      defines += [ "__LINUX__" ]
357    }
358    if (is_nacl) {
359      defines += [ "__NACL__" ]
360    }
361    if (is_win) {
362      defines += [ "__WINDOWS__" ]
363    }
364    if (is_mingw) {
365      defines += [ "___MINGW32__" ]
366    }
367    if (is_android) {
368      defines += [ "__ANDROID__" ]
369    }
370    if (is_ios) {
371      defines += [ "__IOS__" ]
372    }
373    if (current_cpu == "x86") {
374      defines += [ "__x86_32__" ]
375    }
376    if (current_cpu == "x86_64") {
377      defines += [ "__x86_64__" ]
378    }
379    if (current_cpu == "arm") {
380      defines += [ "__arm32__" ]
381    }
382    if (current_cpu == "arm64") {
383      defines += [ "__arm64__" ]
384    }
385  }
386}
387