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