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