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 # =============================================================================
162 # =============================================================================
165 # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
166 # unless the override flag is specified.
174 # =============================================================================
176 # =============================================================================
178 # These patterns filter out platform-specific files when assigning to the
179 # sources variable. The magic variable |sources_assignment_filter| is applied
180 # to each assignment or appending to the sources variable and matches are
181 # automatcally removed.
183 # We define lists of filters for each platform for all builds so they can
184 # be used by individual targets if necessary (a target can always change
185 # sources_assignment_filter on itself if it needs something more specific).
187 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
188 # boundary = end of string or slash) are supported, and the entire string
189 # muct match the pattern (so you need "*.cc" to match all .cc files, for
192 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
194 windows_sources_filters = [
201 mac_sources_filters = [
212 "*_cocoa_unittest.h",
213 "*_cocoa_unittest.cc",
214 "*_cocoa_unittest.mm",
217 ios_sources_filters = [
226 objective_c_sources_filters = [
229 linux_sources_filters = [
232 "*_linux_unittest.h",
233 "*_linux_unittest.cc",
236 android_sources_filters = [
239 "*_android_unittest.h",
240 "*_android_unittest.cc",
243 posix_sources_filters = [
246 "*_posix_unittest.h",
247 "*_posix_unittest.cc",
250 chromeos_sources_filters = [
253 "*_chromeos_unittest.h",
254 "*_chromeos_unittest.cc",
257 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
260 # Construct the full list of sources we're using for this platform.
261 sources_assignment_filter = []
263 sources_assignment_filter += posix_sources_filters
265 sources_assignment_filter += windows_sources_filters
268 sources_assignment_filter += mac_sources_filters
271 sources_assignment_filter += ios_sources_filters
273 if (!is_mac && !is_ios) {
274 sources_assignment_filter += objective_c_sources_filters
277 sources_assignment_filter += linux_sources_filters
280 sources_assignment_filter += android_sources_filters
283 sources_assignment_filter += chromeos_sources_filters
286 # Actually save this list.
288 # DO NOT ADD MORE PATTERNS TO THIS LIST.
290 # These patterns are executed for every file in the source tree of every run.
291 # Therefore, adding more patterns slows down the build for everybody. We should
292 # only add automatic patterns for configurations affecting hundreds of files
293 # across many projects in the tree.
295 # Therefore, we only add rules to this list corresponding to platforms on the
296 # Chromium waterfall. This is not for non-officially-supported platforms
297 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
298 # write a conditional in the target to remove the file(s) from the list when
299 # your platform/toolkit/feature doesn't apply.
300 set_sources_assignment_filter(sources_assignment_filter)
302 # =============================================================================
304 # =============================================================================
306 if (is_component_build) {
307 component_mode = "shared_library"
309 component_mode = "static_library"
312 # These Sanitizers all imply using the Clang compiler. On Windows they either
313 # don't work or work differently.
314 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
318 # =============================================================================
320 # =============================================================================
322 # Set up the default configuration for every build target of the given type.
323 # The values configured here will be automatically set on the scope of the
324 # corresponding target. Target definitions can add or remove to the settings
327 # Holds all configs used for making native executables and libraries, to avoid
328 # duplication in each target below.
329 native_compiler_configs = [
330 "//build/config:feature_flags",
332 "//build/config/compiler:compiler",
333 "//build/config/compiler:chromium_code",
334 "//build/config/compiler:default_warnings",
335 "//build/config/compiler:no_rtti",
336 "//build/config/compiler:runtime_library",
339 native_compiler_configs += [
340 "//build/config/win:lean_and_mean",
341 "//build/config/win:sdk",
342 "//build/config/win:unicode",
344 } else if (is_linux) {
345 native_compiler_configs += [ "//build/config/linux:sdk", ]
347 native_compiler_configs += [ "//build/config/mac:sdk", ]
349 native_compiler_configs += [ "//build/config/ios:sdk", ]
350 } else if (is_android) {
351 native_compiler_configs += [ "//build/config/android:sdk", ]
354 native_compiler_configs += [ "//build/config/gcc:symbol_visibility_hidden" ]
357 native_compiler_configs += [
358 "//build/config/clang:find_bad_constructs",
359 "//build/config/clang:extra_warnings",
363 # Optimizations and debug checking.
365 native_compiler_configs += [ "//build/config:debug" ]
366 default_optimization_config = "//build/config/compiler:no_optimize"
368 native_compiler_configs += [ "//build/config:release" ]
369 default_optimization_config = "//build/config/compiler:optimize"
371 native_compiler_configs += [ default_optimization_config ]
374 if (is_clang && (is_linux || is_android)) {
375 # Clang creates chubby debug information, which makes linking very slow.
376 # For now, don't create debug information with clang.
377 # See http://crbug.com/70000
378 # TODO(brettw) This just copies GYP. Why not do this on Mac as well?
379 default_symbols_config = "//build/config/compiler:no_symbols"
380 } else 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.
394 default_incremental_linking_config =
395 "//build/config/win:incremental_linking"
397 default_incremental_linking_config =
398 "//build/config/win:no_incremental_linking"
400 windows_linker_configs = [
401 default_incremental_linking_config,
402 "//build/config/win:sdk_link",
403 "//build/config/win:common_linker_setup",
404 # Default to console-mode apps. Most of our targets are tests and such
405 # that shouldn't use the windows subsystem.
406 "//build/config/win:console",
410 set_defaults("executable") {
411 configs = native_compiler_configs + [
412 "//build/config:default_libs",
415 configs += windows_linker_configs
418 "//build/config/mac:mac_dynamic_flags",
419 "//build/config/mac:mac_executable_flags" ]
420 } else if (is_linux || is_android) {
421 configs += [ "//build/config/linux:executable_ldconfig" ]
425 set_defaults("static_library") {
426 configs = native_compiler_configs
429 set_defaults("shared_library") {
430 configs = native_compiler_configs + [
431 "//build/config:default_libs",
434 configs += windows_linker_configs
436 configs += [ "//build/config/mac:mac_dynamic_flags" ]
440 set_defaults("source_set") {
441 configs = native_compiler_configs
444 # ==============================================================================
446 # ==============================================================================
448 # Here we set the default toolchain, as well as the variable host_toolchain
449 # which will identify the toolchain corresponding to the local system when
450 # doing cross-compiles. When not cross-compiling, this will be the same as the
454 # TODO(brettw) name the toolchains the same as cpu_arch as with Linux below
455 # to eliminate these conditionals.
456 if (build_cpu_arch == "x64") {
457 host_toolchain = "//build/toolchain/win:64"
458 } else if (build_cpu_arch == "x86") {
459 host_toolchain = "//build/toolchain/win:32"
462 if (cpu_arch == "x64") {
463 set_default_toolchain("//build/toolchain/win:64")
464 } else if (cpu_arch == "x86") {
465 set_default_toolchain("//build/toolchain/win:32")
467 } else if (is_android) {
468 host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
469 set_default_toolchain("//build/toolchain/android:$cpu_arch")
470 } else if (is_linux) {
471 host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
472 set_default_toolchain("//build/toolchain/linux:$cpu_arch")
474 host_toolchain = "//build/toolchain/mac:clang"
475 set_default_toolchain(host_toolchain)
477 host_toolchain = "//build/toolchain/mac:host_clang"
478 set_default_toolchain("//build/toolchain/mac:clang")