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.
34 is_clang = (os == "mac" || os == "ios" || os == "linux")
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") {
104 } else if (os == "android") {
113 } else if (os == "chromeos") {
122 } else if (os == "nacl") {
123 # os == "nacl" will be passed by the nacl toolchain definition. It is not
124 # set by default or on the command line. We treat is as a Posix variant.
133 } else if (os == "ios") {
142 } else if (os == "linux") {
153 is_desktop_linux = is_linux && !is_chromeos
155 # =============================================================================
157 # =============================================================================
160 # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
161 # unless the override flag is specified.
169 # =============================================================================
171 # =============================================================================
173 # These patterns filter out platform-specific files when assigning to the
174 # sources variable. The magic variable |sources_assignment_filter| is applied
175 # to each assignment or appending to the sources variable and matches are
176 # automatcally removed.
178 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
179 # boundary = end of string or slash) are supported, and the entire string
180 # muct match the pattern (so you need "*.cc" to match all .cc files, for
183 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
185 sources_assignment_filter = []
187 sources_assignment_filter += [
190 "*_posix_unittest.h",
191 "*_posix_unittest.cc",
196 sources_assignment_filter += [
205 sources_assignment_filter += [
216 "*_cocoa_unittest.h",
217 "*_cocoa_unittest.cc",
218 "*_cocoa_unittest.mm",
223 sources_assignment_filter += [
233 if (!is_mac && !is_ios) {
234 sources_assignment_filter += [
239 sources_assignment_filter += [
242 "*_linux_unittest.h",
243 "*_linux_unittest.cc",
248 sources_assignment_filter += [
251 "*_android_unittest.h",
252 "*_android_unittest.cc",
257 sources_assignment_filter += [
260 "*_chromeos_unittest.h",
261 "*_chromeos_unittest.cc",
265 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
268 # Actually save this list.
270 # These patterns are executed for every file in the source tree of every run.
271 # Therefore, adding more patterns slows down the build for everybody. We should
272 # only add automatic patterns for configurations affecting hundreds of files
273 # across many projects in the tree.
275 # Therefore, we only add rules to this list corresponding to platforms on the
276 # Chromium waterfall. This is not for non-officially-supported platforms
277 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
278 # write a conditional in the target to remove the file(s) from the list when
279 # your platform/toolkit/feature doesn't apply.
280 set_sources_assignment_filter(sources_assignment_filter)
282 # =============================================================================
284 # =============================================================================
286 if (is_component_build) {
287 component_mode = "shared_library"
289 component_mode = "source_set"
292 # These Sanitizers all imply using the Clang compiler. On Windows they either
293 # don't work or work differently.
294 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
298 # =============================================================================
300 # =============================================================================
302 # Set up the default configuration for every build target of the given type.
303 # The values configured here will be automatically set on the scope of the
304 # corresponding target. Target definitions can add or remove to the settings
307 # Holds all configs used for making native executables and libraries, to avoid
308 # duplication in each target below.
309 _native_compiler_configs = [
310 "//build/config:feature_flags",
312 "//build/config/compiler:compiler",
313 "//build/config/compiler:compiler_arm_fpu",
314 "//build/config/compiler:chromium_code",
315 "//build/config/compiler:default_include_dirs",
316 "//build/config/compiler:default_warnings",
317 "//build/config/compiler:no_rtti",
318 "//build/config/compiler:runtime_library",
321 _native_compiler_configs += [
322 "//build/config/win:lean_and_mean",
323 "//build/config/win:nominmax",
324 "//build/config/win:sdk",
325 "//build/config/win:unicode",
329 _native_compiler_configs += [
330 "//build/config/gcc:no_exceptions",
331 "//build/config/gcc:symbol_visibility_hidden",
336 _native_compiler_configs += [ "//build/config/linux:sdk", ]
338 _native_compiler_configs += [ "//build/config/mac:sdk", ]
340 _native_compiler_configs += [ "//build/config/ios:sdk", ]
341 } else if (is_android) {
342 _native_compiler_configs += [ "//build/config/android:sdk", ]
346 _native_compiler_configs += [
347 "//build/config/clang:find_bad_constructs",
348 "//build/config/clang:extra_warnings",
352 # Optimizations and debug checking.
354 _native_compiler_configs += [ "//build/config:debug" ]
355 _default_optimization_config = "//build/config/compiler:no_optimize"
357 _native_compiler_configs += [ "//build/config:release" ]
358 _default_optimization_config = "//build/config/compiler:optimize"
360 _native_compiler_configs += [ _default_optimization_config ]
363 if (symbol_level == 2) {
364 _default_symbols_config = "//build/config/compiler:symbols"
365 } else if (symbol_level == 1) {
366 _default_symbols_config = "//build/config/compiler:minimal_symbols"
367 } else if (symbol_level == 0) {
368 _default_symbols_config = "//build/config/compiler:no_symbols"
370 assert(false, "Bad value for symbol_level.")
372 _native_compiler_configs += [ _default_symbols_config ]
374 # Windows linker setup for EXEs and DLLs.
377 _default_incremental_linking_config =
378 "//build/config/win:incremental_linking"
380 _default_incremental_linking_config =
381 "//build/config/win:no_incremental_linking"
383 _windows_linker_configs = [
384 _default_incremental_linking_config,
385 "//build/config/win:sdk_link",
386 "//build/config/win:common_linker_setup",
387 # Default to console-mode apps. Most of our targets are tests and such
388 # that shouldn't use the windows subsystem.
389 "//build/config/win:console",
393 set_defaults("executable") {
394 configs = _native_compiler_configs + [
395 "//build/config:default_libs",
398 configs += _windows_linker_configs
401 "//build/config/mac:mac_dynamic_flags",
402 "//build/config/mac:mac_executable_flags" ]
403 } else if (is_linux || is_android) {
404 configs += [ "//build/config/gcc:executable_ldconfig" ]
408 set_defaults("static_library") {
409 configs = _native_compiler_configs
412 set_defaults("shared_library") {
413 configs = _native_compiler_configs + [
414 "//build/config:default_libs",
417 configs += _windows_linker_configs
419 configs += [ "//build/config/mac:mac_dynamic_flags" ]
423 set_defaults("source_set") {
424 configs = _native_compiler_configs
427 # ==============================================================================
429 # ==============================================================================
431 # Here we set the default toolchain, as well as the variable host_toolchain
432 # which will identify the toolchain corresponding to the local system when
433 # doing cross-compiles. When not cross-compiling, this will be the same as the
437 # TODO(brettw) name the toolchains the same as cpu_arch as with Linux below
438 # to eliminate these conditionals.
439 if (build_cpu_arch == "x64") {
440 host_toolchain = "//build/toolchain/win:64"
441 } else if (build_cpu_arch == "x86") {
442 host_toolchain = "//build/toolchain/win:32"
445 if (cpu_arch == "x64") {
446 set_default_toolchain("//build/toolchain/win:64")
447 } else if (cpu_arch == "x86") {
448 set_default_toolchain("//build/toolchain/win:32")
450 } else if (is_android) {
451 # Use clang for the x86/64 Linux host builds.
452 if (build_cpu_arch == "x86" || build_cpu_arch == "x64") {
453 host_toolchain = "//build/toolchain/linux:clang_$build_cpu_arch"
455 host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
457 set_default_toolchain("//build/toolchain/android:$cpu_arch")
458 } else if (is_linux) {
460 host_toolchain = "//build/toolchain/linux:clang_$build_cpu_arch"
461 set_default_toolchain("//build/toolchain/linux:clang_$cpu_arch")
463 host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
464 set_default_toolchain("//build/toolchain/linux:$cpu_arch")
467 host_toolchain = "//build/toolchain/mac:clang"
468 set_default_toolchain(host_toolchain)
470 host_toolchain = "//build/toolchain/mac:host_clang"
471 set_default_toolchain("//build/toolchain/mac:clang")