Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / build / config / BUILDCONFIG.gn
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.
19 declare_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   # ASH is enabled.
37   # TODO(brettw) this should be moved out of the main build config file.
38   use_ash = false
39   # Aura is enabled.
40   # TODO(brettw) this should be moved out of the main build config file.
41   use_aura = false
42   # Ozone is enabled.
43   # TODO(brettw) this should be moved out of the main build config file.
44   use_ozone = false
45
46   # Forces a 64-bit build on Windows. Does nothing on other platforms. Normally
47   # we build 32-bit on Windows regardless of the current host OS bit depth.
48   # Setting this flag will override this logic and generate 64-bit toolchains.
49   #
50   # Normally this would get set automatically when you specify a target using
51   # the 64-bit toolchain. You can also set this on the command line to convert
52   # the default toolchain to 64-bit.
53   force_win64 = false
54
55   # Set to true on the command line when invoked by GYP. Build files can key
56   # off of this to make any GYP-output-specific changes to the build.
57   is_gyp = false
58
59   # Selects the desired build flavor. Official builds get additional
60   # processing to prepare for release. Normally you will want to develop and
61   # test with this flag off.
62   is_official_build = false
63
64   # Select the desired branding flavor. False means normal Chromium branding,
65   # true means official Google Chrome branding (requires extra Google-internal
66   # resources).
67   is_chrome_branded = false
68
69   # Compile for Address Sanitizer to find memory bugs.
70   is_asan = false
71
72   # Compile for Leak Sanitizer to find leaks.
73   is_lsan = false
74
75   # Compile for Memory Sanitizer to find uninitialized reads.
76   is_msan = false
77
78   # Compile for Thread Sanitizer to find threading bugs.
79   is_tsan = false
80
81   # When running in gyp-generating mode, this is the root of the build tree.
82   gyp_output_dir = "out"
83 }
84
85 # =============================================================================
86 # OS DEFINITIONS
87 # =============================================================================
88 #
89 # We set these various is_FOO booleans for convenience in writing OS-based
90 # conditions.
91 #
92 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
93 # - is_mac is set only for desktop Mac. It is not set on iOS.
94 # - is_posix is true for mac and any Unix-like system (basically everything
95 #   except Windows).
96 # - is_linux is true for any Linux variant including Android and ChromeOS.
97 #
98 # Do not add more is_* variants here for random lesser-used Unix systems like
99 # aix or one of the BSDs. If you need to check these, just check the os value
100 # directly.
101
102 if (os == "win") {
103   is_android = false
104   is_chromeos = false
105   is_ios = false
106   is_linux = false
107   is_mac = false
108   is_nacl = false
109   is_posix = false
110   is_win = true
111
112   # Windows currelty implies Aura.
113   use_aura = true
114 } else if (os == "mac") {
115   is_android = false
116   is_chromeos = false
117   is_ios = false
118   is_linux = false
119   is_mac = true
120   is_nacl = false
121   is_posix = true
122   is_win = false
123   if (!is_clang) {
124     is_clang = true  # Always use clang on Mac.
125   }
126 } else if (os == "android") {
127   is_android = true
128   is_chromeos = false
129   is_ios = false
130   is_linux = true
131   is_mac = false
132   is_nacl = false
133   is_posix = true
134   is_win = false
135 } else if (os == "chromeos") {
136   is_android = false
137   is_chromeos = true
138   is_ios = false
139   is_linux = true
140   is_mac = false
141   is_nacl = false
142   is_posix = true
143   is_win = false
144 } else if (os == "nacl") {
145   # os == "nacl" will be passed by the nacl toolchain definition. It is not
146   # set by default or on the command line. We treat is as a Posix variant.
147   is_android = false
148   is_chromeos = false
149   is_ios = false
150   is_linux = false
151   is_mac = false
152   is_nacl = true
153   is_posix = true
154   is_win = false
155 } else if (os == "ios") {
156   is_android = false
157   is_chromeos = false
158   is_ios = true
159   is_linux = false
160   is_mac = false
161   is_nacl = false
162   is_posix = true
163   is_win = false
164   if (!is_clang) {
165     # Always use clang on iOS when using ninja
166     # (which is always true when using GN).
167     is_clang = true
168   }
169 } else if (os == "linux") {
170   is_android = false
171   is_chromeos = false
172   is_ios = false
173   is_linux = true
174   is_mac = false
175   is_nacl = false
176   is_posix = true
177   is_win = false
178 }
179
180 # =============================================================================
181 # CPU ARCHITECTURE
182 # =============================================================================
183
184 if (is_win) {
185   # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
186   # unless the override flag is specified.
187   if (force_win64) {
188     cpu_arch = "x64"
189   } else {
190     cpu_arch = "x86"
191   }
192 }
193
194 # =============================================================================
195 # SOURCES FILTERS
196 # =============================================================================
197 #
198 # These patterns filter out platform-specific files when assigning to the
199 # sources variable. The magic variable |sources_assignment_filter| is applied
200 # to each assignment or appending to the sources variable and matches are
201 # automatcally removed.
202 #
203 # We define lists of filters for each platform for all builds so they can
204 # be used by individual targets if necessary (a target can always change
205 # sources_assignment_filter on itself if it needs something more specific).
206 #
207 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
208 # boundary = end of string or slash) are supported, and the entire string
209 # muct match the pattern (so you need "*.cc" to match all .cc files, for
210 # example).
211
212 windows_sources_filters = [
213   "*_win.cc",
214   "*_win.h",
215   "*_win_unittest.cc",
216   "*\bwin/*",
217 ]
218 mac_sources_filters = [
219   "*_mac.h",
220   "*_mac.cc",
221   "*_mac.mm",
222   "*_mac_unittest.h",
223   "*_mac_unittest.cc",
224   "*_mac_unittest.mm",
225   "*\bmac/*",
226   "*_cocoa.h",
227   "*_cocoa.cc",
228   "*_cocoa.mm",
229   "*_cocoa_unittest.h",
230   "*_cocoa_unittest.cc",
231   "*_cocoa_unittest.mm",
232   "*\bcocoa/*",
233 ]
234 ios_sources_filters = [
235   "*_ios.h",
236   "*_ios.cc",
237   "*_ios.mm",
238   "*_ios_unittest.h",
239   "*_ios_unittest.cc",
240   "*_ios_unittest.mm",
241   "*\bios/*",
242 ]
243 objective_c_sources_filters = [
244   "*.mm",
245 ]
246 linux_sources_filters = [
247   "*_linux.h",
248   "*_linux.cc",
249   "*_linux_unittest.h",
250   "*_linux_unittest.cc",
251   "*\blinux/*",
252   "*_x11.cc",
253   "*_x11.h",
254 ]
255 android_sources_filters = [
256   "*_android.h",
257   "*_android.cc",
258   "*_android_unittest.h",
259   "*_android_unittest.cc",
260   "*\bandroid/*",
261 ]
262 posix_sources_filters = [
263   "*_posix.h",
264   "*_posix.cc",
265   "*_posix_unittest.h",
266   "*_posix_unittest.cc",
267   "*\bposix/*",
268 ]
269
270 # Construct the full list of sources we're using for this platform.
271 sources_assignment_filter = []
272 if (is_win) {
273   sources_assignment_filter += posix_sources_filters
274 } else {
275   sources_assignment_filter += windows_sources_filters
276 }
277 if (!is_mac) {
278   sources_assignment_filter += mac_sources_filters
279 }
280 if (!is_ios) {
281   sources_assignment_filter += ios_sources_filters
282 }
283 if (!is_mac && !is_ios) {
284   sources_assignment_filter += objective_c_sources_filters
285 }
286 if (!is_linux) {
287   sources_assignment_filter += linux_sources_filters
288 }
289 if (!is_android) {
290   sources_assignment_filter += android_sources_filters
291 }
292
293 # This is the actual set.
294 set_sources_assignment_filter(sources_assignment_filter)
295
296 # =============================================================================
297 # BUILD OPTIONS
298 # =============================================================================
299
300 if (is_component_build) {
301   component_mode = "shared_library"
302 } else {
303   component_mode = "static_library"
304 }
305
306 # These Sanitizers all imply using the Clang compiler. On Windows they either
307 # don't work or work differently.
308 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
309   is_clang = true
310 }
311
312 toolkit_uses_gtk = is_linux
313
314 # =============================================================================
315 # TARGET DEFAULTS
316 # =============================================================================
317 #
318 # Set up the default configuration for every build target of the given type.
319 # The values configured here will be automatically set on the scope of the
320 # corresponding target. Target definitions can add or remove to the settings
321 # here as needed.
322
323 # Holds all configs used for making native executables and libraries, to avoid
324 # duplication in each target below.
325 native_compiler_configs = [
326   "//build/config:my_msvs",  # TODO(brettw) eraseme
327
328   "//build/config/compiler:compiler",
329   "//build/config/compiler:chromium_code",
330   "//build/config/compiler:default_warnings",
331   "//build/config/compiler:no_rtti",
332   "//build/config/compiler:runtime_library",
333 ]
334 if (is_win) {
335   native_compiler_configs += [
336     "//build/config/win:sdk",
337   ]
338 } else if (is_clang) {
339   native_compiler_configs += [ "//build/config/clang:find_bad_constructs" ]
340 }
341
342 # Optimizations and debug checking.
343 if (is_debug) {
344   native_compiler_configs += [ "//build/config:debug" ]
345   default_optimization_config = "//build/config/compiler:no_optimize"
346 } else {
347   native_compiler_configs += [ "//build/config:release" ]
348   default_optimization_config = "//build/config/compiler:optimize"
349 }
350 native_compiler_configs += [ default_optimization_config ]
351
352 # Symbol setup.
353 if (is_clang && (is_linux || is_android)) {
354   # Clang creates chubby debug information, which makes linking very slow.
355   # For now, don't create debug information with clang.
356   # See http://crbug.com/70000
357   # TODO(brettw) This just copies GYP. Why not do this on Mac as well?
358   default_symbols_config = "//build/config/compiler:no_symbols"
359 } else if (symbol_level == 2) {
360   default_symbols_config = "//build/config/compiler:symbols"
361 } else if (symbol_level == 1) {
362   default_symbols_config = "//build/config/compiler:minimal_symbols"
363 } else if (symbol_level == 0) {
364   default_symbols_config = "//build/config/compiler:no_symbols"
365 } else {
366   assert(false, "Bad value for symbol_level.")
367 }
368 native_compiler_configs += [ default_symbols_config ]
369
370 # Windows linker setup for EXEs and DLLs.
371 if (is_win) {
372   if (is_debug) {
373     default_incremental_linking_config =
374       "//build/config/win:incremental_linking"
375   } else {
376     default_incremental_linking_config =
377       "//build/config/win:no_incremental_linking"
378   }
379   windows_linker_configs = [
380     default_incremental_linking_config,
381     "//build/config/win:sdk_link",
382     "//build/config/win:common_linker_setup",
383     # Default to console-mode apps. Most of our targets are tests and such
384     # that shouldn't use the windows subsystem.
385     "//build/config/win:console",
386   ]
387 }
388
389 set_defaults("executable") {
390   configs = native_compiler_configs
391   if (is_win) {
392     configs += windows_linker_configs
393   } else if (is_mac) {
394     configs += [ "//build/config/mac:mac_dynamic_flags" ]
395   } else if (is_linux) {
396     configs += [ "//build/config/linux:executable_ldconfig" ]
397   }
398 }
399
400 set_defaults("static_library") {
401   configs = native_compiler_configs
402 }
403
404 set_defaults("shared_library") {
405   configs = native_compiler_configs
406   if (is_win) {
407     configs += windows_linker_configs
408   } else if (is_mac) {
409     configs += [ "//build/config/mac:mac_dynamic_flags" ]
410   }
411 }
412
413 set_defaults("source_set") {
414   configs = native_compiler_configs
415 }
416
417 # ==============================================================================
418 # TOOLCHAIN SETUP
419 # ==============================================================================
420 #
421 # Here we set the default toolchain, as well as the variable host_toolchain
422 # which will identify the toolchain corresponding to the local system when
423 # doing cross-compiles. When not cross-compiling, this will be the same as the
424 # default toolchain.
425
426 if (is_win) {
427   # TODO(brettw) name the toolchains the same as cpu_arch as with Linux below
428   # to eliminate these conditionals.
429   if (build_cpu_arch == "x64") {
430     host_toolchain = "//build/toolchain/win:64"
431   } else if (build_cpu_arch == "x86") {
432     host_toolchain = "//build/toolchain/win:32"
433   }
434
435   if (cpu_arch == "x64") {
436     set_default_toolchain("//build/toolchain/win:64")
437   } else if (cpu_arch == "x86") {
438     set_default_toolchain("//build/toolchain/win:32")
439   }
440 } else if (is_android) {
441   host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
442   set_default_toolchain("//build/toolchain/android:$cpu_arch")
443 } else if (is_linux) {
444   host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
445   set_default_toolchain("//build/toolchain/linux:$cpu_arch")
446 } else if (is_mac || is_ios) {
447   host_toolchain = "//build/toolchain/mac:clang"
448   set_default_toolchain(host_toolchain)
449 }