cmGlobalVisualStudio10Generator.cxx 56 KB

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