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 | |
| 6 | declare_args() { |
Kevin Lubick | 2677a9a | 2017-03-28 15:45:41 -0400 | [diff] [blame] | 7 | extra_asmflags = [] |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 8 | extra_cflags = [] |
| 9 | extra_cflags_c = [] |
| 10 | extra_cflags_cc = [] |
| 11 | extra_ldflags = [] |
mtklein | cab0bb7 | 2016-08-26 13:43:19 -0700 | [diff] [blame] | 12 | |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 13 | malloc = "" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 14 | } |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 15 | |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 16 | if (is_ios) { |
Matthew Leibowitz | 3150ec6 | 2017-03-14 16:22:32 -0400 | [diff] [blame] | 17 | if (is_tvos) { |
| 18 | sdk = "appletvos" |
| 19 | if (target_cpu == "x86" || target_cpu == "x64") { |
| 20 | sdk = "appletvsimulator" |
| 21 | } |
| 22 | } else { |
| 23 | sdk = "iphoneos" |
| 24 | if (target_cpu == "x86" || target_cpu == "x64") { |
| 25 | sdk = "iphonesimulator" |
| 26 | } |
Mike Klein | 7a5e0f3 | 2017-03-13 09:25:33 -0700 | [diff] [blame] | 27 | } |
| 28 | ios_sysroot = exec_script("find_ios_sysroot.py", [ sdk ], "trim string") |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 29 | } |
| 30 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 31 | config("default") { |
| 32 | asmflags = [] |
| 33 | cflags = [] |
| 34 | cflags_c = [] |
| 35 | cflags_cc = [] |
| 36 | defines = [] |
| 37 | ldflags = [] |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 38 | libs = [] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 39 | |
| 40 | if (is_win) { |
| 41 | cflags += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 42 | "/bigobj", # Some of our files are bigger than the regular limits. |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 43 | "/WX", # Treat warnings as errors. |
Ben Wagner | e6b274e | 2017-01-03 17:09:59 -0500 | [diff] [blame] | 44 | "/utf-8", # Set Source and Executable character sets to UTF-8. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 45 | ] |
Mike Klein | a91ec58 | 2017-07-31 16:35:17 -0400 | [diff] [blame] | 46 | if (is_clang) { |
| 47 | cflags += [ "-fms-compatibility-version=19" ] # 2015 |
| 48 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 49 | defines += [ |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 50 | "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf(). |
| 51 | "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL. |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 52 | "WIN32_LEAN_AND_MEAN", |
| 53 | "NOMINMAX", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 54 | ] |
Mike Klein | 98adfa8 | 2017-07-31 15:46:47 -0400 | [diff] [blame] | 55 | |
Brian Osman | d34c4a3 | 2017-12-06 13:26:38 -0500 | [diff] [blame] | 56 | if (msvc == 2015) { |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 57 | _include_dirs = [ "$win_vc/include" ] |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 58 | } else { # 2017 |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 59 | _include_dirs = [ "$win_vc/Tools/MSVC/$win_toolchain_version/include" ] |
Ravi Mistry | f5ab269 | 2017-12-06 21:51:23 +0000 | [diff] [blame] | 60 | } |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 61 | _include_dirs += [ |
| 62 | "$win_sdk/Include/$win_sdk_version/shared", |
| 63 | "$win_sdk/Include/$win_sdk_version/ucrt", |
| 64 | "$win_sdk/Include/$win_sdk_version/um", |
| 65 | "$win_sdk/Include/$win_sdk_version/winrt", |
| 66 | ] |
| 67 | |
Mike Klein | 98adfa8 | 2017-07-31 15:46:47 -0400 | [diff] [blame] | 68 | if (is_clang) { |
| 69 | foreach(dir, _include_dirs) { |
| 70 | cflags += [ |
| 71 | "-imsvc", |
| 72 | dir, |
| 73 | ] |
| 74 | } |
| 75 | } else { |
| 76 | include_dirs = _include_dirs |
| 77 | } |
| 78 | |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 79 | lib_dirs = [ |
| 80 | "$win_sdk/Lib/$win_sdk_version/ucrt/$target_cpu", |
| 81 | "$win_sdk/Lib/$win_sdk_version/um/$target_cpu", |
| 82 | ] |
Brian Osman | d34c4a3 | 2017-12-06 13:26:38 -0500 | [diff] [blame] | 83 | if (msvc == 2015) { |
Brian Osman | d34c4a3 | 2017-12-06 13:26:38 -0500 | [diff] [blame] | 84 | if (target_cpu == "x86") { |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 85 | lib_dirs += [ "$win_vc/lib" ] |
Brian Osman | d34c4a3 | 2017-12-06 13:26:38 -0500 | [diff] [blame] | 86 | } else { |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 87 | lib_dirs += [ "$win_vc/lib/amd64" ] |
Brian Osman | d34c4a3 | 2017-12-06 13:26:38 -0500 | [diff] [blame] | 88 | } |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 89 | } else { # 2017 |
| 90 | lib_dirs += |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 91 | [ "$win_vc/Tools/MSVC/$win_toolchain_version/lib/$target_cpu" ] |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 92 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 93 | } else { |
| 94 | cflags += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 95 | "-fstrict-aliasing", |
| 96 | "-fPIC", |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 97 | ] |
Brian Salomon | 7258e97 | 2018-06-02 11:18:33 -0400 | [diff] [blame] | 98 | cflags_cc += [ "-std=c++14" ] |
Mike Klein | eec23d1 | 2017-03-26 20:11:48 -0400 | [diff] [blame] | 99 | |
| 100 | # The main idea is to slim the exported API, but these flags also improve link time on Mac. |
| 101 | # 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] | 102 | if (is_component_build || is_ios || is_mac) { |
Mike Klein | eec23d1 | 2017-03-26 20:11:48 -0400 | [diff] [blame] | 103 | cflags += [ "-fvisibility=hidden" ] |
| 104 | cflags_cc += [ "-fvisibility-inlines-hidden" ] |
| 105 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 106 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 107 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 108 | if (current_cpu == "arm") { |
| 109 | cflags += [ |
| 110 | "-march=armv7-a", |
| 111 | "-mfpu=neon", |
| 112 | "-mthumb", |
| 113 | ] |
Ben Wagner | 9bd736b | 2018-04-04 15:35:01 -0400 | [diff] [blame] | 114 | } else if (current_cpu == "loongson3a") { |
| 115 | asmflags += [ "-march=loongson3a" ] |
| 116 | cflags += [ |
| 117 | "-march=loongson3a", |
| 118 | |
| 119 | # Causes an internal compiler error. |
| 120 | "-DSKCMS_PORTABLE", |
| 121 | ] |
| 122 | } else if (current_cpu == "mips64el") { |
| 123 | asmflags += [ "-march=mips64" ] |
| 124 | cflags += [ "-march=mips64" ] |
Mike Klein | 4d4b3aa | 2018-03-21 13:07:35 -0400 | [diff] [blame] | 125 | } else if (current_cpu == "x86" && !is_win) { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 126 | asmflags += [ "-m32" ] |
| 127 | cflags += [ |
| 128 | "-m32", |
| 129 | "-msse2", |
| 130 | "-mfpmath=sse", |
| 131 | ] |
| 132 | ldflags += [ "-m32" ] |
| 133 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 134 | |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 135 | if (malloc != "" && !is_win) { |
| 136 | cflags += [ |
| 137 | "-fno-builtin-malloc", |
| 138 | "-fno-builtin-calloc", |
| 139 | "-fno-builtin-realloc", |
| 140 | "-fno-builtin-free", |
| 141 | ] |
| 142 | libs += [ malloc ] |
| 143 | } |
| 144 | |
Hal Canary | a083404 | 2018-06-01 20:22:25 +0000 | [diff] [blame] | 145 | if (is_android) { |
Derek Sollenberger | 19b2a56 | 2017-06-27 11:55:05 -0400 | [diff] [blame] | 146 | asmflags += [ "--target=$ndk_target" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 147 | cflags += [ |
Derek Sollenberger | 19b2a56 | 2017-06-27 11:55:05 -0400 | [diff] [blame] | 148 | "--sysroot=$ndk/sysroot", |
| 149 | "-isystem$ndk/sysroot/usr/include/$ndk_target", |
| 150 | "-D__ANDROID_API__=$ndk_api", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 151 | "--target=$ndk_target", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 152 | ] |
| 153 | cflags_cc += [ |
Mike Klein | 21b620c | 2018-01-08 17:16:00 -0500 | [diff] [blame] | 154 | "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", |
| 155 | "-isystem$ndk/sources/cxx-stl/llvm-libc++abi/include", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 156 | "-isystem$ndk/sources/android/support/include", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 157 | ] |
| 158 | ldflags += [ |
| 159 | "--sysroot=$ndk/platforms/$ndk_platform", |
| 160 | "--target=$ndk_target", |
| 161 | "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 162 | ] |
| 163 | lib_dirs = [ |
Mike Klein | 21b620c | 2018-01-08 17:16:00 -0500 | [diff] [blame] | 164 | "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 165 | "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x", |
| 166 | ] |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 167 | |
Mike Klein | 21b620c | 2018-01-08 17:16:00 -0500 | [diff] [blame] | 168 | libs += [ |
| 169 | "c++_static", |
| 170 | "c++abi", |
Mike Klein | 21b620c | 2018-01-08 17:16:00 -0500 | [diff] [blame] | 171 | ] |
Mike Klein | 8803ebb | 2018-05-14 13:25:46 -0400 | [diff] [blame] | 172 | if (ndk_api < 21) { |
| 173 | libs += [ "android_support" ] |
| 174 | } |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 175 | } |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 176 | |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 177 | if (is_ios) { |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 178 | _target = target_cpu |
| 179 | if (target_cpu == "arm") { |
| 180 | _target = "armv7" |
Mike Klein | 7a5e0f3 | 2017-03-13 09:25:33 -0700 | [diff] [blame] | 181 | } else if (target_cpu == "x86") { |
| 182 | _target = "i386" |
| 183 | } else if (target_cpu == "x64") { |
| 184 | _target = "x86_64" |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 185 | } |
Mike Klein | 4fe2b15 | 2017-02-17 15:36:01 -0500 | [diff] [blame] | 186 | asmflags += [ |
| 187 | "-isysroot", |
| 188 | ios_sysroot, |
| 189 | "-arch", |
| 190 | _target, |
| 191 | ] |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 192 | cflags += [ |
Mike Klein | 6749af4 | 2016-11-07 15:38:48 -0500 | [diff] [blame] | 193 | "-isysroot", |
| 194 | ios_sysroot, |
| 195 | "-arch", |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 196 | _target, |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 197 | ] |
| 198 | cflags_cc += [ "-stdlib=libc++" ] |
| 199 | ldflags += [ |
Mike Klein | 6749af4 | 2016-11-07 15:38:48 -0500 | [diff] [blame] | 200 | "-isysroot", |
| 201 | ios_sysroot, |
| 202 | "-arch", |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 203 | _target, |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 204 | "-stdlib=libc++", |
| 205 | ] |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 206 | libs += [ "objc" ] |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 207 | } |
| 208 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 209 | if (is_linux) { |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 210 | libs += [ "pthread" ] |
Cary Clark | eb1d900 | 2018-07-13 10:39:39 -0400 | [diff] [blame] | 211 | if (is_debug && sanitize == "") { |
| 212 | defines += [ "_GLIBCXX_DEBUG" ] |
| 213 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 214 | } |
Mike Klein | 15f46c3 | 2017-12-07 12:48:57 -0500 | [diff] [blame] | 215 | if (is_mac) { |
| 216 | # Disable linker warnings. They're usually just annoyances like, |
| 217 | # ld: warning: text-based stub file |
| 218 | # /System/Library/Frameworks/foo.framework/foo.tbd and library file |
| 219 | # /System/Library/Frameworks/foo.framework/foo are out of sync. |
| 220 | # Falling back to library file for linking. |
| 221 | ldflags += [ "-Wl,-w" ] |
| 222 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 223 | |
| 224 | if (sanitize != "") { |
| 225 | # You can either pass the sanitizers directly, e.g. "address,undefined", |
| 226 | # or pass one of the couple common aliases used by the bots. |
| 227 | sanitizers = sanitize |
Kevin Lubick | d095040 | 2018-03-20 10:10:58 -0400 | [diff] [blame] | 228 | |
Ben Wagner | 314d7c2 | 2018-01-03 11:04:30 -0500 | [diff] [blame] | 229 | if (sanitize == "ASAN" || sanitize == "UBSAN") { |
| 230 | # ASAN implicitly runs all UBSAN checks also. |
Mike Klein | 02046a7 | 2018-08-10 12:25:12 -0400 | [diff] [blame] | 231 | sanitizers = "undefined" |
Ben Wagner | 314d7c2 | 2018-01-03 11:04:30 -0500 | [diff] [blame] | 232 | if (sanitize == "ASAN") { |
| 233 | sanitizers += ",address" |
Mike Klein | e4781e9 | 2017-09-28 11:42:28 -0400 | [diff] [blame] | 234 | } |
Kevin Lubick | 4f0f933 | 2018-01-12 14:31:48 -0500 | [diff] [blame] | 235 | |
Mike Klein | 02046a7 | 2018-08-10 12:25:12 -0400 | [diff] [blame] | 236 | if (is_android) { |
| 237 | # TODO(mtklein): work out UBSAN link errors |
| 238 | sanitizers = "address" |
Kevin Lubick | 4f0f933 | 2018-01-12 14:31:48 -0500 | [diff] [blame] | 239 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 240 | } else if (sanitize == "TSAN") { |
| 241 | sanitizers = "thread" |
| 242 | } else if (sanitize == "MSAN") { |
| 243 | sanitizers = "memory" |
| 244 | } |
| 245 | |
Mike Klein | 475c5e9 | 2018-08-08 10:23:17 -0400 | [diff] [blame] | 246 | _blacklist = rebase_path("../tools/xsan.blacklist") |
| 247 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 248 | cflags += [ |
Mike Klein | 02046a7 | 2018-08-10 12:25:12 -0400 | [diff] [blame] | 249 | "-fsanitize=$sanitizers", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 250 | "-fno-sanitize-recover=$sanitizers", |
Mike Klein | 475c5e9 | 2018-08-08 10:23:17 -0400 | [diff] [blame] | 251 | "-fsanitize-blacklist=$_blacklist", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 252 | ] |
Mike Klein | 02046a7 | 2018-08-10 12:25:12 -0400 | [diff] [blame] | 253 | ldflags += [ "-fsanitize=$sanitizers" ] |
| 254 | |
Mike Klein | 94c4f41 | 2018-08-09 17:24:45 -0400 | [diff] [blame] | 255 | if (is_win) { |
| 256 | cflags += [ "/FI$_blacklist" ] |
| 257 | } else { |
| 258 | cflags += [ |
| 259 | "-include$_blacklist", |
| 260 | "-fno-omit-frame-pointer", |
| 261 | ] |
Kevin Lubick | 5798c9f | 2018-02-15 09:45:58 -0500 | [diff] [blame] | 262 | } |
Mike Klein | 94c4f41 | 2018-08-09 17:24:45 -0400 | [diff] [blame] | 263 | |
Kevin Lubick | 5798c9f | 2018-02-15 09:45:58 -0500 | [diff] [blame] | 264 | if (is_linux) { |
Kevin Lubick | 43bd259 | 2018-02-15 09:03:44 -0500 | [diff] [blame] | 265 | cflags_cc += [ "-stdlib=libc++" ] |
| 266 | ldflags += [ "-stdlib=libc++" ] |
Kevin Lubick | 3cda39f | 2018-02-01 12:09:55 -0500 | [diff] [blame] | 267 | } |
Mike Klein | 02046a7 | 2018-08-10 12:25:12 -0400 | [diff] [blame] | 268 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 269 | if (sanitizers == "memory") { |
| 270 | cflags += [ "-fsanitize-memory-track-origins" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
Mike Klein | 6e55fef | 2016-10-26 11:41:47 -0400 | [diff] [blame] | 275 | config("no_exceptions") { |
Mike Klein | 228276d | 2017-08-16 13:20:20 +0000 | [diff] [blame] | 276 | # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.) |
Mike Klein | 6e55fef | 2016-10-26 11:41:47 -0400 | [diff] [blame] | 277 | if (!is_win) { |
| 278 | cflags_cc = [ "-fno-exceptions" ] |
| 279 | } |
| 280 | } |
| 281 | |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 282 | config("warnings") { |
| 283 | cflags = [] |
| 284 | cflags_cc = [] |
Mike Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 285 | cflags_objc = [] |
Greg Daniel | 6b7e0e2 | 2017-07-12 16:21:09 -0400 | [diff] [blame] | 286 | cflags_objcc = [] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 287 | if (is_win) { |
| 288 | cflags += [ |
| 289 | "/W3", # Turn on lots of warnings. |
| 290 | |
| 291 | # Disable a bunch of warnings: |
| 292 | "/wd4244", # conversion from 'float' to 'int', possible loss of data |
| 293 | "/wd4267", # conversion from 'size_t' to 'int', possible loss of data |
| 294 | "/wd4800", # forcing value to bool 'true' or 'false' (performance warning) |
| 295 | |
| 296 | # Probably only triggers when /EHsc is enabled. |
| 297 | "/wd4291", # no matching operator delete found; |
| 298 | # memory will not be freed if initialization throws an exception |
| 299 | ] |
| 300 | } else { |
| 301 | cflags += [ |
Mike Klein | d84c1e6 | 2018-09-04 10:15:58 -0400 | [diff] [blame] | 302 | "-Werror", |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 303 | "-Wall", |
| 304 | "-Wextra", |
| 305 | "-Winit-self", |
| 306 | "-Wpointer-arith", |
| 307 | "-Wsign-compare", |
| 308 | "-Wvla", |
| 309 | |
| 310 | "-Wno-deprecated-declarations", |
Mike Klein | db402ca | 2016-12-13 12:46:05 -0500 | [diff] [blame] | 311 | "-Wno-maybe-uninitialized", |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 312 | ] |
Ben Wagner | f8a131d | 2018-03-13 16:56:43 -0400 | [diff] [blame] | 313 | cflags_cc += [ |
| 314 | "-Wnon-virtual-dtor", |
| 315 | "-Wno-noexcept-type", |
| 316 | ] |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 317 | } |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 318 | |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 319 | if (is_clang) { |
| 320 | cflags += [ |
| 321 | "-Weverything", |
| 322 | "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings. |
| 323 | ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 324 | |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 325 | if (target_cpu == "arm" && is_ios) { |
| 326 | # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS. |
| 327 | # We're pretty sure it's actually 8-byte alignment. |
| 328 | cflags += [ "-Wno-over-aligned" ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 329 | } |
Mike Klein | 0428279 | 2018-01-08 18:23:32 -0500 | [diff] [blame] | 330 | if (target_cpu == "x86" && is_android) { |
| 331 | # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds. |
| 332 | # We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info. |
| 333 | cflags += [ "-Wno-over-aligned" ] |
| 334 | } |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 335 | |
| 336 | # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose |
| 337 | # their case during copy, causing case-sensitivity mismatch on remote machines. |
| 338 | cflags += [ |
| 339 | "-Wno-nonportable-include-path", |
| 340 | "-Wno-nonportable-system-include-path", |
| 341 | ] |
| 342 | |
| 343 | # TODO: These would all be really great warnings to turn on. |
| 344 | cflags += [ |
| 345 | "-Wno-cast-align", |
| 346 | "-Wno-cast-qual", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 347 | "-Wno-conversion", |
| 348 | "-Wno-disabled-macro-expansion", |
| 349 | "-Wno-documentation", |
| 350 | "-Wno-documentation-unknown-command", |
| 351 | "-Wno-double-promotion", |
| 352 | "-Wno-exit-time-destructors", # TODO: OK outside libskia |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 353 | "-Wno-float-equal", |
| 354 | "-Wno-format-nonliteral", |
| 355 | "-Wno-global-constructors", # TODO: OK outside libskia |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 356 | "-Wno-missing-prototypes", |
| 357 | "-Wno-missing-variable-declarations", |
| 358 | "-Wno-pedantic", |
| 359 | "-Wno-reserved-id-macro", |
| 360 | "-Wno-shadow", |
| 361 | "-Wno-shift-sign-overflow", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 362 | "-Wno-signed-enum-bitfield", |
| 363 | "-Wno-switch-enum", |
| 364 | "-Wno-undef", |
| 365 | "-Wno-unreachable-code", |
| 366 | "-Wno-unreachable-code-break", |
| 367 | "-Wno-unreachable-code-return", |
| 368 | "-Wno-unused-macros", |
| 369 | "-Wno-unused-member-function", |
| 370 | "-Wno-unused-template", |
| 371 | "-Wno-zero-as-null-pointer-constant", |
| 372 | ] |
| 373 | cflags_cc += [ |
| 374 | "-Wno-abstract-vbase-init", |
| 375 | "-Wno-weak-vtables", |
| 376 | ] |
| 377 | |
| 378 | # We are unlikely to want to fix these. |
| 379 | cflags += [ |
Brian Osman | 9061ffc | 2018-05-16 15:58:31 -0400 | [diff] [blame] | 380 | "-Wno-bad-function-cast", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 381 | "-Wno-covered-switch-default", |
| 382 | "-Wno-deprecated", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 383 | "-Wno-missing-noreturn", |
| 384 | "-Wno-old-style-cast", |
| 385 | "-Wno-padded", |
Chris Dalton | d1ec410 | 2017-12-04 13:31:21 -0700 | [diff] [blame] | 386 | "-Wno-newline-eof", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 387 | ] |
| 388 | cflags_cc += [ |
| 389 | "-Wno-c++98-compat", |
| 390 | "-Wno-c++98-compat-pedantic", |
| 391 | "-Wno-undefined-func-template", |
| 392 | ] |
| 393 | cflags_objc += [ |
| 394 | "-Wno-direct-ivar-access", |
| 395 | "-Wno-objc-interface-ivars", |
| 396 | ] |
| 397 | cflags_objcc += [ |
| 398 | "-Wno-direct-ivar-access", |
| 399 | "-Wno-objcc-interface-ivars", |
| 400 | ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 401 | } |
Mike Klein | ee77da2 | 2018-02-22 15:36:24 -0500 | [diff] [blame] | 402 | if (!is_win || is_clang) { |
| 403 | cflags += [ "-Wno-implicit-fallthrough" ] |
| 404 | } |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 405 | } |
Mike Klein | 50500ad | 2016-11-16 12:13:44 -0500 | [diff] [blame] | 406 | config("warnings_except_public_headers") { |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 407 | if (!is_win || is_clang) { |
Mike Klein | 50500ad | 2016-11-16 12:13:44 -0500 | [diff] [blame] | 408 | cflags = [ "-Wno-unused-parameter" ] |
| 409 | } |
| 410 | } |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 411 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 412 | config("extra_flags") { |
Kevin Lubick | 2677a9a | 2017-03-28 15:45:41 -0400 | [diff] [blame] | 413 | asmflags = extra_asmflags |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 414 | cflags = extra_cflags |
| 415 | cflags_c = extra_cflags_c |
| 416 | cflags_cc = extra_cflags_cc |
| 417 | ldflags = extra_ldflags |
| 418 | } |
| 419 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 420 | config("debug_symbols") { |
| 421 | # It's annoying to wait for full debug symbols to push over |
| 422 | # to Android devices. -gline-tables-only is a lot slimmer. |
| 423 | if (is_android) { |
Mike Klein | 1b4602b | 2017-08-30 10:23:01 -0400 | [diff] [blame] | 424 | cflags = [ |
| 425 | "-gline-tables-only", |
| 426 | "-funwind-tables", # Helps make in-process backtraces fuller. |
| 427 | ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 428 | } else if (is_win) { |
Mike Klein | 67a86d5 | 2017-12-15 07:34:27 -0500 | [diff] [blame] | 429 | cflags = [ "/Z7" ] |
Brian Osman | 7142ae5 | 2018-12-12 16:32:35 -0500 | [diff] [blame] | 430 | if (is_clang) { |
Mike Klein | cae020a | 2018-12-23 10:25:44 -0500 | [diff] [blame] | 431 | cflags += [ "-mllvm", "-emit-codeview-ghash-section" ] |
| 432 | ldflags = [ "/DEBUG:GHASH" ] |
Brian Osman | 7142ae5 | 2018-12-12 16:32:35 -0500 | [diff] [blame] | 433 | } else { |
Mike Klein | a6e0c2b | 2018-12-10 08:48:03 -0500 | [diff] [blame] | 434 | ldflags = [ "/DEBUG:FASTLINK" ] |
Brian Osman | 0ab5684 | 2018-09-13 15:46:02 -0400 | [diff] [blame] | 435 | } |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 436 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 437 | cflags = [ "-g" ] |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | config("no_rtti") { |
| 442 | if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 443 | if (is_win) { |
| 444 | cflags_cc = [ "/GR-" ] |
| 445 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 446 | cflags_cc = [ "-fno-rtti" ] |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
Mike Klein | 7ea977b | 2018-09-19 13:44:43 -0400 | [diff] [blame] | 451 | config("optimize") { |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 452 | if (is_win) { |
Mike Klein | 916ca1d | 2016-10-20 13:34:18 -0400 | [diff] [blame] | 453 | cflags = [ |
| 454 | "/O2", |
| 455 | "/Zc:inline", |
| 456 | ] |
Mike Klein | 90a381f | 2016-10-20 13:52:38 -0400 | [diff] [blame] | 457 | ldflags = [ |
| 458 | "/OPT:ICF", |
| 459 | "/OPT:REF", |
| 460 | ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 461 | } else { |
Mike Klein | 0bcfeac | 2016-10-19 22:24:10 -0400 | [diff] [blame] | 462 | cflags = [ |
| 463 | "-O3", |
Mike Klein | bd9be4d | 2017-02-10 07:59:39 -0500 | [diff] [blame] | 464 | "-fdata-sections", |
| 465 | "-ffunction-sections", |
Mike Klein | 0bcfeac | 2016-10-19 22:24:10 -0400 | [diff] [blame] | 466 | ] |
Mike Klein | bd9be4d | 2017-02-10 07:59:39 -0500 | [diff] [blame] | 467 | if (is_mac || is_ios) { |
| 468 | ldflags = [ "-dead_strip" ] |
| 469 | } else { |
| 470 | ldflags = [ "-Wl,--gc-sections" ] |
| 471 | } |
Kevin Lubick | ebf648e | 2017-09-21 13:45:16 -0400 | [diff] [blame] | 472 | if (target_cpu == "wasm") { |
| 473 | # The compiler asks us to add an optimization flag to both cflags |
| 474 | # and ldflags to cut down on the local variables, |
| 475 | # for performance reasons. |
| 476 | # The "linking" step is the conversion to javascript. |
| 477 | ldflags += [ "-O3" ] |
| 478 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 479 | } |
Mike Klein | 7ea977b | 2018-09-19 13:44:43 -0400 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | config("NDEBUG") { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 483 | defines = [ "NDEBUG" ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | config("executable") { |
Mike Klein | c5875fb | 2016-12-06 10:46:02 -0500 | [diff] [blame] | 487 | if (is_android) { |
Mike Klein | 1b4602b | 2017-08-30 10:23:01 -0400 | [diff] [blame] | 488 | ldflags = [ |
| 489 | "-pie", |
| 490 | "-rdynamic", |
| 491 | ] |
Mike Klein | c5875fb | 2016-12-06 10:46:02 -0500 | [diff] [blame] | 492 | } else if (is_mac) { |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 493 | ldflags = [ "-Wl,-rpath,@loader_path/." ] |
| 494 | } else if (is_linux) { |
mtklein | a846c72 | 2016-09-15 10:44:15 -0700 | [diff] [blame] | 495 | ldflags = [ |
| 496 | "-rdynamic", |
| 497 | "-Wl,-rpath,\$ORIGIN", |
| 498 | ] |
Mike Klein | 4b6b503 | 2016-11-06 11:54:19 -0500 | [diff] [blame] | 499 | } else if (is_win) { |
| 500 | ldflags = [ |
| 501 | "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed". |
| 502 | "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to. |
| 503 | ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 504 | } |
| 505 | } |