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 is_official_build = false
71 # Select the desired branding flavor. False means normal Chromium branding,
72 # true means official Google Chrome branding (requires extra Google-internal
74 is_chrome_branded = false
76 # Compile for Address Sanitizer to find memory bugs.
79 # Compile for Leak Sanitizer to find leaks.
82 # Compile for Memory Sanitizer to find uninitialized reads.
85 # Compile for Thread Sanitizer to find threading bugs.
88 if (current_os == "chromeos") {
89 # Allows the target toolchain to be injected as arguments. This is needed
90 # to support the CrOS build system which supports per-build-configuration
92 cros_use_custom_toolchain = false
96 # =============================================================================
98 # =============================================================================
100 # We set these various is_FOO booleans for convenience in writing OS-based
103 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
104 # - is_mac is set only for desktop Mac. It is not set on iOS.
105 # - is_posix is true for mac and any Unix-like system (basically everything
107 # - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
108 # generally too different despite being based on the Linux kernel).
110 # Do not add more is_* variants here for random lesser-used Unix systems like
111 # aix or one of the BSDs. If you need to check these, just check the
112 # current_os value directly.
114 if (current_os == "win") {
123 } else if (current_os == "mac") {
132 } else if (current_os == "android") {
141 } else if (current_os == "chromeos") {
150 } else if (current_os == "nacl") {
151 # current_os == "nacl" will be passed by the nacl toolchain definition.
152 # It is not set by default or on the command line. We treat is as a
162 } else if (current_os == "ios") {
171 } else if (current_os == "linux") {
182 # =============================================================================
184 # =============================================================================
186 # These patterns filter out platform-specific files when assigning to the
187 # sources variable. The magic variable |sources_assignment_filter| is applied
188 # to each assignment or appending to the sources variable and matches are
189 # automatcally removed.
191 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
192 # boundary = end of string or slash) are supported, and the entire string
193 # muct match the pattern (so you need "*.cc" to match all .cc files, for
196 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
198 sources_assignment_filter = []
200 sources_assignment_filter += [
203 "*_posix_unittest.h",
204 "*_posix_unittest.cc",
209 sources_assignment_filter += [
218 sources_assignment_filter += [
229 "*_cocoa_unittest.h",
230 "*_cocoa_unittest.cc",
231 "*_cocoa_unittest.mm",
236 sources_assignment_filter += [
246 if (!is_mac && !is_ios) {
247 sources_assignment_filter += [ "*.mm" ]
250 sources_assignment_filter += [
253 "*_linux_unittest.h",
254 "*_linux_unittest.cc",
259 sources_assignment_filter += [
262 "*_android_unittest.h",
263 "*_android_unittest.cc",
268 sources_assignment_filter += [
271 "*_chromeos_unittest.h",
272 "*_chromeos_unittest.cc",
277 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
280 # Actually save this list.
282 # These patterns are executed for every file in the source tree of every run.
283 # Therefore, adding more patterns slows down the build for everybody. We should
284 # only add automatic patterns for configurations affecting hundreds of files
285 # across many projects in the tree.
287 # Therefore, we only add rules to this list corresponding to platforms on the
288 # Chromium waterfall. This is not for non-officially-supported platforms
289 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
290 # write a conditional in the target to remove the file(s) from the list when
291 # your platform/toolkit/feature doesn't apply.
292 set_sources_assignment_filter(sources_assignment_filter)
294 # =============================================================================
296 # =============================================================================
298 # These Sanitizers all imply using the Clang compiler. On Windows they either
299 # don't work or work differently.
300 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
304 # =============================================================================
306 # =============================================================================
308 # Set up the default configuration for every build target of the given type.
309 # The values configured here will be automatically set on the scope of the
310 # corresponding target. Target definitions can add or remove to the settings
313 # Holds all configs used for making native executables and libraries, to avoid
314 # duplication in each target below.
315 _native_compiler_configs = [
316 "//build/config:feature_flags",
317 "//build/config/compiler:compiler",
318 "//build/config/compiler:compiler_arm_fpu",
319 "//build/config/compiler:chromium_code",
320 "//build/config/compiler:default_include_dirs",
321 "//build/config/compiler:default_warnings",
322 "//build/config/compiler:no_rtti",
323 "//build/config/compiler:runtime_library",
326 _native_compiler_configs += [
327 "//build/config/win:lean_and_mean",
328 "//build/config/win:nominmax",
329 "//build/config/win:sdk",
330 "//build/config/win:unicode",
331 "//build/config/win:winver",
335 _native_compiler_configs += [
336 "//build/config/gcc:no_exceptions",
337 "//build/config/gcc:symbol_visibility_hidden",
342 _native_compiler_configs += [ "//build/config/linux:sdk" ]
344 _native_compiler_configs += [ "//build/config/mac:sdk" ]
346 _native_compiler_configs += [ "//build/config/ios:sdk" ]
347 } else if (is_android) {
348 _native_compiler_configs += [ "//build/config/android:sdk" ]
352 _native_compiler_configs += [
353 "//build/config/clang:find_bad_constructs",
354 "//build/config/clang:extra_warnings",
358 # Optimizations and debug checking.
360 _native_compiler_configs += [ "//build/config:debug" ]
361 _default_optimization_config = "//build/config/compiler:no_optimize"
363 _native_compiler_configs += [ "//build/config:release" ]
364 _default_optimization_config = "//build/config/compiler:optimize"
366 _native_compiler_configs += [ _default_optimization_config ]
368 # If it wasn't manually set, set to an appropriate default.
369 if (symbol_level == -1) {
370 # Linux is slowed by having symbols as part of the target binary, whereas
371 # Mac and Windows have them separate, so in Release Linux, default them off.
372 if (is_debug || !is_linux) {
380 if (symbol_level == 2) {
381 _default_symbols_config = "//build/config/compiler:symbols"
382 } else if (symbol_level == 1) {
383 _default_symbols_config = "//build/config/compiler:minimal_symbols"
384 } else if (symbol_level == 0) {
385 _default_symbols_config = "//build/config/compiler:no_symbols"
387 assert(false, "Bad value for symbol_level.")
389 _native_compiler_configs += [ _default_symbols_config ]
391 # Windows linker setup for EXEs and DLLs.
393 _windows_linker_configs = [
394 "//build/config/win:default_incremental_linking",
395 "//build/config/win:sdk_link",
396 "//build/config/win:common_linker_setup",
398 # Default to console-mode apps. Most of our targets are tests and such
399 # that shouldn't use the windows subsystem.
400 "//build/config/win:console",
404 # Executable defaults.
405 _executable_configs =
406 _native_compiler_configs + [ "//build/config:default_libs" ]
408 _executable_configs += _windows_linker_configs
410 _executable_configs += [
411 "//build/config/mac:mac_dynamic_flags",
412 "//build/config/mac:mac_executable_flags",
414 } else if (is_linux || is_android) {
415 _executable_configs += [ "//build/config/gcc:executable_ldconfig" ]
417 _executable_configs += [ "//build/config/android:executable_config" ]
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 =
431 _native_compiler_configs + [ "//build/config:default_libs" ]
433 _shared_library_configs += _windows_linker_configs
435 _shared_library_configs += [ "//build/config/mac:mac_dynamic_flags" ]
436 } else if (is_android) {
437 # Strip native JNI exports from shared libraries by default. Binaries that
438 # want this can remove this config.
439 _shared_library_configs +=
440 [ "//build/config/android:hide_native_jni_exports" ]
442 set_defaults("shared_library") {
443 configs = _shared_library_configs
445 if (is_component_build) {
446 set_defaults("component") {
447 configs = _shared_library_configs
451 # Source set defaults (also for components in non-component mode).
452 set_defaults("source_set") {
453 configs = _native_compiler_configs
455 if (!is_component_build) {
456 set_defaults("component") {
457 configs = _native_compiler_configs
462 set_defaults("test") {
464 configs = _shared_library_configs
466 configs = _executable_configs
470 # ==============================================================================
472 # ==============================================================================
474 # Here we set the default toolchain, as well as the variable host_toolchain
475 # which will identify the toolchain corresponding to the local system when
476 # doing cross-compiles. When not cross-compiling, this will be the same as the
480 # On windows we use the same toolchain for host and target by default.
481 # TODO(dpranke): rename the toolchains to x64 and x86 to match current_cpu.
482 if (current_cpu == "x64") {
483 host_toolchain = "//build/toolchain/win:64"
484 } else if (current_cpu == "x86") {
485 host_toolchain = "//build/toolchain/win:32"
487 set_default_toolchain("$host_toolchain")
488 } else if (is_android) {
489 # Use clang for the x86/64 Linux host builds.
490 if (host_cpu == "x86" || host_cpu == "x64") {
491 host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
493 host_toolchain = "//build/toolchain/linux:$host_cpu"
495 set_default_toolchain("//build/toolchain/android:$current_cpu")
496 } else if (is_linux) {
498 host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
499 set_default_toolchain("//build/toolchain/linux:clang_$current_cpu")
501 host_toolchain = "//build/toolchain/linux:$host_cpu"
502 set_default_toolchain("//build/toolchain/linux:$current_cpu")
504 if (is_chromeos && cros_use_custom_toolchain) {
505 set_default_toolchain("//build/toolchain/cros:target")
508 host_toolchain = "//build/toolchain/mac:clang"
509 set_default_toolchain(host_toolchain)
511 host_toolchain = "//build/toolchain/mac:host_clang"
512 set_default_toolchain("//build/toolchain/mac:clang")
513 } else if (is_nacl) {
514 # TODO(GYP): This will need to change when we get NaCl working
515 # on multiple platforms, but this whole block of code (how we define
516 # host_toolchain) needs to be reworked regardless to key off of host_os
517 # and host_cpu rather than the is_* variables.
518 host_toolchain = "//build/toolchain/linux:clang_x64"
521 # ==============================================================================
523 # ==============================================================================
525 # TODO(brettw) erase this once the built-in "component" function is removed.
526 if (is_component_build) {
527 component_mode = "shared_library"
529 component_mode = "source_set"
532 template("component") {
533 if (is_component_build) {
534 shared_library(target_name) {
535 # Configs will always be defined since we set_defaults for a component
536 # above. We want to use those rather than whatever came with the nested
537 # shared/static library inside the component.
538 configs = [] # Prevent list overwriting warning.
539 configs = invoker.configs
541 # The sources assignment filter will have already been applied when the
542 # code was originally executed. We don't want to apply it again, since
543 # the original target may have override it for some assignments.
544 set_sources_assignment_filter([])
546 if (defined(invoker.all_dependent_configs)) {
547 all_dependent_configs = invoker.all_dependent_configs
549 if (defined(invoker.allow_circular_includes_from)) {
550 allow_circular_includes_from = invoker.allow_circular_includes_from
552 if (defined(invoker.cflags)) {
553 cflags = invoker.cflags
555 if (defined(invoker.cflags_c)) {
556 cflags_c = invoker.cflags_c
558 if (defined(invoker.cflags_cc)) {
559 cflags_cc = invoker.cflags_cc
561 if (defined(invoker.cflags_objc)) {
562 cflags_objc = invoker.cflags_objc
564 if (defined(invoker.cflags_objcc)) {
565 cflags_objcc = invoker.cflags_objcc
567 if (defined(invoker.check_includes)) {
568 check_includes = invoker.check_includes
570 if (defined(invoker.data)) {
573 if (defined(invoker.data_deps)) {
574 data_deps = invoker.data_deps
576 if (defined(invoker.datadeps)) {
577 datadeps = invoker.datadeps
579 if (defined(invoker.defines)) {
580 defines = invoker.defines
583 # All shared libraries must have the sanitizer deps to properly link in
584 # asan mode (this target will be empty in other cases).
585 if (defined(invoker.deps)) {
586 deps = invoker.deps + [ "//build/config/sanitizers:deps" ]
589 "//build/config/sanitizers:deps",
592 if (defined(invoker.direct_dependent_configs)) {
593 direct_dependent_configs = invoker.direct_dependent_configs
595 if (defined(invoker.forward_dependent_configs_from)) {
596 forward_dependent_configs_from = invoker.forward_dependent_configs_from
598 if (defined(invoker.include_dirs)) {
599 include_dirs = invoker.include_dirs
601 if (defined(invoker.ldflags)) {
602 ldflags = invoker.ldflags
604 if (defined(invoker.lib_dirs)) {
605 lib_dirs = invoker.lib_dirs
607 if (defined(invoker.libs)) {
610 if (defined(invoker.output_extension)) {
611 output_extension = invoker.output_extension
613 if (defined(invoker.output_name)) {
614 output_name = invoker.output_name
616 if (defined(invoker.public)) {
617 public = invoker.public
619 if (defined(invoker.public_configs)) {
620 public_configs = invoker.public_configs
622 if (defined(invoker.public_deps)) {
623 public_deps = invoker.public_deps
625 if (defined(invoker.sources)) {
626 sources = invoker.sources
628 if (defined(invoker.testonly)) {
629 testonly = invoker.testonly
631 if (defined(invoker.visibility)) {
632 visibility = invoker.visibility
636 source_set(target_name) {
638 configs = [] # Prevent list overwriting warning.
639 configs = invoker.configs
642 set_sources_assignment_filter([])
644 if (defined(invoker.all_dependent_configs)) {
645 all_dependent_configs = invoker.all_dependent_configs
647 if (defined(invoker.allow_circular_includes_from)) {
648 allow_circular_includes_from = invoker.allow_circular_includes_from
650 if (defined(invoker.cflags)) {
651 cflags = invoker.cflags
653 if (defined(invoker.cflags_c)) {
654 cflags_c = invoker.cflags_c
656 if (defined(invoker.cflags_cc)) {
657 cflags_cc = invoker.cflags_cc
659 if (defined(invoker.cflags_objc)) {
660 cflags_objc = invoker.cflags_objc
662 if (defined(invoker.cflags_objcc)) {
663 cflags_objcc = invoker.cflags_objcc
665 if (defined(invoker.check_includes)) {
666 check_includes = invoker.check_includes
668 if (defined(invoker.data)) {
671 if (defined(invoker.data_deps)) {
672 data_deps = invoker.data_deps
674 if (defined(invoker.datadeps)) {
675 datadeps = invoker.datadeps
677 if (defined(invoker.defines)) {
678 defines = invoker.defines
680 if (defined(invoker.deps)) {
683 if (defined(invoker.direct_dependent_configs)) {
684 direct_dependent_configs = invoker.direct_dependent_configs
686 if (defined(invoker.forward_dependent_configs_from)) {
687 forward_dependent_configs_from = invoker.forward_dependent_configs_from
689 if (defined(invoker.include_dirs)) {
690 include_dirs = invoker.include_dirs
692 if (defined(invoker.ldflags)) {
693 ldflags = invoker.ldflags
695 if (defined(invoker.lib_dirs)) {
696 lib_dirs = invoker.lib_dirs
698 if (defined(invoker.libs)) {
701 if (defined(invoker.output_extension)) {
702 output_extension = invoker.output_extension
704 if (defined(invoker.output_name)) {
705 output_name = invoker.output_name
707 if (defined(invoker.public)) {
708 public = invoker.public
710 if (defined(invoker.public_configs)) {
711 public_configs = invoker.public_configs
713 if (defined(invoker.public_deps)) {
714 public_deps = invoker.public_deps
716 if (defined(invoker.sources)) {
717 sources = invoker.sources
719 if (defined(invoker.testonly)) {
720 testonly = invoker.testonly
722 if (defined(invoker.visibility)) {
723 visibility = invoker.visibility