Upstream version 7.36.149.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   # 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
86 if (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
160 # =============================================================================
161 # CPU ARCHITECTURE
162 # =============================================================================
163
164 if (is_win) {
165   # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
166   # unless the override flag is specified.
167   if (force_win64) {
168     cpu_arch = "x64"
169   } else {
170     cpu_arch = "x86"
171   }
172 }
173
174 # =============================================================================
175 # SOURCES FILTERS
176 # =============================================================================
177 #
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.
182 #
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).
186 #
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
190 # example).
191
192 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
193 # below.
194 windows_sources_filters = [
195   "*_win.cc",
196   "*_win.h",
197   "*_win_unittest.cc",
198   "*\bwin/*",
199   "*.rc",
200 ]
201 mac_sources_filters = [
202   "*_mac.h",
203   "*_mac.cc",
204   "*_mac.mm",
205   "*_mac_unittest.h",
206   "*_mac_unittest.cc",
207   "*_mac_unittest.mm",
208   "*\bmac/*",
209   "*_cocoa.h",
210   "*_cocoa.cc",
211   "*_cocoa.mm",
212   "*_cocoa_unittest.h",
213   "*_cocoa_unittest.cc",
214   "*_cocoa_unittest.mm",
215   "*\bcocoa/*",
216 ]
217 ios_sources_filters = [
218   "*_ios.h",
219   "*_ios.cc",
220   "*_ios.mm",
221   "*_ios_unittest.h",
222   "*_ios_unittest.cc",
223   "*_ios_unittest.mm",
224   "*\bios/*",
225 ]
226 objective_c_sources_filters = [
227   "*.mm",
228 ]
229 linux_sources_filters = [
230   "*_linux.h",
231   "*_linux.cc",
232   "*_linux_unittest.h",
233   "*_linux_unittest.cc",
234   "*\blinux/*",
235 ]
236 android_sources_filters = [
237   "*_android.h",
238   "*_android.cc",
239   "*_android_unittest.h",
240   "*_android_unittest.cc",
241   "*\bandroid/*",
242 ]
243 posix_sources_filters = [
244   "*_posix.h",
245   "*_posix.cc",
246   "*_posix_unittest.h",
247   "*_posix_unittest.cc",
248   "*\bposix/*",
249 ]
250 chromeos_sources_filters = [
251   "*_chromeos.h",
252   "*_chromeos.cc",
253   "*_chromeos_unittest.h",
254   "*_chromeos_unittest.cc",
255   "*\bchromeos/*",
256 ]
257 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
258 # below.
259
260 # Construct the full list of sources we're using for this platform.
261 sources_assignment_filter = []
262 if (is_win) {
263   sources_assignment_filter += posix_sources_filters
264 } else {
265   sources_assignment_filter += windows_sources_filters
266 }
267 if (!is_mac) {
268   sources_assignment_filter += mac_sources_filters
269 }
270 if (!is_ios) {
271   sources_assignment_filter += ios_sources_filters
272 }
273 if (!is_mac && !is_ios) {
274   sources_assignment_filter += objective_c_sources_filters
275 }
276 if (!is_linux) {
277   sources_assignment_filter += linux_sources_filters
278 }
279 if (!is_android) {
280   sources_assignment_filter += android_sources_filters
281 }
282 if (!is_chromeos) {
283   sources_assignment_filter += chromeos_sources_filters
284 }
285
286 # Actually save this list.
287 #
288 # DO NOT ADD MORE PATTERNS TO THIS LIST.
289 #
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.
294 #
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)
301
302 # =============================================================================
303 # BUILD OPTIONS
304 # =============================================================================
305
306 if (is_component_build) {
307   component_mode = "shared_library"
308 } else {
309   component_mode = "static_library"
310 }
311
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)) {
315   is_clang = true
316 }
317
318 # =============================================================================
319 # TARGET DEFAULTS
320 # =============================================================================
321 #
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
325 # here as needed.
326
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",
331
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",
337 ]
338 if (is_win) {
339   native_compiler_configs += [
340     "//build/config/win:lean_and_mean",
341     "//build/config/win:sdk",
342     "//build/config/win:unicode",
343   ]
344 } else if (is_linux) {
345   native_compiler_configs += [ "//build/config/linux:sdk", ]
346 } else if (is_mac) {
347   native_compiler_configs += [ "//build/config/mac:sdk", ]
348 } else if (is_ios) {
349   native_compiler_configs += [ "//build/config/ios:sdk", ]
350 } else if (is_android) {
351   native_compiler_configs += [ "//build/config/android:sdk", ]
352 }
353 if (!is_win) {
354   native_compiler_configs += [ "//build/config/gcc:symbol_visibility_hidden" ]
355 }
356 if (is_clang) {
357   native_compiler_configs += [
358     "//build/config/clang:find_bad_constructs",
359     "//build/config/clang:extra_warnings",
360   ]
361 }
362
363 # Optimizations and debug checking.
364 if (is_debug) {
365   native_compiler_configs += [ "//build/config:debug" ]
366   default_optimization_config = "//build/config/compiler:no_optimize"
367 } else {
368   native_compiler_configs += [ "//build/config:release" ]
369   default_optimization_config = "//build/config/compiler:optimize"
370 }
371 native_compiler_configs += [ default_optimization_config ]
372
373 # Symbol setup.
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"
386 } else {
387   assert(false, "Bad value for symbol_level.")
388 }
389 native_compiler_configs += [ default_symbols_config ]
390
391 # Windows linker setup for EXEs and DLLs.
392 if (is_win) {
393   if (is_debug) {
394     default_incremental_linking_config =
395       "//build/config/win:incremental_linking"
396   } else {
397     default_incremental_linking_config =
398       "//build/config/win:no_incremental_linking"
399   }
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",
407   ]
408 }
409
410 set_defaults("executable") {
411   configs = native_compiler_configs + [
412     "//build/config:default_libs",
413   ]
414   if (is_win) {
415     configs += windows_linker_configs
416   } else if (is_mac) {
417     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" ]
422   }
423 }
424
425 set_defaults("static_library") {
426   configs = native_compiler_configs
427 }
428
429 set_defaults("shared_library") {
430   configs = native_compiler_configs + [
431     "//build/config:default_libs",
432   ]
433   if (is_win) {
434     configs += windows_linker_configs
435   } else if (is_mac) {
436     configs += [ "//build/config/mac:mac_dynamic_flags" ]
437   }
438 }
439
440 set_defaults("source_set") {
441   configs = native_compiler_configs
442 }
443
444 # ==============================================================================
445 # TOOLCHAIN SETUP
446 # ==============================================================================
447 #
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
451 # default toolchain.
452
453 if (is_win) {
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"
460   }
461
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")
466   }
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")
473 } else if (is_mac) {
474   host_toolchain = "//build/toolchain/mac:clang"
475   set_default_toolchain(host_toolchain)
476 } else if (is_ios) {
477   host_toolchain = "//build/toolchain/mac:host_clang"
478   set_default_toolchain("//build/toolchain/mac:clang")
479 }