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.
9 if (target_cpu == "") {
10 if (target_os == "android") {
11 # If we're building for Android, we should assume that we want to
12 # build for ARM by default, not the host_cpu (which is likely x64).
13 # This allows us to not have to specify both target_os and target_cpu
14 # on the command line.
21 if (current_cpu == "") {
22 current_cpu = target_cpu
24 if (current_os == "") {
25 current_os = target_os
28 # =============================================================================
30 # =============================================================================
32 # This block lists input arguments to the build, along with their default
35 # If a value is specified on the command line, it will overwrite the defaults
36 # given in a declare_args block, otherwise the default will be used.
38 # YOU SHOULD ALMOST NEVER NEED TO ADD FLAGS TO THIS FILE. GN allows any file in
39 # the build to declare build flags. If you need a flag for a single component,
40 # you can just declare it in the corresponding BUILD.gn file. If you need a
41 # flag in multiple components, there are a few options:
43 # - If your feature is a single target, say //components/foo, and the targets
44 # depending on foo need to have some define set if foo is enabled: (1) Write
45 # a declare_args block in foo's BUILD.gn file listing your enable_foo build
46 # flag. (2) Write a config in that file listing the define, and list that
47 # config in foo's public_configs. This will propagate that define to all the
48 # targets depending on foo. (3) When foo is not enabled, just make it expand
49 # to an empty group (or whatever's appropriate for the "off" state of your
52 # - If a semi-random set of targets need to know about a define: (1) In the
53 # lowest level of the build that knows about this feature, add a declare_args
54 # block in the build file for your enable flag. (2) Write a config that adds
55 # a define conditionally based on that build flags. (3) Manually add that
56 # config to the "configs" applying to the targets that need the define.
58 # - If a semi-random set of targets need to know about the build flag (to do
59 # file inclusion or exclusion, more than just defines): (1) Write a .gni file
60 # in the lowest-level directory that knows about the feature. (2) Put the
61 # declare_args block with your build flag in that .gni file. (3) Import that
62 # .gni file from the BUILD.gn files that need the flag.
66 # - Use boolean values when possible. If you need a default value that expands
67 # to some complex thing in the default case (like the location of the
68 # compiler which would be computed by a script), use a default value of -1 or
69 # the empty string. Outside of the declare_args block, conditionally expand
70 # the default value as necessary.
72 # - Use a name like "use_foo" or "is_foo" (whatever is more appropriate for
73 # your feature) rather than just "foo".
75 # - Write good comments directly above the declaration with no blank line.
76 # These comments will appear as documentation in "gn args --list".
78 # - Don't call exec_script inside declare_args. This will execute the script
79 # even if the value is overridden, which is wasteful. See first bullet.
82 # How many symbols to include in the build. This affects the performance of
83 # the build since the symbols are large and dealing with them is slow.
84 # 2 means regular build with symbols.
85 # 1 means minimal symbols, usually enough for backtraces only.
87 # -1 means auto-set (off in release, regular in debug).
91 is_component_build = false
96 # Whether we're a traditional desktop unix.
97 is_desktop_linux = current_os == "linux" && current_os != "chromeos"
99 # Set to true when compiling with the Clang compiler. Typically this is used
100 # to configure warnings.
101 is_clang = current_os == "mac" || current_os == "ios" ||
102 current_os == "linux" || current_os == "chromeos"
104 # Selects the desired build flavor. Official builds get additional
105 # processing to prepare for release. Normally you will want to develop and
106 # test with this flag off.
107 # TODO(brettw) move to chrome_build.gni when DEPS are updated.
108 is_official_build = false
110 # Select the desired branding flavor. False means normal Chromium branding,
111 # true means official Google Chrome branding (requires extra Google-internal
113 # TODO(brettw) move to chrome_build.gni when DEPS are updated.
114 is_chrome_branded = false
116 # Compile for Address Sanitizer to find memory bugs.
119 # Compile for Leak Sanitizer to find leaks.
122 # Compile for Memory Sanitizer to find uninitialized reads.
125 # Compile for Thread Sanitizer to find threading bugs.
128 if (current_os == "chromeos") {
129 # Allows the target toolchain to be injected as arguments. This is needed
130 # to support the CrOS build system which supports per-build-configuration
132 cros_use_custom_toolchain = false
135 # DON'T ADD MORE FLAGS HERE. Read the comment above.
138 # =============================================================================
140 # =============================================================================
142 # We set these various is_FOO booleans for convenience in writing OS-based
145 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
146 # - is_mac is set only for desktop Mac. It is not set on iOS.
147 # - is_posix is true for mac and any Unix-like system (basically everything
149 # - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
150 # generally too different despite being based on the Linux kernel).
152 # Do not add more is_* variants here for random lesser-used Unix systems like
153 # aix or one of the BSDs. If you need to check these, just check the
154 # current_os value directly.
156 if (current_os == "win") {
165 } else if (current_os == "mac") {
174 } else if (current_os == "android") {
183 } else if (current_os == "chromeos") {
192 } else if (current_os == "nacl") {
193 # current_os == "nacl" will be passed by the nacl toolchain definition.
194 # It is not set by default or on the command line. We treat is as a
204 } else if (current_os == "ios") {
213 } else if (current_os == "linux") {
224 # =============================================================================
226 # =============================================================================
228 # These patterns filter out platform-specific files when assigning to the
229 # sources variable. The magic variable |sources_assignment_filter| is applied
230 # to each assignment or appending to the sources variable and matches are
231 # automatcally removed.
233 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
234 # boundary = end of string or slash) are supported, and the entire string
235 # muct match the pattern (so you need "*.cc" to match all .cc files, for
238 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
240 sources_assignment_filter = []
242 sources_assignment_filter += [
245 "*_posix_unittest.h",
246 "*_posix_unittest.cc",
251 sources_assignment_filter += [
261 sources_assignment_filter += [
272 "*_cocoa_unittest.h",
273 "*_cocoa_unittest.cc",
274 "*_cocoa_unittest.mm",
279 sources_assignment_filter += [
289 if (!is_mac && !is_ios) {
290 sources_assignment_filter += [ "*.mm" ]
293 sources_assignment_filter += [
296 "*_linux_unittest.h",
297 "*_linux_unittest.cc",
302 sources_assignment_filter += [
305 "*_android_unittest.h",
306 "*_android_unittest.cc",
311 sources_assignment_filter += [
314 "*_chromeos_unittest.h",
315 "*_chromeos_unittest.cc",
320 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
323 # Actually save this list.
325 # These patterns are executed for every file in the source tree of every run.
326 # Therefore, adding more patterns slows down the build for everybody. We should
327 # only add automatic patterns for configurations affecting hundreds of files
328 # across many projects in the tree.
330 # Therefore, we only add rules to this list corresponding to platforms on the
331 # Chromium waterfall. This is not for non-officially-supported platforms
332 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
333 # write a conditional in the target to remove the file(s) from the list when
334 # your platform/toolkit/feature doesn't apply.
335 set_sources_assignment_filter(sources_assignment_filter)
337 # =============================================================================
339 # =============================================================================
341 # These Sanitizers all imply using the Clang compiler. On Windows they either
342 # don't work or work differently.
343 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
347 # =============================================================================
349 # =============================================================================
351 # Set up the default configuration for every build target of the given type.
352 # The values configured here will be automatically set on the scope of the
353 # corresponding target. Target definitions can add or remove to the settings
356 # Holds all configs used for making native executables and libraries, to avoid
357 # duplication in each target below.
358 _native_compiler_configs = [
359 "//build/config:feature_flags",
360 "//build/config/compiler:compiler",
361 "//build/config/compiler:compiler_arm_fpu",
362 "//build/config/compiler:chromium_code",
363 "//build/config/compiler:default_include_dirs",
364 "//build/config/compiler:no_rtti",
365 "//build/config/compiler:runtime_library",
368 _native_compiler_configs += [
369 "//build/config/win:lean_and_mean",
370 "//build/config/win:nominmax",
371 "//build/config/win:sdk",
372 "//build/config/win:unicode",
373 "//build/config/win:winver",
377 _native_compiler_configs += [
378 "//build/config/gcc:no_exceptions",
379 "//build/config/gcc:symbol_visibility_hidden",
384 _native_compiler_configs += [ "//build/config/linux:sdk" ]
386 _native_compiler_configs += [ "//build/config/mac:sdk" ]
388 _native_compiler_configs += [ "//build/config/ios:sdk" ]
389 } else if (is_android) {
390 _native_compiler_configs += [ "//build/config/android:sdk" ]
394 _native_compiler_configs += [
395 "//build/config/clang:find_bad_constructs",
396 "//build/config/clang:extra_warnings",
400 # Optimizations and debug checking.
402 _native_compiler_configs += [ "//build/config:debug" ]
403 _default_optimization_config = "//build/config/compiler:no_optimize"
405 _native_compiler_configs += [ "//build/config:release" ]
406 _default_optimization_config = "//build/config/compiler:optimize"
408 _native_compiler_configs += [ _default_optimization_config ]
410 # If it wasn't manually set, set to an appropriate default.
411 if (symbol_level == -1) {
412 # Linux is slowed by having symbols as part of the target binary, whereas
413 # Mac and Windows have them separate, so in Release Linux, default them off.
414 if (is_debug || !is_linux) {
416 } else if (is_asan || is_lsan || is_tsan || is_msan) {
417 # Sanitizers require symbols for filename suppressions to work.
425 if (symbol_level == 2) {
426 _default_symbols_config = "//build/config/compiler:symbols"
427 } else if (symbol_level == 1) {
428 _default_symbols_config = "//build/config/compiler:minimal_symbols"
429 } else if (symbol_level == 0) {
430 _default_symbols_config = "//build/config/compiler:no_symbols"
432 assert(false, "Bad value for symbol_level.")
434 _native_compiler_configs += [ _default_symbols_config ]
436 # Windows linker setup for EXEs and DLLs.
438 _windows_linker_configs = [
439 "//build/config/win:default_incremental_linking",
440 "//build/config/win:sdk_link",
441 "//build/config/win:common_linker_setup",
443 # Default to console-mode apps. Most of our targets are tests and such
444 # that shouldn't use the windows subsystem.
445 "//build/config/win:console",
449 # Executable defaults.
450 _executable_configs =
451 _native_compiler_configs + [ "//build/config:default_libs" ]
453 _executable_configs += _windows_linker_configs
455 _executable_configs += [
456 "//build/config/mac:mac_dynamic_flags",
457 "//build/config/mac:mac_executable_flags",
459 } else if (is_linux || is_android) {
460 _executable_configs += [ "//build/config/gcc:executable_ldconfig" ]
462 _executable_configs += [ "//build/config/android:executable_config" ]
465 set_defaults("executable") {
466 configs = _executable_configs
469 # Static library defaults.
470 set_defaults("static_library") {
471 configs = _native_compiler_configs
474 # Shared library defaults (also for components in component mode).
475 _shared_library_configs =
476 _native_compiler_configs + [ "//build/config:default_libs" ]
478 _shared_library_configs += _windows_linker_configs
480 _shared_library_configs += [ "//build/config/mac:mac_dynamic_flags" ]
481 } else if (is_android) {
482 # Strip native JNI exports from shared libraries by default. Binaries that
483 # want this can remove this config.
484 _shared_library_configs +=
485 [ "//build/config/android:hide_native_jni_exports" ]
487 set_defaults("shared_library") {
488 configs = _shared_library_configs
490 if (is_component_build) {
491 set_defaults("component") {
492 configs = _shared_library_configs
496 # Source set defaults (also for components in non-component mode).
497 set_defaults("source_set") {
498 configs = _native_compiler_configs
500 if (!is_component_build) {
501 set_defaults("component") {
502 configs = _native_compiler_configs
507 set_defaults("test") {
509 configs = _shared_library_configs
511 configs = _executable_configs
515 # ==============================================================================
517 # ==============================================================================
519 # Here we set the default toolchain, as well as the variable host_toolchain
520 # which will identify the toolchain corresponding to the local system when
521 # doing cross-compiles. When not cross-compiling, this will be the same as the
525 # On windows we use the same toolchain for host and target by default.
527 host_toolchain = "//build/toolchain/win:clang_$current_cpu"
529 host_toolchain = "//build/toolchain/win:$current_cpu"
531 set_default_toolchain("$host_toolchain")
532 } else if (is_android) {
533 if (host_os == "linux") {
534 # Use clang for the x86/64 Linux host builds.
535 if (host_cpu == "x86" || host_cpu == "x64") {
536 host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
538 host_toolchain = "//build/toolchain/linux:$host_cpu"
540 } else if (host_os == "mac") {
541 host_toolchain = "//build/toolchain/mac:clang_$host_cpu"
543 assert(false, "Unknown host for android cross compile")
545 set_default_toolchain("//build/toolchain/android:$current_cpu")
546 } else if (is_linux) {
548 host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
549 set_default_toolchain("//build/toolchain/linux:clang_$current_cpu")
551 host_toolchain = "//build/toolchain/linux:$host_cpu"
552 set_default_toolchain("//build/toolchain/linux:$current_cpu")
554 if (is_chromeos && cros_use_custom_toolchain) {
555 set_default_toolchain("//build/toolchain/cros:target")
558 host_toolchain = "//build/toolchain/mac:clang_x64"
559 set_default_toolchain(host_toolchain)
561 host_toolchain = "//build/toolchain/mac:clang_x64"
562 set_default_toolchain("//build/toolchain/mac:clang_$current_cpu")
563 } else if (is_nacl) {
564 # TODO(GYP): This will need to change when we get NaCl working
565 # on multiple platforms, but this whole block of code (how we define
566 # host_toolchain) needs to be reworked regardless to key off of host_os
567 # and host_cpu rather than the is_* variables.
568 host_toolchain = "//build/toolchain/linux:clang_x64"
571 # ==============================================================================
573 # ==============================================================================
575 # TODO(brettw) erase this once the built-in "component" function is removed.
576 if (is_component_build) {
577 component_mode = "shared_library"
579 component_mode = "source_set"
582 template("component") {
583 if (is_component_build) {
584 shared_library(target_name) {
585 # Configs will always be defined since we set_defaults for a component
586 # above. We want to use those rather than whatever came with the nested
587 # shared/static library inside the component.
588 configs = [] # Prevent list overwriting warning.
589 configs = invoker.configs
591 # The sources assignment filter will have already been applied when the
592 # code was originally executed. We don't want to apply it again, since
593 # the original target may have override it for some assignments.
594 set_sources_assignment_filter([])
596 if (defined(invoker.all_dependent_configs)) {
597 all_dependent_configs = invoker.all_dependent_configs
599 if (defined(invoker.allow_circular_includes_from)) {
600 allow_circular_includes_from = invoker.allow_circular_includes_from
602 if (defined(invoker.cflags)) {
603 cflags = invoker.cflags
605 if (defined(invoker.cflags_c)) {
606 cflags_c = invoker.cflags_c
608 if (defined(invoker.cflags_cc)) {
609 cflags_cc = invoker.cflags_cc
611 if (defined(invoker.cflags_objc)) {
612 cflags_objc = invoker.cflags_objc
614 if (defined(invoker.cflags_objcc)) {
615 cflags_objcc = invoker.cflags_objcc
617 if (defined(invoker.check_includes)) {
618 check_includes = invoker.check_includes
620 if (defined(invoker.data)) {
623 if (defined(invoker.data_deps)) {
624 data_deps = invoker.data_deps
626 if (defined(invoker.datadeps)) {
627 datadeps = invoker.datadeps
629 if (defined(invoker.defines)) {
630 defines = invoker.defines
633 # All shared libraries must have the sanitizer deps to properly link in
634 # asan mode (this target will be empty in other cases).
635 if (defined(invoker.deps)) {
636 deps = invoker.deps + [ "//build/config/sanitizers:deps" ]
639 "//build/config/sanitizers:deps",
642 if (defined(invoker.direct_dependent_configs)) {
643 direct_dependent_configs = invoker.direct_dependent_configs
645 if (defined(invoker.forward_dependent_configs_from)) {
646 forward_dependent_configs_from = invoker.forward_dependent_configs_from
648 if (defined(invoker.include_dirs)) {
649 include_dirs = invoker.include_dirs
651 if (defined(invoker.ldflags)) {
652 ldflags = invoker.ldflags
654 if (defined(invoker.lib_dirs)) {
655 lib_dirs = invoker.lib_dirs
657 if (defined(invoker.libs)) {
660 if (defined(invoker.output_extension)) {
661 output_extension = invoker.output_extension
663 if (defined(invoker.output_name)) {
664 output_name = invoker.output_name
666 if (defined(invoker.public)) {
667 public = invoker.public
669 if (defined(invoker.public_configs)) {
670 public_configs = invoker.public_configs
672 if (defined(invoker.public_deps)) {
673 public_deps = invoker.public_deps
675 if (defined(invoker.sources)) {
676 sources = invoker.sources
678 if (defined(invoker.testonly)) {
679 testonly = invoker.testonly
681 if (defined(invoker.visibility)) {
682 visibility = invoker.visibility
686 source_set(target_name) {
688 configs = [] # Prevent list overwriting warning.
689 configs = invoker.configs
692 set_sources_assignment_filter([])
694 if (defined(invoker.all_dependent_configs)) {
695 all_dependent_configs = invoker.all_dependent_configs
697 if (defined(invoker.allow_circular_includes_from)) {
698 allow_circular_includes_from = invoker.allow_circular_includes_from
700 if (defined(invoker.cflags)) {
701 cflags = invoker.cflags
703 if (defined(invoker.cflags_c)) {
704 cflags_c = invoker.cflags_c
706 if (defined(invoker.cflags_cc)) {
707 cflags_cc = invoker.cflags_cc
709 if (defined(invoker.cflags_objc)) {
710 cflags_objc = invoker.cflags_objc
712 if (defined(invoker.cflags_objcc)) {
713 cflags_objcc = invoker.cflags_objcc
715 if (defined(invoker.check_includes)) {
716 check_includes = invoker.check_includes
718 if (defined(invoker.data)) {
721 if (defined(invoker.data_deps)) {
722 data_deps = invoker.data_deps
724 if (defined(invoker.datadeps)) {
725 datadeps = invoker.datadeps
727 if (defined(invoker.defines)) {
728 defines = invoker.defines
730 if (defined(invoker.deps)) {
733 if (defined(invoker.direct_dependent_configs)) {
734 direct_dependent_configs = invoker.direct_dependent_configs
736 if (defined(invoker.forward_dependent_configs_from)) {
737 forward_dependent_configs_from = invoker.forward_dependent_configs_from
739 if (defined(invoker.include_dirs)) {
740 include_dirs = invoker.include_dirs
742 if (defined(invoker.ldflags)) {
743 ldflags = invoker.ldflags
745 if (defined(invoker.lib_dirs)) {
746 lib_dirs = invoker.lib_dirs
748 if (defined(invoker.libs)) {
751 if (defined(invoker.output_extension)) {
752 output_extension = invoker.output_extension
754 if (defined(invoker.output_name)) {
755 output_name = invoker.output_name
757 if (defined(invoker.public)) {
758 public = invoker.public
760 if (defined(invoker.public_configs)) {
761 public_configs = invoker.public_configs
763 if (defined(invoker.public_deps)) {
764 public_deps = invoker.public_deps
766 if (defined(invoker.sources)) {
767 sources = invoker.sources
769 if (defined(invoker.testonly)) {
770 testonly = invoker.testonly
772 if (defined(invoker.visibility)) {
773 visibility = invoker.visibility