1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # Base compiler configuration.
7 include_dirs = [ "//" ]
10 "/Gy", # Enable function-level linking.
11 "/GS", # Enable buffer security checking.
12 "/EHsc", # Assume C functions can't throw exceptions and don't catch
13 # structured exceptions (only C++ ones).
16 # Common GCC compiler flags setup.
17 # --------------------------------
19 "-fno-strict-aliasing", # See http://crbug.com/32204
20 "-fvisibility=hidden",
26 "-fno-threadsafe-statics",
27 "-fvisibility-inlines-hidden",
33 # TODO(brettw) why do we have different values for all of these cases?
35 cflags += "-fstack-protector-all"
36 } else if (is_chromeos) {
37 cflags += "-fstack-protector-strong"
38 } else if (is_linux) {
39 cflags += [ "-fstack-protector", "--param=ssp-buffer-size=4" ]
42 # Mac-specific compiler flags setup.
43 # ----------------------------------
45 # These flags are shared between the C compiler and linker.
47 # TODO(brettw) obviously this arch flag needs to be parameterized.
50 # Set which SDK to use.
51 # TODO(brettw) this needs to be configurable somehow.
52 "-isysroot", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk",
54 "-mmacosx-version-min=10.6",
57 cflags += common_mac_flags + [
58 # Without this, the constructors and destructors of a C++ object inside
59 # an Objective C struct won't be called, which is very bad.
60 "-fobjc-call-cxx-cdtors",
63 cflags_c += [ "-std=c99" ]
64 cflags_cc += [ "-std=gnu++11" ]
66 ldflags += common_mac_flags + [
69 # TODO(brettW) I don't understand these options.
70 "-Wl,-rpath,@loader_path/.",
71 "-Wl,-rpath,@loader_path/../../..",
75 # Linux-specific compiler flags setup.
76 # ------------------------------------
81 "-pipe", # Use pipes for communicating between sub-processes. Faster.
84 # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of
85 # address space, and it doesn't support cross-compiling).
86 if (cpu_arch == "ia64") {
87 gold_path = rebase_path("//third_party/gold", ".", root_build_dir)
91 # There seems to be a conflict of --icf and -pie in gold which can
92 # generate crashy binaries. As a security measure, -pie takes
93 # precendence for now.
94 # TODO(brettw) common.gypi has this only for target toolset.
98 # Experimentation found that using four linking threads
99 # saved ~20% of link time.
100 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
101 # Only apply this to the target linker, since the host
102 # linker might not be gold, but isn't used much anyway.
104 "-Wl,--thread-count=4",
111 "-Wl,-z,noexecstack",
117 # Clang-specific compiler flags setup.
118 # ------------------------------------
121 "-fcolor-diagnostics",
127 # runtime_library -------------------------------------------------------------
129 # Sets the runtime library and associated options.
131 # We don't bother making multiple versions that are toggle-able since there
132 # is more than one axis of control (which makes it complicated) and there's
133 # no practical reason for anybody to change this since the CRT must agree.
135 config("runtime_library") {
136 if (is_component_build) {
137 # Component mode: dynamic CRT.
138 defines = [ "COMPONENT_BUILD" ]
140 # Since the library is shared, it requires exceptions or will give errors
141 # about things not matching, so keep exceptions on.
151 # We don't use exceptions, and when we link statically we can just get
152 # rid of them entirely.
153 defines = [ "_HAS_EXCEPTIONS=0" ]
165 "__STDC_CONSTANT_MACROS",
166 "__STDC_FORMAT_MACROS",
168 "_CRT_SECURE_NO_DEPRECATE",
169 "_SCL_SECURE_NO_DEPRECATE",
176 # chromium_code ---------------------------------------------------------------
178 # Toggles between higher and lower warnings for code that is (or isn't)
181 config("chromium_code") {
184 "/W4", # Warning level 4.
185 "/WX", # Treat warnings as errors.
192 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
193 # so we specify it explicitly.
194 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
195 # http://code.google.com/p/chromium/issues/detail?id=90453
199 # In Chromium code, we define __STDC_foo_MACROS in order to get the
200 # C99 macros on Mac and Linux.
202 "__STDC_CONSTANT_MACROS",
203 "__STDC_FORMAT_MACROS",
206 # TODO(brettw) this should also be enabled on Linux but some files
213 config("no_chromium_code") {
216 "/W3", # Warning level 3.
217 "/wd4800", # Disable warning when forcing value to bool.
220 "_CRT_NONSTDC_NO_WARNINGS",
221 "_CRT_NONSTDC_NO_DEPRECATE",
226 # rtti ------------------------------------------------------------------------
228 # Allows turning Run-Time Type Identification on or off.
232 cflags_cc = [ "/GR" ]
237 cflags_cc = [ "/GR-" ]
239 cflags_cc = [ "-fno-rtti" ]
243 # Warnings ---------------------------------------------------------------------
245 config("default_warnings") {
247 # Please keep ordered and add names if you add more.
249 "/wd4018", # Comparing signed and unsigned values.
250 "/wd4100", # Unreferenced formal function parameter.
251 "/wd4121", # Alignment of a member was sensitive to packing.
252 "/wd4125", # Decimal digit terminates octal escape sequence.
253 "/wd4127", # Conditional expression is constant.
254 "/wd4130", # Logical operation on address of string constant.
255 # TODO(brettw) is this necessary? If so, it should probably be on whoever
256 # is silly enough to be doing this rather than globally.
257 #"/wd4131", # Function uses old-style declarator.
258 "/wd4189", # A variable was declared and initialized but never used.
259 "/wd4201", # Nonstandard extension used: nameless struct/union.
260 "/wd4238", # Nonstandard extension used: class rvalue used as lvalue.
261 "/wd4244", # Conversion: possible loss of data.
262 "/wd4245", # Conversion: signed/unsigned mismatch,
263 "/wd4251", # Class needs to have dll-interface.
264 "/wd4310", # Cast truncates constant value.
265 "/wd4351", # Elements of array will be default initialized.
266 "/wd4355", # 'this' used in base member initializer list.
267 "/wd4396", # Inline friend template thing.
268 "/wd4428", # Universal character name encountered in source.
269 "/wd4481", # Nonstandard extension: override specifier.
270 "/wd4503", # Decorated name length exceeded, name was truncated.
271 "/wd4505", # Unreferenced local function has been removed.
272 "/wd4510", # Default constructor could not be generated.
273 "/wd4512", # Assignment operator could not be generated.
274 "/wd4530", # Exception handler used, but unwind semantics not enabled.
275 "/wd4610", # Class can never be instantiated, constructor required.
276 "/wd4611", # C++ object destruction and 'catch'.
277 "/wd4701", # Potentially uninitialized local variable name used.
278 "/wd4702", # Unreachable code.
279 "/wd4706", # Assignment within conditional expression.
280 "/wd4819", # Character not in the current code page.
283 # Common GCC warning setup.
286 "-Wendif-labels", # Weird old-style text after an #endif.
289 "-Wno-missing-field-initializers", # "struct foo f = {0};"
290 "-Wno-unused-parameter", # Unused function parameters.
291 "-Wno-write-strings",
300 # TODO(brettw) Ones below here should be clang-only when we have a flag
306 # This warns on using ints as initializers for floats in
307 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
308 # which happens in several places in chrome code. Not sure if
309 # this is worth fixing.
310 "-Wno-c++11-narrowing",
312 # Don't die on dtoa code that uses a char as an array index.
313 # This is required solely for base/third_party/dmg_fp/dtoa.cc.
314 # TODO(brettw) move this to that project then!
315 "-Wno-char-subscripts",
317 # Warns on switches on enums that cover all enum values but
318 # also contain a default: branch. Chrome is full of that.
319 "-Wno-covered-switch-default",
321 # Clang considers the `register` keyword as deprecated, but e.g.
322 # code generated by flex (used in angle) contains that keyword.
323 # http://crbug.com/255186
324 "-Wno-deprecated-register",
326 # Clang spots more unused functions.
327 "-Wno-unused-function",
329 # Warns when a const char[] is converted to bool.
330 "-Wstring-conversion",
336 # Optimization -----------------------------------------------------------------
342 "/Ob2", # Both explicit and auto inlining.
343 "/Oy-", # Disable omitting frame pointers, must be after /O2.
354 config("no_optimize") {
357 "/Od", # Disable optimization.
358 "/Ob0", # Disable all inlining (on by default).
359 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
366 # Symbols ----------------------------------------------------------------------
368 # TODO(brettw) Since this sets ldflags on Windows which is inherited across
369 # static library boundaries, if you want to remove the default symbol config
370 # and set a different one on a target, you also have to do it for all static
371 # libraries that go into that target, which is messed up. Either we need a
372 # more flexible system for defining linker flags, or we need to separate this
373 # out into a "symbols_linker" config that is only applied to DLLs and EXEs.
376 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
377 ldflags = [ "/DEBUG" ]
383 config("minimal_symbols") {
385 # Linker symbols for backtraces only.
386 ldflags = [ "/DEBUG" ]
392 config("no_symbols") {