blob: f75637a961903705a80427e9cb89cfc1259d1c27 [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() {
Kevin Lubick2677a9a2017-03-28 15:45:41 -04007 extra_asmflags = []
Mike Klein121563e2016-10-04 17:09:13 -04008 extra_cflags = []
9 extra_cflags_c = []
10 extra_cflags_cc = []
11 extra_ldflags = []
mtkleincab0bb72016-08-26 13:43:19 -070012
Herb Derby76073c12016-12-08 19:00:40 -050013 malloc = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070014}
Mike Klein82364ba2016-10-24 16:49:15 -040015
Mike Klein7d302882016-11-03 14:06:31 -040016if (is_ios) {
Matthew Leibowitz3150ec62017-03-14 16:22:32 -040017 if (is_tvos) {
18 sdk = "appletvos"
19 if (target_cpu == "x86" || target_cpu == "x64") {
20 sdk = "appletvsimulator"
21 }
22 } else {
23 sdk = "iphoneos"
24 if (target_cpu == "x86" || target_cpu == "x64") {
25 sdk = "iphonesimulator"
26 }
Mike Klein7a5e0f32017-03-13 09:25:33 -070027 }
28 ios_sysroot = exec_script("find_ios_sysroot.py", [ sdk ], "trim string")
Mike Klein7d302882016-11-03 14:06:31 -040029}
30
mtkleinb9be9792016-09-16 14:44:18 -070031config("default") {
32 asmflags = []
33 cflags = []
34 cflags_c = []
35 cflags_cc = []
36 defines = []
37 ldflags = []
Herb Derby76073c12016-12-08 19:00:40 -050038 libs = []
mtkleinb9be9792016-09-16 14:44:18 -070039
40 if (is_win) {
41 cflags += [
herbb6318bf2016-09-16 13:29:57 -070042 "/bigobj", # Some of our files are bigger than the regular limits.
Mike Kleinc7165c22016-10-12 23:58:06 -040043 "/WX", # Treat warnings as errors.
Ben Wagnere6b274e2017-01-03 17:09:59 -050044 "/utf-8", # Set Source and Executable character sets to UTF-8.
herbb6318bf2016-09-16 13:29:57 -070045 ]
Mike Kleina91ec582017-07-31 16:35:17 -040046 if (is_clang) {
47 cflags += [ "-fms-compatibility-version=19" ] # 2015
48 }
mtkleinb9be9792016-09-16 14:44:18 -070049 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040050 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
51 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070052 "WIN32_LEAN_AND_MEAN",
53 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070054 ]
Mike Klein98adfa82017-07-31 15:46:47 -040055
Brian Osmand34c4a32017-12-06 13:26:38 -050056 if (msvc == 2015) {
Brian Osman852ca312017-12-07 16:16:21 -050057 _include_dirs = [ "$win_vc/include" ]
Brian Osman5f872622017-12-06 15:21:44 -050058 } else { # 2017
Brian Osman852ca312017-12-07 16:16:21 -050059 _include_dirs = [ "$win_vc/Tools/MSVC/$win_toolchain_version/include" ]
Ravi Mistryf5ab2692017-12-06 21:51:23 +000060 }
Brian Osman5f872622017-12-06 15:21:44 -050061 _include_dirs += [
62 "$win_sdk/Include/$win_sdk_version/shared",
63 "$win_sdk/Include/$win_sdk_version/ucrt",
64 "$win_sdk/Include/$win_sdk_version/um",
65 "$win_sdk/Include/$win_sdk_version/winrt",
66 ]
67
Mike Klein98adfa82017-07-31 15:46:47 -040068 if (is_clang) {
69 foreach(dir, _include_dirs) {
70 cflags += [
71 "-imsvc",
72 dir,
73 ]
74 }
75 } else {
76 include_dirs = _include_dirs
77 }
78
Brian Osman5f872622017-12-06 15:21:44 -050079 lib_dirs = [
80 "$win_sdk/Lib/$win_sdk_version/ucrt/$target_cpu",
81 "$win_sdk/Lib/$win_sdk_version/um/$target_cpu",
82 ]
Brian Osmand34c4a32017-12-06 13:26:38 -050083 if (msvc == 2015) {
Brian Osmand34c4a32017-12-06 13:26:38 -050084 if (target_cpu == "x86") {
Brian Osman852ca312017-12-07 16:16:21 -050085 lib_dirs += [ "$win_vc/lib" ]
Brian Osmand34c4a32017-12-06 13:26:38 -050086 } else {
Brian Osman852ca312017-12-07 16:16:21 -050087 lib_dirs += [ "$win_vc/lib/amd64" ]
Brian Osmand34c4a32017-12-06 13:26:38 -050088 }
Brian Osman5f872622017-12-06 15:21:44 -050089 } else { # 2017
90 lib_dirs +=
Brian Osman852ca312017-12-07 16:16:21 -050091 [ "$win_vc/Tools/MSVC/$win_toolchain_version/lib/$target_cpu" ]
Mike Klein0bc5a762016-10-12 22:42:55 -040092 }
mtkleinb9be9792016-09-16 14:44:18 -070093 } else {
94 cflags += [
herbb6318bf2016-09-16 13:29:57 -070095 "-fstrict-aliasing",
96 "-fPIC",
herbb6318bf2016-09-16 13:29:57 -070097 "-Werror",
mtklein2b3c2a32016-09-08 08:39:34 -070098 ]
Mike Klein28f5b772017-04-06 23:04:42 -040099 cflags_cc += [ "-std=c++11" ]
Mike Kleineec23d12017-03-26 20:11:48 -0400100
101 # The main idea is to slim the exported API, but these flags also improve link time on Mac.
102 # These would make stack traces worse on Linux, so we don't just set them willy-nilly.
Mike Klein8cb66482017-03-28 14:16:22 -0400103 if (is_component_build || is_ios || is_mac) {
Mike Kleineec23d12017-03-26 20:11:48 -0400104 cflags += [ "-fvisibility=hidden" ]
105 cflags_cc += [ "-fvisibility-inlines-hidden" ]
106 }
mtkleinb9be9792016-09-16 14:44:18 -0700107 }
herbb6318bf2016-09-16 13:29:57 -0700108
mtkleinb9be9792016-09-16 14:44:18 -0700109 if (current_cpu == "arm") {
110 cflags += [
111 "-march=armv7-a",
112 "-mfpu=neon",
113 "-mthumb",
114 ]
Ben Wagnerdf574042018-03-13 15:11:14 -0400115 } else if (current_cpu == "x86" && is_win) {
116 cflags += [ "/arch:SSE2" ]
117 } else if (current_cpu == "x86") {
mtkleinb9be9792016-09-16 14:44:18 -0700118 asmflags += [ "-m32" ]
119 cflags += [
120 "-m32",
121 "-msse2",
122 "-mfpmath=sse",
123 ]
124 ldflags += [ "-m32" ]
125 }
herbb6318bf2016-09-16 13:29:57 -0700126
Herb Derby76073c12016-12-08 19:00:40 -0500127 if (malloc != "" && !is_win) {
128 cflags += [
129 "-fno-builtin-malloc",
130 "-fno-builtin-calloc",
131 "-fno-builtin-realloc",
132 "-fno-builtin-free",
133 ]
134 libs += [ malloc ]
135 }
136
mtkleinb9be9792016-09-16 14:44:18 -0700137 if (is_android) {
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400138 asmflags += [ "--target=$ndk_target" ]
mtkleinb9be9792016-09-16 14:44:18 -0700139 cflags += [
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400140 "--sysroot=$ndk/sysroot",
141 "-isystem$ndk/sysroot/usr/include/$ndk_target",
142 "-D__ANDROID_API__=$ndk_api",
mtkleinb9be9792016-09-16 14:44:18 -0700143 "--target=$ndk_target",
mtkleinb9be9792016-09-16 14:44:18 -0700144 ]
145 cflags_cc += [
Mike Klein21b620c2018-01-08 17:16:00 -0500146 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include",
147 "-isystem$ndk/sources/cxx-stl/llvm-libc++abi/include",
mtkleinb9be9792016-09-16 14:44:18 -0700148 "-isystem$ndk/sources/android/support/include",
mtkleinb9be9792016-09-16 14:44:18 -0700149 ]
150 ldflags += [
151 "--sysroot=$ndk/platforms/$ndk_platform",
152 "--target=$ndk_target",
153 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700154 ]
155 lib_dirs = [
Mike Klein21b620c2018-01-08 17:16:00 -0500156 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
mtkleinb9be9792016-09-16 14:44:18 -0700157 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
158 ]
herbb6318bf2016-09-16 13:29:57 -0700159
Mike Klein21b620c2018-01-08 17:16:00 -0500160 libs += [
161 "c++_static",
162 "c++abi",
163 "android_support",
164 ]
mtklein2b3c2a32016-09-08 08:39:34 -0700165 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700166
Mike Klein7d302882016-11-03 14:06:31 -0400167 if (is_ios) {
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500168 _target = target_cpu
169 if (target_cpu == "arm") {
170 _target = "armv7"
Mike Klein7a5e0f32017-03-13 09:25:33 -0700171 } else if (target_cpu == "x86") {
172 _target = "i386"
173 } else if (target_cpu == "x64") {
174 _target = "x86_64"
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500175 }
Mike Klein4fe2b152017-02-17 15:36:01 -0500176 asmflags += [
177 "-isysroot",
178 ios_sysroot,
179 "-arch",
180 _target,
181 ]
Mike Klein7d302882016-11-03 14:06:31 -0400182 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500183 "-isysroot",
184 ios_sysroot,
185 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500186 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400187 ]
188 cflags_cc += [ "-stdlib=libc++" ]
189 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500190 "-isysroot",
191 ios_sysroot,
192 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500193 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400194 "-stdlib=libc++",
195 ]
Herb Derby76073c12016-12-08 19:00:40 -0500196 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400197 }
198
mtkleinb9be9792016-09-16 14:44:18 -0700199 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500200 libs += [ "pthread" ]
mtkleinb9be9792016-09-16 14:44:18 -0700201 }
Mike Klein15f46c32017-12-07 12:48:57 -0500202 if (is_mac) {
203 # Disable linker warnings. They're usually just annoyances like,
204 # ld: warning: text-based stub file
205 # /System/Library/Frameworks/foo.framework/foo.tbd and library file
206 # /System/Library/Frameworks/foo.framework/foo are out of sync.
207 # Falling back to library file for linking.
208 ldflags += [ "-Wl,-w" ]
209 }
mtkleinb9be9792016-09-16 14:44:18 -0700210
211 if (sanitize != "") {
212 # You can either pass the sanitizers directly, e.g. "address,undefined",
213 # or pass one of the couple common aliases used by the bots.
214 sanitizers = sanitize
Ben Wagner314d7c22018-01-03 11:04:30 -0500215 if (sanitize == "ASAN" || sanitize == "UBSAN") {
216 # ASAN implicitly runs all UBSAN checks also.
217 sanitizers = "bool,float-cast-overflow,integer-divide-by-zero,nonnull-attribute,null,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound"
218 if (!is_mac && !is_win) {
219 sanitizers += ",function" # Not supported on Mac or Win.
Mike Klein46d6c682017-10-05 11:22:09 -0400220 }
Ben Wagner314d7c22018-01-03 11:04:30 -0500221 if (!is_win) {
222 sanitizers += ",vptr" # Not supported on Win.
223 }
224 if (!is_debug && !is_win) {
225 # No-op with somewhat annoying warning at -O0.
226 # Seems to be broken on Win.
227 sanitizers += ",object-size"
228 }
229 if (sanitize == "ASAN") {
230 sanitizers += ",address"
Mike Kleine4781e92017-09-28 11:42:28 -0400231 }
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500232 if (is_android) {
233 # Android only easily supports address for now
234 # UBSAN runs into linking errors
235 sanitizers = "address"
236
237 # recommended by
238 # https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid
239 cflags += [ "-fno-omit-frame-pointer" ]
240 }
mtkleinb9be9792016-09-16 14:44:18 -0700241 } else if (sanitize == "TSAN") {
242 sanitizers = "thread"
243 } else if (sanitize == "MSAN") {
244 sanitizers = "memory"
245 }
246
247 cflags += [
248 "-fsanitize=$sanitizers",
249 "-fno-sanitize-recover=$sanitizers",
mtkleinb9be9792016-09-16 14:44:18 -0700250 ]
Kevin Lubick3cda39f2018-02-01 12:09:55 -0500251 if (!is_win) {
252 cflags += [ "-fno-omit-frame-pointer" ]
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500253 }
254 if (is_linux) {
Kevin Lubick43bd2592018-02-15 09:03:44 -0500255 cflags_cc += [ "-stdlib=libc++" ]
256 ldflags += [ "-stdlib=libc++" ]
Kevin Lubick3cda39f2018-02-01 12:09:55 -0500257 }
mtkleinb9be9792016-09-16 14:44:18 -0700258 ldflags += [ "-fsanitize=$sanitizers" ]
259 if (sanitizers == "memory") {
260 cflags += [ "-fsanitize-memory-track-origins" ]
mtkleinb9be9792016-09-16 14:44:18 -0700261 }
262 }
263}
264
Mike Klein6e55fef2016-10-26 11:41:47 -0400265config("no_exceptions") {
Mike Klein228276d2017-08-16 13:20:20 +0000266 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
Mike Klein6e55fef2016-10-26 11:41:47 -0400267 if (!is_win) {
268 cflags_cc = [ "-fno-exceptions" ]
269 }
270}
271
Mike Kleinc7165c22016-10-12 23:58:06 -0400272config("warnings") {
273 cflags = []
274 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400275 cflags_objc = []
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400276 cflags_objcc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400277 if (is_win) {
278 cflags += [
279 "/W3", # Turn on lots of warnings.
280
281 # Disable a bunch of warnings:
282 "/wd4244", # conversion from 'float' to 'int', possible loss of data
283 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
284 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
285
286 # Probably only triggers when /EHsc is enabled.
287 "/wd4291", # no matching operator delete found;
288 # memory will not be freed if initialization throws an exception
289 ]
290 } else {
291 cflags += [
292 "-Wall",
293 "-Wextra",
294 "-Winit-self",
295 "-Wpointer-arith",
296 "-Wsign-compare",
297 "-Wvla",
298
299 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500300 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400301 ]
Ben Wagnerf8a131d2018-03-13 16:56:43 -0400302 cflags_cc += [
303 "-Wnon-virtual-dtor",
304 "-Wno-noexcept-type",
305 ]
Chris Dalton1ef80942017-12-04 12:01:30 -0700306 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400307
Chris Dalton1ef80942017-12-04 12:01:30 -0700308 if (is_clang) {
309 cflags += [
310 "-Weverything",
311 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
312 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400313
Chris Dalton1ef80942017-12-04 12:01:30 -0700314 if (target_cpu == "arm" && is_ios) {
315 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS.
316 # We're pretty sure it's actually 8-byte alignment.
317 cflags += [ "-Wno-over-aligned" ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400318 }
Mike Klein04282792018-01-08 18:23:32 -0500319 if (target_cpu == "x86" && is_android) {
320 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds.
321 # We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info.
322 cflags += [ "-Wno-over-aligned" ]
323 }
Chris Dalton1ef80942017-12-04 12:01:30 -0700324
325 # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose
326 # their case during copy, causing case-sensitivity mismatch on remote machines.
327 cflags += [
328 "-Wno-nonportable-include-path",
329 "-Wno-nonportable-system-include-path",
330 ]
331
332 # TODO: These would all be really great warnings to turn on.
333 cflags += [
334 "-Wno-cast-align",
335 "-Wno-cast-qual",
Chris Dalton1ef80942017-12-04 12:01:30 -0700336 "-Wno-conversion",
337 "-Wno-disabled-macro-expansion",
338 "-Wno-documentation",
339 "-Wno-documentation-unknown-command",
340 "-Wno-double-promotion",
341 "-Wno-exit-time-destructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700342 "-Wno-float-equal",
343 "-Wno-format-nonliteral",
344 "-Wno-global-constructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700345 "-Wno-missing-prototypes",
346 "-Wno-missing-variable-declarations",
347 "-Wno-pedantic",
348 "-Wno-reserved-id-macro",
349 "-Wno-shadow",
350 "-Wno-shift-sign-overflow",
Chris Dalton1ef80942017-12-04 12:01:30 -0700351 "-Wno-signed-enum-bitfield",
352 "-Wno-switch-enum",
353 "-Wno-undef",
354 "-Wno-unreachable-code",
355 "-Wno-unreachable-code-break",
356 "-Wno-unreachable-code-return",
357 "-Wno-unused-macros",
358 "-Wno-unused-member-function",
359 "-Wno-unused-template",
360 "-Wno-zero-as-null-pointer-constant",
361 ]
362 cflags_cc += [
363 "-Wno-abstract-vbase-init",
364 "-Wno-weak-vtables",
365 ]
366
367 # We are unlikely to want to fix these.
368 cflags += [
369 "-Wno-covered-switch-default",
370 "-Wno-deprecated",
Chris Dalton1ef80942017-12-04 12:01:30 -0700371 "-Wno-missing-noreturn",
372 "-Wno-old-style-cast",
373 "-Wno-padded",
Chris Daltond1ec4102017-12-04 13:31:21 -0700374 "-Wno-newline-eof",
Chris Dalton1ef80942017-12-04 12:01:30 -0700375 ]
376 cflags_cc += [
377 "-Wno-c++98-compat",
378 "-Wno-c++98-compat-pedantic",
379 "-Wno-undefined-func-template",
380 ]
381 cflags_objc += [
382 "-Wno-direct-ivar-access",
383 "-Wno-objc-interface-ivars",
384 ]
385 cflags_objcc += [
386 "-Wno-direct-ivar-access",
387 "-Wno-objcc-interface-ivars",
388 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400389 }
Mike Kleinee77da22018-02-22 15:36:24 -0500390 if (!is_win || is_clang) {
391 cflags += [ "-Wno-implicit-fallthrough" ]
392 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400393}
Mike Klein50500ad2016-11-16 12:13:44 -0500394config("warnings_except_public_headers") {
Chris Dalton1ef80942017-12-04 12:01:30 -0700395 if (!is_win || is_clang) {
Mike Klein50500ad2016-11-16 12:13:44 -0500396 cflags = [ "-Wno-unused-parameter" ]
397 }
398}
Mike Kleinc7165c22016-10-12 23:58:06 -0400399
Mike Klein121563e2016-10-04 17:09:13 -0400400config("extra_flags") {
Kevin Lubick2677a9a2017-03-28 15:45:41 -0400401 asmflags = extra_asmflags
Mike Klein121563e2016-10-04 17:09:13 -0400402 cflags = extra_cflags
403 cflags_c = extra_cflags_c
404 cflags_cc = extra_cflags_cc
405 ldflags = extra_ldflags
406}
407
mtkleinb9be9792016-09-16 14:44:18 -0700408config("debug_symbols") {
409 # It's annoying to wait for full debug symbols to push over
410 # to Android devices. -gline-tables-only is a lot slimmer.
411 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400412 cflags = [
413 "-gline-tables-only",
414 "-funwind-tables", # Helps make in-process backtraces fuller.
415 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400416 } else if (is_win) {
Mike Klein67a86d52017-12-15 07:34:27 -0500417 cflags = [ "/Z7" ]
Brian Osmana99d9822017-12-28 14:53:10 -0500418 ldflags = [ "/DEBUG:FASTLINK" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400419 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700420 cflags = [ "-g" ]
421 }
422}
423
424config("no_rtti") {
425 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400426 if (is_win) {
427 cflags_cc = [ "/GR-" ]
428 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700429 cflags_cc = [ "-fno-rtti" ]
430 }
431 }
432}
433
434config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400435 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400436 cflags = [
437 "/O2",
438 "/Zc:inline",
439 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400440 ldflags = [
441 "/OPT:ICF",
442 "/OPT:REF",
443 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400444 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400445 cflags = [
446 "-O3",
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500447 "-fdata-sections",
448 "-ffunction-sections",
Mike Klein0bcfeac2016-10-19 22:24:10 -0400449 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500450 if (is_mac || is_ios) {
451 ldflags = [ "-dead_strip" ]
452 } else {
453 ldflags = [ "-Wl,--gc-sections" ]
454 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400455 if (target_cpu == "wasm") {
456 # The compiler asks us to add an optimization flag to both cflags
457 # and ldflags to cut down on the local variables,
458 # for performance reasons.
459 # The "linking" step is the conversion to javascript.
460 ldflags += [ "-O3" ]
461 }
herbb6318bf2016-09-16 13:29:57 -0700462 }
mtkleinb9be9792016-09-16 14:44:18 -0700463 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700464}
465
466config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500467 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400468 ldflags = [
469 "-pie",
470 "-rdynamic",
471 ]
Mike Kleinc5875fb2016-12-06 10:46:02 -0500472 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700473 ldflags = [ "-Wl,-rpath,@loader_path/." ]
474 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700475 ldflags = [
476 "-rdynamic",
477 "-Wl,-rpath,\$ORIGIN",
478 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500479 } else if (is_win) {
480 ldflags = [
481 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
482 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
483 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700484 }
485}