Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / build / config / compiler / BUILD.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 import("//build/config/android/config.gni")
6 if (cpu_arch == "arm") {
7   import("//build/config/arm.gni")
8 }
9 if (is_posix) {
10   import("//build/config/gcc/gcc_version.gni")
11 }
12
13 declare_args() {
14   # Normally, Android builds are lightly optimized, even for debug builds, to
15   # keep binary size down. Setting this flag to true disables such optimization
16   android_full_debug = false
17
18   # Whether to use the binary binutils checked into third_party/binutils.
19   # These are not multi-arch so cannot be used except on x86 and x86-64 (the
20   # only two architectures that are currently checked in). Turn this off when
21   # you are using a custom toolchain and need to control -B in cflags.
22   linux_use_bundled_binutils = is_linux && cpu_arch == "x64"
23 }
24
25 use_gold = is_linux && cpu_arch == "x64"
26
27 if (!is_win) {
28   # linux_use_debug_fission: whether to use split DWARF debug info
29   # files. This can reduce link time significantly, but is incompatible
30   # with some utilities such as icecc and ccache. Requires gold and
31   # gcc >= 4.8 or clang.
32   # http://gcc.gnu.org/wiki/DebugFission
33   use_debug_fission = use_gold && linux_use_bundled_binutils
34 }
35
36 # default_include_dirs ---------------------------------------------------------
37 #
38 # This is a separate config so that third_party code (which would not use the
39 # source root and might have conflicting versions of some headers) can remove
40 # this and specify their own include paths.
41 config("default_include_dirs") {
42   include_dirs = [
43     "//",
44     root_gen_dir,
45   ]
46 }
47
48 # TODO(GYP): is_ubsan, is_ubsan_vptr
49 if (!is_win) {
50   using_sanitizer = is_asan || is_lsan || is_tsan || is_msan
51 }
52
53 # compiler ---------------------------------------------------------------------
54 #
55 # Base compiler configuration.
56 #
57 # See also "runtime_library" below for related stuff and a discusison about
58 # where stuff should go. Put warning related stuff in the "warnings" config.
59
60 config("compiler") {
61   cflags = []
62   cflags_c = []
63   cflags_cc = []
64   ldflags = []
65   defines = []
66
67   # In general, Windows is totally different, but all the other builds share
68   # some common GCC configuration. This section sets up Windows and the common
69   # GCC flags, and then we handle the other non-Windows platforms specifically
70   # below.
71   if (is_win) {
72     # Windows compiler flags setup.
73     # -----------------------------
74     cflags += [
75       "/Gy",  # Enable function-level linking.
76       "/GS",  # Enable buffer security checking.
77       "/FS",  # Preserve previous PDB behavior.
78     ]
79     if (is_component_build) {
80       cflags += [
81         "/EHsc",  # Assume C functions can't throw exceptions and don't catch
82                   # structured exceptions (only C++ ones).
83       ]
84     }
85   } else {
86     # Common GCC compiler flags setup.
87     # --------------------------------
88     cflags += [
89       "-fno-strict-aliasing",  # See http://crbug.com/32204
90     ]
91     cflags_cc += [
92       "-fno-threadsafe-statics",
93       # Not exporting C++ inline functions can generally be applied anywhere
94       # so we do so here. Normal function visibility is controlled by
95       # //build/config/gcc:symbol_visibility_hidden.
96       "-fvisibility-inlines-hidden",
97     ]
98
99     # Stack protection.
100     if (is_mac) {
101       cflags += [ "-fstack-protector-all" ]
102     } else if (is_linux) {
103       cflags += [ "-fstack-protector", "--param=ssp-buffer-size=4" ]
104     }
105
106     # Linker warnings.
107     if (!(is_chromeos && cpu_arch == "arm") && !is_mac) {
108       # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
109       ldflags += [ "-Wl,--fatal-warnings" ]
110     }
111
112     # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and
113     # MemorySanitizer
114     if (using_sanitizer) {
115       cflags += [
116         "-fno-omit-frame-pointer",
117         "-gline-tables-only",
118       ]
119     }
120     if (is_asan) {
121       cflags += [ "-fsanitize=address" ]
122       if (is_mac) {
123         cflags += [ "-mllvm -asan-globals=0" ]  # http://crbug.com/352073
124         # TODO(GYP): deal with mac_bundles.
125       }
126     }
127   }
128
129   if (is_clang && is_debug) {
130     # Allow comparing the address of references and 'this' against 0
131     # in debug builds. Technically, these can never be null in
132     # well-defined C/C++ and Clang can optimize such checks away in
133     # release builds, but they may be used in asserts in debug builds.
134     cflags_cc += [
135       "-Wno-undefined-bool-conversion",
136       "-Wno-tautological-undefined-compare",
137     ]
138   }
139
140   if (is_clang && !is_win) {
141     # This is here so that all files get recompiled after a clang roll and
142     # when turning clang on or off. (defines are passed via the command line,
143     # and build system rebuild things when their commandline changes). Nothing
144     # should ever read this define.
145     defines += [
146       "CR_CLANG_REVISION=" +
147           exec_script(
148               "//tools/clang/scripts/posix-print-revision.py", [], "value")
149     ]
150   }
151
152   # Mac-specific compiler flags setup.
153   # ----------------------------------
154   if (is_mac || is_ios) {
155     # These flags are shared between the C compiler and linker.
156     common_mac_flags = []
157
158     # CPU architecture.
159     if (cpu_arch == "x64") {
160       common_mac_flags += [ "-arch", "x86_64" ]
161     } else if (cpu_arch == "x86") {
162       common_mac_flags += [ "-arch", "i386" ]
163     }
164
165     cflags += common_mac_flags
166
167     # Without this, the constructors and destructors of a C++ object inside
168     # an Objective C struct won't be called, which is very bad.
169     cflags_objcc = [ "-fobjc-call-cxx-cdtors", ]
170
171     cflags_c += [ "-std=c99" ]
172     cflags_cc += [ "-std=gnu++11" ]
173
174     ldflags += common_mac_flags
175   } else if (is_posix) {
176     # Non-Mac Posix compiler flags setup.
177     # -----------------------------------
178     if (gcc_version >= 48) {
179       cflags_cc += [
180         "-std=gnu++11",
181       ]
182     }
183
184     # CPU architecture. We may or may not be doing a cross compile now, so for
185     # simplicity we always explicitly set the architecture.
186     if (cpu_arch == "x64") {
187       cflags += [ "-m64", "-march=x86-64", ]
188       ldflags += [ "-m64" ]
189     } else if (cpu_arch == "x86") {
190       cflags += [ "-m32" ]
191       ldflags += [ "-m32" ]
192       if (is_clang) {
193         cflags += [
194           # Else building libyuv gives clang's register allocator issues,
195           # see llvm.org/PR15798 / crbug.com/233709
196           "-momit-leaf-frame-pointer",
197           # Align the stack on 16-byte boundaries, http://crbug.com/418554.
198           "-mstack-alignment=16",
199           "-mstackrealign",
200         ]
201       }
202     } else if (cpu_arch == "arm") {
203       # Don't set the compiler flags for the WebView build. These will come
204       # from the Android build system.
205       if (!is_android_webview_build) {
206         cflags += [
207           "-march=$arm_arch",
208           "-mfloat-abi=$arm_float_abi",
209         ]
210         if (arm_tune != "") {
211           cflags += [ "-mtune=$arm_tune" ]
212         }
213         if (arm_use_thumb) {
214           cflags += [ "-mthumb" ]
215           if (is_android && !is_clang) {  # Clang doesn't support this option.
216             cflags += [ "-mthumb-interwork" ]
217           }
218         }
219         if (!is_clang) {
220           # Clang doesn't support these flags.
221           cflags += [
222             # The tree-sra optimization (scalar replacement for
223             # aggregates enabling subsequent optimizations) leads to
224             # invalid code generation when using the Android NDK's
225             # compiler (r5-r7). This can be verified using
226             # webkit_unit_tests' WTF.Checked_int8_t test.
227             "-fno-tree-sra",
228             # The following option is disabled to improve binary
229             # size and performance in gcc 4.9.
230             "-fno-caller-saves",
231           ]
232         }
233       }
234     }
235
236     defines += [ "_FILE_OFFSET_BITS=64" ]
237
238     # Omit unwind support in official builds to save space. We can use breakpad
239     # for these builds.
240     if (is_chrome_branded && is_official_build) {
241       cflags += [
242         "-fno-unwind-tables",
243         "-fno-asynchronous-unwind-tables",
244       ]
245     } else {
246       cflags += [ "-funwind-tables" ]
247     }
248   }
249
250   # Linux/Android common flags setup.
251   # ---------------------------------
252   if (is_linux || is_android) {
253     cflags += [
254       "-fPIC",
255       "-pipe",  # Use pipes for communicating between sub-processes. Faster.
256     ]
257
258     ldflags += [
259       "-fPIC",
260       "-Wl,-z,noexecstack",
261       "-Wl,-z,now",
262       "-Wl,-z,relro",
263     ]
264   }
265
266   # Linux-specific compiler flags setup.
267   # ------------------------------------
268   if (is_linux) {
269     cflags += [ "-pthread" ]
270     ldflags += [
271       "-pthread",
272     ]
273   }
274   if (use_gold) {
275     # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of
276     # address space, and it doesn't support cross-compiling).
277     gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
278                             root_build_dir)
279     ldflags += [
280       "-B$gold_path",
281
282       # Newer gccs and clangs support -fuse-ld, use the flag to force gold
283       # selection.
284       # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
285       "-fuse-ld=gold",
286
287       # TODO(brettw) common.gypi has this only for target toolset.
288       "-Wl,--icf=safe",
289
290       # Experimentation found that using four linking threads
291       # saved ~20% of link time.
292       # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
293       # Only apply this to the target linker, since the host
294       # linker might not be gold, but isn't used much anyway.
295       # TODO(raymes): Disable threading because gold is frequently
296       # crashing on the bots: crbug.com/161942.
297       #"-Wl,--threads",
298       #"-Wl,--thread-count=4",
299     ]
300   }
301
302   if (linux_use_bundled_binutils) {
303     binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
304                                 root_build_dir)
305     cflags += [ "-B$binutils_path" ]
306   }
307
308   # Clang-specific compiler flags setup.
309   # ------------------------------------
310   if (is_clang) {
311     cflags += [
312       "-fcolor-diagnostics",
313     ]
314     cflags_cc += [
315       "-std=gnu++11",
316     ]
317   }
318
319   # Android-specific flags setup.
320   # -----------------------------
321   if (is_android) {
322     cflags += [
323       "-ffunction-sections",
324       "-funwind-tables",
325       "-fno-short-enums",
326     ]
327     if (!is_clang) {
328       # Clang doesn't support these flags.
329       cflags += [
330         "-finline-limit=64",
331       ]
332     }
333     if (is_android_webview_build) {
334       # Android predefines this as 1; undefine it here so Chromium can redefine
335       # it later to be 2 for chromium code and unset for third party code. This
336       # works because cflags are added before defines.
337       # TODO(brettw) the above comment seems incorrect. We specify defines
338       # before cflags on our compiler command lines.
339       cflags += [ "-U_FORTIFY_SOURCE" ]
340     }
341
342     if (is_asan) {
343       # Android build relies on -Wl,--gc-sections removing unreachable code.
344       # ASan instrumentation for globals inhibits this and results in a library
345       # with unresolvable relocations.
346       # TODO(eugenis): find a way to reenable this.
347       cflags += [ "-mllvm -asan-globals=0" ]
348     }
349
350     defines += [ "ANDROID" ]
351     if (!is_android_webview_build) {
352       # The NDK has these things, but doesn't define the constants
353       # to say that it does. Define them here instead.
354       defines += [ "HAVE_SYS_UIO_H" ]
355     }
356
357     # Use gold for Android for most CPU architectures.
358     if (cpu_arch == "x86" || cpu_arch == "x64" || cpu_arch == "arm") {
359       ldflags += [ "-fuse-ld=gold" ]
360       if (is_clang) {
361         # Let clang find the ld.gold in the NDK.
362         ldflags += [ "--gcc-toolchain=" + rebase_path(android_toolchain_root,
363                                                       root_build_dir) ]
364       }
365     }
366
367     ldflags += [
368       "-Wl,--no-undefined",
369       # Don't export symbols from statically linked libraries.
370       "-Wl,--exclude-libs=ALL",
371     ]
372     if (cpu_arch == "arm") {
373       ldflags += [
374         # Enable identical code folding to reduce size.
375         "-Wl,--icf=safe",
376       ]
377     }
378
379     if (is_clang) {
380       if (cpu_arch == "arm") {
381         cflags += [
382           "-target arm-linux-androideabi",
383         ]
384         ldflags += [ "-target arm-linux-androideabi" ]
385       } else if (cpu_arch == "x86") {
386         cflags += [ "-target x86-linux-androideabi" ]
387         ldflags += [ "-target x86-linux-androideabi" ]
388       }
389     }
390   }
391 }
392
393 config("compiler_arm_fpu") {
394   if (cpu_arch == "arm" && !is_android_webview_build) {
395     cflags = [
396       "-mfpu=$arm_fpu",
397     ]
398   }
399 }
400
401 # runtime_library -------------------------------------------------------------
402 #
403 # Sets the runtime library and associated options.
404 #
405 # How do you determine what should go in here vs. "compiler" above? Consider if
406 # a target might choose to use a different runtime library (ignore for a moment
407 # if this is possible or reasonable on your system). If such a target would want
408 # to change or remove your option, put it in the runtime_library config. If a
409 # target wants the option regardless, put it in the compiler config.
410
411 config("runtime_library") {
412   cflags = []
413   defines = []
414   ldflags = []
415   lib_dirs = []
416   libs = []
417
418   if (is_component_build) {
419     # Component mode: dynamic CRT.
420     defines += [ "COMPONENT_BUILD" ]
421     if (is_win) {
422       # Since the library is shared, it requires exceptions or will give errors
423       # about things not matching, so keep exceptions on.
424       if (is_debug) {
425         cflags += [ "/MDd" ]
426       } else {
427         cflags += [ "/MD" ]
428       }
429     }
430   } else {
431     # Static CRT.
432     if (is_win) {
433       # We don't use exceptions, and when we link statically we can just get
434       # rid of them entirely.
435       defines += [ "_HAS_EXCEPTIONS=0" ]
436       if (is_debug) {
437         cflags += [ "/MTd" ]
438       } else {
439         cflags += [ "/MT" ]
440       }
441     }
442   }
443
444   if (is_win) {
445     defines += [
446       "__STD_C",
447       "__STDC_CONSTANT_MACROS",
448       "__STDC_FORMAT_MACROS",
449       "_CRT_RAND_S",
450       "_CRT_SECURE_NO_DEPRECATE",
451       "_SCL_SECURE_NO_DEPRECATE",
452     ]
453   }
454
455   # Stlport setup. Android uses a different (smaller) version of the STL.
456   if (is_android) {
457     if (is_clang) {
458       # Work around incompatibilities between bionic and clang headers.
459       defines += [
460         "__compiler_offsetof=__builtin_offsetof",
461         "nan=__builtin_nan",
462       ]
463     }
464
465     defines += [
466       "USE_STLPORT=1",
467       "_STLP_USE_PTR_SPECIALIZATIONS=1",
468       "__GNU_SOURCE=1",  # Necessary for clone().
469     ]
470
471     ldflags += [
472       "-Wl,--warn-shared-textrel",
473       "-nostdlib",
474     ]
475
476     # NOTE: The stlport header include paths below are specified in cflags
477     # rather than include_dirs because they need to come after include_dirs.
478     # Think of them like system headers, but don't use '-isystem' because the
479     # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
480     # strange errors. The include ordering here is important; change with
481     # caution.
482     android_stlport_root = "$android_ndk_root/sources/cxx-stl/stlport"
483
484     cflags += [
485       "-isystem" + rebase_path("$android_stlport_root/stlport",
486                                root_build_dir)
487     ]
488     if (arm_use_thumb) {
489       lib_dirs += [ "$android_stlport_root/libs/$android_app_abi/thumb" ]
490     } else {
491       lib_dirs += [ "$android_stlport_root/libs/$android_app_abi" ]
492     }
493
494     if (component_mode == "shared_library") {
495       libs += [ "stlport_shared" ]
496     } else {
497       libs += [ "stlport_static" ]
498     }
499
500     if (cpu_arch == "mipsel") {
501       libs += [
502         # ld linker is used for mips Android, and ld does not accept library
503         # absolute path prefixed by "-l"; Since libgcc does not exist in mips
504         # sysroot the proper library will be linked.
505         # TODO(gordanac): Remove once gold linker is used for mips Android.
506         "gcc",
507       ]
508     } else {
509       libs += [
510         # Manually link the libgcc.a that the cross compiler uses. This is
511         # absolute because the linker will look inside the sysroot if it's not.
512         rebase_path(android_libgcc_file),
513       ]
514     }
515
516     libs += [
517       "c",
518       "dl",
519       "m",
520     ]
521
522   }
523 }
524
525 # chromium_code ---------------------------------------------------------------
526 #
527 # Toggles between higher and lower warnings for code that is (or isn't)
528 # part of Chromium.
529
530 config("chromium_code") {
531   if (is_win) {
532     cflags = [
533       "/W4",  # Warning level 4.
534     ]
535   } else {
536     cflags = [
537       "-Wall",
538
539       # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
540       # so we specify it explicitly.
541       # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
542       # http://code.google.com/p/chromium/issues/detail?id=90453
543       "-Wsign-compare",
544     ]
545
546     # In Chromium code, we define __STDC_foo_MACROS in order to get the
547     # C99 macros on Mac and Linux.
548     defines = [
549       "__STDC_CONSTANT_MACROS",
550       "__STDC_FORMAT_MACROS",
551     ]
552   }
553 }
554 config("no_chromium_code") {
555   cflags = []
556   cflags_cc = []
557   defines = []
558
559   if (is_win) {
560     cflags += [
561       "/W3",  # Warning level 3.
562       "/wd4800",  # Disable warning when forcing value to bool.
563       "/wd4267",  # TODO(jschuh): size_t to int.
564     ]
565     defines += [
566       "_CRT_NONSTDC_NO_WARNINGS",
567       "_CRT_NONSTDC_NO_DEPRECATE",
568     ]
569   }
570
571   if (is_linux) {
572     # Don't warn about ignoring the return value from e.g. close(). This is
573     # off by default in some gccs but on by default in others. BSD systems do
574     # not support this option, since they are usually using gcc 4.2.1, which
575     # does not have this flag yet.
576     cflags += [ "-Wno-unused-result" ]
577   }
578
579   if (is_linux || is_android) {
580     cflags += [
581       # Don't warn about printf format problems. This is off by default in gcc
582       # but on in Ubuntu's gcc(!).
583       "-Wno-format",
584     ]
585     cflags_cc += [
586       # Don't warn about hash_map in third-party code.
587       "-Wno-deprecated",
588     ]
589   }
590
591   if (is_android_webview_build) {
592     # There is a class of warning which:
593     #  1) Android always enables and also treats as errors
594     #  2) Chromium ignores in third party code
595     # So we re-enable those warnings when building Android.
596     cflags += [
597       "-Wno-address",
598       "-Wno-format-security",
599       "-Wno-return-type",
600       "-Wno-sequence-point",
601     ]
602     cflags_cc += [ "-Wno-non-virtual-dtor" ]
603   }
604 }
605
606 # rtti ------------------------------------------------------------------------
607 #
608 # Allows turning Run-Time Type Identification on or off.
609
610 config("rtti") {
611   if (is_win) {
612     cflags_cc = [ "/GR" ]
613   }
614 }
615 config("no_rtti") {
616   if (is_win) {
617     cflags_cc = [ "/GR-" ]
618   } else {
619     cflags_cc = [ "-fno-rtti" ]
620   }
621 }
622
623 # Warnings ---------------------------------------------------------------------
624 #
625 # This is where we disable various warnings that we've decided aren't
626 # worthwhile, and enable special warnings.
627
628 config("default_warnings") {
629   if (is_win) {
630     cflags = [
631       "/WX",      # Treat warnings as errors.
632
633       # Warnings permanently disabled:
634
635       # TODO(GYP) The GYP build doesn't have this globally enabled but disabled
636       # for a bunch of individual targets. Re-enable this globally when those
637       # targets are fixed.
638       "/wd4018",  # Comparing signed and unsigned values.
639
640       # C4127: conditional expression is constant
641       # This warning can in theory catch dead code and other problems, but
642       # triggers in far too many desirable cases where the conditional
643       # expression is either set by macros or corresponds some legitimate
644       # compile-time constant expression (due to constant template args,
645       # conditionals comparing the sizes of different types, etc.).  Some of
646       # these can be worked around, but it's not worth it.
647       "/wd4127",
648
649       # C4251: 'identifier' : class 'type' needs to have dll-interface to be
650       #        used by clients of class 'type2'
651       # This is necessary for the shared library build.
652       "/wd4251",
653
654       # C4351: new behavior: elements of array 'array' will be default
655       #        initialized
656       # This is a silly "warning" that basically just alerts you that the
657       # compiler is going to actually follow the language spec like it's
658       # supposed to, instead of not following it like old buggy versions did.
659       # There's absolutely no reason to turn this on.
660       "/wd4351",
661
662       # C4355: 'this': used in base member initializer list
663       # It's commonly useful to pass |this| to objects in a class' initializer
664       # list.  While this warning can catch real bugs, most of the time the
665       # constructors in question don't attempt to call methods on the passed-in
666       # pointer (until later), and annotating every legit usage of this is
667       # simply more hassle than the warning is worth.
668       "/wd4355",
669
670       # C4503: 'identifier': decorated name length exceeded, name was
671       #        truncated
672       # This only means that some long error messages might have truncated
673       # identifiers in the presence of lots of templates.  It has no effect on
674       # program correctness and there's no real reason to waste time trying to
675       # prevent it.
676       "/wd4503",
677
678       # C4611: interaction between 'function' and C++ object destruction is
679       #        non-portable
680       # This warning is unavoidable when using e.g. setjmp/longjmp.  MSDN
681       # suggests using exceptions instead of setjmp/longjmp for C++, but
682       # Chromium code compiles without exception support.  We therefore have to
683       # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
684       # have to turn off this warning (and be careful about how object
685       # destruction happens in such cases).
686       "/wd4611",
687
688
689       # Warnings to evaluate and possibly fix/reenable later:
690
691       "/wd4100",  # Unreferenced formal function parameter.
692       "/wd4189",  # A variable was declared and initialized but never used.
693       "/wd4244",  # Conversion: possible loss of data.
694       "/wd4481",  # Nonstandard extension: override specifier.
695       "/wd4505",  # Unreferenced local function has been removed.
696       "/wd4510",  # Default constructor could not be generated.
697       "/wd4512",  # Assignment operator could not be generated.
698       "/wd4610",  # Class can never be instantiated, constructor required.
699     ]
700   } else {
701     # Common GCC warning setup.
702     cflags = [
703       # Enables.
704       "-Wendif-labels",  # Weird old-style text after an #endif.
705       "-Werror",  # Warnings as errors.
706
707       # Disables.
708       "-Wno-missing-field-initializers",  # "struct foo f = {0};"
709       "-Wno-unused-parameter",  # Unused function parameters.
710     ]
711     cflags_cc = []
712
713     if (is_mac) {
714       cflags += [
715         "-Wnewline-eof",
716       ]
717     }
718
719     if (is_clang) {
720       cflags += [
721         # This warns on using ints as initializers for floats in
722         # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
723         # which happens in several places in chrome code. Not sure if
724         # this is worth fixing.
725         "-Wno-c++11-narrowing",
726
727         # Don't die on dtoa code that uses a char as an array index.
728         # This is required solely for base/third_party/dmg_fp/dtoa.cc.
729         # TODO(brettw) move this to that project then!
730         "-Wno-char-subscripts",
731
732         # Warns on switches on enums that cover all enum values but
733         # also contain a default: branch. Chrome is full of that.
734         "-Wno-covered-switch-default",
735
736         # Clang considers the `register` keyword as deprecated, but e.g.
737         # code generated by flex (used in angle) contains that keyword.
738         # http://crbug.com/255186
739         "-Wno-deprecated-register",
740
741         # TODO(thakis): This used to be implied by -Wno-unused-function,
742         # which we no longer use. Check if it makes sense to remove
743         # this as well. http://crbug.com/316352
744         "-Wno-unneeded-internal-declaration",
745
746         # TODO(thakis): Remove, http://crbug.com/263960
747         "-Wno-reserved-user-defined-literal",
748
749         # TODO(hans): Clean this up. Or disable with finer granularity.
750         "-Wno-unused-local-typedef",
751       ]
752     }
753     if (gcc_version >= 48) {
754       cflags_cc += [
755         # See comment for -Wno-c++11-narrowing.
756         "-Wno-narrowing",
757         # TODO(thakis): Remove, http://crbug.com/263960
758         "-Wno-literal-suffix",
759       ]
760     }
761
762     # Suppress warnings about ABI changes on ARM (Clang doesn't give this
763     # warning).
764     if (cpu_arch == "arm" && !is_clang) {
765       cflags += [ "-Wno-psabi" ]
766     }
767
768     if (is_android) {
769       # Disable any additional warnings enabled by the Android build system but
770       # which chromium does not build cleanly with (when treating warning as
771       # errors).
772       cflags += [
773         "-Wno-extra",
774         "-Wno-ignored-qualifiers",
775         "-Wno-type-limits",
776       ]
777       cflags_cc += [
778         # Disabling c++0x-compat should be handled in WebKit, but
779         # this currently doesn't work because gcc_version is not set
780         # correctly when building with the Android build system.
781         # TODO(torne): Fix this in WebKit.
782         "-Wno-error=c++0x-compat",
783         # Other things unrelated to -Wextra:
784         "-Wno-non-virtual-dtor",
785         "-Wno-sign-promo",
786       ]
787     }
788
789     if (gcc_version >= 48) {
790       # Don't warn about the "typedef 'foo' locally defined but not used"
791       # for gcc 4.8.
792       # TODO: remove this flag once all builds work. See crbug.com/227506
793       cflags += [
794         "-Wno-unused-local-typedefs",
795       ]
796     }
797   }
798 }
799
800 # This will generate warnings when using Clang if code generates exit-time
801 # destructors, which will slow down closing the program.
802 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
803 config("wexit_time_destructors") {
804   if (is_clang) {
805     cflags = [ "-Wexit-time-destructors" ]
806   }
807 }
808
809 # Optimization -----------------------------------------------------------------
810 #
811 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"
812 # which it will assign to the config it implicitly applies to every target. If
813 # you want to override the optimization level for your target, remove this
814 # config (which will expand differently for debug or release builds), and then
815 # add back the one you want to override it with:
816 #
817 #   configs -= default_optimization_config
818 #   configs += [ "//build/config/compiler/optimize_max" ]
819
820 # Shared settings for both "optimize" and "optimize_max" configs.
821 if (is_win) {
822   common_optimize_on_cflags = [
823     "/O2",
824     "/Ob2",  # both explicit and auto inlining.
825     "/Oy-",  # disable omitting frame pointers, must be after /o2.
826     "/Os",   # favor size over speed.
827   ]
828   common_optimize_on_ldflags = []
829 } else {
830   common_optimize_on_cflags = [
831     # Don't emit the GCC version ident directives, they just end up in the
832     # .comment section taking up binary size.
833     "-fno-ident",
834     # Put data and code in their own sections, so that unused symbols
835     # can be removed at link time with --gc-sections.
836     "-fdata-sections",
837     "-ffunction-sections",
838   ]
839   common_optimize_on_ldflags = []
840
841   if (is_android) {
842     if (!using_sanitizer) {
843       common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
844     }
845     common_optimize_on_ldflags += [
846       # Warn in case of text relocations.
847       "-Wl,--warn-shared-textrel",
848     ]
849   }
850
851   if (is_mac) {
852     if (symbol_level == 2) {
853       # Mac dead code stripping requires symbols.
854       common_optimize_on_ldflags += [
855         "-Wl,-dead_strip",
856       ]
857     }
858   } else {
859     # Non-Mac Posix linker flags.
860     common_optimize_on_ldflags += [
861       # Specifically tell the linker to perform optimizations.
862       # See http://lwn.net/Articles/192624/ .
863       "-Wl,-O1",
864       "-Wl,--as-needed",
865       "-Wl,--gc-sections",
866     ]
867   }
868 }
869
870 # Default "optimization on" config. On Windows, this favors size over speed.
871 config("optimize") {
872   cflags = common_optimize_on_cflags
873   ldflags = common_optimize_on_ldflags
874   if (is_win) {
875     cflags += [
876       "/Os",   # favor size over speed.
877     ]
878   } else if (is_android || is_ios) {
879     cflags += [
880       "-Os",  # Favor size over speed.
881     ]
882   } else {
883     cflags += [
884       "-O2",
885     ]
886   }
887 }
888
889 # Turn off optimizations.
890 config("no_optimize") {
891   if (is_win) {
892     cflags = [
893       "/Od",  # Disable optimization.
894       "/Ob0",  # Disable all inlining (on by default).
895       "/RTC1",  # Runtime checks for stack frame and uninitialized variables.
896     ]
897   } else if (is_android && !android_full_debug) {
898     # On Android we kind of optimize some things that don't affect debugging
899     # much even when optimization is disabled to get the binary size down.
900     cflags = [
901       "-Os",
902       "-fdata-sections",
903       "-ffunction-sections",
904     ]
905     if (!using_sanitizer) {
906       cflags += [ "-fomit-frame-pointer" ]
907     }
908     ldflags = common_optimize_on_ldflags
909   } else {
910     cflags = [ "-O0" ]
911   }
912 }
913
914 # Turns up the optimization level. On Windows, this implies whole program
915 # optimization and link-time code generation which is very expensive and should
916 # be used sparingly.
917 config("optimize_max") {
918   cflags = common_optimize_on_cflags
919   ldflags = common_optimize_on_ldflags
920   if (is_win) {
921     cflags += [
922       "/Ot",   # Favor speed over size.
923       "/GL",   # Whole program optimization.
924       # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
925       # Probably anything that this would catch that wouldn't be caught in a
926       # normal build isn't going to actually be a bug, so the incremental value
927       # of C4702 for PGO builds is likely very small.
928       "/wd4702",
929     ]
930   } else {
931     cflags += [
932       "-O2",
933     ]
934   }
935 }
936
937 # Symbols ----------------------------------------------------------------------
938
939 config("symbols") {
940   if (is_win) {
941     cflags = [ "/Zi" ]  # Produce PDB file, no edit and continue.
942     ldflags = [ "/DEBUG" ]
943   } else {
944     cflags = [ "-g2" ]
945     if (use_debug_fission) {
946       cflags += [ "-gsplit-dwarf" ]
947     }
948   }
949 }
950
951 config("minimal_symbols") {
952   if (is_win) {
953     # Linker symbols for backtraces only.
954     ldflags = [ "/DEBUG" ]
955   } else {
956     cflags = [ "-g1" ]
957     if (use_debug_fission) {
958       cflags += [ "-gsplit-dwarf" ]
959     }
960   }
961 }
962
963 config("no_symbols") {
964   if (!is_win) {
965     cflags = [ "-g0" ]
966   }
967 }