blob: 04e2f8f536d0dbd49722ba59520462ec4f6bf585 [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" ]
mtkleinb9be9792016-09-16 14:44:18 -0700229 }
Herb Derbyc65eb342019-10-18 14:29:09 -0400230
Mike Klein15f46c32017-12-07 12:48:57 -0500231 if (is_mac) {
Herb Derbyc65eb342019-10-18 14:29:09 -0400232 # If there was a xcode_sysroot set in args or calculated then use it, else don't set anything
233 # because the XCode cc/c++ already know all this stuff.
234 if (xcode_sysroot != "") {
235 asmflags += [
236 "-isysroot",
237 xcode_sysroot,
238 ]
239 cflags += [
240 "-isysroot",
241 xcode_sysroot,
242 ]
243 ldflags += [
244 "-isysroot",
245 xcode_sysroot,
246 ]
247 }
248
Mike Klein15f46c32017-12-07 12:48:57 -0500249 # Disable linker warnings. They're usually just annoyances like,
250 # ld: warning: text-based stub file
251 # /System/Library/Frameworks/foo.framework/foo.tbd and library file
252 # /System/Library/Frameworks/foo.framework/foo are out of sync.
253 # Falling back to library file for linking.
254 ldflags += [ "-Wl,-w" ]
255 }
mtkleinb9be9792016-09-16 14:44:18 -0700256
Brian Osman50ea3c02019-02-04 10:01:53 -0500257 if (sanitize != "" && sanitize != "MSVC") {
mtkleinb9be9792016-09-16 14:44:18 -0700258 # You can either pass the sanitizers directly, e.g. "address,undefined",
259 # or pass one of the couple common aliases used by the bots.
260 sanitizers = sanitize
Kevin Lubickd0950402018-03-20 10:10:58 -0400261
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500262 if (sanitize == "ASAN") {
Ben Wagner314d7c22018-01-03 11:04:30 -0500263 # ASAN implicitly runs all UBSAN checks also.
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500264 sanitizers = "undefined,address"
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500265
Mike Klein02046a72018-08-10 12:25:12 -0400266 if (is_android) {
267 # TODO(mtklein): work out UBSAN link errors
268 sanitizers = "address"
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500269 }
mtkleinb9be9792016-09-16 14:44:18 -0700270 } else if (sanitize == "TSAN") {
271 sanitizers = "thread"
272 } else if (sanitize == "MSAN") {
273 sanitizers = "memory"
274 }
275
Mike Klein475c5e92018-08-08 10:23:17 -0400276 _blacklist = rebase_path("../tools/xsan.blacklist")
277
mtkleinb9be9792016-09-16 14:44:18 -0700278 cflags += [
Mike Klein02046a72018-08-10 12:25:12 -0400279 "-fsanitize=$sanitizers",
mtkleinb9be9792016-09-16 14:44:18 -0700280 "-fno-sanitize-recover=$sanitizers",
Mike Klein475c5e92018-08-08 10:23:17 -0400281 "-fsanitize-blacklist=$_blacklist",
mtkleinb9be9792016-09-16 14:44:18 -0700282 ]
Mike Kleincdb0e8f2019-12-18 14:25:50 -0600283
Mike Klein94c4f412018-08-09 17:24:45 -0400284 if (is_win) {
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500285 cflags += [
286 "/FI$_blacklist",
287
288 # On Release builds, we get strange warnings about string literals.
289 "/GF-",
290 ]
291
292 assert(clang_win != "")
293 libs += [ "$clang_win/lib/clang/$clang_win_version/lib/windows/clang_rt.asan-x86_64.lib" ]
Mike Klein94c4f412018-08-09 17:24:45 -0400294 } else {
295 cflags += [
296 "-include$_blacklist",
297 "-fno-omit-frame-pointer",
298 ]
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500299
300 ldflags += [ "-fsanitize=$sanitizers" ]
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500301 }
Mike Klein94c4f412018-08-09 17:24:45 -0400302
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500303 if (is_linux) {
Kevin Lubick43bd2592018-02-15 09:03:44 -0500304 cflags_cc += [ "-stdlib=libc++" ]
305 ldflags += [ "-stdlib=libc++" ]
Kevin Lubick3cda39f2018-02-01 12:09:55 -0500306 }
Mike Klein02046a72018-08-10 12:25:12 -0400307
mtkleinb9be9792016-09-16 14:44:18 -0700308 if (sanitizers == "memory") {
309 cflags += [ "-fsanitize-memory-track-origins" ]
mtkleinb9be9792016-09-16 14:44:18 -0700310 }
Brian Salomon8283fa42019-11-07 10:42:41 -0500311 if (sanitizers == "safe-stack") {
312 cflags_cc += [ "-fno-aligned-allocation" ]
313 }
mtkleinb9be9792016-09-16 14:44:18 -0700314 }
315}
316
Mike Kleinc0c05222020-01-31 11:07:51 -0600317# See skia:9731.
318config("recover_pointer_overflow") {
319 cflags = [ "-fsanitize-recover=pointer-overflow" ]
320}
321
Mike Klein6e55fef2016-10-26 11:41:47 -0400322config("no_exceptions") {
Mike Klein228276d2017-08-16 13:20:20 +0000323 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
Mike Klein6e55fef2016-10-26 11:41:47 -0400324 if (!is_win) {
325 cflags_cc = [ "-fno-exceptions" ]
326 }
327}
328
Mike Kleinc7165c22016-10-12 23:58:06 -0400329config("warnings") {
330 cflags = []
331 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400332 cflags_objc = []
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400333 cflags_objcc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400334 if (is_win) {
335 cflags += [
336 "/W3", # Turn on lots of warnings.
337
338 # Disable a bunch of warnings:
339 "/wd4244", # conversion from 'float' to 'int', possible loss of data
340 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
Mike Kleina01c6b02020-04-01 13:47:34 -0500341 "/wd4800", # forcing value to bool 'true' or 'false' (performance
342 # warning)
Mike Kleinc7165c22016-10-12 23:58:06 -0400343
344 # Probably only triggers when /EHsc is enabled.
345 "/wd4291", # no matching operator delete found;
Mike Kleina01c6b02020-04-01 13:47:34 -0500346 # memory will not be freed if initialization throws an
347 # exception
Brian Osmaneec1e9e2019-04-10 16:22:15 -0400348
349 # These only show up in shared builds:
Mike Kleina01c6b02020-04-01 13:47:34 -0500350 "/wd4251", # class 'type' needs to have dll-interface to be used by
351 # clients of class 'type2'
352 "/wd4275", # non dll-interface class 'base' used as base for
353 # dll-interface class 'derived'
Brian Salomon8283fa42019-11-07 10:42:41 -0500354
355 # It'd be nice to fix these and turn this on:
Mike Kleina01c6b02020-04-01 13:47:34 -0500356 "/wd5041", # out-of-line definition for constexpr static data member is
357 # not needed and is deprecated in C++17
Mike Kleindc976a92020-04-30 06:45:25 -0500358
359 # warning C4996: 'std::result_of_t': warning STL4014: std::result_of and std::result_of_t are
360 # deprecated in C++17. They are superseded by std::invoke_result and std::invoke_result_t.
361 "/wd4996",
Mike Kleinc7165c22016-10-12 23:58:06 -0400362 ]
363 } else {
364 cflags += [
365 "-Wall",
366 "-Wextra",
367 "-Winit-self",
368 "-Wpointer-arith",
369 "-Wsign-compare",
370 "-Wvla",
371
372 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500373 "-Wno-maybe-uninitialized",
Mike Kleinc7165c22016-10-12 23:58:06 -0400374 ]
Ben Wagnerf8a131d2018-03-13 16:56:43 -0400375 cflags_cc += [
376 "-Wnon-virtual-dtor",
377 "-Wno-noexcept-type",
Ben Wagner7363af82020-03-27 14:29:38 -0400378 "-Wno-redundant-move", #TODO: gcc conflict with return-std-move-in-c++11
Ben Wagnerf8a131d2018-03-13 16:56:43 -0400379 ]
Chris Dalton1ef80942017-12-04 12:01:30 -0700380 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400381
Chris Dalton1ef80942017-12-04 12:01:30 -0700382 if (is_clang) {
383 cflags += [
Mike Kleinb7b2da82019-02-28 08:47:44 -0600384 "-fcolor-diagnostics",
Chris Dalton1ef80942017-12-04 12:01:30 -0700385 "-Weverything",
Mike Kleina01c6b02020-04-01 13:47:34 -0500386 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs'
387 # warnings.
Chris Dalton1ef80942017-12-04 12:01:30 -0700388 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400389
Chris Dalton1ef80942017-12-04 12:01:30 -0700390 if (target_cpu == "arm" && is_ios) {
391 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS.
392 # We're pretty sure it's actually 8-byte alignment.
393 cflags += [ "-Wno-over-aligned" ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400394 }
Mike Klein04282792018-01-08 18:23:32 -0500395 if (target_cpu == "x86" && is_android) {
396 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds.
397 # We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info.
398 cflags += [ "-Wno-over-aligned" ]
399 }
Chris Dalton1ef80942017-12-04 12:01:30 -0700400
401 # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose
402 # their case during copy, causing case-sensitivity mismatch on remote machines.
403 cflags += [
404 "-Wno-nonportable-include-path",
405 "-Wno-nonportable-system-include-path",
406 ]
407
408 # TODO: These would all be really great warnings to turn on.
409 cflags += [
410 "-Wno-cast-align",
411 "-Wno-cast-qual",
Chris Dalton1ef80942017-12-04 12:01:30 -0700412 "-Wno-conversion",
413 "-Wno-disabled-macro-expansion",
414 "-Wno-documentation",
415 "-Wno-documentation-unknown-command",
416 "-Wno-double-promotion",
417 "-Wno-exit-time-destructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700418 "-Wno-float-equal",
419 "-Wno-format-nonliteral",
420 "-Wno-global-constructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700421 "-Wno-missing-prototypes",
422 "-Wno-missing-variable-declarations",
423 "-Wno-pedantic",
424 "-Wno-reserved-id-macro",
425 "-Wno-shadow",
426 "-Wno-shift-sign-overflow",
Chris Dalton1ef80942017-12-04 12:01:30 -0700427 "-Wno-signed-enum-bitfield",
428 "-Wno-switch-enum",
429 "-Wno-undef",
430 "-Wno-unreachable-code",
431 "-Wno-unreachable-code-break",
432 "-Wno-unreachable-code-return",
433 "-Wno-unused-macros",
434 "-Wno-unused-member-function",
435 "-Wno-unused-template",
436 "-Wno-zero-as-null-pointer-constant",
Herb Derbya1b7be62019-05-09 16:59:18 -0400437 "-Wno-thread-safety-negative",
Chris Dalton1ef80942017-12-04 12:01:30 -0700438 ]
439 cflags_cc += [
440 "-Wno-abstract-vbase-init",
441 "-Wno-weak-vtables",
442 ]
443
444 # We are unlikely to want to fix these.
445 cflags += [
446 "-Wno-covered-switch-default",
447 "-Wno-deprecated",
Chris Dalton1ef80942017-12-04 12:01:30 -0700448 "-Wno-missing-noreturn",
449 "-Wno-old-style-cast",
450 "-Wno-padded",
Chris Daltond1ec4102017-12-04 13:31:21 -0700451 "-Wno-newline-eof",
Chris Dalton1ef80942017-12-04 12:01:30 -0700452 ]
453 cflags_cc += [
454 "-Wno-c++98-compat",
455 "-Wno-c++98-compat-pedantic",
456 "-Wno-undefined-func-template",
457 ]
458 cflags_objc += [
459 "-Wno-direct-ivar-access",
460 "-Wno-objc-interface-ivars",
461 ]
462 cflags_objcc += [
463 "-Wno-direct-ivar-access",
464 "-Wno-objcc-interface-ivars",
465 ]
Ben Wagner833313b2020-03-23 17:22:24 -0400466
467 # Wno-deprecated turns off the whole group, but also has its own warnings like
468 # out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated [-Werror,-Wdeprecated]
469 # but we would like others. Created from clang/include/clang/Basic/DiagnosticGroups.td
470 cflags += [
471 "-Wdeprecated-anon-enum-enum-conversion",
472 "-Wdeprecated-array-compare",
473 "-Wdeprecated-attributes",
474 "-Wdeprecated-comma-subscript",
475 "-Wdeprecated-copy",
Ben Wagner7345d882020-03-27 11:28:03 -0400476
Ben Wagner507e4862020-03-31 22:31:46 +0000477 #"-Wdeprecated-copy-dtor",
Ben Wagner833313b2020-03-23 17:22:24 -0400478 #"-Wdeprecated-declarations",
479 "-Wdeprecated-dynamic-exception-spec",
480 "-Wdeprecated-enum-compare",
481 "-Wdeprecated-enum-compare-conditional",
482 "-Wdeprecated-enum-enum-conversion",
483 "-Wdeprecated-enum-float-conversion",
484 "-Wdeprecated-increment-bool",
485 "-Wdeprecated-register",
486 "-Wdeprecated-this-capture",
487 "-Wdeprecated-volatile",
488 "-Wdeprecated-writable-str",
489 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400490 }
Mike Kleinee77da22018-02-22 15:36:24 -0500491 if (!is_win || is_clang) {
492 cflags += [ "-Wno-implicit-fallthrough" ]
493 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400494}
Mike Klein50500ad2016-11-16 12:13:44 -0500495config("warnings_except_public_headers") {
Chris Dalton1ef80942017-12-04 12:01:30 -0700496 if (!is_win || is_clang) {
Mike Klein50500ad2016-11-16 12:13:44 -0500497 cflags = [ "-Wno-unused-parameter" ]
498 }
499}
Mike Kleinc7165c22016-10-12 23:58:06 -0400500
Mike Klein121563e2016-10-04 17:09:13 -0400501config("extra_flags") {
Kevin Lubick2677a9a2017-03-28 15:45:41 -0400502 asmflags = extra_asmflags
Mike Klein121563e2016-10-04 17:09:13 -0400503 cflags = extra_cflags
504 cflags_c = extra_cflags_c
505 cflags_cc = extra_cflags_cc
506 ldflags = extra_ldflags
507}
508
mtkleinb9be9792016-09-16 14:44:18 -0700509config("debug_symbols") {
510 # It's annoying to wait for full debug symbols to push over
511 # to Android devices. -gline-tables-only is a lot slimmer.
512 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400513 cflags = [
514 "-gline-tables-only",
515 "-funwind-tables", # Helps make in-process backtraces fuller.
516 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400517 } else if (is_win) {
Mike Klein67a86d52017-12-15 07:34:27 -0500518 cflags = [ "/Z7" ]
Brian Osman7142ae52018-12-12 16:32:35 -0500519 if (is_clang) {
Eric Boren56bf8ce2019-02-07 13:05:06 -0500520 cflags += [ "-gcodeview-ghash" ]
Mike Kleincae020a2018-12-23 10:25:44 -0500521 ldflags = [ "/DEBUG:GHASH" ]
Brian Osman7142ae52018-12-12 16:32:35 -0500522 } else {
Mike Kleina6e0c2b2018-12-10 08:48:03 -0500523 ldflags = [ "/DEBUG:FASTLINK" ]
Brian Osman0ab56842018-09-13 15:46:02 -0400524 }
Mike Kleincc300a12016-10-12 16:25:27 -0400525 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700526 cflags = [ "-g" ]
527 }
528}
529
530config("no_rtti") {
531 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400532 if (is_win) {
533 cflags_cc = [ "/GR-" ]
534 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700535 cflags_cc = [ "-fno-rtti" ]
536 }
537 }
538}
539
Mike Klein7ea977b2018-09-19 13:44:43 -0400540config("optimize") {
Mike Kleincc300a12016-10-12 16:25:27 -0400541 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400542 cflags = [
543 "/O2",
544 "/Zc:inline",
545 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400546 ldflags = [
547 "/OPT:ICF",
548 "/OPT:REF",
549 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400550 } else {
Mike Klein13daa4f2019-06-20 10:08:55 -0500551 cflags = [ "-O3" ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500552 if (is_mac || is_ios) {
553 ldflags = [ "-dead_strip" ]
554 } else {
Mike Klein13daa4f2019-06-20 10:08:55 -0500555 cflags += [
556 "-fdata-sections",
557 "-ffunction-sections",
558 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500559 ldflags = [ "-Wl,--gc-sections" ]
560 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400561 if (target_cpu == "wasm") {
562 # The compiler asks us to add an optimization flag to both cflags
563 # and ldflags to cut down on the local variables,
564 # for performance reasons.
565 # The "linking" step is the conversion to javascript.
566 ldflags += [ "-O3" ]
567 }
herbb6318bf2016-09-16 13:29:57 -0700568 }
Mike Klein7ea977b2018-09-19 13:44:43 -0400569}
570
571config("NDEBUG") {
mtkleinb9be9792016-09-16 14:44:18 -0700572 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700573}
574
575config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500576 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400577 ldflags = [
578 "-pie",
579 "-rdynamic",
580 ]
Mike Kleinc5875fb2016-12-06 10:46:02 -0500581 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700582 ldflags = [ "-Wl,-rpath,@loader_path/." ]
583 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700584 ldflags = [
585 "-rdynamic",
586 "-Wl,-rpath,\$ORIGIN",
587 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500588 } else if (is_win) {
589 ldflags = [
590 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
Mike Kleina01c6b02020-04-01 13:47:34 -0500591 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link
592 # by never trying to.
Mike Klein4b6b5032016-11-06 11:54:19 -0500593 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700594 }
595}