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() { |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 7 | ar = "ar" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 8 | cc = "cc" |
| 9 | cxx = "c++" |
mtklein | 8079ba6 | 2016-08-16 09:31:16 -0700 | [diff] [blame] | 10 | |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 11 | if (is_android) { |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 12 | if (host_os == "win") { |
Mike Klein | 67702f6 | 2016-12-09 10:32:28 -0500 | [diff] [blame] | 13 | ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar.exe" |
| 14 | cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang.exe" |
| 15 | cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++.exe" |
| 16 | } else { |
| 17 | ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar" |
| 18 | cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang" |
| 19 | cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++" |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 20 | } |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 21 | } |
| 22 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 23 | windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 24 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 25 | extra_cflags = [] |
| 26 | extra_cflags_c = [] |
| 27 | extra_cflags_cc = [] |
| 28 | extra_ldflags = [] |
mtklein | cab0bb7 | 2016-08-26 13:43:19 -0700 | [diff] [blame] | 29 | |
mtklein | 60b7ab7 | 2016-09-20 12:09:12 -0700 | [diff] [blame] | 30 | cc_wrapper = "" |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 31 | malloc = "" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 34 | if (host_os == "win") { |
| 35 | python = "python.bat" |
| 36 | stamp = "cmd.exe /c echo >" |
| 37 | } else { |
| 38 | python = "python" |
| 39 | stamp = "touch" |
| 40 | } |
| 41 | |
Mike Klein | 87c36f2 | 2016-11-13 10:29:25 -0500 | [diff] [blame] | 42 | is_clang = is_android || is_ios || is_mac || (cc == "clang" && cxx == "clang++") |
| 43 | if (!is_clang && !is_win) { |
Mike Klein | 461d328 | 2016-10-11 13:51:55 -0400 | [diff] [blame] | 44 | is_clang = exec_script("is_clang.py", |
| 45 | [ |
| 46 | cc, |
| 47 | cxx, |
| 48 | ], |
| 49 | "value") |
| 50 | } |
mtklein | f347c51 | 2016-09-26 08:40:12 -0700 | [diff] [blame] | 51 | |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 52 | if (is_ios) { |
| 53 | ios_sysroot = exec_script("find_ios_sysroot.py", [], "trim string") |
| 54 | } |
| 55 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 56 | config("default") { |
| 57 | asmflags = [] |
| 58 | cflags = [] |
| 59 | cflags_c = [] |
| 60 | cflags_cc = [] |
| 61 | defines = [] |
| 62 | ldflags = [] |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 63 | libs = [] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 64 | |
| 65 | if (is_win) { |
| 66 | cflags += [ |
| 67 | "/FS", # Preserve previous PDB behavior. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 68 | "/bigobj", # Some of our files are bigger than the regular limits. |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 69 | "/WX", # Treat warnings as errors. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 70 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 71 | defines += [ |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 72 | "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf(). |
| 73 | "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL. |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 74 | "WIN32_LEAN_AND_MEAN", |
| 75 | "NOMINMAX", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 76 | ] |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 77 | include_dirs = [ |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 78 | "$windk/VC/include", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 79 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 80 | # For local builds. |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 81 | "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt", |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 82 | "$windk/../Windows Kits/8.1/Include/shared", |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 83 | "$windk/../Windows Kits/8.1/Include/um", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 84 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 85 | # For builds using win_toolchain asset. |
| 86 | "$windk/win_sdk/Include/10.0.10586.0/shared", |
| 87 | "$windk/win_sdk/Include/10.0.10586.0/ucrt", |
| 88 | "$windk/win_sdk/Include/10.0.10586.0/um", |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 89 | ] |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 90 | lib_dirs = [ |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 91 | # For local builds. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 92 | "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu", |
| 93 | "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu", |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 94 | |
Mike Klein | d301683 | 2016-10-12 15:52:44 -0400 | [diff] [blame] | 95 | # For builds using win_toolchain asset. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 96 | "$windk/win_sdk/Lib/10.0.10586.0/ucrt/$target_cpu", |
| 97 | "$windk/win_sdk/Lib/10.0.10586.0/um/$target_cpu", |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 98 | ] |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 99 | if (target_cpu == "x86") { |
| 100 | lib_dirs += [ "$windk/VC/lib" ] |
| 101 | } else { |
| 102 | lib_dirs += [ "$windk/VC/lib/amd64" ] |
| 103 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 104 | } else { |
| 105 | cflags += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 106 | "-fstrict-aliasing", |
| 107 | "-fPIC", |
| 108 | "-fvisibility=hidden", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 109 | "-Werror", |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 110 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 111 | cflags_cc += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 112 | "-std=c++11", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 113 | "-fno-threadsafe-statics", |
| 114 | "-fvisibility-inlines-hidden", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 115 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 116 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 117 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 118 | if (current_cpu == "arm") { |
| 119 | cflags += [ |
| 120 | "-march=armv7-a", |
| 121 | "-mfpu=neon", |
| 122 | "-mthumb", |
| 123 | ] |
| 124 | } else if (current_cpu == "mipsel") { |
| 125 | cflags += [ |
| 126 | "-march=mips32r2", |
| 127 | "-mdspr2", |
| 128 | ] |
Mike Klein | 5d8cf29 | 2016-10-12 19:36:09 -0400 | [diff] [blame] | 129 | } else if (current_cpu == "x86" && !is_win) { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 130 | asmflags += [ "-m32" ] |
| 131 | cflags += [ |
| 132 | "-m32", |
| 133 | "-msse2", |
| 134 | "-mfpmath=sse", |
| 135 | ] |
| 136 | ldflags += [ "-m32" ] |
| 137 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 138 | |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 139 | if (malloc != "" && !is_win) { |
| 140 | cflags += [ |
| 141 | "-fno-builtin-malloc", |
| 142 | "-fno-builtin-calloc", |
| 143 | "-fno-builtin-realloc", |
| 144 | "-fno-builtin-free", |
| 145 | ] |
| 146 | libs += [ malloc ] |
| 147 | } |
| 148 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 149 | if (is_android) { |
| 150 | asmflags += [ |
| 151 | "--target=$ndk_target", |
| 152 | "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
| 153 | ] |
| 154 | cflags += [ |
| 155 | "--sysroot=$ndk/platforms/$ndk_platform", |
| 156 | "--target=$ndk_target", |
| 157 | "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
| 158 | ] |
| 159 | cflags_cc += [ |
| 160 | "-isystem$ndk/sources/android/support/include", |
Mike Klein | 4fdc543 | 2016-10-11 11:21:36 -0400 | [diff] [blame] | 161 | "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b. |
| 162 | "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13. |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 163 | ] |
| 164 | ldflags += [ |
| 165 | "--sysroot=$ndk/platforms/$ndk_platform", |
| 166 | "--target=$ndk_target", |
| 167 | "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 168 | ] |
| 169 | lib_dirs = [ |
| 170 | "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib", |
| 171 | "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x", |
| 172 | ] |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 173 | |
Mike Klein | 4fdc543 | 2016-10-11 11:21:36 -0400 | [diff] [blame] | 174 | if (current_cpu == "mips64el") { |
| 175 | # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches |
| 176 | # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib, |
| 177 | # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually. |
| 178 | lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ] |
Mike Klein | 978cceb | 2016-12-08 10:29:27 -0500 | [diff] [blame] | 179 | ldflags += [ "-B$ndk/platforms/$ndk_platform/usr/lib64" ] |
Mike Klein | 4fdc543 | 2016-10-11 11:21:36 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 182 | libs += [ |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 183 | # Order matters here! Keep these three in exactly this order. |
| 184 | "c++_static", |
| 185 | "c++abi", |
| 186 | "android_support", |
| 187 | ] |
| 188 | if (target_cpu == "arm") { |
| 189 | libs += [ "unwind" ] |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 190 | } |
| 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) { |
| 194 | cflags += [ |
Mike Klein | 6749af4 | 2016-11-07 15:38:48 -0500 | [diff] [blame] | 195 | "-isysroot", |
| 196 | ios_sysroot, |
| 197 | "-arch", |
| 198 | target_cpu, |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 199 | ] |
| 200 | cflags_cc += [ "-stdlib=libc++" ] |
| 201 | ldflags += [ |
Mike Klein | 6749af4 | 2016-11-07 15:38:48 -0500 | [diff] [blame] | 202 | "-isysroot", |
| 203 | ios_sysroot, |
| 204 | "-arch", |
| 205 | target_cpu, |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 206 | "-stdlib=libc++", |
| 207 | ] |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 208 | libs += [ "objc" ] |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 209 | |
| 210 | # We used to link all our iOS tools together, so none actually defines main(). |
| 211 | # Instead they each define their own entry point, which our iOS mega-app called. |
| 212 | # If we can we'd like to not do that anymore. While we're building both ways, here's |
| 213 | # our clever hack to give each tool back its own main(). |
| 214 | cflags += [ |
| 215 | "-Ddm_main=main", |
| 216 | "-Dnanobench_main=main", |
| 217 | "-Dtool_main=main", |
| 218 | "-Dtest_main=main", |
| 219 | ] |
| 220 | } |
| 221 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 222 | if (is_linux) { |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 223 | libs += [ "pthread" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | if (sanitize != "") { |
| 227 | # You can either pass the sanitizers directly, e.g. "address,undefined", |
| 228 | # or pass one of the couple common aliases used by the bots. |
| 229 | sanitizers = sanitize |
| 230 | if (sanitize == "ASAN") { |
| 231 | 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" |
| 232 | } else if (sanitize == "TSAN") { |
| 233 | sanitizers = "thread" |
| 234 | } else if (sanitize == "MSAN") { |
| 235 | sanitizers = "memory" |
| 236 | } |
| 237 | |
| 238 | cflags += [ |
| 239 | "-fsanitize=$sanitizers", |
| 240 | "-fno-sanitize-recover=$sanitizers", |
| 241 | "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"), |
| 242 | ] |
| 243 | ldflags += [ "-fsanitize=$sanitizers" ] |
| 244 | if (sanitizers == "memory") { |
| 245 | cflags += [ "-fsanitize-memory-track-origins" ] |
| 246 | cflags_cc += [ "-stdlib=libc++" ] |
| 247 | ldflags += [ "-stdlib=libc++" ] |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
Mike Klein | 6e55fef | 2016-10-26 11:41:47 -0400 | [diff] [blame] | 252 | config("no_exceptions") { |
| 253 | # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.) |
| 254 | if (!is_win) { |
| 255 | cflags_cc = [ "-fno-exceptions" ] |
| 256 | } |
| 257 | } |
| 258 | |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 259 | config("warnings") { |
| 260 | cflags = [] |
| 261 | cflags_cc = [] |
Mike Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 262 | cflags_objc = [] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 263 | if (is_win) { |
| 264 | cflags += [ |
| 265 | "/W3", # Turn on lots of warnings. |
| 266 | |
| 267 | # Disable a bunch of warnings: |
| 268 | "/wd4244", # conversion from 'float' to 'int', possible loss of data |
| 269 | "/wd4267", # conversion from 'size_t' to 'int', possible loss of data |
| 270 | "/wd4800", # forcing value to bool 'true' or 'false' (performance warning) |
| 271 | |
| 272 | # Probably only triggers when /EHsc is enabled. |
| 273 | "/wd4291", # no matching operator delete found; |
| 274 | # memory will not be freed if initialization throws an exception |
| 275 | ] |
| 276 | } else { |
| 277 | cflags += [ |
| 278 | "-Wall", |
| 279 | "-Wextra", |
| 280 | "-Winit-self", |
| 281 | "-Wpointer-arith", |
| 282 | "-Wsign-compare", |
| 283 | "-Wvla", |
| 284 | |
| 285 | "-Wno-deprecated-declarations", |
Mike Klein | db402ca | 2016-12-13 12:46:05 -0500 | [diff] [blame^] | 286 | "-Wno-maybe-uninitialized", |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 287 | ] |
| 288 | cflags_cc += [ "-Wnon-virtual-dtor" ] |
| 289 | |
| 290 | if (is_clang) { |
| 291 | cflags += [ |
| 292 | "-Weverything", |
| 293 | "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings. |
| 294 | ] |
| 295 | |
| 296 | if (is_android && target_cpu == "x86") { |
| 297 | # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android. |
| 298 | # We're pretty sure it's actually 8-byte alignment. |
| 299 | cflags += [ "-Wno-over-aligned" ] |
| 300 | } |
| 301 | |
| 302 | cflags += [ |
| 303 | "-Wno-cast-align", |
| 304 | "-Wno-conditional-uninitialized", |
| 305 | "-Wno-conversion", |
| 306 | "-Wno-disabled-macro-expansion", |
| 307 | "-Wno-documentation", |
| 308 | "-Wno-documentation-unknown-command", |
| 309 | "-Wno-double-promotion", |
| 310 | "-Wno-exit-time-destructors", # TODO: OK outside libskia |
| 311 | "-Wno-float-conversion", |
| 312 | "-Wno-float-equal", |
| 313 | "-Wno-format-nonliteral", |
| 314 | "-Wno-global-constructors", # TODO: OK outside libskia |
| 315 | "-Wno-gnu-zero-variadic-macro-arguments", |
| 316 | "-Wno-missing-prototypes", |
| 317 | "-Wno-missing-variable-declarations", |
| 318 | "-Wno-pedantic", |
| 319 | "-Wno-reserved-id-macro", |
| 320 | "-Wno-shadow", |
| 321 | "-Wno-shift-sign-overflow", |
| 322 | "-Wno-sign-conversion", |
| 323 | "-Wno-switch-enum", |
| 324 | "-Wno-undef", |
| 325 | "-Wno-unreachable-code", |
| 326 | "-Wno-unreachable-code-break", |
| 327 | "-Wno-unreachable-code-return", |
| 328 | "-Wno-unused-macros", |
| 329 | "-Wno-unused-member-function", |
| 330 | ] |
| 331 | cflags_cc += [ |
| 332 | "-Wno-abstract-vbase-init", |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 333 | "-Wno-weak-vtables", |
| 334 | ] |
| 335 | |
| 336 | # We are unlikely to want to fix these. |
| 337 | cflags += [ |
| 338 | "-Wno-covered-switch-default", |
| 339 | "-Wno-deprecated", |
| 340 | "-Wno-implicit-fallthrough", |
| 341 | "-Wno-missing-noreturn", |
| 342 | "-Wno-old-style-cast", |
| 343 | "-Wno-padded", |
| 344 | ] |
| 345 | cflags_cc += [ |
| 346 | "-Wno-c++98-compat", |
| 347 | "-Wno-c++98-compat-pedantic", |
| 348 | "-Wno-undefined-func-template", |
| 349 | ] |
Mike Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 350 | cflags_objc += [ |
| 351 | "-Wno-direct-ivar-access", |
| 352 | "-Wno-objc-interface-ivars", |
| 353 | ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | } |
Mike Klein | 50500ad | 2016-11-16 12:13:44 -0500 | [diff] [blame] | 357 | config("warnings_except_public_headers") { |
| 358 | if (!is_win) { |
| 359 | cflags = [ "-Wno-unused-parameter" ] |
| 360 | } |
| 361 | } |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 362 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 363 | config("extra_flags") { |
| 364 | cflags = extra_cflags |
| 365 | cflags_c = extra_cflags_c |
| 366 | cflags_cc = extra_cflags_cc |
| 367 | ldflags = extra_ldflags |
| 368 | } |
| 369 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 370 | config("debug_symbols") { |
| 371 | # It's annoying to wait for full debug symbols to push over |
| 372 | # to Android devices. -gline-tables-only is a lot slimmer. |
| 373 | if (is_android) { |
| 374 | cflags = [ "-gline-tables-only" ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 375 | } else if (is_win) { |
| 376 | cflags = [ "/Zi" ] |
Mike Klein | 5286d6c | 2016-10-13 13:19:25 -0400 | [diff] [blame] | 377 | ldflags = [ "/DEBUG" ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 378 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 379 | cflags = [ "-g" ] |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | config("no_rtti") { |
| 384 | if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 385 | if (is_win) { |
| 386 | cflags_cc = [ "/GR-" ] |
| 387 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 388 | cflags_cc = [ "-fno-rtti" ] |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | config("release") { |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 394 | if (is_win) { |
Mike Klein | 916ca1d | 2016-10-20 13:34:18 -0400 | [diff] [blame] | 395 | cflags = [ |
| 396 | "/O2", |
| 397 | "/Zc:inline", |
Mike Klein | 8ffb260 | 2016-10-20 15:45:02 -0400 | [diff] [blame] | 398 | "/GS-", |
Mike Klein | 916ca1d | 2016-10-20 13:34:18 -0400 | [diff] [blame] | 399 | ] |
Mike Klein | 90a381f | 2016-10-20 13:52:38 -0400 | [diff] [blame] | 400 | ldflags = [ |
| 401 | "/OPT:ICF", |
| 402 | "/OPT:REF", |
| 403 | ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 404 | } else { |
Mike Klein | 0bcfeac | 2016-10-19 22:24:10 -0400 | [diff] [blame] | 405 | cflags = [ |
| 406 | "-O3", |
| 407 | "-momit-leaf-frame-pointer", |
| 408 | ] |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 409 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 410 | defines = [ "NDEBUG" ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | config("executable") { |
Mike Klein | c5875fb | 2016-12-06 10:46:02 -0500 | [diff] [blame] | 414 | if (is_android) { |
| 415 | ldflags = [ "-pie" ] |
| 416 | } else if (is_mac) { |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 417 | ldflags = [ "-Wl,-rpath,@loader_path/." ] |
| 418 | } else if (is_linux) { |
mtklein | a846c72 | 2016-09-15 10:44:15 -0700 | [diff] [blame] | 419 | ldflags = [ |
| 420 | "-rdynamic", |
| 421 | "-Wl,-rpath,\$ORIGIN", |
| 422 | ] |
Mike Klein | 4b6b503 | 2016-11-06 11:54:19 -0500 | [diff] [blame] | 423 | } else if (is_win) { |
| 424 | ldflags = [ |
| 425 | "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed". |
| 426 | "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to. |
| 427 | ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 431 | toolchain("msvc") { |
Mike Klein | 3eb7121 | 2016-10-11 17:08:53 -0400 | [diff] [blame] | 432 | lib_dir_switch = "/LIBPATH:" |
| 433 | |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 434 | bin = "$windk/VC/bin/amd64" |
| 435 | env_setup = "" |
| 436 | if (target_cpu == "x86") { |
| 437 | bin += "_x86" |
| 438 | env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && " |
| 439 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 440 | |
| 441 | tool("cc") { |
| 442 | rspfile = "{{output}}.rsp" |
| 443 | precompiled_header_type = "msvc" |
| 444 | pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" |
| 445 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 446 | # Label names may have spaces so pdbname must be quoted. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 447 | command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\"" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 448 | depsformat = "msvc" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 449 | outputs = [ |
| 450 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 451 | ] |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 452 | rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 453 | description = "compile {{source}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | tool("cxx") { |
| 457 | rspfile = "{{output}}.rsp" |
| 458 | precompiled_header_type = "msvc" |
| 459 | pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" |
| 460 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 461 | # Label names may have spaces so pdbname must be quoted. |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 462 | command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\"" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 463 | depsformat = "msvc" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 464 | outputs = [ |
| 465 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", |
| 466 | ] |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 467 | rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 468 | description = "compile {{source}}" |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 469 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 470 | |
| 471 | tool("alink") { |
| 472 | rspfile = "{{output}}.rsp" |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 473 | |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 474 | command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 475 | outputs = [ |
| 476 | # Ignore {{output_extension}} and always use .lib, there's no reason to |
| 477 | # allow targets to override this extension on Windows. |
| 478 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 479 | ] |
| 480 | default_output_extension = ".lib" |
| 481 | default_output_dir = "{{target_out_dir}}" |
| 482 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 483 | # inputs_newline works around a fixed per-line buffer size in the linker. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 484 | rspfile_content = "{{inputs_newline}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 485 | description = "link {{output}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Mike Klein | 1a8d675 | 2016-10-17 11:51:11 -0400 | [diff] [blame] | 488 | tool("solink") { |
| 489 | dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}" |
| 490 | libname = "${dllname}.lib" |
| 491 | pdbname = "${dllname}.pdb" |
| 492 | rspfile = "${dllname}.rsp" |
| 493 | |
| 494 | command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile" |
| 495 | outputs = [ |
| 496 | dllname, |
| 497 | libname, |
| 498 | pdbname, |
| 499 | ] |
| 500 | default_output_extension = ".dll" |
| 501 | default_output_dir = "{{root_out_dir}}" |
| 502 | |
| 503 | link_output = libname |
| 504 | depend_output = libname |
| 505 | runtime_outputs = [ |
| 506 | dllname, |
| 507 | pdbname, |
| 508 | ] |
| 509 | |
| 510 | # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn. |
| 511 | restat = true |
| 512 | |
| 513 | # inputs_newline works around a fixed per-line buffer size in the linker. |
| 514 | rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}" |
| 515 | description = "link {{output}}" |
| 516 | } |
| 517 | |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 518 | tool("link") { |
| 519 | exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" |
| 520 | pdbname = "$exename.pdb" |
| 521 | rspfile = "$exename.rsp" |
| 522 | |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 523 | command = |
| 524 | "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 525 | |
| 526 | default_output_extension = ".exe" |
| 527 | default_output_dir = "{{root_out_dir}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 528 | outputs = [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 529 | exename, |
| 530 | ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 531 | |
Mike Klein | 0f61faa | 2016-10-11 16:26:57 -0400 | [diff] [blame] | 532 | # inputs_newline works around a fixed per-line buffer size in the linker. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 533 | rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 534 | description = "link {{output}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 535 | } |
| 536 | |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 537 | tool("stamp") { |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 538 | command = "$stamp {{output}}" |
Mike Klein | c756e86 | 2016-10-13 14:31:01 -0400 | [diff] [blame] | 539 | description = "stamp {{output}}" |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 540 | } |
Mike Klein | 1a8d675 | 2016-10-17 11:51:11 -0400 | [diff] [blame] | 541 | |
| 542 | tool("copy") { |
| 543 | cp_py = rebase_path("cp.py") |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 544 | command = "$python $cp_py {{source}} {{output}}" |
Mike Klein | 1a8d675 | 2016-10-17 11:51:11 -0400 | [diff] [blame] | 545 | description = "copy {{source}} {{output}}" |
| 546 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 547 | } |
| 548 | |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 549 | toolchain("gcc_like") { |
| 550 | lib_switch = "-l" |
| 551 | lib_dir_switch = "-L" |
| 552 | |
| 553 | tool("cc") { |
| 554 | depfile = "{{output}}.d" |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 555 | command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 556 | depsformat = "gcc" |
| 557 | outputs = [ |
| 558 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 559 | ] |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 560 | description = "compile {{source}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | tool("cxx") { |
| 564 | depfile = "{{output}}.d" |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 565 | command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 566 | depsformat = "gcc" |
| 567 | outputs = [ |
| 568 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 569 | ] |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 570 | description = "compile {{source}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Mike Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 573 | tool("objc") { |
| 574 | depfile = "{{output}}.d" |
| 575 | command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}" |
| 576 | depsformat = "gcc" |
| 577 | outputs = [ |
| 578 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 579 | ] |
| 580 | description = "compile {{source}}" |
| 581 | } |
| 582 | |
| 583 | tool("objcxx") { |
| 584 | depfile = "{{output}}.d" |
| 585 | command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}" |
| 586 | depsformat = "gcc" |
| 587 | outputs = [ |
| 588 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 589 | ] |
| 590 | description = "compile {{source}}" |
| 591 | } |
| 592 | |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 593 | tool("asm") { |
| 594 | depfile = "{{output}}.d" |
mtklein | 60b7ab7 | 2016-09-20 12:09:12 -0700 | [diff] [blame] | 595 | command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 596 | depsformat = "gcc" |
| 597 | outputs = [ |
| 598 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 599 | ] |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 600 | description = "compile {{source}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | tool("alink") { |
Mike Klein | 44b36a2 | 2016-11-06 11:20:09 -0500 | [diff] [blame] | 604 | rspfile = "{{output}}.rsp" |
| 605 | rspfile_content = "{{inputs}}" |
| 606 | ar_py = rebase_path("ar.py") |
| 607 | command = "$python $ar_py $ar {{output}} $rspfile" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 608 | outputs = [ |
mtklein | 5db44aa | 2016-07-29 09:10:31 -0700 | [diff] [blame] | 609 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 610 | ] |
| 611 | default_output_extension = ".a" |
| 612 | output_prefix = "lib" |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 613 | description = "link {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | tool("solink") { |
| 617 | soname = "{{target_output_name}}{{output_extension}}" |
| 618 | |
| 619 | rpath = "-Wl,-soname,$soname" |
| 620 | if (is_mac) { |
| 621 | rpath = "-Wl,-install_name,@rpath/$soname" |
| 622 | } |
| 623 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 624 | command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 625 | outputs = [ |
| 626 | "{{root_out_dir}}/$soname", |
| 627 | ] |
| 628 | output_prefix = "lib" |
| 629 | default_output_extension = ".so" |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 630 | description = "link {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | tool("link") { |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 634 | command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 635 | outputs = [ |
| 636 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 637 | ] |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 638 | description = "link {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | tool("stamp") { |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 642 | command = "$stamp {{output}}" |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 643 | description = "stamp {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | tool("copy") { |
Mike Klein | 1a8d675 | 2016-10-17 11:51:11 -0400 | [diff] [blame] | 647 | cp_py = rebase_path("cp.py") |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 648 | command = "$python $cp_py {{source}} {{output}}" |
Mike Klein | 24267ff | 2016-10-17 10:41:41 -0400 | [diff] [blame] | 649 | description = "copy {{source}} {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 650 | } |
| 651 | } |