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 # TODO(dpranke): The os and cpu_arch variables exist for backwards
21 # compatibility and should be deleted once all of the build files and
22 # bots have been updated to use current_cpu/target_cpu and
23 # current_os/target_os instead.
25 if (target_os == "") {
27 # If os is defined, it was set in an args file and needs to be
28 # used for backwards-compatibility.
35 if (target_cpu == "") {
36 if (defined(cpu_arch)) {
37 # If cpu_arch is defined, it was set in an args file and needs to be
38 # used for backwards-compatibility.
40 } else if (target_os == "android") {
41 # If we're building for Android, we should assume that we want to
42 # build for ARM by default, not the host_cpu (which is likely x64).
43 # This allows us to not have to specify both target_os and target_cpu
44 # on the command line.
51 if (current_cpu == "") {
52 current_cpu = target_cpu
54 if (current_os == "") {
55 current_os = target_os
59 # TODO(dpranke): These values are here for backwards compatibility and
60 # should be deleted when all of the builders and configs have been updated.
63 build_cpu_arch = host_cpu
66 # How many symbols to include in the build. This affects the performance of
67 # the build since the symbols are large and dealing with them is slow.
68 # 2 means regular build with symbols.
69 # 1 means minimal symbols, usually enough for backtraces only.
71 # -1 means auto-set (off in release, regular in debug).
75 is_component_build = false
80 # Whether we're a traditional desktop unix.
81 is_desktop_linux = current_os == "linux" && current_os != "chromeos"
83 # Set to true when compiling with the Clang compiler. Typically this is used
84 # to configure warnings.
85 is_clang = current_os == "mac" || current_os == "ios" ||
86 current_os == "linux" || current_os == "chromeos"
88 # Selects the desired build flavor. Official builds get additional
89 # processing to prepare for release. Normally you will want to develop and
90 # test with this flag off.
91 is_official_build = false
93 # Select the desired branding flavor. False means normal Chromium branding,
94 # true means official Google Chrome branding (requires extra Google-internal
96 is_chrome_branded = false
98 # Compile for Address Sanitizer to find memory bugs.
101 # Compile for Leak Sanitizer to find leaks.
104 # Compile for Memory Sanitizer to find uninitialized reads.
107 # Compile for Thread Sanitizer to find threading bugs.
110 if (current_os == "chromeos") {
111 # Allows the target toolchain to be injected as arguments. This is needed
112 # to support the CrOS build system which supports per-build-configuration
114 cros_use_custom_toolchain = false
118 # TODO(dpranke): Remove these asserts when os and cpu_arch are removed.
119 assert(current_cpu == cpu_arch)
120 assert(current_os == os)
122 # =============================================================================
124 # =============================================================================
126 # We set these various is_FOO booleans for convenience in writing OS-based
129 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
130 # - is_mac is set only for desktop Mac. It is not set on iOS.
131 # - is_posix is true for mac and any Unix-like system (basically everything
133 # - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
134 # generally too different despite being based on the Linux kernel).
136 # Do not add more is_* variants here for random lesser-used Unix systems like
137 # aix or one of the BSDs. If you need to check these, just check the
138 # current_os value directly.
140 if (current_os == "win") {
149 } else if (current_os == "mac") {
158 } else if (current_os == "android") {
167 } else if (current_os == "chromeos") {
176 } else if (current_os == "nacl") {
177 # current_os == "nacl" will be passed by the nacl toolchain definition.
178 # It is not set by default or on the command line. We treat is as a
188 } else if (current_os == "ios") {
197 } else if (current_os == "linux") {
208 # =============================================================================
210 # =============================================================================
212 # These patterns filter out platform-specific files when assigning to the
213 # sources variable. The magic variable |sources_assignment_filter| is applied
214 # to each assignment or appending to the sources variable and matches are
215 # automatcally removed.
217 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
218 # boundary = end of string or slash) are supported, and the entire string
219 # muct match the pattern (so you need "*.cc" to match all .cc files, for
222 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
224 sources_assignment_filter = []
226 sources_assignment_filter += [
229 "*_posix_unittest.h",
230 "*_posix_unittest.cc",
235 sources_assignment_filter += [
244 sources_assignment_filter += [
255 "*_cocoa_unittest.h",
256 "*_cocoa_unittest.cc",
257 "*_cocoa_unittest.mm",
262 sources_assignment_filter += [
272 if (!is_mac && !is_ios) {
273 sources_assignment_filter += [ "*.mm" ]
276 sources_assignment_filter += [
279 "*_linux_unittest.h",
280 "*_linux_unittest.cc",
285 sources_assignment_filter += [
288 "*_android_unittest.h",
289 "*_android_unittest.cc",
294 sources_assignment_filter += [
297 "*_chromeos_unittest.h",
298 "*_chromeos_unittest.cc",
303 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
306 # Actually save this list.
308 # These patterns are executed for every file in the source tree of every run.
309 # Therefore, adding more patterns slows down the build for everybody. We should
310 # only add automatic patterns for configurations affecting hundreds of files
311 # across many projects in the tree.
313 # Therefore, we only add rules to this list corresponding to platforms on the
314 # Chromium waterfall. This is not for non-officially-supported platforms
315 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
316 # write a conditional in the target to remove the file(s) from the list when
317 # your platform/toolkit/feature doesn't apply.
318 set_sources_assignment_filter(sources_assignment_filter)
320 # =============================================================================
322 # =============================================================================
324 # These Sanitizers all imply using the Clang compiler. On Windows they either
325 # don't work or work differently.
326 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
330 # =============================================================================
332 # =============================================================================
334 # Set up the default configuration for every build target of the given type.
335 # The values configured here will be automatically set on the scope of the
336 # corresponding target. Target definitions can add or remove to the settings
339 # Holds all configs used for making native executables and libraries, to avoid
340 # duplication in each target below.
341 _native_compiler_configs = [
342 "//build/config:feature_flags",
343 "//build/config/compiler:compiler",
344 "//build/config/compiler:compiler_arm_fpu",
345 "//build/config/compiler:chromium_code",
346 "//build/config/compiler:default_include_dirs",
347 "//build/config/compiler:default_warnings",
348 "//build/config/compiler:no_rtti",
349 "//build/config/compiler:runtime_library",
352 _native_compiler_configs += [
353 "//build/config/win:lean_and_mean",
354 "//build/config/win:nominmax",
355 "//build/config/win:sdk",
356 "//build/config/win:unicode",
357 "//build/config/win:winver",
361 _native_compiler_configs += [
362 "//build/config/gcc:no_exceptions",
363 "//build/config/gcc:symbol_visibility_hidden",
368 _native_compiler_configs += [ "//build/config/linux:sdk" ]
370 _native_compiler_configs += [ "//build/config/mac:sdk" ]
372 _native_compiler_configs += [ "//build/config/ios:sdk" ]
373 } else if (is_android) {
374 _native_compiler_configs += [ "//build/config/android:sdk" ]
378 _native_compiler_configs += [
379 "//build/config/clang:find_bad_constructs",
380 "//build/config/clang:extra_warnings",
384 # Optimizations and debug checking.
386 _native_compiler_configs += [ "//build/config:debug" ]
387 _default_optimization_config = "//build/config/compiler:no_optimize"
389 _native_compiler_configs += [ "//build/config:release" ]
390 _default_optimization_config = "//build/config/compiler:optimize"
392 _native_compiler_configs += [ _default_optimization_config ]
394 # If it wasn't manually set, set to an appropriate default.
395 if (symbol_level == -1) {
396 # Linux is slowed by having symbols as part of the target binary, whereas
397 # Mac and Windows have them separate, so in Release Linux, default them off.
398 if (is_debug || !is_linux) {
406 if (symbol_level == 2) {
407 _default_symbols_config = "//build/config/compiler:symbols"
408 } else if (symbol_level == 1) {
409 _default_symbols_config = "//build/config/compiler:minimal_symbols"
410 } else if (symbol_level == 0) {
411 _default_symbols_config = "//build/config/compiler:no_symbols"
413 assert(false, "Bad value for symbol_level.")
415 _native_compiler_configs += [ _default_symbols_config ]
417 # Windows linker setup for EXEs and DLLs.
420 _default_incremental_linking_config =
421 "//build/config/win:incremental_linking"
423 _default_incremental_linking_config =
424 "//build/config/win:no_incremental_linking"
426 _windows_linker_configs = [
427 _default_incremental_linking_config,
428 "//build/config/win:sdk_link",
429 "//build/config/win:common_linker_setup",
431 # Default to console-mode apps. Most of our targets are tests and such
432 # that shouldn't use the windows subsystem.
433 "//build/config/win:console",
437 # Executable defaults.
438 _executable_configs =
439 _native_compiler_configs + [ "//build/config:default_libs" ]
441 _executable_configs += _windows_linker_configs
443 _executable_configs += [
444 "//build/config/mac:mac_dynamic_flags",
445 "//build/config/mac:mac_executable_flags",
447 } else if (is_linux || is_android) {
448 _executable_configs += [ "//build/config/gcc:executable_ldconfig" ]
450 _executable_configs += [ "//build/config/android:executable_config" ]
453 set_defaults("executable") {
454 configs = _executable_configs
457 # Static library defaults.
458 set_defaults("static_library") {
459 configs = _native_compiler_configs
462 # Shared library defaults (also for components in component mode).
463 _shared_library_configs =
464 _native_compiler_configs + [ "//build/config:default_libs" ]
466 _shared_library_configs += _windows_linker_configs
468 _shared_library_configs += [ "//build/config/mac:mac_dynamic_flags" ]
469 } else if (is_android) {
470 # Strip native JNI exports from shared libraries by default. Binaries that
471 # want this can remove this config.
472 _shared_library_configs +=
473 [ "//build/config/android:hide_native_jni_exports" ]
475 set_defaults("shared_library") {
476 configs = _shared_library_configs
478 if (is_component_build) {
479 set_defaults("component") {
480 configs = _shared_library_configs
484 # Source set defaults (also for components in non-component mode).
485 set_defaults("source_set") {
486 configs = _native_compiler_configs
488 if (!is_component_build) {
489 set_defaults("component") {
490 configs = _native_compiler_configs
495 set_defaults("test") {
497 configs = _shared_library_configs
499 configs = _executable_configs
503 # ==============================================================================
505 # ==============================================================================
507 # Here we set the default toolchain, as well as the variable host_toolchain
508 # which will identify the toolchain corresponding to the local system when
509 # doing cross-compiles. When not cross-compiling, this will be the same as the
513 # On windows we use the same toolchain for host and target by default.
514 # TODO(dpranke): rename the toolchains to x64 and x86 to match current_cpu.
515 if (current_cpu == "x64") {
516 host_toolchain = "//build/toolchain/win:64"
517 } else if (current_cpu == "x86") {
518 host_toolchain = "//build/toolchain/win:32"
520 set_default_toolchain("$host_toolchain")
521 } else if (is_android) {
522 # Use clang for the x86/64 Linux host builds.
523 if (host_cpu == "x86" || host_cpu == "x64") {
524 host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
526 host_toolchain = "//build/toolchain/linux:$host_cpu"
528 set_default_toolchain("//build/toolchain/android:$current_cpu")
529 } else if (is_linux) {
531 host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
532 set_default_toolchain("//build/toolchain/linux:clang_$current_cpu")
534 host_toolchain = "//build/toolchain/linux:$host_cpu"
535 set_default_toolchain("//build/toolchain/linux:$current_cpu")
537 if (is_chromeos && cros_use_custom_toolchain) {
538 set_default_toolchain("//build/toolchain/cros:target")
541 host_toolchain = "//build/toolchain/mac:clang"
542 set_default_toolchain(host_toolchain)
544 host_toolchain = "//build/toolchain/mac:host_clang"
545 set_default_toolchain("//build/toolchain/mac:clang")
546 } else if (is_nacl) {
547 # TODO(GYP): This will need to change when we get NaCl working
548 # on multiple platforms, but this whole block of code (how we define
549 # host_toolchain) needs to be reworked regardless to key off of build_os
550 # and build_cpu_arch rather than the is_* variables.
551 host_toolchain = "//build/toolchain/linux:clang_x64"
554 # ==============================================================================
556 # ==============================================================================
558 # TODO(brettw) erase this once the built-in "component" function is removed.
559 if (is_component_build) {
560 component_mode = "shared_library"
562 component_mode = "source_set"
565 template("component") {
566 if (is_component_build) {
567 shared_library(target_name) {
568 # Configs will always be defined since we set_defaults for a component
569 # above. We want to use those rather than whatever came with the nested
570 # shared/static library inside the component.
571 configs = [] # Prevent list overwriting warning.
572 configs = invoker.configs
574 # The sources assignment filter will have already been applied when the
575 # code was originally executed. We don't want to apply it again, since
576 # the original target may have override it for some assignments.
577 set_sources_assignment_filter([])
579 if (defined(invoker.all_dependent_configs)) {
580 all_dependent_configs = invoker.all_dependent_configs
582 if (defined(invoker.allow_circular_includes_from)) {
583 allow_circular_includes_from = invoker.allow_circular_includes_from
585 if (defined(invoker.cflags)) {
586 cflags = invoker.cflags
588 if (defined(invoker.cflags_c)) {
589 cflags_c = invoker.cflags_c
591 if (defined(invoker.cflags_cc)) {
592 cflags_cc = invoker.cflags_cc
594 if (defined(invoker.cflags_objc)) {
595 cflags_objc = invoker.cflags_objc
597 if (defined(invoker.cflags_objcc)) {
598 cflags_objcc = invoker.cflags_objcc
600 if (defined(invoker.check_includes)) {
601 check_includes = invoker.check_includes
603 if (defined(invoker.data)) {
606 if (defined(invoker.data_deps)) {
607 data_deps = invoker.data_deps
609 if (defined(invoker.datadeps)) {
610 datadeps = invoker.datadeps
612 if (defined(invoker.defines)) {
613 defines = invoker.defines
616 # All shared libraries must have the sanitizer deps to properly link in
617 # asan mode (this target will be empty in other cases).
618 if (defined(invoker.deps)) {
619 deps = invoker.deps + [ "//build/config/sanitizers:deps" ]
622 "//build/config/sanitizers:deps",
625 if (defined(invoker.direct_dependent_configs)) {
626 direct_dependent_configs = invoker.direct_dependent_configs
628 if (defined(invoker.forward_dependent_configs_from)) {
629 forward_dependent_configs_from = invoker.forward_dependent_configs_from
631 if (defined(invoker.include_dirs)) {
632 include_dirs = invoker.include_dirs
634 if (defined(invoker.ldflags)) {
635 ldflags = invoker.ldflags
637 if (defined(invoker.lib_dirs)) {
638 lib_dirs = invoker.lib_dirs
640 if (defined(invoker.libs)) {
643 if (defined(invoker.output_extension)) {
644 output_extension = invoker.output_extension
646 if (defined(invoker.output_name)) {
647 output_name = invoker.output_name
649 if (defined(invoker.public)) {
650 public = invoker.public
652 if (defined(invoker.public_configs)) {
653 public_configs = invoker.public_configs
655 if (defined(invoker.public_deps)) {
656 public_deps = invoker.public_deps
658 if (defined(invoker.sources)) {
659 sources = invoker.sources
661 if (defined(invoker.testonly)) {
662 testonly = invoker.testonly
664 if (defined(invoker.visibility)) {
665 visibility = invoker.visibility
669 source_set(target_name) {
671 configs = [] # Prevent list overwriting warning.
672 configs = invoker.configs
675 set_sources_assignment_filter([])
677 if (defined(invoker.all_dependent_configs)) {
678 all_dependent_configs = invoker.all_dependent_configs
680 if (defined(invoker.allow_circular_includes_from)) {
681 allow_circular_includes_from = invoker.allow_circular_includes_from
683 if (defined(invoker.cflags)) {
684 cflags = invoker.cflags
686 if (defined(invoker.cflags_c)) {
687 cflags_c = invoker.cflags_c
689 if (defined(invoker.cflags_cc)) {
690 cflags_cc = invoker.cflags_cc
692 if (defined(invoker.cflags_objc)) {
693 cflags_objc = invoker.cflags_objc
695 if (defined(invoker.cflags_objcc)) {
696 cflags_objcc = invoker.cflags_objcc
698 if (defined(invoker.check_includes)) {
699 check_includes = invoker.check_includes
701 if (defined(invoker.data)) {
704 if (defined(invoker.data_deps)) {
705 data_deps = invoker.data_deps
707 if (defined(invoker.datadeps)) {
708 datadeps = invoker.datadeps
710 if (defined(invoker.defines)) {
711 defines = invoker.defines
713 if (defined(invoker.deps)) {
716 if (defined(invoker.direct_dependent_configs)) {
717 direct_dependent_configs = invoker.direct_dependent_configs
719 if (defined(invoker.forward_dependent_configs_from)) {
720 forward_dependent_configs_from = invoker.forward_dependent_configs_from
722 if (defined(invoker.include_dirs)) {
723 include_dirs = invoker.include_dirs
725 if (defined(invoker.ldflags)) {
726 ldflags = invoker.ldflags
728 if (defined(invoker.lib_dirs)) {
729 lib_dirs = invoker.lib_dirs
731 if (defined(invoker.libs)) {
734 if (defined(invoker.output_extension)) {
735 output_extension = invoker.output_extension
737 if (defined(invoker.output_name)) {
738 output_name = invoker.output_name
740 if (defined(invoker.public)) {
741 public = invoker.public
743 if (defined(invoker.public_configs)) {
744 public_configs = invoker.public_configs
746 if (defined(invoker.public_deps)) {
747 public_deps = invoker.public_deps
749 if (defined(invoker.sources)) {
750 sources = invoker.sources
752 if (defined(invoker.testonly)) {
753 testonly = invoker.testonly
755 if (defined(invoker.visibility)) {
756 visibility = invoker.visibility