blob: 7edff663c5a34f6af78802539a4c17d1732f031b [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 ]
Brian Salomon7258e972018-06-02 11:18:33 -040099 cflags_cc += [ "-std=c++14" ]
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 Wagner9bd736b2018-04-04 15:35:01 -0400115 } else if (current_cpu == "loongson3a") {
116 asmflags += [ "-march=loongson3a" ]
117 cflags += [
118 "-march=loongson3a",
119
120 # Causes an internal compiler error.
121 "-DSKCMS_PORTABLE",
122 ]
123 } else if (current_cpu == "mips64el") {
124 asmflags += [ "-march=mips64" ]
125 cflags += [ "-march=mips64" ]
Mike Klein4d4b3aa2018-03-21 13:07:35 -0400126 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700127 asmflags += [ "-m32" ]
128 cflags += [
129 "-m32",
130 "-msse2",
131 "-mfpmath=sse",
132 ]
133 ldflags += [ "-m32" ]
134 }
herbb6318bf2016-09-16 13:29:57 -0700135
Herb Derby76073c12016-12-08 19:00:40 -0500136 if (malloc != "" && !is_win) {
137 cflags += [
138 "-fno-builtin-malloc",
139 "-fno-builtin-calloc",
140 "-fno-builtin-realloc",
141 "-fno-builtin-free",
142 ]
143 libs += [ malloc ]
144 }
145
Hal Canarya0834042018-06-01 20:22:25 +0000146 if (is_android) {
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400147 asmflags += [ "--target=$ndk_target" ]
mtkleinb9be9792016-09-16 14:44:18 -0700148 cflags += [
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400149 "--sysroot=$ndk/sysroot",
150 "-isystem$ndk/sysroot/usr/include/$ndk_target",
151 "-D__ANDROID_API__=$ndk_api",
mtkleinb9be9792016-09-16 14:44:18 -0700152 "--target=$ndk_target",
mtkleinb9be9792016-09-16 14:44:18 -0700153 ]
154 cflags_cc += [
Mike Klein21b620c2018-01-08 17:16:00 -0500155 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include",
156 "-isystem$ndk/sources/cxx-stl/llvm-libc++abi/include",
mtkleinb9be9792016-09-16 14:44:18 -0700157 "-isystem$ndk/sources/android/support/include",
mtkleinb9be9792016-09-16 14:44:18 -0700158 ]
159 ldflags += [
160 "--sysroot=$ndk/platforms/$ndk_platform",
161 "--target=$ndk_target",
162 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700163 ]
164 lib_dirs = [
Mike Klein21b620c2018-01-08 17:16:00 -0500165 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
mtkleinb9be9792016-09-16 14:44:18 -0700166 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
167 ]
herbb6318bf2016-09-16 13:29:57 -0700168
Mike Klein21b620c2018-01-08 17:16:00 -0500169 libs += [
170 "c++_static",
171 "c++abi",
Mike Klein21b620c2018-01-08 17:16:00 -0500172 ]
Mike Klein8803ebb2018-05-14 13:25:46 -0400173 if (ndk_api < 21) {
174 libs += [ "android_support" ]
175 }
mtklein2b3c2a32016-09-08 08:39:34 -0700176 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700177
Mike Klein7d302882016-11-03 14:06:31 -0400178 if (is_ios) {
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500179 _target = target_cpu
180 if (target_cpu == "arm") {
181 _target = "armv7"
Mike Klein7a5e0f32017-03-13 09:25:33 -0700182 } else if (target_cpu == "x86") {
183 _target = "i386"
184 } else if (target_cpu == "x64") {
185 _target = "x86_64"
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500186 }
Mike Klein4fe2b152017-02-17 15:36:01 -0500187 asmflags += [
188 "-isysroot",
189 ios_sysroot,
190 "-arch",
191 _target,
192 ]
Mike Klein7d302882016-11-03 14:06:31 -0400193 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500194 "-isysroot",
195 ios_sysroot,
196 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500197 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400198 ]
199 cflags_cc += [ "-stdlib=libc++" ]
200 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500201 "-isysroot",
202 ios_sysroot,
203 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500204 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400205 "-stdlib=libc++",
206 ]
Herb Derby76073c12016-12-08 19:00:40 -0500207 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400208 }
209
mtkleinb9be9792016-09-16 14:44:18 -0700210 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500211 libs += [ "pthread" ]
Cary Clarkeb1d9002018-07-13 10:39:39 -0400212 if (is_debug && sanitize == "") {
213 defines += [ "_GLIBCXX_DEBUG" ]
214 }
mtkleinb9be9792016-09-16 14:44:18 -0700215 }
Mike Klein15f46c32017-12-07 12:48:57 -0500216 if (is_mac) {
217 # Disable linker warnings. They're usually just annoyances like,
218 # ld: warning: text-based stub file
219 # /System/Library/Frameworks/foo.framework/foo.tbd and library file
220 # /System/Library/Frameworks/foo.framework/foo are out of sync.
221 # Falling back to library file for linking.
222 ldflags += [ "-Wl,-w" ]
223 }
mtkleinb9be9792016-09-16 14:44:18 -0700224
225 if (sanitize != "") {
226 # You can either pass the sanitizers directly, e.g. "address,undefined",
227 # or pass one of the couple common aliases used by the bots.
228 sanitizers = sanitize
Kevin Lubickd0950402018-03-20 10:10:58 -0400229
230 # fyi_sanitizers only print out stacktraces of their issues
231 fyi_sanitizers = fyi_sanitize
Ben Wagner314d7c22018-01-03 11:04:30 -0500232 if (sanitize == "ASAN" || sanitize == "UBSAN") {
233 # ASAN implicitly runs all UBSAN checks also.
Mike Klein475c5e92018-08-08 10:23:17 -0400234 sanitizers = "alignment,bool,float-cast-overflow,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound"
Kevin Lubickd0950402018-03-20 10:10:58 -0400235
236 if (fyi_sanitize == "" && !is_android) {
237 fyi_sanitizers = "float-divide-by-zero"
238 }
239
Ben Wagner314d7c22018-01-03 11:04:30 -0500240 if (!is_mac && !is_win) {
241 sanitizers += ",function" # Not supported on Mac or Win.
Mike Klein46d6c682017-10-05 11:22:09 -0400242 }
Ben Wagner314d7c22018-01-03 11:04:30 -0500243 if (!is_win) {
244 sanitizers += ",vptr" # Not supported on Win.
245 }
246 if (!is_debug && !is_win) {
247 # No-op with somewhat annoying warning at -O0.
248 # Seems to be broken on Win.
249 sanitizers += ",object-size"
250 }
251 if (sanitize == "ASAN") {
252 sanitizers += ",address"
Mike Kleine4781e92017-09-28 11:42:28 -0400253 }
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500254 if (is_android) {
255 # Android only easily supports address for now
256 # UBSAN runs into linking errors
257 sanitizers = "address"
258
259 # recommended by
260 # https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid
261 cflags += [ "-fno-omit-frame-pointer" ]
262 }
mtkleinb9be9792016-09-16 14:44:18 -0700263 } else if (sanitize == "TSAN") {
264 sanitizers = "thread"
265 } else if (sanitize == "MSAN") {
266 sanitizers = "memory"
267 }
268
Mike Klein475c5e92018-08-08 10:23:17 -0400269 _blacklist = rebase_path("../tools/xsan.blacklist")
270
mtkleinb9be9792016-09-16 14:44:18 -0700271 cflags += [
Kevin Lubickd0950402018-03-20 10:10:58 -0400272 "-fsanitize=$sanitizers,$fyi_sanitizers",
mtkleinb9be9792016-09-16 14:44:18 -0700273 "-fno-sanitize-recover=$sanitizers",
Mike Klein475c5e92018-08-08 10:23:17 -0400274 "-fsanitize-blacklist=$_blacklist",
275 "-include$_blacklist",
mtkleinb9be9792016-09-16 14:44:18 -0700276 ]
Kevin Lubick3cda39f2018-02-01 12:09:55 -0500277 if (!is_win) {
278 cflags += [ "-fno-omit-frame-pointer" ]
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500279 }
280 if (is_linux) {
Kevin Lubick43bd2592018-02-15 09:03:44 -0500281 cflags_cc += [ "-stdlib=libc++" ]
282 ldflags += [ "-stdlib=libc++" ]
Kevin Lubick3cda39f2018-02-01 12:09:55 -0500283 }
mtkleinb9be9792016-09-16 14:44:18 -0700284 ldflags += [ "-fsanitize=$sanitizers" ]
285 if (sanitizers == "memory") {
286 cflags += [ "-fsanitize-memory-track-origins" ]
mtkleinb9be9792016-09-16 14:44:18 -0700287 }
288 }
289}
290
Mike Klein6e55fef2016-10-26 11:41:47 -0400291config("no_exceptions") {
Mike Klein228276d2017-08-16 13:20:20 +0000292 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
Mike Klein6e55fef2016-10-26 11:41:47 -0400293 if (!is_win) {
294 cflags_cc = [ "-fno-exceptions" ]
295 }
296}
297
Mike Kleinc7165c22016-10-12 23:58:06 -0400298config("warnings") {
299 cflags = []
300 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400301 cflags_objc = []
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400302 cflags_objcc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400303 if (is_win) {
304 cflags += [
305 "/W3", # Turn on lots of warnings.
306
307 # Disable a bunch of warnings:
308 "/wd4244", # conversion from 'float' to 'int', possible loss of data
309 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
310 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
311
312 # Probably only triggers when /EHsc is enabled.
313 "/wd4291", # no matching operator delete found;
314 # memory will not be freed if initialization throws an exception
315 ]
316 } else {
317 cflags += [
318 "-Wall",
319 "-Wextra",
320 "-Winit-self",
321 "-Wpointer-arith",
322 "-Wsign-compare",
323 "-Wvla",
324
325 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500326 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400327 ]
Ben Wagnerf8a131d2018-03-13 16:56:43 -0400328 cflags_cc += [
329 "-Wnon-virtual-dtor",
330 "-Wno-noexcept-type",
331 ]
Chris Dalton1ef80942017-12-04 12:01:30 -0700332 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400333
Chris Dalton1ef80942017-12-04 12:01:30 -0700334 if (is_clang) {
335 cflags += [
336 "-Weverything",
337 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
338 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400339
Chris Dalton1ef80942017-12-04 12:01:30 -0700340 if (target_cpu == "arm" && is_ios) {
341 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS.
342 # We're pretty sure it's actually 8-byte alignment.
343 cflags += [ "-Wno-over-aligned" ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400344 }
Mike Klein04282792018-01-08 18:23:32 -0500345 if (target_cpu == "x86" && is_android) {
346 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds.
347 # We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info.
348 cflags += [ "-Wno-over-aligned" ]
349 }
Chris Dalton1ef80942017-12-04 12:01:30 -0700350
351 # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose
352 # their case during copy, causing case-sensitivity mismatch on remote machines.
353 cflags += [
354 "-Wno-nonportable-include-path",
355 "-Wno-nonportable-system-include-path",
356 ]
357
358 # TODO: These would all be really great warnings to turn on.
359 cflags += [
360 "-Wno-cast-align",
361 "-Wno-cast-qual",
Chris Dalton1ef80942017-12-04 12:01:30 -0700362 "-Wno-conversion",
363 "-Wno-disabled-macro-expansion",
364 "-Wno-documentation",
365 "-Wno-documentation-unknown-command",
366 "-Wno-double-promotion",
367 "-Wno-exit-time-destructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700368 "-Wno-float-equal",
369 "-Wno-format-nonliteral",
370 "-Wno-global-constructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700371 "-Wno-missing-prototypes",
372 "-Wno-missing-variable-declarations",
373 "-Wno-pedantic",
374 "-Wno-reserved-id-macro",
375 "-Wno-shadow",
376 "-Wno-shift-sign-overflow",
Chris Dalton1ef80942017-12-04 12:01:30 -0700377 "-Wno-signed-enum-bitfield",
378 "-Wno-switch-enum",
379 "-Wno-undef",
380 "-Wno-unreachable-code",
381 "-Wno-unreachable-code-break",
382 "-Wno-unreachable-code-return",
383 "-Wno-unused-macros",
384 "-Wno-unused-member-function",
385 "-Wno-unused-template",
386 "-Wno-zero-as-null-pointer-constant",
387 ]
388 cflags_cc += [
389 "-Wno-abstract-vbase-init",
390 "-Wno-weak-vtables",
391 ]
392
393 # We are unlikely to want to fix these.
394 cflags += [
Brian Osman9061ffc2018-05-16 15:58:31 -0400395 "-Wno-bad-function-cast",
Chris Dalton1ef80942017-12-04 12:01:30 -0700396 "-Wno-covered-switch-default",
397 "-Wno-deprecated",
Chris Dalton1ef80942017-12-04 12:01:30 -0700398 "-Wno-missing-noreturn",
399 "-Wno-old-style-cast",
400 "-Wno-padded",
Chris Daltond1ec4102017-12-04 13:31:21 -0700401 "-Wno-newline-eof",
Chris Dalton1ef80942017-12-04 12:01:30 -0700402 ]
403 cflags_cc += [
404 "-Wno-c++98-compat",
405 "-Wno-c++98-compat-pedantic",
406 "-Wno-undefined-func-template",
407 ]
408 cflags_objc += [
409 "-Wno-direct-ivar-access",
410 "-Wno-objc-interface-ivars",
411 ]
412 cflags_objcc += [
413 "-Wno-direct-ivar-access",
414 "-Wno-objcc-interface-ivars",
415 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400416 }
Mike Kleinee77da22018-02-22 15:36:24 -0500417 if (!is_win || is_clang) {
418 cflags += [ "-Wno-implicit-fallthrough" ]
419 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400420}
Mike Klein50500ad2016-11-16 12:13:44 -0500421config("warnings_except_public_headers") {
Chris Dalton1ef80942017-12-04 12:01:30 -0700422 if (!is_win || is_clang) {
Mike Klein50500ad2016-11-16 12:13:44 -0500423 cflags = [ "-Wno-unused-parameter" ]
424 }
425}
Mike Kleinc7165c22016-10-12 23:58:06 -0400426
Mike Klein121563e2016-10-04 17:09:13 -0400427config("extra_flags") {
Kevin Lubick2677a9a2017-03-28 15:45:41 -0400428 asmflags = extra_asmflags
Mike Klein121563e2016-10-04 17:09:13 -0400429 cflags = extra_cflags
430 cflags_c = extra_cflags_c
431 cflags_cc = extra_cflags_cc
432 ldflags = extra_ldflags
433}
434
mtkleinb9be9792016-09-16 14:44:18 -0700435config("debug_symbols") {
436 # It's annoying to wait for full debug symbols to push over
437 # to Android devices. -gline-tables-only is a lot slimmer.
438 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400439 cflags = [
440 "-gline-tables-only",
441 "-funwind-tables", # Helps make in-process backtraces fuller.
442 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400443 } else if (is_win) {
Mike Klein67a86d52017-12-15 07:34:27 -0500444 cflags = [ "/Z7" ]
Brian Osmana99d9822017-12-28 14:53:10 -0500445 ldflags = [ "/DEBUG:FASTLINK" ]
Mike Kleincc300a12016-10-12 16:25:27 -0400446 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700447 cflags = [ "-g" ]
448 }
449}
450
451config("no_rtti") {
452 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400453 if (is_win) {
454 cflags_cc = [ "/GR-" ]
455 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700456 cflags_cc = [ "-fno-rtti" ]
457 }
458 }
459}
460
461config("release") {
Mike Kleincc300a12016-10-12 16:25:27 -0400462 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400463 cflags = [
464 "/O2",
465 "/Zc:inline",
466 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400467 ldflags = [
468 "/OPT:ICF",
469 "/OPT:REF",
470 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400471 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400472 cflags = [
473 "-O3",
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500474 "-fdata-sections",
475 "-ffunction-sections",
Mike Klein0bcfeac2016-10-19 22:24:10 -0400476 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500477 if (is_mac || is_ios) {
478 ldflags = [ "-dead_strip" ]
479 } else {
480 ldflags = [ "-Wl,--gc-sections" ]
481 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400482 if (target_cpu == "wasm") {
483 # The compiler asks us to add an optimization flag to both cflags
484 # and ldflags to cut down on the local variables,
485 # for performance reasons.
486 # The "linking" step is the conversion to javascript.
487 ldflags += [ "-O3" ]
488 }
herbb6318bf2016-09-16 13:29:57 -0700489 }
mtkleinb9be9792016-09-16 14:44:18 -0700490 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700491}
492
493config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500494 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400495 ldflags = [
496 "-pie",
497 "-rdynamic",
498 ]
Mike Kleinc5875fb2016-12-06 10:46:02 -0500499 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700500 ldflags = [ "-Wl,-rpath,@loader_path/." ]
501 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700502 ldflags = [
503 "-rdynamic",
504 "-Wl,-rpath,\$ORIGIN",
505 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500506 } else if (is_win) {
507 ldflags = [
508 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
509 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
510 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700511 }
512}