• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5# =============================================================================
6# BUILD FLAGS
7# =============================================================================
8#
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.
12#
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.
15#
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.
19declare_args() {
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.
24  #   0 means no symbols.
25  symbol_level = 2
26
27  # Component build.
28  is_component_build = false
29  # Debug build.
30  is_debug = true
31
32  # Set to true when compiling with the Clang compiler. Typically this is used
33  # to configure warnings.
34  is_clang = false
35
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.
39  #
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.
43  force_win64 = false
44
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
49
50  # Select the desired branding flavor. False means normal Chromium branding,
51  # true means official Google Chrome branding (requires extra Google-internal
52  # resources).
53  is_chrome_branded = false
54
55  # Compile for Address Sanitizer to find memory bugs.
56  is_asan = false
57
58  # Compile for Leak Sanitizer to find leaks.
59  is_lsan = false
60
61  # Compile for Memory Sanitizer to find uninitialized reads.
62  is_msan = false
63
64  # Compile for Thread Sanitizer to find threading bugs.
65  is_tsan = false
66}
67
68# =============================================================================
69# OS DEFINITIONS
70# =============================================================================
71#
72# We set these various is_FOO booleans for convenience in writing OS-based
73# conditions.
74#
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
78#   except Windows).
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).
81#
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
84# directly.
85
86if (os == "win") {
87  is_android = false
88  is_chromeos = false
89  is_ios = false
90  is_linux = false
91  is_mac = false
92  is_nacl = false
93  is_posix = false
94  is_win = true
95} else if (os == "mac") {
96  is_android = false
97  is_chromeos = false
98  is_ios = false
99  is_linux = false
100  is_mac = true
101  is_nacl = false
102  is_posix = true
103  is_win = false
104  if (!is_clang) {
105    is_clang = true  # Always use clang on Mac.
106  }
107} else if (os == "android") {
108  is_android = true
109  is_chromeos = false
110  is_ios = false
111  is_linux = false
112  is_mac = false
113  is_nacl = false
114  is_posix = true
115  is_win = false
116} else if (os == "chromeos") {
117  is_android = false
118  is_chromeos = true
119  is_ios = false
120  is_linux = true
121  is_mac = false
122  is_nacl = false
123  is_posix = true
124  is_win = false
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.
128  is_android = false
129  is_chromeos = false
130  is_ios = false
131  is_linux = false
132  is_mac = false
133  is_nacl = true
134  is_posix = true
135  is_win = false
136} else if (os == "ios") {
137  is_android = false
138  is_chromeos = false
139  is_ios = true
140  is_linux = false
141  is_mac = false
142  is_nacl = false
143  is_posix = true
144  is_win = false
145  if (!is_gyp_xcode_generator) {
146    # Always use clang on iOS when using ninja
147    is_clang = true
148  }
149} else if (os == "linux") {
150  is_android = false
151  is_chromeos = false
152  is_ios = false
153  is_linux = true
154  is_mac = false
155  is_nacl = false
156  is_posix = true
157  is_win = false
158}
159
160is_desktop_linux = is_linux && !is_chromeos
161
162# =============================================================================
163# CPU ARCHITECTURE
164# =============================================================================
165
166if (is_win) {
167  # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
168  # unless the override flag is specified.
169  if (force_win64) {
170    cpu_arch = "x64"
171  } else {
172    cpu_arch = "x86"
173  }
174}
175
176# =============================================================================
177# SOURCES FILTERS
178# =============================================================================
179#
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.
184#
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
188# example).
189
190# DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
191# below.
192sources_assignment_filter = []
193if (!is_posix) {
194  sources_assignment_filter += [
195    "*_posix.h",
196    "*_posix.cc",
197    "*_posix_unittest.h",
198    "*_posix_unittest.cc",
199    "*\bposix/*",
200  ]
201}
202if (!is_win) {
203  sources_assignment_filter += [
204    "*_win.cc",
205    "*_win.h",
206    "*_win_unittest.cc",
207    "*\bwin/*",
208    "*.rc",
209  ]
210}
211if (!is_mac) {
212  sources_assignment_filter += [
213    "*_mac.h",
214    "*_mac.cc",
215    "*_mac.mm",
216    "*_mac_unittest.h",
217    "*_mac_unittest.cc",
218    "*_mac_unittest.mm",
219    "*\bmac/*",
220    "*_cocoa.h",
221    "*_cocoa.cc",
222    "*_cocoa.mm",
223    "*_cocoa_unittest.h",
224    "*_cocoa_unittest.cc",
225    "*_cocoa_unittest.mm",
226    "*\bcocoa/*",
227  ]
228}
229if (!is_ios) {
230  sources_assignment_filter += [
231    "*_ios.h",
232    "*_ios.cc",
233    "*_ios.mm",
234    "*_ios_unittest.h",
235    "*_ios_unittest.cc",
236    "*_ios_unittest.mm",
237    "*\bios/*",
238  ]
239}
240if (!is_mac && !is_ios) {
241  sources_assignment_filter += [
242    "*.mm",
243  ]
244}
245if (!is_linux) {
246  sources_assignment_filter += [
247    "*_linux.h",
248    "*_linux.cc",
249    "*_linux_unittest.h",
250    "*_linux_unittest.cc",
251    "*\blinux/*",
252  ]
253}
254if (!is_android) {
255  sources_assignment_filter += [
256    "*_android.h",
257    "*_android.cc",
258    "*_android_unittest.h",
259    "*_android_unittest.cc",
260    "*\bandroid/*",
261  ]
262}
263if (!is_chromeos) {
264  sources_assignment_filter += [
265    "*_chromeos.h",
266    "*_chromeos.cc",
267    "*_chromeos_unittest.h",
268    "*_chromeos_unittest.cc",
269    "*\bchromeos/*",
270  ]
271}
272# DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
273# below.
274
275# Actually save this list.
276#
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.
281#
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.
287set_sources_assignment_filter(sources_assignment_filter)
288
289# =============================================================================
290# BUILD OPTIONS
291# =============================================================================
292
293if (is_component_build) {
294  component_mode = "shared_library"
295} else {
296  component_mode = "source_set"
297}
298
299# These Sanitizers all imply using the Clang compiler. On Windows they either
300# don't work or work differently.
301if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
302  is_clang = true
303}
304
305# =============================================================================
306# TARGET DEFAULTS
307# =============================================================================
308#
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
312# here as needed.
313
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",
318
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",
324]
325if (is_win) {
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  ]
332}
333if (is_posix) {
334  _native_compiler_configs += [
335    "//build/config/gcc:no_exceptions",
336    "//build/config/gcc:symbol_visibility_hidden",
337  ]
338}
339
340if (is_linux) {
341  _native_compiler_configs += [ "//build/config/linux:sdk", ]
342} else if (is_mac) {
343  _native_compiler_configs += [ "//build/config/mac:sdk", ]
344} else if (is_ios) {
345  _native_compiler_configs += [ "//build/config/ios:sdk", ]
346} else if (is_android) {
347  _native_compiler_configs += [ "//build/config/android:sdk", ]
348}
349
350if (is_clang) {
351  _native_compiler_configs += [
352    "//build/config/clang:find_bad_constructs",
353    "//build/config/clang:extra_warnings",
354  ]
355}
356
357# Optimizations and debug checking.
358if (is_debug) {
359  _native_compiler_configs += [ "//build/config:debug" ]
360  _default_optimization_config = "//build/config/compiler:no_optimize"
361} else {
362  _native_compiler_configs += [ "//build/config:release" ]
363  _default_optimization_config = "//build/config/compiler:optimize"
364}
365_native_compiler_configs += [ _default_optimization_config ]
366
367# Symbol setup.
368if (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"
380} else {
381  assert(false, "Bad value for symbol_level.")
382}
383_native_compiler_configs += [ _default_symbols_config ]
384
385# Windows linker setup for EXEs and DLLs.
386if (is_win) {
387  if (is_debug) {
388    _default_incremental_linking_config =
389      "//build/config/win:incremental_linking"
390  } else {
391    _default_incremental_linking_config =
392      "//build/config/win:no_incremental_linking"
393  }
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",
401  ]
402}
403
404set_defaults("executable") {
405  configs = _native_compiler_configs + [
406    "//build/config:default_libs",
407  ]
408  if (is_win) {
409    configs += _windows_linker_configs
410  } else if (is_mac) {
411    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" ]
416  }
417}
418
419set_defaults("static_library") {
420  configs = _native_compiler_configs
421}
422
423set_defaults("shared_library") {
424  configs = _native_compiler_configs + [
425    "//build/config:default_libs",
426  ]
427  if (is_win) {
428    configs += _windows_linker_configs
429  } else if (is_mac) {
430    configs += [ "//build/config/mac:mac_dynamic_flags" ]
431  }
432}
433
434set_defaults("source_set") {
435  configs = _native_compiler_configs
436}
437
438# ==============================================================================
439# TOOLCHAIN SETUP
440# ==============================================================================
441#
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
445# default toolchain.
446
447if (is_win) {
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"
454  }
455
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")
460  }
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")
467} else if (is_mac) {
468  host_toolchain = "//build/toolchain/mac:clang"
469  set_default_toolchain(host_toolchain)
470} else if (is_ios) {
471  host_toolchain = "//build/toolchain/mac:host_clang"
472  set_default_toolchain("//build/toolchain/mac:clang")
473}
474