blob: a003a2ad373d5c4889095ac6b9cf4b97d720ade0 [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 = ""
Mike Klein29cb9f92020-06-19 16:25:12 -050018 werror = false
Herb Derbyc65eb342019-10-18 14:29:09 -040019 xcode_sysroot = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070020}
Mike Klein82364ba2016-10-24 16:49:15 -040021
Herb Derbyc65eb342019-10-18 14:29:09 -040022if (is_ios && xcode_sysroot == "") {
Matthew Leibowitz3150ec62017-03-14 16:22:32 -040023 if (is_tvos) {
24 sdk = "appletvos"
25 if (target_cpu == "x86" || target_cpu == "x64") {
26 sdk = "appletvsimulator"
27 }
28 } else {
29 sdk = "iphoneos"
30 if (target_cpu == "x86" || target_cpu == "x64") {
31 sdk = "iphonesimulator"
32 }
Mike Klein7a5e0f32017-03-13 09:25:33 -070033 }
Herb Derbyc65eb342019-10-18 14:29:09 -040034 xcode_sysroot = exec_script("find_xcode_sysroot.py", [ sdk ], "trim string")
35}
36
37# If building for mac on a mac then lookup all the system includes so that goma and the clang
38# shipped with chrome can find them. When the gn_to_bp.py tool is run, then the host_os != mac.
39# In this case leave the xcode_sysroot empty, and the cc/c++ that come with XCode will be able to
40# find needed include paths.
41if (is_mac && host_os == "mac" && xcode_sysroot == "") {
42 xcode_sysroot =
43 exec_script("find_xcode_sysroot.py", [ "macosx" ], "trim string")
Mike Klein7d302882016-11-03 14:06:31 -040044}
45
mtkleinb9be9792016-09-16 14:44:18 -070046config("default") {
47 asmflags = []
48 cflags = []
49 cflags_c = []
50 cflags_cc = []
51 defines = []
52 ldflags = []
Herb Derby76073c12016-12-08 19:00:40 -050053 libs = []
mtkleinb9be9792016-09-16 14:44:18 -070054
Mike Kleinba201ae2019-04-23 07:38:07 -050055 if (werror) {
56 if (is_win) {
57 cflags += [ "/WX" ]
58 } else {
59 cflags += [ "-Werror" ]
60 }
61 }
62
Mike Klein28abea52020-02-19 09:17:51 -060063 # Disable warnings about unknown attributes.
64 # (These unknown attribute warnings are on by default, so we don't make
65 # disabling them part of :warnings, as some targets remove :warnings.)
66 if (is_win && !is_clang) {
67 cflags += [ "/wd5030" ]
68 } else {
69 cflags += [ "-Wno-attributes" ]
70 }
71
John Rosasco24cbdab2019-09-25 14:14:35 -070072 if (is_fuchsia && using_fuchsia_sdk) {
Robert Phillipsc919f972019-11-18 11:01:05 -050073 ldflags += [
74 "-v",
75 "--sysroot=" + rebase_path("$fuchsia_sdk_path/arch/$target_cpu/sysroot"),
76 ]
77 cflags += [ "--sysroot=" +
78 rebase_path("$fuchsia_sdk_path/arch/$target_cpu/sysroot") ]
John Rosasco24cbdab2019-09-25 14:14:35 -070079 if (target_cpu == "x64") {
80 target_triple = "--target=x86_64-${target_os}"
81 } else if (target_cpu == "arm64") {
82 target_triple = "--target=aarch64-unknown-${target_os}"
83 } else {
84 print("Unknown target CPU for Fuchsia target build.")
85 assert(false)
86 }
87 ldflags += [ target_triple ]
88 cflags += [ target_triple ]
89 asmflags += [ target_triple ]
90 }
91
mtkleinb9be9792016-09-16 14:44:18 -070092 if (is_win) {
Mike Kleinda8a6e12019-04-17 08:18:10 -050093 if (is_clang && target_cpu == "arm64") {
94 cflags += [ "--target=arm64-windows" ]
95 }
mtkleinb9be9792016-09-16 14:44:18 -070096 cflags += [
herbb6318bf2016-09-16 13:29:57 -070097 "/bigobj", # Some of our files are bigger than the regular limits.
Ben Wagnere6b274e2017-01-03 17:09:59 -050098 "/utf-8", # Set Source and Executable character sets to UTF-8.
herbb6318bf2016-09-16 13:29:57 -070099 ]
Brian Salomon8283fa42019-11-07 10:42:41 -0500100 cflags_cc += [ "/std:c++17" ]
mtkleinb9be9792016-09-16 14:44:18 -0700101 defines += [
Mike Kleinc7165c22016-10-12 23:58:06 -0400102 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
103 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
mtkleinb9be9792016-09-16 14:44:18 -0700104 "WIN32_LEAN_AND_MEAN",
105 "NOMINMAX",
herbb6318bf2016-09-16 13:29:57 -0700106 ]
Mike Klein98adfa82017-07-31 15:46:47 -0400107
Hal Canaryf72728e2019-07-10 11:24:52 -0400108 _include_dirs = [
109 "$win_vc/Tools/MSVC/$win_toolchain_version/include",
Brian Osman5f872622017-12-06 15:21:44 -0500110 "$win_sdk/Include/$win_sdk_version/shared",
111 "$win_sdk/Include/$win_sdk_version/ucrt",
112 "$win_sdk/Include/$win_sdk_version/um",
113 "$win_sdk/Include/$win_sdk_version/winrt",
114 ]
115
Mike Klein98adfa82017-07-31 15:46:47 -0400116 if (is_clang) {
117 foreach(dir, _include_dirs) {
118 cflags += [
119 "-imsvc",
120 dir,
121 ]
122 }
123 } else {
124 include_dirs = _include_dirs
125 }
126
Brian Osman5f872622017-12-06 15:21:44 -0500127 lib_dirs = [
128 "$win_sdk/Lib/$win_sdk_version/ucrt/$target_cpu",
129 "$win_sdk/Lib/$win_sdk_version/um/$target_cpu",
Hal Canaryf72728e2019-07-10 11:24:52 -0400130 "$win_vc/Tools/MSVC/$win_toolchain_version/lib/$target_cpu",
Brian Osman5f872622017-12-06 15:21:44 -0500131 ]
mtkleinb9be9792016-09-16 14:44:18 -0700132 } else {
Shachar Langbeheim07c4e1d2019-12-16 10:46:52 +0200133 cflags += [
134 "-fstrict-aliasing",
135 "-fPIC",
Mike Kleined800352020-08-04 12:06:23 -0500136 "-fvisibility=hidden",
Shachar Langbeheim07c4e1d2019-12-16 10:46:52 +0200137 ]
Mike Kleined800352020-08-04 12:06:23 -0500138 cflags_cc += [
139 "-std=c++17",
140 "-fvisibility-inlines-hidden",
141 ]
mtkleinb9be9792016-09-16 14:44:18 -0700142 }
herbb6318bf2016-09-16 13:29:57 -0700143
mtkleinb9be9792016-09-16 14:44:18 -0700144 if (current_cpu == "arm") {
145 cflags += [
146 "-march=armv7-a",
147 "-mfpu=neon",
148 "-mthumb",
149 ]
Mike Klein4d4b3aa2018-03-21 13:07:35 -0400150 } else if (current_cpu == "x86" && !is_win) {
mtkleinb9be9792016-09-16 14:44:18 -0700151 asmflags += [ "-m32" ]
152 cflags += [
153 "-m32",
154 "-msse2",
155 "-mfpmath=sse",
156 ]
157 ldflags += [ "-m32" ]
158 }
herbb6318bf2016-09-16 13:29:57 -0700159
Herb Derby76073c12016-12-08 19:00:40 -0500160 if (malloc != "" && !is_win) {
161 cflags += [
162 "-fno-builtin-malloc",
163 "-fno-builtin-calloc",
164 "-fno-builtin-realloc",
165 "-fno-builtin-free",
166 ]
167 libs += [ malloc ]
168 }
169
Hal Canarya0834042018-06-01 20:22:25 +0000170 if (is_android) {
Mike Klein5b52c522019-07-03 10:44:21 -0500171 cflags += [ "--sysroot=$ndk/sysroot" ]
Mike Klein2e096932020-10-06 10:12:11 -0500172 cflags_cc += [
173 "-isystem$ndk/sources/cxx-stl/llvm-libc++/include",
174 "-isystem$ndk/sources/cxx-stl/llvm-libc++abi/include",
175 ]
Mike Klein5b52c522019-07-03 10:44:21 -0500176 ldflags += [ "-static-libstdc++" ]
mtklein2b3c2a32016-09-08 08:39:34 -0700177 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700178
Mike Klein7d302882016-11-03 14:06:31 -0400179 if (is_ios) {
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500180 if (target_cpu == "arm") {
Mike Kleina1397882020-08-25 10:03:03 -0500181 _arch_flags = [
182 "-arch",
183 "armv7",
184 ]
185 } else if (target_cpu == "arm64") {
186 _arch_flags = [
187 "-arch",
188 "arm64",
189 "-arch",
190 "arm64e",
191 ]
Mike Klein7a5e0f32017-03-13 09:25:33 -0700192 } else if (target_cpu == "x86") {
Mike Kleina1397882020-08-25 10:03:03 -0500193 _arch_flags = [
194 "-arch",
195 "i386",
196 ]
Mike Klein7a5e0f32017-03-13 09:25:33 -0700197 } else if (target_cpu == "x64") {
Mike Kleina1397882020-08-25 10:03:03 -0500198 _arch_flags = [
199 "-arch",
200 "x86_64",
201 ]
202 } else {
203 _arch_flags = [
204 "-arch",
205 target_cpu,
206 ]
Mike Kleinb48fd3c2017-01-23 11:58:53 -0500207 }
Mike Kleina1397882020-08-25 10:03:03 -0500208
Mike Klein4fe2b152017-02-17 15:36:01 -0500209 asmflags += [
Mike Kleina1397882020-08-25 10:03:03 -0500210 "-isysroot",
211 xcode_sysroot,
212 ] + _arch_flags
Mike Klein7d302882016-11-03 14:06:31 -0400213 cflags += [
Mike Kleina1397882020-08-25 10:03:03 -0500214 "-isysroot",
215 xcode_sysroot,
216 ] + _arch_flags
Brian Salomon8283fa42019-11-07 10:42:41 -0500217 cflags_cc += [
218 "-stdlib=libc++",
219 "-fno-aligned-allocation",
220 ]
Mike Klein7d302882016-11-03 14:06:31 -0400221 ldflags += [
Mike Kleina1397882020-08-25 10:03:03 -0500222 "-isysroot",
223 xcode_sysroot,
224 "-stdlib=libc++",
225 ] + _arch_flags
Herb Derby76073c12016-12-08 19:00:40 -0500226 libs += [ "objc" ]
Mike Klein7d302882016-11-03 14:06:31 -0400227 }
228
mtkleinb9be9792016-09-16 14:44:18 -0700229 if (is_linux) {
Herb Derby76073c12016-12-08 19:00:40 -0500230 libs += [ "pthread" ]
mtkleinb9be9792016-09-16 14:44:18 -0700231 }
Herb Derbyc65eb342019-10-18 14:29:09 -0400232
Mike Klein15f46c32017-12-07 12:48:57 -0500233 if (is_mac) {
Herb Derbyc65eb342019-10-18 14:29:09 -0400234 # If there was a xcode_sysroot set in args or calculated then use it, else don't set anything
235 # because the XCode cc/c++ already know all this stuff.
236 if (xcode_sysroot != "") {
237 asmflags += [
238 "-isysroot",
239 xcode_sysroot,
240 ]
241 cflags += [
242 "-isysroot",
243 xcode_sysroot,
244 ]
245 ldflags += [
246 "-isysroot",
247 xcode_sysroot,
248 ]
249 }
250
Mike Klein15f46c32017-12-07 12:48:57 -0500251 # Disable linker warnings. They're usually just annoyances like,
252 # ld: warning: text-based stub file
253 # /System/Library/Frameworks/foo.framework/foo.tbd and library file
254 # /System/Library/Frameworks/foo.framework/foo are out of sync.
255 # Falling back to library file for linking.
256 ldflags += [ "-Wl,-w" ]
Herb Derby7e581792020-10-20 12:35:51 -0400257
258 # As of 11/2020, gn is an x86 binary and defaults the host_cpu to x86_64.
259 # This allows you to build arm64 mac binaries by setting target_cpu = "arm64"
260 if (current_cpu == "arm64") {
261 asmflags += [
262 "-target",
263 "arm64-apple-macos11",
264 ]
265 cflags += [
266 "-target",
267 "arm64-apple-macos11",
268 ]
269 ldflags += [
270 "-target",
271 "arm64-apple-macos11",
272 ]
273 }
Mike Klein15f46c32017-12-07 12:48:57 -0500274 }
mtkleinb9be9792016-09-16 14:44:18 -0700275
Brian Osman50ea3c02019-02-04 10:01:53 -0500276 if (sanitize != "" && sanitize != "MSVC") {
mtkleinb9be9792016-09-16 14:44:18 -0700277 # You can either pass the sanitizers directly, e.g. "address,undefined",
278 # or pass one of the couple common aliases used by the bots.
279 sanitizers = sanitize
Kevin Lubickd0950402018-03-20 10:10:58 -0400280
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500281 if (sanitize == "ASAN") {
Ben Wagner314d7c22018-01-03 11:04:30 -0500282 # ASAN implicitly runs all UBSAN checks also.
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500283 sanitizers = "undefined,address"
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500284
Mike Klein02046a72018-08-10 12:25:12 -0400285 if (is_android) {
286 # TODO(mtklein): work out UBSAN link errors
287 sanitizers = "address"
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500288 }
mtkleinb9be9792016-09-16 14:44:18 -0700289 } else if (sanitize == "TSAN") {
290 sanitizers = "thread"
291 } else if (sanitize == "MSAN") {
292 sanitizers = "memory"
293 }
294
Mike Kleind26b3e22020-07-24 12:16:50 -0500295 _suppressions = rebase_path("../tools/xsan.supp")
Mike Klein475c5e92018-08-08 10:23:17 -0400296
mtkleinb9be9792016-09-16 14:44:18 -0700297 cflags += [
Mike Klein02046a72018-08-10 12:25:12 -0400298 "-fsanitize=$sanitizers",
mtkleinb9be9792016-09-16 14:44:18 -0700299 "-fno-sanitize-recover=$sanitizers",
Mike Kleind26b3e22020-07-24 12:16:50 -0500300 "-fsanitize-blacklist=$_suppressions",
mtkleinb9be9792016-09-16 14:44:18 -0700301 ]
Mike Kleincdb0e8f2019-12-18 14:25:50 -0600302
Mike Klein94c4f412018-08-09 17:24:45 -0400303 if (is_win) {
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500304 cflags += [
Mike Kleind26b3e22020-07-24 12:16:50 -0500305 "/FI$_suppressions",
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500306
307 # On Release builds, we get strange warnings about string literals.
308 "/GF-",
309 ]
310
311 assert(clang_win != "")
312 libs += [ "$clang_win/lib/clang/$clang_win_version/lib/windows/clang_rt.asan-x86_64.lib" ]
Mike Klein94c4f412018-08-09 17:24:45 -0400313 } else {
314 cflags += [
Mike Kleind26b3e22020-07-24 12:16:50 -0500315 "-include$_suppressions",
Mike Klein94c4f412018-08-09 17:24:45 -0400316 "-fno-omit-frame-pointer",
317 ]
Ben Wagnerb6f98ea2019-12-21 00:53:11 -0500318
319 ldflags += [ "-fsanitize=$sanitizers" ]
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500320 }
Mike Klein94c4f412018-08-09 17:24:45 -0400321
Kevin Lubick5798c9f2018-02-15 09:45:58 -0500322 if (is_linux) {
Kevin Lubick43bd2592018-02-15 09:03:44 -0500323 cflags_cc += [ "-stdlib=libc++" ]
324 ldflags += [ "-stdlib=libc++" ]
Kevin Lubick3cda39f2018-02-01 12:09:55 -0500325 }
Mike Klein02046a72018-08-10 12:25:12 -0400326
mtkleinb9be9792016-09-16 14:44:18 -0700327 if (sanitizers == "memory") {
328 cflags += [ "-fsanitize-memory-track-origins" ]
mtkleinb9be9792016-09-16 14:44:18 -0700329 }
Brian Salomon8283fa42019-11-07 10:42:41 -0500330 if (sanitizers == "safe-stack") {
331 cflags_cc += [ "-fno-aligned-allocation" ]
332 }
mtkleinb9be9792016-09-16 14:44:18 -0700333 }
334}
335
Mike Kleinc0c05222020-01-31 11:07:51 -0600336# See skia:9731.
337config("recover_pointer_overflow") {
338 cflags = [ "-fsanitize-recover=pointer-overflow" ]
339}
340
Mike Klein6e55fef2016-10-26 11:41:47 -0400341config("no_exceptions") {
Mike Klein228276d2017-08-16 13:20:20 +0000342 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
Mike Klein6e55fef2016-10-26 11:41:47 -0400343 if (!is_win) {
344 cflags_cc = [ "-fno-exceptions" ]
345 }
346}
347
Mike Kleinc7165c22016-10-12 23:58:06 -0400348config("warnings") {
349 cflags = []
350 cflags_cc = []
Mike Klein43c25262016-10-20 10:17:47 -0400351 cflags_objc = []
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400352 cflags_objcc = []
Mike Kleinc7165c22016-10-12 23:58:06 -0400353 if (is_win) {
354 cflags += [
355 "/W3", # Turn on lots of warnings.
356
357 # Disable a bunch of warnings:
358 "/wd4244", # conversion from 'float' to 'int', possible loss of data
359 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
Mike Kleina01c6b02020-04-01 13:47:34 -0500360 "/wd4800", # forcing value to bool 'true' or 'false' (performance
361 # warning)
Mike Kleinc7165c22016-10-12 23:58:06 -0400362
363 # Probably only triggers when /EHsc is enabled.
364 "/wd4291", # no matching operator delete found;
Mike Kleina01c6b02020-04-01 13:47:34 -0500365 # memory will not be freed if initialization throws an
366 # exception
Brian Osmaneec1e9e2019-04-10 16:22:15 -0400367
368 # These only show up in shared builds:
Mike Kleina01c6b02020-04-01 13:47:34 -0500369 "/wd4251", # class 'type' needs to have dll-interface to be used by
370 # clients of class 'type2'
371 "/wd4275", # non dll-interface class 'base' used as base for
372 # dll-interface class 'derived'
Brian Salomon8283fa42019-11-07 10:42:41 -0500373
374 # It'd be nice to fix these and turn this on:
Mike Kleina01c6b02020-04-01 13:47:34 -0500375 "/wd5041", # out-of-line definition for constexpr static data member is
376 # not needed and is deprecated in C++17
Mike Kleindc976a92020-04-30 06:45:25 -0500377
378 # warning C4996: 'std::result_of_t': warning STL4014: std::result_of and std::result_of_t are
379 # deprecated in C++17. They are superseded by std::invoke_result and std::invoke_result_t.
380 "/wd4996",
Mike Kleinc7165c22016-10-12 23:58:06 -0400381 ]
382 } else {
383 cflags += [
384 "-Wall",
385 "-Wextra",
386 "-Winit-self",
387 "-Wpointer-arith",
388 "-Wsign-compare",
389 "-Wvla",
390
391 "-Wno-deprecated-declarations",
Mike Kleindb402ca2016-12-13 12:46:05 -0500392 "-Wno-maybe-uninitialized",
Mike Klein90b027a2020-09-02 09:09:11 -0500393 "-Wno-psabi",
Mike Kleinc7165c22016-10-12 23:58:06 -0400394 ]
Ben Wagnerf8a131d2018-03-13 16:56:43 -0400395 cflags_cc += [
396 "-Wnon-virtual-dtor",
397 "-Wno-noexcept-type",
Ben Wagner7363af82020-03-27 14:29:38 -0400398 "-Wno-redundant-move", #TODO: gcc conflict with return-std-move-in-c++11
Ben Wagnerf8a131d2018-03-13 16:56:43 -0400399 ]
Chris Dalton1ef80942017-12-04 12:01:30 -0700400 }
Mike Kleinc7165c22016-10-12 23:58:06 -0400401
Chris Dalton1ef80942017-12-04 12:01:30 -0700402 if (is_clang) {
403 cflags += [
Mike Kleinb7b2da82019-02-28 08:47:44 -0600404 "-fcolor-diagnostics",
Chris Dalton1ef80942017-12-04 12:01:30 -0700405 "-Weverything",
Mike Kleina01c6b02020-04-01 13:47:34 -0500406 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs'
407 # warnings.
Chris Dalton1ef80942017-12-04 12:01:30 -0700408 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400409
Chris Dalton1ef80942017-12-04 12:01:30 -0700410 if (target_cpu == "arm" && is_ios) {
411 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS.
412 # We're pretty sure it's actually 8-byte alignment.
413 cflags += [ "-Wno-over-aligned" ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400414 }
Mike Klein04282792018-01-08 18:23:32 -0500415 if (target_cpu == "x86" && is_android) {
416 # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds.
417 # We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info.
418 cflags += [ "-Wno-over-aligned" ]
419 }
Chris Dalton1ef80942017-12-04 12:01:30 -0700420
421 # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose
422 # their case during copy, causing case-sensitivity mismatch on remote machines.
423 cflags += [
424 "-Wno-nonportable-include-path",
425 "-Wno-nonportable-system-include-path",
426 ]
427
428 # TODO: These would all be really great warnings to turn on.
429 cflags += [
430 "-Wno-cast-align",
431 "-Wno-cast-qual",
Chris Dalton1ef80942017-12-04 12:01:30 -0700432 "-Wno-conversion",
433 "-Wno-disabled-macro-expansion",
434 "-Wno-documentation",
435 "-Wno-documentation-unknown-command",
436 "-Wno-double-promotion",
437 "-Wno-exit-time-destructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700438 "-Wno-float-equal",
439 "-Wno-format-nonliteral",
440 "-Wno-global-constructors", # TODO: OK outside libskia
Chris Dalton1ef80942017-12-04 12:01:30 -0700441 "-Wno-missing-prototypes",
442 "-Wno-missing-variable-declarations",
443 "-Wno-pedantic",
444 "-Wno-reserved-id-macro",
445 "-Wno-shadow",
446 "-Wno-shift-sign-overflow",
Chris Dalton1ef80942017-12-04 12:01:30 -0700447 "-Wno-signed-enum-bitfield",
448 "-Wno-switch-enum",
449 "-Wno-undef",
450 "-Wno-unreachable-code",
451 "-Wno-unreachable-code-break",
452 "-Wno-unreachable-code-return",
453 "-Wno-unused-macros",
454 "-Wno-unused-member-function",
455 "-Wno-unused-template",
456 "-Wno-zero-as-null-pointer-constant",
Herb Derbya1b7be62019-05-09 16:59:18 -0400457 "-Wno-thread-safety-negative",
Mike Kleinfdd542f2020-06-02 11:41:55 -0500458 "-Wno-non-c-typedef-for-linkage", # Dawn, not Skia per se.
Chris Dalton1ef80942017-12-04 12:01:30 -0700459 ]
460 cflags_cc += [
461 "-Wno-abstract-vbase-init",
462 "-Wno-weak-vtables",
463 ]
464
Mike Klein89c909e2020-06-01 15:50:19 -0500465 # Turn back on after -Wno-conversion.
466 # This only affects public headers... see :warnings_except_public_headers.
467 cflags += [ "-Wsign-conversion" ]
468
Chris Dalton1ef80942017-12-04 12:01:30 -0700469 # We are unlikely to want to fix these.
470 cflags += [
471 "-Wno-covered-switch-default",
472 "-Wno-deprecated",
Chris Dalton1ef80942017-12-04 12:01:30 -0700473 "-Wno-missing-noreturn",
474 "-Wno-old-style-cast",
475 "-Wno-padded",
Chris Daltond1ec4102017-12-04 13:31:21 -0700476 "-Wno-newline-eof",
Chris Dalton1ef80942017-12-04 12:01:30 -0700477 ]
478 cflags_cc += [
479 "-Wno-c++98-compat",
480 "-Wno-c++98-compat-pedantic",
481 "-Wno-undefined-func-template",
482 ]
483 cflags_objc += [
484 "-Wno-direct-ivar-access",
485 "-Wno-objc-interface-ivars",
486 ]
487 cflags_objcc += [
488 "-Wno-direct-ivar-access",
489 "-Wno-objcc-interface-ivars",
490 ]
Ben Wagner833313b2020-03-23 17:22:24 -0400491
492 # Wno-deprecated turns off the whole group, but also has its own warnings like
493 # out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated [-Werror,-Wdeprecated]
494 # but we would like others. Created from clang/include/clang/Basic/DiagnosticGroups.td
495 cflags += [
496 "-Wdeprecated-anon-enum-enum-conversion",
497 "-Wdeprecated-array-compare",
498 "-Wdeprecated-attributes",
499 "-Wdeprecated-comma-subscript",
500 "-Wdeprecated-copy",
Ben Wagner7345d882020-03-27 11:28:03 -0400501
Ben Wagner507e4862020-03-31 22:31:46 +0000502 #"-Wdeprecated-copy-dtor",
Ben Wagner833313b2020-03-23 17:22:24 -0400503 #"-Wdeprecated-declarations",
504 "-Wdeprecated-dynamic-exception-spec",
505 "-Wdeprecated-enum-compare",
506 "-Wdeprecated-enum-compare-conditional",
507 "-Wdeprecated-enum-enum-conversion",
508 "-Wdeprecated-enum-float-conversion",
509 "-Wdeprecated-increment-bool",
510 "-Wdeprecated-register",
511 "-Wdeprecated-this-capture",
512 "-Wdeprecated-volatile",
513 "-Wdeprecated-writable-str",
514 ]
Mike Kleinc7165c22016-10-12 23:58:06 -0400515 }
516}
Mike Klein50500ad2016-11-16 12:13:44 -0500517config("warnings_except_public_headers") {
Chris Dalton1ef80942017-12-04 12:01:30 -0700518 if (!is_win || is_clang) {
Mike Klein89c909e2020-06-01 15:50:19 -0500519 cflags = [
520 "-Wno-sign-conversion",
521 "-Wno-unused-parameter",
522 ]
Mike Klein50500ad2016-11-16 12:13:44 -0500523 }
524}
Mike Kleinc7165c22016-10-12 23:58:06 -0400525
Mike Klein121563e2016-10-04 17:09:13 -0400526config("extra_flags") {
Kevin Lubick2677a9a2017-03-28 15:45:41 -0400527 asmflags = extra_asmflags
Mike Klein121563e2016-10-04 17:09:13 -0400528 cflags = extra_cflags
529 cflags_c = extra_cflags_c
530 cflags_cc = extra_cflags_cc
531 ldflags = extra_ldflags
532}
533
mtkleinb9be9792016-09-16 14:44:18 -0700534config("debug_symbols") {
535 # It's annoying to wait for full debug symbols to push over
536 # to Android devices. -gline-tables-only is a lot slimmer.
537 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400538 cflags = [
539 "-gline-tables-only",
540 "-funwind-tables", # Helps make in-process backtraces fuller.
541 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400542 } else if (is_win) {
Mike Klein67a86d52017-12-15 07:34:27 -0500543 cflags = [ "/Z7" ]
Brian Osman7142ae52018-12-12 16:32:35 -0500544 if (is_clang) {
Eric Boren56bf8ce2019-02-07 13:05:06 -0500545 cflags += [ "-gcodeview-ghash" ]
Mike Kleincae020a2018-12-23 10:25:44 -0500546 ldflags = [ "/DEBUG:GHASH" ]
Brian Osman7142ae52018-12-12 16:32:35 -0500547 } else {
Mike Kleina6e0c2b2018-12-10 08:48:03 -0500548 ldflags = [ "/DEBUG:FASTLINK" ]
Brian Osman0ab56842018-09-13 15:46:02 -0400549 }
Mike Kleincc300a12016-10-12 16:25:27 -0400550 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700551 cflags = [ "-g" ]
552 }
553}
554
555config("no_rtti") {
556 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
Mike Kleincc300a12016-10-12 16:25:27 -0400557 if (is_win) {
558 cflags_cc = [ "/GR-" ]
559 } else {
mtkleinb9be9792016-09-16 14:44:18 -0700560 cflags_cc = [ "-fno-rtti" ]
561 }
562 }
563}
564
Mike Klein7ea977b2018-09-19 13:44:43 -0400565config("optimize") {
Mike Kleincc300a12016-10-12 16:25:27 -0400566 if (is_win) {
Mike Klein916ca1d2016-10-20 13:34:18 -0400567 cflags = [
568 "/O2",
569 "/Zc:inline",
570 ]
Mike Klein90a381f2016-10-20 13:52:38 -0400571 ldflags = [
572 "/OPT:ICF",
573 "/OPT:REF",
574 ]
Mike Kleincc300a12016-10-12 16:25:27 -0400575 } else {
Mike Klein13daa4f2019-06-20 10:08:55 -0500576 cflags = [ "-O3" ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500577 if (is_mac || is_ios) {
578 ldflags = [ "-dead_strip" ]
579 } else {
Mike Klein13daa4f2019-06-20 10:08:55 -0500580 cflags += [
581 "-fdata-sections",
582 "-ffunction-sections",
583 ]
Mike Kleinbd9be4d2017-02-10 07:59:39 -0500584 ldflags = [ "-Wl,--gc-sections" ]
585 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400586 if (target_cpu == "wasm") {
587 # The compiler asks us to add an optimization flag to both cflags
588 # and ldflags to cut down on the local variables,
589 # for performance reasons.
590 # The "linking" step is the conversion to javascript.
591 ldflags += [ "-O3" ]
592 }
herbb6318bf2016-09-16 13:29:57 -0700593 }
Mike Klein7ea977b2018-09-19 13:44:43 -0400594}
595
596config("NDEBUG") {
mtkleinb9be9792016-09-16 14:44:18 -0700597 defines = [ "NDEBUG" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700598}
599
600config("executable") {
Mike Kleinc5875fb2016-12-06 10:46:02 -0500601 if (is_android) {
Mike Klein1b4602b2017-08-30 10:23:01 -0400602 ldflags = [
603 "-pie",
604 "-rdynamic",
605 ]
Mike Kleinc5875fb2016-12-06 10:46:02 -0500606 } else if (is_mac) {
mtklein7fbfbbe2016-07-21 12:25:45 -0700607 ldflags = [ "-Wl,-rpath,@loader_path/." ]
608 } else if (is_linux) {
mtkleina846c722016-09-15 10:44:15 -0700609 ldflags = [
610 "-rdynamic",
611 "-Wl,-rpath,\$ORIGIN",
612 ]
Mike Klein4b6b5032016-11-06 11:54:19 -0500613 } else if (is_win) {
614 ldflags = [
615 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
Mike Kleina01c6b02020-04-01 13:47:34 -0500616 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link
617 # by never trying to.
Mike Klein4b6b5032016-11-06 11:54:19 -0500618 ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700619 }
620}