blob: a59ea99504c02a54c0a89a7ba304100afb0e1d39 [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
John Rosasco24cbdab2019-09-25 14:14:35 -07006if (is_fuchsia) {
Robert Phillipsc919f972019-11-18 11:01:05 -05007 import("//build/fuchsia/sdk.gni")
John Rosasco24cbdab2019-09-25 14:14:35 -07008}
9
mtklein7fbfbbe2016-07-21 12:25:45 -070010declare_args() {
Kevin Lubick2677a9a2017-03-28 15:45:41 -040011 extra_asmflags = []
Mike Klein121563e2016-10-04 17:09:13 -040012 extra_cflags = []
13 extra_cflags_c = []
14 extra_cflags_cc = []
15 extra_ldflags = []
mtkleincab0bb72016-08-26 13:43:19 -070016
Herb Derby76073c12016-12-08 19:00:40 -050017 malloc = ""
Herb Derbyc65eb342019-10-18 14:29:09 -040018 xcode_sysroot = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070019}
Mike Klein82364ba2016-10-24 16:49:15 -040020
Herb Derbyc65eb342019-10-18 14:29:09 -040021if (is_ios && xcode_sysroot == "") {
Matthew Leibowitz3150ec62017-03-14 16:22:32 -040022 if (is_tvos) {
23 sdk = "appletvos"
24 if (target_cpu == "x86" || target_cpu == "x64") {
25 sdk = "appletvsimulator"
26 }
27 } else {
28 sdk = "iphoneos"
29 if (target_cpu == "x86" || target_cpu == "x64") {
30 sdk = "iphonesimulator"
31 }
Mike Klein7a5e0f32017-03-13 09:25:33 -070032 }
Herb Derbyc65eb342019-10-18 14:29:09 -040033 xcode_sysroot = exec_script("find_xcode_sysroot.py", [ sdk ], "trim string")
34}
35
36# If building for mac on a mac then lookup all the system includes so that goma and the clang
37# shipped with chrome can find them. When the gn_to_bp.py tool is run, then the host_os != mac.
38# In this case leave the xcode_sysroot empty, and the cc/c++ that come with XCode will be able to
39# find needed include paths.
40if (is_mac && host_os == "mac" && xcode_sysroot == "") {
41 xcode_sysroot =
42 exec_script("find_xcode_sysroot.py", [ "macosx" ], "trim string")
Mike Klein7d302882016-11-03 14:06:31 -040043}
44
mtkleinb9be9792016-09-16 14:44:18 -070045config("default") {
46 asmflags = []
47 cflags = []
48 cflags_c = []
49 cflags_cc = []
50 defines = []
51 ldflags = []
Herb Derby76073c12016-12-08 19:00:40 -050052 libs = []
mtkleinb9be9792016-09-16 14:44:18 -070053
Mike Kleinba201ae2019-04-23 07:38:07 -050054 if (werror) {
55 if (is_win) {
56 cflags += [ "/WX" ]
57 } else {
58 cflags += [ "-Werror" ]
59 }
60 }
61
Mike Klein28abea52020-02-19 09:17:51 -060062 # Disable warnings about unknown attributes.
63 # (These unknown attribute warnings are on by default, so we don't make
64 # disabling them part of :warnings, as some targets remove :warnings.)
65 if (is_win && !is_clang) {
66 cflags += [ "/wd5030" ]
67 } else {
68 cflags += [ "-Wno-attributes" ]
69 }
70
John Rosasco24cbdab2019-09-25 14:14:35 -070071 if (is_fuchsia && using_fuchsia_sdk) {
Robert Phillipsc919f972019-11-18 11:01:05 -050072 ldflags += [
73 "-v",
74 "--sysroot=" + rebase_path("$fuchsia_sdk_path/arch/$target_cpu/sysroot"),
75 ]
76 cflags += [ "--sysroot=" +
77 rebase_path("$fuchsia_sdk_path/arch/$target_cpu/sysroot") ]
John Rosasco24cbdab2019-09-25 14:14:35 -070078 if (target_cpu == "x64") {
79 target_triple = "--target=x86_64-${target_os}"
80 } else if (target_cpu == "arm64") {
81 target_triple = "--target=aarch64-unknown-${target_os}"
82 } else {
83 print("Unknown target CPU for Fuchsia target build.")
84 assert(false)
85 }
86 ldflags += [ target_triple ]
87 cflags += [ target_triple ]
88 asmflags += [ target_triple ]
89 }
90
mtkleinb9be9792016-09-16 14:44:18 -070091 if (is_win) {
Mike Kleinda8a6e12019-04-17 08:18:10 -050092 if (is_clang && target_cpu == "arm64") {
93 cflags += [ "--target=arm64-windows" ]
94 }
mtkleinb9be9792016-09-16 14:44:18 -070095 cflags += [
herbb6318bf2016-09-16 13:29:57 -070096 "/bigobj", # Some of our files are bigger than the regular limits.
Ben Wagnere6b274e2017-01-03 17:09:59 -050097 "/utf-8", # Set Source and Executable character sets to UTF-8.
herbb6318bf2016-09-16 13:29:57 -070098 ]
Brian Salomon8283fa42019-11-07 10:42:41 -050099 cflags_cc += [ "/std:c++17" ]
Mike Kleina91ec582017-07-31 16:35:17 -0400100 if (is_clang) {
101 cflags += [ "-fms-compatibility-version=19" ] # 2015
102 }
mtkleinb9be9792016-09-16 14:44:18 -0700103 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -0400104 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
105 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -0700106 "WIN32_LEAN_AND_MEAN",
107 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -0700108 ]
Mike Klein98adfa82017-07-31 15:46:47 -0400109
Hal Canaryf72728e2019-07-10 11:24:52 -0400110 _include_dirs = [
111 "$win_vc/Tools/MSVC/$win_toolchain_version/include",
Brian Osman5f872622017-12-06 15:21:44 -0500112 "$win_sdk/Include/$win_sdk_version/shared",
113 "$win_sdk/Include/$win_sdk_version/ucrt",
114 "$win_sdk/Include/$win_sdk_version/um",
115 "$win_sdk/Include/$win_sdk_version/winrt",
116 ]
117
Mike Klein98adfa82017-07-31 15:46:47 -0400118 if (is_clang) {
119 foreach(dir, _include_dirs) {
120 cflags += [
121 "-imsvc",
122 dir,
123 ]
124 }
125 } else {
126 include_dirs = _include_dirs
127 }
128
Brian Osman5f872622017-12-06 15:21:44 -0500129 lib_dirs = [
130 "$win_sdk/Lib/$win_sdk_version/ucrt/$target_cpu",
131 "$win_sdk/Lib/$win_sdk_version/um/$target_cpu",
Hal Canaryf72728e2019-07-10 11:24:52 -0400132 "$win_vc/Tools/MSVC/$win_toolchain_version/lib/$target_cpu",
Brian Osman5f872622017-12-06 15:21:44 -0500133 ]
mtkleinb9be9792016-09-16 14:44:18 -0700134 } else {
Shachar Langbeheim07c4e1d2019-12-16 10:46:52 +0200135 cflags += [
136 "-fstrict-aliasing",
137 "-fPIC",
138 ]
Brian Salomon8283fa42019-11-07 10:42:41 -0500139 cflags_cc += [ "-std=c++17" ]
Mike Kleineec23d12017-03-26 20:11:48 -0400140
141 # The main idea is to slim the exported API, but these flags also improve link time on Mac.
142 # These would make stack traces worse on Linux, so we don't just set them willy-nilly.
Mike Klein8cb66482017-03-28 14:16:22 -0400143 if (is_component_build || is_ios || is_mac) {
Mike Kleineec23d12017-03-26 20:11:48 -0400144 cflags += [ "-fvisibility=hidden" ]
145 cflags_cc += [ "-fvisibility-inlines-hidden" ]
146 }
mtkleinb9be9792016-09-16 14:44:18 -0700147 }
herbb6318bf2016-09-16 13:29:57 -0700148
mtkleinb9be9792016-09-16 14:44:18 -0700149 if (current_cpu == "arm") {
150 cflags += [
151 "-march=armv7-a",
152 "-mfpu=neon",
153 "-mthumb",
154 ]
Ben Wagner9bd736b2018-04-04 15:35:01 -0400155 } else if (current_cpu == "loongson3a") {
156 asmflags += [ "-march=loongson3a" ]
157 cflags += [
158 "-march=loongson3a",
159
160 # Causes an internal compiler error.
161 "-DSKCMS_PORTABLE",
162 ]
163 } else if (current_cpu == "mips64el") {
164 asmflags += [ "-march=mips64" ]
165 cflags += [ "-march=mips64" ]
Mike Klein4d4b3aa2018-03-21 13:07:35 -0400166 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700167 asmflags += [ "-m32" ]
168 cflags += [
169 "-m32",
170 "-msse2",
171 "-mfpmath=sse",
172 ]
173 ldflags += [ "-m32" ]
174 }
herbb6318bf2016-09-16 13:29:57 -0700175
Herb Derby76073c12016-12-08 19:00:40 -0500176 if (malloc != "" && !is_win) {
177 cflags += [
178 "-fno-builtin-malloc",
179 "-fno-builtin-calloc",
180 "-fno-builtin-realloc",
181 "-fno-builtin-free",
182 ]
183 libs += [ malloc ]
184 }
185
Hal Canarya0834042018-06-01 20:22:25 +0000186 if (is_android) {
Mike Klein5b52c522019-07-03 10:44:21 -0500187 cflags += [ "--sysroot=$ndk/sysroot" ]
188 cflags_cc += [ "-isystem$ndk/sources/cxx-stl/llvm-libc++/include" ]
189 ldflags += [ "-static-libstdc++" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700190 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700191
Mike Klein7d302882016-11-03 14:06:31 -0400192 if (is_ios) {
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500193 _target = target_cpu
194 if (target_cpu == "arm") {
195 _target = "armv7"
Mike Klein7a5e0f32017-03-13 09:25:33 -0700196 } else if (target_cpu == "x86") {
197 _target = "i386"
198 } else if (target_cpu == "x64") {
199 _target = "x86_64"
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500200 }
Mike Klein4fe2b152017-02-17 15:36:01 -0500201 asmflags += [
202 "-isysroot",
Herb Derbyc65eb342019-10-18 14:29:09 -0400203 xcode_sysroot,
Mike Klein4fe2b152017-02-17 15:36:01 -0500204 "-arch",
205 _target,
206 ]
Mike Klein7d302882016-11-03 14:06:31 -0400207 cflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500208 "-isysroot",
Herb Derbyc65eb342019-10-18 14:29:09 -0400209 xcode_sysroot,
Mike Klein6749af42016-11-07 15:38:48 -0500210 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500211 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400212 ]
Brian Salomon8283fa42019-11-07 10:42:41 -0500213 cflags_cc += [
214 "-stdlib=libc++",
215 "-fno-aligned-allocation",
216 ]
Mike Klein7d302882016-11-03 14:06:31 -0400217 ldflags += [
Mike Klein6749af42016-11-07 15:38:48 -0500218 "-isysroot",
Herb Derbyc65eb342019-10-18 14:29:09 -0400219 xcode_sysroot,
Mike Klein6749af42016-11-07 15:38:48 -0500220 "-arch",
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500221 _target,
Mike Klein7d302882016-11-03 14:06:31 -0400222 "-stdlib=libc++",
223 ]
Herb Derby76073c12016-12-08 19:00:40 -0500224 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400225 }
226
mtkleinb9be9792016-09-16 14:44:18 -0700227 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500228 libs += [ "pthread" ]
Cary Clarkeb1d9002018-07-13 10:39:39 -0400229 if (is_debug && sanitize == "") {
230 defines += [ "_GLIBCXX_DEBUG" ]
231 }
mtkleinb9be9792016-09-16 14:44:18 -0700232 }
Herb Derbyc65eb342019-10-18 14:29:09 -0400233
Mike Klein15f46c32017-12-07 12:48:57 -0500234 if (is_mac) {
Herb Derbyc65eb342019-10-18 14:29:09 -0400235 # If there was a xcode_sysroot set in args or calculated then use it, else don't set anything
236 # because the XCode cc/c++ already know all this stuff.
237 if (xcode_sysroot != "") {
238 asmflags += [
239 "-isysroot",
240 xcode_sysroot,
241 ]
242 cflags += [
243 "-isysroot",
244 xcode_sysroot,
245 ]
246 ldflags += [
247 "-isysroot",
248 xcode_sysroot,
249 ]
250 }
251
Mike Klein15f46c32017-12-07 12:48:57 -0500252 # Disable linker warnings. They're usually just annoyances like,
253 # ld: warning: text-based stub file
254 # /System/Library/Frameworks/foo.framework/foo.tbd and library file
255 # /System/Library/Frameworks/foo.framework/foo are out of sync.
256 # Falling back to library file for linking.
257 ldflags += [ "-Wl,-w" ]
258 }
mtkleinb9be9792016-09-16 14:44:18 -0700259
Brian Osman50ea3c02019-02-04 10:01:53 -0500260 if (sanitize != "" && sanitize != "MSVC") {
mtkleinb9be9792016-09-16 14:44:18 -0700261 # You can either pass the sanitizers directly, e.g. "address,undefined",
262 # or pass one of the couple common aliases used by the bots.
263 sanitizers = sanitize
Kevin Lubickd0950402018-03-20 10:10:58 -0400264
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500265 if (sanitize == "ASAN") {
Ben Wagner314d7c22018-01-03 11:04:30 -0500266 # ASAN implicitly runs all UBSAN checks also.
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500267 sanitizers = "undefined,address"
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500268
Mike Klein02046a72018-08-10 12:25:12 -0400269 if (is_android) {
270 # TODO(mtklein): work out UBSAN link errors
271 sanitizers = "address"
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500272 }
mtkleinb9be9792016-09-16 14:44:18 -0700273 } else if (sanitize == "TSAN") {
274 sanitizers = "thread"
275 } else if (sanitize == "MSAN") {
276 sanitizers = "memory"
277 }
278
Mike Klein475c5e92018-08-08 10:23:17 -0400279 _blacklist = rebase_path("../tools/xsan.blacklist")
280
mtkleinb9be9792016-09-16 14:44:18 -0700281 cflags += [
Mike Klein02046a72018-08-10 12:25:12 -0400282 "-fsanitize=$sanitizers",
mtkleinb9be9792016-09-16 14:44:18 -0700283 "-fno-sanitize-recover=$sanitizers",
Mike Klein475c5e92018-08-08 10:23:17 -0400284 "-fsanitize-blacklist=$_blacklist",
mtkleinb9be9792016-09-16 14:44:18 -0700285 ]
Mike Kleincdb0e8f2019-12-18 14:25:50 -0600286
Mike Klein94c4f412018-08-09 17:24:45 -0400287 if (is_win) {
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500288 cflags += [
289 "/FI$_blacklist",
290
291 # On Release builds, we get strange warnings about string literals.
292 "/GF-",
293 ]
294
295 assert(clang_win != "")
296 libs += [ "$clang_win/lib/clang/$clang_win_version/lib/windows/clang_rt.asan-x86_64.lib" ]
Mike Klein94c4f412018-08-09 17:24:45 -0400297 } else {
298 cflags += [
299 "-include$_blacklist",
300 "-fno-omit-frame-pointer",
301 ]
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500302
303 ldflags += [ "-fsanitize=$sanitizers" ]
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500304 }
Mike Klein94c4f412018-08-09 17:24:45 -0400305
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500306 if (is_linux) {
Kevin Lubick43bd2592018-02-15 09:03:44 -0500307 cflags_cc += [ "-stdlib=libc++" ]
308 ldflags += [ "-stdlib=libc++" ]
Kevin Lubick3cda39f2018-02-01 12:09:55 -0500309 }
Mike Klein02046a72018-08-10 12:25:12 -0400310
mtkleinb9be9792016-09-16 14:44:18 -0700311 if (sanitizers == "memory") {
312 cflags += [ "-fsanitize-memory-track-origins" ]
mtkleinb9be9792016-09-16 14:44:18 -0700313 }
Brian Salomon8283fa42019-11-07 10:42:41 -0500314 if (sanitizers == "safe-stack") {
315 cflags_cc += [ "-fno-aligned-allocation" ]
316 }
mtkleinb9be9792016-09-16 14:44:18 -0700317 }
318}
319
Mike Kleinc0c05222020-01-31 11:07:51 -0600320# See skia:9731.
321config("recover_pointer_overflow") {
322 cflags = [ "-fsanitize-recover=pointer-overflow" ]
323}
324
Mike Klein6e55fef2016-10-26 11:41:47 -0400325config("no_exceptions") {
Mike Klein228276d2017-08-16 13:20:20 +0000326 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
Mike Klein6e55fef2016-10-26 11:41:47 -0400327 if (!is_win) {
328 cflags_cc = [ "-fno-exceptions" ]
329 }
330}
331
Mike Kleinc7165c22016-10-12 23:58:06 -0400332config("warnings") {
333 cflags = []
334 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400335 cflags_objc = []
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400336 cflags_objcc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400337 if (is_win) {
338 cflags += [
339 "/W3", # Turn on lots of warnings.
340
341 # Disable a bunch of warnings:
342 "/wd4244", # conversion from 'float' to 'int', possible loss of data
343 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
344 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
345
346 # Probably only triggers when /EHsc is enabled.
347 "/wd4291", # no matching operator delete found;
348 # memory will not be freed if initialization throws an exception
Brian Osmaneec1e9e2019-04-10 16:22:15 -0400349
350 # These only show up in shared builds:
351 "/wd4251", # class 'type' needs to have dll-interface to be used by clients of class 'type2'
352 "/wd4275", # non dll-interface class 'base' used as base for dll-interface class 'derived'
Brian Salomon8283fa42019-11-07 10:42:41 -0500353
354 # It'd be nice to fix these and turn this on:
355 "/wd5041", # out-of-line definition for constexpr static data member is not needed and is deprecated in C++17
Mike Kleinc7165c22016-10-12 23:58:06 -0400356 ]
357 } else {
358 cflags += [
359 "-Wall",
360 "-Wextra",
361 "-Winit-self",
362 "-Wpointer-arith",
363 "-Wsign-compare",
364 "-Wvla",
365
366 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500367 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400368 ]
Ben Wagnerf8a131d2018-03-13 16:56:43 -0400369 cflags_cc += [
370 "-Wnon-virtual-dtor",
371 "-Wno-noexcept-type",
372 ]
Chris Dalton1ef80942017-12-04 12:01:30 -0700373 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400374
Chris Dalton1ef80942017-12-04 12:01:30 -0700375 if (is_clang) {
376 cflags += [
Mike Kleinb7b2da82019-02-28 08:47:44 -0600377 "-fcolor-diagnostics",
Chris Dalton1ef80942017-12-04 12:01:30 -0700378 "-Weverything",
379 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
380 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400381
Chris Dalton1ef80942017-12-04 12:01:30 -0700382 if (target_cpu == "arm" && is_ios) {
383 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS.
384 # We're pretty sure it's actually 8-byte alignment.
385 cflags += [ "-Wno-over-aligned" ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400386 }
Mike Klein04282792018-01-08 18:23:32 -0500387 if (target_cpu == "x86" && is_android) {
388 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds.
389 # We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info.
390 cflags += [ "-Wno-over-aligned" ]
391 }
Chris Dalton1ef80942017-12-04 12:01:30 -0700392
393 # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose
394 # their case during copy, causing case-sensitivity mismatch on remote machines.
395 cflags += [
396 "-Wno-nonportable-include-path",
397 "-Wno-nonportable-system-include-path",
398 ]
399
400 # TODO: These would all be really great warnings to turn on.
401 cflags += [
402 "-Wno-cast-align",
403 "-Wno-cast-qual",
Chris Dalton1ef80942017-12-04 12:01:30 -0700404 "-Wno-conversion",
405 "-Wno-disabled-macro-expansion",
406 "-Wno-documentation",
407 "-Wno-documentation-unknown-command",
408 "-Wno-double-promotion",
409 "-Wno-exit-time-destructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700410 "-Wno-float-equal",
411 "-Wno-format-nonliteral",
412 "-Wno-global-constructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700413 "-Wno-missing-prototypes",
414 "-Wno-missing-variable-declarations",
415 "-Wno-pedantic",
416 "-Wno-reserved-id-macro",
417 "-Wno-shadow",
418 "-Wno-shift-sign-overflow",
Chris Dalton1ef80942017-12-04 12:01:30 -0700419 "-Wno-signed-enum-bitfield",
420 "-Wno-switch-enum",
421 "-Wno-undef",
422 "-Wno-unreachable-code",
423 "-Wno-unreachable-code-break",
424 "-Wno-unreachable-code-return",
425 "-Wno-unused-macros",
426 "-Wno-unused-member-function",
427 "-Wno-unused-template",
428 "-Wno-zero-as-null-pointer-constant",
Herb Derbya1b7be62019-05-09 16:59:18 -0400429 "-Wno-thread-safety-negative",
Chris Dalton1ef80942017-12-04 12:01:30 -0700430 ]
431 cflags_cc += [
432 "-Wno-abstract-vbase-init",
433 "-Wno-weak-vtables",
434 ]
435
436 # We are unlikely to want to fix these.
437 cflags += [
438 "-Wno-covered-switch-default",
439 "-Wno-deprecated",
Chris Dalton1ef80942017-12-04 12:01:30 -0700440 "-Wno-missing-noreturn",
441 "-Wno-old-style-cast",
442 "-Wno-padded",
Chris Daltond1ec4102017-12-04 13:31:21 -0700443 "-Wno-newline-eof",
Chris Dalton1ef80942017-12-04 12:01:30 -0700444 ]
445 cflags_cc += [
446 "-Wno-c++98-compat",
447 "-Wno-c++98-compat-pedantic",
448 "-Wno-undefined-func-template",
449 ]
450 cflags_objc += [
451 "-Wno-direct-ivar-access",
452 "-Wno-objc-interface-ivars",
453 ]
454 cflags_objcc += [
455 "-Wno-direct-ivar-access",
456 "-Wno-objcc-interface-ivars",
457 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400458 }
Mike Kleinee77da22018-02-22 15:36:24 -0500459 if (!is_win || is_clang) {
460 cflags += [ "-Wno-implicit-fallthrough" ]
461 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400462}
Mike Klein50500ad2016-11-16 12:13:44 -0500463config("warnings_except_public_headers") {
Chris Dalton1ef80942017-12-04 12:01:30 -0700464 if (!is_win || is_clang) {
Mike Klein50500ad2016-11-16 12:13:44 -0500465 cflags = [ "-Wno-unused-parameter" ]
466 }
467}
Mike Kleinc7165c22016-10-12 23:58:06 -0400468
Mike Klein121563e2016-10-04 17:09:13 -0400469config("extra_flags") {
Kevin Lubick2677a9a2017-03-28 15:45:41 -0400470 asmflags = extra_asmflags
Mike Klein121563e2016-10-04 17:09:13 -0400471 cflags = extra_cflags
472 cflags_c = extra_cflags_c
473 cflags_cc = extra_cflags_cc
474 ldflags = extra_ldflags
475}
476
mtkleinb9be9792016-09-16 14:44:18 -0700477config("debug_symbols") {
478 # It's annoying to wait for full debug symbols to push over
479 # to Android devices. -gline-tables-only is a lot slimmer.
480 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400481 cflags = [
482 "-gline-tables-only",
483 "-funwind-tables", # Helps make in-process backtraces fuller.
484 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400485 } else if (is_win) {
Mike Klein67a86d52017-12-15 07:34:27 -0500486 cflags = [ "/Z7" ]
Brian Osman7142ae52018-12-12 16:32:35 -0500487 if (is_clang) {
Eric Boren56bf8ce2019-02-07 13:05:06 -0500488 cflags += [ "-gcodeview-ghash" ]
Mike Kleincae020a2018-12-23 10:25:44 -0500489 ldflags = [ "/DEBUG:GHASH" ]
Brian Osman7142ae52018-12-12 16:32:35 -0500490 } else {
Mike Kleina6e0c2b2018-12-10 08:48:03 -0500491 ldflags = [ "/DEBUG:FASTLINK" ]
Brian Osman0ab56842018-09-13 15:46:02 -0400492 }
Mike Kleincc300a12016-10-12 16:25:27 -0400493 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700494 cflags = [ "-g" ]
495 }
496}
497
498config("no_rtti") {
499 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400500 if (is_win) {
501 cflags_cc = [ "/GR-" ]
502 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700503 cflags_cc = [ "-fno-rtti" ]
504 }
505 }
506}
507
Mike Klein7ea977b2018-09-19 13:44:43 -0400508config("optimize") {
Mike Kleincc300a12016-10-12 16:25:27 -0400509 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400510 cflags = [
511 "/O2",
512 "/Zc:inline",
513 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400514 ldflags = [
515 "/OPT:ICF",
516 "/OPT:REF",
517 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400518 } else {
Mike Klein13daa4f2019-06-20 10:08:55 -0500519 cflags = [ "-O3" ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500520 if (is_mac || is_ios) {
521 ldflags = [ "-dead_strip" ]
522 } else {
Mike Klein13daa4f2019-06-20 10:08:55 -0500523 cflags += [
524 "-fdata-sections",
525 "-ffunction-sections",
526 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500527 ldflags = [ "-Wl,--gc-sections" ]
528 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400529 if (target_cpu == "wasm") {
530 # The compiler asks us to add an optimization flag to both cflags
531 # and ldflags to cut down on the local variables,
532 # for performance reasons.
533 # The "linking" step is the conversion to javascript.
534 ldflags += [ "-O3" ]
535 }
herbb6318bf2016-09-16 13:29:57 -0700536 }
Mike Klein7ea977b2018-09-19 13:44:43 -0400537}
538
539config("NDEBUG") {
mtkleinb9be9792016-09-16 14:44:18 -0700540 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700541}
542
543config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500544 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400545 ldflags = [
546 "-pie",
547 "-rdynamic",
548 ]
Mike Kleinc5875fb2016-12-06 10:46:02 -0500549 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700550 ldflags = [ "-Wl,-rpath,@loader_path/." ]
551 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700552 ldflags = [
553 "-rdynamic",
554 "-Wl,-rpath,\$ORIGIN",
555 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500556 } else if (is_win) {
557 ldflags = [
558 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
559 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
560 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700561 }
562}