blob: 3d4c1104f42698709ac767b89bc80e0ee8c0d34e [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",
mtklein2b3c2a32016-09-08 08:39:34 -070097 ]
Brian Salomon7258e972018-06-02 11:18:33 -040098 cflags_cc += [ "-std=c++14" ]
Mike Kleineec23d12017-03-26 20:11:48 -040099
100 # The main idea is to slim the exported API, but these flags also improve link time on Mac.
101 # These would make stack traces worse on Linux, so we don't just set them willy-nilly.
Mike Klein8cb66482017-03-28 14:16:22 -0400102 if (is_component_build || is_ios || is_mac) {
Mike Kleineec23d12017-03-26 20:11:48 -0400103 cflags += [ "-fvisibility=hidden" ]
104 cflags_cc += [ "-fvisibility-inlines-hidden" ]
105 }
mtkleinb9be9792016-09-16 14:44:18 -0700106 }
herbb6318bf2016-09-16 13:29:57 -0700107
mtkleinb9be9792016-09-16 14:44:18 -0700108 if (current_cpu == "arm") {
109 cflags += [
110 "-march=armv7-a",
111 "-mfpu=neon",
112 "-mthumb",
113 ]
Ben Wagner9bd736b2018-04-04 15:35:01 -0400114 } else if (current_cpu == "loongson3a") {
115 asmflags += [ "-march=loongson3a" ]
116 cflags += [
117 "-march=loongson3a",
118
119 # Causes an internal compiler error.
120 "-DSKCMS_PORTABLE",
121 ]
122 } else if (current_cpu == "mips64el") {
123 asmflags += [ "-march=mips64" ]
124 cflags += [ "-march=mips64" ]
Mike Klein4d4b3aa2018-03-21 13:07:35 -0400125 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700126 asmflags += [ "-m32" ]
127 cflags += [
128 "-m32",
129 "-msse2",
130 "-mfpmath=sse",
131 ]
132 ldflags += [ "-m32" ]
133 }
herbb6318bf2016-09-16 13:29:57 -0700134
Herb Derby76073c12016-12-08 19:00:40 -0500135 if (malloc != "" && !is_win) {
136 cflags += [
137 "-fno-builtin-malloc",
138 "-fno-builtin-calloc",
139 "-fno-builtin-realloc",
140 "-fno-builtin-free",
141 ]
142 libs += [ malloc ]
143 }
144
Hal Canarya0834042018-06-01 20:22:25 +0000145 if (is_android) {
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400146 asmflags += [ "--target=$ndk_target" ]
mtkleinb9be9792016-09-16 14:44:18 -0700147 cflags += [
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400148 "--sysroot=$ndk/sysroot",
149 "-isystem$ndk/sysroot/usr/include/$ndk_target",
150 "-D__ANDROID_API__=$ndk_api",
mtkleinb9be9792016-09-16 14:44:18 -0700151 "--target=$ndk_target",
mtkleinb9be9792016-09-16 14:44:18 -0700152 ]
153 cflags_cc += [
Mike Klein21b620c2018-01-08 17:16:00 -0500154 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include",
155 "-isystem$ndk/sources/cxx-stl/llvm-libc++abi/include",
mtkleinb9be9792016-09-16 14:44:18 -0700156 "-isystem$ndk/sources/android/support/include",
mtkleinb9be9792016-09-16 14:44:18 -0700157 ]
158 ldflags += [
159 "--sysroot=$ndk/platforms/$ndk_platform",
160 "--target=$ndk_target",
161 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700162 ]
163 lib_dirs = [
Mike Klein21b620c2018-01-08 17:16:00 -0500164 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
mtkleinb9be9792016-09-16 14:44:18 -0700165 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
166 ]
herbb6318bf2016-09-16 13:29:57 -0700167
Mike Klein21b620c2018-01-08 17:16:00 -0500168 libs += [
169 "c++_static",
170 "c++abi",
Mike Klein21b620c2018-01-08 17:16:00 -0500171 ]
Mike Klein8803ebb2018-05-14 13:25:46 -0400172 if (ndk_api < 21) {
173 libs += [ "android_support" ]
174 }
mtklein2b3c2a32016-09-08 08:39:34 -0700175 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700176
Mike Klein7d302882016-11-03 14:06:31 -0400177 if (is_ios) {
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500178 _target = target_cpu
179 if (target_cpu == "arm") {
180 _target = "armv7"
Mike Klein7a5e0f32017-03-13 09:25:33 -0700181 } else if (target_cpu == "x86") {
182 _target = "i386"
183 } else if (target_cpu == "x64") {
184 _target = "x86_64"
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500185 }
Mike Klein4fe2b152017-02-17 15:36:01 -0500186 asmflags += [
187 "-isysroot",
188 ios_sysroot,
189 "-arch",
190 _target,
191 ]
Mike Klein7d302882016-11-03 14:06:31 -0400192 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500193 "-isysroot",
194 ios_sysroot,
195 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500196 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400197 ]
198 cflags_cc += [ "-stdlib=libc++" ]
199 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500200 "-isysroot",
201 ios_sysroot,
202 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500203 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400204 "-stdlib=libc++",
205 ]
Herb Derby76073c12016-12-08 19:00:40 -0500206 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400207 }
208
mtkleinb9be9792016-09-16 14:44:18 -0700209 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500210 libs += [ "pthread" ]
Cary Clarkeb1d9002018-07-13 10:39:39 -0400211 if (is_debug && sanitize == "") {
212 defines += [ "_GLIBCXX_DEBUG" ]
213 }
mtkleinb9be9792016-09-16 14:44:18 -0700214 }
Mike Klein15f46c32017-12-07 12:48:57 -0500215 if (is_mac) {
216 # Disable linker warnings. They're usually just annoyances like,
217 # ld: warning: text-based stub file
218 # /System/Library/Frameworks/foo.framework/foo.tbd and library file
219 # /System/Library/Frameworks/foo.framework/foo are out of sync.
220 # Falling back to library file for linking.
221 ldflags += [ "-Wl,-w" ]
222 }
mtkleinb9be9792016-09-16 14:44:18 -0700223
224 if (sanitize != "") {
225 # You can either pass the sanitizers directly, e.g. "address,undefined",
226 # or pass one of the couple common aliases used by the bots.
227 sanitizers = sanitize
Kevin Lubickd0950402018-03-20 10:10:58 -0400228
229 # fyi_sanitizers only print out stacktraces of their issues
230 fyi_sanitizers = fyi_sanitize
Ben Wagner314d7c22018-01-03 11:04:30 -0500231 if (sanitize == "ASAN" || sanitize == "UBSAN") {
232 # ASAN implicitly runs all UBSAN checks also.
Mike Klein02046a72018-08-10 12:25:12 -0400233 sanitizers = "undefined"
Ben Wagner314d7c22018-01-03 11:04:30 -0500234 if (sanitize == "ASAN") {
235 sanitizers += ",address"
Mike Kleine4781e92017-09-28 11:42:28 -0400236 }
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500237
Mike Klein02046a72018-08-10 12:25:12 -0400238 # A whitelist of checks we can't yet pass.
239 if (fyi_sanitize == "" && !is_android) {
240 fyi_sanitizers = "enum,float-divide-by-zero"
241 }
242
243 if (is_android) {
244 # TODO(mtklein): work out UBSAN link errors
245 sanitizers = "address"
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500246 }
mtkleinb9be9792016-09-16 14:44:18 -0700247 } else if (sanitize == "TSAN") {
248 sanitizers = "thread"
249 } else if (sanitize == "MSAN") {
250 sanitizers = "memory"
251 }
252
Mike Klein475c5e92018-08-08 10:23:17 -0400253 _blacklist = rebase_path("../tools/xsan.blacklist")
254
mtkleinb9be9792016-09-16 14:44:18 -0700255 cflags += [
Mike Klein02046a72018-08-10 12:25:12 -0400256 "-fsanitize=$sanitizers",
mtkleinb9be9792016-09-16 14:44:18 -0700257 "-fno-sanitize-recover=$sanitizers",
Mike Klein02046a72018-08-10 12:25:12 -0400258 "-fsanitize-recover=$fyi_sanitizers",
Mike Klein475c5e92018-08-08 10:23:17 -0400259 "-fsanitize-blacklist=$_blacklist",
mtkleinb9be9792016-09-16 14:44:18 -0700260 ]
Mike Klein02046a72018-08-10 12:25:12 -0400261 ldflags += [ "-fsanitize=$sanitizers" ]
262
Mike Klein94c4f412018-08-09 17:24:45 -0400263 if (is_win) {
264 cflags += [ "/FI$_blacklist" ]
265 } else {
266 cflags += [
267 "-include$_blacklist",
268 "-fno-omit-frame-pointer",
269 ]
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500270 }
Mike Klein94c4f412018-08-09 17:24:45 -0400271
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500272 if (is_linux) {
Kevin Lubick43bd2592018-02-15 09:03:44 -0500273 cflags_cc += [ "-stdlib=libc++" ]
274 ldflags += [ "-stdlib=libc++" ]
Kevin Lubick3cda39f2018-02-01 12:09:55 -0500275 }
Mike Klein02046a72018-08-10 12:25:12 -0400276
mtkleinb9be9792016-09-16 14:44:18 -0700277 if (sanitizers == "memory") {
278 cflags += [ "-fsanitize-memory-track-origins" ]
mtkleinb9be9792016-09-16 14:44:18 -0700279 }
280 }
281}
282
Mike Klein6e55fef2016-10-26 11:41:47 -0400283config("no_exceptions") {
Mike Klein228276d2017-08-16 13:20:20 +0000284 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
Mike Klein6e55fef2016-10-26 11:41:47 -0400285 if (!is_win) {
286 cflags_cc = [ "-fno-exceptions" ]
287 }
288}
289
Mike Kleinc7165c22016-10-12 23:58:06 -0400290config("warnings") {
291 cflags = []
292 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400293 cflags_objc = []
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400294 cflags_objcc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400295 if (is_win) {
296 cflags += [
297 "/W3", # Turn on lots of warnings.
298
299 # Disable a bunch of warnings:
300 "/wd4244", # conversion from 'float' to 'int', possible loss of data
301 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
302 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
303
304 # Probably only triggers when /EHsc is enabled.
305 "/wd4291", # no matching operator delete found;
306 # memory will not be freed if initialization throws an exception
307 ]
308 } else {
309 cflags += [
Mike Kleind84c1e62018-09-04 10:15:58 -0400310 "-Werror",
Mike Kleinc7165c22016-10-12 23:58:06 -0400311 "-Wall",
312 "-Wextra",
313 "-Winit-self",
314 "-Wpointer-arith",
315 "-Wsign-compare",
316 "-Wvla",
317
318 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500319 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400320 ]
Ben Wagnerf8a131d2018-03-13 16:56:43 -0400321 cflags_cc += [
322 "-Wnon-virtual-dtor",
323 "-Wno-noexcept-type",
324 ]
Chris Dalton1ef80942017-12-04 12:01:30 -0700325 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400326
Chris Dalton1ef80942017-12-04 12:01:30 -0700327 if (is_clang) {
328 cflags += [
329 "-Weverything",
330 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
331 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400332
Chris Dalton1ef80942017-12-04 12:01:30 -0700333 if (target_cpu == "arm" && is_ios) {
334 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS.
335 # We're pretty sure it's actually 8-byte alignment.
336 cflags += [ "-Wno-over-aligned" ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400337 }
Mike Klein04282792018-01-08 18:23:32 -0500338 if (target_cpu == "x86" && is_android) {
339 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds.
340 # We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info.
341 cflags += [ "-Wno-over-aligned" ]
342 }
Chris Dalton1ef80942017-12-04 12:01:30 -0700343
344 # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose
345 # their case during copy, causing case-sensitivity mismatch on remote machines.
346 cflags += [
347 "-Wno-nonportable-include-path",
348 "-Wno-nonportable-system-include-path",
349 ]
350
351 # TODO: These would all be really great warnings to turn on.
352 cflags += [
353 "-Wno-cast-align",
354 "-Wno-cast-qual",
Chris Dalton1ef80942017-12-04 12:01:30 -0700355 "-Wno-conversion",
356 "-Wno-disabled-macro-expansion",
357 "-Wno-documentation",
358 "-Wno-documentation-unknown-command",
359 "-Wno-double-promotion",
360 "-Wno-exit-time-destructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700361 "-Wno-float-equal",
362 "-Wno-format-nonliteral",
363 "-Wno-global-constructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700364 "-Wno-missing-prototypes",
365 "-Wno-missing-variable-declarations",
366 "-Wno-pedantic",
367 "-Wno-reserved-id-macro",
368 "-Wno-shadow",
369 "-Wno-shift-sign-overflow",
Chris Dalton1ef80942017-12-04 12:01:30 -0700370 "-Wno-signed-enum-bitfield",
371 "-Wno-switch-enum",
372 "-Wno-undef",
373 "-Wno-unreachable-code",
374 "-Wno-unreachable-code-break",
375 "-Wno-unreachable-code-return",
376 "-Wno-unused-macros",
377 "-Wno-unused-member-function",
378 "-Wno-unused-template",
379 "-Wno-zero-as-null-pointer-constant",
380 ]
381 cflags_cc += [
382 "-Wno-abstract-vbase-init",
383 "-Wno-weak-vtables",
384 ]
385
386 # We are unlikely to want to fix these.
387 cflags += [
Brian Osman9061ffc2018-05-16 15:58:31 -0400388 "-Wno-bad-function-cast",
Chris Dalton1ef80942017-12-04 12:01:30 -0700389 "-Wno-covered-switch-default",
390 "-Wno-deprecated",
Chris Dalton1ef80942017-12-04 12:01:30 -0700391 "-Wno-missing-noreturn",
392 "-Wno-old-style-cast",
393 "-Wno-padded",
Chris Daltond1ec4102017-12-04 13:31:21 -0700394 "-Wno-newline-eof",
Chris Dalton1ef80942017-12-04 12:01:30 -0700395 ]
396 cflags_cc += [
397 "-Wno-c++98-compat",
398 "-Wno-c++98-compat-pedantic",
399 "-Wno-undefined-func-template",
400 ]
401 cflags_objc += [
402 "-Wno-direct-ivar-access",
403 "-Wno-objc-interface-ivars",
404 ]
405 cflags_objcc += [
406 "-Wno-direct-ivar-access",
407 "-Wno-objcc-interface-ivars",
408 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400409 }
Mike Kleinee77da22018-02-22 15:36:24 -0500410 if (!is_win || is_clang) {
411 cflags += [ "-Wno-implicit-fallthrough" ]
412 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400413}
Mike Klein50500ad2016-11-16 12:13:44 -0500414config("warnings_except_public_headers") {
Chris Dalton1ef80942017-12-04 12:01:30 -0700415 if (!is_win || is_clang) {
Mike Klein50500ad2016-11-16 12:13:44 -0500416 cflags = [ "-Wno-unused-parameter" ]
417 }
418}
Mike Kleinc7165c22016-10-12 23:58:06 -0400419
Mike Klein121563e2016-10-04 17:09:13 -0400420config("extra_flags") {
Kevin Lubick2677a9a2017-03-28 15:45:41 -0400421 asmflags = extra_asmflags
Mike Klein121563e2016-10-04 17:09:13 -0400422 cflags = extra_cflags
423 cflags_c = extra_cflags_c
424 cflags_cc = extra_cflags_cc
425 ldflags = extra_ldflags
426}
427
mtkleinb9be9792016-09-16 14:44:18 -0700428config("debug_symbols") {
429 # It's annoying to wait for full debug symbols to push over
430 # to Android devices. -gline-tables-only is a lot slimmer.
431 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400432 cflags = [
433 "-gline-tables-only",
434 "-funwind-tables", # Helps make in-process backtraces fuller.
435 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400436 } else if (is_win) {
Mike Klein67a86d52017-12-15 07:34:27 -0500437 cflags = [ "/Z7" ]
Brian Osmana99d9822017-12-28 14:53:10 -0500438 ldflags = [ "/DEBUG:FASTLINK" ]
Brian Osman0ab56842018-09-13 15:46:02 -0400439 if (is_clang) {
440 # /DEBUG:FASTLINK requires every object file to have standalone debug information.
441 cflags += [ "-fstandalone-debug" ]
442 }
Mike Kleincc300a12016-10-12 16:25:27 -0400443 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700444 cflags = [ "-g" ]
445 }
446}
447
448config("no_rtti") {
449 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400450 if (is_win) {
451 cflags_cc = [ "/GR-" ]
452 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700453 cflags_cc = [ "-fno-rtti" ]
454 }
455 }
456}
457
Mike Klein7ea977b2018-09-19 13:44:43 -0400458config("optimize") {
Mike Kleincc300a12016-10-12 16:25:27 -0400459 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400460 cflags = [
461 "/O2",
462 "/Zc:inline",
463 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400464 ldflags = [
465 "/OPT:ICF",
466 "/OPT:REF",
467 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400468 } else {
Mike Klein0bcfeac2016-10-19 22:24:10 -0400469 cflags = [
470 "-O3",
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500471 "-fdata-sections",
472 "-ffunction-sections",
Mike Klein0bcfeac2016-10-19 22:24:10 -0400473 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500474 if (is_mac || is_ios) {
475 ldflags = [ "-dead_strip" ]
476 } else {
477 ldflags = [ "-Wl,--gc-sections" ]
478 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400479 if (target_cpu == "wasm") {
480 # The compiler asks us to add an optimization flag to both cflags
481 # and ldflags to cut down on the local variables,
482 # for performance reasons.
483 # The "linking" step is the conversion to javascript.
484 ldflags += [ "-O3" ]
485 }
herbb6318bf2016-09-16 13:29:57 -0700486 }
Mike Klein7ea977b2018-09-19 13:44:43 -0400487}
488
489config("NDEBUG") {
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}