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 import("//build/config/compiler/compiler.gni") |
| 6 import("//build/config/sanitizers/sanitizers.gni") |
| 7 import("//build/config/win/visual_studio_version.gni") |
| 8 import("//build/toolchain/toolchain.gni") |
| 9 |
| 10 assert(is_win) |
| 11 |
| 12 declare_args() { |
| 13 # Set this to true to enable static analysis through Visual Studio's |
| 14 # /analyze. This dramatically slows compiles and reports thousands of |
| 15 # warnings, so normally this is done on a build machine and only the new |
| 16 # warnings are examined. |
| 17 use_vs_code_analysis = false |
| 18 } |
| 19 |
| 20 # This is included by reference in the //build/config/compiler config that |
| 21 # is applied to all targets. It is here to separate out the logic that is |
| 22 # Windows-only. |
| 23 config("compiler") { |
| 24 if (current_cpu == "x86") { |
| 25 asmflags = [ |
| 26 # When /safeseh is specified, the linker will only produce an image if it |
| 27 # can also produce a table of the image's safe exception handlers. This |
| 28 # table specifies for the operating system which exception handlers are |
| 29 # valid for the image. Note that /SAFESEH isn't accepted on the command |
| 30 # line, only /safeseh. This is only accepted by ml.exe, not ml64.exe. |
| 31 "/safeseh", |
| 32 ] |
| 33 } |
| 34 |
| 35 cflags = [ |
| 36 "/Gy", # Enable function-level linking. |
| 37 "/FS", # Preserve previous PDB behavior. |
| 38 "/bigobj", # Some of our files are bigger than the regular limits. |
| 39 |
| 40 # Tell the compiler to crash on failures. This is undocumented |
| 41 # and unsupported but very handy. |
| 42 "/d2FastFail", |
| 43 ] |
| 44 |
| 45 # Force C/C++ mode for the given GN detected file type. This is necessary |
| 46 # for precompiled headers where the same source file is compiled in both |
| 47 # modes. |
| 48 cflags_c = [ "/TC" ] |
| 49 cflags_cc = [ "/TP" ] |
| 50 |
| 51 if (visual_studio_version == "2015") { |
| 52 cflags += [ |
| 53 # Work around crbug.com/526851, bug in VS 2015 RTM compiler. |
| 54 "/Zc:sizedDealloc-", |
| 55 |
| 56 # Disable thread-safe statics to avoid overhead and because |
| 57 # they are disabled on other platforms. See crbug.com/587210 |
| 58 # and -fno-threadsafe-statics. |
| 59 "/Zc:threadSafeInit-", |
| 60 ] |
| 61 } |
| 62 |
| 63 # Building with Clang on Windows is a work in progress and very |
| 64 # experimental. See crbug.com/82385. |
| 65 # Keep this in sync with the similar block in build/common.gypi |
| 66 if (is_clang) { |
| 67 cflags += [ |
| 68 # Many files use intrinsics without including this header. |
| 69 # TODO(hans): Fix those files, or move this to sub-GYPs. |
| 70 "/FIIntrin.h", |
| 71 ] |
| 72 |
| 73 if (visual_studio_version == "2013") { |
| 74 cflags += [ "-fmsc-version=1800" ] |
| 75 } else if (visual_studio_version == "2015") { |
| 76 cflags += [ "-fmsc-version=1900" ] |
| 77 } |
| 78 |
| 79 if (current_cpu == "x86") { |
| 80 cflags += [ "-m32" ] |
| 81 } else { |
| 82 cflags += [ "-m64" ] |
| 83 } |
| 84 |
| 85 if (exec_script("//build/win/use_ansi_codes.py", [], "trim string") == |
| 86 "True") { |
| 87 cflags += [ |
| 88 # cmd.exe doesn't understand ANSI escape codes by default, |
| 89 # so only enable them if something emulating them is around. |
| 90 "-fansi-escape-codes", |
| 91 ] |
| 92 } |
| 93 |
| 94 # Clang runtime libraries, such as the sanitizer runtimes, live here. |
| 95 lib_dirs = [ "//third_party/llvm-build/Release+Asserts/lib/clang/$clang_vers
ion/lib/windows" ] |
| 96 } |
| 97 |
| 98 if (is_syzyasan) { |
| 99 # SyzyAsan needs /PROFILE turned on to produce appropriate pdbs. |
| 100 assert(!is_win_fastlink, "/PROFILE and /DEBUG:FASTLINK are incompatible") |
| 101 ldflags = [ "/PROFILE" ] |
| 102 } |
| 103 |
| 104 # arflags apply only to static_libraries. The normal linker configs are only |
| 105 # set for executable and shared library targets so arflags must be set |
| 106 # elsewhere. Since this is relatively contained, we just apply them in this |
| 107 # more general config and they will only have an effect on static libraries. |
| 108 arflags = [ |
| 109 # "No public symbols found; archive member will be inaccessible." This |
| 110 # means that one or more object files in the library can never be |
| 111 # pulled in to targets that link to this library. It's just a warning that |
| 112 # the source file is a no-op. |
| 113 "/ignore:4221", |
| 114 ] |
| 115 } |
| 116 |
| 117 config("vs_code_analysis") { |
| 118 if (use_vs_code_analysis) { |
| 119 # When use_vs_code_analysis is specified add the /analyze switch to enable |
| 120 # static analysis. Specifying /analyze:WX- says that /analyze warnings |
| 121 # should not be treated as errors. |
| 122 cflags = [ "/analyze:WX-" ] |
| 123 |
| 124 # Also, disable various noisy warnings that have low value. |
| 125 cflags += [ |
| 126 "/wd6011", # Dereferencing NULL pointer |
| 127 |
| 128 # C6285 is ~16% of raw warnings and has low value |
| 129 "/wd6285", # non-zero constant || non-zero constant |
| 130 "/wd6308", # realloc might return null pointer |
| 131 |
| 132 # Possible infinite loop: use of the constant |
| 133 # EXCEPTION_CONTINUE_EXECUTION in the exception-filter |
| 134 "/wd6312", |
| 135 |
| 136 "/wd6322", # Empty _except block |
| 137 "/wd6330", # 'char' used instead of 'unsigned char' for istype() call |
| 138 |
| 139 # C6334 is ~80% of raw warnings and has low value |
| 140 "/wd6334", # sizeof applied to an expression with an operator |
| 141 "/wd6326", # Potential comparison of constant with constant |
| 142 "/wd6340", # Sign mismatch in function parameter |
| 143 "/wd28159", # Consider using 'GetTickCount64' |
| 144 "/wd28196", # The precondition is not satisfied |
| 145 "/wd28204", # Inconsistent SAL annotations |
| 146 "/wd28251", # Inconsistent SAL annotations |
| 147 "/wd28252", # Inconsistent SAL annotations |
| 148 "/wd28253", # Inconsistent SAL annotations |
| 149 "/wd28278", # Function appears with no prototype in scope |
| 150 "/wd28285", # syntax error in SAL annotation (in algorithm) |
| 151 "/wd28301", # Inconsistent SAL annotations |
| 152 "/wd28182", # Dereferencing NULL pointer |
| 153 ] |
| 154 } |
| 155 } |
| 156 |
| 157 # This is included by reference in the //build/config/compiler:runtime_library |
| 158 # config that is applied to all targets. It is here to separate out the logic |
| 159 # that is Windows-only. Please see that target for advice on what should go in |
| 160 # :runtime_library vs. :compiler. |
| 161 config("runtime_library") { |
| 162 cflags = [] |
| 163 |
| 164 # Defines that set up the CRT. |
| 165 defines = [ |
| 166 "__STD_C", |
| 167 "_CRT_RAND_S", |
| 168 "_CRT_SECURE_NO_DEPRECATE", |
| 169 "_HAS_EXCEPTIONS=0", |
| 170 "_SCL_SECURE_NO_DEPRECATE", |
| 171 ] |
| 172 |
| 173 # Defines that set up the Windows SDK. |
| 174 defines += [ |
| 175 "_ATL_NO_OPENGL", |
| 176 "_WINDOWS", |
| 177 "CERT_CHAIN_PARA_HAS_EXTRA_FIELDS", |
| 178 "NTDDI_VERSION=0x0A000000", |
| 179 "PSAPI_VERSION=1", |
| 180 "WIN32", |
| 181 "_SECURE_ATL", |
| 182 ] |
| 183 |
| 184 if (!use_vs_code_analysis) { |
| 185 # This is required for ATL to use XP-safe versions of its functions. |
| 186 # However it is prohibited when using /analyze |
| 187 defines += [ "_USING_V110_SDK71_" ] |
| 188 } |
| 189 |
| 190 if (is_component_build) { |
| 191 # Component mode: dynamic CRT. Since the library is shared, it requires |
| 192 # exceptions or will give errors about things not matching, so keep |
| 193 # exceptions on. |
| 194 if (is_debug) { |
| 195 cflags += [ "/MDd" ] |
| 196 } else { |
| 197 cflags += [ "/MD" ] |
| 198 } |
| 199 } else { |
| 200 if (current_os != "win") { |
| 201 # WindowsRT: use the dynamic CRT. |
| 202 if (is_debug) { |
| 203 cflags += [ "/MDd" ] |
| 204 } else { |
| 205 cflags += [ "/MD" ] |
| 206 } |
| 207 } else { |
| 208 # Desktop Windows: static CRT. |
| 209 if (is_debug) { |
| 210 cflags += [ "/MTd" ] |
| 211 } else { |
| 212 cflags += [ "/MT" ] |
| 213 } |
| 214 } |
| 215 } |
| 216 } |
| 217 |
| 218 # Sets the default Windows build version. This is separated because some |
| 219 # targets need to manually override it for their compiles. |
| 220 config("winver") { |
| 221 defines = [ |
| 222 "_WIN32_WINNT=0x0A00", |
| 223 "WINVER=0x0A00", |
| 224 ] |
| 225 } |
| 226 |
| 227 # Linker flags for Windows SDK setup, this is applied only to EXEs and DLLs. |
| 228 config("sdk_link") { |
| 229 if (current_cpu == "x64") { |
| 230 ldflags = [ "/MACHINE:X64" ] |
| 231 lib_dirs = [ |
| 232 "$windows_sdk_path\Lib\winv6.3\um\x64", |
| 233 "$visual_studio_path\VC\lib\amd64", |
| 234 "$visual_studio_path\VC\atlmfc\lib\amd64", |
| 235 ] |
| 236 } else { |
| 237 ldflags = [ |
| 238 "/MACHINE:X86", |
| 239 "/SAFESEH", # Not compatible with x64 so use only for x86. |
| 240 "/largeaddressaware", |
| 241 ] |
| 242 lib_dirs = [ |
| 243 "$windows_sdk_path\Lib\winv6.3\um\x86", |
| 244 "$visual_studio_path\VC\lib", |
| 245 "$visual_studio_path\VC\atlmfc\lib", |
| 246 ] |
| 247 } |
| 248 } |
| 249 |
| 250 # This default linker setup is provided separately from the SDK setup so |
| 251 # targets who want different library configurations can remove this and specify |
| 252 # their own. |
| 253 config("common_linker_setup") { |
| 254 ldflags = [ |
| 255 "/FIXED:NO", |
| 256 "/ignore:4199", |
| 257 "/ignore:4221", |
| 258 "/NXCOMPAT", |
| 259 |
| 260 # Suggested by Microsoft Devrel to avoid |
| 261 # LINK : fatal error LNK1248: image size (80000000) |
| 262 # exceeds maximum allowable size (80000000) |
| 263 # which started happening more regularly after VS2013 Update 4. |
| 264 # Needs to be a bit lower for VS2015, or else errors out. |
| 265 "/maxilksize:0x7ff00000", |
| 266 |
| 267 # Tell the linker to crash on failures. |
| 268 "/fastfail", |
| 269 ] |
| 270 |
| 271 # ASLR makes debugging with windbg difficult because Chrome.exe and |
| 272 # Chrome.dll share the same base name. As result, windbg will name the |
| 273 # Chrome.dll module like chrome_<base address>, where <base address> |
| 274 # typically changes with each launch. This in turn means that breakpoints in |
| 275 # Chrome.dll don't stick from one launch to the next. For this reason, we |
| 276 # turn ASLR off in debug builds. |
| 277 if (is_debug) { |
| 278 ldflags += [ "/DYNAMICBASE:NO" ] |
| 279 } else { |
| 280 ldflags += [ "/DYNAMICBASE" ] |
| 281 } |
| 282 } |
| 283 |
| 284 # Subsystem -------------------------------------------------------------------- |
| 285 |
| 286 # This is appended to the subsystem to specify a minimum version. |
| 287 if (current_cpu == "x64") { |
| 288 # The number after the comma is the minimum required OS version. |
| 289 # 5.02 = Windows Server 2003. |
| 290 subsystem_version_suffix = ",5.02" |
| 291 } else { |
| 292 # 5.01 = Windows XP. |
| 293 subsystem_version_suffix = ",5.01" |
| 294 } |
| 295 |
| 296 config("console") { |
| 297 ldflags = [ "/SUBSYSTEM:CONSOLE$subsystem_version_suffix" ] |
| 298 } |
| 299 config("windowed") { |
| 300 ldflags = [ "/SUBSYSTEM:WINDOWS$subsystem_version_suffix" ] |
| 301 } |
| 302 |
| 303 # Incremental linking ---------------------------------------------------------- |
| 304 |
| 305 incremental_linking_on_switch = [ "/INCREMENTAL" ] |
| 306 incremental_linking_off_switch = [ "/INCREMENTAL:NO" ] |
| 307 |
| 308 # Disable incremental linking for syzyasan |
| 309 if (is_debug && !is_syzyasan) { |
| 310 default_incremental_linking_switch = incremental_linking_on_switch |
| 311 } else { |
| 312 default_incremental_linking_switch = incremental_linking_off_switch |
| 313 } |
| 314 |
| 315 # Applies incremental linking or not depending on the current configuration. |
| 316 config("default_incremental_linking") { |
| 317 ldflags = default_incremental_linking_switch |
| 318 } |
| 319 |
| 320 # Explicitly on or off incremental linking |
| 321 config("incremental_linking") { |
| 322 ldflags = incremental_linking_on_switch |
| 323 } |
| 324 config("no_incremental_linking") { |
| 325 ldflags = incremental_linking_off_switch |
| 326 } |
| 327 |
| 328 # Some large modules can't handle incremental linking in some situations. This |
| 329 # config should be applied to large modules to turn off incremental linking |
| 330 # when it won't work. |
| 331 config("default_large_module_incremental_linking") { |
| 332 if (symbol_level > 0 && (current_cpu == "x86" || !is_component_build)) { |
| 333 # When symbols are on, things get so large that the tools fail due to the |
| 334 # size of the .ilk files. |
| 335 ldflags = incremental_linking_off_switch |
| 336 } else { |
| 337 # Otherwise just do the default incremental linking for this build type. |
| 338 ldflags = default_incremental_linking_switch |
| 339 } |
| 340 } |
| 341 |
| 342 # Character set ---------------------------------------------------------------- |
| 343 |
| 344 # Not including this config means "ansi" (8-bit system codepage). |
| 345 config("unicode") { |
| 346 defines = [ |
| 347 "_UNICODE", |
| 348 "UNICODE", |
| 349 ] |
| 350 } |
| 351 |
| 352 # Lean and mean ---------------------------------------------------------------- |
| 353 |
| 354 # Some third party code might not compile with WIN32_LEAN_AND_MEAN so we have |
| 355 # to have a separate config for it. Remove this config from your target to |
| 356 # get the "bloaty and accomodating" version of windows.h. |
| 357 config("lean_and_mean") { |
| 358 defines = [ "WIN32_LEAN_AND_MEAN" ] |
| 359 } |
| 360 |
| 361 # Nominmax -------------------------------------------------------------------- |
| 362 |
| 363 # Some third party code defines NOMINMAX before including windows.h, which |
| 364 # then causes warnings when it's been previously defined on the command line. |
| 365 # For such targets, this config can be removed. |
| 366 |
| 367 config("nominmax") { |
| 368 defines = [ "NOMINMAX" ] |
| 369 } |
| 370 |
| 371 # Target WinRT ---------------------------------------------------------------- |
| 372 |
| 373 # When targeting Windows Runtime, certain compiler/linker flags are necessary. |
| 374 |
| 375 config("target_winrt") { |
| 376 defines = [ |
| 377 "WINRT", |
| 378 "WINAPI_FAMILY=WINAPI_FAMILY_PC_APP", |
| 379 ] |
| 380 cflags_cc = [ |
| 381 "/ZW", |
| 382 "/EHsc", |
| 383 ] |
| 384 } |
| 385 |
| 386 # Internal stuff -------------------------------------------------------------- |
| 387 |
| 388 # Config used by the MIDL template to disable warnings. |
| 389 config("midl_warnings") { |
| 390 if (is_clang) { |
| 391 # MIDL generates code like "#endif !_MIDL_USE_GUIDDEF_". |
| 392 cflags = [ "-Wno-extra-tokens" ] |
| 393 } |
| 394 } |
OLD | NEW |