cmGlobalVisualStudioVersionedGenerator.cxx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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. bool cmGlobalVisualStudioVersionedGenerator::GetVSInstanceVersion(
  358. unsigned long long& vsInstanceVersion) const
  359. {
  360. return vsSetupAPIHelper.GetVSInstanceVersion(vsInstanceVersion);
  361. }
  362. bool cmGlobalVisualStudioVersionedGenerator::IsStdOutEncodingSupported() const
  363. {
  364. // Supported from Visual Studio 16.7 Preview 3.
  365. if (this->Version > cmGlobalVisualStudioGenerator::VSVersion::VS16) {
  366. return true;
  367. }
  368. if (this->Version < cmGlobalVisualStudioGenerator::VSVersion::VS16) {
  369. return false;
  370. }
  371. unsigned long long const vsInstanceVersion16_7_P2 = 4503631666610212;
  372. unsigned long long vsInstanceVersion;
  373. return (this->GetVSInstanceVersion(vsInstanceVersion) &&
  374. vsInstanceVersion > vsInstanceVersion16_7_P2);
  375. }
  376. const char*
  377. cmGlobalVisualStudioVersionedGenerator::GetAndroidApplicationTypeRevision()
  378. const
  379. {
  380. switch (this->Version) {
  381. case cmGlobalVisualStudioGenerator::VS9:
  382. case cmGlobalVisualStudioGenerator::VS10:
  383. case cmGlobalVisualStudioGenerator::VS11:
  384. case cmGlobalVisualStudioGenerator::VS12:
  385. return "";
  386. case cmGlobalVisualStudioGenerator::VS14:
  387. return "2.0";
  388. case cmGlobalVisualStudioGenerator::VS15:
  389. case cmGlobalVisualStudioGenerator::VS16:
  390. return "3.0";
  391. }
  392. return "";
  393. }
  394. cmGlobalVisualStudioVersionedGenerator::AuxToolset
  395. cmGlobalVisualStudioVersionedGenerator::FindAuxToolset(
  396. std::string& version, std::string& props) const
  397. {
  398. if (version.empty()) {
  399. return AuxToolset::None;
  400. }
  401. std::string instancePath;
  402. this->GetVSInstance(instancePath);
  403. cmSystemTools::ConvertToUnixSlashes(instancePath);
  404. // Translate three-component format accepted by "vcvarsall -vcvars_ver=".
  405. cmsys::RegularExpression threeComponent(
  406. "^([0-9]+\\.[0-9]+)\\.[0-9][0-9][0-9][0-9][0-9]$");
  407. if (threeComponent.find(version)) {
  408. // Load "VC/Auxiliary/Build/*/Microsoft.VCToolsVersion.*.txt" files
  409. // with two matching components to check their three-component version.
  410. std::string const& twoComponent = threeComponent.match(1);
  411. std::string pattern =
  412. cmStrCat(instancePath, "/VC/Auxiliary/Build/"_s, twoComponent,
  413. "*/Microsoft.VCToolsVersion."_s, twoComponent, "*.txt"_s);
  414. cmsys::Glob glob;
  415. glob.SetRecurseThroughSymlinks(false);
  416. if (glob.FindFiles(pattern)) {
  417. for (std::string const& txt : glob.GetFiles()) {
  418. std::string ver;
  419. cmsys::ifstream fin(txt.c_str());
  420. if (fin && std::getline(fin, ver)) {
  421. // Strip trailing whitespace.
  422. ver = ver.substr(0, ver.find_first_not_of("0123456789."));
  423. // If the three-component version matches, translate it to
  424. // that used by the "Microsoft.VCToolsVersion.*.txt" file name.
  425. if (ver == version) {
  426. cmsys::RegularExpression extractVersion(
  427. "VCToolsVersion\\.([0-9.]+)\\.txt$");
  428. if (extractVersion.find(txt)) {
  429. version = extractVersion.match(1);
  430. break;
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. if (cmSystemTools::VersionCompareGreaterEq(version, "14.20")) {
  438. props = cmStrCat(instancePath, "/VC/Auxiliary/Build."_s, version,
  439. "/Microsoft.VCToolsVersion."_s, version, ".props"_s);
  440. if (cmSystemTools::PathExists(props)) {
  441. return AuxToolset::PropsExist;
  442. }
  443. }
  444. props = cmStrCat(instancePath, "/VC/Auxiliary/Build/"_s, version,
  445. "/Microsoft.VCToolsVersion."_s, version, ".props"_s);
  446. if (cmSystemTools::PathExists(props)) {
  447. return AuxToolset::PropsExist;
  448. }
  449. // Accept the toolset version that is default in the current VS version
  450. // by matching the name later VS versions will use for the SxS props files.
  451. std::string vcToolsetVersion;
  452. if (this->vsSetupAPIHelper.GetVCToolsetVersion(vcToolsetVersion)) {
  453. // Accept an exact-match (three-component version).
  454. if (version == vcToolsetVersion) {
  455. return AuxToolset::Default;
  456. }
  457. // Accept known SxS props file names using four version components
  458. // in VS versions later than the current.
  459. if (version == "14.28.16.9" && vcToolsetVersion == "14.28.29910") {
  460. return AuxToolset::Default;
  461. }
  462. if (version == "14.29.16.10" && vcToolsetVersion == "14.29.30037") {
  463. return AuxToolset::Default;
  464. }
  465. // The first two components of the default toolset version typically
  466. // match the name used by later VS versions for the SxS props files.
  467. cmsys::RegularExpression twoComponent("^([0-9]+\\.[0-9]+)");
  468. if (twoComponent.find(version)) {
  469. std::string const versionPrefix = cmStrCat(twoComponent.match(1), '.');
  470. if (cmHasPrefix(vcToolsetVersion, versionPrefix)) {
  471. return AuxToolset::Default;
  472. }
  473. }
  474. }
  475. return AuxToolset::PropsMissing;
  476. }
  477. bool cmGlobalVisualStudioVersionedGenerator::InitializeWindows(cmMakefile* mf)
  478. {
  479. // If the Win 8.1 SDK is installed then we can select a SDK matching
  480. // the target Windows version.
  481. if (this->IsWin81SDKInstalled()) {
  482. // VS 2019 does not default to 8.1 so specify it explicitly when needed.
  483. if (this->Version >= cmGlobalVisualStudioGenerator::VS16 &&
  484. !cmSystemTools::VersionCompareGreater(this->SystemVersion, "8.1")) {
  485. this->SetWindowsTargetPlatformVersion("8.1", mf);
  486. return true;
  487. }
  488. return cmGlobalVisualStudio14Generator::InitializeWindows(mf);
  489. }
  490. // Otherwise we must choose a Win 10 SDK even if we are not targeting
  491. // Windows 10.
  492. return this->SelectWindows10SDK(mf, false);
  493. }
  494. bool cmGlobalVisualStudioVersionedGenerator::SelectWindowsStoreToolset(
  495. std::string& toolset) const
  496. {
  497. if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) {
  498. if (this->IsWindowsStoreToolsetInstalled() &&
  499. this->IsWindowsDesktopToolsetInstalled()) {
  500. toolset = VSVersionToToolset(this->Version);
  501. return true;
  502. } else {
  503. return false;
  504. }
  505. }
  506. return this->cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset(
  507. toolset);
  508. }
  509. bool cmGlobalVisualStudioVersionedGenerator::IsWindowsDesktopToolsetInstalled()
  510. const
  511. {
  512. return vsSetupAPIHelper.IsVSInstalled();
  513. }
  514. bool cmGlobalVisualStudioVersionedGenerator::IsWindowsStoreToolsetInstalled()
  515. const
  516. {
  517. return vsSetupAPIHelper.IsWin10SDKInstalled();
  518. }
  519. bool cmGlobalVisualStudioVersionedGenerator::IsWin81SDKInstalled() const
  520. {
  521. // Does the VS installer tool know about one?
  522. if (vsSetupAPIHelper.IsWin81SDKInstalled()) {
  523. return true;
  524. }
  525. // Does the registry know about one (e.g. from VS 2015)?
  526. std::string win81Root;
  527. if (cmSystemTools::ReadRegistryValue(
  528. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  529. "Windows Kits\\Installed Roots;KitsRoot81",
  530. win81Root, cmSystemTools::KeyWOW64_32) ||
  531. cmSystemTools::ReadRegistryValue(
  532. "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\"
  533. "Windows Kits\\Installed Roots;KitsRoot81",
  534. win81Root, cmSystemTools::KeyWOW64_32)) {
  535. return cmSystemTools::FileExists(win81Root + "/include/um/windows.h",
  536. true);
  537. }
  538. return false;
  539. }
  540. std::string
  541. cmGlobalVisualStudioVersionedGenerator::GetWindows10SDKMaxVersionDefault(
  542. cmMakefile*) const
  543. {
  544. return std::string();
  545. }
  546. std::string cmGlobalVisualStudioVersionedGenerator::FindMSBuildCommand()
  547. {
  548. std::string msbuild;
  549. // Ask Visual Studio Installer tool.
  550. std::string vs;
  551. if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) {
  552. msbuild = vs + "/MSBuild/Current/Bin/MSBuild.exe";
  553. if (cmSystemTools::FileExists(msbuild)) {
  554. return msbuild;
  555. }
  556. msbuild = vs + "/MSBuild/15.0/Bin/MSBuild.exe";
  557. if (cmSystemTools::FileExists(msbuild)) {
  558. return msbuild;
  559. }
  560. }
  561. msbuild = "MSBuild.exe";
  562. return msbuild;
  563. }
  564. std::string cmGlobalVisualStudioVersionedGenerator::FindDevEnvCommand()
  565. {
  566. std::string devenv;
  567. // Ask Visual Studio Installer tool.
  568. std::string vs;
  569. if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) {
  570. devenv = vs + "/Common7/IDE/devenv.com";
  571. if (cmSystemTools::FileExists(devenv)) {
  572. return devenv;
  573. }
  574. }
  575. devenv = "devenv.com";
  576. return devenv;
  577. }