| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 # Base compiler configuration. | |
| 6 config("compiler") { | |
| 7 include_dirs = [ "//", root_gen_dir ] | |
| 8 if (is_win) { | |
| 9 cflags = [ | |
| 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). | |
| 14 ] | |
| 15 } else { | |
| 16 # Common GCC compiler flags setup. | |
| 17 # -------------------------------- | |
| 18 cflags = [ | |
| 19 "-fno-strict-aliasing", # See http://crbug.com/32204 | |
| 20 "-fvisibility=hidden", | |
| 21 ] | |
| 22 cflags_c = [ | |
| 23 ] | |
| 24 cflags_cc = [ | |
| 25 "-fno-exceptions", | |
| 26 "-fno-threadsafe-statics", | |
| 27 "-fvisibility-inlines-hidden", | |
| 28 ] | |
| 29 ldflags = [ | |
| 30 ] | |
| 31 | |
| 32 # Stack protection. | |
| 33 # TODO(brettw) why do we have different values for all of these cases? | |
| 34 if (is_mac) { | |
| 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" ] | |
| 40 } | |
| 41 | |
| 42 # Mac-specific compiler flags setup. | |
| 43 # ---------------------------------- | |
| 44 if (is_mac) { | |
| 45 # These flags are shared between the C compiler and linker. | |
| 46 common_mac_flags = [ | |
| 47 # TODO(brettw) obviously this arch flag needs to be parameterized. | |
| 48 "-arch i386", | |
| 49 | |
| 50 # Set which SDK to use. | |
| 51 # TODO(brettw) this needs to be configurable somehow. | |
| 52 "-isysroot", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOS
X.platform/Developer/SDKs/MacOSX10.7.sdk", | |
| 53 | |
| 54 "-mmacosx-version-min=10.6", | |
| 55 ] | |
| 56 | |
| 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", | |
| 61 ] | |
| 62 | |
| 63 cflags_c += [ "-std=c99" ] | |
| 64 cflags_cc += [ "-std=gnu++11" ] | |
| 65 | |
| 66 ldflags += common_mac_flags + [ | |
| 67 "-L.", | |
| 68 | |
| 69 # TODO(brettW) I don't understand these options. | |
| 70 "-Wl,-rpath,@loader_path/.", | |
| 71 "-Wl,-rpath,@loader_path/../../..", | |
| 72 ] | |
| 73 } | |
| 74 | |
| 75 # Linux-specific compiler flags setup. | |
| 76 # ------------------------------------ | |
| 77 if (is_linux) { | |
| 78 cflags += [ | |
| 79 "-fPIC", | |
| 80 "-pthread", | |
| 81 "-pipe", # Use pipes for communicating between sub-processes. Faster. | |
| 82 ] | |
| 83 | |
| 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) | |
| 88 ldflags += [ | |
| 89 "-B$gold_path", | |
| 90 | |
| 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. | |
| 95 #"-Wl,--icf=safe", | |
| 96 "-Wl,--icf=none", | |
| 97 | |
| 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_t
hread/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. | |
| 103 "-Wl,--threads", | |
| 104 "-Wl,--thread-count=4", | |
| 105 ] | |
| 106 } | |
| 107 | |
| 108 ldflags += [ | |
| 109 "-fPIC", | |
| 110 "-pthread", | |
| 111 "-Wl,-z,noexecstack", | |
| 112 "-Wl,-z,now", | |
| 113 "-Wl,-z,relro", | |
| 114 ] | |
| 115 } | |
| 116 | |
| 117 # Clang-specific compiler flags setup. | |
| 118 # ------------------------------------ | |
| 119 if (is_clang) { | |
| 120 cflags += [ | |
| 121 "-fcolor-diagnostics", | |
| 122 ] | |
| 123 } | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 # runtime_library ------------------------------------------------------------- | |
| 128 # | |
| 129 # Sets the runtime library and associated options. | |
| 130 # | |
| 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. | |
| 134 | |
| 135 config("runtime_library") { | |
| 136 if (is_component_build) { | |
| 137 # Component mode: dynamic CRT. | |
| 138 defines = [ "COMPONENT_BUILD" ] | |
| 139 if (is_win) { | |
| 140 # Since the library is shared, it requires exceptions or will give errors | |
| 141 # about things not matching, so keep exceptions on. | |
| 142 if (is_debug) { | |
| 143 cflags = [ "/MDd" ] | |
| 144 } else { | |
| 145 cflags = [ "/MD" ] | |
| 146 } | |
| 147 } | |
| 148 } else { | |
| 149 # Static CRT. | |
| 150 if (is_win) { | |
| 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" ] | |
| 154 if (is_debug) { | |
| 155 cflags = [ "/MTd" ] | |
| 156 } else { | |
| 157 cflags = [ "/MT" ] | |
| 158 } | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 if (is_win) { | |
| 163 defines += [ | |
| 164 "__STD_C", | |
| 165 "__STDC_CONSTANT_MACROS", | |
| 166 "__STDC_FORMAT_MACROS", | |
| 167 "_CRT_RAND_S", | |
| 168 "_CRT_SECURE_NO_DEPRECATE", | |
| 169 "_SCL_SECURE_NO_DEPRECATE", | |
| 170 "_UNICODE", | |
| 171 "UNICODE", | |
| 172 ] | |
| 173 } | |
| 174 } | |
| 175 | |
| 176 # chromium_code --------------------------------------------------------------- | |
| 177 # | |
| 178 # Toggles between higher and lower warnings for code that is (or isn't) | |
| 179 # part of Chromium. | |
| 180 | |
| 181 config("chromium_code") { | |
| 182 if (is_win) { | |
| 183 cflags = [ | |
| 184 "/W4", # Warning level 4. | |
| 185 "/WX", # Treat warnings as errors. | |
| 186 ] | |
| 187 } else { | |
| 188 cflags = [ | |
| 189 "-Wall", | |
| 190 "-Werror", | |
| 191 | |
| 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 | |
| 196 "-Wsign-compare", | |
| 197 ] | |
| 198 | |
| 199 # In Chromium code, we define __STDC_foo_MACROS in order to get the | |
| 200 # C99 macros on Mac and Linux. | |
| 201 defines = [ | |
| 202 "__STDC_CONSTANT_MACROS", | |
| 203 "__STDC_FORMAT_MACROS", | |
| 204 ] | |
| 205 | |
| 206 # TODO(brettw) this should also be enabled on Linux but some files | |
| 207 # currently fail. | |
| 208 if (is_mac) { | |
| 209 cflags += "-Wextra" | |
| 210 } | |
| 211 } | |
| 212 } | |
| 213 config("no_chromium_code") { | |
| 214 if (is_win) { | |
| 215 cflags = [ | |
| 216 "/W3", # Warning level 3. | |
| 217 "/wd4800", # Disable warning when forcing value to bool. | |
| 218 ] | |
| 219 defines = [ | |
| 220 "_CRT_NONSTDC_NO_WARNINGS", | |
| 221 "_CRT_NONSTDC_NO_DEPRECATE", | |
| 222 ] | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 # rtti ------------------------------------------------------------------------ | |
| 227 # | |
| 228 # Allows turning Run-Time Type Identification on or off. | |
| 229 | |
| 230 config("rtti") { | |
| 231 if (is_win) { | |
| 232 cflags_cc = [ "/GR" ] | |
| 233 } | |
| 234 } | |
| 235 config("no_rtti") { | |
| 236 if (is_win) { | |
| 237 cflags_cc = [ "/GR-" ] | |
| 238 } else { | |
| 239 cflags_cc = [ "-fno-rtti" ] | |
| 240 } | |
| 241 } | |
| 242 | |
| 243 # Warnings --------------------------------------------------------------------- | |
| 244 | |
| 245 config("default_warnings") { | |
| 246 if (is_win) { | |
| 247 # Please keep ordered and add names if you add more. | |
| 248 cflags = [ | |
| 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. | |
| 281 ] | |
| 282 } else { | |
| 283 # Common GCC warning setup. | |
| 284 cflags = [ | |
| 285 # Enables. | |
| 286 "-Wendif-labels", # Weird old-style text after an #endif. | |
| 287 | |
| 288 # Disables. | |
| 289 "-Wno-missing-field-initializers", # "struct foo f = {0};" | |
| 290 "-Wno-unused-parameter", # Unused function parameters. | |
| 291 "-Wno-write-strings", | |
| 292 ] | |
| 293 | |
| 294 if (is_mac) { | |
| 295 cflags += [ | |
| 296 "-Wnewline-eof", | |
| 297 ] | |
| 298 } | |
| 299 | |
| 300 # TODO(brettw) Ones below here should be clang-only when we have a flag | |
| 301 # for it. | |
| 302 if (is_clang) { | |
| 303 cflags += [ | |
| 304 "-Wheader-hygiene", | |
| 305 | |
| 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", | |
| 311 | |
| 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", | |
| 316 | |
| 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", | |
| 320 | |
| 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", | |
| 325 | |
| 326 # Clang spots more unused functions. | |
| 327 "-Wno-unused-function", | |
| 328 | |
| 329 # Warns when a const char[] is converted to bool. | |
| 330 "-Wstring-conversion", | |
| 331 ] | |
| 332 } | |
| 333 } | |
| 334 } | |
| 335 | |
| 336 # Optimization ----------------------------------------------------------------- | |
| 337 | |
| 338 config("optimize") { | |
| 339 if (is_win) { | |
| 340 cflags = [ | |
| 341 "/O2", | |
| 342 "/Ob2", # Both explicit and auto inlining. | |
| 343 "/Oy-", # Disable omitting frame pointers, must be after /O2. | |
| 344 ] | |
| 345 } else { | |
| 346 if (is_ios) { | |
| 347 cflags = [ "-Os" ] | |
| 348 } else { | |
| 349 cflags = [ "-O2" ] | |
| 350 } | |
| 351 } | |
| 352 } | |
| 353 | |
| 354 config("no_optimize") { | |
| 355 if (is_win) { | |
| 356 cflags = [ | |
| 357 "/Od", # Disable optimization. | |
| 358 "/Ob0", # Disable all inlining (on by default). | |
| 359 "/RTC1", # Runtime checks for stack frame and uninitialized variables. | |
| 360 ] | |
| 361 } else { | |
| 362 cflags = [ "-O0" ] | |
| 363 } | |
| 364 } | |
| 365 | |
| 366 # Symbols ---------------------------------------------------------------------- | |
| 367 | |
| 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. | |
| 374 config("symbols") { | |
| 375 if (is_win) { | |
| 376 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue. | |
| 377 ldflags = [ "/DEBUG" ] | |
| 378 } else { | |
| 379 cflags = [ "-g2" ] | |
| 380 } | |
| 381 } | |
| 382 | |
| 383 config("minimal_symbols") { | |
| 384 if (is_win) { | |
| 385 # Linker symbols for backtraces only. | |
| 386 ldflags = [ "/DEBUG" ] | |
| 387 } else { | |
| 388 cflags = [ "-g1" ] | |
| 389 } | |
| 390 } | |
| 391 | |
| 392 config("no_symbols") { | |
| 393 if (!is_win) { | |
| 394 cflags = [ "-g0" ] | |
| 395 } | |
| 396 } | |
| OLD | NEW |