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