cmGlobalVisualStudio10Generator.cxx 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmGlobalVisualStudio10Generator.h"
  4. #include <algorithm>
  5. #include <cstring>
  6. #include <map>
  7. #include <sstream>
  8. #include <utility>
  9. #include <cm/memory>
  10. #include <cmext/string_view>
  11. #include <cm3p/json/reader.h>
  12. #include <cm3p/json/value.h>
  13. #include "cmsys/FStream.hxx"
  14. #include "cmsys/Glob.hxx"
  15. #include "cmsys/RegularExpression.hxx"
  16. #include "cmCryptoHash.h"
  17. #include "cmDocumentationEntry.h"
  18. #include "cmExperimental.h"
  19. #include "cmGeneratorTarget.h"
  20. #include "cmGlobalGenerator.h"
  21. #include "cmGlobalVisualStudio7Generator.h"
  22. #include "cmGlobalVisualStudioGenerator.h"
  23. #include "cmIDEFlagTable.h"
  24. #include "cmLocalGenerator.h"
  25. #include "cmLocalVisualStudio10Generator.h"
  26. #include "cmMakefile.h"
  27. #include "cmMessageType.h"
  28. #include "cmSourceFile.h"
  29. #include "cmStringAlgorithms.h"
  30. #include "cmSystemTools.h"
  31. #include "cmVersion.h"
  32. #include "cmVisualStudioSlnData.h"
  33. #include "cmVisualStudioSlnParser.h"
  34. #include "cmXMLParser.h"
  35. #include "cmXMLWriter.h"
  36. #include "cmake.h"
  37. class cmSlnxParser : public cmXMLParser
  38. {
  39. public:
  40. std::map<std::string, std::string> ProjectToPath;
  41. void StartElement(std::string const& name, char const** atts) override
  42. {
  43. if (name == "Project"_s) {
  44. if (char const* rawPath = this->FindAttribute(atts, "Path")) {
  45. std::string path = rawPath;
  46. cmSystemTools::ConvertToUnixSlashes(path);
  47. std::string nameOnly =
  48. cmsys::SystemTools::GetFilenameWithoutLastExtension(path);
  49. this->ProjectToPath[cmSystemTools::LowerCase(nameOnly)] = path;
  50. }
  51. }
  52. }
  53. void EndElement(std::string const&) override {}
  54. };
  55. static std::map<std::string, std::vector<cmIDEFlagTable>> loadedFlagJsonFiles;
  56. static void ConvertToWindowsSlashes(std::string& s)
  57. {
  58. // first convert all of the slashes
  59. for (auto& ch : s) {
  60. if (ch == '/') {
  61. ch = '\\';
  62. }
  63. }
  64. }
  65. cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator(
  66. cmake* cm, std::string const& name)
  67. : cmGlobalVisualStudio8Generator(cm, name)
  68. {
  69. this->DefaultCudaFlagTableName = "v10";
  70. this->DefaultCudaHostFlagTableName = "v10";
  71. this->DefaultMarmasmFlagTableName = "v10";
  72. this->DefaultNasmFlagTableName = "v10";
  73. }
  74. bool cmGlobalVisualStudio10Generator::SetSystemName(std::string const& s,
  75. cmMakefile* mf)
  76. {
  77. this->SystemName = s;
  78. this->SystemVersion = mf->GetSafeDefinition("CMAKE_SYSTEM_VERSION");
  79. if (!this->InitializeSystem(mf)) {
  80. return false;
  81. }
  82. return this->cmGlobalVisualStudio8Generator::SetSystemName(s, mf);
  83. }
  84. static void cmCudaToolVersion(std::string& s)
  85. {
  86. // "CUDA x.y.props" => "x.y"
  87. s = s.substr(5);
  88. s = s.substr(0, s.size() - 6);
  89. }
  90. bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
  91. std::string const& ts, bool build, cmMakefile* mf)
  92. {
  93. if (this->SystemIsWindowsCE && ts.empty() &&
  94. this->DefaultPlatformToolset.empty()) {
  95. mf->IssueMessage(
  96. MessageType::FATAL_ERROR,
  97. cmStrCat(this->GetName(), " Windows CE version '", this->SystemVersion,
  98. "' requires CMAKE_GENERATOR_TOOLSET to be set."));
  99. return false;
  100. }
  101. if (!this->ParseGeneratorToolset(ts, mf)) {
  102. return false;
  103. }
  104. if (build) {
  105. return true;
  106. }
  107. if (this->CustomVCTargetsPath.empty() && !this->FindVCTargetsPath(mf)) {
  108. return false;
  109. }
  110. if (!this->CustomFlagTableDir.empty() &&
  111. !(cmSystemTools::FileIsFullPath(this->CustomFlagTableDir) &&
  112. cmSystemTools::FileIsDirectory(this->CustomFlagTableDir))) {
  113. mf->IssueMessage(
  114. MessageType::FATAL_ERROR,
  115. cmStrCat("Generator\n"
  116. " ",
  117. this->GetName(),
  118. "\n"
  119. "given toolset\n"
  120. " customFlagTableDir=",
  121. this->CustomFlagTableDir,
  122. "\n"
  123. "that is not an absolute path to an existing directory."));
  124. cmSystemTools::SetFatalErrorOccurred();
  125. return false;
  126. }
  127. if (cmHasLiteralPrefix(this->GetPlatformToolsetString(), "v140")) {
  128. // The GenerateDebugInformation link setting for the v140 toolset
  129. // in VS 2015 was originally an enum with "No" and "Debug" values,
  130. // differing from the "false" and "true" values used in older toolsets.
  131. // A VS 2015 update changed it back. Parse the "link.xml" file to
  132. // discover which one we need.
  133. std::string const link_xml =
  134. cmStrCat(this->VCTargetsPath, "/1033/link.xml");
  135. cmsys::ifstream fin(link_xml.c_str());
  136. std::string line;
  137. while (fin && cmSystemTools::GetLineFromStream(fin, line)) {
  138. if (line.find(" Switch=\"DEBUG\" ") != std::string::npos) {
  139. this->PlatformToolsetNeedsDebugEnum =
  140. line.find(" Name=\"Debug\" ") != std::string::npos;
  141. break;
  142. }
  143. }
  144. }
  145. this->SupportsUnityBuilds =
  146. this->Version >= cmGlobalVisualStudioGenerator::VSVersion::VS16 ||
  147. (this->Version == cmGlobalVisualStudioGenerator::VSVersion::VS15 &&
  148. cmSystemTools::PathExists(
  149. cmStrCat(this->VCTargetsPath, "/Microsoft.Cpp.Unity.targets")));
  150. if (this->GeneratorToolsetCuda.empty()) {
  151. // Find the highest available version of the CUDA tools.
  152. std::vector<std::string> cudaTools;
  153. std::string bcDir;
  154. if (this->GeneratorToolsetCudaCustomDir.empty()) {
  155. bcDir = cmStrCat(this->VCTargetsPath, "/BuildCustomizations");
  156. } else {
  157. bcDir = cmStrCat(this->GetPlatformToolsetCudaCustomDirString(),
  158. this->GetPlatformToolsetCudaVSIntegrationSubdirString(),
  159. "extras\\visual_studio_integration\\MSBuildExtensions");
  160. cmSystemTools::ConvertToUnixSlashes(bcDir);
  161. }
  162. cmsys::Glob gl;
  163. gl.SetRelative(bcDir.c_str());
  164. if (gl.FindFiles(cmStrCat(bcDir, "/CUDA *.props"))) {
  165. cudaTools = gl.GetFiles();
  166. }
  167. if (!cudaTools.empty()) {
  168. std::for_each(cudaTools.begin(), cudaTools.end(), cmCudaToolVersion);
  169. std::sort(cudaTools.begin(), cudaTools.end(),
  170. cmSystemTools::VersionCompareGreater);
  171. this->GeneratorToolsetCuda = cudaTools.at(0);
  172. } else if (!this->GeneratorToolsetCudaCustomDir.empty()) {
  173. // Generate an error if Visual Studio integration files are not found
  174. // inside of custom cuda toolset.
  175. mf->IssueMessage(
  176. MessageType::FATAL_ERROR,
  177. cmStrCat("Generator\n"
  178. " ",
  179. this->GetName(),
  180. "\n"
  181. "given toolset\n"
  182. " cuda=",
  183. this->GeneratorToolsetCudaCustomDir,
  184. "\n"
  185. "cannot detect Visual Studio integration files in path\n"
  186. " ",
  187. bcDir));
  188. // Clear the configured tool-set
  189. this->GeneratorToolsetCuda.clear();
  190. }
  191. }
  192. if (this->GeneratorToolsetFortran) {
  193. if (*this->GeneratorToolsetFortran != "ifx" &&
  194. *this->GeneratorToolsetFortran != "ifort") {
  195. mf->IssueMessage(MessageType::FATAL_ERROR,
  196. cmStrCat("Generator\n"
  197. " ",
  198. this->GetName(),
  199. "\n"
  200. "given toolset\n"
  201. " fortran=",
  202. *this->GeneratorToolsetFortran,
  203. "\n"
  204. "but the value is not \"ifx\" or \"ifort\"."));
  205. this->GeneratorToolsetFortran = cm::nullopt;
  206. }
  207. }
  208. if (!this->GeneratorToolsetVersion.empty() &&
  209. this->GeneratorToolsetVersion != "Test Toolset Version"_s) {
  210. // If a specific minor version of the MSVC toolset is requested, verify
  211. // that it is compatible with the PlatformToolset version. The ability to
  212. // choose a minor version of MSVC has been available since v141.
  213. std::string const& platformToolset = this->GetPlatformToolsetString();
  214. cmsys::RegularExpression vcPlatformToolsetRegex("^v[0-9][0-9][0-9]$");
  215. if (vcPlatformToolsetRegex.find(platformToolset) ||
  216. platformToolset == "Test Toolset"_s) {
  217. std::string versionToolset = this->GeneratorToolsetVersion;
  218. cmsys::RegularExpression versionToolsetRegex(
  219. "^([0-9][0-9])\\.([0-9])[0-9](\\.|$)");
  220. if (versionToolsetRegex.find(versionToolset)) {
  221. versionToolset = cmStrCat('v', versionToolsetRegex.match(1),
  222. versionToolsetRegex.match(2));
  223. // Hard-code special cases for toolset versions whose first
  224. // three digits do not match their toolset name.
  225. // The v143 toolset reserves versions 14.30 through 14.49.
  226. if (platformToolset == "v143"_s && versionToolset == "v144"_s) {
  227. versionToolset = "v143";
  228. }
  229. } else {
  230. // Version not recognized. Clear it.
  231. versionToolset.clear();
  232. }
  233. if (versionToolset != platformToolset) {
  234. mf->IssueMessage(
  235. MessageType::FATAL_ERROR,
  236. cmStrCat("Generator\n"
  237. " ",
  238. this->GetName(),
  239. "\n"
  240. "given toolset and version specification\n"
  241. " ",
  242. this->GetPlatformToolsetString(),
  243. ",version=", this->GeneratorToolsetVersion,
  244. "\n"
  245. "contains an invalid version specification."));
  246. // Clear the configured tool-set
  247. this->GeneratorToolsetVersion.clear();
  248. }
  249. }
  250. std::string auxProps;
  251. switch (this->FindAuxToolset(this->GeneratorToolsetVersion, auxProps)) {
  252. case AuxToolset::None:
  253. this->GeneratorToolsetVersionProps = {};
  254. break;
  255. case AuxToolset::Default:
  256. // The given version is the default toolset. Remove the setting.
  257. this->GeneratorToolsetVersion.clear();
  258. this->GeneratorToolsetVersionProps = {};
  259. break;
  260. case AuxToolset::PropsExist:
  261. this->GeneratorToolsetVersionProps = std::move(auxProps);
  262. break;
  263. case AuxToolset::PropsMissing: {
  264. mf->IssueMessage(MessageType::FATAL_ERROR,
  265. cmStrCat("Generator\n"
  266. " ",
  267. this->GetName(),
  268. "\n"
  269. "given toolset and version specification\n"
  270. " ",
  271. this->GetPlatformToolsetString(),
  272. ",version=", this->GeneratorToolsetVersion,
  273. "\n"
  274. "does not seem to be installed at\n"
  275. " ",
  276. auxProps));
  277. // Clear the configured tool-set
  278. this->GeneratorToolsetVersion.clear();
  279. this->GeneratorToolsetVersionProps = {};
  280. } break;
  281. case AuxToolset::PropsIndeterminate: {
  282. mf->IssueMessage(
  283. MessageType::FATAL_ERROR,
  284. cmStrCat("Generator\n"
  285. " ",
  286. this->GetName(),
  287. "\n"
  288. "given toolset and version specification\n"
  289. " ",
  290. this->GetPlatformToolsetString(),
  291. ",version=", this->GeneratorToolsetVersion,
  292. "\n"
  293. "has multiple matches installed at\n"
  294. " ",
  295. auxProps,
  296. "\n"
  297. "The toolset and version specification must resolve \n"
  298. "to a single installed toolset"));
  299. // Clear the configured tool-set
  300. this->GeneratorToolsetVersion.clear();
  301. this->GeneratorToolsetVersionProps = {};
  302. } break;
  303. }
  304. }
  305. if (char const* toolset = this->GetPlatformToolset()) {
  306. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET", toolset);
  307. }
  308. if (!this->GeneratorToolsetVersion.empty()) {
  309. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VERSION",
  310. this->GeneratorToolsetVersion);
  311. }
  312. if (char const* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  313. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE", hostArch);
  314. }
  315. if (char const* cuda = this->GetPlatformToolsetCuda()) {
  316. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA", cuda);
  317. }
  318. if (char const* cudaDir = this->GetPlatformToolsetCudaCustomDir()) {
  319. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR", cudaDir);
  320. }
  321. if (cm::optional<std::string> fortran = this->GetPlatformToolsetFortran()) {
  322. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_FORTRAN", *fortran);
  323. }
  324. if (char const* vcTargetsDir = this->GetCustomVCTargetsPath()) {
  325. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VCTARGETS_CUSTOM_DIR",
  326. vcTargetsDir);
  327. }
  328. return true;
  329. }
  330. bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset(
  331. std::string const& ts, cmMakefile* mf)
  332. {
  333. std::vector<std::string> const fields =
  334. cmTokenize(ts, ',', cmTokenizerMode::New);
  335. if (fields.empty()) {
  336. return true;
  337. }
  338. auto fi = fields.begin();
  339. // The first field may be the VS platform toolset.
  340. if (fi->find('=') == fi->npos) {
  341. this->GeneratorToolset = *fi;
  342. ++fi;
  343. }
  344. std::set<std::string> handled;
  345. // The rest of the fields must be key=value pairs.
  346. for (; fi != fields.end(); ++fi) {
  347. std::string::size_type pos = fi->find('=');
  348. if (pos == fi->npos) {
  349. mf->IssueMessage(
  350. MessageType::FATAL_ERROR,
  351. cmStrCat("Generator\n"
  352. " ",
  353. this->GetName(),
  354. "\n"
  355. "given toolset specification\n"
  356. " ",
  357. ts,
  358. "\n"
  359. "that contains a field after the first ',' with no '='."));
  360. return false;
  361. }
  362. std::string const key = fi->substr(0, pos);
  363. std::string const value = fi->substr(pos + 1);
  364. if (!handled.insert(key).second) {
  365. mf->IssueMessage(MessageType::FATAL_ERROR,
  366. cmStrCat("Generator\n"
  367. " ",
  368. this->GetName(),
  369. "\n"
  370. "given toolset specification\n"
  371. " ",
  372. ts,
  373. "\n"
  374. "that contains duplicate field key '",
  375. key, "'."));
  376. return false;
  377. }
  378. if (!this->ProcessGeneratorToolsetField(key, value)) {
  379. mf->IssueMessage(MessageType::FATAL_ERROR,
  380. cmStrCat("Generator\n"
  381. " ",
  382. this->GetName(),
  383. "\n"
  384. "given toolset specification\n"
  385. " ",
  386. ts,
  387. "\n"
  388. "that contains invalid field '",
  389. *fi, "'."));
  390. return false;
  391. }
  392. }
  393. return true;
  394. }
  395. bool cmGlobalVisualStudio10Generator::ProcessGeneratorToolsetField(
  396. std::string const& key, std::string const& value)
  397. {
  398. if (key == "cuda"_s) {
  399. /* test if cuda toolset is path to custom dir or cuda version */
  400. auto pos = value.find_first_not_of("0123456789.");
  401. if (pos != std::string::npos) {
  402. this->GeneratorToolsetCudaCustomDir = value;
  403. /* ensure trailing backslash for easy path joining */
  404. if (this->GeneratorToolsetCudaCustomDir.back() != '\\') {
  405. this->GeneratorToolsetCudaCustomDir.push_back('\\');
  406. }
  407. /* check for legacy toolkit folder structure */
  408. if (cmsys::SystemTools::FileIsDirectory(
  409. cmStrCat(this->GeneratorToolsetCudaCustomDir, "nvcc"))) {
  410. this->GeneratorToolsetCudaNvccSubdir = "nvcc\\";
  411. }
  412. if (cmsys::SystemTools::FileIsDirectory(
  413. cmStrCat(this->GeneratorToolsetCudaCustomDir,
  414. "CUDAVisualStudioIntegration"))) {
  415. this->GeneratorToolsetCudaVSIntegrationSubdir =
  416. "CUDAVisualStudioIntegration\\";
  417. }
  418. } else {
  419. this->GeneratorToolsetCuda = value;
  420. }
  421. return true;
  422. }
  423. if (key == "customFlagTableDir"_s) {
  424. this->CustomFlagTableDir = value;
  425. cmSystemTools::ConvertToUnixSlashes(this->CustomFlagTableDir);
  426. return true;
  427. }
  428. if (key == "fortran"_s) {
  429. this->GeneratorToolsetFortran = value;
  430. return true;
  431. }
  432. if (key == "version"_s) {
  433. this->GeneratorToolsetVersion = value;
  434. return true;
  435. }
  436. if (key == "VCTargetsPath"_s) {
  437. this->CustomVCTargetsPath = value;
  438. ConvertToWindowsSlashes(this->CustomVCTargetsPath);
  439. return true;
  440. }
  441. return false;
  442. }
  443. bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf)
  444. {
  445. if (this->SystemName == "Windows"_s) {
  446. if (!this->InitializeWindows(mf)) {
  447. return false;
  448. }
  449. } else if (this->SystemName == "WindowsCE"_s) {
  450. this->SystemIsWindowsCE = true;
  451. if (!this->InitializeWindowsCE(mf)) {
  452. return false;
  453. }
  454. } else if (this->SystemName == "WindowsPhone"_s) {
  455. this->SystemIsWindowsPhone = true;
  456. if (!this->InitializeWindowsPhone(mf)) {
  457. return false;
  458. }
  459. } else if (this->SystemName == "WindowsStore"_s) {
  460. this->SystemIsWindowsStore = true;
  461. if (!this->InitializeWindowsStore(mf)) {
  462. return false;
  463. }
  464. } else if (this->SystemName == "WindowsKernelModeDriver"_s) {
  465. this->SystemIsWindowsKernelModeDriver = true;
  466. if (!this->InitializeWindowsKernelModeDriver(mf)) {
  467. return false;
  468. }
  469. } else if (this->SystemName == "Android"_s) {
  470. if (mf->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM") ==
  471. "Tegra-Android"_s) {
  472. if (!this->InitializeTegraAndroid(mf)) {
  473. return false;
  474. }
  475. } else {
  476. this->SystemIsAndroid = true;
  477. if (!this->InitializeAndroid(mf)) {
  478. return false;
  479. }
  480. }
  481. }
  482. return true;
  483. }
  484. bool cmGlobalVisualStudio10Generator::InitializeWindows(cmMakefile*)
  485. {
  486. return true;
  487. }
  488. bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile*)
  489. {
  490. this->DefaultPlatformToolset = this->SelectWindowsCEToolset();
  491. return true;
  492. }
  493. bool cmGlobalVisualStudio10Generator::InitializeWindowsPhone(cmMakefile* mf)
  494. {
  495. mf->IssueMessage(
  496. MessageType::FATAL_ERROR,
  497. cmStrCat(this->GetName(), " does not support Windows Phone."));
  498. return false;
  499. }
  500. bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf)
  501. {
  502. mf->IssueMessage(
  503. MessageType::FATAL_ERROR,
  504. cmStrCat(this->GetName(), " does not support Windows Store."));
  505. return false;
  506. }
  507. bool cmGlobalVisualStudio10Generator::InitializeWindowsKernelModeDriver(
  508. cmMakefile*)
  509. {
  510. this->DefaultPlatformToolset = "WindowsKernelModeDriver10.0";
  511. return true;
  512. }
  513. bool cmGlobalVisualStudio10Generator::InitializeTegraAndroid(cmMakefile* mf)
  514. {
  515. std::string v =
  516. cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion();
  517. if (v.empty()) {
  518. mf->IssueMessage(MessageType::FATAL_ERROR,
  519. "CMAKE_SYSTEM_NAME is 'Android' but "
  520. "'NVIDIA Nsight Tegra Visual Studio Edition' "
  521. "is not installed.");
  522. return false;
  523. }
  524. this->DefaultPlatformName = "Tegra-Android";
  525. this->DefaultPlatformToolset = "Default";
  526. this->NsightTegraVersion = v;
  527. mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v);
  528. return true;
  529. }
  530. bool cmGlobalVisualStudio10Generator::InitializeAndroid(cmMakefile* mf)
  531. {
  532. mf->IssueMessage(MessageType::FATAL_ERROR,
  533. cmStrCat(this->GetName(), " does not support Android."));
  534. return false;
  535. }
  536. bool cmGlobalVisualStudio10Generator::InitializePlatform(cmMakefile* mf)
  537. {
  538. if (this->SystemName == "Windows"_s ||
  539. this->SystemName == "WindowsStore"_s) {
  540. if (!this->InitializePlatformWindows(mf)) {
  541. return false;
  542. }
  543. } else if (!this->SystemName.empty() &&
  544. !this->VerifyNoGeneratorPlatformVersion(mf)) {
  545. return false;
  546. }
  547. return this->cmGlobalVisualStudio8Generator::InitializePlatform(mf);
  548. }
  549. bool cmGlobalVisualStudio10Generator::InitializePlatformWindows(cmMakefile*)
  550. {
  551. return true;
  552. }
  553. bool cmGlobalVisualStudio10Generator::VerifyNoGeneratorPlatformVersion(
  554. cmMakefile*) const
  555. {
  556. return true;
  557. }
  558. bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
  559. std::string& toolset) const
  560. {
  561. toolset.clear();
  562. return false;
  563. }
  564. bool cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset(
  565. std::string& toolset) const
  566. {
  567. toolset.clear();
  568. return false;
  569. }
  570. std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const
  571. {
  572. if (this->SystemVersion == "8.0"_s) {
  573. return "CE800";
  574. }
  575. return "";
  576. }
  577. //! Create a local generator appropriate to this Global Generator
  578. std::unique_ptr<cmLocalGenerator>
  579. cmGlobalVisualStudio10Generator::CreateLocalGenerator(cmMakefile* mf)
  580. {
  581. return std::unique_ptr<cmLocalGenerator>(
  582. cm::make_unique<cmLocalVisualStudio10Generator>(this, mf));
  583. }
  584. void cmGlobalVisualStudio10Generator::Generate()
  585. {
  586. this->LongestSource = LongestSourcePath();
  587. this->cmGlobalVisualStudio8Generator::Generate();
  588. if (!this->AndroidExecutableWarnings.empty() &&
  589. !this->CMakeInstance->GetIsInTryCompile()) {
  590. std::ostringstream e;
  591. /* clang-format off */
  592. e <<
  593. "You are using Visual Studio tools for Android, which does not support "
  594. "standalone executables. However, the following executable targets do "
  595. "not have the ANDROID_GUI property set, and thus will not be built as "
  596. "expected. They will be built as shared libraries with executable "
  597. "filenames:\n"
  598. " ";
  599. /* clang-format on */
  600. bool first = true;
  601. for (auto const& name : this->AndroidExecutableWarnings) {
  602. if (!first) {
  603. e << ", ";
  604. }
  605. first = false;
  606. e << name;
  607. }
  608. this->CMakeInstance->IssueMessage(MessageType::WARNING, e.str());
  609. }
  610. if (this->LongestSource.Length > 0) {
  611. cmLocalGenerator* lg = this->LongestSource.Target->GetLocalGenerator();
  612. lg->IssueMessage(
  613. MessageType::WARNING,
  614. cmStrCat(
  615. "The binary and/or source directory paths may be too long to generate "
  616. "Visual Studio 10 files for this project. "
  617. "Consider choosing shorter directory names to build this project with "
  618. "Visual Studio 10. "
  619. "A more detailed explanation follows."
  620. "\n"
  621. "There is a bug in the VS 10 IDE that renders property dialog fields "
  622. "blank for files referenced by full path in the project file. "
  623. "However, CMake must reference at least one file by full path:\n"
  624. " ",
  625. this->LongestSource.SourceFile->GetFullPath(),
  626. "\n"
  627. "This is because some Visual Studio tools would append the relative "
  628. "path to the end of the referencing directory path, as in:\n"
  629. " ",
  630. lg->GetCurrentBinaryDirectory(), '/', this->LongestSource.SourceRel,
  631. "\n"
  632. "and then incorrectly complain that the file does not exist because "
  633. "the path length is too long for some internal buffer or API. "
  634. "To avoid this problem CMake must use a full path for this file "
  635. "which then triggers the VS 10 property dialog bug."));
  636. }
  637. if (cmValue cached = this->CMakeInstance->GetState()->GetCacheEntryValue(
  638. "CMAKE_VS_NUGET_PACKAGE_RESTORE")) {
  639. this->CMakeInstance->MarkCliAsUsed("CMAKE_VS_NUGET_PACKAGE_RESTORE");
  640. }
  641. }
  642. void cmGlobalVisualStudio10Generator::EnableLanguage(
  643. std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
  644. {
  645. for (std::string const& it : lang) {
  646. if (it == "ASM_NASM"_s) {
  647. this->NasmEnabled = true;
  648. }
  649. if (it == "CUDA"_s) {
  650. this->CudaEnabled = true;
  651. }
  652. }
  653. this->AddPlatformDefinitions(mf);
  654. cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
  655. }
  656. char const* cmGlobalVisualStudio10Generator::GetCustomVCTargetsPath() const
  657. {
  658. if (this->CustomVCTargetsPath.empty()) {
  659. return nullptr;
  660. }
  661. return this->CustomVCTargetsPath.c_str();
  662. }
  663. char const* cmGlobalVisualStudio10Generator::GetPlatformToolset() const
  664. {
  665. std::string const& toolset = this->GetPlatformToolsetString();
  666. if (toolset.empty()) {
  667. return nullptr;
  668. }
  669. return toolset.c_str();
  670. }
  671. std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString()
  672. const
  673. {
  674. if (!this->GeneratorToolset.empty()) {
  675. return this->GeneratorToolset;
  676. }
  677. if (this->SystemIsAndroid) {
  678. if (!this->DefaultAndroidToolset.empty()) {
  679. return this->DefaultAndroidToolset;
  680. }
  681. } else {
  682. if (!this->DefaultPlatformToolset.empty()) {
  683. return this->DefaultPlatformToolset;
  684. }
  685. }
  686. static std::string const empty;
  687. return empty;
  688. }
  689. std::string const&
  690. cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionProps() const
  691. {
  692. return this->GeneratorToolsetVersionProps;
  693. }
  694. char const*
  695. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const
  696. {
  697. std::string const& hostArch =
  698. this->GetPlatformToolsetHostArchitectureString();
  699. if (hostArch.empty()) {
  700. return nullptr;
  701. }
  702. return hostArch.c_str();
  703. }
  704. std::string const&
  705. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitectureString()
  706. const
  707. {
  708. if (!this->GeneratorToolsetHostArchitecture.empty()) {
  709. return this->GeneratorToolsetHostArchitecture;
  710. }
  711. if (!this->DefaultPlatformToolsetHostArchitecture.empty()) {
  712. return this->DefaultPlatformToolsetHostArchitecture;
  713. }
  714. static std::string const empty;
  715. return empty;
  716. }
  717. char const* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
  718. {
  719. if (!this->GeneratorToolsetCuda.empty()) {
  720. return this->GeneratorToolsetCuda.c_str();
  721. }
  722. return nullptr;
  723. }
  724. std::string const&
  725. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaString() const
  726. {
  727. return this->GeneratorToolsetCuda;
  728. }
  729. char const* cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDir()
  730. const
  731. {
  732. if (!this->GeneratorToolsetCudaCustomDir.empty()) {
  733. return this->GeneratorToolsetCudaCustomDir.c_str();
  734. }
  735. return nullptr;
  736. }
  737. std::string const&
  738. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDirString() const
  739. {
  740. return this->GeneratorToolsetCudaCustomDir;
  741. }
  742. std::string const&
  743. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaNvccSubdirString() const
  744. {
  745. return this->GeneratorToolsetCudaNvccSubdir;
  746. }
  747. std::string const& cmGlobalVisualStudio10Generator::
  748. GetPlatformToolsetCudaVSIntegrationSubdirString() const
  749. {
  750. return this->GeneratorToolsetCudaVSIntegrationSubdir;
  751. }
  752. cm::optional<std::string>
  753. cmGlobalVisualStudio10Generator::GetPlatformToolsetFortran() const
  754. {
  755. if (this->GeneratorToolsetFortran) {
  756. return this->GeneratorToolsetFortran;
  757. }
  758. return this->DefaultToolsetFortran;
  759. }
  760. cmGlobalVisualStudio10Generator::AuxToolset
  761. cmGlobalVisualStudio10Generator::FindAuxToolset(std::string&,
  762. std::string&) const
  763. {
  764. return AuxToolset::None;
  765. }
  766. bool cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf)
  767. {
  768. if (!this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf)) {
  769. return false;
  770. }
  771. mf->AddDefinition("CMAKE_VS_MSBUILD_COMMAND", this->GetMSBuildCommand());
  772. return true;
  773. }
  774. std::string const& cmGlobalVisualStudio10Generator::GetMSBuildCommand()
  775. {
  776. if (!this->MSBuildCommandInitialized) {
  777. this->MSBuildCommandInitialized = true;
  778. this->MSBuildCommand = this->FindMSBuildCommand();
  779. }
  780. return this->MSBuildCommand;
  781. }
  782. cm::optional<std::string>
  783. cmGlobalVisualStudio10Generator::FindMSBuildCommandEarly(cmMakefile*)
  784. {
  785. return this->GetMSBuildCommand();
  786. }
  787. std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand()
  788. {
  789. std::string msbuild;
  790. std::string mskey;
  791. // Search in standard location.
  792. mskey =
  793. cmStrCat(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\)",
  794. this->GetToolsVersion(), ";MSBuildToolsPath");
  795. if (cmSystemTools::ReadRegistryValue(mskey, msbuild,
  796. cmSystemTools::KeyWOW64_32)) {
  797. cmSystemTools::ConvertToUnixSlashes(msbuild);
  798. msbuild += "/MSBuild.exe";
  799. if (cmSystemTools::FileExists(msbuild, true)) {
  800. return msbuild;
  801. }
  802. }
  803. msbuild = "MSBuild.exe";
  804. return msbuild;
  805. }
  806. std::string cmGlobalVisualStudio10Generator::FindDevEnvCommand()
  807. {
  808. if (this->ExpressEdition) {
  809. // Visual Studio Express >= 10 do not have "devenv.com" or
  810. // "VCExpress.exe" that we can use to build reliably.
  811. // Tell the caller it needs to use MSBuild instead.
  812. return "";
  813. }
  814. // Skip over the cmGlobalVisualStudio8Generator implementation because
  815. // we expect a real devenv and do not want to look for VCExpress.
  816. // NOLINTNEXTLINE(bugprone-parent-virtual-call)
  817. return this->cmGlobalVisualStudio7Generator::FindDevEnvCommand();
  818. }
  819. bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
  820. {
  821. // Skip this in special cases within our own test suite.
  822. if (this->GetPlatformName() == "Test Platform"_s ||
  823. this->GetPlatformToolsetString() == "Test Toolset"_s) {
  824. return true;
  825. }
  826. std::string wd;
  827. if (!this->ConfiguredFilesPath.empty()) {
  828. // In a try-compile we are given the outer CMakeFiles directory.
  829. wd = this->ConfiguredFilesPath;
  830. } else {
  831. wd = cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(),
  832. "/CMakeFiles");
  833. }
  834. wd += '/';
  835. wd += cmVersion::GetCMakeVersion();
  836. // We record the result persistently in a file.
  837. std::string const txt = cmStrCat(wd, "/VCTargetsPath.txt");
  838. // If we have a recorded result, use it.
  839. {
  840. cmsys::ifstream fin(txt.c_str());
  841. if (fin && cmSystemTools::GetLineFromStream(fin, this->VCTargetsPath) &&
  842. cmSystemTools::FileIsDirectory(this->VCTargetsPath)) {
  843. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  844. return true;
  845. }
  846. }
  847. // Prepare the work directory.
  848. if (!cmSystemTools::MakeDirectory(wd)) {
  849. mf->IssueMessage(MessageType::FATAL_ERROR,
  850. cmStrCat("Failed to make directory:\n ", wd));
  851. cmSystemTools::SetFatalErrorOccurred();
  852. return false;
  853. }
  854. // Generate a project file for MSBuild to tell us the VCTargetsPath value.
  855. std::string const vcxproj = "VCTargetsPath.vcxproj";
  856. {
  857. std::string const vcxprojAbs = cmStrCat(wd, '/', vcxproj);
  858. cmsys::ofstream fout(vcxprojAbs.c_str());
  859. cmXMLWriter xw(fout);
  860. cmXMLDocument doc(xw);
  861. cmXMLElement eprj(doc, "Project");
  862. eprj.Attribute("DefaultTargets", "Build");
  863. eprj.Attribute("ToolsVersion", "4.0");
  864. eprj.Attribute("xmlns",
  865. "http://schemas.microsoft.com/developer/msbuild/2003");
  866. if (this->IsNsightTegra()) {
  867. cmXMLElement epg(eprj, "PropertyGroup");
  868. epg.Attribute("Label", "NsightTegraProject");
  869. cmXMLElement(epg, "NsightTegraProjectRevisionNumber").Content("6");
  870. }
  871. {
  872. cmXMLElement eig(eprj, "ItemGroup");
  873. eig.Attribute("Label", "ProjectConfigurations");
  874. cmXMLElement epc(eig, "ProjectConfiguration");
  875. epc.Attribute("Include", cmStrCat("Debug|", this->GetPlatformName()));
  876. cmXMLElement(epc, "Configuration").Content("Debug");
  877. cmXMLElement(epc, "Platform").Content(this->GetPlatformName());
  878. }
  879. {
  880. cmXMLElement epg(eprj, "PropertyGroup");
  881. epg.Attribute("Label", "Globals");
  882. cmXMLElement(epg, "ProjectGuid")
  883. .Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}");
  884. cmXMLElement(epg, "Keyword")
  885. .Content(mf->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Android"_s
  886. ? "Android"
  887. : "Win32Proj");
  888. cmXMLElement(epg, "Platform").Content(this->GetPlatformName());
  889. if (this->GetSystemName() == "WindowsPhone"_s) {
  890. cmXMLElement(epg, "ApplicationType").Content("Windows Phone");
  891. cmXMLElement(epg, "ApplicationTypeRevision")
  892. .Content(this->GetApplicationTypeRevision());
  893. } else if (this->GetSystemName() == "WindowsStore"_s) {
  894. cmXMLElement(epg, "ApplicationType").Content("Windows Store");
  895. cmXMLElement(epg, "ApplicationTypeRevision")
  896. .Content(this->GetApplicationTypeRevision());
  897. } else if (this->GetSystemName() == "Android"_s) {
  898. cmXMLElement(epg, "ApplicationType").Content("Android");
  899. cmXMLElement(epg, "ApplicationTypeRevision")
  900. .Content(this->GetApplicationTypeRevision());
  901. }
  902. if (!this->WindowsTargetPlatformVersion.empty()) {
  903. cmXMLElement(epg, "WindowsTargetPlatformVersion")
  904. .Content(this->WindowsTargetPlatformVersion);
  905. }
  906. if (this->GetSystemName() != "Android"_s) {
  907. if (this->GetPlatformName() == "ARM64"_s) {
  908. cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true");
  909. } else if (this->GetPlatformName() == "ARM"_s) {
  910. cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true");
  911. }
  912. }
  913. }
  914. cmXMLElement(eprj, "Import")
  915. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  916. if (char const* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  917. cmXMLElement epg(eprj, "PropertyGroup");
  918. cmXMLElement(epg, "PreferredToolArchitecture").Content(hostArch);
  919. }
  920. {
  921. cmXMLElement epg(eprj, "PropertyGroup");
  922. epg.Attribute("Label", "Configuration");
  923. {
  924. // noqa: spellcheck off
  925. cmXMLElement ect(epg, "ConfigurationType");
  926. if (this->IsNsightTegra()) {
  927. // Tegra-Android platform does not understand "Utility".
  928. ect.Content("StaticLibrary");
  929. } else {
  930. ect.Content("Utility");
  931. }
  932. // noqa: spellcheck on
  933. }
  934. cmXMLElement(epg, "CharacterSet").Content("MultiByte");
  935. if (this->IsNsightTegra()) {
  936. cmXMLElement(epg, "NdkToolchainVersion")
  937. .Content(this->GetPlatformToolsetString());
  938. } else {
  939. cmXMLElement(epg, "PlatformToolset")
  940. .Content(this->GetPlatformToolsetString());
  941. }
  942. }
  943. cmXMLElement(eprj, "Import")
  944. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  945. {
  946. cmXMLElement eidg(eprj, "ItemDefinitionGroup");
  947. cmXMLElement epbe(eidg, "PostBuildEvent");
  948. cmXMLElement(epbe, "Command")
  949. .Content("echo VCTargetsPath=$(VCTargetsPath)");
  950. }
  951. cmXMLElement(eprj, "Import")
  952. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  953. }
  954. std::vector<std::string> cmd;
  955. cmd.push_back(this->GetMSBuildCommand());
  956. cmd.push_back(vcxproj);
  957. cmd.emplace_back("/p:Configuration=Debug");
  958. cmd.emplace_back(cmStrCat("/p:Platform=", this->GetPlatformName()));
  959. cmd.emplace_back(cmStrCat("/p:VisualStudioVersion=", this->GetIDEVersion()));
  960. std::string out;
  961. int ret = 0;
  962. cmsys::RegularExpression regex("\n *VCTargetsPath=([^%\r\n]+)[\r\n]");
  963. if (!cmSystemTools::RunSingleCommand(cmd, &out, &out, &ret, wd.c_str(),
  964. cmSystemTools::OUTPUT_NONE) ||
  965. ret != 0 || !regex.find(out)) {
  966. cmSystemTools::ReplaceString(out, "\n", "\n ");
  967. std::ostringstream e;
  968. /* clang-format off */
  969. e <<
  970. "Failed to run MSBuild command:\n"
  971. " " << cmd[0] << "\n"
  972. "to get the value of VCTargetsPath:\n"
  973. " " << out << '\n'
  974. ;
  975. /* clang-format on */
  976. if (ret != 0) {
  977. e << "Exit code: " << ret << '\n';
  978. }
  979. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  980. cmSystemTools::SetFatalErrorOccurred();
  981. return false;
  982. }
  983. this->VCTargetsPath = regex.match(1);
  984. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  985. {
  986. cmsys::ofstream fout(txt.c_str());
  987. fout << this->VCTargetsPath << '\n';
  988. }
  989. return true;
  990. }
  991. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  992. cmGlobalVisualStudio10Generator::GenerateBuildCommand(
  993. std::string const& makeProgram, std::string const& projectName,
  994. std::string const& projectDir, std::vector<std::string> const& targetNames,
  995. std::string const& config, int jobs, bool verbose,
  996. cmBuildOptions buildOptions, std::vector<std::string> const& makeOptions,
  997. BuildTryCompile /*isInTryCompile*/)
  998. {
  999. std::vector<GeneratedMakeCommand> makeCommands;
  1000. // Select the caller- or user-preferred make program, else MSBuild.
  1001. std::string makeProgramSelected =
  1002. this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand());
  1003. std::string const slnFile = this->GetSLNFile(projectDir, projectName);
  1004. // Check if the caller explicitly requested a devenv tool.
  1005. std::string makeProgramLower = makeProgramSelected;
  1006. cmSystemTools::LowerCase(makeProgramLower);
  1007. bool useDevEnv = (makeProgramLower.find("devenv") != std::string::npos ||
  1008. makeProgramLower.find("vcexpress") != std::string::npos);
  1009. // Workaround to convince VCExpress.exe to produce output.
  1010. bool const requiresOutputForward =
  1011. (makeProgramLower.find("vcexpress") != std::string::npos);
  1012. // MSBuild is preferred (and required for VS Express), but if the .sln has
  1013. // an Intel Fortran .vfproj then we have to use devenv. Parse it to find out.
  1014. cmSlnxParser slnxParser;
  1015. cmSlnData slnData;
  1016. if (this->Version >= VSVersion::VS18) {
  1017. if (slnxParser.ParseFile(slnFile.c_str())) {
  1018. for (auto const& i : slnxParser.ProjectToPath) {
  1019. if (cmHasLiteralSuffix(i.second, ".vfproj")) {
  1020. useDevEnv = true;
  1021. break;
  1022. }
  1023. }
  1024. }
  1025. } else {
  1026. cmVisualStudioSlnParser parser;
  1027. if (parser.ParseFile(slnFile, slnData,
  1028. cmVisualStudioSlnParser::DataGroupAll)) {
  1029. std::vector<cmSlnProjectEntry> slnProjects = slnData.GetProjects();
  1030. for (cmSlnProjectEntry const& project : slnProjects) {
  1031. std::string proj = project.GetRelativePath();
  1032. if (cmHasLiteralSuffix(proj, ".vfproj")) {
  1033. useDevEnv = true;
  1034. break;
  1035. }
  1036. }
  1037. }
  1038. }
  1039. if (useDevEnv) {
  1040. // Use devenv to build solutions containing Intel Fortran projects.
  1041. return cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  1042. makeProgram, projectName, projectDir, targetNames, config, jobs, verbose,
  1043. buildOptions, makeOptions);
  1044. }
  1045. std::vector<std::string> realTargetNames = targetNames;
  1046. if (targetNames.empty() ||
  1047. ((targetNames.size() == 1) && targetNames.front().empty())) {
  1048. realTargetNames = { "ALL_BUILD" };
  1049. }
  1050. for (auto const& tname : realTargetNames) {
  1051. // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug
  1052. // /target:ALL_BUILD
  1053. // /m
  1054. if (tname.empty()) {
  1055. continue;
  1056. }
  1057. GeneratedMakeCommand makeCommand;
  1058. makeCommand.RequiresOutputForward = requiresOutputForward;
  1059. makeCommand.Add(makeProgramSelected);
  1060. if (tname == "clean"_s) {
  1061. makeCommand.Add(slnFile);
  1062. makeCommand.Add("/t:Clean");
  1063. } else {
  1064. std::string targetProject = cmStrCat(tname, ".vcxproj");
  1065. if (targetProject.find('/') == std::string::npos) {
  1066. // it might be in a subdir
  1067. if (this->Version >= VSVersion::VS18) {
  1068. auto i =
  1069. slnxParser.ProjectToPath.find(cmSystemTools::LowerCase(tname));
  1070. if (i != slnxParser.ProjectToPath.end()) {
  1071. targetProject = i->second;
  1072. }
  1073. } else {
  1074. if (cmSlnProjectEntry const* proj =
  1075. slnData.GetProjectByName(tname)) {
  1076. targetProject = proj->GetRelativePath();
  1077. cmSystemTools::ConvertToUnixSlashes(targetProject);
  1078. }
  1079. }
  1080. }
  1081. makeCommand.Add(targetProject);
  1082. // Check if we do need a restore at all (i.e. if there are package
  1083. // references and restore has not been disabled by a command line option.
  1084. PackageResolveMode restoreMode = buildOptions.ResolveMode;
  1085. bool requiresRestore = true;
  1086. if (restoreMode == PackageResolveMode::Disable) {
  1087. requiresRestore = false;
  1088. } else if (cmValue cached =
  1089. this->CMakeInstance->GetState()->GetCacheEntryValue(
  1090. cmStrCat(tname, "_REQUIRES_VS_PACKAGE_RESTORE"))) {
  1091. requiresRestore = cached.IsOn();
  1092. } else {
  1093. // There are no package references defined.
  1094. requiresRestore = false;
  1095. }
  1096. // If a restore is required, evaluate the restore mode.
  1097. if (requiresRestore) {
  1098. if (restoreMode == PackageResolveMode::OnlyResolve) {
  1099. // Only invoke the restore target on the project.
  1100. makeCommand.Add("/t:Restore");
  1101. } else {
  1102. // Invoke restore target, unless it has been explicitly disabled.
  1103. bool restorePackages = true;
  1104. if (this->Version < VSVersion::VS15) {
  1105. // Package restore is only supported starting from Visual Studio
  1106. // 2017. Package restore must be executed manually using NuGet
  1107. // shell for older versions.
  1108. this->CMakeInstance->IssueMessage(
  1109. MessageType::WARNING,
  1110. "Restoring package references is only supported for Visual "
  1111. "Studio 2017 and later. You have to manually restore the "
  1112. "packages using NuGet before building the project.");
  1113. restorePackages = false;
  1114. } else if (restoreMode == PackageResolveMode::Default) {
  1115. // Decide if a restore is performed, based on a cache variable.
  1116. if (cmValue cached =
  1117. this->CMakeInstance->GetState()->GetCacheEntryValue(
  1118. "CMAKE_VS_NUGET_PACKAGE_RESTORE")) {
  1119. restorePackages = cached.IsOn();
  1120. }
  1121. }
  1122. if (restorePackages) {
  1123. if (this->IsMsBuildRestoreSupported()) {
  1124. makeCommand.Add("/restore");
  1125. } else {
  1126. GeneratedMakeCommand restoreCommand;
  1127. restoreCommand.Add(makeProgramSelected);
  1128. restoreCommand.Add(targetProject);
  1129. restoreCommand.Add("/t:Restore");
  1130. makeCommands.emplace_back(restoreCommand);
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }
  1136. makeCommand.Add(
  1137. cmStrCat("/p:Configuration=", config.empty() ? "Debug" : config));
  1138. makeCommand.Add(cmStrCat("/p:Platform=", this->GetPlatformName()));
  1139. makeCommand.Add(
  1140. cmStrCat("/p:VisualStudioVersion=", this->GetIDEVersion()));
  1141. if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
  1142. if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
  1143. makeCommand.Add("/m");
  1144. } else {
  1145. makeCommand.Add(cmStrCat("/m:", jobs));
  1146. }
  1147. }
  1148. // Respect the verbosity: 'n' normal will show build commands
  1149. // 'm' minimal only the build step's title
  1150. makeCommand.Add(cmStrCat("/v:", ((verbose) ? 'n' : 'm')));
  1151. makeCommand.Add(makeOptions.begin(), makeOptions.end());
  1152. makeCommands.emplace_back(std::move(makeCommand));
  1153. }
  1154. return makeCommands;
  1155. }
  1156. std::string cmGlobalVisualStudio10Generator::GenerateRuleFile(
  1157. std::string const& output) const
  1158. {
  1159. // The VS 10 generator needs to create the .rule files on disk.
  1160. // Hide them away under the CMakeFiles directory.
  1161. cmCryptoHash hasher(cmCryptoHash::AlgoMD5);
  1162. std::string ruleDir = cmStrCat(
  1163. this->GetCMakeInstance()->GetHomeOutputDirectory(), "/CMakeFiles/",
  1164. hasher.HashString(cmSystemTools::GetFilenamePath(output)));
  1165. std::string ruleFile =
  1166. cmStrCat(ruleDir, '/', cmSystemTools::GetFilenameName(output), ".rule");
  1167. return ruleFile;
  1168. }
  1169. void cmGlobalVisualStudio10Generator::PathTooLong(cmGeneratorTarget* target,
  1170. cmSourceFile const* sf,
  1171. std::string const& sfRel)
  1172. {
  1173. size_t len =
  1174. (target->GetLocalGenerator()->GetCurrentBinaryDirectory().length() + 1 +
  1175. sfRel.length());
  1176. if (len > this->LongestSource.Length) {
  1177. this->LongestSource.Length = len;
  1178. this->LongestSource.Target = target;
  1179. this->LongestSource.SourceFile = sf;
  1180. this->LongestSource.SourceRel = sfRel;
  1181. }
  1182. }
  1183. std::string cmGlobalVisualStudio10Generator::Encoding()
  1184. {
  1185. return "utf-8";
  1186. }
  1187. char const* cmGlobalVisualStudio10Generator::GetToolsVersion() const
  1188. {
  1189. switch (this->Version) {
  1190. case cmGlobalVisualStudioGenerator::VSVersion::VS14:
  1191. return "14.0";
  1192. case cmGlobalVisualStudioGenerator::VSVersion::VS15:
  1193. return "15.0";
  1194. case cmGlobalVisualStudioGenerator::VSVersion::VS16:
  1195. return "16.0";
  1196. case cmGlobalVisualStudioGenerator::VSVersion::VS17:
  1197. return "17.0";
  1198. case cmGlobalVisualStudioGenerator::VSVersion::VS18:
  1199. return "18.0";
  1200. }
  1201. return "";
  1202. }
  1203. bool cmGlobalVisualStudio10Generator::IsNsightTegra() const
  1204. {
  1205. return !this->NsightTegraVersion.empty();
  1206. }
  1207. std::string cmGlobalVisualStudio10Generator::GetNsightTegraVersion() const
  1208. {
  1209. return this->NsightTegraVersion;
  1210. }
  1211. std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
  1212. {
  1213. std::string version;
  1214. cmSystemTools::ReadRegistryValue(
  1215. "HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;"
  1216. "Version",
  1217. version, cmSystemTools::KeyWOW64_32);
  1218. return version;
  1219. }
  1220. std::string cmGlobalVisualStudio10Generator::GetApplicationTypeRevision() const
  1221. {
  1222. if (this->GetSystemName() == "Android"_s) {
  1223. return this->GetAndroidApplicationTypeRevision();
  1224. }
  1225. // Return the first two '.'-separated components of the Windows version.
  1226. std::string::size_type end1 = this->SystemVersion.find('.');
  1227. std::string::size_type end2 =
  1228. end1 == std::string::npos ? end1 : this->SystemVersion.find('.', end1 + 1);
  1229. return this->SystemVersion.substr(0, end2);
  1230. }
  1231. static std::string cmLoadFlagTableString(Json::Value entry, char const* field)
  1232. {
  1233. if (entry.isMember(field)) {
  1234. auto string = entry[field];
  1235. if (string.isConvertibleTo(Json::ValueType::stringValue)) {
  1236. return string.asString();
  1237. }
  1238. }
  1239. return "";
  1240. }
  1241. static unsigned int cmLoadFlagTableSpecial(Json::Value entry,
  1242. char const* field)
  1243. {
  1244. unsigned int value = 0;
  1245. if (entry.isMember(field)) {
  1246. auto specials = entry[field];
  1247. if (specials.isArray()) {
  1248. for (auto const& special : specials) {
  1249. std::string s = special.asString();
  1250. if (s == "UserValue"_s) {
  1251. value |= cmIDEFlagTable::UserValue;
  1252. } else if (s == "UserIgnored"_s) {
  1253. value |= cmIDEFlagTable::UserIgnored;
  1254. } else if (s == "UserRequired"_s) {
  1255. value |= cmIDEFlagTable::UserRequired;
  1256. } else if (s == "Continue"_s) {
  1257. value |= cmIDEFlagTable::Continue;
  1258. } else if (s == "SemicolonAppendable"_s) {
  1259. value |= cmIDEFlagTable::SemicolonAppendable;
  1260. } else if (s == "UserFollowing"_s) {
  1261. value |= cmIDEFlagTable::UserFollowing;
  1262. } else if (s == "CaseInsensitive"_s) {
  1263. value |= cmIDEFlagTable::CaseInsensitive;
  1264. } else if (s == "SpaceAppendable"_s) {
  1265. value |= cmIDEFlagTable::SpaceAppendable;
  1266. } else if (s == "CommaAppendable"_s) {
  1267. value |= cmIDEFlagTable::CommaAppendable;
  1268. }
  1269. }
  1270. }
  1271. }
  1272. return value;
  1273. }
  1274. namespace {
  1275. cmIDEFlagTable const* cmLoadFlagTableJson(std::string const& flagJsonPath,
  1276. cm::optional<std::string> vsVer)
  1277. {
  1278. cmIDEFlagTable* ret = nullptr;
  1279. auto savedFlagIterator = loadedFlagJsonFiles.find(flagJsonPath);
  1280. if (savedFlagIterator != loadedFlagJsonFiles.end()) {
  1281. ret = savedFlagIterator->second.data();
  1282. } else {
  1283. Json::Reader reader;
  1284. cmsys::ifstream stream;
  1285. stream.open(flagJsonPath.c_str(), std::ios_base::in);
  1286. if (stream) {
  1287. Json::Value flags;
  1288. if (reader.parse(stream, flags, false) && flags.isArray()) {
  1289. std::vector<cmIDEFlagTable> flagTable;
  1290. for (auto const& flag : flags) {
  1291. Json::Value const& vsminJson = flag["vsmin"];
  1292. if (vsminJson.isString()) {
  1293. std::string const& vsmin = vsminJson.asString();
  1294. if (!vsmin.empty()) {
  1295. if (!vsVer ||
  1296. cmSystemTools::VersionCompareGreater(vsmin, *vsVer)) {
  1297. continue;
  1298. }
  1299. }
  1300. }
  1301. cmIDEFlagTable flagEntry;
  1302. flagEntry.IDEName = cmLoadFlagTableString(flag, "name");
  1303. flagEntry.commandFlag = cmLoadFlagTableString(flag, "switch");
  1304. flagEntry.comment = cmLoadFlagTableString(flag, "comment");
  1305. flagEntry.value = cmLoadFlagTableString(flag, "value");
  1306. flagEntry.special = cmLoadFlagTableSpecial(flag, "flags");
  1307. flagTable.push_back(flagEntry);
  1308. }
  1309. cmIDEFlagTable endFlag{ "", "", "", "", 0 };
  1310. flagTable.push_back(endFlag);
  1311. loadedFlagJsonFiles[flagJsonPath] = flagTable;
  1312. ret = loadedFlagJsonFiles[flagJsonPath].data();
  1313. }
  1314. }
  1315. }
  1316. return ret;
  1317. }
  1318. }
  1319. cm::optional<std::string> cmGlobalVisualStudio10Generator::FindFlagTable(
  1320. cm::string_view toolsetName, cm::string_view table) const
  1321. {
  1322. if (!this->CustomFlagTableDir.empty()) {
  1323. std::string customFlagTableFile =
  1324. cmStrCat(this->CustomFlagTableDir, '/', this->GetPlatformName(), '_',
  1325. toolsetName, '_', table, ".json");
  1326. if (cmSystemTools::FileExists(customFlagTableFile)) {
  1327. return customFlagTableFile;
  1328. }
  1329. customFlagTableFile =
  1330. cmStrCat(this->CustomFlagTableDir, '/', this->GetPlatformName(), '_',
  1331. table, ".json");
  1332. if (cmSystemTools::FileExists(customFlagTableFile)) {
  1333. return customFlagTableFile;
  1334. }
  1335. }
  1336. std::string fullPath =
  1337. cmStrCat(cmSystemTools::GetCMakeRoot(), "/Templates/MSBuild/FlagTables/",
  1338. toolsetName, '_', table, ".json");
  1339. if (cmSystemTools::FileExists(fullPath)) {
  1340. return fullPath;
  1341. }
  1342. return {};
  1343. }
  1344. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable(
  1345. std::string const& toolSpecificName, std::string const& defaultName,
  1346. std::string const& table) const
  1347. {
  1348. cmMakefile* mf = this->GetCurrentMakefile();
  1349. std::string filename;
  1350. if (!toolSpecificName.empty()) {
  1351. if (cm::optional<std::string> found =
  1352. this->FindFlagTable(toolSpecificName, table)) {
  1353. filename = std::move(*found);
  1354. } else {
  1355. mf->IssueMessage(MessageType::FATAL_ERROR,
  1356. cmStrCat("JSON flag table for ", table,
  1357. " not found for toolset ", toolSpecificName));
  1358. return nullptr;
  1359. }
  1360. } else {
  1361. std::string const& genericName =
  1362. this->CanonicalToolsetName(this->GetPlatformToolsetString());
  1363. cm::optional<std::string> found = this->FindFlagTable(genericName, table);
  1364. if (!found) {
  1365. found = this->FindFlagTable(defaultName, table);
  1366. }
  1367. if (found) {
  1368. filename = std::move(*found);
  1369. } else {
  1370. mf->IssueMessage(MessageType::FATAL_ERROR,
  1371. cmStrCat("JSON flag table for ", table,
  1372. " not found for toolset ", genericName, ' ',
  1373. defaultName));
  1374. return nullptr;
  1375. }
  1376. }
  1377. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1378. if (cmIDEFlagTable const* ret = cmLoadFlagTableJson(filename, vsVer)) {
  1379. return ret;
  1380. }
  1381. mf->IssueMessage(
  1382. MessageType::FATAL_ERROR,
  1383. cmStrCat("JSON flag table could not be loaded:\n ", filename));
  1384. return nullptr;
  1385. }
  1386. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const
  1387. {
  1388. return LoadFlagTable(this->GetClFlagTableName(),
  1389. this->DefaultCLFlagTableName, "CL");
  1390. }
  1391. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable()
  1392. const
  1393. {
  1394. return LoadFlagTable(this->GetCSharpFlagTableName(),
  1395. this->DefaultCSharpFlagTableName, "CSharp");
  1396. }
  1397. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const
  1398. {
  1399. return LoadFlagTable(this->GetRcFlagTableName(),
  1400. this->DefaultRCFlagTableName, "RC");
  1401. }
  1402. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const
  1403. {
  1404. return LoadFlagTable(this->GetLibFlagTableName(),
  1405. this->DefaultLibFlagTableName, "LIB");
  1406. }
  1407. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const
  1408. {
  1409. return LoadFlagTable(this->GetLinkFlagTableName(),
  1410. this->DefaultLinkFlagTableName, "Link");
  1411. }
  1412. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaFlagTable() const
  1413. {
  1414. return LoadFlagTable(std::string(), this->DefaultCudaFlagTableName, "Cuda");
  1415. }
  1416. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaHostFlagTable()
  1417. const
  1418. {
  1419. return LoadFlagTable(std::string(), this->DefaultCudaHostFlagTableName,
  1420. "CudaHost");
  1421. }
  1422. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMarmasmFlagTable()
  1423. const
  1424. {
  1425. return LoadFlagTable(std::string(), this->DefaultMarmasmFlagTableName,
  1426. "MARMASM");
  1427. }
  1428. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const
  1429. {
  1430. return LoadFlagTable(this->GetMasmFlagTableName(),
  1431. this->DefaultMasmFlagTableName, "MASM");
  1432. }
  1433. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const
  1434. {
  1435. return LoadFlagTable(std::string(), this->DefaultNasmFlagTableName, "NASM");
  1436. }
  1437. bool cmGlobalVisualStudio10Generator::IsMsBuildRestoreSupported() const
  1438. {
  1439. if (this->Version >= VSVersion::VS16) {
  1440. return true;
  1441. }
  1442. static std::string const vsVer15_7_5 = "15.7.27703.2042";
  1443. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1444. return (vsVer &&
  1445. cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer15_7_5));
  1446. }
  1447. bool cmGlobalVisualStudio10Generator::IsBuildInParallelSupported() const
  1448. {
  1449. if (this->Version >= VSVersion::VS16) {
  1450. return true;
  1451. }
  1452. static std::string const vsVer15_8_0 = "15.8.27705.0";
  1453. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1454. return (vsVer &&
  1455. cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer15_8_0));
  1456. }
  1457. bool cmGlobalVisualStudio10Generator::SupportsShortObjectNames() const
  1458. {
  1459. return true;
  1460. }
  1461. std::string cmGlobalVisualStudio10Generator::GetClFlagTableName() const
  1462. {
  1463. std::string const& toolset = this->GetPlatformToolsetString();
  1464. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1465. if (toolset == "v142"_s) {
  1466. return "v142";
  1467. }
  1468. if (toolset == "v141"_s) {
  1469. return "v141";
  1470. }
  1471. if (useToolset == "v140"_s) {
  1472. return "v140";
  1473. }
  1474. if (useToolset == "v120"_s) {
  1475. return "v12";
  1476. }
  1477. if (useToolset == "v110"_s) {
  1478. return "v11";
  1479. }
  1480. if (useToolset == "v100"_s) {
  1481. return "v10";
  1482. }
  1483. return "";
  1484. }
  1485. std::string cmGlobalVisualStudio10Generator::GetCSharpFlagTableName() const
  1486. {
  1487. std::string const& toolset = this->GetPlatformToolsetString();
  1488. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1489. if (useToolset == "v142"_s) {
  1490. return "v142";
  1491. }
  1492. if (useToolset == "v141"_s) {
  1493. return "v141";
  1494. }
  1495. if (useToolset == "v140"_s) {
  1496. return "v140";
  1497. }
  1498. if (useToolset == "v120"_s) {
  1499. return "v12";
  1500. }
  1501. if (useToolset == "v110"_s) {
  1502. return "v11";
  1503. }
  1504. if (useToolset == "v100"_s) {
  1505. return "v10";
  1506. }
  1507. return "";
  1508. }
  1509. std::string cmGlobalVisualStudio10Generator::GetRcFlagTableName() const
  1510. {
  1511. std::string const& toolset = this->GetPlatformToolsetString();
  1512. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1513. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1514. (useToolset == "v142"_s)) {
  1515. return "v14";
  1516. }
  1517. if (useToolset == "v120"_s) {
  1518. return "v12";
  1519. }
  1520. if (useToolset == "v110"_s) {
  1521. return "v11";
  1522. }
  1523. if (useToolset == "v100"_s) {
  1524. return "v10";
  1525. }
  1526. return "";
  1527. }
  1528. std::string cmGlobalVisualStudio10Generator::GetLibFlagTableName() const
  1529. {
  1530. std::string const& toolset = this->GetPlatformToolsetString();
  1531. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1532. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1533. (useToolset == "v142"_s)) {
  1534. return "v14";
  1535. }
  1536. if (useToolset == "v120"_s) {
  1537. return "v12";
  1538. }
  1539. if (useToolset == "v110"_s) {
  1540. return "v11";
  1541. }
  1542. if (useToolset == "v100"_s) {
  1543. return "v10";
  1544. }
  1545. return "";
  1546. }
  1547. std::string cmGlobalVisualStudio10Generator::GetLinkFlagTableName() const
  1548. {
  1549. std::string const& toolset = this->GetPlatformToolsetString();
  1550. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1551. if (useToolset == "v142"_s) {
  1552. return "v142";
  1553. }
  1554. if (useToolset == "v141"_s) {
  1555. return "v141";
  1556. }
  1557. if (useToolset == "v140"_s) {
  1558. return "v140";
  1559. }
  1560. if (useToolset == "v120"_s) {
  1561. return "v12";
  1562. }
  1563. if (useToolset == "v110"_s) {
  1564. return "v11";
  1565. }
  1566. if (useToolset == "v100"_s) {
  1567. return "v10";
  1568. }
  1569. return "";
  1570. }
  1571. std::string cmGlobalVisualStudio10Generator::GetMasmFlagTableName() const
  1572. {
  1573. std::string const& toolset = this->GetPlatformToolsetString();
  1574. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1575. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1576. (useToolset == "v142"_s)) {
  1577. return "v14";
  1578. }
  1579. if (useToolset == "v120"_s) {
  1580. return "v12";
  1581. }
  1582. if (useToolset == "v110"_s) {
  1583. return "v11";
  1584. }
  1585. if (useToolset == "v100"_s) {
  1586. return "v10";
  1587. }
  1588. return "";
  1589. }
  1590. std::string cmGlobalVisualStudio10Generator::CanonicalToolsetName(
  1591. std::string const& toolset) const
  1592. {
  1593. std::size_t length = toolset.length();
  1594. if (cmHasLiteralSuffix(toolset, "_xp")) {
  1595. length -= 3;
  1596. }
  1597. return toolset.substr(0, length);
  1598. }