| # Copyright (C) 2017 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| import("//build/android.gni") |
| import("//build/c++.gni") |
| import("//build/mac.gni") |
| import("//build/sanitizers/sanitizers.gni") |
| |
| config("extra_warnings") { |
| cflags = [ |
| "-Wextra", |
| "-Wno-missing-field-initializers", |
| ] |
| if (is_clang) { |
| cflags += [ |
| "-Weverything", |
| "-Wno-c++98-compat", |
| "-Wno-c++98-compat-pedantic", |
| "-Wno-gnu-include-next", |
| "-Wno-gnu-statement-expression", |
| "-Wno-padded", |
| "-Wno-reserved-id-macro", |
| "-Wno-unused-parameter", |
| "-Wno-unknown-warning-option", |
| ] |
| } |
| } |
| |
| config("no_exceptions") { |
| cflags = [ "-fno-exceptions" ] |
| } |
| |
| config("no_rtti") { |
| cflags = [ "-fno-rtti" ] |
| } |
| |
| config("default") { |
| asmflags = [] |
| cflags = [] |
| cflags_c = [] |
| cflags_cc = [] |
| defines = [] |
| ldflags = [] |
| libs = [] |
| |
| include_dirs = [ ".." ] |
| |
| cflags_cc += [ "-std=c++11" ] |
| |
| cflags += [ |
| "-fstrict-aliasing", |
| "-fstack-protector", |
| "-fPIC", |
| "-Wa,--noexecstack", |
| "-Wformat", |
| "-Wall", |
| "-Werror", |
| ] |
| |
| # Color compiler output, see https://github.com/ninja-build/ninja/wiki/FAQ |
| if (is_clang) { |
| cflags += [ "-fcolor-diagnostics" ] |
| } |
| |
| if (current_cpu == "arm") { |
| cflags += [ |
| "-march=armv7-a", |
| "-mfpu=neon", |
| "-mthumb", |
| ] |
| } else if (current_cpu == "x86") { |
| asmflags += [ "-m32" ] |
| cflags += [ |
| "-m32", |
| "-msse2", |
| "-mfpmath=sse", |
| ] |
| ldflags += [ "-m32" ] |
| } |
| |
| if (is_linux) { |
| libs += [ "pthread" ] |
| } |
| |
| if (is_android) { |
| libs += [ "log" ] |
| } |
| |
| if (is_android) { |
| asmflags += [ "--target=$android_abi_target" ] |
| cflags += [ |
| "-isystem$android_ndk_root/$android_sysroot_subdir/usr/include", |
| "--sysroot=$android_ndk_root/$android_sysroot_subdir", |
| "-DANDROID", |
| "--target=$android_abi_target", |
| ] |
| cflags_cc += [ |
| "-I$android_ndk_root/sources/cxx-stl/llvm-libc++/include", |
| "-I$android_ndk_root/sources/android/support/include", |
| "-I$android_ndk_root/sources/cxx-stl/llvm-libc++abi/include", |
| ] |
| ldflags += [ |
| "-Wl,-z,nocopyreloc", |
| "-gcc-toolchain", |
| "$android_toolchain_root", |
| "--sysroot=$android_ndk_root/$android_sysroot_subdir", |
| "--target=$android_abi_target", |
| "-Wl,--exclude-libs,libunwind.a", |
| "-Wl,--exclude-libs,libgcc.a", |
| "-Wl,--exclude-libs,libc++_static.a", |
| "-Wl,--build-id", |
| "-Wl,--no-undefined", |
| "-Wl,-z,noexecstack", |
| "-Wl,-z,relro", |
| "-Wl,-z,now", |
| "-Wl,--warn-shared-textrel", |
| "-Wl,--fatal-warnings", |
| ] |
| lib_dirs = [ |
| "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi", |
| "$android_ndk_root/$android_sysroot_subdir/usr/lib", |
| ] |
| libs += [ |
| "gcc", |
| "c++_static", |
| "c++abi", |
| "android_support", |
| ] |
| } |
| } |
| |
| config("debug_symbols") { |
| if (is_android) { |
| cflags = [ |
| "-gline-tables-only", |
| "-funwind-tables", |
| ] |
| } else { |
| cflags = [ "-g2" ] |
| } |
| } |
| |
| config("runtime_library") { |
| if (use_custom_libcxx) { |
| defines = [ |
| "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS", |
| "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS", |
| ] |
| cflags_cc = [ |
| "-nostdinc++", |
| "-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir), |
| "-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir), |
| ] |
| } |
| } |
| |
| config("release") { |
| cflags = [ |
| "-O3", |
| "-fdata-sections", |
| "-ffunction-sections", |
| ] |
| if (is_mac) { |
| ldflags = [ "-dead_strip" ] |
| } else { |
| ldflags = [ "-Wl,--gc-sections" ] |
| } |
| defines = [ "NDEBUG" ] |
| } |
| |
| group("exe_and_shlib_deps") { |
| public_deps = [] |
| if (using_sanitizer) { |
| public_deps += [ "//build/sanitizers:deps" ] |
| } |
| if (use_custom_libcxx) { |
| public_deps += [ "//buildtools:libc++" ] |
| } |
| } |
| |
| config("shared_library") { |
| if (is_android || is_linux) { |
| ldflags = [ "-fPIC" ] |
| } |
| } |
| |
| config("executable") { |
| if (is_android) { |
| asmflags = [ "-fPIE" ] |
| cflags = [ "-fPIE" ] |
| ldflags = [ |
| "-fPIE", |
| "-pie", |
| ] |
| } |
| } |