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 | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 15 | import("//gn/perfetto_check_build_deps.gni") |
Primiano Tucci | 7a40e4d | 2017-12-06 09:51:09 +0000 | [diff] [blame] | 16 | import("//gn/standalone/android.gni") |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 17 | import("//gn/standalone/libc++/libc++.gni") |
Primiano Tucci | 7a40e4d | 2017-12-06 09:51:09 +0000 | [diff] [blame] | 18 | import("//gn/standalone/sanitizers/sanitizers.gni") |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 19 | import("//gn/standalone/toolchain/msvc.gni") |
Primiano Tucci | 8b3feb4 | 2019-07-04 03:17:31 +0100 | [diff] [blame] | 20 | import("//gn/standalone/wasm.gni") |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 21 | |
Primiano Tucci | fbcfeeb | 2020-01-28 00:46:43 +0000 | [diff] [blame] | 22 | # These warnings have been introduced with the newest version of clang (only in |
| 23 | # the hermetic build) and are enabled just with -Werror. |
Florian Mayer | 39e40d4 | 2020-07-16 14:52:07 +0200 | [diff] [blame] | 24 | hermetic_clang_suppressions = [ "-Wno-c99-designator" ] |
Primiano Tucci | fbcfeeb | 2020-01-28 00:46:43 +0000 | [diff] [blame] | 25 | |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 26 | # We deal with three toolchains here: |
| 27 | # 1. Clang, used in most cases. |
| 28 | # 2. GCC, used in some Linux cases. |
| 29 | # 3. MSVC, used in some Windows cases. |
| 30 | # Clang vs gcc is typically not a problem: both support roughly the same |
| 31 | # switches. -Wno-unknown-warning-option fixes the mismatching ones. |
| 32 | # The situation on Windows is a bit trickier: clang-cl.exe really pretends to be |
| 33 | # cl.exe (MSVC), so we should use MSVC-style switches (e.g. /W2). However, |
| 34 | # clang-cl.exe still supports some -Wclang-style-switches for flags that don't |
| 35 | # have a corresponding version in MSVC. |
| 36 | # |
| 37 | # In the rules below, the conditionals should be interpreted as follows: |
| 38 | # is_win -> can be either clang-cl.exe or cl.exe (MSVC). Only MSVC-style |
| 39 | # switches (the common denominator) should be used. |
| 40 | # is_clang -> could be clang-on-linux, clang-on-mac or clang-cl.exe. |
| 41 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 42 | config("extra_warnings") { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 43 | if (is_win) { |
| 44 | cflags = [ |
| 45 | "/W2", |
| 46 | "/wd4244", # conversion from 'float' to 'int', possible loss of data |
| 47 | "/wd4267", # conversion from 'size_t' to 'int', possible loss of data |
| 48 | ] |
| 49 | if (is_clang) { |
| 50 | cflags += [ |
| 51 | "-Wno-float-equal", |
| 52 | "-Wno-unused-macros", |
| 53 | "-Wno-old-style-cast", |
| 54 | ] |
| 55 | } |
| 56 | } else { |
| 57 | # Clang or Gcc. On linux, Android and Mac. |
| 58 | cflags = [ |
| 59 | "-Wall", |
| 60 | "-Wextra", |
| 61 | "-Wpedantic", |
| 62 | ] |
| 63 | } |
Primiano Tucci | 8a5b9a8 | 2018-12-28 13:18:21 +0100 | [diff] [blame] | 64 | |
Lalit Maganti | b4eaf21 | 2020-01-16 18:34:41 +0000 | [diff] [blame] | 65 | # Disable variadic macro warning as we make extensive use of them in trace |
| 66 | # processor and client API. |
| 67 | if (is_clang) { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 68 | if (!is_fuzzer) { |
| 69 | # Disable Weverything on fuzzers to avoid breakages when new versions of |
| 70 | # clang are rolled into OSS-fuzz. |
| 71 | cflags += [ "-Weverything" ] |
| 72 | } |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 73 | cflags += [ |
Sami Kyostila | 3a946ae | 2017-09-29 14:56:36 +0100 | [diff] [blame] | 74 | "-Wno-c++98-compat-pedantic", |
Primiano Tucci | 1333134 | 2017-10-25 17:08:13 +0100 | [diff] [blame] | 75 | "-Wno-c++98-compat", |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 76 | "-Wno-disabled-macro-expansion", |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 77 | "-Wno-documentation-unknown-command", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 78 | "-Wno-gnu-include-next", |
| 79 | "-Wno-gnu-statement-expression", |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 80 | "-Wno-gnu-zero-variadic-macro-arguments", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 81 | "-Wno-padded", |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 82 | "-Wno-poison-system-directories", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 83 | "-Wno-reserved-id-macro", |
Primiano Tucci | 8652a85 | 2021-09-08 14:56:19 +0100 | [diff] [blame] | 84 | "-Wno-reserved-identifier", |
Primiano Tucci | 91c4a41 | 2019-03-20 09:49:32 +0000 | [diff] [blame] | 85 | "-Wno-unknown-sanitizers", |
Primiano Tucci | f68444a | 2020-08-05 11:53:39 +0200 | [diff] [blame] | 86 | "-Wno-unknown-warning-option", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 87 | ] |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 88 | } else if (!is_clang && !is_win) { |
| 89 | # Use return std::move(...) for compatibility with old GCC compilers. |
Sami Kyostila | 2b626d9 | 2020-04-28 12:16:29 +0100 | [diff] [blame] | 90 | cflags += [ "-Wno-redundant-move" ] |
| 91 | } |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 92 | } |
| 93 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 94 | config("no_exceptions") { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 95 | # Exceptions are disabled by default on Windows (Use /EHsc to enable them). |
| 96 | if (!is_win) { |
| 97 | cflags_cc = [ "-fno-exceptions" ] |
| 98 | } |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | config("no_rtti") { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 102 | if (is_win) { |
| 103 | cflags_cc = [ "/GR-" ] |
| 104 | } else { |
| 105 | cflags_cc = [ "-fno-rtti" ] |
| 106 | } |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 109 | config("c++11") { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 110 | # C++11 is the default on Windows. |
| 111 | if (!is_win) { |
| 112 | cflags_cc = [ "-std=c++11" ] |
Sami Kyostila | f43e650 | 2021-01-06 14:18:49 +0000 | [diff] [blame] | 113 | } else if (is_win && !is_clang) { |
| 114 | # Enable standards-conforming compiler behavior. |
| 115 | cflags_cc = [ "/permissive-" ] |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 116 | } |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Ryan Savitski | e65c405 | 2022-03-24 18:22:19 +0000 | [diff] [blame] | 119 | # Used in buildtools dependencies for standalone builds. |
| 120 | config("c++14") { |
| 121 | if (is_win) { |
| 122 | cflags_cc = [ "/std:c++14" ] |
| 123 | } else { |
| 124 | cflags_cc = [ "-std=c++14" ] |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | # Used in buildtools dependencies for standalone builds. |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 129 | config("c++17") { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 130 | if (is_win) { |
| 131 | cflags_cc = [ "/std:c++17" ] |
| 132 | } else { |
| 133 | cflags_cc = [ "-std=c++17" ] |
| 134 | } |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 135 | } |
| 136 | |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 137 | config("visibility_hidden") { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 138 | if (!is_win) { |
| 139 | cflags = [ "-fvisibility=hidden" ] |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | config("win32_lean_and_mean") { |
| 144 | if (is_win) { |
| 145 | defines = [ "WIN32_LEAN_AND_MEAN" ] |
| 146 | } |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 149 | config("default") { |
| 150 | asmflags = [] |
| 151 | cflags = [] |
| 152 | cflags_c = [] |
| 153 | cflags_cc = [] |
| 154 | defines = [] |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 155 | include_dirs = [] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 156 | ldflags = [] |
| 157 | libs = [] |
| 158 | |
Primiano Tucci | 7e9865c | 2021-01-10 23:55:15 +0100 | [diff] [blame] | 159 | if ((is_android || is_linux) && !is_wasm) { |
Florian Mayer | 5d016a5 | 2020-09-14 21:06:36 +0100 | [diff] [blame] | 160 | ldflags += [ "-Wl,--build-id" ] |
| 161 | } |
| 162 | |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 163 | if (is_clang || !is_win) { # Clang or GCC, but not MSVC. |
| 164 | cflags += [ |
| 165 | "-fstrict-aliasing", |
| 166 | "-Wformat", |
| 167 | ] |
| 168 | } |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 169 | |
Daniele Di Proietto | b9a246e | 2022-09-05 10:59:55 +0100 | [diff] [blame] | 170 | if (is_clang && is_win) { |
| 171 | # clang-cl from version 16 does not like out-of-line definition of static |
| 172 | # constexpr, even in C++14 mode. Disable the deprecated warnings to work |
| 173 | # around the problem. |
| 174 | cflags += [ "-Wno-deprecated" ] |
| 175 | } |
| 176 | |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 177 | if (is_win) { |
| 178 | cflags += [ |
| 179 | "/bigobj", # Some of our files are bigger than the regular limits. |
| 180 | "/Gy", # Enable function-level linking. |
Primiano Tucci | 5f3008e | 2021-05-19 21:34:45 +0100 | [diff] [blame] | 181 | "/FS", # Preserve previous PDB behavior. |
| 182 | "/utf-8", # Assume UTF-8 by default to avoid code page dependencies. |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 183 | ] |
| 184 | defines += [ |
| 185 | "_CRT_NONSTDC_NO_WARNINGS", |
| 186 | "_CRT_SECURE_NO_DEPRECATE", |
| 187 | "_CRT_SECURE_NO_WARNINGS", # Disables warnings on some POSIX-compat API. |
| 188 | "_SCL_SECURE_NO_DEPRECATE", |
| 189 | "NOMINMAX", |
| 190 | ] |
| 191 | if (!use_custom_libcxx) { |
| 192 | defines += [ "_HAS_EXCEPTIONS=0" ] # Disables exceptions in MSVC STL. |
| 193 | } |
Primiano Tucci | 7e9865c | 2021-01-10 23:55:15 +0100 | [diff] [blame] | 194 | } else if (!is_wasm) { # !is_win |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 195 | cflags += [ |
| 196 | "-g", |
| 197 | "-fPIC", |
| 198 | "-fstack-protector-strong", |
| 199 | ] |
| 200 | } |
| 201 | |
| 202 | # Treat warnings as errors, but give up on fuzzer builds. |
Florian Mayer | 7010f3a | 2019-09-09 10:48:12 +0100 | [diff] [blame] | 203 | if (!is_fuzzer) { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 204 | if (is_win) { |
| 205 | cflags += [ "/WX" ] |
| 206 | } else { |
| 207 | cflags += [ "-Werror" ] |
| 208 | } |
Florian Mayer | 7010f3a | 2019-09-09 10:48:12 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Hector Dearman | 32c32ad | 2017-10-18 11:53:32 +0100 | [diff] [blame] | 211 | if (is_clang) { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 212 | cflags += [ "-fcolor-diagnostics" ] |
| 213 | if (!is_win) { |
| 214 | cflags += [ "-fdiagnostics-show-template-tree" ] |
| 215 | } |
Hector Dearman | 32c32ad | 2017-10-18 11:53:32 +0100 | [diff] [blame] | 216 | } |
| 217 | |
Primiano Tucci | fbcfeeb | 2020-01-28 00:46:43 +0000 | [diff] [blame] | 218 | if (is_hermetic_clang && is_linux && !is_wasm) { |
| 219 | cflags += hermetic_clang_suppressions |
| 220 | } else { |
| 221 | not_needed([ "hermetic_clang_suppressions" ]) |
| 222 | } |
| 223 | |
Primiano Tucci | 8c3f40a | 2018-09-01 08:31:50 +0200 | [diff] [blame] | 224 | if (is_lto) { |
| 225 | cflags += [ "-flto=full" ] |
| 226 | ldflags += [ "-flto=full" ] |
| 227 | } |
| 228 | |
Primiano Tucci | 497c3ed | 2021-05-24 12:24:39 +0100 | [diff] [blame] | 229 | if (is_win) { |
| 230 | # We support only x86/x64 builds on Windows. |
| 231 | assert(current_cpu == "x64" || current_cpu == "x86") |
| 232 | } else if (current_cpu == "arm") { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 233 | cflags += [ |
| 234 | "-march=armv7-a", |
| 235 | "-mfpu=neon", |
| 236 | "-mthumb", |
| 237 | ] |
| 238 | } else if (current_cpu == "x86") { |
| 239 | asmflags += [ "-m32" ] |
| 240 | cflags += [ |
| 241 | "-m32", |
| 242 | "-msse2", |
| 243 | "-mfpmath=sse", |
| 244 | ] |
Florian Mayer | 27985ac | 2019-09-13 16:56:56 +0100 | [diff] [blame] | 245 | ldflags += [ |
| 246 | "-m32", |
| 247 | "-lgcc", |
| 248 | ] |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 249 | } else if (current_cpu == "arm64") { |
| 250 | cflags += [ "-fno-omit-frame-pointer" ] |
Primiano Tucci | 2277f06 | 2021-11-08 22:24:05 +0000 | [diff] [blame] | 251 | } else if (current_cpu == "x64") { |
| 252 | cflags += [ "-fno-omit-frame-pointer" ] # For perf profiling. |
| 253 | if (enable_perfetto_x64_cpu_opt) { |
| 254 | # When updating these flags, the CheckCpuOptimizations() in utils.cc must |
| 255 | # be updated accordingly. |
| 256 | cflags += [ |
Lalit Maganti | 25a4534 | 2022-06-14 14:56:48 +0100 | [diff] [blame] | 257 | "-mbmi", |
| 258 | "-mbmi2", |
Primiano Tucci | 682a998 | 2022-05-20 17:13:28 +0100 | [diff] [blame] | 259 | "-mavx2", |
Primiano Tucci | 2277f06 | 2021-11-08 22:24:05 +0000 | [diff] [blame] | 260 | "-mpopcnt", |
| 261 | "-msse4.2", |
| 262 | ] |
| 263 | } |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | if (is_linux) { |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 267 | libs += [ |
| 268 | "pthread", |
| 269 | "rt", |
| 270 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 271 | } |
| 272 | |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 273 | if (is_win && !is_clang) { |
| 274 | # When using MSVC we need to manually pass the include dirs. clang-cl.exe |
| 275 | # doesn't need them because it's smart enough to figure out the right path |
| 276 | # by querying the registry on its own. |
| 277 | include_dirs = win_msvc_inc_dirs # Defined in msvc.gni. |
| 278 | } |
| 279 | |
Florian Mayer | 6aba66d | 2018-02-02 10:53:28 +0000 | [diff] [blame] | 280 | if (is_debug) { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 281 | if (is_win) { |
| 282 | cflags += [ "/Z7" ] |
| 283 | if (is_clang) { |
| 284 | # Required to see symbols in windbg when building with clang-cl.exe. |
| 285 | cflags += [ "-gcodeview-ghash" ] |
| 286 | ldflags = [ "/DEBUG:GHASH" ] |
| 287 | } |
| 288 | } else { |
| 289 | libs += [ "dl" ] |
| 290 | } |
Florian Mayer | 6aba66d | 2018-02-02 10:53:28 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 293 | if (is_android) { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 294 | asmflags += [ "--target=$android_abi_target" ] |
| 295 | cflags += [ |
Primiano Tucci | b45bfac | 2017-11-28 14:37:48 +0000 | [diff] [blame] | 296 | "--sysroot=$android_compile_sysroot", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 297 | "-DANDROID", |
Florian Mayer | 46ef922 | 2018-08-22 14:46:01 -0700 | [diff] [blame] | 298 | "-D__ANDROID_API__=${android_api_level}", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 299 | "--target=$android_abi_target", |
| 300 | ] |
| 301 | cflags_cc += [ |
Lalit Maganti | 7690522 | 2022-05-20 14:24:14 +0100 | [diff] [blame] | 302 | "-isystem$android_ndk_root/sources/cxx-stl/llvm-libc++/include", |
| 303 | "-isystem$android_ndk_root/sources/android/support/include", |
| 304 | "-isystem$android_ndk_root/sources/cxx-stl/llvm-libc++abi/include", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 305 | ] |
Lalit Maganti | 7690522 | 2022-05-20 14:24:14 +0100 | [diff] [blame] | 306 | |
| 307 | # Keep these include paths *after* the above to prevent the wrong include |
| 308 | # being used for some headers (e.g. math.h). |
| 309 | # We need to add to each language (cflags_c, cflags_cc etc.) separately as |
| 310 | # we added to cflags directly, these inludes would end up before the |
| 311 | # languge and thus the above includes. |
| 312 | sysroot_cflags = [ |
| 313 | "-isystem$android_compile_sysroot/$android_compile_sysroot_subdir", |
| 314 | "-isystem$android_compile_sysroot", |
| 315 | ] |
| 316 | cflags_c += sysroot_cflags |
| 317 | cflags_cc += sysroot_cflags |
| 318 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 319 | ldflags += [ |
| 320 | "-Wl,-z,nocopyreloc", |
| 321 | "-gcc-toolchain", |
| 322 | "$android_toolchain_root", |
Primiano Tucci | b45bfac | 2017-11-28 14:37:48 +0000 | [diff] [blame] | 323 | "--sysroot=$android_ndk_root/$android_link_sysroot_subdir", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 324 | "--target=$android_abi_target", |
| 325 | "-Wl,--exclude-libs,libunwind.a", |
| 326 | "-Wl,--exclude-libs,libgcc.a", |
| 327 | "-Wl,--exclude-libs,libc++_static.a", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 328 | "-Wl,--no-undefined", |
| 329 | "-Wl,-z,noexecstack", |
| 330 | "-Wl,-z,relro", |
| 331 | "-Wl,-z,now", |
| 332 | "-Wl,--warn-shared-textrel", |
| 333 | "-Wl,--fatal-warnings", |
Florian Mayer | 5592685 | 2021-02-17 14:42:32 +0000 | [diff] [blame] | 334 | |
| 335 | # New NDKs need setting this to not give "unable to find library -lc++". |
| 336 | # See https://github.com/android/ndk/issues/951#issuecomment-501017894. |
| 337 | "-nostdlib++", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 338 | ] |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 339 | lib_dirs = [ |
| 340 | "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi", |
| 341 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 342 | libs += [ |
| 343 | "gcc", |
| 344 | "c++_static", |
| 345 | "c++abi", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 346 | ] |
Florian Mayer | aa5316b | 2018-08-20 17:45:12 -0700 | [diff] [blame] | 347 | |
| 348 | if (current_cpu == "arm") { |
| 349 | # New NDKs don't have libandroid_support for arm64. |
| 350 | libs += [ "android_support" ] |
| 351 | } |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
| 355 | config("debug_symbols") { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 356 | cflags = [] |
| 357 | if (is_win) { |
| 358 | cflags = [ "/Od" ] |
| 359 | } else { |
| 360 | cflags = [ "-O0" ] |
| 361 | } |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 362 | if (is_android || is_linux) { |
| 363 | cflags += [ "-funwind-tables" ] |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 367 | config("release") { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 368 | # Compiler flags for release builds. |
| 369 | if (is_win) { |
| 370 | cflags = [ |
| 371 | "/O2", |
| 372 | "/Zc:inline", |
| 373 | ] |
| 374 | } else if (is_android) { |
| 375 | cflags = [ "-O2" ] |
Florian Mayer | 2e48071 | 2018-12-07 16:25:41 +0000 | [diff] [blame] | 376 | } else if (is_fuzzer) { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 377 | cflags = [ "-O1" ] |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 378 | } else { |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 379 | cflags = [ "-O3" ] |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 380 | } |
Primiano Tucci | 2f81155 | 2020-12-07 16:48:22 +0100 | [diff] [blame] | 381 | if (!is_win) { |
| 382 | cflags += [ |
| 383 | "-fdata-sections", |
| 384 | "-ffunction-sections", |
| 385 | ] |
| 386 | } |
| 387 | |
| 388 | # Linker flags for release builds. |
| 389 | if (is_win) { |
| 390 | ldflags = [ |
| 391 | "/OPT:REF", |
| 392 | "/OPT:ICF", |
| 393 | "/INCREMENTAL:NO", |
| 394 | "/FIXED:NO", |
| 395 | ] |
| 396 | } else if (is_mac) { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 397 | ldflags = [ "-dead_strip" ] |
Primiano Tucci | 7e9865c | 2021-01-10 23:55:15 +0100 | [diff] [blame] | 398 | } else if (!is_win && !is_wasm) { |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 399 | ldflags = [ |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 400 | "-Wl,--gc-sections", |
| 401 | "-Wl,--icf=all", |
| 402 | "-Wl,-O1", |
| 403 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 404 | } |
| 405 | defines = [ "NDEBUG" ] |
| 406 | } |
| 407 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 408 | config("shared_library") { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 409 | if (is_android || is_linux) { |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 410 | ldflags = [ "-fPIC" ] |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | config("executable") { |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 415 | ldflags = [] |
| 416 | |
| 417 | # Android will refuse to run executables if they aren't position independent. |
| 418 | # Instead on Linux there isn't any need and they break ASan (goo.gl/paFR6K). |
Florian Mayer | a74aaf0 | 2021-01-27 17:05:38 +0000 | [diff] [blame] | 419 | # The OSS-Fuzz provided AFL library is not PIC, so we we cannot use -fPIE |
| 420 | # for the fuzzer executables. |
| 421 | if ((is_android || is_linux) && !is_wasm && !is_fuzzer) { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 422 | asmflags = [ "-fPIE" ] |
| 423 | cflags = [ "-fPIE" ] |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 424 | ldflags += [ "-pie" ] |
| 425 | } |
| 426 | |
| 427 | # -rpath stores the path to the linked shared libraries into the binary, so |
| 428 | # that they can be launched without passing any LD_LIBRARY_PATH. It's |
| 429 | # supported only by Linux, not Android. But concretely we need this only when |
| 430 | # use_custom_libcxx=true && custom_libcxx_is_static=false, which happens only |
| 431 | # on Linux right now. |
Primiano Tucci | 7e9865c | 2021-01-10 23:55:15 +0100 | [diff] [blame] | 432 | if (is_linux && !is_wasm) { |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 433 | ldflags += [ |
| 434 | "-Wl,-rpath=\$ORIGIN/.", |
| 435 | "-Wl,-rpath-link=.", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 436 | ] |
| 437 | } |
| 438 | } |
Ryan Savitski | a3da9be | 2019-01-30 17:45:53 +0000 | [diff] [blame] | 439 | |
| 440 | # This config is only added to certain leaf target types (see BUILDCONFIG.gn). |
| 441 | # This allows us to remove the config (and thus the dependency) on a per-target |
| 442 | # basis. If the config was applied to source_sets, then they would unavoidably |
| 443 | # carry the dependency onto liblog to the final target. |
| 444 | config("android_liblog") { |
| 445 | if (is_android) { |
| 446 | libs = [ "log" ] |
| 447 | } |
| 448 | } |
Primiano Tucci | 00da64a | 2019-02-22 14:51:10 +0000 | [diff] [blame] | 449 | |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 450 | # Checks that tools/install-build-deps has been run since it last changed. |
| 451 | perfetto_check_build_deps("check_build_deps") { |
| 452 | args = [] |
| 453 | } |
| 454 | |
| 455 | perfetto_check_build_deps("check_build_deps_android") { |
| 456 | args = [ "--android" ] |
| 457 | } |