Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 1 | # Copyright (C) 2017 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Primiano Tucci | 7a40e4d | 2017-12-06 09:51:09 +0000 | [diff] [blame] | 15 | import("//gn/standalone/android.gni") |
| 16 | import("//gn/standalone/sanitizers/sanitizers.gni") |
Primiano Tucci | 8b3feb4 | 2019-07-04 03:17:31 +0100 | [diff] [blame] | 17 | import("//gn/standalone/wasm.gni") |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 18 | |
| 19 | config("extra_warnings") { |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 20 | cflags = [ |
Primiano Tucci | 3cbb10a | 2018-04-10 17:52:40 +0100 | [diff] [blame] | 21 | "-Wall", |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 22 | "-Wextra", |
Sami Kyostila | 1c76dff | 2020-01-15 16:32:21 +0000 | [diff] [blame] | 23 | "-Wpedantic", |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 24 | ] |
Primiano Tucci | 8a5b9a8 | 2018-12-28 13:18:21 +0100 | [diff] [blame] | 25 | |
Lalit Maganti | b4eaf21 | 2020-01-16 18:34:41 +0000 | [diff] [blame^] | 26 | # Disable variadic macro warning as we make extensive use of them in trace |
| 27 | # processor and client API. |
| 28 | if (is_clang) { |
| 29 | cflags += [ "-Wno-gnu-zero-variadic-macro-arguments" ] |
| 30 | } |
| 31 | |
Primiano Tucci | 8a5b9a8 | 2018-12-28 13:18:21 +0100 | [diff] [blame] | 32 | # Disable Weverything on fuzzers to avoid breakages when new versions of clang |
| 33 | # are rolled into OSS-fuzz. |
| 34 | if (is_clang && !is_fuzzer) { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 35 | cflags += [ |
| 36 | "-Weverything", |
Sami Kyostila | 3a946ae | 2017-09-29 14:56:36 +0100 | [diff] [blame] | 37 | "-Wno-c++98-compat-pedantic", |
Primiano Tucci | 1333134 | 2017-10-25 17:08:13 +0100 | [diff] [blame] | 38 | "-Wno-c++98-compat", |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 39 | "-Wno-disabled-macro-expansion", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 40 | "-Wno-gnu-include-next", |
| 41 | "-Wno-gnu-statement-expression", |
| 42 | "-Wno-padded", |
| 43 | "-Wno-reserved-id-macro", |
Primiano Tucci | 91c4a41 | 2019-03-20 09:49:32 +0000 | [diff] [blame] | 44 | "-Wno-unknown-sanitizers", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 45 | ] |
| 46 | } |
| 47 | } |
| 48 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 49 | config("no_exceptions") { |
Primiano Tucci | e1d7638 | 2018-04-04 09:39:06 +0200 | [diff] [blame] | 50 | cflags_cc = [ "-fno-exceptions" ] |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | config("no_rtti") { |
Primiano Tucci | e1d7638 | 2018-04-04 09:39:06 +0200 | [diff] [blame] | 54 | cflags_cc = [ "-fno-rtti" ] |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 57 | config("c++11") { |
| 58 | cflags_cc = [ "-std=c++11" ] |
| 59 | } |
| 60 | |
| 61 | # This is needed to compile libunwindstack. |
| 62 | config("c++17") { |
| 63 | cflags_cc = [ "-std=c++17" ] |
| 64 | } |
| 65 | |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 66 | config("visibility_hidden") { |
| 67 | cflags = [ "-fvisibility=hidden" ] |
| 68 | } |
| 69 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 70 | config("default") { |
| 71 | asmflags = [] |
| 72 | cflags = [] |
| 73 | cflags_c = [] |
| 74 | cflags_cc = [] |
| 75 | defines = [] |
| 76 | ldflags = [] |
| 77 | libs = [] |
| 78 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 79 | cflags += [ |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 80 | "-fstrict-aliasing", |
| 81 | "-fstack-protector", |
| 82 | "-fPIC", |
Primiano Tucci | bc8318e | 2017-12-19 09:29:37 +0100 | [diff] [blame] | 83 | "-g", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 84 | "-Wformat", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 85 | ] |
| 86 | |
Florian Mayer | 7010f3a | 2019-09-09 10:48:12 +0100 | [diff] [blame] | 87 | if (!is_fuzzer) { |
| 88 | cflags += [ "-Werror" ] |
| 89 | } |
| 90 | |
Hector Dearman | 32c32ad | 2017-10-18 11:53:32 +0100 | [diff] [blame] | 91 | if (is_clang) { |
Primiano Tucci | d7d1be0 | 2017-10-30 17:41:34 +0000 | [diff] [blame] | 92 | cflags += [ |
Primiano Tucci | 3cbb10a | 2018-04-10 17:52:40 +0100 | [diff] [blame] | 93 | # Color compiler output, see https://github.com/ninja-build/ninja/wiki/FAQ |
Primiano Tucci | d7d1be0 | 2017-10-30 17:41:34 +0000 | [diff] [blame] | 94 | "-fcolor-diagnostics", |
Florian Mayer | 18614fe | 2018-03-29 17:51:20 +0100 | [diff] [blame] | 95 | "-fdiagnostics-show-template-tree", |
Primiano Tucci | d7d1be0 | 2017-10-30 17:41:34 +0000 | [diff] [blame] | 96 | ] |
Hector Dearman | 32c32ad | 2017-10-18 11:53:32 +0100 | [diff] [blame] | 97 | } |
| 98 | |
Primiano Tucci | 8c3f40a | 2018-09-01 08:31:50 +0200 | [diff] [blame] | 99 | if (is_lto) { |
| 100 | cflags += [ "-flto=full" ] |
| 101 | ldflags += [ "-flto=full" ] |
| 102 | } |
| 103 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 104 | if (current_cpu == "arm") { |
| 105 | cflags += [ |
| 106 | "-march=armv7-a", |
| 107 | "-mfpu=neon", |
| 108 | "-mthumb", |
| 109 | ] |
| 110 | } else if (current_cpu == "x86") { |
| 111 | asmflags += [ "-m32" ] |
| 112 | cflags += [ |
| 113 | "-m32", |
| 114 | "-msse2", |
| 115 | "-mfpmath=sse", |
| 116 | ] |
Florian Mayer | 27985ac | 2019-09-13 16:56:56 +0100 | [diff] [blame] | 117 | ldflags += [ |
| 118 | "-m32", |
| 119 | "-lgcc", |
| 120 | ] |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 121 | } else if (current_cpu == "arm64") { |
| 122 | cflags += [ "-fno-omit-frame-pointer" ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | if (is_linux) { |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 126 | libs += [ |
| 127 | "pthread", |
| 128 | "rt", |
| 129 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 130 | } |
| 131 | |
Florian Mayer | 6aba66d | 2018-02-02 10:53:28 +0000 | [diff] [blame] | 132 | if (is_debug) { |
| 133 | libs += [ "dl" ] |
| 134 | } |
| 135 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 136 | if (is_android) { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 137 | asmflags += [ "--target=$android_abi_target" ] |
| 138 | cflags += [ |
Primiano Tucci | b45bfac | 2017-11-28 14:37:48 +0000 | [diff] [blame] | 139 | "--sysroot=$android_compile_sysroot", |
| 140 | "-isystem$android_compile_sysroot/$android_compile_sysroot_subdir", |
| 141 | "-isystem$android_compile_sysroot", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 142 | "-DANDROID", |
Florian Mayer | 46ef922 | 2018-08-22 14:46:01 -0700 | [diff] [blame] | 143 | "-D__ANDROID_API__=${android_api_level}", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 144 | "--target=$android_abi_target", |
| 145 | ] |
| 146 | cflags_cc += [ |
| 147 | "-I$android_ndk_root/sources/cxx-stl/llvm-libc++/include", |
| 148 | "-I$android_ndk_root/sources/android/support/include", |
| 149 | "-I$android_ndk_root/sources/cxx-stl/llvm-libc++abi/include", |
Florian Mayer | aa5316b | 2018-08-20 17:45:12 -0700 | [diff] [blame] | 150 | |
| 151 | # This is needed for NDK libc++. Using -isystem instead of -I above |
| 152 | # results in build breakage related to cmath.h. |
| 153 | "-Wno-format-nonliteral", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 154 | ] |
| 155 | ldflags += [ |
| 156 | "-Wl,-z,nocopyreloc", |
| 157 | "-gcc-toolchain", |
| 158 | "$android_toolchain_root", |
Primiano Tucci | b45bfac | 2017-11-28 14:37:48 +0000 | [diff] [blame] | 159 | "--sysroot=$android_ndk_root/$android_link_sysroot_subdir", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 160 | "--target=$android_abi_target", |
| 161 | "-Wl,--exclude-libs,libunwind.a", |
| 162 | "-Wl,--exclude-libs,libgcc.a", |
| 163 | "-Wl,--exclude-libs,libc++_static.a", |
| 164 | "-Wl,--build-id", |
| 165 | "-Wl,--no-undefined", |
| 166 | "-Wl,-z,noexecstack", |
| 167 | "-Wl,-z,relro", |
| 168 | "-Wl,-z,now", |
| 169 | "-Wl,--warn-shared-textrel", |
| 170 | "-Wl,--fatal-warnings", |
| 171 | ] |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 172 | lib_dirs = [ |
| 173 | "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi", |
| 174 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 175 | libs += [ |
| 176 | "gcc", |
| 177 | "c++_static", |
| 178 | "c++abi", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 179 | ] |
Florian Mayer | aa5316b | 2018-08-20 17:45:12 -0700 | [diff] [blame] | 180 | |
| 181 | if (current_cpu == "arm") { |
| 182 | # New NDKs don't have libandroid_support for arm64. |
| 183 | libs += [ "android_support" ] |
| 184 | } |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
| 188 | config("debug_symbols") { |
Primiano Tucci | bc8318e | 2017-12-19 09:29:37 +0100 | [diff] [blame] | 189 | cflags = [ "-O0" ] |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 190 | if (is_android || is_linux) { |
| 191 | cflags += [ "-funwind-tables" ] |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 195 | config("release") { |
| 196 | cflags = [ |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 197 | "-fdata-sections", |
| 198 | "-ffunction-sections", |
| 199 | ] |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 200 | if (is_android) { |
Ryan Savitski | f929107 | 2019-09-24 16:49:13 +0100 | [diff] [blame] | 201 | cflags += [ "-O2" ] |
Florian Mayer | 2e48071 | 2018-12-07 16:25:41 +0000 | [diff] [blame] | 202 | } else if (is_fuzzer) { |
Primiano Tucci | a65497e | 2018-09-26 19:53:58 +0100 | [diff] [blame] | 203 | cflags += [ "-O1" ] |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 204 | } else { |
| 205 | cflags += [ "-O3" ] |
| 206 | } |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 207 | if (is_mac) { |
| 208 | ldflags = [ "-dead_strip" ] |
| 209 | } else { |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 210 | ldflags = [ |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 211 | "-Wl,--gc-sections", |
| 212 | "-Wl,--icf=all", |
| 213 | "-Wl,-O1", |
| 214 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 215 | } |
| 216 | defines = [ "NDEBUG" ] |
| 217 | } |
| 218 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 219 | config("shared_library") { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 220 | if (is_android || is_linux) { |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 221 | ldflags = [ "-fPIC" ] |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | config("executable") { |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 226 | ldflags = [] |
| 227 | |
| 228 | # Android will refuse to run executables if they aren't position independent. |
| 229 | # Instead on Linux there isn't any need and they break ASan (goo.gl/paFR6K). |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 230 | if (is_android) { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 231 | asmflags = [ "-fPIE" ] |
| 232 | cflags = [ "-fPIE" ] |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 233 | ldflags += [ "-pie" ] |
| 234 | } |
| 235 | |
| 236 | # -rpath stores the path to the linked shared libraries into the binary, so |
| 237 | # that they can be launched without passing any LD_LIBRARY_PATH. It's |
| 238 | # supported only by Linux, not Android. But concretely we need this only when |
| 239 | # use_custom_libcxx=true && custom_libcxx_is_static=false, which happens only |
| 240 | # on Linux right now. |
| 241 | if (is_linux) { |
| 242 | ldflags += [ |
| 243 | "-Wl,-rpath=\$ORIGIN/.", |
| 244 | "-Wl,-rpath-link=.", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 245 | ] |
| 246 | } |
| 247 | } |
Ryan Savitski | a3da9be | 2019-01-30 17:45:53 +0000 | [diff] [blame] | 248 | |
| 249 | # This config is only added to certain leaf target types (see BUILDCONFIG.gn). |
| 250 | # This allows us to remove the config (and thus the dependency) on a per-target |
| 251 | # basis. If the config was applied to source_sets, then they would unavoidably |
| 252 | # carry the dependency onto liblog to the final target. |
| 253 | config("android_liblog") { |
| 254 | if (is_android) { |
| 255 | libs = [ "log" ] |
| 256 | } |
| 257 | } |
Primiano Tucci | 00da64a | 2019-02-22 14:51:10 +0000 | [diff] [blame] | 258 | |
| 259 | config("gen_include_path") { |
| 260 | include_dirs = [ root_gen_dir ] |
| 261 | } |
| 262 | |
| 263 | # This action generates a perfetto_version.gen.h which contains the git SHA1 |
| 264 | # of HEAD. The file can be included from C/C++ sources and exposes a |
| 265 | # PERFETTO_GET_GIT_REVISION() macro that contains the git revision. |
| 266 | action("gen_git_revision") { |
| 267 | script = "gen_git_revision.py" |
| 268 | generated_header = "${root_gen_dir}/perfetto_version.gen.h" |
| 269 | args = [ rebase_path(generated_header, root_build_dir) ] |
| 270 | inputs = [] |
| 271 | outputs = [ |
| 272 | generated_header, |
| 273 | ] |
| 274 | public_configs = [ ":gen_include_path" ] |
| 275 | } |