LLVM  16.0.0git
MSVCPaths.h
Go to the documentation of this file.
1 //===-- MSVCPaths.h - MSVC path-parsing helpers -----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_WINDOWSDRIVER_MSVCPATHS_H
10 #define LLVM_WINDOWSDRIVER_MSVCPATHS_H
11 
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/ADT/SmallString.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/Triple.h"
16 #include <string>
17 
18 namespace llvm {
19 
20 namespace vfs {
21 class FileSystem;
22 }
23 
24 enum class SubDirectoryType {
25  Bin,
26  Include,
27  Lib,
28 };
29 
30 enum class ToolsetLayout {
31  OlderVS,
34 };
35 
36 // Windows SDKs and VC Toolchains group their contents into subdirectories based
37 // on the target architecture. This function converts an llvm::Triple::ArchType
38 // to the corresponding subdirectory name.
40 
41 // Similar to the above function, but for Visual Studios before VS2017.
43 
44 // Similar to the above function, but for DevDiv internal builds.
46 
47 bool appendArchToWindowsSDKLibPath(int SDKMajor, llvm::SmallString<128> LibPath,
49  std::string &path);
50 
51 // Get the path to a specific subdirectory in the current toolchain for
52 // a given target architecture.
53 // VS2017 changed the VC toolchain layout, so this should be used instead
54 // of hardcoding paths.
55 std::string getSubDirectoryPath(SubDirectoryType Type, ToolsetLayout VSLayout,
56  const std::string &VCToolChainPath,
57  llvm::Triple::ArchType TargetArch,
58  llvm::StringRef SubdirParent = "");
59 
60 // Check if the Include path of a specified version of Visual Studio contains
61 // specific header files. If not, they are probably shipped with Universal CRT.
62 bool useUniversalCRT(ToolsetLayout VSLayout, const std::string &VCToolChainPath,
63  llvm::Triple::ArchType TargetArch,
65 
66 /// Get Windows SDK installation directory.
67 bool getWindowsSDKDir(vfs::FileSystem &VFS,
69  llvm::Optional<llvm::StringRef> WinSdkVersion,
71  std::string &Path, int &Major,
72  std::string &WindowsSDKIncludeVersion,
73  std::string &WindowsSDKLibVersion);
74 
75 bool getUniversalCRTSdkDir(vfs::FileSystem &VFS,
77  llvm::Optional<llvm::StringRef> WinSdkVersion,
79  std::string &Path,
80  std::string &UCRTVersion);
81 
82 // Check command line arguments to try and find a toolchain.
84  vfs::FileSystem &VFS, llvm::Optional<llvm::StringRef> VCToolsDir,
85  llvm::Optional<llvm::StringRef> VCToolsVersion,
86  llvm::Optional<llvm::StringRef> WinSysRoot, std::string &Path,
87  ToolsetLayout &VSLayout);
88 
89 // Check various environment variables to try and find a toolchain.
90 bool findVCToolChainViaEnvironment(vfs::FileSystem &VFS, std::string &Path,
91  ToolsetLayout &VSLayout);
92 
93 // Query the Setup Config server for installs, then pick the newest version
94 // and find its default VC toolchain.
95 // This is the preferred way to discover new Visual Studios, as they're no
96 // longer listed in the registry.
97 bool findVCToolChainViaSetupConfig(vfs::FileSystem &VFS, std::string &Path,
98  ToolsetLayout &VSLayout);
99 
100 // Look in the registry for Visual Studio installs, and use that to get
101 // a toolchain path. VS2017 and newer don't get added to the registry.
102 // So if we find something here, we know that it's an older version.
103 bool findVCToolChainViaRegistry(std::string &Path, ToolsetLayout &VSLayout);
104 
105 } // namespace llvm
106 
107 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::appendArchToWindowsSDKLibPath
bool appendArchToWindowsSDKLibPath(int SDKMajor, llvm::SmallString< 128 > LibPath, llvm::Triple::ArchType Arch, std::string &path)
Definition: MSVCPaths.cpp:310
Optional.h
llvm::archToLegacyVCArch
const char * archToLegacyVCArch(llvm::Triple::ArchType Arch)
Definition: MSVCPaths.cpp:278
llvm::getSubDirectoryPath
std::string getSubDirectoryPath(SubDirectoryType Type, ToolsetLayout VSLayout, const std::string &VCToolChainPath, llvm::Triple::ArchType TargetArch, llvm::StringRef SubdirParent="")
Definition: MSVCPaths.cpp:334
StringRef.h
llvm::ToolsetLayout::OlderVS
@ OlderVS
llvm::findVCToolChainViaCommandLine
bool findVCToolChainViaCommandLine(vfs::FileSystem &VFS, llvm::Optional< llvm::StringRef > VCToolsDir, llvm::Optional< llvm::StringRef > VCToolsVersion, llvm::Optional< llvm::StringRef > WinSysRoot, std::string &Path, ToolsetLayout &VSLayout)
Definition: MSVCPaths.cpp:475
llvm::Optional< llvm::StringRef >
llvm::getUniversalCRTSdkDir
bool getUniversalCRTSdkDir(vfs::FileSystem &VFS, llvm::Optional< llvm::StringRef > WinSdkDir, llvm::Optional< llvm::StringRef > WinSdkVersion, llvm::Optional< llvm::StringRef > WinSysRoot, std::string &Path, std::string &UCRTVersion)
Definition: MSVCPaths.cpp:451
llvm::ToolsetLayout::DevDivInternal
@ DevDivInternal
llvm::SubDirectoryType::Bin
@ Bin
llvm::findVCToolChainViaRegistry
bool findVCToolChainViaRegistry(std::string &Path, ToolsetLayout &VSLayout)
Definition: MSVCPaths.cpp:700
llvm::Triple::ArchType
ArchType
Definition: Triple.h:46
SmallString.h
llvm::SubDirectoryType::Lib
@ Lib
llvm::findVCToolChainViaSetupConfig
bool findVCToolChainViaSetupConfig(vfs::FileSystem &VFS, std::string &Path, ToolsetLayout &VSLayout)
Definition: MSVCPaths.cpp:611
llvm::findVCToolChainViaEnvironment
bool findVCToolChainViaEnvironment(vfs::FileSystem &VFS, std::string &Path, ToolsetLayout &VSLayout)
Definition: MSVCPaths.cpp:502
llvm::SmallString< 128 >
llvm::ToolsetLayout::VS2017OrNewer
@ VS2017OrNewer
llvm::ToolsetLayout
ToolsetLayout
Definition: MSVCPaths.h:30
llvm::getWindowsSDKDir
bool getWindowsSDKDir(vfs::FileSystem &VFS, llvm::Optional< llvm::StringRef > WinSdkDir, llvm::Optional< llvm::StringRef > WinSdkVersion, llvm::Optional< llvm::StringRef > WinSysRoot, std::string &Path, int &Major, std::string &WindowsSDKIncludeVersion, std::string &WindowsSDKLibVersion)
Get Windows SDK installation directory.
Definition: MSVCPaths.cpp:396
Triple.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::SubDirectoryType::Include
@ Include
llvm::archToWindowsSDKArch
const char * archToWindowsSDKArch(llvm::Triple::ArchType Arch)
Definition: MSVCPaths.cpp:263
llvm::vfs::FileSystem
The virtual file system interface.
Definition: VirtualFileSystem.h:268
llvm::SubDirectoryType
SubDirectoryType
Definition: MSVCPaths.h:24
llvm::archToDevDivInternalArch
const char * archToDevDivInternalArch(llvm::Triple::ArchType Arch)
Definition: MSVCPaths.cpp:295
llvm::useUniversalCRT
bool useUniversalCRT(ToolsetLayout VSLayout, const std::string &VCToolChainPath, llvm::Triple::ArchType TargetArch, llvm::vfs::FileSystem &VFS)
Definition: MSVCPaths.cpp:388