| # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("//build/config/android/config.gni") |
| import("//build/config/chrome_build.gni") |
| if (current_cpu == "arm") { |
| import("//build/config/arm.gni") |
| } |
| if (current_cpu == "mipsel" || current_cpu == "mips64el") { |
| import("//build/config/mips.gni") |
| } |
| if (is_posix) { |
| import("//build/config/gcc/gcc_version.gni") |
| } |
| import("//build/config/nacl/config.gni") |
| import("//build/toolchain/ccache.gni") |
| import("//build/config/sanitizers/sanitizers.gni") |
| |
| declare_args() { |
| # Normally, Android builds are lightly optimized, even for debug builds, to |
| # keep binary size down. Setting this flag to true disables such optimization |
| android_full_debug = false |
| |
| # Whether to use the binary binutils checked into third_party/binutils. |
| # These are not multi-arch so cannot be used except on x86 and x86-64 (the |
| # only two architectures that are currently checked in). Turn this off when |
| # you are using a custom toolchain and need to control -B in cflags. |
| linux_use_bundled_binutils = is_linux && current_cpu == "x64" |
| |
| # Compile in such a way as to enable profiling of the generated code. For |
| # example, don't omit the frame pointer and leave in symbols. |
| enable_profiling = false |
| |
| # Compile in such a way as to make it possible for the profiler to unwind full |
| # stack frames. Setting this flag has a large effect on the performance of the |
| # generated code than just setting profiling, but gives the profiler more |
| # information to analyze. |
| # Requires profiling to be set to true. |
| enable_full_stack_frames_for_profiling = false |
| |
| # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of |
| # address space, and it doesn't support cross-compiling). |
| use_gold = is_linux && current_cpu == "x64" |
| |
| # use_debug_fission: whether to use split DWARF debug info |
| # files. This can reduce link time significantly, but is incompatible |
| # with some utilities such as icecc and ccache. Requires gold and |
| # gcc >= 4.8 or clang. |
| # http://gcc.gnu.org/wiki/DebugFission |
| use_debug_fission = use_gold && linux_use_bundled_binutils && !use_ccache |
| } |
| |
| # default_include_dirs --------------------------------------------------------- |
| # |
| # This is a separate config so that third_party code (which would not use the |
| # source root and might have conflicting versions of some headers) can remove |
| # this and specify their own include paths. |
| config("default_include_dirs") { |
| include_dirs = [ |
| "//", |
| root_gen_dir, |
| ] |
| } |
| |
| # TODO(GYP): is_ubsan, is_ubsan_vptr |
| using_sanitizer = is_asan || is_lsan || is_tsan || is_msan |
| |
| # compiler --------------------------------------------------------------------- |
| # |
| # Base compiler configuration. |
| # |
| # See also "runtime_library" below for related stuff and a discussion about |
| # where stuff should go. Put warning related stuff in the "warnings" config. |
| |
| config("compiler") { |
| asmflags = [] |
| cflags = [] |
| cflags_c = [] |
| cflags_cc = [] |
| ldflags = [] |
| defines = [] |
| |
| # Common GCC compiler flags setup. |
| # -------------------------------- |
| cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204 |
| cflags_cc += [ |
| # Not exporting C++ inline functions can generally be applied anywhere |
| # so we do so here. Normal function visibility is controlled by |
| # //build/config/gcc:symbol_visibility_hidden. |
| "-fvisibility-inlines-hidden", |
| ] |
| |
| # Stack protection. |
| if (is_mac) { |
| cflags += [ "-fstack-protector-all" ] |
| } else if (is_linux) { |
| cflags += [ |
| "-fstack-protector", |
| "--param=ssp-buffer-size=4", |
| ] |
| } |
| |
| # Linker warnings. |
| if (!is_mac && !is_ios) { |
| ldflags += [ "-Wl,--fatal-warnings" ] |
| } |
| |
| # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and |
| # MemorySanitizer |
| if (using_sanitizer) { |
| cflags += [ |
| "-fno-omit-frame-pointer", |
| "-gline-tables-only", |
| ] |
| } |
| if (is_asan) { |
| asan_blacklist_path = |
| rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir) |
| cflags += [ |
| "-fsanitize=address", |
| "-fsanitize-blacklist=$asan_blacklist_path", |
| ] |
| if (is_mac) { |
| cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073 |
| # TODO(GYP): deal with mac_bundles. |
| } |
| } |
| if (is_lsan) { |
| cflags += [ "-fsanitize=leak" ] |
| } |
| if (is_tsan) { |
| tsan_blacklist_path = |
| rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir) |
| cflags += [ |
| "-fsanitize=thread", |
| "-fsanitize-blacklist=$tsan_blacklist_path", |
| ] |
| } |
| if (is_msan) { |
| msan_blacklist_path = |
| rebase_path("//tools/msan/blacklist.txt", root_build_dir) |
| cflags += [ |
| "-fsanitize=memory", |
| "-fsanitize-memory-track-origins=$msan_track_origins", |
| "-fsanitize-blacklist=$msan_blacklist_path", |
| ] |
| } |
| |
| if (use_custom_libcxx) { |
| cflags_cc += [ "-nostdinc++" ] |
| include_dirs = [ |
| "//buildtools/third_party/libc++/trunk/include", |
| "//buildtools/third_party/libc++abi/trunk/include", |
| ] |
| } |
| |
| if (is_clang && is_debug) { |
| # Allow comparing the address of references and 'this' against 0 |
| # in debug builds. Technically, these can never be null in |
| # well-defined C/C++ and Clang can optimize such checks away in |
| # release builds, but they may be used in asserts in debug builds. |
| cflags_cc += [ |
| "-Wno-undefined-bool-conversion", |
| "-Wno-tautological-undefined-compare", |
| ] |
| } |
| |
| if (is_clang && !is_nacl) { |
| # This is here so that all files get recompiled after a clang roll and |
| # when turning clang on or off. (defines are passed via the command line, |
| # and build system rebuild things when their commandline changes). Nothing |
| # should ever read this define. |
| defines += |
| [ "CR_CLANG_REVISION=" + exec_script("//tools/clang/scripts/update.py", |
| [ "--print-revision" ], |
| "trim string") ] |
| } |
| |
| # Mac-specific compiler flags setup. |
| # ---------------------------------- |
| if (is_mac || is_ios) { |
| # These flags are shared between the C compiler and linker. |
| common_mac_flags = [] |
| |
| # CPU architecture. |
| if (current_cpu == "x64") { |
| common_mac_flags += [ |
| "-arch", |
| "x86_64", |
| ] |
| } else if (current_cpu == "x86") { |
| common_mac_flags += [ |
| "-arch", |
| "i386", |
| ] |
| } else if (current_cpu == "arm") { |
| common_mac_flags += [ |
| "-arch", |
| "armv7", |
| ] |
| } |
| |
| cflags += common_mac_flags |
| |
| # Without this, the constructors and destructors of a C++ object inside |
| # an Objective C struct won't be called, which is very bad. |
| cflags_objcc = [ "-fobjc-call-cxx-cdtors" ] |
| |
| cflags_c += [ "-std=c99" ] |
| |
| ldflags += common_mac_flags |
| } else if (is_posix) { |
| # Non-Mac Posix compiler flags setup. |
| # ----------------------------------- |
| if (enable_profiling && !is_debug) { |
| # The GYP build spams this define into every compilation unit, as we do |
| # here, but it only appears to be used in base and a couple other places. |
| # TODO(abarth): Should we move this define closer to where it's used? |
| defines += [ "ENABLE_PROFILING" ] |
| |
| cflags += [ |
| "-fno-omit-frame-pointer", |
| "-g", |
| ] |
| |
| if (enable_full_stack_frames_for_profiling) { |
| cflags += [ |
| "-fno-inline", |
| "-fno-optimize-sibling-calls", |
| ] |
| } |
| } |
| |
| # CPU architecture. We may or may not be doing a cross compile now, so for |
| # simplicity we always explicitly set the architecture. |
| if (current_cpu == "x64") { |
| cflags += [ |
| "-m64", |
| "-march=x86-64", |
| ] |
| ldflags += [ "-m64" ] |
| } else if (current_cpu == "x86") { |
| cflags += [ "-m32" ] |
| ldflags += [ "-m32" ] |
| if (is_clang) { |
| cflags += [ |
| # Else building libyuv gives clang's register allocator issues, |
| # see llvm.org/PR15798 / crbug.com/233709 |
| "-momit-leaf-frame-pointer", |
| |
| # Align the stack on 16-byte boundaries, http://crbug.com/418554. |
| "-mstack-alignment=16", |
| "-mstackrealign", |
| ] |
| } |
| } else if (current_cpu == "arm") { |
| cflags += [ |
| "-march=$arm_arch", |
| "-mfloat-abi=$arm_float_abi", |
| ] |
| if (arm_tune != "") { |
| cflags += [ "-mtune=$arm_tune" ] |
| } |
| if (arm_use_thumb) { |
| cflags += [ "-mthumb" ] |
| if (is_android && !is_clang) { # Clang doesn't support this option. |
| cflags += [ "-mthumb-interwork" ] |
| } |
| } |
| if (!is_clang) { |
| # Clang doesn't support these flags. |
| cflags += [ |
| # The tree-sra optimization (scalar replacement for |
| # aggregates enabling subsequent optimizations) leads to |
| # invalid code generation when using the Android NDK's |
| # compiler (r5-r7). This can be verified using |
| # webkit_unit_tests' WTF.Checked_int8_t test. |
| "-fno-tree-sra", |
| |
| # The following option is disabled to improve binary |
| # size and performance in gcc 4.9. |
| "-fno-caller-saves", |
| ] |
| } |
| } else if (current_cpu == "mipsel") { |
| if (mips_arch_variant == "r6") { |
| cflags += [ |
| "-mips32r6", |
| "-Wa,-mips32r6", |
| ] |
| if (is_android) { |
| ldflags += [ |
| "-mips32r6", |
| "-Wl,-melf32ltsmip", |
| ] |
| } |
| } else if (mips_arch_variant == "r2") { |
| cflags += [ |
| "-mips32r2", |
| "-Wa,-mips32r2", |
| ] |
| if (mips_float_abi == "hard" && mips_fpu_mode != "") { |
| cflags += [ "-m$mips_fpu_mode" ] |
| } |
| } else if (mips_arch_variant == "r1") { |
| cflags += [ |
| "-mips32", |
| "-Wa,-mips32", |
| ] |
| } |
| |
| if (mips_dsp_rev == 1) { |
| cflags += [ "-mdsp" ] |
| } else if (mips_dsp_rev == 2) { |
| cflags += [ "-mdspr2" ] |
| } |
| |
| cflags += [ "-m${mips_float_abi}-float" ] |
| } else if (current_cpu == "mips64el") { |
| if (mips_arch_variant == "r6") { |
| cflags += [ |
| "-mips64r6", |
| "-Wa,-mips64r6", |
| ] |
| ldflags += [ "-mips64r6" ] |
| } else if (mips_arch_variant == "r2") { |
| cflags += [ |
| "-mips64r2", |
| "-Wa,-mips64r2", |
| ] |
| ldflags += [ "-mips64r2" ] |
| } |
| } |
| |
| defines += [ "_FILE_OFFSET_BITS=64" ] |
| |
| if (!is_android) { |
| defines += [ |
| "_LARGEFILE_SOURCE", |
| "_LARGEFILE64_SOURCE", |
| ] |
| } |
| |
| # Omit unwind support in official builds to save space. We can use breakpad |
| # for these builds. |
| if (is_chrome_branded && is_official_build) { |
| cflags += [ |
| "-fno-unwind-tables", |
| "-fno-asynchronous-unwind-tables", |
| ] |
| defines += [ "NO_UNWIND_TABLES" ] |
| } else { |
| cflags += [ "-funwind-tables" ] |
| } |
| |
| if (is_clang && !is_nacl && !is_debug) { |
| # Non-unique section names appears to make linker dead stripping |
| # less effective. See http://crbug.com/483026#c20 |
| # TODO(hans): Remove this if resolved upstream. |
| cflags += [ "-funique-section-names" ] |
| } |
| } |
| |
| # Linux/Android common flags setup. |
| # --------------------------------- |
| if (is_linux || is_android) { |
| cflags += [ |
| "-fPIC", |
| "-pipe", # Use pipes for communicating between sub-processes. Faster. |
| ] |
| |
| ldflags += [ |
| "-fPIC", |
| "-Wl,-z,noexecstack", |
| "-Wl,-z,now", |
| "-Wl,-z,relro", |
| ] |
| if (!using_sanitizer) { |
| ldflags += [ "-Wl,-z,defs" ] |
| } |
| } |
| |
| # Linux-specific compiler flags setup. |
| # ------------------------------------ |
| if (is_linux) { |
| cflags += [ "-pthread" ] |
| ldflags += [ "-pthread" ] |
| } |
| if (use_gold) { |
| gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", |
| root_build_dir) |
| ldflags += [ |
| "-B$gold_path", |
| |
| # Newer gccs and clangs support -fuse-ld, use the flag to force gold |
| # selection. |
| # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html |
| "-fuse-ld=gold", |
| |
| # Experimentation found that using four linking threads |
| # saved ~20% of link time. |
| # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36 |
| # Only apply this to the target linker, since the host |
| # linker might not be gold, but isn't used much anyway. |
| # TODO(raymes): Disable threading because gold is frequently |
| # crashing on the bots: crbug.com/161942. |
| #"-Wl,--threads", |
| #"-Wl,--thread-count=4", |
| ] |
| |
| if (!is_asan && !is_msan && !is_lsan && !is_tsan) { |
| # TODO(brettw) common.gypi has this only for target toolset. |
| if (current_cpu == "x64") { |
| # --icf=safe disables much more folding on x86_64 than elsewhere, see |
| # http://crbug.com/492177. Turning it on saves over 12 MB of binary |
| # size, but it seems to regress cold startup time by over a second |
| # (see http://crbug.com/492809). |
| # TODO(thakis): Check if disabling ICF would inmprove android cold start |
| # times by several seconds too. |
| ldflags += [ "-Wl,--icf=safe" ] |
| } else { |
| ldflags += [ "-Wl,--icf=all" ] |
| } |
| } |
| } |
| |
| if (linux_use_bundled_binutils) { |
| binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", |
| root_build_dir) |
| cflags += [ "-B$binutils_path" ] |
| } |
| |
| # Clang-specific compiler flags setup. |
| # ------------------------------------ |
| if (is_clang) { |
| cflags += [ "-fcolor-diagnostics" ] |
| } |
| |
| # C++11 compiler flags setup. |
| # --------------------------- |
| if (is_nacl) { |
| # gnu++11 instead of c++11 is needed because some code uses typeof() (a |
| # GNU extension). |
| # TODO(thakis): Eventually switch this to c++11 instead, |
| # http://crbug.com/427584 |
| cflags_cc += [ "-std=gnu++11" ] |
| } else { |
| cflags_cc += [ "-std=c++11" ] |
| } |
| |
| # Android-specific flags setup. |
| # ----------------------------- |
| if (is_android) { |
| cflags += [ |
| "-ffunction-sections", |
| "-funwind-tables", |
| "-fno-short-enums", |
| ] |
| if (!is_clang) { |
| # Clang doesn't support these flags. |
| cflags += [ "-finline-limit=64" ] |
| } |
| if (is_asan) { |
| # Android build relies on -Wl,--gc-sections removing unreachable code. |
| # ASan instrumentation for globals inhibits this and results in a library |
| # with unresolvable relocations. |
| # TODO(eugenis): find a way to reenable this. |
| cflags += [ "-mllvm -asan-globals=0" ] |
| } |
| |
| defines += [ "ANDROID" ] |
| |
| # The NDK has these things, but doesn't define the constants |
| # to say that it does. Define them here instead. |
| defines += [ "HAVE_SYS_UIO_H" ] |
| |
| # Use gold for Android for most CPU architectures. |
| if (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm") { |
| ldflags += [ "-fuse-ld=gold" ] |
| if (is_clang) { |
| # Let clang find the ld.gold in the NDK. |
| ldflags += [ "--gcc-toolchain=" + |
| rebase_path(android_toolchain_root, root_build_dir) ] |
| } |
| } |
| |
| ldflags += [ |
| "-Wl,--no-undefined", |
| |
| # Don't allow visible symbols from libgcc or libc++ to be |
| # re-exported. |
| "-Wl,--exclude-libs=libgcc.a", |
| "-Wl,--exclude-libs=libc++_static.a", |
| |
| # Don't allow visible symbols from libraries that contain |
| # assembly code with symbols that aren't hidden properly. |
| # http://crbug.com/448386 |
| "-Wl,--exclude-libs=libvpx_assembly_arm.a", |
| ] |
| if (current_cpu == "arm") { |
| ldflags += [ |
| # Enable identical code folding to reduce size. |
| "-Wl,--icf=safe", |
| ] |
| } |
| |
| if (is_clang) { |
| if (current_cpu == "arm") { |
| cflags += [ "-target arm-linux-androideabi" ] |
| ldflags += [ "-target arm-linux-androideabi" ] |
| } else if (current_cpu == "x86") { |
| cflags += [ "-target x86-linux-androideabi" ] |
| ldflags += [ "-target x86-linux-androideabi" ] |
| } |
| } |
| } |
| |
| # Assign any flags set for the C compiler to asmflags so that they are sent |
| # to the assembler. |
| asmflags += cflags |
| asmflags += cflags_c |
| } |
| |
| # This provides the basic options to select the target CPU and ABI. |
| # It is factored out of "compiler" so that special cases can use this |
| # without using everything that "compiler" brings in. Options that |
| # tweak code generation for a particular CPU do not belong here! |
| # See "compiler_codegen", below. |
| config("compiler_cpu_abi") { |
| cflags = [] |
| ldflags = [] |
| |
| if (is_posix && !(is_mac || is_ios)) { |
| # CPU architecture. We may or may not be doing a cross compile now, so for |
| # simplicity we always explicitly set the architecture. |
| if (current_cpu == "x64") { |
| cflags += [ |
| "-m64", |
| "-march=x86-64", |
| ] |
| ldflags += [ "-m64" ] |
| } else if (current_cpu == "x86") { |
| cflags += [ "-m32" ] |
| ldflags += [ "-m32" ] |
| } else if (current_cpu == "arm") { |
| if (is_clang && !is_android && !is_nacl) { |
| cflags += [ |
| "-target", |
| "arm-linux-gnueabihf", |
| ] |
| ldflags += [ |
| "-target", |
| "arm-linux-gnueabihf", |
| ] |
| } |
| if (!is_nacl) { |
| cflags += [ |
| "-march=$arm_arch", |
| "-mfloat-abi=$arm_float_abi", |
| ] |
| if (arm_use_thumb) { |
| cflags += [ "-mthumb" ] |
| if (is_android && !is_clang) { |
| # Clang doesn't support this option. |
| cflags += [ "-mthumb-interwork" ] |
| } |
| } |
| } |
| if (arm_tune != "") { |
| cflags += [ "-mtune=$arm_tune" ] |
| } |
| } else if (current_cpu == "mipsel") { |
| if (mips_arch_variant == "r6") { |
| cflags += [ |
| "-mips32r6", |
| "-Wa,-mips32r6", |
| ] |
| if (is_android) { |
| ldflags += [ |
| "-mips32r6", |
| "-Wl,-melf32ltsmip", |
| ] |
| } |
| } else if (mips_arch_variant == "r2") { |
| cflags += [ |
| "-mips32r2", |
| "-Wa,-mips32r2", |
| ] |
| if (mips_float_abi == "hard" && mips_fpu_mode != "") { |
| cflags += [ "-m$mips_fpu_mode" ] |
| } |
| } else if (mips_arch_variant == "r1") { |
| cflags += [ |
| "-mips32", |
| "-Wa,-mips32", |
| ] |
| } |
| |
| if (mips_dsp_rev == 1) { |
| cflags += [ "-mdsp" ] |
| } else if (mips_dsp_rev == 2) { |
| cflags += [ "-mdspr2" ] |
| } |
| |
| cflags += [ "-m${mips_float_abi}-float" ] |
| } else if (current_cpu == "mips64el") { |
| if (mips_arch_variant == "r6") { |
| cflags += [ |
| "-mips64r6", |
| "-Wa,-mips64r6", |
| ] |
| ldflags += [ "-mips64r6" ] |
| } else if (mips_arch_variant == "r2") { |
| cflags += [ |
| "-mips64r2", |
| "-Wa,-mips64r2", |
| ] |
| ldflags += [ "-mips64r2" ] |
| } |
| } |
| } |
| |
| asmflags = cflags |
| } |
| |
| config("compiler_arm_fpu") { |
| if (current_cpu == "arm" && !is_ios) { |
| cflags = [ "-mfpu=$arm_fpu" ] |
| asmflags = cflags |
| } |
| } |
| |
| # runtime_library ------------------------------------------------------------- |
| # |
| # Sets the runtime library and associated options. |
| # |
| # How do you determine what should go in here vs. "compiler" above? Consider if |
| # a target might choose to use a different runtime library (ignore for a moment |
| # if this is possible or reasonable on your system). If such a target would want |
| # to change or remove your option, put it in the runtime_library config. If a |
| # target wants the option regardless, put it in the compiler config. |
| |
| config("runtime_library") { |
| cflags = [] |
| defines = [] |
| ldflags = [] |
| lib_dirs = [] |
| libs = [] |
| |
| if (is_component_build) { |
| # Component mode: dynamic CRT. |
| defines += [ "COMPONENT_BUILD" ] |
| } |
| |
| # Android standard library setup. |
| if (is_android) { |
| if (is_clang) { |
| # Work around incompatibilities between bionic and clang headers. |
| defines += [ |
| "__compiler_offsetof=__builtin_offsetof", |
| "nan=__builtin_nan", |
| ] |
| } |
| |
| defines += [ "__GNU_SOURCE=1" ] # Necessary for clone(). |
| |
| # TODO(jdduke) Re-enable on mips after resolving linking |
| # issues with libc++ (crbug.com/456380). |
| if (current_cpu != "mipsel" && current_cpu != "mips64el") { |
| ldflags += [ "-Wl,--warn-shared-textrel" ] |
| } |
| ldflags += [ "-nostdlib" ] |
| |
| # NOTE: The libc++ header include paths below are specified in cflags |
| # rather than include_dirs because they need to come after include_dirs. |
| # Think of them like system headers, but don't use '-isystem' because the |
| # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit |
| # strange errors. The include ordering here is important; change with |
| # caution. |
| android_libcpp_root = "$android_ndk_root/sources/cxx-stl/llvm-libc++" |
| |
| cflags += [ |
| "-isystem" + |
| rebase_path("$android_libcpp_root/libcxx/include", root_build_dir), |
| "-isystem" + rebase_path( |
| "$android_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/include", |
| root_build_dir), |
| "-isystem" + |
| rebase_path("$android_ndk_root/sources/android/support/include", |
| root_build_dir), |
| ] |
| |
| lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ] |
| |
| if (component_mode == "shared_library") { |
| android_libcpp_library = "c++_shared" |
| } else { |
| android_libcpp_library = "c++_static" |
| } |
| |
| libs += [ "$android_libcpp_library" ] |
| |
| if (current_cpu == "mipsel") { |
| libs += [ |
| # ld linker is used for mips Android, and ld does not accept library |
| # absolute path prefixed by "-l"; Since libgcc does not exist in mips |
| # sysroot the proper library will be linked. |
| # TODO(gordanac): Remove once gold linker is used for mips Android. |
| "gcc", |
| ] |
| } else { |
| libs += [ |
| # Manually link the libgcc.a that the cross compiler uses. This is |
| # absolute because the linker will look inside the sysroot if it's not. |
| rebase_path(android_libgcc_file), |
| ] |
| } |
| |
| libs += [ |
| "c", |
| "dl", |
| "m", |
| ] |
| |
| # Clang with libc++ does not require an explicit atomic library reference. |
| if (!is_clang) { |
| libs += [ "atomic" ] |
| } |
| } |
| } |
| |
| # default_warning_flags collects all warning flags that are used by default. |
| # This is in a variable instead of a config so that it can be used in |
| # both chromium_code and no_chromium_code. This way these flags are guaranteed |
| # to appear on the compile command line after -Wall. |
| |
| default_warning_flags = [] |
| default_warning_flags_cc = [] |
| |
| # Common GCC warning setup. |
| default_warning_flags += [ |
| # Enables. |
| "-Wendif-labels", # Weird old-style text after an #endif. |
| "-Werror", # Warnings as errors. |
| |
| # Disables. |
| "-Wno-missing-field-initializers", # "struct foo f = {0};" |
| ] |
| |
| if (is_mac) { |
| if (!is_nacl) { |
| # When compiling Objective-C, warns if a method is used whose |
| # availability is newer than the deployment target. This is not |
| # required when compiling Chrome for iOS. |
| default_warning_flags += [ "-Wpartial-availability" ] |
| } |
| } |
| |
| if (gcc_version >= 48) { |
| default_warning_flags_cc += [ |
| # See comment for -Wno-c++11-narrowing. |
| "-Wno-narrowing", |
| |
| # TODO(thakis): Remove, http://crbug.com/263960 |
| "-Wno-literal-suffix", |
| ] |
| } |
| |
| # Suppress warnings about ABI changes on ARM (Clang doesn't give this |
| # warning). |
| if (current_cpu == "arm" && !is_clang) { |
| default_warning_flags += [ "-Wno-psabi" ] |
| } |
| |
| if (is_android) { |
| # Disable any additional warnings enabled by the Android build system but |
| # which chromium does not build cleanly with (when treating warning as |
| # errors). |
| default_warning_flags += [ |
| "-Wno-extra", |
| "-Wno-ignored-qualifiers", |
| "-Wno-type-limits", |
| ] |
| default_warning_flags_cc += [ |
| # Disabling c++0x-compat should be handled in WebKit, but |
| # this currently doesn't work because gcc_version is not set |
| # correctly when building with the Android build system. |
| # TODO(torne): Fix this in WebKit. |
| "-Wno-error=c++0x-compat", |
| |
| # Other things unrelated to -Wextra: |
| "-Wno-non-virtual-dtor", |
| "-Wno-sign-promo", |
| ] |
| } |
| |
| if (gcc_version >= 48) { |
| # Don't warn about the "typedef 'foo' locally defined but not used" |
| # for gcc 4.8. |
| # TODO: remove this flag once all builds work. See crbug.com/227506 |
| default_warning_flags += [ "-Wno-unused-local-typedefs" ] |
| } |
| |
| if (is_clang) { |
| default_warning_flags += [ |
| # This warns on using ints as initializers for floats in |
| # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|), |
| # which happens in several places in chrome code. Not sure if |
| # this is worth fixing. |
| "-Wno-c++11-narrowing", |
| |
| # Don't die on dtoa code that uses a char as an array index. |
| # This is required solely for base/third_party/dmg_fp/dtoa.cc. |
| # TODO(brettw) move this to that project then! |
| "-Wno-char-subscripts", |
| |
| # Warns on switches on enums that cover all enum values but |
| # also contain a default: branch. Chrome is full of that. |
| "-Wno-covered-switch-default", |
| |
| # Clang considers the `register` keyword as deprecated, but e.g. |
| # code generated by flex (used in angle) contains that keyword. |
| # http://crbug.com/255186 |
| "-Wno-deprecated-register", |
| ] |
| |
| # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost |
| # always have different versions. Certain flags may not be recognized by |
| # one version or the other. |
| if (!is_nacl) { |
| # Flags NaCl (Clang 3.7) does not recognize. |
| default_warning_flags += [ |
| # TODO(smklein): Enable this, crbug.com/507717 |
| "-Wno-shift-negative-value", |
| ] |
| } |
| } |
| |
| # chromium_code --------------------------------------------------------------- |
| # |
| # Toggles between higher and lower warnings for code that is (or isn't) |
| # part of Chromium. |
| |
| config("chromium_code") { |
| cflags = [ |
| "-Wall", |
| |
| # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't, |
| # so we specify it explicitly. |
| # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it. |
| # http://code.google.com/p/chromium/issues/detail?id=90453 |
| "-Wsign-compare", |
| ] |
| |
| # In Chromium code, we define __STDC_foo_MACROS in order to get the |
| # C99 macros on Mac and Linux. |
| defines = [ |
| "__STDC_CONSTANT_MACROS", |
| "__STDC_FORMAT_MACROS", |
| ] |
| |
| if (!is_debug && !using_sanitizer && |
| (!is_linux || !is_clang || is_official_build)) { |
| # _FORTIFY_SOURCE isn't really supported by Clang now, see |
| # http://llvm.org/bugs/show_bug.cgi?id=16821. |
| # It seems to work fine with Ubuntu 12 headers though, so use it in |
| # official builds. |
| # |
| # Non-chromium code is not guaranteed to compile cleanly with |
| # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are |
| # disabled, so only do that for Release build. |
| defines += [ "_FORTIFY_SOURCE=2" ] |
| } |
| |
| cflags += default_warning_flags |
| cflags_cc = default_warning_flags_cc |
| } |
| config("no_chromium_code") { |
| cflags = [] |
| cflags_cc = [] |
| defines = [] |
| |
| if (is_linux) { |
| # Don't warn about ignoring the return value from e.g. close(). This is |
| # off by default in some gccs but on by default in others. BSD systems do |
| # not support this option, since they are usually using gcc 4.2.1, which |
| # does not have this flag yet. |
| cflags += [ |
| "-Wno-logical-not-parentheses", |
| "-Wno-unused-result", |
| ] |
| } |
| |
| if (is_linux || is_android) { |
| cflags += [ |
| # Don't warn about printf format problems. This is off by default in gcc |
| # but on in Ubuntu's gcc(!). |
| "-Wno-format", |
| ] |
| cflags_cc += [ |
| # Don't warn about hash_map in third-party code. |
| "-Wno-deprecated", |
| ] |
| } |
| |
| if (is_clang) { |
| cflags += [ |
| # TODO(hans): Get this cleaned up. |
| "-Wno-inconsistent-missing-override", |
| ] |
| } |
| |
| cflags += default_warning_flags |
| cflags_cc += default_warning_flags_cc |
| |
| if (is_clang) { |
| cflags += [ |
| # TODO(dalesat): Remove once not broken by third party (ffmpeg). |
| # See https://github.com/domokit/mojo/issues/692. |
| "-Wno-constant-conversion", |
| ] |
| } |
| } |
| |
| # rtti ------------------------------------------------------------------------ |
| # |
| # Allows turning Run-Time Type Identification on or off. |
| |
| config("rtti") { |
| } |
| config("no_rtti") { |
| cflags_cc = [ "-fno-rtti" ] |
| } |
| |
| # Warnings --------------------------------------------------------------------- |
| |
| # This will generate warnings when using Clang if code generates exit-time |
| # destructors, which will slow down closing the program. |
| # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600 |
| config("wexit_time_destructors") { |
| if (is_clang) { |
| cflags = [ "-Wexit-time-destructors" ] |
| } |
| } |
| |
| # On Windows compiling on x64, VC will issue a warning when converting |
| # size_t to int because it will truncate the value. Our code should not have |
| # these warnings and one should use a static_cast or a checked_cast for the |
| # conversion depending on the case. However, a lot of code still needs to be |
| # fixed. Apply this config to such targets to disable the warning. |
| # |
| # Note that this can be applied regardless of platform and architecture to |
| # clean up the call sites. This will only apply the flag when necessary. |
| # |
| # TODO(jschuh): crbug.com/167187 fix this and delete this config. |
| config("no_size_t_to_int_warning") { |
| } |
| |
| # Some code presumes that pointers to structures/objects are compatible |
| # regardless of whether what they point to is already known to be valid. |
| config("no_incompatible_pointer_warnings") { |
| cflags = [] |
| if (is_clang) { |
| cflags += [ "-Wno-incompatible-pointer-types" ] |
| } |
| } |
| |
| # Optimization ----------------------------------------------------------------- |
| # |
| # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config" |
| # which it will assign to the config it implicitly applies to every target. If |
| # you want to override the optimization level for your target, remove this |
| # config (which will expand differently for debug or release builds), and then |
| # add back the one you want to override it with: |
| # |
| # configs -= default_optimization_config |
| # configs += [ "//build/config/compiler/optimize_max" ] |
| |
| # Shared settings for both "optimize" and "optimize_max" configs. |
| common_optimize_on_cflags = [ |
| # Don't emit the GCC version ident directives, they just end up in the |
| # .comment section taking up binary size. |
| "-fno-ident", |
| |
| # Put data and code in their own sections, so that unused symbols |
| # can be removed at link time with --gc-sections. |
| "-fdata-sections", |
| "-ffunction-sections", |
| ] |
| common_optimize_on_ldflags = [] |
| |
| if (is_android) { |
| if (!using_sanitizer) { |
| common_optimize_on_cflags += [ "-fomit-frame-pointer" ] |
| } |
| |
| # TODO(jdduke) Re-enable on mips after resolving linking |
| # issues with libc++ (crbug.com/456380). |
| if (current_cpu != "mipsel" && current_cpu != "mips64el") { |
| common_optimize_on_ldflags += [ |
| # Warn in case of text relocations. |
| "-Wl,--warn-shared-textrel", |
| ] |
| } |
| } |
| |
| if (is_mac) { |
| if (symbol_level == 2) { |
| # Mac dead code stripping requires symbols. |
| common_optimize_on_ldflags += [ "-Wl,-dead_strip" ] |
| } |
| } else { |
| # Non-Mac Posix linker flags. |
| common_optimize_on_ldflags += [ |
| # Specifically tell the linker to perform optimizations. |
| # See http://lwn.net/Articles/192624/ . |
| "-Wl,-O1", |
| "-Wl,--gc-sections", |
| ] |
| |
| if (!using_sanitizer) { |
| # Functions interposed by the sanitizers can make ld think |
| # that some libraries aren't needed when they actually are, |
| # http://crbug.com/234010. As workaround, disable --as-needed. |
| common_optimize_on_ldflags += [ "-Wl,--as-needed" ] |
| } |
| } |
| |
| # Default "optimization on" config. On Windows, this favors size over speed. |
| config("optimize") { |
| cflags = common_optimize_on_cflags |
| ldflags = common_optimize_on_ldflags |
| if (is_android || is_ios) { |
| cflags += [ "-Os" ] # Favor size over speed. |
| } else { |
| cflags += [ "-O2" ] |
| } |
| } |
| |
| # Turn off optimizations. |
| config("no_optimize") { |
| if (is_android && !android_full_debug) { |
| # On Android we kind of optimize some things that don't affect debugging |
| # much even when optimization is disabled to get the binary size down. |
| cflags = [ |
| "-Os", |
| "-fdata-sections", |
| "-ffunction-sections", |
| ] |
| if (!using_sanitizer) { |
| cflags += [ "-fomit-frame-pointer" ] |
| } |
| ldflags = common_optimize_on_ldflags |
| } else if (is_pnacl) { |
| # Linking and optimization is the slowest part of building code |
| # using the PNaCl toolchain. Optimizing actually makes these passes faster, |
| # and results in a smaller building/translation time. |
| cflags = common_optimize_on_cflags |
| cflags += [ "-Os" ] |
| } else { |
| cflags = [ "-O0" ] |
| } |
| } |
| |
| # Turns up the optimization level. On Windows, this implies whole program |
| # optimization and link-time code generation which is very expensive and should |
| # be used sparingly. |
| config("optimize_max") { |
| cflags = common_optimize_on_cflags |
| ldflags = common_optimize_on_ldflags |
| |
| cflags += [ "-O2" ] |
| } |
| |
| # The default optimization applied to all targets. This will be equivalent to |
| # either "optimize" or "no_optimize", depending on the build flags. |
| config("default_optimization") { |
| if (is_nacl_irt) { |
| # The NaCl IRT is a special case and always wants its own config. |
| # It gets optimized the same way regardless of the type of build. |
| configs = [ "//build/config/nacl:irt_optimize" ] |
| } else if (is_debug) { |
| configs = [ ":no_optimize" ] |
| } else { |
| configs = [ ":optimize" ] |
| } |
| } |
| |
| # Symbols ---------------------------------------------------------------------- |
| |
| config("symbols") { |
| cflags = [ "-g2" ] |
| if (use_debug_fission) { |
| cflags += [ "-gsplit-dwarf" ] |
| } |
| asmflags = cflags |
| ldflags = [] |
| } |
| |
| config("minimal_symbols") { |
| cflags = [ "-g1" ] |
| if (use_debug_fission) { |
| cflags += [ "-gsplit-dwarf" ] |
| } |
| asmflags = cflags |
| ldflags = [] |
| } |
| |
| config("no_symbols") { |
| cflags = [ "-g0" ] |
| asmflags = cflags |
| } |
| |
| # Default symbols. |
| config("default_symbols") { |
| if (symbol_level == 0) { |
| configs = [ ":no_symbols" ] |
| } else if (symbol_level == 1) { |
| configs = [ ":minimal_symbols" ] |
| } else if (symbol_level == 2) { |
| configs = [ ":symbols" ] |
| } else { |
| assert(false) |
| } |
| } |