Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / build / config / BUILDCONFIG.gn
1 # Copyright (c) 2014 The Native Client 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   # The current NaCl libc and preps stage, none for trusted toolchains.
21   nacl_libc = "none"
22   nacl_prep = "none"
23
24   use_newlib = true
25   use_glibc = false
26   use_pnacl = false
27
28   use_nacl_x86 = (cpu_arch == "x86")
29   use_nacl_x64 = ((cpu_arch == "x64") || (os == "win"))
30   use_nacl_arm = (cpu_arch == "arm")
31
32   is_android_webview_build = false
33
34   # How many symbols to include in the build. This affects the performance of
35   # the build since the symbols are large and dealing with them is slow.
36   #   2 means regular build with symbols.
37   #   1 means minimal symbols, usually enough for backtraces only.
38   #   0 means no symbols.
39   symbol_level = 2
40
41   # Component build.
42   is_component_build = false
43   # Debug build.
44   is_debug = true
45
46   # Set to true when compiling with the Clang compiler. Typically this is used
47   # to configure warnings.
48   is_clang = false
49
50   # Forces a 64-bit build on Windows. Does nothing on other platforms. Normally
51   # we build 32-bit on Windows regardless of the current host OS bit depth.
52   # Setting this flag will override this logic and generate 64-bit toolchains.
53   #
54   # Normally this would get set automatically when you specify a target using
55   # the 64-bit toolchain. You can also set this on the command line to convert
56   # the default toolchain to 64-bit.
57   force_win64 = 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
82 # =============================================================================
83 # OS DEFINITIONS
84 # =============================================================================
85 #
86 # We set these various is_FOO booleans for convenience in writing OS-based
87 # conditions.
88 #
89 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
90 # - is_mac is set only for desktop Mac. It is not set on iOS.
91 # - is_posix is true for mac and any Unix-like system (basically everything
92 #   except Windows).
93 # - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
94 #   generally too different despite being based on the Linux kernel).
95 #
96 # Do not add more is_* variants here for random lesser-used Unix systems like
97 # aix or one of the BSDs. If you need to check these, just check the os value
98 # directly.
99
100 if (os == "win") {
101   is_android = false
102   is_chromeos = false
103   is_ios = false
104   is_linux = false
105   is_mac = false
106   is_nacl = false
107   is_posix = false
108   is_win = true
109 } else if (os == "mac") {
110   is_android = false
111   is_chromeos = false
112   is_ios = false
113   is_linux = false
114   is_mac = true
115   is_nacl = false
116   is_posix = true
117   is_win = false
118   if (!is_clang) {
119     is_clang = true  # Always use clang on Mac.
120   }
121 } else if (os == "android") {
122   is_android = true
123   is_chromeos = false
124   is_ios = false
125   is_linux = false
126   is_mac = false
127   is_nacl = false
128   is_posix = true
129   is_win = false
130 } else if (os == "chromeos") {
131   is_android = false
132   is_chromeos = true
133   is_ios = false
134   is_linux = true
135   is_mac = false
136   is_nacl = false
137   is_posix = true
138   is_win = false
139 } else if (os == "nacl") {
140   # os == "nacl" will be passed by the nacl toolchain definition. It is not
141   # set by default or on the command line. We treat is as a Posix variant.
142   is_android = false
143   is_chromeos = false
144   is_ios = false
145   is_linux = false
146   is_mac = false
147   is_nacl = true
148   is_posix = true
149   is_win = false
150 } else if (os == "ios") {
151   is_android = false
152   is_chromeos = false
153   is_ios = true
154   is_linux = false
155   is_mac = false
156   is_nacl = false
157   is_posix = true
158   is_win = false
159   if (!is_gyp_xcode_generator) {
160     # Always use clang on iOS when using ninja
161     is_clang = true
162   }
163 } else if (os == "linux") {
164   is_android = false
165   is_chromeos = false
166   is_ios = false
167   is_linux = true
168   is_mac = false
169   is_nacl = false
170   is_posix = true
171   is_win = false
172 }
173
174 is_desktop_linux = is_linux && !is_chromeos
175
176 # =============================================================================
177 # CPU ARCHITECTURE
178 # =============================================================================
179
180 if (is_win) {
181   # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
182   # unless the override flag is specified.
183   if (force_win64) {
184     cpu_arch = "x64"
185   } else {
186     cpu_arch = "x86"
187   }
188 }
189
190 # =============================================================================
191 # SOURCES FILTERS
192 # =============================================================================
193 #
194 # These patterns filter out platform-specific files when assigning to the
195 # sources variable. The magic variable |sources_assignment_filter| is applied
196 # to each assignment or appending to the sources variable and matches are
197 # automatcally removed.
198 #
199 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
200 # boundary = end of string or slash) are supported, and the entire string
201 # muct match the pattern (so you need "*.cc" to match all .cc files, for
202 # example).
203
204 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
205 # below.
206 sources_assignment_filter = []
207 if (!is_posix) {
208   sources_assignment_filter += [
209     "*_posix.h",
210     "*_posix.cc",
211     "*_posix_unittest.h",
212     "*_posix_unittest.cc",
213     "*\bposix/*",
214   ]
215 }
216 if (!is_win) {
217   sources_assignment_filter += [
218     "*_win.cc",
219     "*_win.h",
220     "*_win_unittest.cc",
221     "*\bwin/*",
222     "*.rc",
223   ]
224 }
225 if (!is_mac) {
226   sources_assignment_filter += [
227     "*_mac.h",
228     "*_mac.cc",
229     "*_mac.mm",
230     "*_mac_unittest.h",
231     "*_mac_unittest.cc",
232     "*_mac_unittest.mm",
233     "*\bmac/*",
234     "*_cocoa.h",
235     "*_cocoa.cc",
236     "*_cocoa.mm",
237     "*_cocoa_unittest.h",
238     "*_cocoa_unittest.cc",
239     "*_cocoa_unittest.mm",
240     "*\bcocoa/*",
241   ]
242 }
243 if (!is_ios) {
244   sources_assignment_filter += [
245     "*_ios.h",
246     "*_ios.cc",
247     "*_ios.mm",
248     "*_ios_unittest.h",
249     "*_ios_unittest.cc",
250     "*_ios_unittest.mm",
251     "*\bios/*",
252   ]
253 }
254 if (!is_mac && !is_ios) {
255   sources_assignment_filter += [
256     "*.mm",
257   ]
258 }
259 if (!is_linux) {
260   sources_assignment_filter += [
261     "*_linux.h",
262     "*_linux.cc",
263     "*_linux_unittest.h",
264     "*_linux_unittest.cc",
265     "*\blinux/*",
266   ]
267 }
268 if (!is_android) {
269   sources_assignment_filter += [
270     "*_android.h",
271     "*_android.cc",
272     "*_android_unittest.h",
273     "*_android_unittest.cc",
274     "*\bandroid/*",
275   ]
276 }
277 if (!is_chromeos) {
278   sources_assignment_filter += [
279     "*_chromeos.h",
280     "*_chromeos.cc",
281     "*_chromeos_unittest.h",
282     "*_chromeos_unittest.cc",
283     "*\bchromeos/*",
284   ]
285 }
286 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
287 # below.
288
289 # Actually save this list.
290 #
291 # These patterns are executed for every file in the source tree of every run.
292 # Therefore, adding more patterns slows down the build for everybody. We should
293 # only add automatic patterns for configurations affecting hundreds of files
294 # across many projects in the tree.
295 #
296 # Therefore, we only add rules to this list corresponding to platforms on the
297 # Chromium waterfall.  This is not for non-officially-supported platforms
298 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
299 # write a conditional in the target to remove the file(s) from the list when
300 # your platform/toolkit/feature doesn't apply.
301 set_sources_assignment_filter(sources_assignment_filter)
302
303 # =============================================================================
304 # BUILD OPTIONS
305 # =============================================================================
306
307 if (is_component_build) {
308   component_mode = "shared_library"
309 } else {
310   component_mode = "source_set"
311 }
312
313 # These Sanitizers all imply using the Clang compiler. On Windows they either
314 # don't work or work differently.
315 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
316   is_clang = true
317 }
318
319 # ==============================================================================
320 # TOOLCHAIN SETUP
321 # ==============================================================================
322 #
323 # Here we set the default toolchain, as well as the variable host_toolchain
324 # which will identify the toolchain corresponding to the local system when
325 # doing cross-compiles. When not cross-compiling, this will be the same as the
326 # default toolchain.
327
328 if (is_nacl) {
329   if (build_os == "mac") {
330     host_toolchain = "//native_client/build/toolchain/mac:clang"
331   }
332   else {
333     host_toolchain = "//native_client/build/toolchain/${build_os}:${build_cpu_arch}"
334   }
335 } else if (is_win) {
336   # TODO(brettw) name the toolchains the same as cpu_arch as with Linux below
337   # to eliminate these conditionals.
338   if (build_cpu_arch == "x64") {
339     host_toolchain = "//native_client/build/toolchain/win:64"
340   } else if (build_cpu_arch == "x86") {
341     host_toolchain = "//native_client/build/toolchain/win:32"
342   }
343
344   if (cpu_arch == "x64") {
345     set_default_toolchain("//native_client/build/toolchain/win:64")
346   } else if (cpu_arch == "x86") {
347     set_default_toolchain("//native_client/build/toolchain/win:32")
348   }
349 } else if (is_linux) {
350   host_toolchain = "//native_client/build/toolchain/linux:$build_cpu_arch"
351   set_default_toolchain("//native_client/build/toolchain/linux:$cpu_arch")
352 } else if (is_mac) {
353   host_toolchain = "//native_client/build/toolchain/mac:clang"
354   set_default_toolchain(host_toolchain)
355 } else if (is_ios) {
356   host_toolchain = "//native_client/build/toolchain/mac:host_clang"
357   set_default_toolchain("//native_client/build/toolchain/mac:clang")
358 }
359
360 # =============================================================================
361 # TARGET DEFAULTS
362 # =============================================================================
363 #
364 # Set up the default configuration for every build target of the given type.
365 # The values configured here will be automatically set on the scope of the
366 # corresponding target. Target definitions can add or remove to the settings
367 # here as needed.
368
369 #
370 # For NaCl targets, we inject a dependency on prepping the library for cooked
371 # toolchain targets.  For raw targets we inject a dependency on untarring.
372 #
373 _nacl_compiler_configs = [
374   "//native_client/build/config/nacl:nacl_defines",
375   "//native_client/build/config/nacl:nexe_defines"
376 ]
377
378 # Holds all configs used for making native executables and libraries, to avoid
379 # duplication in each target below.
380 _native_compiler_configs = [
381   "//native_client/build/config/nacl:nacl_defines",
382   "//native_client/build/config/compiler:compiler",
383   "//native_client/build/config/compiler:default_warnings",
384   "//native_client/build/config/compiler:no_rtti",
385 ]
386
387 if (is_clang) {
388   _native_compiler_configs += [ "//native_client/build/config/clang:find_bad_constructs" ]
389 }
390
391 # Optimizations and debug checking.
392 if (is_debug) {
393   _native_compiler_configs += [ "//native_client/build/config:debug" ]
394   default_optimization_config = "//native_client/build/config/compiler:no_optimize"
395 } else {
396   native_compiler_configs += [ "//native_client/build/config:release" ]
397   _default_optimization_config = "//native_client/build/config/compiler:optimize"
398 }
399
400 _native_compiler_configs += [ default_optimization_config ]
401
402 # Symbol setup.
403 if (is_clang && is_linux) {
404   # Clang creates chubby debug information, which makes linking very slow.
405   # For now, don't create debug information with clang.
406   # See http://crbug.com/70000
407   # TODO(brettw) This just copies GYP. Why not do this on Mac as well?
408   default_symbols_config = "//native_client/build/config/compiler:no_symbols"
409 } else if (symbol_level == 2) {
410   default_symbols_config = "//native_client/build/config/compiler:symbols"
411 } else if (symbol_level == 1) {
412   default_symbols_config = "//native_client/build/config/compiler:minimal_symbols"
413 } else if (symbol_level == 0) {
414   default_symbols_config = "//native_client/build/config/compiler:no_symbols"
415 } else {
416   assert(false, "Bad value for symbol_level.")
417 }
418 _native_compiler_configs += [ default_symbols_config ]
419
420 # Windows linker setup for EXEs and DLLs.
421 if (is_win) {
422   if (is_debug) {
423     _default_incremental_linking_config =
424       "//native_client/build/config/win:incremental_linking"
425   } else {
426     _default_incremental_linking_config =
427       "//native_client/build/config/win:no_incremental_linking"
428   }
429   _windows_linker_configs = [
430     _default_incremental_linking_config,
431     "//native_client/build/config/win:sdk_link",
432     "//native_client/build/config/win:common_linker_setup",
433     # Default to console-mode apps. Most of our targets are tests and such
434     # that shouldn't use the windows subsystem.
435     "//native_client/build/config/win:console",
436   ]
437 }
438
439 set_defaults("executable") {
440   configs = []
441   if (os != "nacl") {
442     configs = _native_compiler_configs + [
443       "//native_client/build/config:default_libs",
444     ]
445     if (is_win) {
446       configs += _windows_linker_configs
447     } else if (is_mac) {
448   #    configs += [
449   #      "///native_clientbuild/config/mac:mac_dynamic_flags",
450   #      "//native_client/build/config/mac:mac_executable_flags" ]
451     } else if (is_linux) {
452   #    configs += [ "//native_client/build/config/linux:executable_ldconfig" ]
453     }
454   } else {
455     configs = _nacl_compiler_configs
456   }
457 }
458
459 set_defaults("static_library") {
460   configs = []
461   if (os != "nacl") {
462     configs += _native_compiler_configs
463   } else {
464     configs += _nacl_compiler_configs
465   }
466 }
467
468 set_defaults("shared_library") {
469   configs = []
470   if (os != "nacl") {
471     configs += _native_compiler_configs + [
472       "//native_client/build/config:default_libs",
473     ]
474     if (is_win) {
475       configs += _windows_linker_configs
476     } else if (is_mac) {
477       configs += [ "//native_client/build/config/mac:mac_dynamic_flags" ]
478     }
479   } else {
480     configs = _nacl_compiler_configs
481   }
482 }
483
484 set_defaults("source_set") {
485   configs = []
486   if (os != "nacl") {
487     configs = _native_compiler_configs
488   } else {
489     configs = _nacl_compiler_configs
490   }
491 }
492
493