| # 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("//gn/standalone/android.gni") |
| import("//gn/standalone/sanitizers/sanitizers.gni") |
| import("//gn/standalone/wasm.gni") |
| |
| config("extra_warnings") { |
| cflags = [ |
| "-Wall", |
| "-Wextra", |
| ] |
| |
| # Disable Weverything on fuzzers to avoid breakages when new versions of clang |
| # are rolled into OSS-fuzz. |
| if (is_clang && !is_fuzzer) { |
| cflags += [ |
| "-Weverything", |
| "-Wno-c++98-compat-pedantic", |
| "-Wno-c++98-compat", |
| "-Wno-disabled-macro-expansion", |
| "-Wno-gnu-include-next", |
| "-Wno-gnu-statement-expression", |
| "-Wno-gnu-zero-variadic-macro-arguments", |
| "-Wno-padded", |
| "-Wno-reserved-id-macro", |
| "-Wno-unknown-sanitizers", |
| ] |
| } |
| } |
| |
| config("no_exceptions") { |
| cflags_cc = [ "-fno-exceptions" ] |
| } |
| |
| config("no_rtti") { |
| cflags_cc = [ "-fno-rtti" ] |
| } |
| |
| config("c++11") { |
| cflags_cc = [ "-std=c++11" ] |
| } |
| |
| # This is needed to compile libunwindstack. |
| config("c++17") { |
| cflags_cc = [ "-std=c++17" ] |
| } |
| |
| config("visibility_hidden") { |
| cflags = [ "-fvisibility=hidden" ] |
| } |
| |
| config("default") { |
| asmflags = [] |
| cflags = [] |
| cflags_c = [] |
| cflags_cc = [] |
| defines = [] |
| ldflags = [] |
| libs = [] |
| |
| cflags += [ |
| "-fstrict-aliasing", |
| "-fstack-protector", |
| "-fPIC", |
| "-g", |
| "-Wformat", |
| "-Werror", |
| ] |
| |
| if (is_clang) { |
| cflags += [ |
| # Color compiler output, see https://github.com/ninja-build/ninja/wiki/FAQ |
| "-fcolor-diagnostics", |
| "-fdiagnostics-show-template-tree", |
| ] |
| } |
| |
| if (is_lto) { |
| cflags += [ "-flto=full" ] |
| ldflags += [ "-flto=full" ] |
| } |
| |
| 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" ] |
| } else if (current_cpu == "arm64") { |
| cflags += [ "-fno-omit-frame-pointer" ] |
| } |
| |
| if (is_linux) { |
| libs += [ |
| "pthread", |
| "rt", |
| ] |
| } |
| |
| if (is_debug) { |
| libs += [ "dl" ] |
| } |
| |
| if (is_android) { |
| asmflags += [ "--target=$android_abi_target" ] |
| cflags += [ |
| "--sysroot=$android_compile_sysroot", |
| "-isystem$android_compile_sysroot/$android_compile_sysroot_subdir", |
| "-isystem$android_compile_sysroot", |
| "-DANDROID", |
| "-D__ANDROID_API__=${android_api_level}", |
| "--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", |
| |
| # This is needed for NDK libc++. Using -isystem instead of -I above |
| # results in build breakage related to cmath.h. |
| "-Wno-format-nonliteral", |
| ] |
| ldflags += [ |
| "-Wl,-z,nocopyreloc", |
| "-gcc-toolchain", |
| "$android_toolchain_root", |
| "--sysroot=$android_ndk_root/$android_link_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", |
| ] |
| libs += [ |
| "gcc", |
| "c++_static", |
| "c++abi", |
| ] |
| |
| if (current_cpu == "arm") { |
| # New NDKs don't have libandroid_support for arm64. |
| libs += [ "android_support" ] |
| } |
| } |
| } |
| |
| config("debug_symbols") { |
| cflags = [ "-O0" ] |
| if (is_android || is_linux) { |
| cflags += [ "-funwind-tables" ] |
| } |
| } |
| |
| config("release") { |
| cflags = [ |
| "-fdata-sections", |
| "-ffunction-sections", |
| ] |
| if (is_android) { |
| cflags += [ "-Oz" ] |
| } else if (is_fuzzer) { |
| cflags += [ "-O1" ] |
| } else { |
| cflags += [ "-O3" ] |
| } |
| if (is_mac) { |
| ldflags = [ "-dead_strip" ] |
| } else { |
| ldflags = [ |
| "-Wl,--gc-sections", |
| "-Wl,--icf=all", |
| "-Wl,-O1", |
| ] |
| } |
| defines = [ "NDEBUG" ] |
| } |
| |
| config("shared_library") { |
| if (is_android || is_linux) { |
| ldflags = [ "-fPIC" ] |
| } |
| } |
| |
| config("executable") { |
| ldflags = [] |
| |
| # Android will refuse to run executables if they aren't position independent. |
| # Instead on Linux there isn't any need and they break ASan (goo.gl/paFR6K). |
| if (is_android) { |
| asmflags = [ "-fPIE" ] |
| cflags = [ "-fPIE" ] |
| ldflags += [ "-pie" ] |
| } |
| |
| # -rpath stores the path to the linked shared libraries into the binary, so |
| # that they can be launched without passing any LD_LIBRARY_PATH. It's |
| # supported only by Linux, not Android. But concretely we need this only when |
| # use_custom_libcxx=true && custom_libcxx_is_static=false, which happens only |
| # on Linux right now. |
| if (is_linux) { |
| ldflags += [ |
| "-Wl,-rpath=\$ORIGIN/.", |
| "-Wl,-rpath-link=.", |
| ] |
| } |
| } |
| |
| # This config is only added to certain leaf target types (see BUILDCONFIG.gn). |
| # This allows us to remove the config (and thus the dependency) on a per-target |
| # basis. If the config was applied to source_sets, then they would unavoidably |
| # carry the dependency onto liblog to the final target. |
| config("android_liblog") { |
| if (is_android) { |
| libs = [ "log" ] |
| } |
| } |
| |
| config("gen_include_path") { |
| include_dirs = [ root_gen_dir ] |
| } |
| |
| # This action generates a perfetto_version.gen.h which contains the git SHA1 |
| # of HEAD. The file can be included from C/C++ sources and exposes a |
| # PERFETTO_GET_GIT_REVISION() macro that contains the git revision. |
| action("gen_git_revision") { |
| script = "gen_git_revision.py" |
| generated_header = "${root_gen_dir}/perfetto_version.gen.h" |
| args = [ rebase_path(generated_header, root_build_dir) ] |
| inputs = [] |
| outputs = [ |
| generated_header, |
| ] |
| public_configs = [ ":gen_include_path" ] |
| } |