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.
28 is_component_build = false
32 # Set to true when compiling with the Clang compiler. Typically this is used
33 # to configure warnings.
36 # Forces a 64-bit build on Windows. Does nothing on other platforms. Normally
37 # we build 32-bit on Windows regardless of the current host OS bit depth.
38 # Setting this flag will override this logic and generate 64-bit toolchains.
40 # Normally this would get set automatically when you specify a target using
41 # the 64-bit toolchain. You can also set this on the command line to convert
42 # the default toolchain to 64-bit.
45 # Selects the desired build flavor. Official builds get additional
46 # processing to prepare for release. Normally you will want to develop and
47 # test with this flag off.
48 is_official_build = false
50 # Select the desired branding flavor. False means normal Chromium branding,
51 # true means official Google Chrome branding (requires extra Google-internal
53 is_chrome_branded = false
55 # Compile for Address Sanitizer to find memory bugs.
58 # Compile for Leak Sanitizer to find leaks.
61 # Compile for Memory Sanitizer to find uninitialized reads.
64 # Compile for Thread Sanitizer to find threading bugs.
68 # =============================================================================
70 # =============================================================================
72 # We set these various is_FOO booleans for convenience in writing OS-based
75 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
76 # - is_mac is set only for desktop Mac. It is not set on iOS.
77 # - is_posix is true for mac and any Unix-like system (basically everything
79 # - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
80 # generally too different despite being based on the Linux kernel).
82 # Do not add more is_* variants here for random lesser-used Unix systems like
83 # aix or one of the BSDs. If you need to check these, just check the os value
95 } else if (os == "mac") {
105 is_clang = true # Always use clang on Mac.
107 } else if (os == "android") {
116 } else if (os == "chromeos") {
125 } else if (os == "nacl") {
126 # os == "nacl" will be passed by the nacl toolchain definition. It is not
127 # set by default or on the command line. We treat is as a Posix variant.
136 } else if (os == "ios") {
145 if (!is_gyp_xcode_generator) {
146 # Always use clang on iOS when using ninja
149 } else if (os == "linux") {
160 is_desktop_linux = is_linux && !is_chromeos
162 # =============================================================================
164 # =============================================================================
167 # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
168 # unless the override flag is specified.
176 # =============================================================================
178 # =============================================================================
180 # These patterns filter out platform-specific files when assigning to the
181 # sources variable. The magic variable |sources_assignment_filter| is applied
182 # to each assignment or appending to the sources variable and matches are
183 # automatcally removed.
185 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
186 # boundary = end of string or slash) are supported, and the entire string
187 # muct match the pattern (so you need "*.cc" to match all .cc files, for
190 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
192 sources_assignment_filter = []
194 sources_assignment_filter += [
197 "*_posix_unittest.h",
198 "*_posix_unittest.cc",
203 sources_assignment_filter += [
212 sources_assignment_filter += [
223 "*_cocoa_unittest.h",
224 "*_cocoa_unittest.cc",
225 "*_cocoa_unittest.mm",
230 sources_assignment_filter += [
240 if (!is_mac && !is_ios) {
241 sources_assignment_filter += [
246 sources_assignment_filter += [
249 "*_linux_unittest.h",
250 "*_linux_unittest.cc",
255 sources_assignment_filter += [
258 "*_android_unittest.h",
259 "*_android_unittest.cc",
264 sources_assignment_filter += [
267 "*_chromeos_unittest.h",
268 "*_chromeos_unittest.cc",
272 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
275 # Actually save this list.
277 # These patterns are executed for every file in the source tree of every run.
278 # Therefore, adding more patterns slows down the build for everybody. We should
279 # only add automatic patterns for configurations affecting hundreds of files
280 # across many projects in the tree.
282 # Therefore, we only add rules to this list corresponding to platforms on the
283 # Chromium waterfall. This is not for non-officially-supported platforms
284 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
285 # write a conditional in the target to remove the file(s) from the list when
286 # your platform/toolkit/feature doesn't apply.
287 set_sources_assignment_filter(sources_assignment_filter)
289 # =============================================================================
291 # =============================================================================
293 if (is_component_build) {
294 component_mode = "shared_library"
296 component_mode = "source_set"
299 # These Sanitizers all imply using the Clang compiler. On Windows they either
300 # don't work or work differently.
301 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
305 # =============================================================================
307 # =============================================================================
309 # Set up the default configuration for every build target of the given type.
310 # The values configured here will be automatically set on the scope of the
311 # corresponding target. Target definitions can add or remove to the settings
314 # Holds all configs used for making native executables and libraries, to avoid
315 # duplication in each target below.
316 _native_compiler_configs = [
317 "//build/config:feature_flags",
319 "//build/config/compiler:compiler",
320 "//build/config/compiler:chromium_code",
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",
334 _native_compiler_configs += [
335 "//build/config/gcc:no_exceptions",
336 "//build/config/gcc:symbol_visibility_hidden",
341 _native_compiler_configs += [ "//build/config/linux:sdk", ]
343 _native_compiler_configs += [ "//build/config/mac:sdk", ]
345 _native_compiler_configs += [ "//build/config/ios:sdk", ]
346 } else if (is_android) {
347 _native_compiler_configs += [ "//build/config/android:sdk", ]
351 _native_compiler_configs += [
352 "//build/config/clang:find_bad_constructs",
353 "//build/config/clang:extra_warnings",
357 # Optimizations and debug checking.
359 _native_compiler_configs += [ "//build/config:debug" ]
360 _default_optimization_config = "//build/config/compiler:no_optimize"
362 _native_compiler_configs += [ "//build/config:release" ]
363 _default_optimization_config = "//build/config/compiler:optimize"
365 _native_compiler_configs += [ _default_optimization_config ]
368 if (is_clang && (is_linux || is_android)) {
369 # Clang creates chubby debug information, which makes linking very slow.
370 # For now, don't create debug information with clang.
371 # See http://crbug.com/70000
372 # TODO(brettw) This just copies GYP. Why not do this on Mac as well?
373 _default_symbols_config = "//build/config/compiler:no_symbols"
374 } else if (symbol_level == 2) {
375 _default_symbols_config = "//build/config/compiler:symbols"
376 } else if (symbol_level == 1) {
377 _default_symbols_config = "//build/config/compiler:minimal_symbols"
378 } else if (symbol_level == 0) {
379 _default_symbols_config = "//build/config/compiler:no_symbols"
381 assert(false, "Bad value for symbol_level.")
383 _native_compiler_configs += [ _default_symbols_config ]
385 # Windows linker setup for EXEs and DLLs.
388 _default_incremental_linking_config =
389 "//build/config/win:incremental_linking"
391 _default_incremental_linking_config =
392 "//build/config/win:no_incremental_linking"
394 _windows_linker_configs = [
395 _default_incremental_linking_config,
396 "//build/config/win:sdk_link",
397 "//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 set_defaults("executable") {
405 configs = _native_compiler_configs + [
406 "//build/config:default_libs",
409 configs += _windows_linker_configs
412 "//build/config/mac:mac_dynamic_flags",
413 "//build/config/mac:mac_executable_flags" ]
414 } else if (is_linux || is_android) {
415 configs += [ "//build/config/gcc:executable_ldconfig" ]
419 set_defaults("static_library") {
420 configs = _native_compiler_configs
423 set_defaults("shared_library") {
424 configs = _native_compiler_configs + [
425 "//build/config:default_libs",
428 configs += _windows_linker_configs
430 configs += [ "//build/config/mac:mac_dynamic_flags" ]
434 set_defaults("source_set") {
435 configs = _native_compiler_configs
438 # ==============================================================================
440 # ==============================================================================
442 # Here we set the default toolchain, as well as the variable host_toolchain
443 # which will identify the toolchain corresponding to the local system when
444 # doing cross-compiles. When not cross-compiling, this will be the same as the
448 # TODO(brettw) name the toolchains the same as cpu_arch as with Linux below
449 # to eliminate these conditionals.
450 if (build_cpu_arch == "x64") {
451 host_toolchain = "//build/toolchain/win:64"
452 } else if (build_cpu_arch == "x86") {
453 host_toolchain = "//build/toolchain/win:32"
456 if (cpu_arch == "x64") {
457 set_default_toolchain("//build/toolchain/win:64")
458 } else if (cpu_arch == "x86") {
459 set_default_toolchain("//build/toolchain/win:32")
461 } else if (is_android) {
462 host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
463 set_default_toolchain("//build/toolchain/android:$cpu_arch")
464 } else if (is_linux) {
465 host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
466 set_default_toolchain("//build/toolchain/linux:$cpu_arch")
468 host_toolchain = "//build/toolchain/mac:clang"
469 set_default_toolchain(host_toolchain)
471 host_toolchain = "//build/toolchain/mac:host_clang"
472 set_default_toolchain("//build/toolchain/mac:clang")