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