blob: 0ca8e18a5bb1ecef7d74ecac665bcab4a6d07a69 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001# 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/chrome_build.gni")
7import("//build/config/chromecast_build.gni")
8import("//build/config/crypto.gni")
9import("//build/config/features.gni")
10import("//build/config/sanitizers/sanitizers.gni")
11import("//build/config/ui.gni")
12import("//build/toolchain/goma.gni")
13
14# One common error that happens is that GYP-generated headers within gen/ get
15# included rather than the GN-generated ones within gen/ subdirectories.
16# TODO(GYP_GONE): Remove once GYP is gone (as well as exec_script exception).
17assert(
18 exec_script("//build/dir_exists.py", [ "obj.host" ], "string") == "False",
19 "GYP artifacts detected in $root_build_dir.$0x0A" +
20 "You must wipe this directory before building with GN.")
21
22declare_args() {
23 # When set (the default) enables C++ iterator debugging in debug builds.
24 # Iterator debugging is always off in release builds (technically, this flag
25 # affects the "debug" config, which is always available but applied by
26 # default only in debug builds).
27 #
28 # Iterator debugging is generally useful for catching bugs. But it can
29 # introduce extra locking to check the state of an iterator against the state
30 # of the current object. For iterator- and thread-heavy code, this can
31 # significantly slow execution.
32 enable_iterator_debugging = true
33
34 # Set to true to enable dcheck in Release builds.
35 dcheck_always_on = false
36
37 # Normally we try to decide whether to use precompiled headers or
38 # not based on the other build arguments, but in some cases it is
39 # easiest to force them off explicitly.
40 disable_precompiled_headers = false
41}
42
43# TODO(brettw) Most of these should be removed. Instead of global feature
44# flags, we should have more modular flags that apply only to a target and its
45# dependents. For example, depending on the "x11" meta-target should define
46# USE_X11 for all dependents so that everything that could use X11 gets the
47# define, but anything that doesn't depend on X11 doesn't see it.
48#
49# For now we define these globally to match the current GYP build.
50config("feature_flags") {
51 # Don't use deprecated V8 APIs anywhere.
52 defines = [ "V8_DEPRECATION_WARNINGS" ]
53 if (enable_mdns) {
54 defines += [ "ENABLE_MDNS=1" ]
55 }
56 if (enable_notifications) {
57 defines += [ "ENABLE_NOTIFICATIONS" ]
58 }
59 if (enable_pepper_cdms) {
60 # TODO(brettw) should probably be "=1"
61 defines += [ "ENABLE_PEPPER_CDMS" ]
62 }
63 if (enable_browser_cdms) {
64 # TODO(brettw) should probably be "=1"
65 defines += [ "ENABLE_BROWSER_CDMS" ]
66 }
67 if (enable_plugins) {
68 defines += [ "ENABLE_PLUGINS=1" ]
69 }
70 if (enable_pdf) {
71 defines += [ "ENABLE_PDF=1" ]
72 }
73 if (enable_basic_printing || enable_print_preview) {
74 # Convenience define for ENABLE_BASIC_PRINTING || ENABLE_PRINT_PREVIEW.
75 defines += [ "ENABLE_PRINTING=1" ]
76 if (enable_basic_printing) {
77 # Enable basic printing support and UI.
78 defines += [ "ENABLE_BASIC_PRINTING=1" ]
79 }
80 if (enable_print_preview) {
81 # Enable printing with print preview.
82 # Can be defined without ENABLE_BASIC_PRINTING.
83 defines += [ "ENABLE_PRINT_PREVIEW=1" ]
84 }
85 }
86 if (enable_spellcheck) {
87 defines += [ "ENABLE_SPELLCHECK=1" ]
88 }
89 if (use_browser_spellchecker) {
90 defines += [ "USE_BROWSER_SPELLCHECKER=1" ]
91 }
92 if (dcheck_always_on) {
93 defines += [ "DCHECK_ALWAYS_ON=1" ]
94 }
95 if (use_udev) {
96 # TODO(brettw) should probably be "=1".
97 defines += [ "USE_UDEV" ]
98 }
99 if (ui_compositor_image_transport) {
100 # TODO(brettw) should probably be "=1".
101 defines += [ "UI_COMPOSITOR_IMAGE_TRANSPORT" ]
102 }
103 if (use_ash) {
104 defines += [ "USE_ASH=1" ]
105 }
106 if (use_aura) {
107 defines += [ "USE_AURA=1" ]
108 }
109 if (use_pango) {
110 defines += [ "USE_PANGO=1" ]
111 }
112 if (use_cairo) {
113 defines += [ "USE_CAIRO=1" ]
114 }
115 if (use_clipboard_aurax11) {
116 defines += [ "USE_CLIPBOARD_AURAX11=1" ]
117 }
118 if (use_default_render_theme) {
119 defines += [ "USE_DEFAULT_RENDER_THEME=1" ]
120 }
121 if (use_glib) {
122 defines += [ "USE_GLIB=1" ]
123 }
124 if (use_openssl_certs) {
125 defines += [ "USE_OPENSSL_CERTS=1" ]
126 }
127 if (use_nss_certs) {
128 defines += [ "USE_NSS_CERTS=1" ]
129 }
130 if (use_ozone) {
131 defines += [ "USE_OZONE=1" ]
132 }
133 if (use_x11) {
134 defines += [ "USE_X11=1" ]
135 }
136 if (use_allocator != "tcmalloc") {
137 defines += [ "NO_TCMALLOC" ]
138 }
139 if (is_asan || is_lsan || is_tsan || is_msan) {
140 defines += [
141 "MEMORY_TOOL_REPLACES_ALLOCATOR",
142 "MEMORY_SANITIZER_INITIAL_SIZE",
143 ]
144 }
145 if (is_asan) {
146 defines += [ "ADDRESS_SANITIZER" ]
147 }
148 if (is_lsan) {
149 defines += [
150 "LEAK_SANITIZER",
151 "WTF_USE_LEAK_SANITIZER=1",
152 ]
153 }
154 if (is_tsan) {
155 defines += [
156 "THREAD_SANITIZER",
157 "DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1",
158 "WTF_USE_DYNAMIC_ANNOTATIONS_NOIMPL=1",
159 ]
160 }
161 if (is_msan) {
162 defines += [ "MEMORY_SANITIZER" ]
163 }
164 if (is_ubsan || is_ubsan_vptr || is_ubsan_security) {
165 defines += [ "UNDEFINED_SANITIZER" ]
166 }
167 if (enable_webrtc) {
168 defines += [ "ENABLE_WEBRTC=1" ]
169 }
170 if (!enable_nacl) {
171 defines += [ "DISABLE_NACL" ]
172 }
173 if (enable_extensions) {
174 defines += [ "ENABLE_EXTENSIONS=1" ]
175 }
176 if (enable_task_manager) {
177 defines += [ "ENABLE_TASK_MANAGER=1" ]
178 }
179 if (enable_themes) {
180 defines += [ "ENABLE_THEMES=1" ]
181 }
182 if (enable_captive_portal_detection) {
183 defines += [ "ENABLE_CAPTIVE_PORTAL_DETECTION=1" ]
184 }
185 if (enable_session_service) {
186 defines += [ "ENABLE_SESSION_SERVICE=1" ]
187 }
188 if (enable_rlz) {
189 defines += [ "ENABLE_RLZ" ]
190 }
191 if (enable_plugin_installation) {
192 defines += [ "ENABLE_PLUGIN_INSTALLATION=1" ]
193 }
194 if (enable_app_list) {
195 defines += [ "ENABLE_APP_LIST=1" ]
196 }
197 if (enable_settings_app) {
198 defines += [ "ENABLE_SETTINGS_APP=1" ]
199 }
200 if (enable_supervised_users) {
201 defines += [ "ENABLE_SUPERVISED_USERS=1" ]
202 }
203 if (enable_service_discovery) {
204 defines += [ "ENABLE_SERVICE_DISCOVERY=1" ]
205 }
206 if (enable_image_loader_extension) {
207 defines += [ "IMAGE_LOADER_EXTENSION=1" ]
208 }
209 if (enable_topchrome_md) {
210 defines += [ "ENABLE_TOPCHROME_MD=1" ]
211 }
212 if (enable_wayland_server) {
213 defines += [ "ENABLE_WAYLAND_SERVER=1" ]
214 }
215 if (enable_wifi_display) {
216 defines += [ "ENABLE_WIFI_DISPLAY=1" ]
217 }
218 if (proprietary_codecs) {
219 defines += [ "USE_PROPRIETARY_CODECS" ]
220 }
221 if (enable_hangout_services_extension) {
222 defines += [ "ENABLE_HANGOUT_SERVICES_EXTENSION=1" ]
223 }
224 if (enable_video_hole) {
225 defines += [ "VIDEO_HOLE=1" ]
226 }
227 if (safe_browsing_mode == 1) {
228 defines += [ "FULL_SAFE_BROWSING" ]
229 defines += [ "SAFE_BROWSING_CSD" ]
230 defines += [ "SAFE_BROWSING_DB_LOCAL" ]
231 } else if (safe_browsing_mode == 2) {
232 defines += [ "SAFE_BROWSING_DB_REMOTE" ]
233 }
234 if (is_official_build) {
235 defines += [ "OFFICIAL_BUILD" ]
236 }
237 if (is_chrome_branded) {
238 defines += [ "GOOGLE_CHROME_BUILD" ]
239 } else {
240 defines += [ "CHROMIUM_BUILD" ]
241 }
242 if (enable_media_router) {
243 defines += [ "ENABLE_MEDIA_ROUTER=1" ]
244 }
245 if (enable_webvr) {
246 defines += [ "ENABLE_WEBVR" ]
247 }
248 if (is_syzyasan) {
249 defines += [
250 "SYZYASAN",
251 "MEMORY_TOOL_REPLACES_ALLOCATOR",
252 "MEMORY_SANITIZER_INITIAL_SIZE",
253 ]
254 }
255 if (!fieldtrial_testing_like_official_build && !is_chrome_branded) {
256 defines += [ "FIELDTRIAL_TESTING_ENABLED" ]
257 }
258}
259
260# Debug/release ----------------------------------------------------------------
261
262config("debug") {
263 defines = [
264 "_DEBUG",
265 "DYNAMIC_ANNOTATIONS_ENABLED=1",
266 "WTF_USE_DYNAMIC_ANNOTATIONS=1",
267 ]
268
269 if (is_nacl) {
270 defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ]
271 }
272
273 if (is_win) {
274 if (!enable_iterator_debugging) {
275 # Iterator debugging is enabled by default by the compiler on debug
276 # builds, and we have to tell it to turn it off.
277 defines += [ "_HAS_ITERATOR_DEBUGGING=0" ]
278 }
279 } else if (is_linux && current_cpu == "x64" && enable_iterator_debugging) {
280 # Enable libstdc++ debugging facilities to help catch problems early, see
281 # http://crbug.com/65151 .
282 # TODO(phajdan.jr): Should we enable this for all of POSIX?
283 defines += [ "_GLIBCXX_DEBUG=1" ]
284 }
285}
286
287config("release") {
288 defines = [ "NDEBUG" ]
289
290 # Sanitizers.
291 if (is_tsan) {
292 defines += [
293 "DYNAMIC_ANNOTATIONS_ENABLED=1",
294 "WTF_USE_DYNAMIC_ANNOTATIONS=1",
295 ]
296 } else {
297 defines += [ "NVALGRIND" ]
298 if (!is_nacl) {
299 # NaCl always enables dynamic annotations. Currently this value is set to
300 # 1 for all .nexes.
301 defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=0" ]
302 }
303 }
304}
305
306# Default libraries ------------------------------------------------------------
307
308# This config defines the default libraries applied to all targets.
309config("default_libs") {
310 if (is_win) {
311 # TODO(brettw) this list of defaults should probably be smaller, and
312 # instead the targets that use the less common ones (e.g. wininet or
313 # winspool) should include those explicitly.
314 libs = [
315 "advapi32.lib",
316 "comdlg32.lib",
317 "dbghelp.lib",
318 "delayimp.lib",
319 "dnsapi.lib",
320 "gdi32.lib",
321 "kernel32.lib",
322 "msimg32.lib",
323 "odbc32.lib",
324 "odbccp32.lib",
325 "ole32.lib",
326 "oleaut32.lib",
327 "psapi.lib",
328 "shell32.lib",
329 "shlwapi.lib",
330 "user32.lib",
331 "usp10.lib",
332 "uuid.lib",
333 "version.lib",
334 "wininet.lib",
335 "winmm.lib",
336 "winspool.lib",
337 "ws2_32.lib",
338
339 # Please don't add more stuff here. We should actually be making this
340 # list smaller, since all common things should be covered. If you need
341 # some extra libraries, please just add a libs = [ "foo.lib" ] to your
342 # target that needs it.
343 ]
344 } else if (is_android) {
345 libs = [
346 "dl",
347 "m",
348 ]
349 } else if (is_mac) {
350 # Targets should choose to explicitly link frameworks they require. Since
351 # linking can have run-time side effects, nothing should be listed here.
352 libs = []
353 } else if (is_ios) {
354 # The libraries listed here will be specified for both the target and the
355 # host. Only the common ones should be listed here.
356 libs = [
357 "CoreFoundation.framework",
358 "CoreGraphics.framework",
359 "CoreText.framework",
360 "Foundation.framework",
361 ]
362 } else if (is_linux) {
363 libs = [
364 "dl",
365 "rt",
366 ]
367 }
368}
369
370# Executable configs -----------------------------------------------------------
371
372# Windows linker setup for EXEs and DLLs.
373if (is_win) {
374 _windows_linker_configs = [
375 "//build/config/win:sdk_link",
376 "//build/config/win:common_linker_setup",
377 ]
378}
379
380# This config defines the configs applied to all executables.
381config("executable_config") {
382 configs = []
383
384 if (is_win) {
385 configs += _windows_linker_configs
386 } else if (is_mac) {
387 configs += [
388 "//build/config/mac:mac_dynamic_flags",
389 "//build/config/mac:mac_executable_flags",
390 ]
391 } else if (is_linux || is_android) {
392 configs += [ "//build/config/gcc:executable_ldconfig" ]
393 if (is_android) {
394 configs += [ "//build/config/android:executable_config" ]
395 } else if (is_chromecast) {
396 configs += [ "//build/config/chromecast:executable_config" ]
397 }
398 }
399}
400
401# Shared library configs -------------------------------------------------------
402
403# This config defines the configs applied to all shared libraries.
404config("shared_library_config") {
405 configs = []
406
407 if (is_win) {
408 configs += _windows_linker_configs
409 } else if (is_mac) {
410 configs += [ "//build/config/mac:mac_dynamic_flags" ]
411 } else if (is_chromecast) {
412 configs += [ "//build/config/chromecast:shared_library_config" ]
413 }
414}
415
416# Add this config to your target to enable precompiled headers.
417#
418# Precompiled headers are done on a per-target basis. If you have just a couple
419# of files, the time it takes to precompile (~2 seconds) can actually be longer
420# than the time saved. On a Z620, a 100 file target compiles about 2 seconds
421# faster with precompiled headers, with greater savings for larger targets.
422#
423# Recommend precompiled headers for targets with more than 50 .cc files.
424config("precompiled_headers") {
425 if (!is_official_build && !use_goma && !disable_precompiled_headers) {
426 if (is_win) {
427 # This is a string rather than a file GN knows about. It has to match
428 # exactly what's in the /FI flag below, and what might appear in the
429 # source code in quotes for an #include directive.
430 precompiled_header = "build/precompile.h"
431
432 # This is a file that GN will compile with the above header. It will be
433 # implicitly added to the sources (potentially multiple times, with one
434 # variant for each language used in the target).
435 precompiled_source = "//build/precompile.cc"
436
437 # Force include the header.
438 cflags = [ "/FI$precompiled_header" ]
439
440 # Disable warning for "this file was empty after preprocessing". This
441 # error is generated only in C mode for ANSI compatibility. It conflicts
442 # with precompiled headers since the source file that's "compiled" for
443 # making the precompiled header is empty.
444 #
445 # This error doesn't happen every time. In VS2013, it seems if the .pch
446 # file doesn't exist, no error will be generated (probably MS tested this
447 # case but forgot the other one?). To reproduce this error, do a build,
448 # then delete the precompile.c.obj file, then build again.
449 cflags_c = [ "/wd4206" ]
450 } else if (is_mac) {
451 precompiled_header = "build/precompile.h"
452 precompiled_source = "//build/precompile.h"
453 }
454 }
455}