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 if (target_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.
36 if (current_cpu == "") {
37 current_cpu = target_cpu
39 if (current_os == "") {
40 current_os = target_os
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.
49 # -1 means auto-set (off in release, regular in debug).
53 is_component_build = false
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 # TODO(brettw) move to chrome_build.gni when DEPS are updated.
70 is_official_build = false
72 # Select the desired branding flavor. False means normal Chromium branding,
73 # true means official Google Chrome branding (requires extra Google-internal
75 # TODO(brettw) move to chrome_build.gni when DEPS are updated.
76 is_chrome_branded = false
78 # Compile for Address Sanitizer to find memory bugs.
81 # Compile for Leak Sanitizer to find leaks.
84 # Compile for Memory Sanitizer to find uninitialized reads.
87 # Compile for Thread Sanitizer to find threading bugs.
90 if (current_os == "chromeos") {
91 # Allows the target toolchain to be injected as arguments. This is needed
92 # to support the CrOS build system which supports per-build-configuration
94 cros_use_custom_toolchain = false
98 # =============================================================================
100 # =============================================================================
102 # We set these various is_FOO booleans for convenience in writing OS-based
105 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
106 # - is_mac is set only for desktop Mac. It is not set on iOS.
107 # - is_posix is true for mac and any Unix-like system (basically everything
109 # - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
110 # generally too different despite being based on the Linux kernel).
112 # Do not add more is_* variants here for random lesser-used Unix systems like
113 # aix or one of the BSDs. If you need to check these, just check the
114 # current_os value directly.
116 if (current_os == "win") {
125 } else if (current_os == "mac") {
134 } else if (current_os == "android") {
143 } else if (current_os == "chromeos") {
152 } else if (current_os == "nacl") {
153 # current_os == "nacl" will be passed by the nacl toolchain definition.
154 # It is not set by default or on the command line. We treat is as a
164 } else if (current_os == "ios") {
173 } else if (current_os == "linux") {
184 # =============================================================================
186 # =============================================================================
188 # These patterns filter out platform-specific files when assigning to the
189 # sources variable. The magic variable |sources_assignment_filter| is applied
190 # to each assignment or appending to the sources variable and matches are
191 # automatcally removed.
193 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
194 # boundary = end of string or slash) are supported, and the entire string
195 # muct match the pattern (so you need "*.cc" to match all .cc files, for
198 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
200 sources_assignment_filter = []
202 sources_assignment_filter += [
205 "*_posix_unittest.h",
206 "*_posix_unittest.cc",
211 sources_assignment_filter += [
220 sources_assignment_filter += [
231 "*_cocoa_unittest.h",
232 "*_cocoa_unittest.cc",
233 "*_cocoa_unittest.mm",
238 sources_assignment_filter += [
248 if (!is_mac && !is_ios) {
249 sources_assignment_filter += [ "*.mm" ]
252 sources_assignment_filter += [
255 "*_linux_unittest.h",
256 "*_linux_unittest.cc",
261 sources_assignment_filter += [
264 "*_android_unittest.h",
265 "*_android_unittest.cc",
270 sources_assignment_filter += [
273 "*_chromeos_unittest.h",
274 "*_chromeos_unittest.cc",
279 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
282 # Actually save this list.
284 # These patterns are executed for every file in the source tree of every run.
285 # Therefore, adding more patterns slows down the build for everybody. We should
286 # only add automatic patterns for configurations affecting hundreds of files
287 # across many projects in the tree.
289 # Therefore, we only add rules to this list corresponding to platforms on the
290 # Chromium waterfall. This is not for non-officially-supported platforms
291 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
292 # write a conditional in the target to remove the file(s) from the list when
293 # your platform/toolkit/feature doesn't apply.
294 set_sources_assignment_filter(sources_assignment_filter)
296 # =============================================================================
298 # =============================================================================
300 # These Sanitizers all imply using the Clang compiler. On Windows they either
301 # don't work or work differently.
302 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
306 # =============================================================================
308 # =============================================================================
310 # Set up the default configuration for every build target of the given type.
311 # The values configured here will be automatically set on the scope of the
312 # corresponding target. Target definitions can add or remove to the settings
315 # Holds all configs used for making native executables and libraries, to avoid
316 # duplication in each target below.
317 _native_compiler_configs = [
318 "//build/config:feature_flags",
319 "//build/config/compiler:compiler",
320 "//build/config/compiler:compiler_arm_fpu",
321 "//build/config/compiler:chromium_code",
322 "//build/config/compiler:default_include_dirs",
323 "//build/config/compiler:default_warnings",
324 "//build/config/compiler:no_rtti",
325 "//build/config/compiler:runtime_library",
328 _native_compiler_configs += [
329 "//build/config/win:lean_and_mean",
330 "//build/config/win:nominmax",
331 "//build/config/win:sdk",
332 "//build/config/win:unicode",
333 "//build/config/win:winver",
337 _native_compiler_configs += [
338 "//build/config/gcc:no_exceptions",
339 "//build/config/gcc:symbol_visibility_hidden",
344 _native_compiler_configs += [ "//build/config/linux:sdk" ]
346 _native_compiler_configs += [ "//build/config/mac:sdk" ]
348 _native_compiler_configs += [ "//build/config/ios:sdk" ]
349 } else if (is_android) {
350 _native_compiler_configs += [ "//build/config/android:sdk" ]
354 _native_compiler_configs += [
355 "//build/config/clang:find_bad_constructs",
356 "//build/config/clang:extra_warnings",
360 # Optimizations and debug checking.
362 _native_compiler_configs += [ "//build/config:debug" ]
363 _default_optimization_config = "//build/config/compiler:no_optimize"
365 _native_compiler_configs += [ "//build/config:release" ]
366 _default_optimization_config = "//build/config/compiler:optimize"
368 _native_compiler_configs += [ _default_optimization_config ]
370 # If it wasn't manually set, set to an appropriate default.
371 if (symbol_level == -1) {
372 # Linux is slowed by having symbols as part of the target binary, whereas
373 # Mac and Windows have them separate, so in Release Linux, default them off.
374 if (is_debug || !is_linux) {
382 if (symbol_level == 2) {
383 _default_symbols_config = "//build/config/compiler:symbols"
384 } else if (symbol_level == 1) {
385 _default_symbols_config = "//build/config/compiler:minimal_symbols"
386 } else if (symbol_level == 0) {
387 _default_symbols_config = "//build/config/compiler:no_symbols"
389 assert(false, "Bad value for symbol_level.")
391 _native_compiler_configs += [ _default_symbols_config ]
393 # Windows linker setup for EXEs and DLLs.
395 _windows_linker_configs = [
396 "//build/config/win:default_incremental_linking",
397 "//build/config/win:sdk_link",
398 "//build/config/win:common_linker_setup",
400 # Default to console-mode apps. Most of our targets are tests and such
401 # that shouldn't use the windows subsystem.
402 "//build/config/win:console",
406 # Executable defaults.
407 _executable_configs =
408 _native_compiler_configs + [ "//build/config:default_libs" ]
410 _executable_configs += _windows_linker_configs
412 _executable_configs += [
413 "//build/config/mac:mac_dynamic_flags",
414 "//build/config/mac:mac_executable_flags",
416 } else if (is_linux || is_android) {
417 _executable_configs += [ "//build/config/gcc:executable_ldconfig" ]
419 _executable_configs += [ "//build/config/android:executable_config" ]
422 set_defaults("executable") {
423 configs = _executable_configs
426 # Static library defaults.
427 set_defaults("static_library") {
428 configs = _native_compiler_configs
431 # Shared library defaults (also for components in component mode).
432 _shared_library_configs =
433 _native_compiler_configs + [ "//build/config:default_libs" ]
435 _shared_library_configs += _windows_linker_configs
437 _shared_library_configs += [ "//build/config/mac:mac_dynamic_flags" ]
438 } else if (is_android) {
439 # Strip native JNI exports from shared libraries by default. Binaries that
440 # want this can remove this config.
441 _shared_library_configs +=
442 [ "//build/config/android:hide_native_jni_exports" ]
444 set_defaults("shared_library") {
445 configs = _shared_library_configs
447 if (is_component_build) {
448 set_defaults("component") {
449 configs = _shared_library_configs
453 # Source set defaults (also for components in non-component mode).
454 set_defaults("source_set") {
455 configs = _native_compiler_configs
457 if (!is_component_build) {
458 set_defaults("component") {
459 configs = _native_compiler_configs
464 set_defaults("test") {
466 configs = _shared_library_configs
468 configs = _executable_configs
472 # ==============================================================================
474 # ==============================================================================
476 # Here we set the default toolchain, as well as the variable host_toolchain
477 # which will identify the toolchain corresponding to the local system when
478 # doing cross-compiles. When not cross-compiling, this will be the same as the
482 # On windows we use the same toolchain for host and target by default.
483 # TODO(dpranke): rename the toolchains to x64 and x86 to match current_cpu.
484 if (current_cpu == "x64") {
485 host_toolchain = "//build/toolchain/win:64"
486 } else if (current_cpu == "x86") {
487 host_toolchain = "//build/toolchain/win:32"
489 set_default_toolchain("$host_toolchain")
490 } else if (is_android) {
491 # Use clang for the x86/64 Linux host builds.
492 if (host_cpu == "x86" || host_cpu == "x64") {
493 host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
495 host_toolchain = "//build/toolchain/linux:$host_cpu"
497 set_default_toolchain("//build/toolchain/android:$current_cpu")
498 } else if (is_linux) {
500 host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
501 set_default_toolchain("//build/toolchain/linux:clang_$current_cpu")
503 host_toolchain = "//build/toolchain/linux:$host_cpu"
504 set_default_toolchain("//build/toolchain/linux:$current_cpu")
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")
515 } else if (is_nacl) {
516 # TODO(GYP): This will need to change when we get NaCl working
517 # on multiple platforms, but this whole block of code (how we define
518 # host_toolchain) needs to be reworked regardless to key off of host_os
519 # and host_cpu rather than the is_* variables.
520 host_toolchain = "//build/toolchain/linux:clang_x64"
523 # ==============================================================================
525 # ==============================================================================
527 # TODO(brettw) erase this once the built-in "component" function is removed.
528 if (is_component_build) {
529 component_mode = "shared_library"
531 component_mode = "source_set"
534 template("component") {
535 if (is_component_build) {
536 shared_library(target_name) {
537 # Configs will always be defined since we set_defaults for a component
538 # above. We want to use those rather than whatever came with the nested
539 # shared/static library inside the component.
540 configs = [] # Prevent list overwriting warning.
541 configs = invoker.configs
543 # The sources assignment filter will have already been applied when the
544 # code was originally executed. We don't want to apply it again, since
545 # the original target may have override it for some assignments.
546 set_sources_assignment_filter([])
548 if (defined(invoker.all_dependent_configs)) {
549 all_dependent_configs = invoker.all_dependent_configs
551 if (defined(invoker.allow_circular_includes_from)) {
552 allow_circular_includes_from = invoker.allow_circular_includes_from
554 if (defined(invoker.cflags)) {
555 cflags = invoker.cflags
557 if (defined(invoker.cflags_c)) {
558 cflags_c = invoker.cflags_c
560 if (defined(invoker.cflags_cc)) {
561 cflags_cc = invoker.cflags_cc
563 if (defined(invoker.cflags_objc)) {
564 cflags_objc = invoker.cflags_objc
566 if (defined(invoker.cflags_objcc)) {
567 cflags_objcc = invoker.cflags_objcc
569 if (defined(invoker.check_includes)) {
570 check_includes = invoker.check_includes
572 if (defined(invoker.data)) {
575 if (defined(invoker.data_deps)) {
576 data_deps = invoker.data_deps
578 if (defined(invoker.datadeps)) {
579 datadeps = invoker.datadeps
581 if (defined(invoker.defines)) {
582 defines = invoker.defines
585 # All shared libraries must have the sanitizer deps to properly link in
586 # asan mode (this target will be empty in other cases).
587 if (defined(invoker.deps)) {
588 deps = invoker.deps + [ "//build/config/sanitizers:deps" ]
591 "//build/config/sanitizers:deps",
594 if (defined(invoker.direct_dependent_configs)) {
595 direct_dependent_configs = invoker.direct_dependent_configs
597 if (defined(invoker.forward_dependent_configs_from)) {
598 forward_dependent_configs_from = invoker.forward_dependent_configs_from
600 if (defined(invoker.include_dirs)) {
601 include_dirs = invoker.include_dirs
603 if (defined(invoker.ldflags)) {
604 ldflags = invoker.ldflags
606 if (defined(invoker.lib_dirs)) {
607 lib_dirs = invoker.lib_dirs
609 if (defined(invoker.libs)) {
612 if (defined(invoker.output_extension)) {
613 output_extension = invoker.output_extension
615 if (defined(invoker.output_name)) {
616 output_name = invoker.output_name
618 if (defined(invoker.public)) {
619 public = invoker.public
621 if (defined(invoker.public_configs)) {
622 public_configs = invoker.public_configs
624 if (defined(invoker.public_deps)) {
625 public_deps = invoker.public_deps
627 if (defined(invoker.sources)) {
628 sources = invoker.sources
630 if (defined(invoker.testonly)) {
631 testonly = invoker.testonly
633 if (defined(invoker.visibility)) {
634 visibility = invoker.visibility
638 source_set(target_name) {
640 configs = [] # Prevent list overwriting warning.
641 configs = invoker.configs
644 set_sources_assignment_filter([])
646 if (defined(invoker.all_dependent_configs)) {
647 all_dependent_configs = invoker.all_dependent_configs
649 if (defined(invoker.allow_circular_includes_from)) {
650 allow_circular_includes_from = invoker.allow_circular_includes_from
652 if (defined(invoker.cflags)) {
653 cflags = invoker.cflags
655 if (defined(invoker.cflags_c)) {
656 cflags_c = invoker.cflags_c
658 if (defined(invoker.cflags_cc)) {
659 cflags_cc = invoker.cflags_cc
661 if (defined(invoker.cflags_objc)) {
662 cflags_objc = invoker.cflags_objc
664 if (defined(invoker.cflags_objcc)) {
665 cflags_objcc = invoker.cflags_objcc
667 if (defined(invoker.check_includes)) {
668 check_includes = invoker.check_includes
670 if (defined(invoker.data)) {
673 if (defined(invoker.data_deps)) {
674 data_deps = invoker.data_deps
676 if (defined(invoker.datadeps)) {
677 datadeps = invoker.datadeps
679 if (defined(invoker.defines)) {
680 defines = invoker.defines
682 if (defined(invoker.deps)) {
685 if (defined(invoker.direct_dependent_configs)) {
686 direct_dependent_configs = invoker.direct_dependent_configs
688 if (defined(invoker.forward_dependent_configs_from)) {
689 forward_dependent_configs_from = invoker.forward_dependent_configs_from
691 if (defined(invoker.include_dirs)) {
692 include_dirs = invoker.include_dirs
694 if (defined(invoker.ldflags)) {
695 ldflags = invoker.ldflags
697 if (defined(invoker.lib_dirs)) {
698 lib_dirs = invoker.lib_dirs
700 if (defined(invoker.libs)) {
703 if (defined(invoker.output_extension)) {
704 output_extension = invoker.output_extension
706 if (defined(invoker.output_name)) {
707 output_name = invoker.output_name
709 if (defined(invoker.public)) {
710 public = invoker.public
712 if (defined(invoker.public_configs)) {
713 public_configs = invoker.public_configs
715 if (defined(invoker.public_deps)) {
716 public_deps = invoker.public_deps
718 if (defined(invoker.sources)) {
719 sources = invoker.sources
721 if (defined(invoker.testonly)) {
722 testonly = invoker.testonly
724 if (defined(invoker.visibility)) {
725 visibility = invoker.visibility