mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 1 | # Copyright 2016 Google Inc. |
| 2 | # |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
John Rosasco | 24cbdab | 2019-09-25 14:14:35 -0700 | [diff] [blame] | 6 | if (is_fuchsia) { |
Robert Phillips | c919f97 | 2019-11-18 11:01:05 -0500 | [diff] [blame] | 7 | import("//build/fuchsia/sdk.gni") |
John Rosasco | 24cbdab | 2019-09-25 14:14:35 -0700 | [diff] [blame] | 8 | } |
| 9 | |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 10 | declare_args() { |
Kevin Lubick | 2677a9a | 2017-03-28 15:45:41 -0400 | [diff] [blame] | 11 | extra_asmflags = [] |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 12 | extra_cflags = [] |
| 13 | extra_cflags_c = [] |
| 14 | extra_cflags_cc = [] |
| 15 | extra_ldflags = [] |
mtklein | cab0bb7 | 2016-08-26 13:43:19 -0700 | [diff] [blame] | 16 | |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 17 | malloc = "" |
Mike Klein | 29cb9f9 | 2020-06-19 16:25:12 -0500 | [diff] [blame] | 18 | werror = false |
Herb Derby | c65eb34 | 2019-10-18 14:29:09 -0400 | [diff] [blame] | 19 | xcode_sysroot = "" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 20 | } |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 21 | |
Herb Derby | c65eb34 | 2019-10-18 14:29:09 -0400 | [diff] [blame] | 22 | if (is_ios && xcode_sysroot == "") { |
Matthew Leibowitz | 3150ec6 | 2017-03-14 16:22:32 -0400 | [diff] [blame] | 23 | if (is_tvos) { |
| 24 | sdk = "appletvos" |
| 25 | if (target_cpu == "x86" || target_cpu == "x64") { |
| 26 | sdk = "appletvsimulator" |
| 27 | } |
| 28 | } else { |
| 29 | sdk = "iphoneos" |
| 30 | if (target_cpu == "x86" || target_cpu == "x64") { |
| 31 | sdk = "iphonesimulator" |
| 32 | } |
Mike Klein | 7a5e0f3 | 2017-03-13 09:25:33 -0700 | [diff] [blame] | 33 | } |
Herb Derby | c65eb34 | 2019-10-18 14:29:09 -0400 | [diff] [blame] | 34 | xcode_sysroot = exec_script("find_xcode_sysroot.py", [ sdk ], "trim string") |
| 35 | } |
| 36 | |
| 37 | # If building for mac on a mac then lookup all the system includes so that goma and the clang |
| 38 | # shipped with chrome can find them. When the gn_to_bp.py tool is run, then the host_os != mac. |
| 39 | # In this case leave the xcode_sysroot empty, and the cc/c++ that come with XCode will be able to |
| 40 | # find needed include paths. |
| 41 | if (is_mac && host_os == "mac" && xcode_sysroot == "") { |
| 42 | xcode_sysroot = |
| 43 | exec_script("find_xcode_sysroot.py", [ "macosx" ], "trim string") |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 44 | } |
| 45 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 46 | config("default") { |
| 47 | asmflags = [] |
| 48 | cflags = [] |
| 49 | cflags_c = [] |
| 50 | cflags_cc = [] |
| 51 | defines = [] |
| 52 | ldflags = [] |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 53 | libs = [] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 54 | |
Mike Klein | ba201ae | 2019-04-23 07:38:07 -0500 | [diff] [blame] | 55 | if (werror) { |
| 56 | if (is_win) { |
| 57 | cflags += [ "/WX" ] |
| 58 | } else { |
| 59 | cflags += [ "-Werror" ] |
| 60 | } |
| 61 | } |
| 62 | |
Mike Klein | 28abea5 | 2020-02-19 09:17:51 -0600 | [diff] [blame] | 63 | # Disable warnings about unknown attributes. |
| 64 | # (These unknown attribute warnings are on by default, so we don't make |
| 65 | # disabling them part of :warnings, as some targets remove :warnings.) |
| 66 | if (is_win && !is_clang) { |
| 67 | cflags += [ "/wd5030" ] |
| 68 | } else { |
| 69 | cflags += [ "-Wno-attributes" ] |
| 70 | } |
| 71 | |
John Rosasco | 24cbdab | 2019-09-25 14:14:35 -0700 | [diff] [blame] | 72 | if (is_fuchsia && using_fuchsia_sdk) { |
Robert Phillips | c919f97 | 2019-11-18 11:01:05 -0500 | [diff] [blame] | 73 | ldflags += [ |
| 74 | "-v", |
| 75 | "--sysroot=" + rebase_path("$fuchsia_sdk_path/arch/$target_cpu/sysroot"), |
| 76 | ] |
| 77 | cflags += [ "--sysroot=" + |
| 78 | rebase_path("$fuchsia_sdk_path/arch/$target_cpu/sysroot") ] |
John Rosasco | 24cbdab | 2019-09-25 14:14:35 -0700 | [diff] [blame] | 79 | if (target_cpu == "x64") { |
| 80 | target_triple = "--target=x86_64-${target_os}" |
| 81 | } else if (target_cpu == "arm64") { |
| 82 | target_triple = "--target=aarch64-unknown-${target_os}" |
| 83 | } else { |
| 84 | print("Unknown target CPU for Fuchsia target build.") |
| 85 | assert(false) |
| 86 | } |
| 87 | ldflags += [ target_triple ] |
| 88 | cflags += [ target_triple ] |
| 89 | asmflags += [ target_triple ] |
| 90 | } |
| 91 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 92 | if (is_win) { |
Mike Klein | da8a6e1 | 2019-04-17 08:18:10 -0500 | [diff] [blame] | 93 | if (is_clang && target_cpu == "arm64") { |
| 94 | cflags += [ "--target=arm64-windows" ] |
| 95 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 96 | cflags += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 97 | "/bigobj", # Some of our files are bigger than the regular limits. |
Ben Wagner | e6b274e | 2017-01-03 17:09:59 -0500 | [diff] [blame] | 98 | "/utf-8", # Set Source and Executable character sets to UTF-8. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 99 | ] |
Brian Salomon | 8283fa4 | 2019-11-07 10:42:41 -0500 | [diff] [blame] | 100 | cflags_cc += [ "/std:c++17" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 101 | defines += [ |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 102 | "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf(). |
| 103 | "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL. |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 104 | "WIN32_LEAN_AND_MEAN", |
| 105 | "NOMINMAX", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 106 | ] |
Mike Klein | 98adfa8 | 2017-07-31 15:46:47 -0400 | [diff] [blame] | 107 | |
Hal Canary | f72728e | 2019-07-10 11:24:52 -0400 | [diff] [blame] | 108 | _include_dirs = [ |
| 109 | "$win_vc/Tools/MSVC/$win_toolchain_version/include", |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 110 | "$win_sdk/Include/$win_sdk_version/shared", |
| 111 | "$win_sdk/Include/$win_sdk_version/ucrt", |
| 112 | "$win_sdk/Include/$win_sdk_version/um", |
| 113 | "$win_sdk/Include/$win_sdk_version/winrt", |
| 114 | ] |
| 115 | |
Mike Klein | 98adfa8 | 2017-07-31 15:46:47 -0400 | [diff] [blame] | 116 | if (is_clang) { |
| 117 | foreach(dir, _include_dirs) { |
| 118 | cflags += [ |
| 119 | "-imsvc", |
| 120 | dir, |
| 121 | ] |
| 122 | } |
| 123 | } else { |
| 124 | include_dirs = _include_dirs |
| 125 | } |
| 126 | |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 127 | lib_dirs = [ |
| 128 | "$win_sdk/Lib/$win_sdk_version/ucrt/$target_cpu", |
| 129 | "$win_sdk/Lib/$win_sdk_version/um/$target_cpu", |
Hal Canary | f72728e | 2019-07-10 11:24:52 -0400 | [diff] [blame] | 130 | "$win_vc/Tools/MSVC/$win_toolchain_version/lib/$target_cpu", |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 131 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 132 | } else { |
Shachar Langbeheim | 07c4e1d | 2019-12-16 10:46:52 +0200 | [diff] [blame] | 133 | cflags += [ |
| 134 | "-fstrict-aliasing", |
| 135 | "-fPIC", |
Mike Klein | ed80035 | 2020-08-04 12:06:23 -0500 | [diff] [blame] | 136 | "-fvisibility=hidden", |
Shachar Langbeheim | 07c4e1d | 2019-12-16 10:46:52 +0200 | [diff] [blame] | 137 | ] |
Mike Klein | ed80035 | 2020-08-04 12:06:23 -0500 | [diff] [blame] | 138 | cflags_cc += [ |
| 139 | "-std=c++17", |
| 140 | "-fvisibility-inlines-hidden", |
| 141 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 142 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 143 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 144 | if (current_cpu == "arm") { |
| 145 | cflags += [ |
| 146 | "-march=armv7-a", |
| 147 | "-mfpu=neon", |
| 148 | "-mthumb", |
| 149 | ] |
Mike Klein | 4d4b3aa | 2018-03-21 13:07:35 -0400 | [diff] [blame] | 150 | } else if (current_cpu == "x86" && !is_win) { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 151 | asmflags += [ "-m32" ] |
| 152 | cflags += [ |
| 153 | "-m32", |
| 154 | "-msse2", |
| 155 | "-mfpmath=sse", |
| 156 | ] |
| 157 | ldflags += [ "-m32" ] |
| 158 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 159 | |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 160 | if (malloc != "" && !is_win) { |
| 161 | cflags += [ |
| 162 | "-fno-builtin-malloc", |
| 163 | "-fno-builtin-calloc", |
| 164 | "-fno-builtin-realloc", |
| 165 | "-fno-builtin-free", |
| 166 | ] |
| 167 | libs += [ malloc ] |
| 168 | } |
| 169 | |
Hal Canary | a083404 | 2018-06-01 20:22:25 +0000 | [diff] [blame] | 170 | if (is_android) { |
Mike Klein | a957ac9 | 2020-11-12 08:33:07 -0600 | [diff] [blame] | 171 | cflags += [ "--sysroot=$ndk/toolchains/llvm/prebuilt/$ndk_host/sysroot" ] |
Mike Klein | 5b52c52 | 2019-07-03 10:44:21 -0500 | [diff] [blame] | 172 | ldflags += [ "-static-libstdc++" ] |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 173 | } |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 174 | |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 175 | if (is_ios) { |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 176 | if (target_cpu == "arm") { |
Mike Klein | a139788 | 2020-08-25 10:03:03 -0500 | [diff] [blame] | 177 | _arch_flags = [ |
| 178 | "-arch", |
| 179 | "armv7", |
| 180 | ] |
| 181 | } else if (target_cpu == "arm64") { |
| 182 | _arch_flags = [ |
| 183 | "-arch", |
| 184 | "arm64", |
| 185 | "-arch", |
| 186 | "arm64e", |
| 187 | ] |
Mike Klein | 7a5e0f3 | 2017-03-13 09:25:33 -0700 | [diff] [blame] | 188 | } else if (target_cpu == "x86") { |
Mike Klein | a139788 | 2020-08-25 10:03:03 -0500 | [diff] [blame] | 189 | _arch_flags = [ |
| 190 | "-arch", |
| 191 | "i386", |
| 192 | ] |
Mike Klein | 7a5e0f3 | 2017-03-13 09:25:33 -0700 | [diff] [blame] | 193 | } else if (target_cpu == "x64") { |
Mike Klein | a139788 | 2020-08-25 10:03:03 -0500 | [diff] [blame] | 194 | _arch_flags = [ |
| 195 | "-arch", |
| 196 | "x86_64", |
| 197 | ] |
| 198 | } else { |
| 199 | _arch_flags = [ |
| 200 | "-arch", |
| 201 | target_cpu, |
| 202 | ] |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 203 | } |
Mike Klein | a139788 | 2020-08-25 10:03:03 -0500 | [diff] [blame] | 204 | |
Mike Klein | 4fe2b15 | 2017-02-17 15:36:01 -0500 | [diff] [blame] | 205 | asmflags += [ |
Mike Klein | a139788 | 2020-08-25 10:03:03 -0500 | [diff] [blame] | 206 | "-isysroot", |
| 207 | xcode_sysroot, |
| 208 | ] + _arch_flags |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 209 | cflags += [ |
Mike Klein | a139788 | 2020-08-25 10:03:03 -0500 | [diff] [blame] | 210 | "-isysroot", |
| 211 | xcode_sysroot, |
| 212 | ] + _arch_flags |
Brian Salomon | 8283fa4 | 2019-11-07 10:42:41 -0500 | [diff] [blame] | 213 | cflags_cc += [ |
| 214 | "-stdlib=libc++", |
| 215 | "-fno-aligned-allocation", |
| 216 | ] |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 217 | ldflags += [ |
Mike Klein | a139788 | 2020-08-25 10:03:03 -0500 | [diff] [blame] | 218 | "-isysroot", |
| 219 | xcode_sysroot, |
| 220 | "-stdlib=libc++", |
| 221 | ] + _arch_flags |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 222 | libs += [ "objc" ] |
Jim Van Verth | 2d36627 | 2020-11-18 15:44:04 -0500 | [diff] [blame] | 223 | if (ios_min_target != "") { |
| 224 | cflags += [ "-miphoneos-version-min=$ios_min_target" ] |
| 225 | asmflags += [ "-miphoneos-version-min=$ios_min_target" ] |
| 226 | ldflags += [ "-miphoneos-version-min=$ios_min_target" ] |
| 227 | } |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 228 | } |
| 229 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 230 | if (is_linux) { |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 231 | libs += [ "pthread" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 232 | } |
Herb Derby | c65eb34 | 2019-10-18 14:29:09 -0400 | [diff] [blame] | 233 | |
Mike Klein | 15f46c3 | 2017-12-07 12:48:57 -0500 | [diff] [blame] | 234 | if (is_mac) { |
Herb Derby | c65eb34 | 2019-10-18 14:29:09 -0400 | [diff] [blame] | 235 | # If there was a xcode_sysroot set in args or calculated then use it, else don't set anything |
| 236 | # because the XCode cc/c++ already know all this stuff. |
| 237 | if (xcode_sysroot != "") { |
| 238 | asmflags += [ |
| 239 | "-isysroot", |
| 240 | xcode_sysroot, |
| 241 | ] |
| 242 | cflags += [ |
| 243 | "-isysroot", |
| 244 | xcode_sysroot, |
| 245 | ] |
| 246 | ldflags += [ |
| 247 | "-isysroot", |
| 248 | xcode_sysroot, |
| 249 | ] |
| 250 | } |
| 251 | |
Mike Klein | 15f46c3 | 2017-12-07 12:48:57 -0500 | [diff] [blame] | 252 | # Disable linker warnings. They're usually just annoyances like, |
| 253 | # ld: warning: text-based stub file |
| 254 | # /System/Library/Frameworks/foo.framework/foo.tbd and library file |
| 255 | # /System/Library/Frameworks/foo.framework/foo are out of sync. |
| 256 | # Falling back to library file for linking. |
| 257 | ldflags += [ "-Wl,-w" ] |
Herb Derby | 7e58179 | 2020-10-20 12:35:51 -0400 | [diff] [blame] | 258 | |
| 259 | # As of 11/2020, gn is an x86 binary and defaults the host_cpu to x86_64. |
| 260 | # This allows you to build arm64 mac binaries by setting target_cpu = "arm64" |
| 261 | if (current_cpu == "arm64") { |
| 262 | asmflags += [ |
| 263 | "-target", |
| 264 | "arm64-apple-macos11", |
| 265 | ] |
| 266 | cflags += [ |
| 267 | "-target", |
| 268 | "arm64-apple-macos11", |
| 269 | ] |
| 270 | ldflags += [ |
| 271 | "-target", |
| 272 | "arm64-apple-macos11", |
| 273 | ] |
| 274 | } |
Mike Klein | 15f46c3 | 2017-12-07 12:48:57 -0500 | [diff] [blame] | 275 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 276 | |
Brian Osman | 50ea3c0 | 2019-02-04 10:01:53 -0500 | [diff] [blame] | 277 | if (sanitize != "" && sanitize != "MSVC") { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 278 | # You can either pass the sanitizers directly, e.g. "address,undefined", |
| 279 | # or pass one of the couple common aliases used by the bots. |
| 280 | sanitizers = sanitize |
Kevin Lubick | d095040 | 2018-03-20 10:10:58 -0400 | [diff] [blame] | 281 | |
Ben Wagner | b6f98ea | 2019-12-21 00:53:11 -0500 | [diff] [blame] | 282 | if (sanitize == "ASAN") { |
Ben Wagner | 314d7c2 | 2018-01-03 11:04:30 -0500 | [diff] [blame] | 283 | # ASAN implicitly runs all UBSAN checks also. |
Ben Wagner | b6f98ea | 2019-12-21 00:53:11 -0500 | [diff] [blame] | 284 | sanitizers = "undefined,address" |
Kevin Lubick | 4f0f933 | 2018-01-12 14:31:48 -0500 | [diff] [blame] | 285 | |
Mike Klein | 02046a7 | 2018-08-10 12:25:12 -0400 | [diff] [blame] | 286 | if (is_android) { |
| 287 | # TODO(mtklein): work out UBSAN link errors |
| 288 | sanitizers = "address" |
Kevin Lubick | 4f0f933 | 2018-01-12 14:31:48 -0500 | [diff] [blame] | 289 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 290 | } else if (sanitize == "TSAN") { |
| 291 | sanitizers = "thread" |
| 292 | } else if (sanitize == "MSAN") { |
| 293 | sanitizers = "memory" |
| 294 | } |
| 295 | |
Mike Klein | d26b3e2 | 2020-07-24 12:16:50 -0500 | [diff] [blame] | 296 | _suppressions = rebase_path("../tools/xsan.supp") |
Mike Klein | 475c5e9 | 2018-08-08 10:23:17 -0400 | [diff] [blame] | 297 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 298 | cflags += [ |
Mike Klein | 02046a7 | 2018-08-10 12:25:12 -0400 | [diff] [blame] | 299 | "-fsanitize=$sanitizers", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 300 | "-fno-sanitize-recover=$sanitizers", |
Mike Klein | d26b3e2 | 2020-07-24 12:16:50 -0500 | [diff] [blame] | 301 | "-fsanitize-blacklist=$_suppressions", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 302 | ] |
Mike Klein | cdb0e8f | 2019-12-18 14:25:50 -0600 | [diff] [blame] | 303 | |
Mike Klein | 94c4f41 | 2018-08-09 17:24:45 -0400 | [diff] [blame] | 304 | if (is_win) { |
Ben Wagner | b6f98ea | 2019-12-21 00:53:11 -0500 | [diff] [blame] | 305 | cflags += [ |
Mike Klein | d26b3e2 | 2020-07-24 12:16:50 -0500 | [diff] [blame] | 306 | "/FI$_suppressions", |
Ben Wagner | b6f98ea | 2019-12-21 00:53:11 -0500 | [diff] [blame] | 307 | |
| 308 | # On Release builds, we get strange warnings about string literals. |
| 309 | "/GF-", |
| 310 | ] |
| 311 | |
| 312 | assert(clang_win != "") |
| 313 | libs += [ "$clang_win/lib/clang/$clang_win_version/lib/windows/clang_rt.asan-x86_64.lib" ] |
Mike Klein | 94c4f41 | 2018-08-09 17:24:45 -0400 | [diff] [blame] | 314 | } else { |
| 315 | cflags += [ |
Mike Klein | d26b3e2 | 2020-07-24 12:16:50 -0500 | [diff] [blame] | 316 | "-include$_suppressions", |
Mike Klein | 94c4f41 | 2018-08-09 17:24:45 -0400 | [diff] [blame] | 317 | "-fno-omit-frame-pointer", |
| 318 | ] |
Ben Wagner | b6f98ea | 2019-12-21 00:53:11 -0500 | [diff] [blame] | 319 | |
| 320 | ldflags += [ "-fsanitize=$sanitizers" ] |
Kevin Lubick | 5798c9f | 2018-02-15 09:45:58 -0500 | [diff] [blame] | 321 | } |
Mike Klein | 94c4f41 | 2018-08-09 17:24:45 -0400 | [diff] [blame] | 322 | |
Kevin Lubick | 5798c9f | 2018-02-15 09:45:58 -0500 | [diff] [blame] | 323 | if (is_linux) { |
Kevin Lubick | 43bd259 | 2018-02-15 09:03:44 -0500 | [diff] [blame] | 324 | cflags_cc += [ "-stdlib=libc++" ] |
| 325 | ldflags += [ "-stdlib=libc++" ] |
Kevin Lubick | 3cda39f | 2018-02-01 12:09:55 -0500 | [diff] [blame] | 326 | } |
Mike Klein | 02046a7 | 2018-08-10 12:25:12 -0400 | [diff] [blame] | 327 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 328 | if (sanitizers == "memory") { |
| 329 | cflags += [ "-fsanitize-memory-track-origins" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 330 | } |
Brian Salomon | 8283fa4 | 2019-11-07 10:42:41 -0500 | [diff] [blame] | 331 | if (sanitizers == "safe-stack") { |
| 332 | cflags_cc += [ "-fno-aligned-allocation" ] |
| 333 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
Mike Klein | c0c0522 | 2020-01-31 11:07:51 -0600 | [diff] [blame] | 337 | # See skia:9731. |
| 338 | config("recover_pointer_overflow") { |
| 339 | cflags = [ "-fsanitize-recover=pointer-overflow" ] |
| 340 | } |
| 341 | |
Mike Klein | 6e55fef | 2016-10-26 11:41:47 -0400 | [diff] [blame] | 342 | config("no_exceptions") { |
Mike Klein | 228276d | 2017-08-16 13:20:20 +0000 | [diff] [blame] | 343 | # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.) |
Mike Klein | 6e55fef | 2016-10-26 11:41:47 -0400 | [diff] [blame] | 344 | if (!is_win) { |
| 345 | cflags_cc = [ "-fno-exceptions" ] |
| 346 | } |
| 347 | } |
| 348 | |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 349 | config("warnings") { |
| 350 | cflags = [] |
| 351 | cflags_cc = [] |
Mike Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 352 | cflags_objc = [] |
Greg Daniel | 6b7e0e2 | 2017-07-12 16:21:09 -0400 | [diff] [blame] | 353 | cflags_objcc = [] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 354 | if (is_win) { |
| 355 | cflags += [ |
| 356 | "/W3", # Turn on lots of warnings. |
| 357 | |
| 358 | # Disable a bunch of warnings: |
| 359 | "/wd4244", # conversion from 'float' to 'int', possible loss of data |
| 360 | "/wd4267", # conversion from 'size_t' to 'int', possible loss of data |
Mike Klein | a01c6b0 | 2020-04-01 13:47:34 -0500 | [diff] [blame] | 361 | "/wd4800", # forcing value to bool 'true' or 'false' (performance |
| 362 | # warning) |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 363 | |
| 364 | # Probably only triggers when /EHsc is enabled. |
| 365 | "/wd4291", # no matching operator delete found; |
Mike Klein | a01c6b0 | 2020-04-01 13:47:34 -0500 | [diff] [blame] | 366 | # memory will not be freed if initialization throws an |
| 367 | # exception |
Brian Osman | eec1e9e | 2019-04-10 16:22:15 -0400 | [diff] [blame] | 368 | |
| 369 | # These only show up in shared builds: |
Mike Klein | a01c6b0 | 2020-04-01 13:47:34 -0500 | [diff] [blame] | 370 | "/wd4251", # class 'type' needs to have dll-interface to be used by |
| 371 | # clients of class 'type2' |
| 372 | "/wd4275", # non dll-interface class 'base' used as base for |
| 373 | # dll-interface class 'derived' |
Brian Salomon | 8283fa4 | 2019-11-07 10:42:41 -0500 | [diff] [blame] | 374 | |
| 375 | # It'd be nice to fix these and turn this on: |
Mike Klein | a01c6b0 | 2020-04-01 13:47:34 -0500 | [diff] [blame] | 376 | "/wd5041", # out-of-line definition for constexpr static data member is |
| 377 | # not needed and is deprecated in C++17 |
Mike Klein | dc976a9 | 2020-04-30 06:45:25 -0500 | [diff] [blame] | 378 | |
| 379 | # warning C4996: 'std::result_of_t': warning STL4014: std::result_of and std::result_of_t are |
| 380 | # deprecated in C++17. They are superseded by std::invoke_result and std::invoke_result_t. |
| 381 | "/wd4996", |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 382 | ] |
| 383 | } else { |
| 384 | cflags += [ |
| 385 | "-Wall", |
| 386 | "-Wextra", |
| 387 | "-Winit-self", |
| 388 | "-Wpointer-arith", |
| 389 | "-Wsign-compare", |
| 390 | "-Wvla", |
| 391 | |
| 392 | "-Wno-deprecated-declarations", |
Mike Klein | db402ca | 2016-12-13 12:46:05 -0500 | [diff] [blame] | 393 | "-Wno-maybe-uninitialized", |
Mike Klein | 90b027a | 2020-09-02 09:09:11 -0500 | [diff] [blame] | 394 | "-Wno-psabi", |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 395 | ] |
Ben Wagner | f8a131d | 2018-03-13 16:56:43 -0400 | [diff] [blame] | 396 | cflags_cc += [ |
| 397 | "-Wnon-virtual-dtor", |
| 398 | "-Wno-noexcept-type", |
Ben Wagner | 7363af8 | 2020-03-27 14:29:38 -0400 | [diff] [blame] | 399 | "-Wno-redundant-move", #TODO: gcc conflict with return-std-move-in-c++11 |
Ben Wagner | f8a131d | 2018-03-13 16:56:43 -0400 | [diff] [blame] | 400 | ] |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 401 | } |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 402 | |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 403 | if (is_clang) { |
| 404 | cflags += [ |
Mike Klein | b7b2da8 | 2019-02-28 08:47:44 -0600 | [diff] [blame] | 405 | "-fcolor-diagnostics", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 406 | "-Weverything", |
Mike Klein | a01c6b0 | 2020-04-01 13:47:34 -0500 | [diff] [blame] | 407 | "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' |
| 408 | # warnings. |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 409 | ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 410 | |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 411 | if (target_cpu == "arm" && is_ios) { |
| 412 | # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS. |
| 413 | # We're pretty sure it's actually 8-byte alignment. |
| 414 | cflags += [ "-Wno-over-aligned" ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 415 | } |
Mike Klein | 0428279 | 2018-01-08 18:23:32 -0500 | [diff] [blame] | 416 | if (target_cpu == "x86" && is_android) { |
| 417 | # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds. |
| 418 | # We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info. |
| 419 | cflags += [ "-Wno-over-aligned" ] |
| 420 | } |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 421 | |
| 422 | # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose |
| 423 | # their case during copy, causing case-sensitivity mismatch on remote machines. |
| 424 | cflags += [ |
| 425 | "-Wno-nonportable-include-path", |
| 426 | "-Wno-nonportable-system-include-path", |
| 427 | ] |
| 428 | |
| 429 | # TODO: These would all be really great warnings to turn on. |
| 430 | cflags += [ |
| 431 | "-Wno-cast-align", |
| 432 | "-Wno-cast-qual", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 433 | "-Wno-conversion", |
| 434 | "-Wno-disabled-macro-expansion", |
| 435 | "-Wno-documentation", |
| 436 | "-Wno-documentation-unknown-command", |
| 437 | "-Wno-double-promotion", |
| 438 | "-Wno-exit-time-destructors", # TODO: OK outside libskia |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 439 | "-Wno-float-equal", |
| 440 | "-Wno-format-nonliteral", |
| 441 | "-Wno-global-constructors", # TODO: OK outside libskia |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 442 | "-Wno-missing-prototypes", |
| 443 | "-Wno-missing-variable-declarations", |
| 444 | "-Wno-pedantic", |
| 445 | "-Wno-reserved-id-macro", |
| 446 | "-Wno-shadow", |
| 447 | "-Wno-shift-sign-overflow", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 448 | "-Wno-signed-enum-bitfield", |
| 449 | "-Wno-switch-enum", |
| 450 | "-Wno-undef", |
| 451 | "-Wno-unreachable-code", |
| 452 | "-Wno-unreachable-code-break", |
| 453 | "-Wno-unreachable-code-return", |
| 454 | "-Wno-unused-macros", |
| 455 | "-Wno-unused-member-function", |
| 456 | "-Wno-unused-template", |
| 457 | "-Wno-zero-as-null-pointer-constant", |
Herb Derby | a1b7be6 | 2019-05-09 16:59:18 -0400 | [diff] [blame] | 458 | "-Wno-thread-safety-negative", |
Mike Klein | fdd542f | 2020-06-02 11:41:55 -0500 | [diff] [blame] | 459 | "-Wno-non-c-typedef-for-linkage", # Dawn, not Skia per se. |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 460 | ] |
| 461 | cflags_cc += [ |
| 462 | "-Wno-abstract-vbase-init", |
| 463 | "-Wno-weak-vtables", |
| 464 | ] |
| 465 | |
Mike Klein | 89c909e | 2020-06-01 15:50:19 -0500 | [diff] [blame] | 466 | # Turn back on after -Wno-conversion. |
| 467 | # This only affects public headers... see :warnings_except_public_headers. |
| 468 | cflags += [ "-Wsign-conversion" ] |
| 469 | |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 470 | # We are unlikely to want to fix these. |
| 471 | cflags += [ |
| 472 | "-Wno-covered-switch-default", |
| 473 | "-Wno-deprecated", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 474 | "-Wno-missing-noreturn", |
| 475 | "-Wno-old-style-cast", |
| 476 | "-Wno-padded", |
Chris Dalton | d1ec410 | 2017-12-04 13:31:21 -0700 | [diff] [blame] | 477 | "-Wno-newline-eof", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 478 | ] |
| 479 | cflags_cc += [ |
| 480 | "-Wno-c++98-compat", |
| 481 | "-Wno-c++98-compat-pedantic", |
| 482 | "-Wno-undefined-func-template", |
| 483 | ] |
| 484 | cflags_objc += [ |
| 485 | "-Wno-direct-ivar-access", |
| 486 | "-Wno-objc-interface-ivars", |
| 487 | ] |
| 488 | cflags_objcc += [ |
| 489 | "-Wno-direct-ivar-access", |
| 490 | "-Wno-objcc-interface-ivars", |
| 491 | ] |
Ben Wagner | 833313b | 2020-03-23 17:22:24 -0400 | [diff] [blame] | 492 | |
| 493 | # Wno-deprecated turns off the whole group, but also has its own warnings like |
| 494 | # out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated [-Werror,-Wdeprecated] |
| 495 | # but we would like others. Created from clang/include/clang/Basic/DiagnosticGroups.td |
| 496 | cflags += [ |
| 497 | "-Wdeprecated-anon-enum-enum-conversion", |
| 498 | "-Wdeprecated-array-compare", |
| 499 | "-Wdeprecated-attributes", |
| 500 | "-Wdeprecated-comma-subscript", |
| 501 | "-Wdeprecated-copy", |
Ben Wagner | 7345d88 | 2020-03-27 11:28:03 -0400 | [diff] [blame] | 502 | |
John Stiles | 3744b2a | 2020-11-04 15:23:31 +0000 | [diff] [blame] | 503 | #"-Wdeprecated-copy-dtor", |
Ben Wagner | 833313b | 2020-03-23 17:22:24 -0400 | [diff] [blame] | 504 | #"-Wdeprecated-declarations", |
| 505 | "-Wdeprecated-dynamic-exception-spec", |
| 506 | "-Wdeprecated-enum-compare", |
| 507 | "-Wdeprecated-enum-compare-conditional", |
| 508 | "-Wdeprecated-enum-enum-conversion", |
| 509 | "-Wdeprecated-enum-float-conversion", |
| 510 | "-Wdeprecated-increment-bool", |
| 511 | "-Wdeprecated-register", |
| 512 | "-Wdeprecated-this-capture", |
| 513 | "-Wdeprecated-volatile", |
| 514 | "-Wdeprecated-writable-str", |
| 515 | ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 516 | } |
| 517 | } |
Mike Klein | 50500ad | 2016-11-16 12:13:44 -0500 | [diff] [blame] | 518 | config("warnings_except_public_headers") { |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 519 | if (!is_win || is_clang) { |
Mike Klein | 89c909e | 2020-06-01 15:50:19 -0500 | [diff] [blame] | 520 | cflags = [ |
| 521 | "-Wno-sign-conversion", |
| 522 | "-Wno-unused-parameter", |
| 523 | ] |
Mike Klein | 50500ad | 2016-11-16 12:13:44 -0500 | [diff] [blame] | 524 | } |
| 525 | } |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 526 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 527 | config("extra_flags") { |
Kevin Lubick | 2677a9a | 2017-03-28 15:45:41 -0400 | [diff] [blame] | 528 | asmflags = extra_asmflags |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 529 | cflags = extra_cflags |
| 530 | cflags_c = extra_cflags_c |
| 531 | cflags_cc = extra_cflags_cc |
| 532 | ldflags = extra_ldflags |
| 533 | } |
| 534 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 535 | config("debug_symbols") { |
| 536 | # It's annoying to wait for full debug symbols to push over |
| 537 | # to Android devices. -gline-tables-only is a lot slimmer. |
| 538 | if (is_android) { |
Mike Klein | 1b4602b | 2017-08-30 10:23:01 -0400 | [diff] [blame] | 539 | cflags = [ |
| 540 | "-gline-tables-only", |
| 541 | "-funwind-tables", # Helps make in-process backtraces fuller. |
| 542 | ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 543 | } else if (is_win) { |
Mike Klein | 67a86d5 | 2017-12-15 07:34:27 -0500 | [diff] [blame] | 544 | cflags = [ "/Z7" ] |
Brian Osman | 7142ae5 | 2018-12-12 16:32:35 -0500 | [diff] [blame] | 545 | if (is_clang) { |
Eric Boren | 56bf8ce | 2019-02-07 13:05:06 -0500 | [diff] [blame] | 546 | cflags += [ "-gcodeview-ghash" ] |
Mike Klein | cae020a | 2018-12-23 10:25:44 -0500 | [diff] [blame] | 547 | ldflags = [ "/DEBUG:GHASH" ] |
Brian Osman | 7142ae5 | 2018-12-12 16:32:35 -0500 | [diff] [blame] | 548 | } else { |
Mike Klein | a6e0c2b | 2018-12-10 08:48:03 -0500 | [diff] [blame] | 549 | ldflags = [ "/DEBUG:FASTLINK" ] |
Brian Osman | 0ab5684 | 2018-09-13 15:46:02 -0400 | [diff] [blame] | 550 | } |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 551 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 552 | cflags = [ "-g" ] |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | config("no_rtti") { |
| 557 | if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 558 | if (is_win) { |
| 559 | cflags_cc = [ "/GR-" ] |
| 560 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 561 | cflags_cc = [ "-fno-rtti" ] |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
Mike Klein | 7ea977b | 2018-09-19 13:44:43 -0400 | [diff] [blame] | 566 | config("optimize") { |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 567 | if (is_win) { |
Mike Klein | 916ca1d | 2016-10-20 13:34:18 -0400 | [diff] [blame] | 568 | cflags = [ |
| 569 | "/O2", |
| 570 | "/Zc:inline", |
| 571 | ] |
Mike Klein | 90a381f | 2016-10-20 13:52:38 -0400 | [diff] [blame] | 572 | ldflags = [ |
| 573 | "/OPT:ICF", |
| 574 | "/OPT:REF", |
| 575 | ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 576 | } else { |
Mike Klein | 13daa4f | 2019-06-20 10:08:55 -0500 | [diff] [blame] | 577 | cflags = [ "-O3" ] |
Mike Klein | bd9be4d | 2017-02-10 07:59:39 -0500 | [diff] [blame] | 578 | if (is_mac || is_ios) { |
| 579 | ldflags = [ "-dead_strip" ] |
| 580 | } else { |
Mike Klein | 13daa4f | 2019-06-20 10:08:55 -0500 | [diff] [blame] | 581 | cflags += [ |
| 582 | "-fdata-sections", |
| 583 | "-ffunction-sections", |
| 584 | ] |
Mike Klein | bd9be4d | 2017-02-10 07:59:39 -0500 | [diff] [blame] | 585 | ldflags = [ "-Wl,--gc-sections" ] |
| 586 | } |
Kevin Lubick | ebf648e | 2017-09-21 13:45:16 -0400 | [diff] [blame] | 587 | if (target_cpu == "wasm") { |
| 588 | # The compiler asks us to add an optimization flag to both cflags |
| 589 | # and ldflags to cut down on the local variables, |
| 590 | # for performance reasons. |
| 591 | # The "linking" step is the conversion to javascript. |
| 592 | ldflags += [ "-O3" ] |
| 593 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 594 | } |
Mike Klein | 7ea977b | 2018-09-19 13:44:43 -0400 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | config("NDEBUG") { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 598 | defines = [ "NDEBUG" ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | config("executable") { |
Mike Klein | c5875fb | 2016-12-06 10:46:02 -0500 | [diff] [blame] | 602 | if (is_android) { |
Mike Klein | 1b4602b | 2017-08-30 10:23:01 -0400 | [diff] [blame] | 603 | ldflags = [ |
| 604 | "-pie", |
| 605 | "-rdynamic", |
| 606 | ] |
Mike Klein | c5875fb | 2016-12-06 10:46:02 -0500 | [diff] [blame] | 607 | } else if (is_mac) { |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 608 | ldflags = [ "-Wl,-rpath,@loader_path/." ] |
| 609 | } else if (is_linux) { |
mtklein | a846c72 | 2016-09-15 10:44:15 -0700 | [diff] [blame] | 610 | ldflags = [ |
| 611 | "-rdynamic", |
| 612 | "-Wl,-rpath,\$ORIGIN", |
| 613 | ] |
Mike Klein | 4b6b503 | 2016-11-06 11:54:19 -0500 | [diff] [blame] | 614 | } else if (is_win) { |
| 615 | ldflags = [ |
| 616 | "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed". |
Mike Klein | a01c6b0 | 2020-04-01 13:47:34 -0500 | [diff] [blame] | 617 | "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link |
| 618 | # by never trying to. |
Mike Klein | 4b6b503 | 2016-11-06 11:54:19 -0500 | [diff] [blame] | 619 | ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 620 | } |
| 621 | } |