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 # =============================================================================
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 # How many symbols to include in the build. This affects the performance of
21 # the build since the symbols are large and dealing with them is slow.
22 # 2 means regular build with symbols.
23 # 1 means minimal symbols, usually enough for backtraces only.
25 # -1 means auto-set (off in release, regular in debug).
29 is_component_build = false
33 # Set to true when compiling with the Clang compiler. Typically this is used
34 # to configure warnings.
35 is_clang = (os == "mac" || os == "ios" || os == "linux")
37 # Forces a 64-bit build on Windows. Does nothing on other platforms. Normally
38 # we build 32-bit on Windows regardless of the current host OS bit depth.
39 # Setting this flag will override this logic and generate 64-bit toolchains.
41 # Normally this would get set automatically when you specify a target using
42 # the 64-bit toolchain. You can also set this on the command line to convert
43 # the default toolchain to 64-bit.
46 # Selects the desired build flavor. Official builds get additional
47 # processing to prepare for release. Normally you will want to develop and
48 # test with this flag off.
49 is_official_build = false
51 # Select the desired branding flavor. False means normal Chromium branding,
52 # true means official Google Chrome branding (requires extra Google-internal
54 is_chrome_branded = false
56 # Compile for Address Sanitizer to find memory bugs.
59 # Compile for Leak Sanitizer to find leaks.
62 # Compile for Memory Sanitizer to find uninitialized reads.
65 # Compile for Thread Sanitizer to find threading bugs.
68 if (os == "chromeos") {
69 # Allows the target toolchain to be injected as arguments. This is needed
70 # to support the CrOS build system which supports per-build-configuration
72 cros_use_custom_toolchain = false
76 # =============================================================================
78 # =============================================================================
80 # We set these various is_FOO booleans for convenience in writing OS-based
83 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
84 # - is_mac is set only for desktop Mac. It is not set on iOS.
85 # - is_posix is true for mac and any Unix-like system (basically everything
87 # - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
88 # generally too different despite being based on the Linux kernel).
90 # Do not add more is_* variants here for random lesser-used Unix systems like
91 # aix or one of the BSDs. If you need to check these, just check the os value
103 } else if (os == "mac") {
112 } else if (os == "android") {
121 } else if (os == "chromeos") {
130 } else if (os == "nacl") {
131 # os == "nacl" will be passed by the nacl toolchain definition. It is not
132 # set by default or on the command line. We treat is as a Posix variant.
141 } else if (os == "ios") {
150 } else if (os == "linux") {
161 is_desktop_linux = is_linux && !is_chromeos
163 # =============================================================================
165 # =============================================================================
168 # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
169 # unless the override flag is specified.
177 # =============================================================================
179 # =============================================================================
181 # These patterns filter out platform-specific files when assigning to the
182 # sources variable. The magic variable |sources_assignment_filter| is applied
183 # to each assignment or appending to the sources variable and matches are
184 # automatcally removed.
186 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
187 # boundary = end of string or slash) are supported, and the entire string
188 # muct match the pattern (so you need "*.cc" to match all .cc files, for
191 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
193 sources_assignment_filter = []
195 sources_assignment_filter += [
198 "*_posix_unittest.h",
199 "*_posix_unittest.cc",
204 sources_assignment_filter += [
213 sources_assignment_filter += [
224 "*_cocoa_unittest.h",
225 "*_cocoa_unittest.cc",
226 "*_cocoa_unittest.mm",
231 sources_assignment_filter += [
241 if (!is_mac && !is_ios) {
242 sources_assignment_filter += [
247 sources_assignment_filter += [
250 "*_linux_unittest.h",
251 "*_linux_unittest.cc",
256 sources_assignment_filter += [
259 "*_android_unittest.h",
260 "*_android_unittest.cc",
265 sources_assignment_filter += [
268 "*_chromeos_unittest.h",
269 "*_chromeos_unittest.cc",
273 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
276 # Actually save this list.
278 # These patterns are executed for every file in the source tree of every run.
279 # Therefore, adding more patterns slows down the build for everybody. We should
280 # only add automatic patterns for configurations affecting hundreds of files
281 # across many projects in the tree.
283 # Therefore, we only add rules to this list corresponding to platforms on the
284 # Chromium waterfall. This is not for non-officially-supported platforms
285 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
286 # write a conditional in the target to remove the file(s) from the list when
287 # your platform/toolkit/feature doesn't apply.
288 set_sources_assignment_filter(sources_assignment_filter)
290 # =============================================================================
292 # =============================================================================
294 # These Sanitizers all imply using the Clang compiler. On Windows they either
295 # don't work or work differently.
296 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
300 # =============================================================================
302 # =============================================================================
304 # Set up the default configuration for every build target of the given type.
305 # The values configured here will be automatically set on the scope of the
306 # corresponding target. Target definitions can add or remove to the settings
309 # Holds all configs used for making native executables and libraries, to avoid
310 # duplication in each target below.
311 _native_compiler_configs = [
312 "//build/config:feature_flags",
314 "//build/config/compiler:compiler",
315 "//build/config/compiler:compiler_arm_fpu",
316 "//build/config/compiler:chromium_code",
317 "//build/config/compiler:default_include_dirs",
318 "//build/config/compiler:default_warnings",
319 "//build/config/compiler:no_rtti",
320 "//build/config/compiler:runtime_library",
323 _native_compiler_configs += [
324 "//build/config/win:lean_and_mean",
325 "//build/config/win:nominmax",
326 "//build/config/win:sdk",
327 "//build/config/win:unicode",
328 "//build/config/win:winver",
332 _native_compiler_configs += [
333 "//build/config/gcc:no_exceptions",
334 "//build/config/gcc:symbol_visibility_hidden",
339 _native_compiler_configs += [ "//build/config/linux:sdk", ]
341 _native_compiler_configs += [ "//build/config/mac:sdk", ]
343 _native_compiler_configs += [ "//build/config/ios:sdk", ]
344 } else if (is_android) {
345 _native_compiler_configs += [ "//build/config/android:sdk", ]
349 _native_compiler_configs += [
350 "//build/config/clang:find_bad_constructs",
351 "//build/config/clang:extra_warnings",
355 # Optimizations and debug checking.
357 _native_compiler_configs += [ "//build/config:debug" ]
358 _default_optimization_config = "//build/config/compiler:no_optimize"
360 _native_compiler_configs += [ "//build/config:release" ]
361 _default_optimization_config = "//build/config/compiler:optimize"
363 _native_compiler_configs += [ _default_optimization_config ]
365 # If it wasn't manually set, set to an appropriate default.
366 if (symbol_level == -1) {
367 # Linux is slowed by having symbols as part of the target binary, whereas
368 # Mac and Windows have them separate, so in Release Linux, default them off.
369 if (is_debug || !is_linux) {
377 if (symbol_level == 2) {
378 _default_symbols_config = "//build/config/compiler:symbols"
379 } else if (symbol_level == 1) {
380 _default_symbols_config = "//build/config/compiler:minimal_symbols"
381 } else if (symbol_level == 0) {
382 _default_symbols_config = "//build/config/compiler:no_symbols"
384 assert(false, "Bad value for symbol_level.")
386 _native_compiler_configs += [ _default_symbols_config ]
388 # Windows linker setup for EXEs and DLLs.
391 _default_incremental_linking_config =
392 "//build/config/win:incremental_linking"
394 _default_incremental_linking_config =
395 "//build/config/win:no_incremental_linking"
397 _windows_linker_configs = [
398 _default_incremental_linking_config,
399 "//build/config/win:sdk_link",
400 "//build/config/win:common_linker_setup",
401 # Default to console-mode apps. Most of our targets are tests and such
402 # that shouldn't use the windows subsystem.
403 "//build/config/win:console",
407 # Executable defaults.
408 _executable_configs = _native_compiler_configs + [
409 "//build/config:default_libs",
412 _executable_configs += _windows_linker_configs
414 _executable_configs += [
415 "//build/config/mac:mac_dynamic_flags",
416 "//build/config/mac:mac_executable_flags" ]
417 } else if (is_linux || is_android) {
418 _executable_configs += [ "//build/config/gcc:executable_ldconfig" ]
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 = _native_compiler_configs + [
431 "//build/config:default_libs",
434 _shared_library_configs += _windows_linker_configs
436 _shared_library_configs += [ "//build/config/mac:mac_dynamic_flags" ]
438 set_defaults("shared_library") {
439 configs = _shared_library_configs
441 if (is_component_build) {
442 set_defaults("component") {
443 configs = _shared_library_configs
447 # Source set defaults (also for components in non-component mode).
448 set_defaults("source_set") {
449 configs = _native_compiler_configs
451 if (!is_component_build) {
452 set_defaults("component") {
453 configs = _native_compiler_configs
458 set_defaults("test") {
460 configs = _shared_library_configs
462 configs = _executable_configs
467 # ==============================================================================
469 # ==============================================================================
471 # Here we set the default toolchain, as well as the variable host_toolchain
472 # which will identify the toolchain corresponding to the local system when
473 # doing cross-compiles. When not cross-compiling, this will be the same as the
477 # TODO(brettw) name the toolchains the same as cpu_arch as with Linux below
478 # to eliminate these conditionals.
479 if (build_cpu_arch == "x64") {
480 host_toolchain = "//build/toolchain/win:64"
481 } else if (build_cpu_arch == "x86") {
482 host_toolchain = "//build/toolchain/win:32"
485 if (cpu_arch == "x64") {
486 set_default_toolchain("//build/toolchain/win:64")
487 } else if (cpu_arch == "x86") {
488 set_default_toolchain("//build/toolchain/win:32")
490 } else if (is_android) {
491 # Use clang for the x86/64 Linux host builds.
492 if (build_cpu_arch == "x86" || build_cpu_arch == "x64") {
493 host_toolchain = "//build/toolchain/linux:clang_$build_cpu_arch"
495 host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
497 set_default_toolchain("//build/toolchain/android:$cpu_arch")
498 } else if (is_linux) {
500 host_toolchain = "//build/toolchain/linux:clang_$build_cpu_arch"
501 set_default_toolchain("//build/toolchain/linux:clang_$cpu_arch")
503 host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
504 set_default_toolchain("//build/toolchain/linux:$cpu_arch")
506 if (is_chromeos && cros_use_custom_toolchain) {
507 set_default_toolchain("//build/toolchain/cros:target")
510 host_toolchain = "//build/toolchain/mac:clang"
511 set_default_toolchain(host_toolchain)
513 host_toolchain = "//build/toolchain/mac:host_clang"
514 set_default_toolchain("//build/toolchain/mac:clang")
517 # ==============================================================================
519 # ==============================================================================
521 # TODO(brettw) erase this once the built-in "component" function is removed.
522 if (is_component_build) {
523 component_mode = "shared_library"
525 component_mode = "source_set"
528 template("component") {
529 if (is_component_build) {
530 shared_library(target_name) {
531 # Configs will always be defined since we set_defaults for a component
532 # above. We want to use those rather than whatever came with the nested
533 # shared/static library inside the component.
534 configs = [] # Prevent list overwriting warning.
535 configs = invoker.configs
537 # The sources assignment filter will have already been applied when the
538 # code was originally executed. We don't want to apply it again, since
539 # the original target may have override it for some assignments.
540 set_sources_assignment_filter([])
542 if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
543 if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
544 if (defined(invoker.cflags)) { cflags = invoker.cflags }
545 if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
546 if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
547 if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
548 if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
549 if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
550 if (defined(invoker.data)) { data = invoker.data }
551 if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
552 if (defined(invoker.defines)) { defines = invoker.defines }
553 if (defined(invoker.deps)) { deps = invoker.deps }
554 if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
555 if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
556 if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
557 if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
558 if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
559 if (defined(invoker.libs)) { libs = invoker.libs }
560 if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
561 if (defined(invoker.output_name)) { output_name = invoker.output_name }
562 if (defined(invoker.public)) { public = invoker.public }
563 if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
564 if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
565 if (defined(invoker.sources)) { sources = invoker.sources }
566 if (defined(invoker.testonly)) { testonly = invoker.testonly }
567 if (defined(invoker.visibility)) { visibility = invoker.visibility }
570 source_set(target_name) {
572 configs = [] # Prevent list overwriting warning.
573 configs = invoker.configs
576 set_sources_assignment_filter([])
578 if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
579 if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
580 if (defined(invoker.cflags)) { cflags = invoker.cflags }
581 if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
582 if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
583 if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
584 if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
585 if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
586 if (defined(invoker.data)) { data = invoker.data }
587 if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
588 if (defined(invoker.defines)) { defines = invoker.defines }
589 if (defined(invoker.deps)) { deps = invoker.deps }
590 if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
591 if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
592 if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
593 if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
594 if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
595 if (defined(invoker.libs)) { libs = invoker.libs }
596 if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
597 if (defined(invoker.output_name)) { output_name = invoker.output_name }
598 if (defined(invoker.public)) { public = invoker.public }
599 if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
600 if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
601 if (defined(invoker.sources)) { sources = invoker.sources }
602 if (defined(invoker.testonly)) { testonly = invoker.testonly }
603 if (defined(invoker.visibility)) { visibility = invoker.visibility }
608 # ==============================================================================
610 # ==============================================================================
612 # Define a test as an executable (or shared_library on Android) with the
613 # "testonly" flag set.
616 shared_library(target_name) {
617 # Configs will always be defined since we set_defaults for a component
618 # above. We want to use those rather than whatever came with the nested
619 # shared/static library inside the component.
620 configs = [] # Prevent list overwriting warning.
621 configs = invoker.configs
624 set_sources_assignment_filter([])
628 if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
629 if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
630 if (defined(invoker.cflags)) { cflags = invoker.cflags }
631 if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
632 if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
633 if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
634 if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
635 if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
636 if (defined(invoker.data)) { data = invoker.data }
637 if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
638 if (defined(invoker.defines)) { defines = invoker.defines }
639 if (defined(invoker.deps)) { deps = invoker.deps }
640 if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
641 if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
642 if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
643 if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
644 if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
645 if (defined(invoker.libs)) { libs = invoker.libs }
646 if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
647 if (defined(invoker.output_name)) { output_name = invoker.output_name }
648 if (defined(invoker.public)) { public = invoker.public }
649 if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
650 if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
651 if (defined(invoker.sources)) { sources = invoker.sources }
652 if (defined(invoker.visibility)) { visibility = invoker.visibility }
655 executable(target_name) {
657 configs = [] # Prevent list overwriting warning.
658 configs = invoker.configs
661 set_sources_assignment_filter([])
665 if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
666 if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
667 if (defined(invoker.cflags)) { cflags = invoker.cflags }
668 if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
669 if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
670 if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
671 if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
672 if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
673 if (defined(invoker.data)) { data = invoker.data }
674 if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
675 if (defined(invoker.defines)) { defines = invoker.defines }
676 if (defined(invoker.deps)) { deps = invoker.deps }
677 if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
678 if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
679 if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
680 if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
681 if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
682 if (defined(invoker.libs)) { libs = invoker.libs }
683 if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
684 if (defined(invoker.output_name)) { output_name = invoker.output_name }
685 if (defined(invoker.public)) { public = invoker.public }
686 if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
687 if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
688 if (defined(invoker.sources)) { sources = invoker.sources }
689 if (defined(invoker.visibility)) { visibility = invoker.visibility }