blob: 3573740f99a086e6e5196993dd7723426fe9ecc1 [file] [log] [blame]
mtklein7fbfbbe2016-07-21 12:25:45 -07001# 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
6declare_args() {
mtklein349cece2016-08-26 08:13:04 -07007 ar = "ar"
mtklein7fbfbbe2016-07-21 12:25:45 -07008 cc = "cc"
9 cxx = "c++"
mtklein8079ba62016-08-16 09:31:16 -070010
mtklein7d6fb2c2016-08-25 14:50:44 -070011 if (is_android) {
Mike Klein82364ba2016-10-24 16:49:15 -040012 if (host_os == "win") {
Mike Klein67702f62016-12-09 10:32:28 -050013 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 Klein82364ba2016-10-24 16:49:15 -040020 }
mtklein7d6fb2c2016-08-25 14:50:44 -070021 }
22
Ben Wagner4e8472c2017-03-20 16:53:05 -040023 msvc = 2015
herbb6318bf2016-09-16 13:29:57 -070024
Mike Klein121563e2016-10-04 17:09:13 -040025 extra_cflags = []
26 extra_cflags_c = []
27 extra_cflags_cc = []
28 extra_ldflags = []
mtkleincab0bb72016-08-26 13:43:19 -070029
mtklein60b7ab72016-09-20 12:09:12 -070030 cc_wrapper = ""
Herb Derby76073c12016-12-08 19:00:40 -050031 malloc = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070032}
Ben Wagner4e8472c2017-03-20 16:53:05 -040033declare_args() {
34 if (msvc == 2015) {
35 windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0"
36 } else {
37 windk = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional"
38 }
39}
mtklein7fbfbbe2016-07-21 12:25:45 -070040
Mike Klein82364ba2016-10-24 16:49:15 -040041if (host_os == "win") {
42 python = "python.bat"
43 stamp = "cmd.exe /c echo >"
44} else {
45 python = "python"
46 stamp = "touch"
47}
48
Mike Klein87c36f22016-11-13 10:29:25 -050049is_clang = is_android || is_ios || is_mac || (cc == "clang" && cxx == "clang++")
50if (!is_clang && !is_win) {
Mike Klein461d3282016-10-11 13:51:55 -040051 is_clang = exec_script("is_clang.py",
52 [
53 cc,
54 cxx,
55 ],
56 "value")
57}
mtkleinf347c512016-09-26 08:40:12 -070058
Mike Klein7d302882016-11-03 14:06:31 -040059if (is_ios) {
Matthew Leibowitz3150ec62017-03-14 16:22:32 -040060 if (is_tvos) {
61 sdk = "appletvos"
62 if (target_cpu == "x86" || target_cpu == "x64") {
63 sdk = "appletvsimulator"
64 }
65 } else {
66 sdk = "iphoneos"
67 if (target_cpu == "x86" || target_cpu == "x64") {
68 sdk = "iphonesimulator"
69 }
Mike Klein7a5e0f32017-03-13 09:25:33 -070070 }
71 ios_sysroot = exec_script("find_ios_sysroot.py", [ sdk ], "trim string")
Mike Klein7d302882016-11-03 14:06:31 -040072}
73
mtkleinb9be9792016-09-16 14:44:18 -070074config("default") {
75 asmflags = []
76 cflags = []
77 cflags_c = []
78 cflags_cc = []
79 defines = []
80 ldflags = []
Herb Derby76073c12016-12-08 19:00:40 -050081 libs = []
mtkleinb9be9792016-09-16 14:44:18 -070082
83 if (is_win) {
84 cflags += [
85 "/FS", # Preserve previous PDB behavior.
herbb6318bf2016-09-16 13:29:57 -070086 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040087 "/WX", # Treat warnings as errors.
Ben Wagnere6b274e2017-01-03 17:09:59 -050088 "/utf-8", # Set Source and Executable character sets to UTF-8.
herbb6318bf2016-09-16 13:29:57 -070089 ]
mtkleinb9be9792016-09-16 14:44:18 -070090 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040091 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
92 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070093 "WIN32_LEAN_AND_MEAN",
94 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070095 ]
Mike Klein0f61faa2016-10-11 16:26:57 -040096 include_dirs = [
Ben Wagner4e8472c2017-03-20 16:53:05 -040097 #2017
98 "$windk/VC/Tools/MSVC/14.10.25017/include",
99
100 #2015
Mike Kleind3016832016-10-12 15:52:44 -0400101 "$windk/VC/include",
Mike Kleincc300a12016-10-12 16:25:27 -0400102
Mike Kleind3016832016-10-12 15:52:44 -0400103 # For local builds.
Ben Wagner4e8472c2017-03-20 16:53:05 -0400104 # 2017
105 "$windk/../../../Windows Kits/10/Include/10.0.14393.0/shared",
106 "$windk/../../../Windows Kits/10/Include/10.0.14393.0/ucrt",
107 "$windk/../../../Windows Kits/10/Include/10.0.14393.0/um",
108 "$windk/../../../Windows Kits/10/Include/10.0.14393.0/winrt",
109
110 # 2015
Mike Klein0f61faa2016-10-11 16:26:57 -0400111 "$windk/../Windows Kits/8.1/Include/shared",
Ben Wagner4e8472c2017-03-20 16:53:05 -0400112 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
Mike Klein3eb71212016-10-11 17:08:53 -0400113 "$windk/../Windows Kits/8.1/Include/um",
Brian Osman21d742d2017-01-10 13:31:33 -0500114 "$windk/../Windows Kits/8.1/Include/winrt",
Mike Kleincc300a12016-10-12 16:25:27 -0400115
Mike Kleind3016832016-10-12 15:52:44 -0400116 # For builds using win_toolchain asset.
Brian Osman3f289332017-01-10 10:38:23 -0500117 "$windk/win_sdk/Include/10.0.14393.0/shared",
118 "$windk/win_sdk/Include/10.0.14393.0/ucrt",
119 "$windk/win_sdk/Include/10.0.14393.0/um",
Brian Osman21d742d2017-01-10 13:31:33 -0500120 "$windk/win_sdk/Include/10.0.14393.0/winrt",
Mike Klein0f61faa2016-10-11 16:26:57 -0400121 ]
Mike Klein3eb71212016-10-11 17:08:53 -0400122 lib_dirs = [
Mike Kleind3016832016-10-12 15:52:44 -0400123 # For local builds.
Ben Wagner4e8472c2017-03-20 16:53:05 -0400124 # 2017
125 "$windk/../../../Windows Kits/10/Lib/10.0.14393.0/ucrt/$target_cpu",
126 "$windk/../../../Windows Kits/10/Lib/10.0.14393.0/um/$target_cpu",
127
128 #2015
Mike Klein0bc5a762016-10-12 22:42:55 -0400129 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
130 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
Mike Kleincc300a12016-10-12 16:25:27 -0400131
Mike Kleind3016832016-10-12 15:52:44 -0400132 # For builds using win_toolchain asset.
Brian Osman3f289332017-01-10 10:38:23 -0500133 "$windk/win_sdk/Lib/10.0.14393.0/ucrt/$target_cpu",
134 "$windk/win_sdk/Lib/10.0.14393.0/um/$target_cpu",
Mike Klein3eb71212016-10-11 17:08:53 -0400135 ]
Ben Wagner4e8472c2017-03-20 16:53:05 -0400136
137 #2017
138 lib_dirs += [ "$windk/VC/Tools/MSVC/14.10.25017/lib/$target_cpu" ]
139
140 #2015
Mike Klein0bc5a762016-10-12 22:42:55 -0400141 if (target_cpu == "x86") {
142 lib_dirs += [ "$windk/VC/lib" ]
143 } else {
144 lib_dirs += [ "$windk/VC/lib/amd64" ]
145 }
mtkleinb9be9792016-09-16 14:44:18 -0700146 } else {
147 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700148 "-fstrict-aliasing",
149 "-fPIC",
herbb6318bf2016-09-16 13:29:57 -0700150 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -0700151 ]
mtkleinb9be9792016-09-16 14:44:18 -0700152 cflags_cc += [
herbb6318bf2016-09-16 13:29:57 -0700153 "-std=c++11",
herbb6318bf2016-09-16 13:29:57 -0700154 "-fno-threadsafe-statics",
herbb6318bf2016-09-16 13:29:57 -0700155 ]
Mike Kleineec23d12017-03-26 20:11:48 -0400156
157 # The main idea is to slim the exported API, but these flags also improve link time on Mac.
158 # These would make stack traces worse on Linux, so we don't just set them willy-nilly.
159 if (is_component_build || is_mac) {
160 cflags += [ "-fvisibility=hidden" ]
161 cflags_cc += [ "-fvisibility-inlines-hidden" ]
162 }
mtkleinb9be9792016-09-16 14:44:18 -0700163 }
herbb6318bf2016-09-16 13:29:57 -0700164
mtkleinb9be9792016-09-16 14:44:18 -0700165 if (current_cpu == "arm") {
166 cflags += [
167 "-march=armv7-a",
168 "-mfpu=neon",
169 "-mthumb",
170 ]
171 } else if (current_cpu == "mipsel") {
172 cflags += [
Mike Kleine6320032017-03-04 05:39:54 -0500173 "-no-integrated-as", # Clang <4.0 doesn't understand 'usw' mnemonic.
mtkleinb9be9792016-09-16 14:44:18 -0700174 "-march=mips32r2",
175 "-mdspr2",
176 ]
Mike Klein5d8cf292016-10-12 19:36:09 -0400177 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700178 asmflags += [ "-m32" ]
179 cflags += [
180 "-m32",
181 "-msse2",
182 "-mfpmath=sse",
183 ]
184 ldflags += [ "-m32" ]
185 }
herbb6318bf2016-09-16 13:29:57 -0700186
Herb Derby76073c12016-12-08 19:00:40 -0500187 if (malloc != "" && !is_win) {
188 cflags += [
189 "-fno-builtin-malloc",
190 "-fno-builtin-calloc",
191 "-fno-builtin-realloc",
192 "-fno-builtin-free",
193 ]
194 libs += [ malloc ]
195 }
196
mtkleinb9be9792016-09-16 14:44:18 -0700197 if (is_android) {
198 asmflags += [
199 "--target=$ndk_target",
200 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
201 ]
202 cflags += [
203 "--sysroot=$ndk/platforms/$ndk_platform",
204 "--target=$ndk_target",
205 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
206 ]
207 cflags_cc += [
208 "-isystem$ndk/sources/android/support/include",
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500209 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/include",
210 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib/include",
mtkleinb9be9792016-09-16 14:44:18 -0700211 ]
212 ldflags += [
213 "--sysroot=$ndk/platforms/$ndk_platform",
214 "--target=$ndk_target",
215 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700216 ]
217 lib_dirs = [
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500218 "$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib",
mtkleinb9be9792016-09-16 14:44:18 -0700219 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
220 ]
herbb6318bf2016-09-16 13:29:57 -0700221
Mike Klein4fdc5432016-10-11 11:21:36 -0400222 if (current_cpu == "mips64el") {
223 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
224 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
225 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
226 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein978cceb2016-12-08 10:29:27 -0500227 ldflags += [ "-B$ndk/platforms/$ndk_platform/usr/lib64" ]
Mike Klein4fdc5432016-10-11 11:21:36 -0400228 }
229
Mike Kleinb7ce80b2016-12-14 13:17:53 -0500230 libs += [ "gnustl_static" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700231 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700232
Mike Klein7d302882016-11-03 14:06:31 -0400233 if (is_ios) {
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500234 _target = target_cpu
235 if (target_cpu == "arm") {
236 _target = "armv7"
Mike Klein7a5e0f32017-03-13 09:25:33 -0700237 } else if (target_cpu == "x86") {
238 _target = "i386"
239 } else if (target_cpu == "x64") {
240 _target = "x86_64"
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500241 }
Mike Klein4fe2b152017-02-17 15:36:01 -0500242 asmflags += [
243 "-isysroot",
244 ios_sysroot,
245 "-arch",
246 _target,
247 ]
Mike Klein7d302882016-11-03 14:06:31 -0400248 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500249 "-isysroot",
250 ios_sysroot,
251 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500252 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400253 ]
254 cflags_cc += [ "-stdlib=libc++" ]
255 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500256 "-isysroot",
257 ios_sysroot,
258 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500259 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400260 "-stdlib=libc++",
261 ]
Herb Derby76073c12016-12-08 19:00:40 -0500262 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400263 }
264
mtkleinb9be9792016-09-16 14:44:18 -0700265 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500266 libs += [ "pthread" ]
mtkleinb9be9792016-09-16 14:44:18 -0700267 }
268
269 if (sanitize != "") {
270 # You can either pass the sanitizers directly, e.g. "address,undefined",
271 # or pass one of the couple common aliases used by the bots.
272 sanitizers = sanitize
273 if (sanitize == "ASAN") {
274 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"
275 } else if (sanitize == "TSAN") {
276 sanitizers = "thread"
277 } else if (sanitize == "MSAN") {
278 sanitizers = "memory"
279 }
280
281 cflags += [
282 "-fsanitize=$sanitizers",
283 "-fno-sanitize-recover=$sanitizers",
284 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
285 ]
286 ldflags += [ "-fsanitize=$sanitizers" ]
287 if (sanitizers == "memory") {
288 cflags += [ "-fsanitize-memory-track-origins" ]
289 cflags_cc += [ "-stdlib=libc++" ]
290 ldflags += [ "-stdlib=libc++" ]
291 }
292 }
293}
294
Mike Klein6e55fef2016-10-26 11:41:47 -0400295config("no_exceptions") {
296 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
297 if (!is_win) {
298 cflags_cc = [ "-fno-exceptions" ]
299 }
300}
301
Mike Kleinc7165c22016-10-12 23:58:06 -0400302config("warnings") {
303 cflags = []
304 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400305 cflags_objc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400306 if (is_win) {
307 cflags += [
308 "/W3", # Turn on lots of warnings.
309
310 # Disable a bunch of warnings:
311 "/wd4244", # conversion from 'float' to 'int', possible loss of data
312 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
313 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
314
315 # Probably only triggers when /EHsc is enabled.
316 "/wd4291", # no matching operator delete found;
317 # memory will not be freed if initialization throws an exception
318 ]
319 } else {
320 cflags += [
321 "-Wall",
322 "-Wextra",
323 "-Winit-self",
324 "-Wpointer-arith",
325 "-Wsign-compare",
326 "-Wvla",
327
328 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500329 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400330 ]
331 cflags_cc += [ "-Wnon-virtual-dtor" ]
332
333 if (is_clang) {
334 cflags += [
335 "-Weverything",
336 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
337 ]
338
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500339 if ((target_cpu == "x86" && is_android) ||
340 (target_cpu == "arm" && is_ios)) {
341 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android and 32-bit iOS.
Mike Kleinc7165c22016-10-12 23:58:06 -0400342 # We're pretty sure it's actually 8-byte alignment.
343 cflags += [ "-Wno-over-aligned" ]
344 }
345
346 cflags += [
347 "-Wno-cast-align",
348 "-Wno-conditional-uninitialized",
349 "-Wno-conversion",
350 "-Wno-disabled-macro-expansion",
351 "-Wno-documentation",
352 "-Wno-documentation-unknown-command",
353 "-Wno-double-promotion",
354 "-Wno-exit-time-destructors", # TODO: OK outside libskia
355 "-Wno-float-conversion",
356 "-Wno-float-equal",
357 "-Wno-format-nonliteral",
358 "-Wno-global-constructors", # TODO: OK outside libskia
359 "-Wno-gnu-zero-variadic-macro-arguments",
360 "-Wno-missing-prototypes",
361 "-Wno-missing-variable-declarations",
362 "-Wno-pedantic",
363 "-Wno-reserved-id-macro",
364 "-Wno-shadow",
365 "-Wno-shift-sign-overflow",
366 "-Wno-sign-conversion",
Matt Sarettd3ed4022017-01-04 17:13:44 -0500367 "-Wno-signed-enum-bitfield",
Mike Kleinc7165c22016-10-12 23:58:06 -0400368 "-Wno-switch-enum",
369 "-Wno-undef",
370 "-Wno-unreachable-code",
371 "-Wno-unreachable-code-break",
372 "-Wno-unreachable-code-return",
373 "-Wno-unused-macros",
374 "-Wno-unused-member-function",
375 ]
376 cflags_cc += [
377 "-Wno-abstract-vbase-init",
Mike Kleinc7165c22016-10-12 23:58:06 -0400378 "-Wno-weak-vtables",
379 ]
380
381 # We are unlikely to want to fix these.
382 cflags += [
383 "-Wno-covered-switch-default",
384 "-Wno-deprecated",
385 "-Wno-implicit-fallthrough",
386 "-Wno-missing-noreturn",
387 "-Wno-old-style-cast",
388 "-Wno-padded",
389 ]
390 cflags_cc += [
391 "-Wno-c++98-compat",
392 "-Wno-c++98-compat-pedantic",
393 "-Wno-undefined-func-template",
394 ]
Mike Klein43c25262016-10-20 10:17:47 -0400395 cflags_objc += [
396 "-Wno-direct-ivar-access",
397 "-Wno-objc-interface-ivars",
398 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400399 }
400 }
401}
Mike Klein50500ad2016-11-16 12:13:44 -0500402config("warnings_except_public_headers") {
403 if (!is_win) {
404 cflags = [ "-Wno-unused-parameter" ]
405 }
406}
Mike Kleinc7165c22016-10-12 23:58:06 -0400407
Mike Klein121563e2016-10-04 17:09:13 -0400408config("extra_flags") {
409 cflags = extra_cflags
410 cflags_c = extra_cflags_c
411 cflags_cc = extra_cflags_cc
412 ldflags = extra_ldflags
413}
414
mtkleinb9be9792016-09-16 14:44:18 -0700415config("debug_symbols") {
416 # It's annoying to wait for full debug symbols to push over
417 # to Android devices. -gline-tables-only is a lot slimmer.
418 if (is_android) {
419 cflags = [ "-gline-tables-only" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400420 } else if (is_win) {
421 cflags = [ "/Zi" ]
Mike Klein5286d6c2016-10-13 13:19:25 -0400422 ldflags = [ "/DEBUG" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400423 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700424 cflags = [ "-g" ]
425 }
426}
427
428config("no_rtti") {
429 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400430 if (is_win) {
431 cflags_cc = [ "/GR-" ]
432 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700433 cflags_cc = [ "-fno-rtti" ]
434 }
435 }
436}
437
438config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400439 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400440 cflags = [
441 "/O2",
442 "/Zc:inline",
Mike Klein8ffb2602016-10-20 15:45:02 -0400443 "/GS-",
Mike Klein916ca1d2016-10-20 13:34:18 -0400444 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400445 ldflags = [
446 "/OPT:ICF",
447 "/OPT:REF",
448 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400449 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400450 cflags = [
451 "-O3",
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500452 "-fdata-sections",
453 "-ffunction-sections",
Mike Klein0bcfeac2016-10-19 22:24:10 -0400454 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500455 if (is_mac || is_ios) {
456 ldflags = [ "-dead_strip" ]
457 } else {
458 ldflags = [ "-Wl,--gc-sections" ]
459 }
herbb6318bf2016-09-16 13:29:57 -0700460 }
mtkleinb9be9792016-09-16 14:44:18 -0700461 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700462}
463
464config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500465 if (is_android) {
466 ldflags = [ "-pie" ]
467 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700468 ldflags = [ "-Wl,-rpath,@loader_path/." ]
469 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700470 ldflags = [
471 "-rdynamic",
472 "-Wl,-rpath,\$ORIGIN",
473 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500474 } else if (is_win) {
475 ldflags = [
476 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
477 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
478 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700479 }
480}
481
herbb6318bf2016-09-16 13:29:57 -0700482toolchain("msvc") {
Mike Klein3eb71212016-10-11 17:08:53 -0400483 lib_dir_switch = "/LIBPATH:"
484
Ben Wagner4e8472c2017-03-20 16:53:05 -0400485 if (msvc == 2015) {
486 bin = "$windk/VC/bin/amd64"
487 env_setup = ""
488 if (target_cpu == "x86") {
489 bin += "_x86"
490 env_setup = "cmd /c $windk/win_sdk/bin/SetEnv.cmd /x86 && "
491 }
492 } else {
493 bin = "$windk/VC/Tools/MSVC/14.10.25017/bin/HostX64/$target_cpu"
494 env_setup = ""
495 if (target_cpu == "x86") {
496 print("Be sure to run")
497 print("$windk/VC/Auxiliary/Build/vcvarsall.bat amd64_x86")
498 print("to set up your environment before running ninja.")
499 }
Mike Klein0bc5a762016-10-12 22:42:55 -0400500 }
herbb6318bf2016-09-16 13:29:57 -0700501
Mike Kleined1b9022017-02-21 12:13:44 -0500502 tool("asm") {
503 command = "$env_setup$bin/ml64.exe /nologo /c /Fo {{output}} {{source}}"
504 outputs = [
505 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
506 ]
507 description = "assemble {{source}}"
508 }
509
herbb6318bf2016-09-16 13:29:57 -0700510 tool("cc") {
511 rspfile = "{{output}}.rsp"
512 precompiled_header_type = "msvc"
513 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
514
Mike Klein0f61faa2016-10-11 16:26:57 -0400515 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400516 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700517 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700518 outputs = [
519 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
herbb6318bf2016-09-16 13:29:57 -0700520 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400521 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400522 description = "compile {{source}}"
herbb6318bf2016-09-16 13:29:57 -0700523 }
524
525 tool("cxx") {
526 rspfile = "{{output}}.rsp"
527 precompiled_header_type = "msvc"
528 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
529
Mike Klein0f61faa2016-10-11 16:26:57 -0400530 # Label names may have spaces so pdbname must be quoted.
Mike Klein0bc5a762016-10-12 22:42:55 -0400531 command = "$env_setup$bin/cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
herbb6318bf2016-09-16 13:29:57 -0700532 depsformat = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700533 outputs = [
534 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
535 ]
Mike Klein0f61faa2016-10-11 16:26:57 -0400536 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400537 description = "compile {{source}}"
mtkleinb9be9792016-09-16 14:44:18 -0700538 }
herbb6318bf2016-09-16 13:29:57 -0700539
540 tool("alink") {
541 rspfile = "{{output}}.rsp"
mtkleinb9be9792016-09-16 14:44:18 -0700542
Mike Kleinc756e862016-10-13 14:31:01 -0400543 command = "$env_setup$bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700544 outputs = [
545 # Ignore {{output_extension}} and always use .lib, there's no reason to
546 # allow targets to override this extension on Windows.
547 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
548 ]
549 default_output_extension = ".lib"
550 default_output_dir = "{{target_out_dir}}"
551
Mike Klein0f61faa2016-10-11 16:26:57 -0400552 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700553 rspfile_content = "{{inputs_newline}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400554 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700555 }
556
Mike Klein1a8d6752016-10-17 11:51:11 -0400557 tool("solink") {
558 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
559 libname = "${dllname}.lib"
560 pdbname = "${dllname}.pdb"
561 rspfile = "${dllname}.rsp"
562
563 command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
564 outputs = [
565 dllname,
566 libname,
567 pdbname,
568 ]
569 default_output_extension = ".dll"
570 default_output_dir = "{{root_out_dir}}"
571
572 link_output = libname
573 depend_output = libname
574 runtime_outputs = [
575 dllname,
576 pdbname,
577 ]
578
579 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
580 restat = true
581
582 # inputs_newline works around a fixed per-line buffer size in the linker.
583 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
584 description = "link {{output}}"
585 }
586
herbb6318bf2016-09-16 13:29:57 -0700587 tool("link") {
588 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
589 pdbname = "$exename.pdb"
590 rspfile = "$exename.rsp"
591
Mike Klein0bc5a762016-10-12 22:42:55 -0400592 command =
593 "$env_setup$bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
herbb6318bf2016-09-16 13:29:57 -0700594
595 default_output_extension = ".exe"
596 default_output_dir = "{{root_out_dir}}"
herbb6318bf2016-09-16 13:29:57 -0700597 outputs = [
herbb6318bf2016-09-16 13:29:57 -0700598 exename,
599 ]
mtkleinb9be9792016-09-16 14:44:18 -0700600
Mike Klein0f61faa2016-10-11 16:26:57 -0400601 # inputs_newline works around a fixed per-line buffer size in the linker.
herbb6318bf2016-09-16 13:29:57 -0700602 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400603 description = "link {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700604 }
605
herbb6318bf2016-09-16 13:29:57 -0700606 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400607 command = "$stamp {{output}}"
Mike Kleinc756e862016-10-13 14:31:01 -0400608 description = "stamp {{output}}"
herbb6318bf2016-09-16 13:29:57 -0700609 }
Mike Klein1a8d6752016-10-17 11:51:11 -0400610
611 tool("copy") {
612 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400613 command = "$python $cp_py {{source}} {{output}}"
Mike Klein1a8d6752016-10-17 11:51:11 -0400614 description = "copy {{source}} {{output}}"
615 }
herbb6318bf2016-09-16 13:29:57 -0700616}
617
mtklein7fbfbbe2016-07-21 12:25:45 -0700618toolchain("gcc_like") {
619 lib_switch = "-l"
620 lib_dir_switch = "-L"
621
622 tool("cc") {
623 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400624 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700625 depsformat = "gcc"
626 outputs = [
627 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
628 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400629 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700630 }
631
632 tool("cxx") {
633 depfile = "{{output}}.d"
Mike Klein121563e2016-10-04 17:09:13 -0400634 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700635 depsformat = "gcc"
636 outputs = [
637 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
638 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400639 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700640 }
641
Mike Klein43c25262016-10-20 10:17:47 -0400642 tool("objc") {
643 depfile = "{{output}}.d"
644 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
645 depsformat = "gcc"
646 outputs = [
647 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
648 ]
649 description = "compile {{source}}"
650 }
651
652 tool("objcxx") {
653 depfile = "{{output}}.d"
654 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
655 depsformat = "gcc"
656 outputs = [
657 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
658 ]
659 description = "compile {{source}}"
660 }
661
mtklein7fbfbbe2016-07-21 12:25:45 -0700662 tool("asm") {
663 depfile = "{{output}}.d"
mtklein60b7ab72016-09-20 12:09:12 -0700664 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700665 depsformat = "gcc"
666 outputs = [
667 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
668 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400669 description = "compile {{source}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700670 }
671
672 tool("alink") {
Mike Klein44b36a22016-11-06 11:20:09 -0500673 rspfile = "{{output}}.rsp"
674 rspfile_content = "{{inputs}}"
675 ar_py = rebase_path("ar.py")
676 command = "$python $ar_py $ar {{output}} $rspfile"
mtklein7fbfbbe2016-07-21 12:25:45 -0700677 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700678 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700679 ]
680 default_output_extension = ".a"
681 output_prefix = "lib"
Mike Klein24267ff2016-10-17 10:41:41 -0400682 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700683 }
684
685 tool("solink") {
686 soname = "{{target_output_name}}{{output_extension}}"
687
688 rpath = "-Wl,-soname,$soname"
689 if (is_mac) {
690 rpath = "-Wl,-install_name,@rpath/$soname"
691 }
692
Mike Klein121563e2016-10-04 17:09:13 -0400693 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700694 outputs = [
695 "{{root_out_dir}}/$soname",
696 ]
697 output_prefix = "lib"
698 default_output_extension = ".so"
Mike Klein24267ff2016-10-17 10:41:41 -0400699 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700700 }
701
702 tool("link") {
Mike Klein121563e2016-10-04 17:09:13 -0400703 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700704 outputs = [
705 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
706 ]
Mike Klein24267ff2016-10-17 10:41:41 -0400707 description = "link {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700708 }
709
710 tool("stamp") {
Mike Klein82364ba2016-10-24 16:49:15 -0400711 command = "$stamp {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400712 description = "stamp {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700713 }
714
715 tool("copy") {
Mike Klein1a8d6752016-10-17 11:51:11 -0400716 cp_py = rebase_path("cp.py")
Mike Klein82364ba2016-10-24 16:49:15 -0400717 command = "$python $cp_py {{source}} {{output}}"
Mike Klein24267ff2016-10-17 10:41:41 -0400718 description = "copy {{source}} {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700719 }
720}