Update V8 to version 4.4.26.
[chromium-blink-merge.git] / build / config / BUILDCONFIG.gn
blob455ec0d3dc4bebd3cee1b670fe5c87c277c99bfb
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.
5 # =============================================================================
6 # BUILD FLAGS
7 # =============================================================================
9 # This block lists input arguments to the build, along with their default
10 # values. GN requires listing them explicitly so it can validate input and have
11 # a central place to manage the build flags.
13 # If a value is specified on the command line, it will overwrite the defaults
14 # given here, otherwise the default will be injected into the root scope.
16 # KEEP IN ALPHABETICAL ORDER and write a good description for everything.
17 # Use "is_*" names for intrinsic platform descriptions and build modes, and
18 # "use_*" names for optional features libraries, and configurations.
20 if (target_os == "") {
21   target_os = host_os
24 if (target_cpu == "") {
25   if (target_os == "android") {
26     # If we're building for Android, we should assume that we want to
27     # build for ARM by default, not the host_cpu (which is likely x64).
28     # This allows us to not have to specify both target_os and target_cpu
29     # on the command line.
30     target_cpu = "arm"
31   } else {
32     target_cpu = host_cpu
33   }
36 if (current_cpu == "") {
37   current_cpu = target_cpu
39 if (current_os == "") {
40   current_os = target_os
43 declare_args() {
44   # How many symbols to include in the build. This affects the performance of
45   # the build since the symbols are large and dealing with them is slow.
46   #   2 means regular build with symbols.
47   #   1 means minimal symbols, usually enough for backtraces only.
48   #   0 means no symbols.
49   #   -1 means auto-set (off in release, regular in debug).
50   symbol_level = -1
52   # Component build.
53   is_component_build = false
55   # Debug build.
56   is_debug = true
58   # Whether we're a traditional desktop unix.
59   is_desktop_linux = current_os == "linux" && current_os != "chromeos"
61   # Set to true when compiling with the Clang compiler. Typically this is used
62   # to configure warnings.
63   is_clang = current_os == "mac" || current_os == "ios" ||
64              current_os == "linux" || current_os == "chromeos"
66   # Selects the desired build flavor. Official builds get additional
67   # processing to prepare for release. Normally you will want to develop and
68   # test with this flag off.
69   is_official_build = false
71   # Select the desired branding flavor. False means normal Chromium branding,
72   # true means official Google Chrome branding (requires extra Google-internal
73   # resources).
74   is_chrome_branded = false
76   # Compile for Address Sanitizer to find memory bugs.
77   is_asan = false
79   # Compile for Leak Sanitizer to find leaks.
80   is_lsan = false
82   # Compile for Memory Sanitizer to find uninitialized reads.
83   is_msan = false
85   # Compile for Thread Sanitizer to find threading bugs.
86   is_tsan = false
88   if (current_os == "chromeos") {
89     # Allows the target toolchain to be injected as arguments. This is needed
90     # to support the CrOS build system which supports per-build-configuration
91     # toolchains.
92     cros_use_custom_toolchain = false
93   }
96 # =============================================================================
97 # OS DEFINITIONS
98 # =============================================================================
100 # We set these various is_FOO booleans for convenience in writing OS-based
101 # conditions.
103 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
104 # - is_mac is set only for desktop Mac. It is not set on iOS.
105 # - is_posix is true for mac and any Unix-like system (basically everything
106 #   except Windows).
107 # - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
108 #   generally too different despite being based on the Linux kernel).
110 # Do not add more is_* variants here for random lesser-used Unix systems like
111 # aix or one of the BSDs. If you need to check these, just check the
112 # current_os value directly.
114 if (current_os == "win") {
115   is_android = false
116   is_chromeos = false
117   is_ios = false
118   is_linux = false
119   is_mac = false
120   is_nacl = false
121   is_posix = false
122   is_win = true
123 } else if (current_os == "mac") {
124   is_android = false
125   is_chromeos = false
126   is_ios = false
127   is_linux = false
128   is_mac = true
129   is_nacl = false
130   is_posix = true
131   is_win = false
132 } else if (current_os == "android") {
133   is_android = true
134   is_chromeos = false
135   is_ios = false
136   is_linux = false
137   is_mac = false
138   is_nacl = false
139   is_posix = true
140   is_win = false
141 } else if (current_os == "chromeos") {
142   is_android = false
143   is_chromeos = true
144   is_ios = false
145   is_linux = true
146   is_mac = false
147   is_nacl = false
148   is_posix = true
149   is_win = false
150 } else if (current_os == "nacl") {
151   # current_os == "nacl" will be passed by the nacl toolchain definition.
152   # It is not set by default or on the command line. We treat is as a
153   # Posix variant.
154   is_android = false
155   is_chromeos = false
156   is_ios = false
157   is_linux = false
158   is_mac = false
159   is_nacl = true
160   is_posix = true
161   is_win = false
162 } else if (current_os == "ios") {
163   is_android = false
164   is_chromeos = false
165   is_ios = true
166   is_linux = false
167   is_mac = false
168   is_nacl = false
169   is_posix = true
170   is_win = false
171 } else if (current_os == "linux") {
172   is_android = false
173   is_chromeos = false
174   is_ios = false
175   is_linux = true
176   is_mac = false
177   is_nacl = false
178   is_posix = true
179   is_win = false
182 # =============================================================================
183 # SOURCES FILTERS
184 # =============================================================================
186 # These patterns filter out platform-specific files when assigning to the
187 # sources variable. The magic variable |sources_assignment_filter| is applied
188 # to each assignment or appending to the sources variable and matches are
189 # automatcally removed.
191 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
192 # boundary = end of string or slash) are supported, and the entire string
193 # muct match the pattern (so you need "*.cc" to match all .cc files, for
194 # example).
196 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
197 # below.
198 sources_assignment_filter = []
199 if (!is_posix) {
200   sources_assignment_filter += [
201     "*_posix.h",
202     "*_posix.cc",
203     "*_posix_unittest.h",
204     "*_posix_unittest.cc",
205     "*\bposix/*",
206   ]
208 if (!is_win) {
209   sources_assignment_filter += [
210     "*_win.cc",
211     "*_win.h",
212     "*_win_unittest.cc",
213     "*\bwin/*",
214     "*.rc",
215   ]
217 if (!is_mac) {
218   sources_assignment_filter += [
219     "*_mac.h",
220     "*_mac.cc",
221     "*_mac.mm",
222     "*_mac_unittest.h",
223     "*_mac_unittest.cc",
224     "*_mac_unittest.mm",
225     "*\bmac/*",
226     "*_cocoa.h",
227     "*_cocoa.cc",
228     "*_cocoa.mm",
229     "*_cocoa_unittest.h",
230     "*_cocoa_unittest.cc",
231     "*_cocoa_unittest.mm",
232     "*\bcocoa/*",
233   ]
235 if (!is_ios) {
236   sources_assignment_filter += [
237     "*_ios.h",
238     "*_ios.cc",
239     "*_ios.mm",
240     "*_ios_unittest.h",
241     "*_ios_unittest.cc",
242     "*_ios_unittest.mm",
243     "*\bios/*",
244   ]
246 if (!is_mac && !is_ios) {
247   sources_assignment_filter += [ "*.mm" ]
249 if (!is_linux) {
250   sources_assignment_filter += [
251     "*_linux.h",
252     "*_linux.cc",
253     "*_linux_unittest.h",
254     "*_linux_unittest.cc",
255     "*\blinux/*",
256   ]
258 if (!is_android) {
259   sources_assignment_filter += [
260     "*_android.h",
261     "*_android.cc",
262     "*_android_unittest.h",
263     "*_android_unittest.cc",
264     "*\bandroid/*",
265   ]
267 if (!is_chromeos) {
268   sources_assignment_filter += [
269     "*_chromeos.h",
270     "*_chromeos.cc",
271     "*_chromeos_unittest.h",
272     "*_chromeos_unittest.cc",
273     "*\bchromeos/*",
274   ]
277 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
278 # below.
280 # Actually save this list.
282 # These patterns are executed for every file in the source tree of every run.
283 # Therefore, adding more patterns slows down the build for everybody. We should
284 # only add automatic patterns for configurations affecting hundreds of files
285 # across many projects in the tree.
287 # Therefore, we only add rules to this list corresponding to platforms on the
288 # Chromium waterfall.  This is not for non-officially-supported platforms
289 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
290 # write a conditional in the target to remove the file(s) from the list when
291 # your platform/toolkit/feature doesn't apply.
292 set_sources_assignment_filter(sources_assignment_filter)
294 # =============================================================================
295 # BUILD OPTIONS
296 # =============================================================================
298 # These Sanitizers all imply using the Clang compiler. On Windows they either
299 # don't work or work differently.
300 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
301   is_clang = true
304 # =============================================================================
305 # TARGET DEFAULTS
306 # =============================================================================
308 # Set up the default configuration for every build target of the given type.
309 # The values configured here will be automatically set on the scope of the
310 # corresponding target. Target definitions can add or remove to the settings
311 # here as needed.
313 # Holds all configs used for making native executables and libraries, to avoid
314 # duplication in each target below.
315 _native_compiler_configs = [
316   "//build/config:feature_flags",
317   "//build/config/compiler:compiler",
318   "//build/config/compiler:compiler_arm_fpu",
319   "//build/config/compiler:chromium_code",
320   "//build/config/compiler:default_include_dirs",
321   "//build/config/compiler:default_warnings",
322   "//build/config/compiler:no_rtti",
323   "//build/config/compiler:runtime_library",
325 if (is_win) {
326   _native_compiler_configs += [
327     "//build/config/win:lean_and_mean",
328     "//build/config/win:nominmax",
329     "//build/config/win:sdk",
330     "//build/config/win:unicode",
331     "//build/config/win:winver",
332   ]
334 if (is_posix) {
335   _native_compiler_configs += [
336     "//build/config/gcc:no_exceptions",
337     "//build/config/gcc:symbol_visibility_hidden",
338   ]
341 if (is_linux) {
342   _native_compiler_configs += [ "//build/config/linux:sdk" ]
343 } else if (is_mac) {
344   _native_compiler_configs += [ "//build/config/mac:sdk" ]
345 } else if (is_ios) {
346   _native_compiler_configs += [ "//build/config/ios:sdk" ]
347 } else if (is_android) {
348   _native_compiler_configs += [ "//build/config/android:sdk" ]
351 if (is_clang) {
352   _native_compiler_configs += [
353     "//build/config/clang:find_bad_constructs",
354     "//build/config/clang:extra_warnings",
355   ]
358 # Optimizations and debug checking.
359 if (is_debug) {
360   _native_compiler_configs += [ "//build/config:debug" ]
361   _default_optimization_config = "//build/config/compiler:no_optimize"
362 } else {
363   _native_compiler_configs += [ "//build/config:release" ]
364   _default_optimization_config = "//build/config/compiler:optimize"
366 _native_compiler_configs += [ _default_optimization_config ]
368 # If it wasn't manually set, set to an appropriate default.
369 if (symbol_level == -1) {
370   # Linux is slowed by having symbols as part of the target binary, whereas
371   # Mac and Windows have them separate, so in Release Linux, default them off.
372   if (is_debug || !is_linux) {
373     symbol_level = 2
374   } else {
375     symbol_level = 0
376   }
379 # Symbol setup.
380 if (symbol_level == 2) {
381   _default_symbols_config = "//build/config/compiler:symbols"
382 } else if (symbol_level == 1) {
383   _default_symbols_config = "//build/config/compiler:minimal_symbols"
384 } else if (symbol_level == 0) {
385   _default_symbols_config = "//build/config/compiler:no_symbols"
386 } else {
387   assert(false, "Bad value for symbol_level.")
389 _native_compiler_configs += [ _default_symbols_config ]
391 # Windows linker setup for EXEs and DLLs.
392 if (is_win) {
393   _windows_linker_configs = [
394     "//build/config/win:default_incremental_linking",
395     "//build/config/win:sdk_link",
396     "//build/config/win:common_linker_setup",
398     # Default to console-mode apps. Most of our targets are tests and such
399     # that shouldn't use the windows subsystem.
400     "//build/config/win:console",
401   ]
404 # Executable defaults.
405 _executable_configs =
406     _native_compiler_configs + [ "//build/config:default_libs" ]
407 if (is_win) {
408   _executable_configs += _windows_linker_configs
409 } else if (is_mac) {
410   _executable_configs += [
411     "//build/config/mac:mac_dynamic_flags",
412     "//build/config/mac:mac_executable_flags",
413   ]
414 } else if (is_linux || is_android) {
415   _executable_configs += [ "//build/config/gcc:executable_ldconfig" ]
416   if (is_android) {
417     _executable_configs += [ "//build/config/android:executable_config" ]
418   }
420 set_defaults("executable") {
421   configs = _executable_configs
424 # Static library defaults.
425 set_defaults("static_library") {
426   configs = _native_compiler_configs
429 # Shared library defaults (also for components in component mode).
430 _shared_library_configs =
431     _native_compiler_configs + [ "//build/config:default_libs" ]
432 if (is_win) {
433   _shared_library_configs += _windows_linker_configs
434 } else if (is_mac) {
435   _shared_library_configs += [ "//build/config/mac:mac_dynamic_flags" ]
436 } else if (is_android) {
437   # Strip native JNI exports from shared libraries by default. Binaries that
438   # want this can remove this config.
439   _shared_library_configs +=
440       [ "//build/config/android:hide_native_jni_exports" ]
442 set_defaults("shared_library") {
443   configs = _shared_library_configs
445 if (is_component_build) {
446   set_defaults("component") {
447     configs = _shared_library_configs
448   }
451 # Source set defaults (also for components in non-component mode).
452 set_defaults("source_set") {
453   configs = _native_compiler_configs
455 if (!is_component_build) {
456   set_defaults("component") {
457     configs = _native_compiler_configs
458   }
461 # Test defaults.
462 set_defaults("test") {
463   if (is_android) {
464     configs = _shared_library_configs
465   } else {
466     configs = _executable_configs
467   }
470 # ==============================================================================
471 # TOOLCHAIN SETUP
472 # ==============================================================================
474 # Here we set the default toolchain, as well as the variable host_toolchain
475 # which will identify the toolchain corresponding to the local system when
476 # doing cross-compiles. When not cross-compiling, this will be the same as the
477 # default toolchain.
479 if (is_win) {
480   # On windows we use the same toolchain for host and target by default.
481   # TODO(dpranke): rename the toolchains to x64 and x86 to match current_cpu.
482   if (current_cpu == "x64") {
483     host_toolchain = "//build/toolchain/win:64"
484   } else if (current_cpu == "x86") {
485     host_toolchain = "//build/toolchain/win:32"
486   }
487   set_default_toolchain("$host_toolchain")
488 } else if (is_android) {
489   # Use clang for the x86/64 Linux host builds.
490   if (host_cpu == "x86" || host_cpu == "x64") {
491     host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
492   } else {
493     host_toolchain = "//build/toolchain/linux:$host_cpu"
494   }
495   set_default_toolchain("//build/toolchain/android:$current_cpu")
496 } else if (is_linux) {
497   if (is_clang) {
498     host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
499     set_default_toolchain("//build/toolchain/linux:clang_$current_cpu")
500   } else {
501     host_toolchain = "//build/toolchain/linux:$host_cpu"
502     set_default_toolchain("//build/toolchain/linux:$current_cpu")
503   }
504   if (is_chromeos && cros_use_custom_toolchain) {
505     set_default_toolchain("//build/toolchain/cros:target")
506   }
507 } else if (is_mac) {
508   host_toolchain = "//build/toolchain/mac:clang"
509   set_default_toolchain(host_toolchain)
510 } else if (is_ios) {
511   host_toolchain = "//build/toolchain/mac:host_clang"
512   set_default_toolchain("//build/toolchain/mac:clang")
513 } else if (is_nacl) {
514   # TODO(GYP): This will need to change when we get NaCl working
515   # on multiple platforms, but this whole block of code (how we define
516   # host_toolchain) needs to be reworked regardless to key off of host_os
517   # and host_cpu rather than the is_* variables.
518   host_toolchain = "//build/toolchain/linux:clang_x64"
521 # ==============================================================================
522 # COMPONENT SETUP
523 # ==============================================================================
525 # TODO(brettw) erase this once the built-in "component" function is removed.
526 if (is_component_build) {
527   component_mode = "shared_library"
528 } else {
529   component_mode = "source_set"
532 template("component") {
533   if (is_component_build) {
534     shared_library(target_name) {
535       # Configs will always be defined since we set_defaults for a component
536       # above. We want to use those rather than whatever came with the nested
537       # shared/static library inside the component.
538       configs = []  # Prevent list overwriting warning.
539       configs = invoker.configs
541       # The sources assignment filter will have already been applied when the
542       # code was originally executed. We don't want to apply it again, since
543       # the original target may have override it for some assignments.
544       set_sources_assignment_filter([])
546       if (defined(invoker.all_dependent_configs)) {
547         all_dependent_configs = invoker.all_dependent_configs
548       }
549       if (defined(invoker.allow_circular_includes_from)) {
550         allow_circular_includes_from = invoker.allow_circular_includes_from
551       }
552       if (defined(invoker.cflags)) {
553         cflags = invoker.cflags
554       }
555       if (defined(invoker.cflags_c)) {
556         cflags_c = invoker.cflags_c
557       }
558       if (defined(invoker.cflags_cc)) {
559         cflags_cc = invoker.cflags_cc
560       }
561       if (defined(invoker.cflags_objc)) {
562         cflags_objc = invoker.cflags_objc
563       }
564       if (defined(invoker.cflags_objcc)) {
565         cflags_objcc = invoker.cflags_objcc
566       }
567       if (defined(invoker.check_includes)) {
568         check_includes = invoker.check_includes
569       }
570       if (defined(invoker.data)) {
571         data = invoker.data
572       }
573       if (defined(invoker.data_deps)) {
574         data_deps = invoker.data_deps
575       }
576       if (defined(invoker.datadeps)) {
577         datadeps = invoker.datadeps
578       }
579       if (defined(invoker.defines)) {
580         defines = invoker.defines
581       }
583       # All shared libraries must have the sanitizer deps to properly link in
584       # asan mode (this target will be empty in other cases).
585       if (defined(invoker.deps)) {
586         deps = invoker.deps + [ "//build/config/sanitizers:deps" ]
587       } else {
588         deps = [
589           "//build/config/sanitizers:deps",
590         ]
591       }
592       if (defined(invoker.direct_dependent_configs)) {
593         direct_dependent_configs = invoker.direct_dependent_configs
594       }
595       if (defined(invoker.forward_dependent_configs_from)) {
596         forward_dependent_configs_from = invoker.forward_dependent_configs_from
597       }
598       if (defined(invoker.include_dirs)) {
599         include_dirs = invoker.include_dirs
600       }
601       if (defined(invoker.ldflags)) {
602         ldflags = invoker.ldflags
603       }
604       if (defined(invoker.lib_dirs)) {
605         lib_dirs = invoker.lib_dirs
606       }
607       if (defined(invoker.libs)) {
608         libs = invoker.libs
609       }
610       if (defined(invoker.output_extension)) {
611         output_extension = invoker.output_extension
612       }
613       if (defined(invoker.output_name)) {
614         output_name = invoker.output_name
615       }
616       if (defined(invoker.public)) {
617         public = invoker.public
618       }
619       if (defined(invoker.public_configs)) {
620         public_configs = invoker.public_configs
621       }
622       if (defined(invoker.public_deps)) {
623         public_deps = invoker.public_deps
624       }
625       if (defined(invoker.sources)) {
626         sources = invoker.sources
627       }
628       if (defined(invoker.testonly)) {
629         testonly = invoker.testonly
630       }
631       if (defined(invoker.visibility)) {
632         visibility = invoker.visibility
633       }
634     }
635   } else {
636     source_set(target_name) {
637       # See above.
638       configs = []  # Prevent list overwriting warning.
639       configs = invoker.configs
641       # See above call.
642       set_sources_assignment_filter([])
644       if (defined(invoker.all_dependent_configs)) {
645         all_dependent_configs = invoker.all_dependent_configs
646       }
647       if (defined(invoker.allow_circular_includes_from)) {
648         allow_circular_includes_from = invoker.allow_circular_includes_from
649       }
650       if (defined(invoker.cflags)) {
651         cflags = invoker.cflags
652       }
653       if (defined(invoker.cflags_c)) {
654         cflags_c = invoker.cflags_c
655       }
656       if (defined(invoker.cflags_cc)) {
657         cflags_cc = invoker.cflags_cc
658       }
659       if (defined(invoker.cflags_objc)) {
660         cflags_objc = invoker.cflags_objc
661       }
662       if (defined(invoker.cflags_objcc)) {
663         cflags_objcc = invoker.cflags_objcc
664       }
665       if (defined(invoker.check_includes)) {
666         check_includes = invoker.check_includes
667       }
668       if (defined(invoker.data)) {
669         data = invoker.data
670       }
671       if (defined(invoker.data_deps)) {
672         data_deps = invoker.data_deps
673       }
674       if (defined(invoker.datadeps)) {
675         datadeps = invoker.datadeps
676       }
677       if (defined(invoker.defines)) {
678         defines = invoker.defines
679       }
680       if (defined(invoker.deps)) {
681         deps = invoker.deps
682       }
683       if (defined(invoker.direct_dependent_configs)) {
684         direct_dependent_configs = invoker.direct_dependent_configs
685       }
686       if (defined(invoker.forward_dependent_configs_from)) {
687         forward_dependent_configs_from = invoker.forward_dependent_configs_from
688       }
689       if (defined(invoker.include_dirs)) {
690         include_dirs = invoker.include_dirs
691       }
692       if (defined(invoker.ldflags)) {
693         ldflags = invoker.ldflags
694       }
695       if (defined(invoker.lib_dirs)) {
696         lib_dirs = invoker.lib_dirs
697       }
698       if (defined(invoker.libs)) {
699         libs = invoker.libs
700       }
701       if (defined(invoker.output_extension)) {
702         output_extension = invoker.output_extension
703       }
704       if (defined(invoker.output_name)) {
705         output_name = invoker.output_name
706       }
707       if (defined(invoker.public)) {
708         public = invoker.public
709       }
710       if (defined(invoker.public_configs)) {
711         public_configs = invoker.public_configs
712       }
713       if (defined(invoker.public_deps)) {
714         public_deps = invoker.public_deps
715       }
716       if (defined(invoker.sources)) {
717         sources = invoker.sources
718       }
719       if (defined(invoker.testonly)) {
720         testonly = invoker.testonly
721       }
722       if (defined(invoker.visibility)) {
723         visibility = invoker.visibility
724       }
725     }
726   }