blob: 31422ac2a2e8479ac91ef7e13f0d9f41ac4157d5 [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
Mike Kleinba201ae2019-04-23 07:38:07 -050040 if (werror) {
41 if (is_win) {
42 cflags += [ "/WX" ]
43 } else {
44 cflags += [ "-Werror" ]
45 }
46 }
47
mtkleinb9be9792016-09-16 14:44:18 -070048 if (is_win) {
Mike Kleinda8a6e12019-04-17 08:18:10 -050049 if (is_clang && target_cpu == "arm64") {
50 cflags += [ "--target=arm64-windows" ]
51 }
mtkleinb9be9792016-09-16 14:44:18 -070052 cflags += [
herbb6318bf2016-09-16 13:29:57 -070053 "/bigobj", # Some of our files are bigger than the regular limits.
Ben Wagnere6b274e2017-01-03 17:09:59 -050054 "/utf-8", # Set Source and Executable character sets to UTF-8.
herbb6318bf2016-09-16 13:29:57 -070055 ]
Mike Kleina91ec582017-07-31 16:35:17 -040056 if (is_clang) {
57 cflags += [ "-fms-compatibility-version=19" ] # 2015
58 }
mtkleinb9be9792016-09-16 14:44:18 -070059 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -040060 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
61 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -070062 "WIN32_LEAN_AND_MEAN",
63 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -070064 ]
Mike Klein98adfa82017-07-31 15:46:47 -040065
Brian Osmand34c4a32017-12-06 13:26:38 -050066 if (msvc == 2015) {
Brian Osman852ca312017-12-07 16:16:21 -050067 _include_dirs = [ "$win_vc/include" ]
Brian Osman5f872622017-12-06 15:21:44 -050068 } else { # 2017
Brian Osman852ca312017-12-07 16:16:21 -050069 _include_dirs = [ "$win_vc/Tools/MSVC/$win_toolchain_version/include" ]
Ravi Mistryf5ab2692017-12-06 21:51:23 +000070 }
Brian Osman5f872622017-12-06 15:21:44 -050071 _include_dirs += [
72 "$win_sdk/Include/$win_sdk_version/shared",
73 "$win_sdk/Include/$win_sdk_version/ucrt",
74 "$win_sdk/Include/$win_sdk_version/um",
75 "$win_sdk/Include/$win_sdk_version/winrt",
76 ]
77
Mike Klein98adfa82017-07-31 15:46:47 -040078 if (is_clang) {
79 foreach(dir, _include_dirs) {
80 cflags += [
81 "-imsvc",
82 dir,
83 ]
84 }
85 } else {
86 include_dirs = _include_dirs
87 }
88
Brian Osman5f872622017-12-06 15:21:44 -050089 lib_dirs = [
90 "$win_sdk/Lib/$win_sdk_version/ucrt/$target_cpu",
91 "$win_sdk/Lib/$win_sdk_version/um/$target_cpu",
92 ]
Brian Osmand34c4a32017-12-06 13:26:38 -050093 if (msvc == 2015) {
Brian Osmand34c4a32017-12-06 13:26:38 -050094 if (target_cpu == "x86") {
Brian Osman852ca312017-12-07 16:16:21 -050095 lib_dirs += [ "$win_vc/lib" ]
Brian Osmand34c4a32017-12-06 13:26:38 -050096 } else {
Brian Osman852ca312017-12-07 16:16:21 -050097 lib_dirs += [ "$win_vc/lib/amd64" ]
Brian Osmand34c4a32017-12-06 13:26:38 -050098 }
Brian Osman5f872622017-12-06 15:21:44 -050099 } else { # 2017
100 lib_dirs +=
Brian Osman852ca312017-12-07 16:16:21 -0500101 [ "$win_vc/Tools/MSVC/$win_toolchain_version/lib/$target_cpu" ]
Mike Klein0bc5a762016-10-12 22:42:55 -0400102 }
mtkleinb9be9792016-09-16 14:44:18 -0700103 } else {
104 cflags += [
herbb6318bf2016-09-16 13:29:57 -0700105 "-fstrict-aliasing",
106 "-fPIC",
mtklein2b3c2a32016-09-08 08:39:34 -0700107 ]
Brian Salomon7258e972018-06-02 11:18:33 -0400108 cflags_cc += [ "-std=c++14" ]
Mike Kleineec23d12017-03-26 20:11:48 -0400109
110 # The main idea is to slim the exported API, but these flags also improve link time on Mac.
111 # These would make stack traces worse on Linux, so we don't just set them willy-nilly.
Mike Klein8cb66482017-03-28 14:16:22 -0400112 if (is_component_build || is_ios || is_mac) {
Mike Kleineec23d12017-03-26 20:11:48 -0400113 cflags += [ "-fvisibility=hidden" ]
114 cflags_cc += [ "-fvisibility-inlines-hidden" ]
115 }
mtkleinb9be9792016-09-16 14:44:18 -0700116 }
herbb6318bf2016-09-16 13:29:57 -0700117
mtkleinb9be9792016-09-16 14:44:18 -0700118 if (current_cpu == "arm") {
119 cflags += [
120 "-march=armv7-a",
121 "-mfpu=neon",
122 "-mthumb",
123 ]
Ben Wagner9bd736b2018-04-04 15:35:01 -0400124 } else if (current_cpu == "loongson3a") {
125 asmflags += [ "-march=loongson3a" ]
126 cflags += [
127 "-march=loongson3a",
128
129 # Causes an internal compiler error.
130 "-DSKCMS_PORTABLE",
131 ]
132 } else if (current_cpu == "mips64el") {
133 asmflags += [ "-march=mips64" ]
134 cflags += [ "-march=mips64" ]
Mike Klein4d4b3aa2018-03-21 13:07:35 -0400135 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700136 asmflags += [ "-m32" ]
137 cflags += [
138 "-m32",
139 "-msse2",
140 "-mfpmath=sse",
141 ]
142 ldflags += [ "-m32" ]
143 }
herbb6318bf2016-09-16 13:29:57 -0700144
Herb Derby76073c12016-12-08 19:00:40 -0500145 if (malloc != "" && !is_win) {
146 cflags += [
147 "-fno-builtin-malloc",
148 "-fno-builtin-calloc",
149 "-fno-builtin-realloc",
150 "-fno-builtin-free",
151 ]
152 libs += [ malloc ]
153 }
154
Hal Canarya0834042018-06-01 20:22:25 +0000155 if (is_android) {
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400156 asmflags += [ "--target=$ndk_target" ]
mtkleinb9be9792016-09-16 14:44:18 -0700157 cflags += [
Derek Sollenberger19b2a562017-06-27 11:55:05 -0400158 "--sysroot=$ndk/sysroot",
159 "-isystem$ndk/sysroot/usr/include/$ndk_target",
160 "-D__ANDROID_API__=$ndk_api",
mtkleinb9be9792016-09-16 14:44:18 -0700161 "--target=$ndk_target",
mtkleinb9be9792016-09-16 14:44:18 -0700162 ]
163 cflags_cc += [
Mike Klein21b620c2018-01-08 17:16:00 -0500164 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include",
165 "-isystem$ndk/sources/cxx-stl/llvm-libc++abi/include",
mtkleinb9be9792016-09-16 14:44:18 -0700166 "-isystem$ndk/sources/android/support/include",
mtkleinb9be9792016-09-16 14:44:18 -0700167 ]
168 ldflags += [
169 "--sysroot=$ndk/platforms/$ndk_platform",
170 "--target=$ndk_target",
171 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtkleinb9be9792016-09-16 14:44:18 -0700172 ]
173 lib_dirs = [
Mike Klein21b620c2018-01-08 17:16:00 -0500174 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
mtkleinb9be9792016-09-16 14:44:18 -0700175 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
176 ]
herbb6318bf2016-09-16 13:29:57 -0700177
Mike Klein21b620c2018-01-08 17:16:00 -0500178 libs += [
179 "c++_static",
180 "c++abi",
Mike Klein21b620c2018-01-08 17:16:00 -0500181 ]
Mike Klein8803ebb2018-05-14 13:25:46 -0400182 if (ndk_api < 21) {
183 libs += [ "android_support" ]
184 }
mtklein2b3c2a32016-09-08 08:39:34 -0700185 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700186
Mike Klein7d302882016-11-03 14:06:31 -0400187 if (is_ios) {
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500188 _target = target_cpu
189 if (target_cpu == "arm") {
190 _target = "armv7"
Mike Klein7a5e0f32017-03-13 09:25:33 -0700191 } else if (target_cpu == "x86") {
192 _target = "i386"
193 } else if (target_cpu == "x64") {
194 _target = "x86_64"
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500195 }
Mike Klein4fe2b152017-02-17 15:36:01 -0500196 asmflags += [
197 "-isysroot",
198 ios_sysroot,
199 "-arch",
200 _target,
201 ]
Mike Klein7d302882016-11-03 14:06:31 -0400202 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500203 "-isysroot",
204 ios_sysroot,
205 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500206 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400207 ]
208 cflags_cc += [ "-stdlib=libc++" ]
209 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500210 "-isysroot",
211 ios_sysroot,
212 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500213 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400214 "-stdlib=libc++",
215 ]
Herb Derby76073c12016-12-08 19:00:40 -0500216 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400217 }
218
mtkleinb9be9792016-09-16 14:44:18 -0700219 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500220 libs += [ "pthread" ]
Cary Clarkeb1d9002018-07-13 10:39:39 -0400221 if (is_debug && sanitize == "") {
222 defines += [ "_GLIBCXX_DEBUG" ]
223 }
mtkleinb9be9792016-09-16 14:44:18 -0700224 }
Mike Klein15f46c32017-12-07 12:48:57 -0500225 if (is_mac) {
226 # Disable linker warnings. They're usually just annoyances like,
227 # ld: warning: text-based stub file
228 # /System/Library/Frameworks/foo.framework/foo.tbd and library file
229 # /System/Library/Frameworks/foo.framework/foo are out of sync.
230 # Falling back to library file for linking.
231 ldflags += [ "-Wl,-w" ]
232 }
mtkleinb9be9792016-09-16 14:44:18 -0700233
Brian Osman50ea3c02019-02-04 10:01:53 -0500234 if (sanitize != "" && sanitize != "MSVC") {
mtkleinb9be9792016-09-16 14:44:18 -0700235 # You can either pass the sanitizers directly, e.g. "address,undefined",
236 # or pass one of the couple common aliases used by the bots.
237 sanitizers = sanitize
Kevin Lubickd0950402018-03-20 10:10:58 -0400238
Ben Wagner314d7c22018-01-03 11:04:30 -0500239 if (sanitize == "ASAN" || sanitize == "UBSAN") {
240 # ASAN implicitly runs all UBSAN checks also.
Mike Klein02046a72018-08-10 12:25:12 -0400241 sanitizers = "undefined"
Ben Wagner314d7c22018-01-03 11:04:30 -0500242 if (sanitize == "ASAN") {
243 sanitizers += ",address"
Mike Kleine4781e92017-09-28 11:42:28 -0400244 }
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500245
Mike Klein02046a72018-08-10 12:25:12 -0400246 if (is_android) {
247 # TODO(mtklein): work out UBSAN link errors
248 sanitizers = "address"
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500249 }
mtkleinb9be9792016-09-16 14:44:18 -0700250 } else if (sanitize == "TSAN") {
251 sanitizers = "thread"
252 } else if (sanitize == "MSAN") {
253 sanitizers = "memory"
254 }
255
Mike Klein475c5e92018-08-08 10:23:17 -0400256 _blacklist = rebase_path("../tools/xsan.blacklist")
257
mtkleinb9be9792016-09-16 14:44:18 -0700258 cflags += [
Mike Klein02046a72018-08-10 12:25:12 -0400259 "-fsanitize=$sanitizers",
mtkleinb9be9792016-09-16 14:44:18 -0700260 "-fno-sanitize-recover=$sanitizers",
Mike Klein475c5e92018-08-08 10:23:17 -0400261 "-fsanitize-blacklist=$_blacklist",
mtkleinb9be9792016-09-16 14:44:18 -0700262 ]
Mike Klein02046a72018-08-10 12:25:12 -0400263 ldflags += [ "-fsanitize=$sanitizers" ]
264
Mike Klein94c4f412018-08-09 17:24:45 -0400265 if (is_win) {
266 cflags += [ "/FI$_blacklist" ]
267 } else {
268 cflags += [
269 "-include$_blacklist",
270 "-fno-omit-frame-pointer",
271 ]
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500272 }
Mike Klein94c4f412018-08-09 17:24:45 -0400273
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500274 if (is_linux) {
Kevin Lubick43bd2592018-02-15 09:03:44 -0500275 cflags_cc += [ "-stdlib=libc++" ]
276 ldflags += [ "-stdlib=libc++" ]
Kevin Lubick3cda39f2018-02-01 12:09:55 -0500277 }
Mike Klein02046a72018-08-10 12:25:12 -0400278
mtkleinb9be9792016-09-16 14:44:18 -0700279 if (sanitizers == "memory") {
280 cflags += [ "-fsanitize-memory-track-origins" ]
mtkleinb9be9792016-09-16 14:44:18 -0700281 }
282 }
283}
284
Mike Klein6e55fef2016-10-26 11:41:47 -0400285config("no_exceptions") {
Mike Klein228276d2017-08-16 13:20:20 +0000286 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
Mike Klein6e55fef2016-10-26 11:41:47 -0400287 if (!is_win) {
288 cflags_cc = [ "-fno-exceptions" ]
289 }
290}
291
Mike Kleinc7165c22016-10-12 23:58:06 -0400292config("warnings") {
293 cflags = []
294 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400295 cflags_objc = []
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400296 cflags_objcc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400297 if (is_win) {
298 cflags += [
299 "/W3", # Turn on lots of warnings.
300
301 # Disable a bunch of warnings:
302 "/wd4244", # conversion from 'float' to 'int', possible loss of data
303 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
304 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
305
306 # Probably only triggers when /EHsc is enabled.
307 "/wd4291", # no matching operator delete found;
308 # memory will not be freed if initialization throws an exception
Brian Osmaneec1e9e2019-04-10 16:22:15 -0400309
310 # These only show up in shared builds:
311 "/wd4251", # class 'type' needs to have dll-interface to be used by clients of class 'type2'
312 "/wd4275", # non dll-interface class 'base' used as base for dll-interface class 'derived'
Mike Kleinc7165c22016-10-12 23:58:06 -0400313 ]
314 } else {
315 cflags += [
316 "-Wall",
317 "-Wextra",
318 "-Winit-self",
319 "-Wpointer-arith",
320 "-Wsign-compare",
321 "-Wvla",
322
323 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500324 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400325 ]
Ben Wagnerf8a131d2018-03-13 16:56:43 -0400326 cflags_cc += [
327 "-Wnon-virtual-dtor",
328 "-Wno-noexcept-type",
329 ]
Chris Dalton1ef80942017-12-04 12:01:30 -0700330 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400331
Chris Dalton1ef80942017-12-04 12:01:30 -0700332 if (is_clang) {
333 cflags += [
Mike Kleinb7b2da82019-02-28 08:47:44 -0600334 "-fcolor-diagnostics",
Chris Dalton1ef80942017-12-04 12:01:30 -0700335 "-Weverything",
336 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
337 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400338
Chris Dalton1ef80942017-12-04 12:01:30 -0700339 if (target_cpu == "arm" && is_ios) {
340 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS.
341 # We're pretty sure it's actually 8-byte alignment.
342 cflags += [ "-Wno-over-aligned" ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400343 }
Mike Klein04282792018-01-08 18:23:32 -0500344 if (target_cpu == "x86" && is_android) {
345 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds.
346 # We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info.
347 cflags += [ "-Wno-over-aligned" ]
348 }
Chris Dalton1ef80942017-12-04 12:01:30 -0700349
350 # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose
351 # their case during copy, causing case-sensitivity mismatch on remote machines.
352 cflags += [
353 "-Wno-nonportable-include-path",
354 "-Wno-nonportable-system-include-path",
355 ]
356
357 # TODO: These would all be really great warnings to turn on.
358 cflags += [
359 "-Wno-cast-align",
360 "-Wno-cast-qual",
Chris Dalton1ef80942017-12-04 12:01:30 -0700361 "-Wno-conversion",
362 "-Wno-disabled-macro-expansion",
363 "-Wno-documentation",
364 "-Wno-documentation-unknown-command",
365 "-Wno-double-promotion",
366 "-Wno-exit-time-destructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700367 "-Wno-float-equal",
368 "-Wno-format-nonliteral",
369 "-Wno-global-constructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700370 "-Wno-missing-prototypes",
371 "-Wno-missing-variable-declarations",
372 "-Wno-pedantic",
373 "-Wno-reserved-id-macro",
374 "-Wno-shadow",
375 "-Wno-shift-sign-overflow",
Chris Dalton1ef80942017-12-04 12:01:30 -0700376 "-Wno-signed-enum-bitfield",
377 "-Wno-switch-enum",
378 "-Wno-undef",
379 "-Wno-unreachable-code",
380 "-Wno-unreachable-code-break",
381 "-Wno-unreachable-code-return",
382 "-Wno-unused-macros",
383 "-Wno-unused-member-function",
384 "-Wno-unused-template",
385 "-Wno-zero-as-null-pointer-constant",
Herb Derbya1b7be62019-05-09 16:59:18 -0400386 "-Wno-thread-safety-negative",
Chris Dalton1ef80942017-12-04 12:01:30 -0700387 ]
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 Osman7142ae52018-12-12 16:32:35 -0500445 if (is_clang) {
Eric Boren56bf8ce2019-02-07 13:05:06 -0500446 cflags += [ "-gcodeview-ghash" ]
Mike Kleincae020a2018-12-23 10:25:44 -0500447 ldflags = [ "/DEBUG:GHASH" ]
Brian Osman7142ae52018-12-12 16:32:35 -0500448 } else {
Mike Kleina6e0c2b2018-12-10 08:48:03 -0500449 ldflags = [ "/DEBUG:FASTLINK" ]
Brian Osman0ab56842018-09-13 15:46:02 -0400450 }
Mike Kleincc300a12016-10-12 16:25:27 -0400451 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700452 cflags = [ "-g" ]
453 }
454}
455
456config("no_rtti") {
457 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400458 if (is_win) {
459 cflags_cc = [ "/GR-" ]
460 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700461 cflags_cc = [ "-fno-rtti" ]
462 }
463 }
464}
465
Mike Klein7ea977b2018-09-19 13:44:43 -0400466config("optimize") {
Mike Kleincc300a12016-10-12 16:25:27 -0400467 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400468 cflags = [
469 "/O2",
470 "/Zc:inline",
471 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400472 ldflags = [
473 "/OPT:ICF",
474 "/OPT:REF",
475 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400476 } else {
Mike Klein13daa4f2019-06-20 10:08:55 -0500477 cflags = [ "-O3" ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500478 if (is_mac || is_ios) {
479 ldflags = [ "-dead_strip" ]
480 } else {
Mike Klein13daa4f2019-06-20 10:08:55 -0500481 cflags += [
482 "-fdata-sections",
483 "-ffunction-sections",
484 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500485 ldflags = [ "-Wl,--gc-sections" ]
486 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400487 if (target_cpu == "wasm") {
488 # The compiler asks us to add an optimization flag to both cflags
489 # and ldflags to cut down on the local variables,
490 # for performance reasons.
491 # The "linking" step is the conversion to javascript.
492 ldflags += [ "-O3" ]
493 }
herbb6318bf2016-09-16 13:29:57 -0700494 }
Mike Klein7ea977b2018-09-19 13:44:43 -0400495}
496
497config("NDEBUG") {
mtkleinb9be9792016-09-16 14:44:18 -0700498 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700499}
500
Brian Osman50ea3c02019-02-04 10:01:53 -0500501config("msvc_rtc") {
502 defines = [ "_ALLOW_RTCc_IN_STL" ]
503 cflags = [
504 "/RTCcsu",
505 "/guard:cf",
506 ]
507 ldflags = [ "/guard:cf" ]
508}
509
mtklein7fbfbbe2016-07-21 12:25:45 -0700510config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500511 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400512 ldflags = [
513 "-pie",
514 "-rdynamic",
515 ]
Mike Kleinc5875fb2016-12-06 10:46:02 -0500516 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700517 ldflags = [ "-Wl,-rpath,@loader_path/." ]
518 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700519 ldflags = [
520 "-rdynamic",
521 "-Wl,-rpath,\$ORIGIN",
522 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500523 } else if (is_win) {
524 ldflags = [
525 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
526 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
527 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700528 }
529}