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