MSVCPaths.h 4.4 KB

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