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.
5 import("//build/config/android/config.gni")
6 import("//build/config/chrome_build.gni")
7 if (current_cpu == "arm") {
8 import("//build/config/arm.gni")
10 if (current_cpu == "mipsel" || current_cpu == "mips64el") {
11 import("//build/config/mips.gni")
14 import("//build/config/gcc/gcc_version.gni")
17 import("//build/config/win/visual_studio_version.gni")
20 import("//build/toolchain/ccache.gni")
21 import("//build/config/sanitizers/sanitizers.gni")
24 # Normally, Android builds are lightly optimized, even for debug builds, to
25 # keep binary size down. Setting this flag to true disables such optimization
26 android_full_debug = false
28 # Whether to use the binary binutils checked into third_party/binutils.
29 # These are not multi-arch so cannot be used except on x86 and x86-64 (the
30 # only two architectures that are currently checked in). Turn this off when
31 # you are using a custom toolchain and need to control -B in cflags.
32 linux_use_bundled_binutils = is_linux && current_cpu == "x64"
33 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
36 # Compile in such a way as to enable profiling of the generated code. For
37 # example, don't omit the frame pointer and leave in symbols.
38 enable_profiling = false
40 # Compile in such a way as to make it possible for the profiler to unwind full
41 # stack frames. Setting this flag has a large effect on the performance of the
42 # generated code than just setting profiling, but gives the profiler more
43 # information to analyze.
44 # Requires profiling to be set to true.
45 enable_full_stack_frames_for_profiling = false
47 # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of
48 # address space, and it doesn't support cross-compiling).
49 use_gold = is_linux && current_cpu == "x64"
51 # When we are going to use gold we need to find it.
53 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
59 # use_debug_fission: whether to use split DWARF debug info
60 # files. This can reduce link time significantly, but is incompatible
61 # with some utilities such as icecc and ccache. Requires gold and
62 # gcc >= 4.8 or clang.
63 # http://gcc.gnu.org/wiki/DebugFission
64 use_debug_fission = is_debug && !is_win && use_gold &&
65 linux_use_bundled_binutils && !use_ccache
68 # Whether the VS xtree header has been patched to disable warning 4702. If
69 # it has, then we don't need to disable 4702 (unreachable code warning).
70 # The patch is preapplied to the internal toolchain and hence all bots.
71 msvs_xtree_patched = false
75 # default_include_dirs ---------------------------------------------------------
77 # This is a separate config so that third_party code (which would not use the
78 # source root and might have conflicting versions of some headers) can remove
79 # this and specify their own include paths.
80 config("default_include_dirs") {
87 # TODO(GYP): is_ubsan, is_ubsan_vptr
89 using_sanitizer = is_asan || is_lsan || is_tsan || is_msan
92 # compiler ---------------------------------------------------------------------
94 # Base compiler configuration.
96 # See also "runtime_library" below for related stuff and a discussion about
97 # where stuff should go. Put warning related stuff in the "warnings" config.
108 # In general, Windows is totally different, but all the other builds share
109 # some common GCC configuration. This section sets up Windows and the common
110 # GCC flags, and then we handle the other non-Windows platforms specifically
113 # Windows compiler flags setup.
114 # -----------------------------
116 "/Gy", # Enable function-level linking.
117 "/GS", # Enable buffer security checking.
118 "/FS", # Preserve previous PDB behavior.
119 "/bigobj", # Some of our files are bigger than the regular limits.
122 # Force C/C++ mode for the given GN detected file type. This is necessary
123 # for precompiled headers where the same source file is compiled in both
125 cflags_c += [ "/TC" ]
126 cflags_cc += [ "/TP" ]
128 # Building with Clang on Windows is a work in progress and very
129 # experimental. See crbug.com/82385.
130 # Keep this in sync with the similar block in build/common.gypi
133 # Many files use intrinsics without including this header.
134 # TODO(hans): Fix those files, or move this to sub-GYPs.
138 if (visual_studio_version == "2013") {
139 cflags += [ "-fmsc-version=1800" ]
140 } else if (visual_studio_version == "2015") {
141 cflags += [ "-fmsc-version=1900" ]
144 if (current_cpu == "x86") {
150 if (exec_script("//build/win/use_ansi_codes.py", [], "trim string") ==
153 # cmd.exe doesn't understand ANSI escape codes by default,
154 # so only enable them if something emulating them is around.
155 "-fansi-escape-codes",
161 # SyzyAsan needs /PROFILE turned on to produce appropriate pdbs.
162 assert(!is_win_fastlink, "/PROFILE and /DEBUG:FASTLINK are incompatible")
163 ldflags += [ "/PROFILE" ]
166 # Common GCC compiler flags setup.
167 # --------------------------------
168 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
170 "-fno-threadsafe-statics",
172 # Not exporting C++ inline functions can generally be applied anywhere
173 # so we do so here. Normal function visibility is controlled by
174 # //build/config/gcc:symbol_visibility_hidden.
175 "-fvisibility-inlines-hidden",
180 cflags += [ "-fstack-protector-all" ]
181 } else if (is_posix && !is_chromeos && !is_nacl) {
182 # TODO(phajdan.jr): Use -fstack-protector-strong when our gcc supports it.
183 cflags += [ "--param=ssp-buffer-size=4" ]
184 if (is_android && (current_cpu == "arm64" || current_cpu == "x86")) {
185 cflags += [ "-fno-stack-protector" ]
187 cflags += [ "-fstack-protector" ]
192 if (!(is_chromeos && current_cpu == "arm") && !is_mac && !is_ios) {
193 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
194 ldflags += [ "-Wl,--fatal-warnings" ]
197 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and
199 if (using_sanitizer) {
201 "-fno-omit-frame-pointer",
202 "-gline-tables-only",
206 asan_blacklist_path =
207 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir)
209 "-fsanitize=address",
210 "-fsanitize-blacklist=$asan_blacklist_path",
213 cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073
214 # TODO(GYP): deal with mac_bundles.
218 cflags += [ "-fsanitize=leak" ]
221 tsan_blacklist_path =
222 rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir)
225 "-fsanitize-blacklist=$tsan_blacklist_path",
229 msan_blacklist_path =
230 rebase_path("//tools/msan/blacklist.txt", root_build_dir)
233 "-fsanitize-memory-track-origins=$msan_track_origins",
234 "-fsanitize-blacklist=$msan_blacklist_path",
238 if (use_custom_libcxx) {
239 cflags_cc += [ "-nostdinc++" ]
241 "//buildtools/third_party/libc++/trunk/include",
242 "//buildtools/third_party/libc++abi/trunk/include",
247 if (is_clang && is_debug) {
248 # Allow comparing the address of references and 'this' against 0
249 # in debug builds. Technically, these can never be null in
250 # well-defined C/C++ and Clang can optimize such checks away in
251 # release builds, but they may be used in asserts in debug builds.
253 "-Wno-undefined-bool-conversion",
254 "-Wno-tautological-undefined-compare",
258 if (is_clang && !is_nacl) {
259 # This is here so that all files get recompiled after a clang roll and
260 # when turning clang on or off. (defines are passed via the command line,
261 # and build system rebuild things when their commandline changes). Nothing
262 # should ever read this define.
264 [ "CR_CLANG_REVISION=" + exec_script("//tools/clang/scripts/update.py",
265 [ "--print-revision" ],
269 # Mac-specific compiler flags setup.
270 # ----------------------------------
271 if (is_mac || is_ios) {
272 # These flags are shared between the C compiler and linker.
273 common_mac_flags = []
276 if (current_cpu == "x64") {
277 common_mac_flags += [
281 } else if (current_cpu == "x86") {
282 common_mac_flags += [
286 } else if (current_cpu == "arm") {
287 # TODO(GYP): we may need to distinguish between "arm64", "armv7",
288 # and "armv7s" for iOS, and hence need multiple current_cpu values
289 # rather than just "arm".
290 common_mac_flags += [
296 cflags += common_mac_flags
298 # Without this, the constructors and destructors of a C++ object inside
299 # an Objective C struct won't be called, which is very bad.
300 cflags_objcc += [ "-fobjc-call-cxx-cdtors" ]
302 cflags_c += [ "-std=c99" ]
304 ldflags += common_mac_flags
305 } else if (is_posix) {
306 # Non-Mac Posix compiler flags setup.
307 # -----------------------------------
308 if (enable_profiling && !is_debug) {
309 # The GYP build spams this define into every compilation unit, as we do
310 # here, but it only appears to be used in base and a couple other places.
311 # TODO(abarth): Should we move this define closer to where it's used?
312 defines += [ "ENABLE_PROFILING" ]
315 "-fno-omit-frame-pointer",
319 if (enable_full_stack_frames_for_profiling) {
322 "-fno-optimize-sibling-calls",
327 # CPU architecture. We may or may not be doing a cross compile now, so for
328 # simplicity we always explicitly set the architecture.
329 if (current_cpu == "x64") {
334 ldflags += [ "-m64" ]
335 } else if (current_cpu == "x86") {
337 ldflags += [ "-m32" ]
340 # Else building libyuv gives clang's register allocator issues,
341 # see llvm.org/PR15798 / crbug.com/233709
342 "-momit-leaf-frame-pointer",
344 # Align the stack on 16-byte boundaries, http://crbug.com/418554.
345 "-mstack-alignment=16",
349 } else if (current_cpu == "arm") {
352 "-mfloat-abi=$arm_float_abi",
354 if (arm_tune != "") {
355 cflags += [ "-mtune=$arm_tune" ]
358 cflags += [ "-mthumb" ]
359 if (is_android && !is_clang) { # Clang doesn't support this option.
360 cflags += [ "-mthumb-interwork" ]
364 # Clang doesn't support these flags.
366 # The tree-sra optimization (scalar replacement for
367 # aggregates enabling subsequent optimizations) leads to
368 # invalid code generation when using the Android NDK's
369 # compiler (r5-r7). This can be verified using
370 # webkit_unit_tests' WTF.Checked_int8_t test.
373 # The following option is disabled to improve binary
374 # size and performance in gcc 4.9.
378 } else if (current_cpu == "mipsel") {
379 if (mips_arch_variant == "r6") {
390 } else if (mips_arch_variant == "r2") {
395 if (mips_float_abi == "hard" && mips_fpu_mode != "") {
396 cflags += [ "-m$mips_fpu_mode" ]
398 } else if (mips_arch_variant == "r1") {
405 if (mips_dsp_rev == 1) {
406 cflags += [ "-mdsp" ]
407 } else if (mips_dsp_rev == 2) {
408 cflags += [ "-mdspr2" ]
411 cflags += [ "-m${mips_float_abi}-float" ]
412 } else if (current_cpu == "mips64el") {
413 if (mips_arch_variant == "r6") {
418 ldflags += [ "-mips64r6" ]
419 } else if (mips_arch_variant == "r2") {
424 ldflags += [ "-mips64r2" ]
428 defines += [ "_FILE_OFFSET_BITS=64" ]
433 "_LARGEFILE64_SOURCE",
437 # Omit unwind support in official builds to save space. We can use breakpad
439 if (is_chrome_branded && is_official_build) {
441 "-fno-unwind-tables",
442 "-fno-asynchronous-unwind-tables",
444 defines += [ "NO_UNWIND_TABLES" ]
446 cflags += [ "-funwind-tables" ]
450 # Linux/Android common flags setup.
451 # ---------------------------------
452 if (is_linux || is_android) {
455 "-pipe", # Use pipes for communicating between sub-processes. Faster.
460 "-Wl,-z,noexecstack",
464 if (!using_sanitizer) {
465 ldflags += [ "-Wl,-z,defs" ]
469 # Linux-specific compiler flags setup.
470 # ------------------------------------
472 cflags += [ "-pthread" ]
473 ldflags += [ "-pthread" ]
479 # Newer gccs and clangs support -fuse-ld, use the flag to force gold
481 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
484 # Experimentation found that using four linking threads
485 # saved ~20% of link time.
486 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
487 # Only apply this to the target linker, since the host
488 # linker might not be gold, but isn't used much anyway.
489 # TODO(raymes): Disable threading because gold is frequently
490 # crashing on the bots: crbug.com/161942.
492 #"-Wl,--thread-count=4",
495 if (!is_asan && !is_msan && !is_lsan && !is_tsan) {
496 # TODO(brettw) common.gypi has this only for target toolset.
497 ldflags += [ "-Wl,--icf=all" ]
500 # TODO(thestig): Make this flag work with GN.
501 #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan || is_msan)) {
503 # "-Wl,--detect-odr-violations",
508 if (linux_use_bundled_binutils) {
509 cflags += [ "-B$binutils_path" ]
512 # Clang-specific compiler flags setup.
513 # ------------------------------------
515 cflags += [ "-fcolor-diagnostics" ]
518 # C++11 compiler flags setup.
519 # ---------------------------
520 if (is_linux || is_android || is_nacl) {
521 # gnu++11 instead of c++11 is needed because some code uses typeof() (a
523 # TODO(thakis): Eventually switch this to c++11 instead,
524 # http://crbug.com/427584
525 cflags_cc += [ "-std=gnu++11" ]
526 } else if (!is_win) {
527 cflags_cc += [ "-std=c++11" ]
530 # Android-specific flags setup.
531 # -----------------------------
534 "-ffunction-sections",
539 rebased_android_toolchain_root =
540 rebase_path(android_toolchain_root, root_build_dir)
542 # TODO(hans) Enable integrated-as (crbug.com/124610).
544 "-B${rebased_android_toolchain_root}/bin", # Else /usr/bin/as gets picked up.
547 # Clang doesn't support these flags.
548 cflags += [ "-finline-limit=64" ]
551 # Android build relies on -Wl,--gc-sections removing unreachable code.
552 # ASan instrumentation for globals inhibits this and results in a library
553 # with unresolvable relocations.
554 # TODO(eugenis): find a way to reenable this.
555 cflags += [ "-mllvm -asan-globals=0" ]
558 defines += [ "ANDROID" ]
560 # The NDK has these things, but doesn't define the constants
561 # to say that it does. Define them here instead.
562 defines += [ "HAVE_SYS_UIO_H" ]
564 # Use gold for Android for most CPU architectures.
565 if (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm") {
566 ldflags += [ "-fuse-ld=gold" ]
568 # Let clang find the ld.gold in the NDK.
569 ldflags += [ "--gcc-toolchain=$rebased_android_toolchain_root" ]
574 "-Wl,--no-undefined",
576 # Don't allow visible symbols from libgcc or libc++ to be
578 "-Wl,--exclude-libs=libgcc.a",
579 "-Wl,--exclude-libs=libc++_static.a",
581 # Don't allow visible symbols from libraries that contain
582 # assembly code with symbols that aren't hidden properly.
583 # http://crbug.com/448386
584 "-Wl,--exclude-libs=libvpx_assembly_arm.a",
586 if (current_cpu == "arm") {
588 # Enable identical code folding to reduce size.
594 if (current_cpu == "arm") {
597 "arm-linux-androideabi",
601 "arm-linux-androideabi",
603 } else if (current_cpu == "x86") {
606 "i686-linux-androideabi",
610 "i686-linux-androideabi",
616 # Pass the same C/C++ flags to the objective C/C++ compiler.
617 cflags_objc += cflags_c
618 cflags_objcc += cflags_cc
621 config("compiler_arm_fpu") {
622 if (current_cpu == "arm" && !is_ios) {
623 cflags = [ "-mfpu=$arm_fpu" ]
627 # runtime_library -------------------------------------------------------------
629 # Sets the runtime library and associated options.
631 # How do you determine what should go in here vs. "compiler" above? Consider if
632 # a target might choose to use a different runtime library (ignore for a moment
633 # if this is possible or reasonable on your system). If such a target would want
634 # to change or remove your option, put it in the runtime_library config. If a
635 # target wants the option regardless, put it in the compiler config.
637 config("runtime_library") {
644 if (is_component_build) {
645 # Component mode: dynamic CRT.
646 defines += [ "COMPONENT_BUILD" ]
648 # Since the library is shared, it requires exceptions or will give errors
649 # about things not matching, so keep exceptions on.
657 if (is_win && current_os != "win") {
658 # WindowsRT: use the dynamic CRT.
665 # Desktop Windows: static CRT.
678 "_CRT_SECURE_NO_DEPRECATE",
680 "_SCL_SECURE_NO_DEPRECATE",
684 # Android standard library setup.
687 # Work around incompatibilities between bionic and clang headers.
689 "__compiler_offsetof=__builtin_offsetof",
694 defines += [ "__GNU_SOURCE=1" ] # Necessary for clone().
696 # TODO(jdduke) Re-enable on mips after resolving linking
697 # issues with libc++ (crbug.com/456380).
698 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
699 ldflags += [ "-Wl,--warn-shared-textrel" ]
701 ldflags += [ "-nostdlib" ]
703 # NOTE: The libc++ header include paths below are specified in cflags
704 # rather than include_dirs because they need to come after include_dirs.
705 # Think of them like system headers, but don't use '-isystem' because the
706 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
707 # strange errors. The include ordering here is important; change with
711 rebase_path("$android_libcpp_root/libcxx/include", root_build_dir),
712 "-isystem" + rebase_path(
713 "$android_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/include",
716 rebase_path("$android_ndk_root/sources/android/support/include",
720 lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ]
721 libs += [ "$android_libcpp_library" ]
723 if (current_cpu == "mipsel") {
725 # ld linker is used for mips Android, and ld does not accept library
726 # absolute path prefixed by "-l"; Since libgcc does not exist in mips
727 # sysroot the proper library will be linked.
728 # TODO(gordanac): Remove once gold linker is used for mips Android.
733 # Manually link the libgcc.a that the cross compiler uses. This is
734 # absolute because the linker will look inside the sysroot if it's not.
735 rebase_path(android_libgcc_file),
745 # Clang with libc++ does not require an explicit atomic library reference.
752 # default_warning_flags collects all warning flags that are used by default.
753 # This is in a variable instead of a config so that it can be used in
754 # both chromium_code and no_chromium_code. This way these flags are guaranteed
755 # to appear on the compile command line after -Wall.
757 default_warning_flags = []
758 default_warning_flags_cc = []
760 default_warning_flags += [
761 # Treat warnings as errors.
764 # Warnings permanently disabled:
766 # C4127: conditional expression is constant
767 # This warning can in theory catch dead code and other problems, but
768 # triggers in far too many desirable cases where the conditional
769 # expression is either set by macros or corresponds some legitimate
770 # compile-time constant expression (due to constant template args,
771 # conditionals comparing the sizes of different types, etc.). Some of
772 # these can be worked around, but it's not worth it.
775 # C4251: 'identifier' : class 'type' needs to have dll-interface to be
776 # used by clients of class 'type2'
777 # This is necessary for the shared library build.
780 # C4351: new behavior: elements of array 'array' will be default
782 # This is a silly "warning" that basically just alerts you that the
783 # compiler is going to actually follow the language spec like it's
784 # supposed to, instead of not following it like old buggy versions did.
785 # There's absolutely no reason to turn this on.
788 # C4355: 'this': used in base member initializer list
789 # It's commonly useful to pass |this| to objects in a class' initializer
790 # list. While this warning can catch real bugs, most of the time the
791 # constructors in question don't attempt to call methods on the passed-in
792 # pointer (until later), and annotating every legit usage of this is
793 # simply more hassle than the warning is worth.
796 # C4503: 'identifier': decorated name length exceeded, name was
798 # This only means that some long error messages might have truncated
799 # identifiers in the presence of lots of templates. It has no effect on
800 # program correctness and there's no real reason to waste time trying to
804 # Warning C4589 says: "Constructor of abstract class ignores
805 # initializer for virtual base class." Disable this warning because it
806 # is flaky in VS 2015 RTM. It triggers on compiler generated
807 # copy-constructors in some cases.
810 # C4611: interaction between 'function' and C++ object destruction is
812 # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN
813 # suggests using exceptions instead of setjmp/longjmp for C++, but
814 # Chromium code compiles without exception support. We therefore have to
815 # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
816 # have to turn off this warning (and be careful about how object
817 # destruction happens in such cases).
820 # Warnings to evaluate and possibly fix/reenable later:
822 "/wd4100", # Unreferenced formal function parameter.
823 "/wd4121", # Alignment of a member was sensitive to packing.
824 "/wd4244", # Conversion: possible loss of data.
825 "/wd4481", # Nonstandard extension: override specifier.
826 "/wd4505", # Unreferenced local function has been removed.
827 "/wd4510", # Default constructor could not be generated.
828 "/wd4512", # Assignment operator could not be generated.
829 "/wd4610", # Class can never be instantiated, constructor required.
830 "/wd4995", # 'X': name was marked as #pragma deprecated
831 "/wd4996", # Deprecated function warning.
834 # VS xtree header file needs to be patched or 4702 (unreachable code
835 # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is
837 if (!msvs_xtree_patched &&
838 exec_script("../../win_is_xtree_patched.py", [], "value") == 0) {
839 default_warning_flags += [ "/wd4702" ] # Unreachable code.
842 # Building with Clang on Windows is a work in progress and very
843 # experimental. See crbug.com/82385.
844 # Keep this in sync with the similar block in build/common.gypi
846 default_warning_flags += [
847 # TODO(hans): Make this list shorter eventually, http://crbug.com/504657
848 "-Qunused-arguments", # http://crbug.com/504658
849 "-Wno-microsoft", # http://crbug.com/505296
850 "-Wno-switch", # http://crbug.com/505308
851 "-Wno-unknown-pragmas", # http://crbug.com/505314
852 "-Wno-unused-value", # http://crbug.com/505318
856 # Common GCC warning setup.
857 default_warning_flags += [
859 "-Wendif-labels", # Weird old-style text after an #endif.
860 "-Werror", # Warnings as errors.
863 "-Wno-missing-field-initializers", # "struct foo f = {0};"
864 "-Wno-unused-parameter", # Unused function parameters.
868 default_warning_flags += [ "-Wnewline-eof" ]
870 # When compiling Objective-C, warns if a method is used whose
871 # availability is newer than the deployment target. This is not
872 # required when compiling Chrome for iOS.
873 default_warning_flags += [ "-Wpartial-availability" ]
877 if (gcc_version >= 48) {
878 default_warning_flags_cc += [
879 # See comment for -Wno-c++11-narrowing.
883 default_warning_flags_cc += [
884 # TODO(thakis): Remove, http://crbug.com/263960
885 "-Wno-literal-suffix",
890 # Suppress warnings about ABI changes on ARM (Clang doesn't give this
892 if (current_cpu == "arm" && !is_clang) {
893 default_warning_flags += [ "-Wno-psabi" ]
897 # Disable any additional warnings enabled by the Android build system but
898 # which chromium does not build cleanly with (when treating warning as
900 default_warning_flags += [
902 "-Wno-ignored-qualifiers",
905 default_warning_flags_cc += [
906 # Disabling c++0x-compat should be handled in WebKit, but
907 # this currently doesn't work because gcc_version is not set
908 # correctly when building with the Android build system.
909 # TODO(torne): Fix this in WebKit.
910 "-Wno-error=c++0x-compat",
912 # Other things unrelated to -Wextra:
913 "-Wno-non-virtual-dtor",
918 if (gcc_version >= 48) {
919 # Don't warn about the "typedef 'foo' locally defined but not used"
921 # TODO: remove this flag once all builds work. See crbug.com/227506
922 default_warning_flags += [ "-Wno-unused-local-typedefs" ]
926 default_warning_flags += [
927 # This warns on using ints as initializers for floats in
928 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
929 # which happens in several places in chrome code. Not sure if
930 # this is worth fixing.
931 "-Wno-c++11-narrowing",
933 # Don't die on dtoa code that uses a char as an array index.
934 # This is required solely for base/third_party/dmg_fp/dtoa.cc.
935 # TODO(brettw) move this to that project then!
936 "-Wno-char-subscripts",
938 # Warns on switches on enums that cover all enum values but
939 # also contain a default: branch. Chrome is full of that.
940 "-Wno-covered-switch-default",
942 # Clang considers the `register` keyword as deprecated, but e.g.
943 # code generated by flex (used in angle) contains that keyword.
944 # http://crbug.com/255186
945 "-Wno-deprecated-register",
947 # TODO(thakis): This used to be implied by -Wno-unused-function,
948 # which we no longer use. Check if it makes sense to remove
949 # this as well. http://crbug.com/316352
950 "-Wno-unneeded-internal-declaration",
952 # TODO(thakis): Remove, http://crbug.com/263960
953 "-Wno-reserved-user-defined-literal",
956 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost
957 # always have different versions. Certain flags may not be recognized by
958 # one version or the other.
960 # Flags NaCl does not recognize.
961 default_warning_flags += [
962 # TODO(hans): Get this cleaned up, http://crbug.com/428099
963 "-Wno-inconsistent-missing-override",
965 # TODO(thakis): Enable this, crbug.com/507717
966 "-Wno-shift-negative-value",
971 # chromium_code ---------------------------------------------------------------
973 # Toggles between higher and lower warnings for code that is (or isn't)
976 config("chromium_code") {
978 cflags = [ "/W4" ] # Warning level 4.
983 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
984 # so we specify it explicitly.
985 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
986 # http://code.google.com/p/chromium/issues/detail?id=90453
990 # In Chromium code, we define __STDC_foo_MACROS in order to get the
991 # C99 macros on Mac and Linux.
993 "__STDC_CONSTANT_MACROS",
994 "__STDC_FORMAT_MACROS",
997 if (!using_sanitizer && (!is_linux || !is_clang || is_official_build)) {
998 # _FORTIFY_SOURCE isn't really supported by Clang now, see
999 # http://llvm.org/bugs/show_bug.cgi?id=16821.
1000 # It seems to work fine with Ubuntu 12 headers though, so use it in
1003 # Non-chromium code is not guaranteed to compile cleanly with
1004 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are
1005 # disabled, so only do that for Release build.
1006 defines += [ "_FORTIFY_SOURCE=2" ]
1009 cflags += default_warning_flags
1010 cflags_cc = default_warning_flags_cc
1012 config("no_chromium_code") {
1019 "/W3", # Warning level 3.
1020 "/wd4800", # Disable warning when forcing value to bool.
1021 "/wd4267", # TODO(jschuh): size_t to int.
1022 "/wd4996", # Deprecated function warning.
1025 "_CRT_NONSTDC_NO_WARNINGS",
1026 "_CRT_NONSTDC_NO_DEPRECATE",
1031 # Don't warn about ignoring the return value from e.g. close(). This is
1032 # off by default in some gccs but on by default in others. BSD systems do
1033 # not support this option, since they are usually using gcc 4.2.1, which
1034 # does not have this flag yet.
1035 cflags += [ "-Wno-unused-result" ]
1040 # TODO(mgiuca): Move this suppression into individual third-party
1041 # libraries as required. http://crbug.com/505301.
1042 "-Wno-overloaded-virtual",
1044 # TODO(thakis): Move this suppression into individual third-party
1045 # libraries as required. http://crbug.com/505316.
1046 "-Wno-unused-function",
1048 # Lots of third-party libraries have unused variables. Instead of
1049 # suppressing them individually, we just blanket suppress them here.
1050 "-Wno-unused-variable",
1054 if (is_linux || is_android) {
1056 # Don't warn about printf format problems. This is off by default in gcc
1057 # but on in Ubuntu's gcc(!).
1061 # Don't warn about hash_map in third-party code.
1065 cflags += default_warning_flags
1066 cflags_cc += default_warning_flags_cc
1069 # rtti ------------------------------------------------------------------------
1071 # Allows turning Run-Time Type Identification on or off.
1075 cflags_cc = [ "/GR" ]
1080 cflags_cc = [ "/GR-" ]
1082 cflags_cc = [ "-fno-rtti" ]
1083 cflags_objcc = cflags_cc
1087 # Warnings ---------------------------------------------------------------------
1089 # This will generate warnings when using Clang if code generates exit-time
1090 # destructors, which will slow down closing the program.
1091 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
1092 config("wexit_time_destructors") {
1093 # TODO: Enable on Windows too, http://crbug.com/404525
1094 if (is_clang && !is_win) {
1095 cflags = [ "-Wexit-time-destructors" ]
1099 # On Windows compiling on x64, VC will issue a warning when converting
1100 # size_t to int because it will truncate the value. Our code should not have
1101 # these warnings and one should use a static_cast or a checked_cast for the
1102 # conversion depending on the case. However, a lot of code still needs to be
1103 # fixed. Apply this config to such targets to disable the warning.
1105 # Note that this can be applied regardless of platform and architecture to
1106 # clean up the call sites. This will only apply the flag when necessary.
1108 # TODO(jschuh): crbug.com/167187 fix this and delete this config.
1109 config("no_size_t_to_int_warning") {
1110 if (is_win && current_cpu == "x64") {
1111 cflags = [ "/wd4267" ]
1115 # Some code presumes that pointers to structures/objects are compatible
1116 # regardless of whether what they point to is already known to be valid.
1117 # gcc 4.9 and earlier had no way of suppressing this warning without
1118 # supressing the rest of them. Here we centralize the identification of
1119 # the gcc 4.9 toolchains.
1120 config("no_incompatible_pointer_warnings") {
1123 cflags += [ "-Wno-incompatible-pointer-types" ]
1124 } else if (current_cpu == "mipsel") {
1126 } else if (is_chromeos && current_cpu == "arm") {
1131 # Optimization -----------------------------------------------------------------
1133 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"
1134 # which it will assign to the config it implicitly applies to every target. If
1135 # you want to override the optimization level for your target, remove this
1136 # config (which will expand differently for debug or release builds), and then
1137 # add back the one you want to override it with:
1139 # configs -= default_optimization_config
1140 # configs += [ "//build/config/compiler/optimize_max" ]
1142 # Shared settings for both "optimize" and "optimize_max" configs.
1143 # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags.
1145 common_optimize_on_cflags = [
1146 "/Ob2", # Both explicit and auto inlining.
1147 "/Oy-", # Disable omitting frame pointers, must be after /O2.
1150 common_optimize_on_cflags += [
1151 # Put data in separate COMDATs. This allows the linker
1152 # to put bit-identical constants at the same address even if
1153 # they're unrelated constants, which saves binary size.
1154 # This optimization can't be used when ASan is enabled because
1155 # it is not compatible with the ASan ODR checker.
1159 common_optimize_on_ldflags = [ "/OPT:REF" ]
1161 common_optimize_on_cflags = [
1162 # Don't emit the GCC version ident directives, they just end up in the
1163 # .comment section taking up binary size.
1166 # Put data and code in their own sections, so that unused symbols
1167 # can be removed at link time with --gc-sections.
1169 "-ffunction-sections",
1171 common_optimize_on_ldflags = []
1174 if (!using_sanitizer) {
1175 common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
1178 # TODO(jdduke) Re-enable on mips after resolving linking
1179 # issues with libc++ (crbug.com/456380).
1180 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
1181 common_optimize_on_ldflags += [
1182 # Warn in case of text relocations.
1183 "-Wl,--warn-shared-textrel",
1188 if (is_mac || is_ios) {
1189 if (symbol_level == 2) {
1190 # Mac dead code stripping requires symbols.
1191 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ]
1194 # Non-Mac Posix linker flags.
1195 common_optimize_on_ldflags += [
1196 # Specifically tell the linker to perform optimizations.
1197 # See http://lwn.net/Articles/192624/ .
1199 "-Wl,--gc-sections",
1202 if (!using_sanitizer) {
1203 # Functions interposed by the sanitizers can make ld think
1204 # that some libraries aren't needed when they actually are,
1205 # http://crbug.com/234010. As workaround, disable --as-needed.
1206 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
1211 # Default "optimization on" config. On Windows, this favors size over speed.
1212 config("optimize") {
1214 # Favor size over speed, /O1 must be before the common flags. The GYP
1215 # build also specifies /Os and /GF but these are implied by /O1.
1216 cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
1217 } else if (is_android || is_ios) {
1218 cflags = [ "-Os" ] + common_optimize_on_cflags # Favor size over speed.
1220 cflags = [ "-O2" ] + common_optimize_on_cflags
1222 ldflags = common_optimize_on_ldflags
1225 # Turn off optimizations.
1226 config("no_optimize") {
1229 "/Od", # Disable optimization.
1230 "/Ob0", # Disable all inlining (on by default).
1231 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
1233 } else if (is_android && !android_full_debug) {
1234 # On Android we kind of optimize some things that don't affect debugging
1235 # much even when optimization is disabled to get the binary size down.
1239 "-ffunction-sections",
1241 if (!using_sanitizer) {
1242 cflags += [ "-fomit-frame-pointer" ]
1244 ldflags = common_optimize_on_ldflags
1250 # Turns up the optimization level. On Windows, this implies whole program
1251 # optimization and link-time code generation which is very expensive and should
1252 # be used sparingly.
1253 config("optimize_max") {
1254 ldflags = common_optimize_on_ldflags
1256 # Favor speed over size, /O2 must be before the common flags. The GYP
1257 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2.
1258 cflags = [ "/O2" ] + common_optimize_on_cflags
1259 if (is_official_build) {
1260 # TODO(GYP): TODO(dpranke): Should these only be on in an official
1261 # build, or on all the time? For now we'll require official build so
1262 # that the compile is clean.
1264 "/GL", # Whole program optimization.
1266 # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds.
1267 # Probably anything that this would catch that wouldn't be caught in a
1268 # normal build isn't going to actually be a bug, so the incremental
1269 # value of C4702 for PGO builds is likely very small.
1272 ldflags += [ "/LTCG" ]
1275 cflags = [ "-O2" ] + common_optimize_on_cflags
1279 # Symbols ----------------------------------------------------------------------
1283 import("//build/toolchain/goma.gni")
1285 cflags = [ "/Z7" ] # No PDB file
1287 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
1289 if (is_win_fastlink) {
1290 # Tell VS 2015+ to create a PDB that references debug
1291 # information in .obj and .lib files instead of copying
1292 # it all. This flag is incompatible with /PROFILE
1293 ldflags = [ "/DEBUG:FASTLINK" ]
1295 ldflags = [ "/DEBUG" ]
1299 if (use_debug_fission) {
1300 cflags += [ "-gsplit-dwarf" ]
1305 config("minimal_symbols") {
1307 # Linker symbols for backtraces only.
1308 if (is_win_fastlink) {
1309 # Tell VS 2015+ to create a PDB that references debug
1310 # information in .obj and .lib files instead of copying
1311 # it all. This flag is incompatible with /PROFILE
1312 ldflags = [ "/DEBUG:FASTLINK" ]
1314 ldflags = [ "/DEBUG" ]
1318 if (use_debug_fission) {
1319 cflags += [ "-gsplit-dwarf" ]
1324 config("no_symbols") {