cmGlobalVisualStudioVersionedGenerator.cxx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGlobalVisualStudioVersionedGenerator.h"
  4. #include <cmext/string_view>
  5. #include "cmsys/FStream.hxx"
  6. #include "cmsys/Glob.hxx"
  7. #include "cmAlgorithms.h"
  8. #include "cmDocumentationEntry.h"
  9. #include "cmLocalVisualStudio10Generator.h"
  10. #include "cmMakefile.h"
  11. #include "cmStringAlgorithms.h"
  12. #include "cmVSSetupHelper.h"
  13. #include "cmake.h"
  14. #if defined(_M_ARM64)
  15. # define HOST_PLATFORM_NAME "ARM64"
  16. # define HOST_TOOLS_ARCH ""
  17. #elif defined(_M_ARM)
  18. # define HOST_PLATFORM_NAME "ARM"
  19. # define HOST_TOOLS_ARCH ""
  20. #elif defined(_M_IA64)
  21. # define HOST_PLATFORM_NAME "Itanium"
  22. # define HOST_TOOLS_ARCH ""
  23. #elif defined(_WIN64)
  24. # define HOST_PLATFORM_NAME "x64"
  25. # define HOST_TOOLS_ARCH "x64"
  26. #else
  27. static bool VSIsWow64()
  28. {
  29. BOOL isWow64 = false;
  30. return IsWow64Process(GetCurrentProcess(), &isWow64) && isWow64;
  31. }
  32. #endif
  33. static std::string VSHostPlatformName()
  34. {
  35. #ifdef HOST_PLATFORM_NAME
  36. return HOST_PLATFORM_NAME;
  37. #else
  38. if (VSIsWow64()) {
  39. return "x64";
  40. } else {
  41. return "Win32";
  42. }
  43. #endif
  44. }
  45. static std::string VSHostArchitecture()
  46. {
  47. #ifdef HOST_TOOLS_ARCH
  48. return HOST_TOOLS_ARCH;
  49. #else
  50. if (VSIsWow64()) {
  51. return "x64";
  52. } else {
  53. return "x86";
  54. }
  55. #endif
  56. }
  57. static unsigned int VSVersionToMajor(
  58. cmGlobalVisualStudioGenerator::VSVersion v)
  59. {
  60. switch (v) {
  61. case cmGlobalVisualStudioGenerator::VS9:
  62. return 9;
  63. case cmGlobalVisualStudioGenerator::VS10:
  64. return 10;
  65. case cmGlobalVisualStudioGenerator::VS11:
  66. return 11;
  67. case cmGlobalVisualStudioGenerator::VS12:
  68. return 12;
  69. case cmGlobalVisualStudioGenerator::VS14:
  70. return 14;
  71. case cmGlobalVisualStudioGenerator::VS15:
  72. return 15;
  73. case cmGlobalVisualStudioGenerator::VS16:
  74. return 16;
  75. }
  76. return 0;
  77. }
  78. static const char* VSVersionToToolset(
  79. cmGlobalVisualStudioGenerator::VSVersion v)
  80. {
  81. switch (v) {
  82. case cmGlobalVisualStudioGenerator::VS9:
  83. return "v90";
  84. case cmGlobalVisualStudioGenerator::VS10:
  85. return "v100";
  86. case cmGlobalVisualStudioGenerator::VS11:
  87. return "v110";
  88. case cmGlobalVisualStudioGenerator::VS12:
  89. return "v120";
  90. case cmGlobalVisualStudioGenerator::VS14:
  91. return "v140";
  92. case cmGlobalVisualStudioGenerator::VS15:
  93. return "v141";
  94. case cmGlobalVisualStudioGenerator::VS16:
  95. return "v142";
  96. }
  97. return "";
  98. }
  99. static const char* VSVersionToAndroidToolset(
  100. cmGlobalVisualStudioGenerator::VSVersion v)
  101. {
  102. switch (v) {
  103. case cmGlobalVisualStudioGenerator::VS9:
  104. case cmGlobalVisualStudioGenerator::VS10:
  105. case cmGlobalVisualStudioGenerator::VS11:
  106. case cmGlobalVisualStudioGenerator::VS12:
  107. return "";
  108. case cmGlobalVisualStudioGenerator::VS14:
  109. return "Clang_3_8";
  110. case cmGlobalVisualStudioGenerator::VS15:
  111. case cmGlobalVisualStudioGenerator::VS16:
  112. return "Clang_5_0";
  113. }
  114. return "";
  115. }
  116. static const char vs15generatorName[] = "Visual Studio 15 2017";
  117. // Map generator name without year to name with year.
  118. static const char* cmVS15GenName(const std::string& name, std::string& genName)
  119. {
  120. if (strncmp(name.c_str(), vs15generatorName,
  121. sizeof(vs15generatorName) - 6) != 0) {
  122. return 0;
  123. }
  124. const char* p = name.c_str() + sizeof(vs15generatorName) - 6;
  125. if (cmHasLiteralPrefix(p, " 2017")) {
  126. p += 5;
  127. }
  128. genName = std::string(vs15generatorName) + p;
  129. return p;
  130. }
  131. class cmGlobalVisualStudioVersionedGenerator::Factory15
  132. : public cmGlobalGeneratorFactory
  133. {
  134. public:
  135. std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
  136. const std::string& name, bool allowArch, cmake* cm) const override
  137. {
  138. std::string genName;
  139. const char* p = cmVS15GenName(name, genName);
  140. if (!p) {
  141. return std::unique_ptr<cmGlobalGenerator>();
  142. }
  143. if (!*p) {
  144. return std::unique_ptr<cmGlobalGenerator>(
  145. new cmGlobalVisualStudioVersionedGenerator(
  146. cmGlobalVisualStudioGenerator::VS15, cm, genName, ""));
  147. }
  148. if (!allowArch || *p++ != ' ') {
  149. return std::unique_ptr<cmGlobalGenerator>();
  150. }
  151. if (strcmp(p, "Win64") == 0) {
  152. return std::unique_ptr<cmGlobalGenerator>(
  153. new cmGlobalVisualStudioVersionedGenerator(
  154. cmGlobalVisualStudioGenerator::VS15, cm, genName, "x64"));
  155. }
  156. if (strcmp(p, "ARM") == 0) {
  157. return std::unique_ptr<cmGlobalGenerator>(
  158. new cmGlobalVisualStudioVersionedGenerator(
  159. cmGlobalVisualStudioGenerator::VS15, cm, genName, "ARM"));
  160. }
  161. return std::unique_ptr<cmGlobalGenerator>();
  162. }
  163. void GetDocumentation(cmDocumentationEntry& entry) const override
  164. {
  165. entry.Name = std::string(vs15generatorName) + " [arch]";
  166. entry.Brief = "Generates Visual Studio 2017 project files. "
  167. "Optional [arch] can be \"Win64\" or \"ARM\".";
  168. }
  169. std::vector<std::string> GetGeneratorNames() const override
  170. {
  171. std::vector<std::string> names;
  172. names.push_back(vs15generatorName);
  173. return names;
  174. }
  175. std::vector<std::string> GetGeneratorNamesWithPlatform() const override
  176. {
  177. std::vector<std::string> names;
  178. names.push_back(vs15generatorName + std::string(" ARM"));
  179. names.push_back(vs15generatorName + std::string(" Win64"));
  180. return names;
  181. }
  182. bool SupportsToolset() const override { return true; }
  183. bool SupportsPlatform() const override { return true; }
  184. std::vector<std::string> GetKnownPlatforms() const override
  185. {
  186. std::vector<std::string> platforms;
  187. platforms.emplace_back("x64");
  188. platforms.emplace_back("Win32");
  189. platforms.emplace_back("ARM");
  190. platforms.emplace_back("ARM64");
  191. platforms.emplace_back("ARM64EC");
  192. return platforms;
  193. }
  194. std::string GetDefaultPlatformName() const override { return "Win32"; }
  195. };
  196. std::unique_ptr<cmGlobalGeneratorFactory>
  197. cmGlobalVisualStudioVersionedGenerator::NewFactory15()
  198. {
  199. return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory15);
  200. }
  201. static const char vs16generatorName[] = "Visual Studio 16 2019";
  202. // Map generator name without year to name with year.
  203. static const char* cmVS16GenName(const std::string& name, std::string& genName)
  204. {
  205. if (strncmp(name.c_str(), vs16generatorName,
  206. sizeof(vs16generatorName) - 6) != 0) {
  207. return 0;
  208. }
  209. const char* p = name.c_str() + sizeof(vs16generatorName) - 6;
  210. if (cmHasLiteralPrefix(p, " 2019")) {
  211. p += 5;
  212. }
  213. genName = std::string(vs16generatorName) + p;
  214. return p;
  215. }
  216. class cmGlobalVisualStudioVersionedGenerator::Factory16
  217. : public cmGlobalGeneratorFactory
  218. {
  219. public:
  220. std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
  221. const std::string& name, bool /*allowArch*/, cmake* cm) const override
  222. {
  223. std::string genName;
  224. const char* p = cmVS16GenName(name, genName);
  225. if (!p) {
  226. return std::unique_ptr<cmGlobalGenerator>();
  227. }
  228. if (!*p) {
  229. return std::unique_ptr<cmGlobalGenerator>(
  230. new cmGlobalVisualStudioVersionedGenerator(
  231. cmGlobalVisualStudioGenerator::VS16, cm, genName, ""));
  232. }
  233. return std::unique_ptr<cmGlobalGenerator>();
  234. }
  235. void GetDocumentation(cmDocumentationEntry& entry) const override
  236. {
  237. entry.Name = std::string(vs16generatorName);
  238. entry.Brief = "Generates Visual Studio 2019 project files. "
  239. "Use -A option to specify architecture.";
  240. }
  241. std::vector<std::string> GetGeneratorNames() const override
  242. {
  243. std::vector<std::string> names;
  244. names.push_back(vs16generatorName);
  245. return names;
  246. }
  247. std::vector<std::string> GetGeneratorNamesWithPlatform() const override
  248. {
  249. return std::vector<std::string>();
  250. }
  251. bool SupportsToolset() const override { return true; }
  252. bool SupportsPlatform() const override { return true; }
  253. std::vector<std::string> GetKnownPlatforms() const override
  254. {
  255. std::vector<std::string> platforms;
  256. platforms.emplace_back("x64");
  257. platforms.emplace_back("Win32");
  258. platforms.emplace_back("ARM");
  259. platforms.emplace_back("ARM64");
  260. return platforms;
  261. }
  262. std::string GetDefaultPlatformName() const override
  263. {
  264. return VSHostPlatformName();
  265. }
  266. };
  267. std::unique_ptr<cmGlobalGeneratorFactory>
  268. cmGlobalVisualStudioVersionedGenerator::NewFactory16()
  269. {
  270. return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory16);
  271. }
  272. cmGlobalVisualStudioVersionedGenerator::cmGlobalVisualStudioVersionedGenerator(
  273. VSVersion version, cmake* cm, const std::string& name,
  274. std::string const& platformInGeneratorName)
  275. : cmGlobalVisualStudio14Generator(cm, name, platformInGeneratorName)
  276. , vsSetupAPIHelper(VSVersionToMajor(version))
  277. {
  278. this->Version = version;
  279. this->ExpressEdition = false;
  280. this->DefaultPlatformToolset = VSVersionToToolset(this->Version);
  281. this->DefaultAndroidToolset = VSVersionToAndroidToolset(this->Version);
  282. this->DefaultCLFlagTableName = VSVersionToToolset(this->Version);
  283. this->DefaultCSharpFlagTableName = VSVersionToToolset(this->Version);
  284. this->DefaultLinkFlagTableName = VSVersionToToolset(this->Version);
  285. if (this->Version >= cmGlobalVisualStudioGenerator::VS16) {
  286. this->DefaultPlatformName = VSHostPlatformName();
  287. this->DefaultPlatformToolsetHostArchitecture = VSHostArchitecture();
  288. }
  289. }
  290. bool cmGlobalVisualStudioVersionedGenerator::MatchesGeneratorName(
  291. const std::string& name) const
  292. {
  293. std::string genName;
  294. switch (this->Version) {
  295. case cmGlobalVisualStudioGenerator::VS9:
  296. case cmGlobalVisualStudioGenerator::VS10:
  297. case cmGlobalVisualStudioGenerator::VS11:
  298. case cmGlobalVisualStudioGenerator::VS12:
  299. case cmGlobalVisualStudioGenerator::VS14:
  300. break;
  301. case cmGlobalVisualStudioGenerator::VS15:
  302. if (cmVS15GenName(name, genName)) {
  303. return genName == this->GetName();
  304. }
  305. break;
  306. case cmGlobalVisualStudioGenerator::VS16:
  307. if (cmVS16GenName(name, genName)) {
  308. return genName == this->GetName();
  309. }
  310. break;
  311. }
  312. return false;
  313. }
  314. bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance(
  315. std::string const& i, cmMakefile* mf)
  316. {
  317. if (!i.empty()) {
  318. if (!this->vsSetupAPIHelper.SetVSInstance(i)) {
  319. std::ostringstream e;
  320. /* clang-format off */
  321. e <<
  322. "Generator\n"
  323. " " << this->GetName() << "\n"
  324. "could not find specified instance of Visual Studio:\n"
  325. " " << i;
  326. /* clang-format on */
  327. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  328. return false;
  329. }
  330. }
  331. std::string vsInstance;
  332. if (!this->vsSetupAPIHelper.GetVSInstanceInfo(vsInstance)) {
  333. std::ostringstream e;
  334. /* clang-format off */
  335. e <<
  336. "Generator\n"
  337. " " << this->GetName() << "\n"
  338. "could not find any instance of Visual Studio.\n";
  339. /* clang-format on */
  340. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  341. return false;
  342. }
  343. // Save the selected instance persistently.
  344. std::string genInstance = mf->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE");
  345. if (vsInstance != genInstance) {
  346. this->CMakeInstance->AddCacheEntry(
  347. "CMAKE_GENERATOR_INSTANCE", vsInstance.c_str(),
  348. "Generator instance identifier.", cmStateEnums::INTERNAL);
  349. }
  350. return true;
  351. }
  352. bool cmGlobalVisualStudioVersionedGenerator::GetVSInstance(
  353. std::string& dir) const
  354. {
  355. return vsSetupAPIHelper.GetVSInstanceInfo(dir);
  356. }
  357. cm::optional<std::string>
  358. cmGlobalVisualStudioVersionedGenerator::GetVSInstanceVersion() const
  359. {
  360. cm::optional<std::string> result;
  361. std::string vsInstanceVersion;
  362. if (vsSetupAPIHelper.GetVSInstanceVersion(vsInstanceVersion)) {
  363. result = vsInstanceVersion;
  364. }
  365. return result;
  366. }
  367. bool cmGlobalVisualStudioVersionedGenerator::IsStdOutEncodingSupported() const
  368. {
  369. // Supported from Visual Studio 16.7 Preview 3.
  370. if (this->Version > cmGlobalVisualStudioGenerator::VSVersion::VS16) {
  371. return true;
  372. }
  373. if (this->Version < cmGlobalVisualStudioGenerator::VSVersion::VS16) {
  374. return false;
  375. }
  376. static std::string const vsVer16_7_P2 = "16.7.30128.36";
  377. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  378. return (vsVer &&
  379. cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer16_7_P2));
  380. }
  381. const char*
  382. cmGlobalVisualStudioVersionedGenerator::GetAndroidApplicationTypeRevision()
  383. const
  384. {
  385. switch (this->Version) {
  386. case cmGlobalVisualStudioGenerator::VS9:
  387. case cmGlobalVisualStudioGenerator::VS10:
  388. case cmGlobalVisualStudioGenerator::VS11:
  389. case cmGlobalVisualStudioGenerator::VS12:
  390. return "";
  391. case cmGlobalVisualStudioGenerator::VS14:
  392. return "2.0";
  393. case cmGlobalVisualStudioGenerator::VS15:
  394. case cmGlobalVisualStudioGenerator::VS16:
  395. return "3.0";
  396. }
  397. return "";
  398. }
  399. cmGlobalVisualStudioVersionedGenerator::AuxToolset
  400. cmGlobalVisualStudioVersionedGenerator::FindAuxToolset(
  401. std::string& version, std::string& props) const
  402. {
  403. if (version.empty()) {
  404. return AuxToolset::None;
  405. }
  406. std::string instancePath;
  407. this->GetVSInstance(instancePath);
  408. cmSystemTools::ConvertToUnixSlashes(instancePath);
  409. // Translate three-component format accepted by "vcvarsall -vcvars_ver=".
  410. cmsys::RegularExpression threeComponent(
  411. "^([0-9]+\\.[0-9]+)\\.[0-9][0-9][0-9][0-9][0-9]$");
  412. if (threeComponent.find(version)) {
  413. // Load "VC/Auxiliary/Build/*/Microsoft.VCToolsVersion.*.txt" files
  414. // with two matching components to check their three-component version.
  415. std::string const& twoComponent = threeComponent.match(1);
  416. std::string pattern =
  417. cmStrCat(instancePath, "/VC/Auxiliary/Build/"_s, twoComponent,
  418. "*/Microsoft.VCToolsVersion."_s, twoComponent, "*.txt"_s);
  419. cmsys::Glob glob;
  420. glob.SetRecurseThroughSymlinks(false);
  421. if (glob.FindFiles(pattern)) {
  422. for (std::string const& txt : glob.GetFiles()) {
  423. std::string ver;
  424. cmsys::ifstream fin(txt.c_str());
  425. if (fin && std::getline(fin, ver)) {
  426. // Strip trailing whitespace.
  427. ver = ver.substr(0, ver.find_first_not_of("0123456789."));
  428. // If the three-component version matches, translate it to
  429. // that used by the "Microsoft.VCToolsVersion.*.txt" file name.
  430. if (ver == version) {
  431. cmsys::RegularExpression extractVersion(
  432. "VCToolsVersion\\.([0-9.]+)\\.txt$");
  433. if (extractVersion.find(txt)) {
  434. version = extractVersion.match(1);
  435. break;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. if (cmSystemTools::VersionCompareGreaterEq(version, "14.20")) {
  443. props = cmStrCat(instancePath, "/VC/Auxiliary/Build."_s, version,
  444. "/Microsoft.VCToolsVersion."_s, version, ".props"_s);
  445. if (cmSystemTools::PathExists(props)) {
  446. return AuxToolset::PropsExist;
  447. }
  448. }
  449. props = cmStrCat(instancePath, "/VC/Auxiliary/Build/"_s, version,
  450. "/Microsoft.VCToolsVersion."_s, version, ".props"_s);
  451. if (cmSystemTools::PathExists(props)) {
  452. return AuxToolset::PropsExist;
  453. }
  454. // Accept the toolset version that is default in the current VS version
  455. // by matching the name later VS versions will use for the SxS props files.
  456. std::string vcToolsetVersion;
  457. if (this->vsSetupAPIHelper.GetVCToolsetVersion(vcToolsetVersion)) {
  458. // Accept an exact-match (three-component version).
  459. if (version == vcToolsetVersion) {
  460. return AuxToolset::Default;
  461. }
  462. // Accept known SxS props file names using four version components
  463. // in VS versions later than the current.
  464. if (version == "14.28.16.9" && vcToolsetVersion == "14.28.29910") {
  465. return AuxToolset::Default;
  466. }
  467. if (version == "14.29.16.10" && vcToolsetVersion == "14.29.30037") {
  468. return AuxToolset::Default;
  469. }
  470. // The first two components of the default toolset version typically
  471. // match the name used by later VS versions for the SxS props files.
  472. cmsys::RegularExpression twoComponent("^([0-9]+\\.[0-9]+)");
  473. if (twoComponent.find(version)) {
  474. std::string const versionPrefix = cmStrCat(twoComponent.match(1), '.');
  475. if (cmHasPrefix(vcToolsetVersion, versionPrefix)) {
  476. return AuxToolset::Default;
  477. }
  478. }
  479. }
  480. return AuxToolset::PropsMissing;
  481. }
  482. bool cmGlobalVisualStudioVersionedGenerator::InitializeWindows(cmMakefile* mf)
  483. {
  484. // If the Win 8.1 SDK is installed then we can select a SDK matching
  485. // the target Windows version.
  486. if (this->IsWin81SDKInstalled()) {
  487. // VS 2019 does not default to 8.1 so specify it explicitly when needed.
  488. if (this->Version >= cmGlobalVisualStudioGenerator::VS16 &&
  489. !cmSystemTools::VersionCompareGreater(this->SystemVersion, "8.1")) {
  490. this->SetWindowsTargetPlatformVersion("8.1", mf);
  491. return true;
  492. }
  493. return cmGlobalVisualStudio14Generator::InitializeWindows(mf);
  494. }
  495. // Otherwise we must choose a Win 10 SDK even if we are not targeting
  496. // Windows 10.
  497. return this->SelectWindows10SDK(mf, false);
  498. }
  499. bool cmGlobalVisualStudioVersionedGenerator::SelectWindowsStoreToolset(
  500. std::string& toolset) const
  501. {
  502. if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) {
  503. if (this->IsWindowsStoreToolsetInstalled() &&
  504. this->IsWindowsDesktopToolsetInstalled()) {
  505. toolset = VSVersionToToolset(this->Version);
  506. return true;
  507. } else {
  508. return false;
  509. }
  510. }
  511. return this->cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset(
  512. toolset);
  513. }
  514. bool cmGlobalVisualStudioVersionedGenerator::IsWindowsDesktopToolsetInstalled()
  515. const
  516. {
  517. return vsSetupAPIHelper.IsVSInstalled();
  518. }
  519. bool cmGlobalVisualStudioVersionedGenerator::IsWindowsStoreToolsetInstalled()
  520. const
  521. {
  522. return vsSetupAPIHelper.IsWin10SDKInstalled();
  523. }
  524. bool cmGlobalVisualStudioVersionedGenerator::IsWin81SDKInstalled() const
  525. {
  526. // Does the VS installer tool know about one?
  527. if (vsSetupAPIHelper.IsWin81SDKInstalled()) {
  528. return true;
  529. }
  530. // Does the registry know about one (e.g. from VS 2015)?
  531. std::string win81Root;
  532. if (cmSystemTools::ReadRegistryValue(
  533. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  534. "Windows Kits\\Installed Roots;KitsRoot81",
  535. win81Root, cmSystemTools::KeyWOW64_32) ||
  536. cmSystemTools::ReadRegistryValue(
  537. "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\"
  538. "Windows Kits\\Installed Roots;KitsRoot81",
  539. win81Root, cmSystemTools::KeyWOW64_32)) {
  540. return cmSystemTools::FileExists(win81Root + "/include/um/windows.h",
  541. true);
  542. }
  543. return false;
  544. }
  545. std::string
  546. cmGlobalVisualStudioVersionedGenerator::GetWindows10SDKMaxVersionDefault(
  547. cmMakefile*) const
  548. {
  549. return std::string();
  550. }
  551. std::string cmGlobalVisualStudioVersionedGenerator::FindMSBuildCommand()
  552. {
  553. std::string msbuild;
  554. // Ask Visual Studio Installer tool.
  555. std::string vs;
  556. if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) {
  557. msbuild = vs + "/MSBuild/Current/Bin/MSBuild.exe";
  558. if (cmSystemTools::FileExists(msbuild)) {
  559. return msbuild;
  560. }
  561. msbuild = vs + "/MSBuild/15.0/Bin/MSBuild.exe";
  562. if (cmSystemTools::FileExists(msbuild)) {
  563. return msbuild;
  564. }
  565. }
  566. msbuild = "MSBuild.exe";
  567. return msbuild;
  568. }
  569. std::string cmGlobalVisualStudioVersionedGenerator::FindDevEnvCommand()
  570. {
  571. std::string devenv;
  572. // Ask Visual Studio Installer tool.
  573. std::string vs;
  574. if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) {
  575. devenv = vs + "/Common7/IDE/devenv.com";
  576. if (cmSystemTools::FileExists(devenv)) {
  577. return devenv;
  578. }
  579. }
  580. devenv = "devenv.com";
  581. return devenv;
  582. }