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 | 87c36f2 | 2016-11-13 10:29:25 -0500 | [diff] [blame] | 16 | is_clang = is_android || is_ios || is_mac || (cc == "clang" && cxx == "clang++") |
| 17 | if (!is_clang && !is_win) { |
Mike Klein | 461d328 | 2016-10-11 13:51:55 -0400 | [diff] [blame] | 18 | is_clang = exec_script("is_clang.py", |
| 19 | [ |
| 20 | cc, |
| 21 | cxx, |
| 22 | ], |
| 23 | "value") |
| 24 | } |
mtklein | f347c51 | 2016-09-26 08:40:12 -0700 | [diff] [blame] | 25 | |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 26 | if (is_ios) { |
Matthew Leibowitz | 3150ec6 | 2017-03-14 16:22:32 -0400 | [diff] [blame] | 27 | if (is_tvos) { |
| 28 | sdk = "appletvos" |
| 29 | if (target_cpu == "x86" || target_cpu == "x64") { |
| 30 | sdk = "appletvsimulator" |
| 31 | } |
| 32 | } else { |
| 33 | sdk = "iphoneos" |
| 34 | if (target_cpu == "x86" || target_cpu == "x64") { |
| 35 | sdk = "iphonesimulator" |
| 36 | } |
Mike Klein | 7a5e0f3 | 2017-03-13 09:25:33 -0700 | [diff] [blame] | 37 | } |
| 38 | ios_sysroot = exec_script("find_ios_sysroot.py", [ sdk ], "trim string") |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 39 | } |
| 40 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 41 | config("default") { |
| 42 | asmflags = [] |
| 43 | cflags = [] |
| 44 | cflags_c = [] |
| 45 | cflags_cc = [] |
| 46 | defines = [] |
| 47 | ldflags = [] |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 48 | libs = [] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 49 | |
| 50 | if (is_win) { |
| 51 | cflags += [ |
| 52 | "/FS", # Preserve previous PDB behavior. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 53 | "/bigobj", # Some of our files are bigger than the regular limits. |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 54 | "/WX", # Treat warnings as errors. |
Ben Wagner | e6b274e | 2017-01-03 17:09:59 -0500 | [diff] [blame] | 55 | "/utf-8", # Set Source and Executable character sets to UTF-8. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 56 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 57 | defines += [ |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 58 | "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf(). |
| 59 | "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL. |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 60 | "WIN32_LEAN_AND_MEAN", |
| 61 | "NOMINMAX", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 62 | ] |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 63 | include_dirs = [ |
Ben Wagner | 4e8472c | 2017-03-20 16:53:05 -0400 | [diff] [blame] | 64 | #2017 |
| 65 | "$windk/VC/Tools/MSVC/14.10.25017/include", |
| 66 | |
| 67 | #2015 |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 68 | "$windk/VC/include", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 69 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 70 | # For local builds. |
Ben Wagner | 4e8472c | 2017-03-20 16:53:05 -0400 | [diff] [blame] | 71 | # 2017 |
| 72 | "$windk/../../../Windows Kits/10/Include/10.0.14393.0/shared", |
| 73 | "$windk/../../../Windows Kits/10/Include/10.0.14393.0/ucrt", |
| 74 | "$windk/../../../Windows Kits/10/Include/10.0.14393.0/um", |
| 75 | "$windk/../../../Windows Kits/10/Include/10.0.14393.0/winrt", |
| 76 | |
| 77 | # 2015 |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 78 | "$windk/../Windows Kits/8.1/Include/shared", |
Ben Wagner | 4e8472c | 2017-03-20 16:53:05 -0400 | [diff] [blame] | 79 | "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt", |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 80 | "$windk/../Windows Kits/8.1/Include/um", |
Brian Osman | 21d742d | 2017-01-10 13:31:33 -0500 | [diff] [blame] | 81 | "$windk/../Windows Kits/8.1/Include/winrt", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 82 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 83 | # For builds using win_toolchain asset. |
Brian Osman | 3f28933 | 2017-01-10 10:38:23 -0500 | [diff] [blame] | 84 | "$windk/win_sdk/Include/10.0.14393.0/shared", |
| 85 | "$windk/win_sdk/Include/10.0.14393.0/ucrt", |
| 86 | "$windk/win_sdk/Include/10.0.14393.0/um", |
Brian Osman | 21d742d | 2017-01-10 13:31:33 -0500 | [diff] [blame] | 87 | "$windk/win_sdk/Include/10.0.14393.0/winrt", |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 88 | ] |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 89 | lib_dirs = [ |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 90 | # For local builds. |
Ben Wagner | 4e8472c | 2017-03-20 16:53:05 -0400 | [diff] [blame] | 91 | # 2017 |
| 92 | "$windk/../../../Windows Kits/10/Lib/10.0.14393.0/ucrt/$target_cpu", |
| 93 | "$windk/../../../Windows Kits/10/Lib/10.0.14393.0/um/$target_cpu", |
| 94 | |
| 95 | #2015 |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 96 | "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu", |
| 97 | "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 98 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 99 | # For builds using win_toolchain asset. |
Brian Osman | 3f28933 | 2017-01-10 10:38:23 -0500 | [diff] [blame] | 100 | "$windk/win_sdk/Lib/10.0.14393.0/ucrt/$target_cpu", |
| 101 | "$windk/win_sdk/Lib/10.0.14393.0/um/$target_cpu", |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 102 | ] |
Ben Wagner | 4e8472c | 2017-03-20 16:53:05 -0400 | [diff] [blame] | 103 | |
| 104 | #2017 |
| 105 | lib_dirs += [ "$windk/VC/Tools/MSVC/14.10.25017/lib/$target_cpu" ] |
| 106 | |
| 107 | #2015 |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 108 | if (target_cpu == "x86") { |
| 109 | lib_dirs += [ "$windk/VC/lib" ] |
| 110 | } else { |
| 111 | lib_dirs += [ "$windk/VC/lib/amd64" ] |
| 112 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 113 | } else { |
| 114 | cflags += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 115 | "-fstrict-aliasing", |
| 116 | "-fPIC", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 117 | "-Werror", |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 118 | ] |
Mike Klein | 28f5b77 | 2017-04-06 23:04:42 -0400 | [diff] [blame] | 119 | cflags_cc += [ "-std=c++11" ] |
Mike Klein | eec23d1 | 2017-03-26 20:11:48 -0400 | [diff] [blame] | 120 | |
| 121 | # The main idea is to slim the exported API, but these flags also improve link time on Mac. |
| 122 | # 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] | 123 | if (is_component_build || is_ios || is_mac) { |
Mike Klein | eec23d1 | 2017-03-26 20:11:48 -0400 | [diff] [blame] | 124 | cflags += [ "-fvisibility=hidden" ] |
| 125 | cflags_cc += [ "-fvisibility-inlines-hidden" ] |
| 126 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 127 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 128 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 129 | if (current_cpu == "arm") { |
| 130 | cflags += [ |
| 131 | "-march=armv7-a", |
| 132 | "-mfpu=neon", |
| 133 | "-mthumb", |
| 134 | ] |
| 135 | } else if (current_cpu == "mipsel") { |
Derek Sollenberger | 19b2a56 | 2017-06-27 11:55:05 -0400 | [diff] [blame] | 136 | cflags += [ "-march=mips32r2" ] |
| 137 | } else if (current_cpu == "mips64el") { |
| 138 | asmflags += [ "-integrated-as" ] |
| 139 | cflags += [ "-integrated-as" ] |
Mike Klein | 5d8cf29 | 2016-10-12 19:36:09 -0400 | [diff] [blame] | 140 | } else if (current_cpu == "x86" && !is_win) { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 141 | asmflags += [ "-m32" ] |
| 142 | cflags += [ |
| 143 | "-m32", |
| 144 | "-msse2", |
| 145 | "-mfpmath=sse", |
| 146 | ] |
| 147 | ldflags += [ "-m32" ] |
| 148 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 149 | |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 150 | if (malloc != "" && !is_win) { |
| 151 | cflags += [ |
| 152 | "-fno-builtin-malloc", |
| 153 | "-fno-builtin-calloc", |
| 154 | "-fno-builtin-realloc", |
| 155 | "-fno-builtin-free", |
| 156 | ] |
| 157 | libs += [ malloc ] |
| 158 | } |
| 159 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 160 | if (is_android) { |
Derek Sollenberger | 19b2a56 | 2017-06-27 11:55:05 -0400 | [diff] [blame] | 161 | asmflags += [ "--target=$ndk_target" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 162 | cflags += [ |
Derek Sollenberger | 19b2a56 | 2017-06-27 11:55:05 -0400 | [diff] [blame] | 163 | "--sysroot=$ndk/sysroot", |
| 164 | "-isystem$ndk/sysroot/usr/include/$ndk_target", |
| 165 | "-D__ANDROID_API__=$ndk_api", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 166 | "--target=$ndk_target", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 167 | ] |
| 168 | cflags_cc += [ |
| 169 | "-isystem$ndk/sources/android/support/include", |
Mike Klein | b7ce80b | 2016-12-14 13:17:53 -0500 | [diff] [blame] | 170 | "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/include", |
| 171 | "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib/include", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 172 | ] |
| 173 | ldflags += [ |
| 174 | "--sysroot=$ndk/platforms/$ndk_platform", |
| 175 | "--target=$ndk_target", |
| 176 | "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 177 | ] |
| 178 | lib_dirs = [ |
Mike Klein | b7ce80b | 2016-12-14 13:17:53 -0500 | [diff] [blame] | 179 | "$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 180 | "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x", |
| 181 | ] |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 182 | |
Mike Klein | 4fdc543 | 2016-10-11 11:21:36 -0400 | [diff] [blame] | 183 | if (current_cpu == "mips64el") { |
Derek Sollenberger | 19b2a56 | 2017-06-27 11:55:05 -0400 | [diff] [blame] | 184 | # The r15b NDK deployed on our bots fails to find /usr/lib64 in the |
| 185 | # MIPS64 sysroots, so we must point Clang at /usr/lib64 manually. |
Mike Klein | 4fdc543 | 2016-10-11 11:21:36 -0400 | [diff] [blame] | 186 | lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ] |
Mike Klein | 978cceb | 2016-12-08 10:29:27 -0500 | [diff] [blame] | 187 | ldflags += [ "-B$ndk/platforms/$ndk_platform/usr/lib64" ] |
Mike Klein | 4fdc543 | 2016-10-11 11:21:36 -0400 | [diff] [blame] | 188 | } |
| 189 | |
Mike Klein | b7ce80b | 2016-12-14 13:17:53 -0500 | [diff] [blame] | 190 | libs += [ "gnustl_static" ] |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 191 | } |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 192 | |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 193 | if (is_ios) { |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 194 | _target = target_cpu |
| 195 | if (target_cpu == "arm") { |
| 196 | _target = "armv7" |
Mike Klein | 7a5e0f3 | 2017-03-13 09:25:33 -0700 | [diff] [blame] | 197 | } else if (target_cpu == "x86") { |
| 198 | _target = "i386" |
| 199 | } else if (target_cpu == "x64") { |
| 200 | _target = "x86_64" |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 201 | } |
Mike Klein | 4fe2b15 | 2017-02-17 15:36:01 -0500 | [diff] [blame] | 202 | asmflags += [ |
| 203 | "-isysroot", |
| 204 | ios_sysroot, |
| 205 | "-arch", |
| 206 | _target, |
| 207 | ] |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 208 | cflags += [ |
Mike Klein | 6749af4 | 2016-11-07 15:38:48 -0500 | [diff] [blame] | 209 | "-isysroot", |
| 210 | ios_sysroot, |
| 211 | "-arch", |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 212 | _target, |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 213 | ] |
| 214 | cflags_cc += [ "-stdlib=libc++" ] |
| 215 | ldflags += [ |
Mike Klein | 6749af4 | 2016-11-07 15:38:48 -0500 | [diff] [blame] | 216 | "-isysroot", |
| 217 | ios_sysroot, |
| 218 | "-arch", |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 219 | _target, |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 220 | "-stdlib=libc++", |
| 221 | ] |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 222 | libs += [ "objc" ] |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 223 | } |
| 224 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 225 | if (is_linux) { |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 226 | libs += [ "pthread" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | if (sanitize != "") { |
| 230 | # You can either pass the sanitizers directly, e.g. "address,undefined", |
| 231 | # or pass one of the couple common aliases used by the bots. |
| 232 | sanitizers = sanitize |
| 233 | if (sanitize == "ASAN") { |
| 234 | sanitizers = "address,bool,function,integer-divide-by-zero,nonnull-attribute,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr" |
| 235 | } else if (sanitize == "TSAN") { |
| 236 | sanitizers = "thread" |
| 237 | } else if (sanitize == "MSAN") { |
| 238 | sanitizers = "memory" |
| 239 | } |
| 240 | |
| 241 | cflags += [ |
| 242 | "-fsanitize=$sanitizers", |
| 243 | "-fno-sanitize-recover=$sanitizers", |
| 244 | "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"), |
| 245 | ] |
| 246 | ldflags += [ "-fsanitize=$sanitizers" ] |
| 247 | if (sanitizers == "memory") { |
| 248 | cflags += [ "-fsanitize-memory-track-origins" ] |
| 249 | cflags_cc += [ "-stdlib=libc++" ] |
| 250 | ldflags += [ "-stdlib=libc++" ] |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
Mike Klein | 6e55fef | 2016-10-26 11:41:47 -0400 | [diff] [blame] | 255 | config("no_exceptions") { |
| 256 | # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.) |
| 257 | if (!is_win) { |
| 258 | cflags_cc = [ "-fno-exceptions" ] |
| 259 | } |
| 260 | } |
| 261 | |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 262 | config("warnings") { |
| 263 | cflags = [] |
| 264 | cflags_cc = [] |
Mike Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 265 | cflags_objc = [] |
Greg Daniel | 6b7e0e2 | 2017-07-12 16:21:09 -0400 | [diff] [blame] | 266 | cflags_objcc = [] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 267 | if (is_win) { |
| 268 | cflags += [ |
| 269 | "/W3", # Turn on lots of warnings. |
| 270 | |
| 271 | # Disable a bunch of warnings: |
| 272 | "/wd4244", # conversion from 'float' to 'int', possible loss of data |
| 273 | "/wd4267", # conversion from 'size_t' to 'int', possible loss of data |
| 274 | "/wd4800", # forcing value to bool 'true' or 'false' (performance warning) |
| 275 | |
| 276 | # Probably only triggers when /EHsc is enabled. |
| 277 | "/wd4291", # no matching operator delete found; |
| 278 | # memory will not be freed if initialization throws an exception |
| 279 | ] |
| 280 | } else { |
| 281 | cflags += [ |
| 282 | "-Wall", |
| 283 | "-Wextra", |
| 284 | "-Winit-self", |
| 285 | "-Wpointer-arith", |
| 286 | "-Wsign-compare", |
| 287 | "-Wvla", |
| 288 | |
| 289 | "-Wno-deprecated-declarations", |
Mike Klein | db402ca | 2016-12-13 12:46:05 -0500 | [diff] [blame] | 290 | "-Wno-maybe-uninitialized", |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 291 | ] |
| 292 | cflags_cc += [ "-Wnon-virtual-dtor" ] |
| 293 | |
| 294 | if (is_clang) { |
| 295 | cflags += [ |
| 296 | "-Weverything", |
| 297 | "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings. |
| 298 | ] |
| 299 | |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 300 | if ((target_cpu == "x86" && is_android) || |
| 301 | (target_cpu == "arm" && is_ios)) { |
| 302 | # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android and 32-bit iOS. |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 303 | # We're pretty sure it's actually 8-byte alignment. |
| 304 | cflags += [ "-Wno-over-aligned" ] |
| 305 | } |
| 306 | |
| 307 | cflags += [ |
| 308 | "-Wno-cast-align", |
| 309 | "-Wno-conditional-uninitialized", |
| 310 | "-Wno-conversion", |
| 311 | "-Wno-disabled-macro-expansion", |
| 312 | "-Wno-documentation", |
| 313 | "-Wno-documentation-unknown-command", |
| 314 | "-Wno-double-promotion", |
| 315 | "-Wno-exit-time-destructors", # TODO: OK outside libskia |
| 316 | "-Wno-float-conversion", |
| 317 | "-Wno-float-equal", |
| 318 | "-Wno-format-nonliteral", |
| 319 | "-Wno-global-constructors", # TODO: OK outside libskia |
| 320 | "-Wno-gnu-zero-variadic-macro-arguments", |
| 321 | "-Wno-missing-prototypes", |
| 322 | "-Wno-missing-variable-declarations", |
| 323 | "-Wno-pedantic", |
| 324 | "-Wno-reserved-id-macro", |
| 325 | "-Wno-shadow", |
| 326 | "-Wno-shift-sign-overflow", |
| 327 | "-Wno-sign-conversion", |
Matt Sarett | d3ed402 | 2017-01-04 17:13:44 -0500 | [diff] [blame] | 328 | "-Wno-signed-enum-bitfield", |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 329 | "-Wno-switch-enum", |
| 330 | "-Wno-undef", |
| 331 | "-Wno-unreachable-code", |
| 332 | "-Wno-unreachable-code-break", |
| 333 | "-Wno-unreachable-code-return", |
| 334 | "-Wno-unused-macros", |
| 335 | "-Wno-unused-member-function", |
| 336 | ] |
| 337 | cflags_cc += [ |
| 338 | "-Wno-abstract-vbase-init", |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 339 | "-Wno-weak-vtables", |
| 340 | ] |
| 341 | |
| 342 | # We are unlikely to want to fix these. |
| 343 | cflags += [ |
| 344 | "-Wno-covered-switch-default", |
| 345 | "-Wno-deprecated", |
| 346 | "-Wno-implicit-fallthrough", |
| 347 | "-Wno-missing-noreturn", |
| 348 | "-Wno-old-style-cast", |
| 349 | "-Wno-padded", |
| 350 | ] |
| 351 | cflags_cc += [ |
| 352 | "-Wno-c++98-compat", |
| 353 | "-Wno-c++98-compat-pedantic", |
| 354 | "-Wno-undefined-func-template", |
| 355 | ] |
Mike Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 356 | cflags_objc += [ |
| 357 | "-Wno-direct-ivar-access", |
| 358 | "-Wno-objc-interface-ivars", |
| 359 | ] |
Greg Daniel | 6b7e0e2 | 2017-07-12 16:21:09 -0400 | [diff] [blame] | 360 | cflags_objcc += [ |
| 361 | "-Wno-direct-ivar-access", |
| 362 | "-Wno-objcc-interface-ivars", |
| 363 | ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | } |
Mike Klein | 50500ad | 2016-11-16 12:13:44 -0500 | [diff] [blame] | 367 | config("warnings_except_public_headers") { |
| 368 | if (!is_win) { |
| 369 | cflags = [ "-Wno-unused-parameter" ] |
| 370 | } |
| 371 | } |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 372 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 373 | config("extra_flags") { |
Kevin Lubick | 2677a9a | 2017-03-28 15:45:41 -0400 | [diff] [blame] | 374 | asmflags = extra_asmflags |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 375 | cflags = extra_cflags |
| 376 | cflags_c = extra_cflags_c |
| 377 | cflags_cc = extra_cflags_cc |
| 378 | ldflags = extra_ldflags |
| 379 | } |
| 380 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 381 | config("debug_symbols") { |
| 382 | # It's annoying to wait for full debug symbols to push over |
| 383 | # to Android devices. -gline-tables-only is a lot slimmer. |
| 384 | if (is_android) { |
| 385 | cflags = [ "-gline-tables-only" ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 386 | } else if (is_win) { |
| 387 | cflags = [ "/Zi" ] |
Mike Klein | 5286d6c | 2016-10-13 13:19:25 -0400 | [diff] [blame] | 388 | ldflags = [ "/DEBUG" ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 389 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 390 | cflags = [ "-g" ] |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | config("no_rtti") { |
| 395 | if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 396 | if (is_win) { |
| 397 | cflags_cc = [ "/GR-" ] |
| 398 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 399 | cflags_cc = [ "-fno-rtti" ] |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | config("release") { |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 405 | if (is_win) { |
Mike Klein | 916ca1d | 2016-10-20 13:34:18 -0400 | [diff] [blame] | 406 | cflags = [ |
| 407 | "/O2", |
| 408 | "/Zc:inline", |
Mike Klein | 8ffb260 | 2016-10-20 15:45:02 -0400 | [diff] [blame] | 409 | "/GS-", |
Mike Klein | 916ca1d | 2016-10-20 13:34:18 -0400 | [diff] [blame] | 410 | ] |
Mike Klein | 90a381f | 2016-10-20 13:52:38 -0400 | [diff] [blame] | 411 | ldflags = [ |
| 412 | "/OPT:ICF", |
| 413 | "/OPT:REF", |
| 414 | ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 415 | } else { |
Mike Klein | 0bcfeac | 2016-10-19 22:24:10 -0400 | [diff] [blame] | 416 | cflags = [ |
| 417 | "-O3", |
Mike Klein | bd9be4d | 2017-02-10 07:59:39 -0500 | [diff] [blame] | 418 | "-fdata-sections", |
| 419 | "-ffunction-sections", |
Mike Klein | 0bcfeac | 2016-10-19 22:24:10 -0400 | [diff] [blame] | 420 | ] |
Mike Klein | bd9be4d | 2017-02-10 07:59:39 -0500 | [diff] [blame] | 421 | if (is_mac || is_ios) { |
| 422 | ldflags = [ "-dead_strip" ] |
| 423 | } else { |
| 424 | ldflags = [ "-Wl,--gc-sections" ] |
| 425 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 426 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 427 | defines = [ "NDEBUG" ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | config("executable") { |
Mike Klein | c5875fb | 2016-12-06 10:46:02 -0500 | [diff] [blame] | 431 | if (is_android) { |
| 432 | ldflags = [ "-pie" ] |
| 433 | } else if (is_mac) { |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 434 | ldflags = [ "-Wl,-rpath,@loader_path/." ] |
| 435 | } else if (is_linux) { |
mtklein | a846c72 | 2016-09-15 10:44:15 -0700 | [diff] [blame] | 436 | ldflags = [ |
| 437 | "-rdynamic", |
| 438 | "-Wl,-rpath,\$ORIGIN", |
| 439 | ] |
Mike Klein | 4b6b503 | 2016-11-06 11:54:19 -0500 | [diff] [blame] | 440 | } else if (is_win) { |
| 441 | ldflags = [ |
| 442 | "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed". |
| 443 | "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to. |
| 444 | ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 445 | } |
| 446 | } |