summaryrefslogtreecommitdiffstats
path: root/build/config/BUILD.gn
blob: 907dff696244ee11687f243de5f0ae66c5836ae4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/allocator.gni")
import("//build/config/chrome_build.gni")
import("//build/config/chromecast_build.gni")
import("//build/config/crypto.gni")
import("//build/config/features.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/ui.gni")
import("//build/toolchain/goma.gni")

# One common error that happens is that GYP-generated headers within gen/ get
# included rather than the GN-generated ones within gen/ subdirectories.
# TODO(agrieve): Remove once GYP is gone (as well as exec_script exception).
assert(
    exec_script("//build/dir_exists.py", [ "obj.host" ], "string") == "False",
    "GYP artifacts detected in $root_build_dir.$0x0A" +
        "You must wipe this directory before building with GN.")

declare_args() {
  # When set (the default) enables C++ iterator debugging in debug builds.
  # Iterator debugging is always off in release builds (technically, this flag
  # affects the "debug" config, which is always available but applied by
  # default only in debug builds).
  #
  # Iterator debugging is generally useful for catching bugs. But it can
  # introduce extra locking to check the state of an iterator against the state
  # of the current object. For iterator- and thread-heavy code, this can
  # significantly slow execution.
  enable_iterator_debugging = true

  # Set to true to enable dcheck in Release builds.
  dcheck_always_on = false
}

# TODO(brettw) Most of these should be removed. Instead of global feature
# flags, we should have more modular flags that apply only to a target and its
# dependents. For example, depending on the "x11" meta-target should define
# USE_X11 for all dependents so that everything that could use X11 gets the
# define, but anything that doesn't depend on X11 doesn't see it.
#
# For now we define these globally to match the current GYP build.
config("feature_flags") {
  # TODO(brettw) this probably needs to be parameterized.
  defines = [
    "V8_DEPRECATION_WARNINGS",  # Don't use deprecated V8 APIs anywhere.
    "CLD_VERSION=$cld_version",
  ]
  if (enable_mdns) {
    defines += [ "ENABLE_MDNS=1" ]
  }
  if (enable_notifications) {
    defines += [ "ENABLE_NOTIFICATIONS" ]
  }
  if (enable_pepper_cdms) {
    # TODO(brettw) should probably be "=1"
    defines += [ "ENABLE_PEPPER_CDMS" ]
  }
  if (enable_browser_cdms) {
    # TODO(brettw) should probably be "=1"
    defines += [ "ENABLE_BROWSER_CDMS" ]
  }
  if (enable_plugins) {
    defines += [ "ENABLE_PLUGINS=1" ]
  }
  if (enable_pdf) {
    defines += [ "ENABLE_PDF=1" ]
  }
  if (enable_basic_printing || enable_print_preview) {
    # Convenience define for ENABLE_BASIC_PRINTING || ENABLE_PRINT_PREVIEW.
    defines += [ "ENABLE_PRINTING=1" ]
    if (enable_basic_printing) {
      # Enable basic printing support and UI.
      defines += [ "ENABLE_BASIC_PRINTING=1" ]
    }
    if (enable_print_preview) {
      # Enable printing with print preview.
      # Can be defined without ENABLE_BASIC_PRINTING.
      defines += [ "ENABLE_PRINT_PREVIEW=1" ]
    }
  }
  if (enable_spellcheck) {
    defines += [ "ENABLE_SPELLCHECK=1" ]
  }
  if (use_browser_spellchecker) {
    defines += [ "USE_BROWSER_SPELLCHECKER=1" ]
  }
  if (dcheck_always_on) {
    defines += [ "DCHECK_ALWAYS_ON=1" ]
  }
  if (use_udev) {
    # TODO(brettw) should probably be "=1".
    defines += [ "USE_UDEV" ]
  }
  if (ui_compositor_image_transport) {
    # TODO(brettw) should probably be "=1".
    defines += [ "UI_COMPOSITOR_IMAGE_TRANSPORT" ]
  }
  if (use_ash) {
    defines += [ "USE_ASH=1" ]
  }
  if (use_aura) {
    defines += [ "USE_AURA=1" ]
  }
  if (use_pango) {
    defines += [ "USE_PANGO=1" ]
  }
  if (use_cairo) {
    defines += [ "USE_CAIRO=1" ]
  }
  if (use_clipboard_aurax11) {
    defines += [ "USE_CLIPBOARD_AURAX11=1" ]
  }
  if (use_default_render_theme) {
    defines += [ "USE_DEFAULT_RENDER_THEME=1" ]
  }
  if (use_glib) {
    defines += [ "USE_GLIB=1" ]
  }
  if (use_openssl) {
    defines += [ "USE_OPENSSL=1" ]
  }
  if (use_openssl_certs) {
    defines += [ "USE_OPENSSL_CERTS=1" ]
  }
  if (use_nss_certs) {
    defines += [ "USE_NSS_CERTS=1" ]
  }
  if (use_nss_verifier) {
    defines += [ "USE_NSS_VERIFIER=1" ]
  }
  if (use_ozone) {
    defines += [ "USE_OZONE=1" ]
  }
  if (use_x11) {
    defines += [ "USE_X11=1" ]
  }
  if (use_allocator != "tcmalloc") {
    defines += [ "NO_TCMALLOC" ]
  }
  if (is_asan || is_lsan || is_tsan || is_msan) {
    defines += [
      "MEMORY_TOOL_REPLACES_ALLOCATOR",
      "MEMORY_SANITIZER_INITIAL_SIZE",
    ]
  }
  if (is_asan) {
    defines += [ "ADDRESS_SANITIZER" ]
  }
  if (is_lsan) {
    defines += [
      "LEAK_SANITIZER",
      "WTF_USE_LEAK_SANITIZER=1",
    ]
  }
  if (is_tsan) {
    defines += [
      "THREAD_SANITIZER",
      "DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1",
      "WTF_USE_DYNAMIC_ANNOTATIONS_NOIMPL=1",
    ]
  }
  if (is_msan) {
    defines += [ "MEMORY_SANITIZER" ]
  }
  if (is_ubsan || is_ubsan_vptr) {
    defines += [ "UNDEFINED_SANITIZER" ]
  }
  if (enable_webrtc) {
    defines += [ "ENABLE_WEBRTC=1" ]
  }
  if (!enable_nacl) {
    defines += [ "DISABLE_NACL" ]
  }
  if (enable_extensions) {
    defines += [ "ENABLE_EXTENSIONS=1" ]
  }
  if (enable_task_manager) {
    defines += [ "ENABLE_TASK_MANAGER=1" ]
  }
  if (enable_themes) {
    defines += [ "ENABLE_THEMES=1" ]
  }
  if (enable_captive_portal_detection) {
    defines += [ "ENABLE_CAPTIVE_PORTAL_DETECTION=1" ]
  }
  if (enable_session_service) {
    defines += [ "ENABLE_SESSION_SERVICE=1" ]
  }
  if (enable_rlz) {
    defines += [ "ENABLE_RLZ" ]
  }
  if (enable_plugin_installation) {
    defines += [ "ENABLE_PLUGIN_INSTALLATION=1" ]
  }
  if (enable_app_list) {
    defines += [ "ENABLE_APP_LIST=1" ]
  }
  if (enable_settings_app) {
    defines += [ "ENABLE_SETTINGS_APP=1" ]
  }
  if (enable_supervised_users) {
    defines += [ "ENABLE_SUPERVISED_USERS=1" ]
  }
  if (enable_service_discovery) {
    defines += [ "ENABLE_SERVICE_DISCOVERY=1" ]
  }
  if (enable_autofill_dialog) {
    defines += [ "ENABLE_AUTOFILL_DIALOG=1" ]
  }
  if (enable_image_loader_extension) {
    defines += [ "IMAGE_LOADER_EXTENSION=1" ]
  }
  if (enable_topchrome_md) {
    defines += [ "ENABLE_TOPCHROME_MD=1" ]
  }
  if (enable_wayland_server) {
    defines += [ "ENABLE_WAYLAND_SERVER=1" ]
  }
  if (enable_wifi_display) {
    defines += [ "ENABLE_WIFI_DISPLAY=1" ]
  }
  if (proprietary_codecs) {
    defines += [ "USE_PROPRIETARY_CODECS" ]
  }
  if (enable_hangout_services_extension) {
    defines += [ "ENABLE_HANGOUT_SERVICES_EXTENSION=1" ]
  }
  if (enable_video_hole) {
    defines += [ "VIDEO_HOLE=1" ]
  }
  if (safe_browsing_mode == 1) {
    defines += [ "FULL_SAFE_BROWSING" ]
    defines += [ "SAFE_BROWSING_CSD" ]
    defines += [ "SAFE_BROWSING_DB_LOCAL" ]
  } else if (safe_browsing_mode == 2) {
    defines += [ "SAFE_BROWSING_DB_REMOTE" ]
  }
  if (is_official_build) {
    defines += [ "OFFICIAL_BUILD" ]
  }
  if (is_chrome_branded) {
    defines += [ "GOOGLE_CHROME_BUILD" ]
  } else {
    defines += [ "CHROMIUM_BUILD" ]
  }
  if (enable_media_router) {
    defines += [ "ENABLE_MEDIA_ROUTER=1" ]
  }
  if (enable_webvr) {
    defines += [ "ENABLE_WEBVR" ]
  }
  if (is_syzyasan) {
    defines += [
      "SYZYASAN",
      "MEMORY_TOOL_REPLACES_ALLOCATOR",
      "MEMORY_SANITIZER_INITIAL_SIZE",
    ]
  }
  if (!fieldtrial_testing_like_official_build && !is_chrome_branded) {
    defines += [ "FIELDTRIAL_TESTING_ENABLED" ]
  }
}

# Debug/release ----------------------------------------------------------------

config("debug") {
  defines = [
    "_DEBUG",
    "DYNAMIC_ANNOTATIONS_ENABLED=1",
    "WTF_USE_DYNAMIC_ANNOTATIONS=1",
  ]

  if (is_nacl) {
    defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ]
  }

  if (is_win) {
    if (!enable_iterator_debugging) {
      # Iterator debugging is enabled by default by the compiler on debug
      # builds, and we have to tell it to turn it off.
      defines += [ "_HAS_ITERATOR_DEBUGGING=0" ]
    }
  } else if (is_linux && current_cpu == "x64" && enable_iterator_debugging) {
    # Enable libstdc++ debugging facilities to help catch problems early, see
    # http://crbug.com/65151 .
    # TODO(phajdan.jr): Should we enable this for all of POSIX?
    defines += [ "_GLIBCXX_DEBUG=1" ]
  }
}

config("release") {
  defines = [ "NDEBUG" ]

  # Sanitizers.
  # TODO(GYP) The GYP build has "release_valgrind_build == 0" for this
  # condition. When Valgrind is set up, we need to do the same here.
  if (is_tsan) {
    defines += [
      "DYNAMIC_ANNOTATIONS_ENABLED=1",
      "WTF_USE_DYNAMIC_ANNOTATIONS=1",
    ]
  } else {
    defines += [ "NVALGRIND" ]
    if (!is_nacl) {
      # NaCl always enables dynamic annotations. Currently this value is set to
      # 1 for all .nexes.
      defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=0" ]
    }
  }
}

# Default libraries ------------------------------------------------------------

# This config defines the default libraries applied to all targets.
config("default_libs") {
  if (is_win) {
    # TODO(brettw) this list of defaults should probably be smaller, and
    # instead the targets that use the less common ones (e.g. wininet or
    # winspool) should include those explicitly.
    libs = [
      "advapi32.lib",
      "comdlg32.lib",
      "dbghelp.lib",
      "delayimp.lib",
      "dnsapi.lib",
      "gdi32.lib",
      "kernel32.lib",
      "msimg32.lib",
      "odbc32.lib",
      "odbccp32.lib",
      "ole32.lib",
      "oleaut32.lib",
      "psapi.lib",
      "shell32.lib",
      "shlwapi.lib",
      "user32.lib",
      "usp10.lib",
      "uuid.lib",
      "version.lib",
      "wininet.lib",
      "winmm.lib",
      "winspool.lib",
      "ws2_32.lib",

      # Please don't add more stuff here. We should actually be making this
      # list smaller, since all common things should be covered. If you need
      # some extra libraries, please just add a libs = [ "foo.lib" ] to your
      # target that needs it.
    ]
  } else if (is_android) {
    libs = [
      "dl",
      "m",
    ]
  } else if (is_mac) {
    libs = [
      "AppKit.framework",
      "ApplicationServices.framework",
      "Carbon.framework",
      "CoreFoundation.framework",
      "Foundation.framework",
      "IOKit.framework",
      "OpenGL.framework",
      "Security.framework",
    ]
  } else if (is_ios) {
    # The libraries listed here will be specified for both the target and the
    # host. Only the common ones should be listed here.
    libs = [
      "CoreFoundation.framework",
      "CoreGraphics.framework",
      "CoreText.framework",
      "Foundation.framework",
    ]
  } else if (is_linux) {
    libs = [
      "dl",
      "rt",
    ]
  }
}

# Executable configs -----------------------------------------------------------

# Windows linker setup for EXEs and DLLs.
if (is_win) {
  _windows_linker_configs = [
    "//build/config/win:sdk_link",
    "//build/config/win:common_linker_setup",
  ]
}

# This config defines the configs applied to all executables.
config("executable_config") {
  configs = []

  if (is_win) {
    configs += _windows_linker_configs
  } else if (is_mac) {
    configs += [
      "//build/config/mac:mac_dynamic_flags",
      "//build/config/mac:mac_executable_flags",
    ]
  } else if (is_linux || is_android) {
    configs += [ "//build/config/gcc:executable_ldconfig" ]
    if (is_android) {
      configs += [ "//build/config/android:executable_config" ]
    } else if (is_chromecast) {
      configs += [ "//build/config/chromecast:executable_config" ]
    }
  }
}

# Shared library configs -------------------------------------------------------

# This config defines the configs applied to all shared libraries.
config("shared_library_config") {
  configs = []

  if (is_win) {
    configs += _windows_linker_configs
  } else if (is_mac) {
    configs += [ "//build/config/mac:mac_dynamic_flags" ]
  } else if (is_chromecast) {
    configs += [ "//build/config/chromecast:shared_library_config" ]
  }
}

# Add this config to your target to enable precompiled headers.
#
# Precompiled headers are done on a per-target basis. If you have just a couple
# of files, the time it takes to precompile (~2 seconds) can actually be longer
# than the time saved. On a Z620, a 100 file target compiles about 2 seconds
# faster with precompiled headers, with greater savings for larger targets.
#
# Recommend precompiled headers for targets with more than 50 .cc files.
config("precompiled_headers") {
  if (is_win && !is_official_build && !use_goma) {
    # This is a string rather than a file GN knows about. It has to match
    # exactly what's in the /FI flag below, and what might appear in the source
    # code in quotes for an #include directive.
    precompiled_header = "build/precompile.h"

    # This is a file that GN will compile with the above header. It will be
    # implicitly added to the sources (potentially multiple times, with one
    # variant for each language used in the target).
    precompiled_source = "//build/precompile.cc"

    # Force include the header.
    cflags = [ "/FI$precompiled_header" ]

    # Disable warning for "this file was empty after preprocessing". This
    # error is generated only in C mode for ANSI compatibility. It conflicts
    # with precompiled headers since the source file that's "compiled" for
    # making the precompiled header is empty.
    #
    # This error doesn't happen every time. In VS2013, it seems if the .pch
    # file doesn't exist, no error will be generated (probably MS tested this
    # case but forgot the other one?). To reproduce this error, do a build,
    # then delete the precompile.c.obj file, then build again.
    cflags_c = [ "/wd4206" ]
  } else if (is_mac && !is_official_build && !use_goma) {
    precompiled_header = "build/precompile.h"
    precompiled_source = "//build/precompile.h"
  }
}