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" || os == "chromeos")
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
75 # TODO(cjhopman): Make target_arch work for all platforms.
77 # Architecture of the target device. For Android builds, this will be equal to
78 # the cpu_arch of the default toolchain. When checking the CPU architecture
79 # for source files and build dependencies you should almost alway use cpu_arch
80 # instead. cpu_arch is the architecture of the current toolchain and allows
81 # cross-compiles (compiling the same target for multiple toolchains in the
82 # same build) to work.
86 # =============================================================================
88 # =============================================================================
90 # We set these various is_FOO booleans for convenience in writing OS-based
93 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
94 # - is_mac is set only for desktop Mac. It is not set on iOS.
95 # - is_posix is true for mac and any Unix-like system (basically everything
97 # - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
98 # generally too different despite being based on the Linux kernel).
100 # Do not add more is_* variants here for random lesser-used Unix systems like
101 # aix or one of the BSDs. If you need to check these, just check the os value
113 } else if (os == "mac") {
122 } else if (os == "android") {
131 } else if (os == "chromeos") {
140 } else if (os == "nacl") {
141 # os == "nacl" will be passed by the nacl toolchain definition. It is not
142 # set by default or on the command line. We treat is as a Posix variant.
151 } else if (os == "ios") {
160 } else if (os == "linux") {
171 is_desktop_linux = is_linux && !is_chromeos
173 # =============================================================================
175 # =============================================================================
178 # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
179 # unless the override flag is specified.
188 # TODO(cjhopman): enable this assert once bots are updated to not set
190 #assert(cpu_arch == build_cpu_arch, "Android device target architecture should
191 # be set with 'target_arch', not 'cpu_arch'")
192 cpu_arch = target_arch
195 # =============================================================================
197 # =============================================================================
199 # These patterns filter out platform-specific files when assigning to the
200 # sources variable. The magic variable |sources_assignment_filter| is applied
201 # to each assignment or appending to the sources variable and matches are
202 # automatcally removed.
204 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
205 # boundary = end of string or slash) are supported, and the entire string
206 # muct match the pattern (so you need "*.cc" to match all .cc files, for
209 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
211 sources_assignment_filter = []
213 sources_assignment_filter += [
216 "*_posix_unittest.h",
217 "*_posix_unittest.cc",
222 sources_assignment_filter += [
231 sources_assignment_filter += [
242 "*_cocoa_unittest.h",
243 "*_cocoa_unittest.cc",
244 "*_cocoa_unittest.mm",
249 sources_assignment_filter += [
259 if (!is_mac && !is_ios) {
260 sources_assignment_filter += [
265 sources_assignment_filter += [
268 "*_linux_unittest.h",
269 "*_linux_unittest.cc",
274 sources_assignment_filter += [
277 "*_android_unittest.h",
278 "*_android_unittest.cc",
283 sources_assignment_filter += [
286 "*_chromeos_unittest.h",
287 "*_chromeos_unittest.cc",
291 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
294 # Actually save this list.
296 # These patterns are executed for every file in the source tree of every run.
297 # Therefore, adding more patterns slows down the build for everybody. We should
298 # only add automatic patterns for configurations affecting hundreds of files
299 # across many projects in the tree.
301 # Therefore, we only add rules to this list corresponding to platforms on the
302 # Chromium waterfall. This is not for non-officially-supported platforms
303 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
304 # write a conditional in the target to remove the file(s) from the list when
305 # your platform/toolkit/feature doesn't apply.
306 set_sources_assignment_filter(sources_assignment_filter)
308 # =============================================================================
310 # =============================================================================
312 # These Sanitizers all imply using the Clang compiler. On Windows they either
313 # don't work or work differently.
314 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
318 # =============================================================================
320 # =============================================================================
322 # Set up the default configuration for every build target of the given type.
323 # The values configured here will be automatically set on the scope of the
324 # corresponding target. Target definitions can add or remove to the settings
327 # Holds all configs used for making native executables and libraries, to avoid
328 # duplication in each target below.
329 _native_compiler_configs = [
330 "//build/config:feature_flags",
332 "//build/config/compiler:compiler",
333 "//build/config/compiler:compiler_arm_fpu",
334 "//build/config/compiler:chromium_code",
335 "//build/config/compiler:default_include_dirs",
336 "//build/config/compiler:default_warnings",
337 "//build/config/compiler:no_rtti",
338 "//build/config/compiler:runtime_library",
341 _native_compiler_configs += [
342 "//build/config/win:lean_and_mean",
343 "//build/config/win:nominmax",
344 "//build/config/win:sdk",
345 "//build/config/win:unicode",
346 "//build/config/win:winver",
350 _native_compiler_configs += [
351 "//build/config/gcc:no_exceptions",
352 "//build/config/gcc:symbol_visibility_hidden",
357 _native_compiler_configs += [ "//build/config/linux:sdk", ]
359 _native_compiler_configs += [ "//build/config/mac:sdk", ]
361 _native_compiler_configs += [ "//build/config/ios:sdk", ]
362 } else if (is_android) {
363 _native_compiler_configs += [ "//build/config/android:sdk", ]
367 _native_compiler_configs += [
368 "//build/config/clang:find_bad_constructs",
369 "//build/config/clang:extra_warnings",
373 # Optimizations and debug checking.
375 _native_compiler_configs += [ "//build/config:debug" ]
376 _default_optimization_config = "//build/config/compiler:no_optimize"
378 _native_compiler_configs += [ "//build/config:release" ]
379 _default_optimization_config = "//build/config/compiler:optimize"
381 _native_compiler_configs += [ _default_optimization_config ]
383 # If it wasn't manually set, set to an appropriate default.
384 if (symbol_level == -1) {
385 # Linux is slowed by having symbols as part of the target binary, whereas
386 # Mac and Windows have them separate, so in Release Linux, default them off.
387 if (is_debug || !is_linux) {
395 if (symbol_level == 2) {
396 _default_symbols_config = "//build/config/compiler:symbols"
397 } else if (symbol_level == 1) {
398 _default_symbols_config = "//build/config/compiler:minimal_symbols"
399 } else if (symbol_level == 0) {
400 _default_symbols_config = "//build/config/compiler:no_symbols"
402 assert(false, "Bad value for symbol_level.")
404 _native_compiler_configs += [ _default_symbols_config ]
406 # Windows linker setup for EXEs and DLLs.
409 _default_incremental_linking_config =
410 "//build/config/win:incremental_linking"
412 _default_incremental_linking_config =
413 "//build/config/win:no_incremental_linking"
415 _windows_linker_configs = [
416 _default_incremental_linking_config,
417 "//build/config/win:sdk_link",
418 "//build/config/win:common_linker_setup",
419 # Default to console-mode apps. Most of our targets are tests and such
420 # that shouldn't use the windows subsystem.
421 "//build/config/win:console",
425 # Executable defaults.
426 _executable_configs = _native_compiler_configs + [
427 "//build/config:default_libs",
430 _executable_configs += _windows_linker_configs
432 _executable_configs += [
433 "//build/config/mac:mac_dynamic_flags",
434 "//build/config/mac:mac_executable_flags" ]
435 } else if (is_linux || is_android) {
436 _executable_configs += [ "//build/config/gcc:executable_ldconfig" ]
438 _executable_configs += [ "//build/config/android:executable_config" ]
441 set_defaults("executable") {
442 configs = _executable_configs
445 # Static library defaults.
446 set_defaults("static_library") {
447 configs = _native_compiler_configs
450 # Shared library defaults (also for components in component mode).
451 _shared_library_configs = _native_compiler_configs + [
452 "//build/config:default_libs",
455 _shared_library_configs += _windows_linker_configs
457 _shared_library_configs += [ "//build/config/mac:mac_dynamic_flags" ]
459 set_defaults("shared_library") {
460 configs = _shared_library_configs
462 if (is_component_build) {
463 set_defaults("component") {
464 configs = _shared_library_configs
468 # Source set defaults (also for components in non-component mode).
469 set_defaults("source_set") {
470 configs = _native_compiler_configs
472 if (!is_component_build) {
473 set_defaults("component") {
474 configs = _native_compiler_configs
479 set_defaults("test") {
481 configs = _shared_library_configs
483 configs = _executable_configs
488 # ==============================================================================
490 # ==============================================================================
492 # Here we set the default toolchain, as well as the variable host_toolchain
493 # which will identify the toolchain corresponding to the local system when
494 # doing cross-compiles. When not cross-compiling, this will be the same as the
498 # TODO(brettw) name the toolchains the same as cpu_arch as with Linux below
499 # to eliminate these conditionals.
500 if (build_cpu_arch == "x64") {
501 host_toolchain = "//build/toolchain/win:64"
502 } else if (build_cpu_arch == "x86") {
503 host_toolchain = "//build/toolchain/win:32"
506 if (cpu_arch == "x64") {
507 set_default_toolchain("//build/toolchain/win:64")
508 } else if (cpu_arch == "x86") {
509 set_default_toolchain("//build/toolchain/win:32")
511 } else if (is_android) {
512 # Use clang for the x86/64 Linux host builds.
513 if (build_cpu_arch == "x86" || build_cpu_arch == "x64") {
514 host_toolchain = "//build/toolchain/linux:clang_$build_cpu_arch"
516 host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
518 set_default_toolchain("//build/toolchain/android:$cpu_arch")
519 } else if (is_linux) {
521 host_toolchain = "//build/toolchain/linux:clang_$build_cpu_arch"
522 set_default_toolchain("//build/toolchain/linux:clang_$cpu_arch")
524 host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
525 set_default_toolchain("//build/toolchain/linux:$cpu_arch")
527 if (is_chromeos && cros_use_custom_toolchain) {
528 set_default_toolchain("//build/toolchain/cros:target")
531 host_toolchain = "//build/toolchain/mac:clang"
532 set_default_toolchain(host_toolchain)
534 host_toolchain = "//build/toolchain/mac:host_clang"
535 set_default_toolchain("//build/toolchain/mac:clang")
538 # ==============================================================================
540 # ==============================================================================
542 # TODO(brettw) erase this once the built-in "component" function is removed.
543 if (is_component_build) {
544 component_mode = "shared_library"
546 component_mode = "source_set"
549 template("component") {
550 if (is_component_build) {
551 shared_library(target_name) {
552 # Configs will always be defined since we set_defaults for a component
553 # above. We want to use those rather than whatever came with the nested
554 # shared/static library inside the component.
555 configs = [] # Prevent list overwriting warning.
556 configs = invoker.configs
558 # The sources assignment filter will have already been applied when the
559 # code was originally executed. We don't want to apply it again, since
560 # the original target may have override it for some assignments.
561 set_sources_assignment_filter([])
563 if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
564 if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
565 if (defined(invoker.cflags)) { cflags = invoker.cflags }
566 if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
567 if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
568 if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
569 if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
570 if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
571 if (defined(invoker.data)) { data = invoker.data }
572 if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
573 if (defined(invoker.defines)) { defines = invoker.defines }
574 # All shared libraries must have the sanitizer deps to properly link in
575 # asan mode (this target will be empty in other cases).
576 if (defined(invoker.deps)) {
577 deps = invoker.deps + [ "//build/config/sanitizers:deps" ]
579 deps = [ "//build/config/sanitizers:deps" ]
581 if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
582 if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
583 if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
584 if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
585 if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
586 if (defined(invoker.libs)) { libs = invoker.libs }
587 if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
588 if (defined(invoker.output_name)) { output_name = invoker.output_name }
589 if (defined(invoker.public)) { public = invoker.public }
590 if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
591 if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
592 if (defined(invoker.sources)) { sources = invoker.sources }
593 if (defined(invoker.testonly)) { testonly = invoker.testonly }
594 if (defined(invoker.visibility)) { visibility = invoker.visibility }
597 source_set(target_name) {
599 configs = [] # Prevent list overwriting warning.
600 configs = invoker.configs
603 set_sources_assignment_filter([])
605 if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
606 if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
607 if (defined(invoker.cflags)) { cflags = invoker.cflags }
608 if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
609 if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
610 if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
611 if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
612 if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
613 if (defined(invoker.data)) { data = invoker.data }
614 if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
615 if (defined(invoker.defines)) { defines = invoker.defines }
616 if (defined(invoker.deps)) { deps = invoker.deps }
617 if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
618 if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
619 if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
620 if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
621 if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
622 if (defined(invoker.libs)) { libs = invoker.libs }
623 if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
624 if (defined(invoker.output_name)) { output_name = invoker.output_name }
625 if (defined(invoker.public)) { public = invoker.public }
626 if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
627 if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
628 if (defined(invoker.sources)) { sources = invoker.sources }
629 if (defined(invoker.testonly)) { testonly = invoker.testonly }
630 if (defined(invoker.visibility)) { visibility = invoker.visibility }
635 # ==============================================================================
637 # ==============================================================================
639 # Define a test as an executable (or shared_library on Android) with the
640 # "testonly" flag set.
643 shared_library(target_name) {
644 # Configs will always be defined since we set_defaults for a component
645 # above. We want to use those rather than whatever came with the nested
646 # shared/static library inside the component.
647 configs = [] # Prevent list overwriting warning.
648 configs = invoker.configs
651 set_sources_assignment_filter([])
655 if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
656 if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
657 if (defined(invoker.cflags)) { cflags = invoker.cflags }
658 if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
659 if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
660 if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
661 if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
662 if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
663 if (defined(invoker.data)) { data = invoker.data }
664 if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
665 if (defined(invoker.defines)) { defines = invoker.defines }
666 if (defined(invoker.deps)) { deps = invoker.deps }
667 if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
668 if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
669 if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
670 if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
671 if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
672 if (defined(invoker.libs)) { libs = invoker.libs }
673 if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
674 if (defined(invoker.output_name)) { output_name = invoker.output_name }
675 if (defined(invoker.public)) { public = invoker.public }
676 if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
677 if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
678 if (defined(invoker.sources)) { sources = invoker.sources }
679 if (defined(invoker.visibility)) { visibility = invoker.visibility }
682 executable(target_name) {
684 configs = [] # Prevent list overwriting warning.
685 configs = invoker.configs
688 set_sources_assignment_filter([])
692 if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
693 if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
694 if (defined(invoker.cflags)) { cflags = invoker.cflags }
695 if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
696 if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
697 if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
698 if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
699 if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
700 if (defined(invoker.data)) { data = invoker.data }
701 if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
702 if (defined(invoker.defines)) { defines = invoker.defines }
703 # All shared libraries must have the sanitizer deps to properly link in
704 # asan mode (this target will be empty in other cases).
705 if (defined(invoker.deps)) {
706 deps = invoker.deps + [ "//build/config/sanitizers:deps" ]
708 deps = [ "//build/config/sanitizers:deps" ]
710 if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
711 if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
712 if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
713 if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
714 if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
715 if (defined(invoker.libs)) { libs = invoker.libs }
716 if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
717 if (defined(invoker.output_name)) { output_name = invoker.output_name }
718 if (defined(invoker.public)) { public = invoker.public }
719 if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
720 if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
721 if (defined(invoker.sources)) { sources = invoker.sources }
722 if (defined(invoker.visibility)) { visibility = invoker.visibility }