3 SPDX-FileCopyrightText: Copyright The SCons Foundation (https://scons.org)
4 SPDX-License-Identifier: MIT
5 SPDX-FileType: DOCUMENTATION
7 This file is processed by the bin/SConsDoc.py module.
11 <!ENTITY % scons SYSTEM '../../doc/scons.mod'>
13 <!ENTITY % builders-mod SYSTEM '../../doc/generated/builders.mod'>
15 <!ENTITY % functions-mod SYSTEM '../../doc/generated/functions.mod'>
17 <!ENTITY % tools-mod SYSTEM '../../doc/generated/tools.mod'>
19 <!ENTITY % variables-mod SYSTEM '../../doc/generated/variables.mod'>
23 <sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
24 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25 xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
30 Sets &consvars; for the &MSVC; compiler.
34 <item>CCDEPFLAGS</item>
35 <item>CCPDBFLAGS</item>
36 <item>CCPCHFLAGS</item>
37 <item><!--CCCOMFLAGS--></item>
43 <item>SHCCFLAGS</item>
50 <item>SHCXXFLAGS</item>
52 <item>CPPDEFPREFIX</item>
53 <item>CPPDEFSUFFIX</item>
54 <item>INCPREFIX</item>
55 <item>INCSUFFIX</item>
56 <item><!--STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME--></item>
61 <item>OBJPREFIX</item>
62 <item>OBJSUFFIX</item>
63 <item>SHOBJPREFIX</item>
64 <item>SHOBJSUFFIX</item>
65 <item>CFILESUFFIX</item>
66 <item>CXXFILESUFFIX</item>
67 <item>PCHPDBFLAGS</item>
72 <item>SHCCCOMSTR</item>
73 <item>CXXCOMSTR</item>
74 <item>SHCXXCOMSTR</item>
78 <item>MSVC_VERSION</item>
79 <item>MSVC_USE_SCRIPT</item>
80 <item>MSVC_USE_SCRIPT_ARGS</item>
81 <item>MSVC_USE_SETTINGS</item>
82 <item>MSVC_NOTFOUND_POLICY</item>
83 <item>MSVC_SCRIPTERROR_POLICY</item>
84 <item>MSVC_SCRIPT_ARGS</item>
85 <item>MSVC_SDK_VERSION</item>
86 <item>MSVC_TOOLSET_VERSION</item>
87 <item>MSVC_SPECTRE_LIBS</item>
95 Builds a &MSVC; precompiled header.
97 returns a list of two target nodes: the PCH as the first element,
98 and the object file as the second element.
99 Normally the object file is ignored.
100 The &b-PCH; builder is generally used in
101 conjunction with the &cv-link-PCH; &consvar; to force object files to use
102 the precompiled header:
106 env['PCH'] = env.PCH('StdAfx.cpp')[0]
111 This builder is specific to the PCH implementation in &MSVC;.
112 Other compiler chains also implement precompiled header support,
113 but &b-PCH; does not work with them at this time.
114 As a result, the builder is only generated into the
115 construction environment when
116 &MSVC; is being used as the compiler.
119 The builder only works correctly in a C++ project.
120 The Microsoft implementation distinguishes between
121 precompiled headers from C and C++.
122 Use of the builder will cause the PCH generation to happen with a flag
123 that tells <application>cl.exe</application> all of the
124 files are C++ files; if that PCH file is then supplied when
125 compiling a C source file,
126 <application>cl.exe</application> will fail the build with
127 a compatibility violation.
130 If possible, arrange the project so that a
131 C++ source file passed to the &b-PCH; builder
132 is not also included in the list of sources
133 to be otherwise compiled in the project.
134 &SCons; will correctly track that file in the dependency tree
135 as a result of the &b-PCH; call,
136 and (for MSVC 11.0 and greater) automatically add the
137 corresponding object file to the link line.
138 If the source list is automatically generated,
139 for example using the &f-link-Glob; function,
140 it may be necessary to remove that file from the list.
149 Builds a &MSVC; resource file.
150 This builder method is only provided
151 when &MSVC; or MinGW is being used as the compiler. The
152 <filename>.res</filename>
154 <filename>.o</filename>
155 for MinGW) suffix is added to the target name if no other suffix is given.
157 file is scanned for implicit dependencies as though it were a C file.
162 env.RES('resource.rc')
167 <cvar name="CCPCHFLAGS">
170 Options added to the compiler command line
171 to support building with precompiled headers.
172 The default value expands expands to the appropriate
173 &MSVC; command-line options
174 when the &cv-link-PCH; &consvar; is set.
179 <cvar name="CCPDBFLAGS">
182 Options added to the compiler command line
183 to support storing debugging information in a
185 The default value expands expands to appropriate
186 &MSVC; command-line options
187 when the &cv-link-PDB; &consvar; is set.
191 The &MSVC; compiler option that &SCons; uses by default
192 to generate PDB information is <option>/Z7</option>.
193 This works correctly with parallel (<option>-j</option>) builds
194 because it embeds the debug information in the intermediate object files,
195 as opposed to sharing a single PDB file between multiple object files.
196 This is also the only way to get debug information
197 embedded into a static library.
198 Using the <option>/Zi</option> instead may yield improved
199 link-time performance,
200 although parallel builds will no longer work.
204 You can generate PDB files with the <option>/Zi</option>
205 switch by overriding the default &cv-link-CCPDBFLAGS; variable as follows:
209 env['CCPDBFLAGS'] = ['${(PDB and "/Zi /Fd%s" % File(PDB)) or ""}']
213 An alternative would be to use the <option>/Zi</option>
214 to put the debugging information in a separate <filename>.pdb</filename>
215 file for each object file by overriding
216 the &cv-link-CCPDBFLAGS; variable as follows:
220 env['CCPDBFLAGS'] = '/Zi /Fd${TARGET}.pdb'
225 <cvar name="MSVC_BATCH">
228 When set to any true value,
229 specifies that &SCons; should batch
230 compilation of object files
231 when calling the &MSVC; compiler.
232 All compilations of source files from the same source directory
233 that generate target files in a same output directory
234 and were configured in &SCons; using the same &consenv;
235 will be built in a single call to the compiler.
236 Only source files that have changed since their
237 object files were built will be passed to each compiler invocation
238 (via the &cv-link-CHANGED_SOURCES; &consvar;).
239 Any compilations where the object (target) file base name
240 (minus the <filename>.obj</filename>)
241 does not match the source file base name
242 will be compiled separately.
250 A node for the &MSVC; precompiled header that will be
251 used when compiling object files.
252 This variable is ignored by tools other than &MSVC;.
253 When this variable is
254 defined, &SCons; will add options to the compiler command line to
255 cause it to use the precompiled header, and will also set up the
256 dependencies for the PCH file.
261 env['PCH'] = File('StdAfx.pch')
262 env['PCH'] = env.PCH('pch.cc')[0]
270 The command line used by the
272 builder to generated a precompiled header.
277 <cvar name="PCHCOMSTR">
280 The string displayed when generating a precompiled header.
281 If not set, then &cv-link-PCHCOM; (the command line) is displayed.
286 <cvar name="PCHPDBFLAGS">
289 A &consvar; that, when expanded,
290 adds the <option>/yD</option> flag to the command line
291 only if the &cv-link-PDB; &consvar; is set.
296 <cvar name="PCHSTOP">
299 This variable specifies how much of a source file is precompiled. This
300 variable is ignored by tools other than &MSVC;, or when
301 the PCH variable is not being used. When this variable is defined, it
302 must be a string that is the name of the header that
303 is included at the end of the precompiled portion of the source files, or
304 the empty string if the "#pragma hrdstop" construct is being used:
308 env['PCHSTOP'] = 'StdAfx.h'
316 The resource compiler used to build
317 a &MSVC; resource file.
325 The command line used to build
326 a &MSVC; resource file.
331 <cvar name="RCCOMSTR">
334 The string displayed when invoking the resource compiler
335 to build a &MSVC; resource file.
336 If this is not set, then &cv-link-RCCOM; (the command line) is displayed.
341 <cvar name="RCFLAGS">
344 The flags passed to the resource compiler by the &b-link-RES; builder.
349 <cvar name="RCINCFLAGS">
352 An automatically-generated &consvar;
353 containing the command-line options
354 for specifying directories to be searched
355 by the resource compiler.
356 The value of &cv-RCINCFLAGS; is created
357 by respectively prepending and appending
358 &cv-link-RCINCPREFIX; and &cv-link-RCINCSUFFIX;
359 to the beginning and end
360 of each directory in &cv-link-CPPPATH;.
365 <cvar name="RCINCPREFIX">
368 The prefix (flag) used to specify an include directory
369 on the resource compiler command line.
370 This will be prepended to the beginning of each directory
371 in the &cv-link-CPPPATH; &consvar;
372 when the &cv-link-RCINCFLAGS; variable is expanded.
377 <cvar name="RCINCSUFFIX">
380 The suffix used to specify an include directory
381 on the resource compiler command line.
382 This will be appended to the end of each directory
383 in the &cv-link-CPPPATH; &consvar;
384 when the &cv-link-RCINCFLAGS; variable is expanded.
389 <cvar name="MSVC_VERSION">
392 A string to select the preferred version of &MSVC;.
393 If the specified version is unavailable and/or unknown to &SCons;,
394 a warning is issued showing the versions actually discovered,
395 and the build will eventually fail indicating a missing compiler binary.
396 If &cv-MSVC_VERSION; is not set, &SCons; will (by default) select the
397 latest version of &MSVC; installed on your system
398 (excluding any preview versions).
403 In order to take effect, &cv-MSVC_VERSION; must be set before
404 the initial &MSVC; compiler discovery takes place.
405 Discovery happens, at the latest, during the first call to the
406 &f-link-Environment; function, unless a <parameter>tools</parameter>
407 list is specified which excludes the entire &MSVC; toolchain -
408 that is, omits <literal>"defaults"</literal>
409 and any specific tool module that refers to parts of the toolchain
410 (&t-link-msvc;, &t-link-mslink;, &t-link-masm;, &t-link-midl;
411 and &t-link-msvs;). In this case, detection is deferred until
412 any one of those tool modules is invoked manually.
413 The following two examples illustrate this:
417 # MSVC_VERSION set as Environment is created
418 env = Environment(MSVC_VERSION='14.2')
420 # Initialization deferred with empty tools, triggered manually
421 env = Environment(tools=[])
422 env['MSVC_VERSION'] = '14.2
430 The valid values for &cv-MSVC_VERSION; represent major versions
431 of the compiler, except that versions ending in <literal>Exp</literal>
432 refer to "Express" or "Express for Desktop" Visual Studio editions.
433 Values that do not look like a valid compiler version
434 <emphasis>string</emphasis> are not supported.
438 The following table shows the correspondence
439 of &cv-MSVC_VERSION; values to various version indicators
440 ('x' is used as a placeholder for
441 a single digit that can vary).
446 <colspec align="left" />
447 <colspec align="center" />
448 <colspec align="center" />
449 <colspec align="left" />
450 <colspec align="center" />
453 <entry> SCons Key </entry>
454 <entry> <literallayout>
456 Version </literallayout></entry>
457 <entry> <literal>_MSVC_VER</literal> </entry>
458 <entry> Visual Studio Product </entry>
459 <!--entry> <literallayout>
461 Product </literallayout></entry-->
462 <entry> <literallayout>
464 Visual Studio </literallayout></entry>
469 <entry> <literal>"14.3"</literal> </entry>
470 <entry> 14.3x </entry>
471 <entry> 193x </entry>
472 <entry> Visual Studio 2022 </entry>
473 <entry> 17.x, 17.1x </entry>
476 <entry> <literal>"14.2"</literal> </entry>
477 <entry> 14.2x </entry>
478 <entry> 192x </entry>
479 <entry> Visual Studio 2019 </entry>
480 <entry> 16.x, 16.1x </entry>
483 <entry> <literal>"14.1"</literal> </entry>
484 <entry> 14.1 or 14.1x </entry>
485 <entry> 191x </entry>
486 <entry> Visual Studio 2017 </entry>
487 <entry> 15.x </entry>
490 <entry> <literal>"14.1Exp"</literal> </entry>
491 <entry> 14.1 or 14.1x </entry>
492 <entry> 191x </entry>
493 <entry> Visual Studio 2017 Express </entry>
494 <entry> 15.x </entry>
497 <entry> <literal>"14.0"</literal> </entry>
498 <entry> 14.0 </entry>
499 <entry> 1900 </entry>
500 <entry> Visual Studio 2015 </entry>
501 <entry> 14.0 </entry>
504 <entry> <literal>"14.0Exp"</literal> </entry>
505 <entry> 14.0 </entry>
506 <entry> 1900 </entry>
507 <entry> Visual Studio 2015 Express </entry>
508 <entry> 14.0 </entry>
511 <entry> <literal>"12.0"</literal> </entry>
512 <entry> 12.0 </entry>
513 <entry> 1800 </entry>
514 <entry> Visual Studio 2013 </entry>
515 <entry> 12.0 </entry>
518 <entry> <literal>"12.0Exp"</literal> </entry>
519 <entry> 12.0 </entry>
520 <entry> 1800 </entry>
521 <entry> Visual Studio 2013 Express </entry>
522 <entry> 12.0 </entry>
525 <entry> <literal>"11.0"</literal> </entry>
526 <entry> 11.0 </entry>
527 <entry> 1700 </entry>
528 <entry> Visual Studio 2012 </entry>
529 <entry> 11.0 </entry>
532 <entry> <literal>"11.0Exp"</literal> </entry>
533 <entry> 11.0 </entry>
534 <entry> 1700 </entry>
535 <entry> Visual Studio 2012 Express </entry>
536 <entry> 11.0 </entry>
539 <entry> <literal>"10.0"</literal> </entry>
540 <entry> 10.0 </entry>
541 <entry> 1600 </entry>
542 <entry> Visual Studio 2010 </entry>
543 <entry> 10.0 </entry>
546 <entry> <literal>"10.0Exp"</literal> </entry>
547 <entry> 10.0 </entry>
548 <entry> 1600 </entry>
549 <entry> Visual C++ Express 2010 </entry>
550 <entry> 10.0 </entry>
553 <entry> <literal>"9.0"</literal> </entry>
555 <entry> 1500 </entry>
556 <entry> Visual Studio 2008 </entry>
560 <entry> <literal>"9.0Exp"</literal> </entry>
562 <entry> 1500 </entry>
563 <entry> Visual C++ Express 2008 </entry>
567 <entry> <literal>"8.0"</literal> </entry>
569 <entry> 1400 </entry>
570 <entry> Visual Studio 2005 </entry>
574 <entry> <literal>"8.0Exp"</literal> </entry>
576 <entry> 1400 </entry>
577 <entry> Visual C++ Express 2005 </entry>
581 <entry> <literal>"7.1"</literal> </entry>
583 <entry> 1300 </entry>
584 <entry> Visual Studio .NET 2003 </entry>
588 <entry> <literal>"7.0"</literal> </entry>
590 <entry> 1200 </entry>
591 <entry> Visual Studio .NET 2002 </entry>
595 <entry> <literal>"6.0"</literal> </entry>
597 <entry> 1100 </entry>
598 <entry> Visual Studio 6.0 </entry>
609 It is not necessary to install a Visual Studio IDE
610 to build with &SCons; (for example, you can install only
611 Build Tools), but when a Visual Studio IDE is installed,
612 additional builders such as &b-link-MSVSSolution; and
613 &b-link-MSVSProject; become available and correspond to
614 the specified versions.
618 Versions ending in <literal>Exp</literal> refer to historical
619 "Express" or "Express for Desktop" Visual Studio editions,
620 which had feature limitations compared to the full editions.
621 It is only necessary to specify the <literal>Exp</literal>
622 suffix to select the express edition when both express and
623 non-express editions of the same product are installed
624 simultaneously. The <literal>Exp</literal> suffix is unnecessary,
625 but accepted, when only the express edition is installed.
631 The compilation environment can be further or more precisely specified through the
632 use of several other &consvars;: see the descriptions of
633 &cv-link-MSVC_TOOLSET_VERSION;,
634 &cv-link-MSVC_SDK_VERSION;,
635 &cv-link-MSVC_USE_SCRIPT;,
636 &cv-link-MSVC_USE_SCRIPT_ARGS;,
637 and &cv-link-MSVC_USE_SETTINGS;.
643 <cvar name="MSVC_USE_SCRIPT">
646 Use a batch script to set up the &MSVC; compiler.
650 If set to the name of a Visual Studio <filename>.bat</filename> file
651 (e.g. <filename>vcvars.bat</filename>),
652 &SCons; will run that batch file instead of the auto-detected one,
653 and extract the relevant variables from the result (typically
654 <envar>%INCLUDE%</envar>,
655 <envar>%LIB%</envar>, and
656 <envar>%PATH%</envar>) for supplying to the build.
657 This can be useful to force the use of a compiler version that
658 &SCons; does not detect.
659 &cv-link-MSVC_USE_SCRIPT_ARGS; provides arguments passed to this script.
664 &cv-MSVC_USE_SCRIPT; to <constant>None</constant> bypasses the
665 Visual Studio autodetection entirely;
666 use this if you are running &SCons; in a Visual Studio <command>cmd</command>
667 window and importing the shell's environment variables - that
668 is, if you are sure everything is set correctly already and
669 you don't want &SCons; to change anything.
672 &cv-MSVC_USE_SCRIPT; ignores &cv-link-MSVC_VERSION; and &cv-link-TARGET_ARCH;.
675 <para><emphasis>Changed in version 4.4:</emphasis>
676 new &cv-link-MSVC_USE_SCRIPT_ARGS; provides a
677 way to pass arguments.
683 <cvar name="MSVC_USE_SCRIPT_ARGS">
686 Provides arguments passed to the script &cv-link-MSVC_USE_SCRIPT;.
689 <para><emphasis>New in version 4.4</emphasis></para>
694 <cvar name="MSVC_USE_SETTINGS">
697 Use a dictionary to set up the &MSVC; compiler.
701 &cv-MSVC_USE_SETTINGS; is ignored when &cv-link-MSVC_USE_SCRIPT; is defined
702 and/or when &cv-MSVC_USE_SETTINGS; is set to <constant>None</constant>.
706 The dictionary is used to populate the environment with the relevant variables
707 (typically <envar>%INCLUDE%</envar>, <envar>%LIB%</envar>, and <envar>%PATH%</envar>)
708 for supplying to the build. This can be useful to force the use of a compiler environment
709 that &SCons; does not configure correctly. This is an alternative to manually configuring
710 the environment when bypassing Visual Studio autodetection entirely by setting
711 &cv-link-MSVC_USE_SCRIPT; to <constant>None</constant>.
715 Here is an example of configuring a build environment using the &MSVC; compiler
716 included in the Microsoft SDK on a 64-bit host and building for a 64-bit architecture:
718 # Microsoft SDK 6.0 (MSVC 8.0): 64-bit host and 64-bit target
719 msvc_use_settings = {
721 "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0\\VC\\Bin\\x64",
722 "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0\\Bin\\x64",
723 "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0\\Bin",
724 "C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727",
725 "C:\\Windows\\system32",
727 "C:\\Windows\\System32\\Wbem",
728 "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\"
731 "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0\\VC\\Include",
732 "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0\\VC\\Include\\Sys",
733 "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0\\Include",
734 "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0\\Include\\gl",
737 "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0\\VC\\Lib\\x64",
738 "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0\\Lib\\x64",
741 "VSCMD_ARG_app_plat": [],
743 "VCToolsInstallDir": []
746 # Specifying MSVC_VERSION is recommended
747 env = Environment(MSVC_VERSION='8.0', MSVC_USE_SETTINGS=msvc_use_settings)
752 Important usage details:
756 &cv-MSVC_USE_SETTINGS; must be passed as an argument to the &f-link-Environment;
757 constructor when an msvc tool (e.g., &t-link-msvc;, &t-link-msvs;, etc.) is
758 loaded via the default tools list or via a tools list passed to the
759 &f-link-Environment; constructor.
760 Otherwise, &cv-MSVC_USE_SETTINGS; must be set before the first msvc tool is
761 loaded into the environment.
766 The dictionary content requirements are based on the internal msvc implementation and
767 therefore may change at any time.
769 The burden is on the user to ensure the dictionary contents are minimally sufficient to
770 ensure successful builds.
778 <para><emphasis>New in version 4.4</emphasis></para>
783 <!-- This has moved to Platform/Platform.xml to avoid duplication
784 <cvar name="HOST_ARCH">
792 <!-- This has moved to Platform/Platform.xml to avoid duplication
793 <cvar name="TARGET_ARCH">
801 <cvar name="MSVC_UWP_APP">
804 Build with the Universal Windows Platform (UWP) application &MSVC; libraries.
808 The valid values for &cv-MSVC_UWP_APP; are: <literal>True</literal>,
809 <literal>'1'</literal>, <literal>False</literal>, <literal>'0'</literal>,
810 or <literal>None</literal>.
814 When &cv-MSVC_UWP_APP; is enabled (i.e., <literal>True</literal> or
815 <literal>'1'</literal>), the &MSVC; environment will be set up to point
816 to the Windows Store compatible libraries and &MSVC; runtimes. In doing so,
817 any libraries that are built will be able to be used in a UWP App and published
818 to the Windows Store.
819 <!-- This flag will only have an effect with Visual Studio 2015 or later. -->
820 <!-- This variable must be passed as an argument to the Environment()
821 constructor; setting it later has no effect. -->
825 An exception is raised when any of the following conditions are satisfied:
828 &cv-MSVC_UWP_APP; is enabled for Visual Studio 2013 and earlier.
831 &cv-MSVC_UWP_APP; is enabled and a UWP argument is specified in
832 &cv-link-MSVC_SCRIPT_ARGS;. Multiple UWP declarations via &cv-MSVC_UWP_APP;
833 and &cv-link-MSVC_SCRIPT_ARGS; are not allowed.
839 Example - A Visual Studio 2022 build for the Universal Windows Platform:
841 env = Environment(MSVC_VERSION='14.3', MSVC_UWP_APP=True)
846 Important usage details:
850 &cv-MSVC_UWP_APP; must be passed as an argument to the &f-link-Environment;
851 constructor when an msvc tool (e.g., &t-link-msvc;, &t-link-msvs;, etc.) is
852 loaded via the default tools list or via a tools list passed to the
853 &f-link-Environment; constructor.
854 Otherwise, &cv-MSVC_UWP_APP; must be set before the first msvc tool is
855 loaded into the environment.
860 The existence of the UWP libraries is not verified when &cv-MSVC_UWP_APP; is enabled
861 which could result in build failures.
863 The burden is on the user to ensure the requisite UWP libraries are installed.
872 <cvar name="VSWHERE">
875 Specify the location of <command>vswhere.exe</command>.
879 The <command>vswhere.exe</command> executable is distributed with
880 Microsoft Visual Studio and Build Tools since the 2017 edition,
881 but is also available as a standalone installation.
882 It allows queries to obtain detailed information about
883 installations of 2017 and later editions.
884 &SCons; makes use of this information to determine
885 the state of compiler support for those editions.
888 Setting the &cv-VSWHERE; variable to the path to a specific
889 <command>vswhere.exe</command> binary
890 causes &SCons; to use that binary.
891 If not set, &SCons; will search for one,
892 looking in the following locations in order,
893 using the first found
894 (&cv-VSWHERE; is updated with the location):
897 <simplelist type="vert">
898 <member><literal>%ProgramFiles(x86)%\Microsoft Visual Studio\Installer</literal></member>
899 <member><literal>%ProgramFiles%\Microsoft Visual Studio\Installer</literal></member>
900 <member><literal>%ChocolateyInstall%\bin</literal></member>
901 <member><literal>%LOCALAPPDATA%\Microsoft\WinGet\Links</literal></member>
902 <member><literal>%USERPROFILE%\scoop\shims</literal></member>
903 <member><literal>%SCOOP%\shims</literal></member>
909 In order to take effect, &cv-VSWHERE; must be set before
910 the initial &MSVC; compiler discovery takes place.
911 Discovery happens, at the latest, during the first call to the
912 &f-link-Environment; function, unless a <parameter>tools</parameter>
913 list is specified which excludes the entire &MSVC; toolchain -
914 that is, omits <literal>"defaults"</literal>
915 and any specific tool module that refers to parts of the toolchain
916 (&t-link-msvc;, &t-link-mslink;, &t-link-masm;, &t-link-midl;
917 and &t-link-msvs;). In this case, detection is deferred until
918 any one of those tool modules is invoked manually.
919 The following two examples illustrate this:
923 # VSWHERE set as Environment is created
924 env = Environment(VSWHERE='c:/my/path/to/vswhere')
926 # Initialization deferred with empty tools, triggered manually
927 env = Environment(tools=[])
928 env['VSWHERE'] = r'c:/my/vswhere/install/location/vswhere.exe'
938 <cvar name="MSVC_NOTFOUND_POLICY">
941 Specify the &scons; behavior when the &MSVC; compiler is not detected.
945 The &cv-MSVC_NOTFOUND_POLICY; specifies the &scons; behavior when no msvc versions are detected or
946 when the requested msvc version is not detected.
950 The valid values for &cv-MSVC_NOTFOUND_POLICY; and the corresponding &scons; behavior are:
956 <term><parameter>'Error' or 'Exception'</parameter></term>
959 Raise an exception when no msvc versions are detected or when the requested msvc version is not detected.
965 <term><parameter>'Warning' or 'Warn'</parameter></term>
968 Issue a warning and continue when no msvc versions are detected or when the requested msvc version is not detected.
969 Depending on usage, this could result in build failure(s).
975 <term><parameter>'Ignore' or 'Suppress'</parameter></term>
978 Take no action and continue when no msvc versions are detected or when the requested msvc version is not detected.
979 Depending on usage, this could result in build failure(s).
987 Note: in addition to the camel case values shown above, lower case and upper case values are accepted as well.
991 The &cv-MSVC_NOTFOUND_POLICY; is applied when any of the following conditions are satisfied:
994 &cv-MSVC_VERSION; is specified, the default tools list is implicitly defined (i.e., the tools list is not specified),
995 and the default tools list contains one or more of the msvc tools.
998 &cv-MSVC_VERSION; is specified, the default tools list is explicitly specified (e.g., <literal>tools=['default']</literal>),
999 and the default tools list contains one or more of the msvc tools.
1002 A non-default tools list is specified that contains one or more of the msvc tools (e.g., <literal>tools=['msvc', 'mslink']</literal>).
1008 The &cv-MSVC_NOTFOUND_POLICY; is ignored when any of the following conditions are satisfied:
1011 &cv-MSVC_VERSION; is not specified and the default tools list is implicitly defined (i.e., the tools list is not specified).
1014 &cv-MSVC_VERSION; is not specified and the default tools list is explicitly specified (e.g., <literal>tools=['default']</literal>).
1017 A non-default tool list is specified that does not contain any of the msvc tools (e.g., <literal>tools=['mingw']</literal>).
1023 Important usage details:
1027 &cv-MSVC_NOTFOUND_POLICY; must be passed as an argument to the &f-link-Environment;
1028 constructor when an msvc tool (e.g., &t-link-msvc;, &t-link-msvs;, etc.) is
1029 loaded via the default tools list or via a tools list passed to the
1030 &f-link-Environment; constructor.
1031 Otherwise, &cv-MSVC_NOTFOUND_POLICY; must be set before the first msvc tool is
1032 loaded into the environment.
1039 When &cv-MSVC_NOTFOUND_POLICY; is not specified, the default &scons; behavior is to issue a warning and continue
1040 subject to the conditions listed above. The default &scons; behavior may change in the future.
1043 <para><emphasis>New in version 4.4</emphasis></para>
1048 <cvar name="MSVC_SCRIPTERROR_POLICY">
1051 Specify the &scons; behavior when &MSVC; batch file errors are detected.
1055 The &cv-MSVC_SCRIPTERROR_POLICY; specifies the &scons; behavior when msvc batch file errors are
1057 When &cv-MSVC_SCRIPTERROR_POLICY; is not specified, the default &scons; behavior is to suppress
1058 msvc batch file error messages.
1061 The root cause of msvc build failures may be difficult to diagnose. In these situations, setting
1062 the &scons; behavior to issue a warning when msvc batch file errors are detected <emphasis>may</emphasis>
1063 produce additional diagnostic information.
1067 The valid values for &cv-MSVC_SCRIPTERROR_POLICY; and the corresponding &scons; behavior are:
1073 <term><parameter>'Error' or 'Exception'</parameter></term>
1076 Raise an exception when msvc batch file errors are detected.
1082 <term><parameter>'Warning' or 'Warn'</parameter></term>
1085 Issue a warning when msvc batch file errors are detected.
1091 <term><parameter>'Ignore' or 'Suppress'</parameter></term>
1094 Suppress msvc batch file error messages.
1097 <para><emphasis>New in version 4.4</emphasis></para>
1105 Note: in addition to the camel case values shown above, lower case and upper case values are accepted as well.
1109 Example 1 - A Visual Studio 2022 build with user-defined script arguments:
1111 env = environment(MSVC_VERSION='14.3', MSVC_SCRIPT_ARGS=['8.1', 'store', '-vcvars_ver=14.1'])
1112 env.Program('hello', ['hello.c'], CCFLAGS='/MD', LIBS=['kernel32', 'user32', 'runtimeobject'])
1117 Example 1 - Output fragment:
1120 link /nologo /OUT:_build001\hello.exe kernel32.lib user32.lib runtimeobject.lib _build001\hello.obj
1121 LINK : fatal error LNK1104: cannot open file 'MSVCRT.lib'
1127 Example 2 - A Visual Studio 2022 build with user-defined script arguments and the script error policy set
1128 to issue a warning when msvc batch file errors are detected:
1130 env = environment(MSVC_VERSION='14.3', MSVC_SCRIPT_ARGS=['8.1', 'store', '-vcvars_ver=14.1'], MSVC_SCRIPTERROR_POLICY='warn')
1131 env.Program('hello', ['hello.c'], CCFLAGS='/MD', LIBS=['kernel32', 'user32', 'runtimeobject'])
1136 Example 2 - Output fragment:
1139 scons: warning: vc script errors detected:
1140 [ERROR:vcvars.bat] The UWP Application Platform requires a Windows 10 SDK.
1141 [ERROR:vcvars.bat] WindowsSdkDir = "C:\Program Files (x86)\Windows Kits\8.1\"
1142 [ERROR:vcvars.bat] host/target architecture is not supported : { x64 , x64 }
1144 link /nologo /OUT:_build001\hello.exe kernel32.lib user32.lib runtimeobject.lib _build001\hello.obj
1145 LINK : fatal error LNK1104: cannot open file 'MSVCRT.lib'
1150 Important usage details:
1154 &cv-MSVC_SCRIPTERROR_POLICY; must be passed as an argument to the &f-link-Environment;
1155 constructor when an msvc tool (e.g., &t-link-msvc;, &t-link-msvs;, etc.) is
1156 loaded via the default tools list or via a tools list passed to the
1157 &f-link-Environment; constructor.
1158 Otherwise, &cv-MSVC_SCRIPTERROR_POLICY; must be set before the first msvc tool is
1159 loaded into the environment.
1163 Due to &scons; implementation details, not all Windows system environment variables are propagated
1164 to the environment in which the msvc batch file is executed. Depending on Visual Studio version
1165 and installation options, non-fatal msvc batch file error messages may be generated for ancillary
1166 tools which may not affect builds with the msvc compiler. For this reason, caution is recommended
1167 when setting the script error policy to raise an exception (e.g., <literal>'Error'</literal>).
1173 <para><emphasis>New in version 4.4</emphasis></para>
1178 <cvar name="MSVC_SCRIPT_ARGS">
1181 Pass user-defined arguments to the &MSVC; batch file determined via autodetection.
1185 &cv-MSVC_SCRIPT_ARGS; is available for msvc batch file arguments that do not have first-class support
1186 via &consvars; or when there is an issue with the appropriate &consvar; validation.
1187 When available, it is recommended to use the appropriate &consvars; (e.g., &cv-link-MSVC_TOOLSET_VERSION;)
1188 rather than &cv-MSVC_SCRIPT_ARGS; arguments.
1192 The valid values for &cv-MSVC_SCRIPT_ARGS; are: <literal>None</literal>, a string,
1193 or a list of strings.
1197 The &cv-MSVC_SCRIPT_ARGS; value is converted to a scalar string (i.e., "flattened").
1198 The resulting scalar string, if not empty, is passed as an argument to the msvc batch file determined
1199 via autodetection subject to the validation conditions listed below.
1203 &cv-MSVC_SCRIPT_ARGS; is ignored when the value is <literal>None</literal> and when the
1204 result from argument conversion is an empty string. The validation conditions below do not apply.
1208 An exception is raised when any of the following conditions are satisfied:
1212 &cv-MSVC_SCRIPT_ARGS; is specified for Visual Studio 2013 and earlier.
1216 Multiple SDK version arguments (e.g., <literal>'10.0.20348.0'</literal>) are specified
1217 in &cv-MSVC_SCRIPT_ARGS;.
1221 &cv-link-MSVC_SDK_VERSION; is specified and an SDK version argument
1222 (e.g., <literal>'10.0.20348.0'</literal>) is specified in &cv-MSVC_SCRIPT_ARGS;.
1223 Multiple SDK version declarations via &cv-link-MSVC_SDK_VERSION; and &cv-MSVC_SCRIPT_ARGS;
1228 Multiple toolset version arguments (e.g., <literal>'-vcvars_ver=14.29'</literal>)
1229 are specified in &cv-MSVC_SCRIPT_ARGS;.
1233 &cv-link-MSVC_TOOLSET_VERSION; is specified and a toolset version argument
1234 (e.g., <literal>'-vcvars_ver=14.29'</literal>) is specified in &cv-MSVC_SCRIPT_ARGS;.
1235 Multiple toolset version declarations via &cv-link-MSVC_TOOLSET_VERSION; and
1236 &cv-MSVC_SCRIPT_ARGS; are not allowed.
1240 Multiple spectre library arguments (e.g., <literal>'-vcvars_spectre_libs=spectre'</literal>)
1241 are specified in &cv-MSVC_SCRIPT_ARGS;.
1245 &cv-link-MSVC_SPECTRE_LIBS; is enabled and a spectre library argument
1246 (e.g., <literal>'-vcvars_spectre_libs=spectre'</literal>) is specified in
1247 &cv-MSVC_SCRIPT_ARGS;. Multiple spectre library declarations via &cv-link-MSVC_SPECTRE_LIBS;
1248 and &cv-MSVC_SCRIPT_ARGS; are not allowed.
1252 Multiple UWP arguments (e.g., <literal>uwp</literal> or <literal>store</literal>) are specified
1253 in &cv-MSVC_SCRIPT_ARGS;.
1257 &cv-link-MSVC_UWP_APP; is enabled and a UWP argument (e.g., <literal>uwp</literal> or
1258 <literal>store</literal>) is specified in &cv-MSVC_SCRIPT_ARGS;. Multiple UWP declarations
1259 via &cv-link-MSVC_UWP_APP; and &cv-MSVC_SCRIPT_ARGS; are not allowed.
1266 Example 1 - A Visual Studio 2022 build with an SDK version and a toolset version
1267 specified with a string argument:
1269 env = Environment(MSVC_VERSION='14.3', MSVC_SCRIPT_ARGS='10.0.20348.0 -vcvars_ver=14.29.30133')
1274 Example 2 - A Visual Studio 2022 build with an SDK version and a toolset version
1275 specified with a list argument:
1277 env = Environment(MSVC_VERSION='14.3', MSVC_SCRIPT_ARGS=['10.0.20348.0', '-vcvars_ver=14.29.30133'])
1282 Important usage details:
1286 &cv-MSVC_SCRIPT_ARGS; must be passed as an argument to the &f-link-Environment;
1287 constructor when an msvc tool (e.g., &t-link-msvc;, &t-link-msvs;, etc.) is
1288 loaded via the default tools list or via a tools list passed to the
1289 &f-link-Environment; constructor.
1290 Otherwise, &cv-MSVC_SCRIPT_ARGS; must be set before the first msvc tool is
1291 loaded into the environment.
1295 Other than checking for multiple declarations as described above, &cv-MSVC_SCRIPT_ARGS; arguments
1301 Erroneous, inconsistent, and/or version incompatible &cv-MSVC_SCRIPT_ARGS; arguments are likely
1302 to result in build failures for reasons that are not readily apparent and may be difficult to diagnose.
1304 The burden is on the user to ensure that the arguments provided to the msvc batch file are valid, consistent
1305 and compatible with the version of msvc selected.
1311 <para><emphasis>New in version 4.4</emphasis></para>
1316 <cvar name="MSVC_SDK_VERSION">
1319 Build with a specific version of the Microsoft Software Development Kit (SDK).
1323 The valid values for &cv-MSVC_SDK_VERSION; are: <literal>None</literal>
1324 or a string containing the requested SDK version (e.g., <literal>'10.0.20348.0'</literal>).
1328 &cv-MSVC_SDK_VERSION; is ignored when the value is <literal>None</literal> and when
1329 the value is an empty string. The validation conditions below do not apply.
1333 An exception is raised when any of the following conditions are satisfied:
1337 &cv-MSVC_SDK_VERSION; is specified for Visual Studio 2013 and earlier.
1341 &cv-MSVC_SDK_VERSION; is specified and an SDK version argument is specified in
1342 &cv-link-MSVC_SCRIPT_ARGS;. Multiple SDK version declarations via &cv-MSVC_SDK_VERSION;
1343 and &cv-link-MSVC_SCRIPT_ARGS; are not allowed.
1347 The &cv-MSVC_SDK_VERSION; specified does not match any of the supported formats:
1350 <literal>'10.0.XXXXX.Y'</literal> [SDK 10.0]
1353 <literal>'8.1'</literal> [SDK 8.1]
1359 The system folder for the corresponding &cv-MSVC_SDK_VERSION; version is not found.
1360 The requested SDK version does not appear to be installed.
1364 The &cv-MSVC_SDK_VERSION; version does not appear to support the requested platform
1365 type (i.e., <literal>UWP</literal> or <literal>Desktop</literal>). The requested SDK version
1366 platform type components do not appear to be installed.
1370 The &cv-MSVC_SDK_VERSION; version is <literal>8.1</literal>, the platform type is
1371 <literal>UWP</literal>, and the build tools selected are from Visual Studio 2017
1372 and later (i.e., &cv-link-MSVC_VERSION; must be '14.0' or &cv-link-MSVC_TOOLSET_VERSION;
1380 Example 1 - A Visual Studio 2022 build with a specific Windows SDK version:
1382 env = Environment(MSVC_VERSION='14.3', MSVC_SDK_VERSION='10.0.20348.0')
1387 Example 2 - A Visual Studio 2022 build with a specific SDK version for the Universal Windows Platform:
1389 env = Environment(MSVC_VERSION='14.3', MSVC_SDK_VERSION='10.0.20348.0', MSVC_UWP_APP=True)
1394 Important usage details:
1398 &cv-MSVC_SDK_VERSION; must be passed as an argument to the &f-link-Environment;
1399 constructor when an msvc tool (e.g., &t-link-msvc;, &t-link-msvs;, etc.) is
1400 loaded via the default tools list or via a tools list passed to the
1401 &f-link-Environment; constructor.
1402 Otherwise, &cv-MSVC_SDK_VERSION; must be set before the first msvc tool is
1403 loaded into the environment.
1408 Should a SDK 10.0 version be installed that does not follow the naming scheme above, the
1409 SDK version will need to be specified via &cv-link-MSVC_SCRIPT_ARGS; until the version number
1410 validation format can be extended.
1415 Should an exception be raised indicating that the SDK version is not found, verify that
1416 the requested SDK version is installed with the necessary platform type components.
1420 There is a known issue with the Microsoft libraries when the target architecture is
1421 <literal>ARM64</literal> and a Windows 11 SDK (version <literal>'10.0.22000.0'</literal> and later) is used
1422 with the <literal>v141</literal> build tools and older <literal>v142</literal> toolsets
1423 (versions <literal>'14.28.29333'</literal> and earlier). Should build failures arise with these combinations
1424 of settings due to unresolved symbols in the Microsoft libraries, &cv-MSVC_SDK_VERSION; may be employed to
1425 specify a Windows 10 SDK (e.g., <literal>'10.0.20348.0'</literal>) for the build.
1431 <para><emphasis>New in version 4.4</emphasis></para>
1436 <cvar name="MSVC_TOOLSET_VERSION">
1439 Build with a specific &MSVC; toolset version.
1443 Specifying &cv-MSVC_TOOLSET_VERSION; does not affect the autodetection and selection
1444 of msvc instances. The &cv-MSVC_TOOLSET_VERSION; is applied <emphasis>after</emphasis>
1445 an msvc instance is selected. This could be the default version of msvc if &cv-link-MSVC_VERSION;
1450 The valid values for &cv-MSVC_TOOLSET_VERSION; are: <literal>None</literal>
1451 or a string containing the requested toolset version (e.g., <literal>'14.29'</literal>).
1455 &cv-MSVC_TOOLSET_VERSION; is ignored when the value is <literal>None</literal> and when
1456 the value is an empty string. The validation conditions below do not apply.
1460 An exception is raised when any of the following conditions are satisfied:
1464 &cv-MSVC_TOOLSET_VERSION; is specified for Visual Studio 2015 and earlier.
1468 &cv-MSVC_TOOLSET_VERSION; is specified and a toolset version argument is specified in
1469 &cv-link-MSVC_SCRIPT_ARGS;. Multiple toolset version declarations via &cv-MSVC_TOOLSET_VERSION;
1470 and &cv-link-MSVC_SCRIPT_ARGS; are not allowed.
1475 The &cv-MSVC_TOOLSET_VERSION; specified does not match any of the supported formats:
1481 <literal>'XX.Y'</literal>
1485 <literal>'XX.YY'</literal>
1489 <literal>'XX.YY.ZZZZZ'</literal>
1493 <literal>'XX.YY.Z'</literal> to <literal>'XX.YY.ZZZZ'</literal>
1495 [&scons; extension not directly supported by the msvc batch files and may be removed in the future]
1500 <literal>'XX.YY.ZZ.N'</literal> [SxS format]
1504 <literal>'XX.YY.ZZ.NN'</literal> [SxS format]
1512 The major msvc version prefix (i.e., <literal>'XX.Y'</literal>) of the &cv-MSVC_TOOLSET_VERSION; specified
1513 is for Visual Studio 2013 and earlier (e.g., <literal>'12.0'</literal>).
1517 The major msvc version prefix (i.e., <literal>'XX.Y'</literal>) of the &cv-MSVC_TOOLSET_VERSION; specified
1518 is greater than the msvc version selected (e.g., <literal>'99.0'</literal>).
1522 A system folder for the corresponding &cv-MSVC_TOOLSET_VERSION; version is not found.
1523 The requested toolset version does not appear to be installed.
1530 Toolset selection details:
1534 When &cv-MSVC_TOOLSET_VERSION; is not an SxS version number or a full toolset version number:
1535 the first toolset version, ranked in descending order, that matches the &cv-MSVC_TOOLSET_VERSION;
1540 When &cv-MSVC_TOOLSET_VERSION; is specified using the major msvc version prefix
1541 (i.e., <literal>'XX.Y'</literal>) and the major msvc version is that of the latest release of
1542 Visual Studio, the selected toolset version may not be the same as the default &MSVC; toolset version.
1544 In the latest release of Visual Studio, the default &MSVC; toolset version is not necessarily the
1545 toolset with the largest version number.
1552 Example 1 - A default Visual Studio build with a partial toolset version specified:
1554 env = Environment(MSVC_TOOLSET_VERSION='14.2')
1559 Example 2 - A default Visual Studio build with a partial toolset version specified:
1561 env = Environment(MSVC_TOOLSET_VERSION='14.29')
1566 Example 3 - A Visual Studio 2022 build with a full toolset version specified:
1568 env = Environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.29.30133')
1573 Example 4 - A Visual Studio 2022 build with an SxS toolset version specified:
1575 env = Environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.29.16.11')
1580 Important usage details:
1584 &cv-MSVC_TOOLSET_VERSION; must be passed as an argument to the &f-link-Environment;
1585 constructor when an msvc tool (e.g., &t-link-msvc;, &t-link-msvs;, etc.) is
1586 loaded via the default tools list or via a tools list passed to the
1587 &f-link-Environment; constructor.
1588 Otherwise, &cv-MSVC_TOOLSET_VERSION; must be set before the first msvc tool is
1589 loaded into the environment.
1594 The existence of the toolset host architecture and target architecture folders are not verified
1595 when &cv-MSVC_TOOLSET_VERSION; is specified which could result in build failures.
1597 The burden is on the user to ensure the requisite toolset target architecture build tools are installed.
1603 <para><emphasis>New in version 4.4</emphasis></para>
1608 <cvar name="MSVC_SPECTRE_LIBS">
1611 Build with the spectre-mitigated &MSVC; libraries.
1615 The valid values for &cv-MSVC_SPECTRE_LIBS; are: <literal>True</literal>,
1616 <literal>False</literal>, or <literal>None</literal>.
1620 When &cv-MSVC_SPECTRE_LIBS; is enabled (i.e., <literal>True</literal>),
1621 the &MSVC; environment will include the paths to the spectre-mitigated implementations
1622 of the &MSVC; libraries.
1626 An exception is raised when any of the following conditions are satisfied:
1630 &cv-MSVC_SPECTRE_LIBS; is enabled for Visual Studio 2015 and earlier.
1634 &cv-MSVC_SPECTRE_LIBS; is enabled and a spectre library argument is specified in
1635 &cv-link-MSVC_SCRIPT_ARGS;. Multiple spectre library declarations via &cv-MSVC_SPECTRE_LIBS;
1636 and &cv-link-MSVC_SCRIPT_ARGS; are not allowed.
1640 &cv-MSVC_SPECTRE_LIBS; is enabled and the platform type is <literal>UWP</literal>. There
1641 are no spectre-mitigated libraries for Universal Windows Platform (UWP) applications or
1649 Example - A Visual Studio 2022 build with spectre mitigated &MSVC; libraries:
1651 env = Environment(MSVC_VERSION='14.3', MSVC_SPECTRE_LIBS=True)
1656 Important usage details:
1660 &cv-MSVC_SPECTRE_LIBS; must be passed as an argument to the &f-link-Environment;
1661 constructor when an msvc tool (e.g., &t-link-msvc;, &t-link-msvs;, etc.) is
1662 loaded via the default tools list or via a tools list passed to the
1663 &f-link-Environment; constructor.
1664 Otherwise, &cv-MSVC_SPECTRE_LIBS; must be set before the first msvc tool is
1665 loaded into the environment.
1669 Additional compiler switches (e.g., <literal>/Qspectre</literal>) are necessary for including
1670 spectre mitigations when building user artifacts. Refer to the Visual Studio documentation for
1676 The existence of the spectre libraries host architecture and target architecture folders are not
1677 verified when &cv-MSVC_SPECTRE_LIBS; is enabled which could result in build failures.
1679 The burden is on the user to ensure the requisite libraries with spectre mitigations are installed.
1685 <para><emphasis>New in version 4.4</emphasis></para>