@@ -94,10 +94,14 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
94
94
// If the VC environment hasn't been configured (perhaps because the user
95
95
// did not run vcvarsall), try to build a consistent link environment. If
96
96
// the environment variable is set however, assume the user knows what
97
- // they're doing. If the user passes /vctoolsdir or /winsdkdir, trust that
98
- // over env vars.
99
- if (const Arg *A = Args.getLastArg (options::OPT__SLASH_diasdkdir,
100
- options::OPT__SLASH_winsysroot)) {
97
+ // they're doing. If the user passes /vctoolsdir or /winsdkdir or any of the
98
+ // other Windows SDK options, trust that over env vars.
99
+ const Arg *A = Args.getLastArg (options::OPT__SLASH_vctoolsdir,
100
+ options::OPT__SLASH_vctoolsversion,
101
+ options::OPT__SLASH_winsysroot,
102
+ options::OPT__SLASH_winsdkdir,
103
+ options::OPT__SLASH_winsdkversion);
104
+ if (A) {
101
105
// cl.exe doesn't find the DIA SDK automatically, so this too requires
102
106
// explicit flags and doesn't automatically look in "DIA SDK" relative
103
107
// to the path we found for VCToolChainPath.
@@ -110,19 +114,15 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
110
114
llvm::archToLegacyVCArch (TC.getArch ()));
111
115
CmdArgs.push_back (Args.MakeArgString (Twine (" -libpath:" ) + DIAPath));
112
116
}
113
- if (!llvm::sys::Process::GetEnv (" LIB" ) ||
114
- Args.getLastArg (options::OPT__SLASH_vctoolsdir,
115
- options::OPT__SLASH_winsysroot)) {
117
+ if (!llvm::sys::Process::GetEnv (" LIB" ) || A) {
116
118
CmdArgs.push_back (Args.MakeArgString (
117
119
Twine (" -libpath:" ) +
118
120
TC.getSubDirectoryPath (llvm::SubDirectoryType::Lib)));
119
121
CmdArgs.push_back (Args.MakeArgString (
120
122
Twine (" -libpath:" ) +
121
123
TC.getSubDirectoryPath (llvm::SubDirectoryType::Lib, " atlmfc" )));
122
124
}
123
- if (!llvm::sys::Process::GetEnv (" LIB" ) ||
124
- Args.getLastArg (options::OPT__SLASH_winsdkdir,
125
- options::OPT__SLASH_winsysroot)) {
125
+ if (!llvm::sys::Process::GetEnv (" LIB" ) || A) {
126
126
if (TC.useUniversalCRT ()) {
127
127
std::string UniversalCRTLibPath;
128
128
if (TC.getUniversalCRTLibraryPath (Args, UniversalCRTLibPath))
@@ -677,9 +677,18 @@ void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
677
677
AddSystemIncludesFromEnv (Var);
678
678
}
679
679
680
+ // Check if the user has explicitly set a vctoolsdir or any of the
681
+ // Windows SDK options. If so, we assume the user knows what they're doing
682
+ // and don't try to find the include directories automatically.
683
+ // If not, we try to find the include directories automatically.
684
+ const Arg *A = DriverArgs.getLastArg (options::OPT__SLASH_vctoolsdir,
685
+ options::OPT__SLASH_vctoolsversion,
686
+ options::OPT__SLASH_winsysroot,
687
+ options::OPT__SLASH_winsdkdir,
688
+ options::OPT__SLASH_winsdkversion);
689
+
680
690
// Add DIA SDK include if requested.
681
- if (const Arg *A = DriverArgs.getLastArg (options::OPT__SLASH_diasdkdir,
682
- options::OPT__SLASH_winsysroot)) {
691
+ if (A) {
683
692
// cl.exe doesn't find the DIA SDK automatically, so this too requires
684
693
// explicit flags and doesn't automatically look in "DIA SDK" relative
685
694
// to the path we found for VCToolChainPath.
@@ -694,9 +703,9 @@ void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
694
703
return ;
695
704
696
705
// Honor %INCLUDE% and %EXTERNAL_INCLUDE%. It should have essential search
697
- // paths set by vcvarsall.bat. Skip if the user expressly set a vctoolsdir.
698
- if (!DriverArgs. getLastArg ( options::OPT__SLASH_vctoolsdir,
699
- options::OPT__SLASH_winsysroot) ) {
706
+ // paths set by vcvarsall.bat. Skip if the user expressly set any of the
707
+ // Windows SDK options.
708
+ if (!A ) {
700
709
bool Found = AddSystemIncludesFromEnv (" INCLUDE" );
701
710
Found |= AddSystemIncludesFromEnv (" EXTERNAL_INCLUDE" );
702
711
if (Found)
0 commit comments