cmGlobalVisualStudio10Generator.cxx 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  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 "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, std::string const& name)
  48. : cmGlobalVisualStudio8Generator(cm, name)
  49. {
  50. this->DefaultCudaFlagTableName = "v10";
  51. this->DefaultCudaHostFlagTableName = "v10";
  52. this->DefaultMarmasmFlagTableName = "v10";
  53. this->DefaultNasmFlagTableName = "v10";
  54. }
  55. bool cmGlobalVisualStudio10Generator::SetSystemName(std::string const& s,
  56. cmMakefile* mf)
  57. {
  58. this->SystemName = s;
  59. this->SystemVersion = mf->GetSafeDefinition("CMAKE_SYSTEM_VERSION");
  60. if (!this->InitializeSystem(mf)) {
  61. return false;
  62. }
  63. return this->cmGlobalVisualStudio8Generator::SetSystemName(s, mf);
  64. }
  65. static void cmCudaToolVersion(std::string& s)
  66. {
  67. // "CUDA x.y.props" => "x.y"
  68. s = s.substr(5);
  69. s = s.substr(0, s.size() - 6);
  70. }
  71. bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
  72. std::string const& ts, bool build, cmMakefile* mf)
  73. {
  74. if (this->SystemIsWindowsCE && ts.empty() &&
  75. this->DefaultPlatformToolset.empty()) {
  76. mf->IssueMessage(
  77. MessageType::FATAL_ERROR,
  78. cmStrCat(this->GetName(), " Windows CE version '", this->SystemVersion,
  79. "' requires CMAKE_GENERATOR_TOOLSET to be set."));
  80. return false;
  81. }
  82. if (!this->ParseGeneratorToolset(ts, mf)) {
  83. return false;
  84. }
  85. if (build) {
  86. return true;
  87. }
  88. if (this->CustomVCTargetsPath.empty() && !this->FindVCTargetsPath(mf)) {
  89. return false;
  90. }
  91. if (!this->CustomFlagTableDir.empty() &&
  92. !(cmSystemTools::FileIsFullPath(this->CustomFlagTableDir) &&
  93. cmSystemTools::FileIsDirectory(this->CustomFlagTableDir))) {
  94. mf->IssueMessage(
  95. MessageType::FATAL_ERROR,
  96. cmStrCat("Generator\n"
  97. " ",
  98. this->GetName(),
  99. "\n"
  100. "given toolset\n"
  101. " customFlagTableDir=",
  102. this->CustomFlagTableDir,
  103. "\n"
  104. "that is not an absolute path to an existing directory."));
  105. cmSystemTools::SetFatalErrorOccurred();
  106. return false;
  107. }
  108. if (cmHasLiteralPrefix(this->GetPlatformToolsetString(), "v140")) {
  109. // The GenerateDebugInformation link setting for the v140 toolset
  110. // in VS 2015 was originally an enum with "No" and "Debug" values,
  111. // differing from the "false" and "true" values used in older toolsets.
  112. // A VS 2015 update changed it back. Parse the "link.xml" file to
  113. // discover which one we need.
  114. std::string const link_xml =
  115. cmStrCat(this->VCTargetsPath, "/1033/link.xml");
  116. cmsys::ifstream fin(link_xml.c_str());
  117. std::string line;
  118. while (fin && cmSystemTools::GetLineFromStream(fin, line)) {
  119. if (line.find(" Switch=\"DEBUG\" ") != std::string::npos) {
  120. this->PlatformToolsetNeedsDebugEnum =
  121. line.find(" Name=\"Debug\" ") != std::string::npos;
  122. break;
  123. }
  124. }
  125. }
  126. this->SupportsUnityBuilds =
  127. this->Version >= cmGlobalVisualStudioGenerator::VSVersion::VS16 ||
  128. (this->Version == cmGlobalVisualStudioGenerator::VSVersion::VS15 &&
  129. cmSystemTools::PathExists(
  130. cmStrCat(this->VCTargetsPath, "/Microsoft.Cpp.Unity.targets")));
  131. if (this->GeneratorToolsetCuda.empty()) {
  132. // Find the highest available version of the CUDA tools.
  133. std::vector<std::string> cudaTools;
  134. std::string bcDir;
  135. if (this->GeneratorToolsetCudaCustomDir.empty()) {
  136. bcDir = cmStrCat(this->VCTargetsPath, "/BuildCustomizations");
  137. } else {
  138. bcDir = cmStrCat(this->GetPlatformToolsetCudaCustomDirString(),
  139. this->GetPlatformToolsetCudaVSIntegrationSubdirString(),
  140. "extras\\visual_studio_integration\\MSBuildExtensions");
  141. cmSystemTools::ConvertToUnixSlashes(bcDir);
  142. }
  143. cmsys::Glob gl;
  144. gl.SetRelative(bcDir.c_str());
  145. if (gl.FindFiles(cmStrCat(bcDir, "/CUDA *.props"))) {
  146. cudaTools = gl.GetFiles();
  147. }
  148. if (!cudaTools.empty()) {
  149. std::for_each(cudaTools.begin(), cudaTools.end(), cmCudaToolVersion);
  150. std::sort(cudaTools.begin(), cudaTools.end(),
  151. cmSystemTools::VersionCompareGreater);
  152. this->GeneratorToolsetCuda = cudaTools.at(0);
  153. } else if (!this->GeneratorToolsetCudaCustomDir.empty()) {
  154. // Generate an error if Visual Studio integration files are not found
  155. // inside of custom cuda toolset.
  156. mf->IssueMessage(
  157. MessageType::FATAL_ERROR,
  158. cmStrCat("Generator\n"
  159. " ",
  160. this->GetName(),
  161. "\n"
  162. "given toolset\n"
  163. " cuda=",
  164. this->GeneratorToolsetCudaCustomDir,
  165. "\n"
  166. "cannot detect Visual Studio integration files in path\n"
  167. " ",
  168. bcDir));
  169. // Clear the configured tool-set
  170. this->GeneratorToolsetCuda.clear();
  171. }
  172. }
  173. if (this->GeneratorToolsetFortran) {
  174. if (*this->GeneratorToolsetFortran != "ifx" &&
  175. *this->GeneratorToolsetFortran != "ifort") {
  176. mf->IssueMessage(MessageType::FATAL_ERROR,
  177. cmStrCat("Generator\n"
  178. " ",
  179. this->GetName(),
  180. "\n"
  181. "given toolset\n"
  182. " fortran=",
  183. *this->GeneratorToolsetFortran,
  184. "\n"
  185. "but the value is not \"ifx\" or \"ifort\"."));
  186. this->GeneratorToolsetFortran = cm::nullopt;
  187. }
  188. }
  189. if (!this->GeneratorToolsetVersion.empty() &&
  190. this->GeneratorToolsetVersion != "Test Toolset Version"_s) {
  191. // If a specific minor version of the MSVC toolset is requested, verify
  192. // that it is compatible with the PlatformToolset version. The ability to
  193. // choose a minor version of MSVC has been available since v141.
  194. std::string const& platformToolset = this->GetPlatformToolsetString();
  195. cmsys::RegularExpression vcPlatformToolsetRegex("^v[0-9][0-9][0-9]$");
  196. if (vcPlatformToolsetRegex.find(platformToolset) ||
  197. platformToolset == "Test Toolset"_s) {
  198. std::string versionToolset = this->GeneratorToolsetVersion;
  199. cmsys::RegularExpression versionToolsetRegex(
  200. "^([0-9][0-9])\\.([0-9])[0-9](\\.|$)");
  201. if (versionToolsetRegex.find(versionToolset)) {
  202. versionToolset = cmStrCat('v', versionToolsetRegex.match(1),
  203. versionToolsetRegex.match(2));
  204. // Hard-code special cases for toolset versions whose first
  205. // three digits do not match their toolset name.
  206. // The v143 toolset reserves versions 14.30 through 14.49.
  207. if (platformToolset == "v143"_s && versionToolset == "v144"_s) {
  208. versionToolset = "v143";
  209. }
  210. } else {
  211. // Version not recognized. Clear it.
  212. versionToolset.clear();
  213. }
  214. if (versionToolset != platformToolset) {
  215. mf->IssueMessage(
  216. MessageType::FATAL_ERROR,
  217. cmStrCat("Generator\n"
  218. " ",
  219. this->GetName(),
  220. "\n"
  221. "given toolset and version specification\n"
  222. " ",
  223. this->GetPlatformToolsetString(),
  224. ",version=", this->GeneratorToolsetVersion,
  225. "\n"
  226. "contains an invalid version specification."));
  227. // Clear the configured tool-set
  228. this->GeneratorToolsetVersion.clear();
  229. }
  230. }
  231. std::string auxProps;
  232. switch (this->FindAuxToolset(this->GeneratorToolsetVersion, auxProps)) {
  233. case AuxToolset::None:
  234. this->GeneratorToolsetVersionProps = {};
  235. break;
  236. case AuxToolset::Default:
  237. // The given version is the default toolset. Remove the setting.
  238. this->GeneratorToolsetVersion.clear();
  239. this->GeneratorToolsetVersionProps = {};
  240. break;
  241. case AuxToolset::PropsExist:
  242. this->GeneratorToolsetVersionProps = std::move(auxProps);
  243. break;
  244. case AuxToolset::PropsMissing: {
  245. mf->IssueMessage(MessageType::FATAL_ERROR,
  246. cmStrCat("Generator\n"
  247. " ",
  248. this->GetName(),
  249. "\n"
  250. "given toolset and version specification\n"
  251. " ",
  252. this->GetPlatformToolsetString(),
  253. ",version=", this->GeneratorToolsetVersion,
  254. "\n"
  255. "does not seem to be installed at\n"
  256. " ",
  257. auxProps));
  258. // Clear the configured tool-set
  259. this->GeneratorToolsetVersion.clear();
  260. this->GeneratorToolsetVersionProps = {};
  261. } break;
  262. case AuxToolset::PropsIndeterminate: {
  263. mf->IssueMessage(
  264. 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. "has multiple matches installed at\n"
  275. " ",
  276. auxProps,
  277. "\n"
  278. "The toolset and version specification must resolve \n"
  279. "to a single installed toolset"));
  280. // Clear the configured tool-set
  281. this->GeneratorToolsetVersion.clear();
  282. this->GeneratorToolsetVersionProps = {};
  283. } break;
  284. }
  285. }
  286. if (char const* toolset = this->GetPlatformToolset()) {
  287. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET", toolset);
  288. }
  289. if (!this->GeneratorToolsetVersion.empty()) {
  290. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VERSION",
  291. this->GeneratorToolsetVersion);
  292. }
  293. if (char const* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  294. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE", hostArch);
  295. }
  296. if (char const* cuda = this->GetPlatformToolsetCuda()) {
  297. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA", cuda);
  298. }
  299. if (char const* cudaDir = this->GetPlatformToolsetCudaCustomDir()) {
  300. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR", cudaDir);
  301. }
  302. if (cm::optional<std::string> fortran = this->GetPlatformToolsetFortran()) {
  303. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_FORTRAN", *fortran);
  304. }
  305. if (char const* vcTargetsDir = this->GetCustomVCTargetsPath()) {
  306. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VCTARGETS_CUSTOM_DIR",
  307. vcTargetsDir);
  308. }
  309. return true;
  310. }
  311. bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset(
  312. std::string const& ts, cmMakefile* mf)
  313. {
  314. std::vector<std::string> const fields =
  315. cmTokenize(ts, ',', cmTokenizerMode::New);
  316. if (fields.empty()) {
  317. return true;
  318. }
  319. auto fi = fields.begin();
  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 == "WindowsKernelModeDriver"_s) {
  446. this->SystemIsWindowsKernelModeDriver = true;
  447. if (!this->InitializeWindowsKernelModeDriver(mf)) {
  448. return false;
  449. }
  450. } else if (this->SystemName == "Android"_s) {
  451. if (mf->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM") ==
  452. "Tegra-Android"_s) {
  453. if (!this->InitializeTegraAndroid(mf)) {
  454. return false;
  455. }
  456. } else {
  457. this->SystemIsAndroid = true;
  458. if (!this->InitializeAndroid(mf)) {
  459. return false;
  460. }
  461. }
  462. }
  463. return true;
  464. }
  465. bool cmGlobalVisualStudio10Generator::InitializeWindows(cmMakefile*)
  466. {
  467. return true;
  468. }
  469. bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile*)
  470. {
  471. this->DefaultPlatformToolset = this->SelectWindowsCEToolset();
  472. return true;
  473. }
  474. bool cmGlobalVisualStudio10Generator::InitializeWindowsPhone(cmMakefile* mf)
  475. {
  476. mf->IssueMessage(
  477. MessageType::FATAL_ERROR,
  478. cmStrCat(this->GetName(), " does not support Windows Phone."));
  479. return false;
  480. }
  481. bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf)
  482. {
  483. mf->IssueMessage(
  484. MessageType::FATAL_ERROR,
  485. cmStrCat(this->GetName(), " does not support Windows Store."));
  486. return false;
  487. }
  488. bool cmGlobalVisualStudio10Generator::InitializeWindowsKernelModeDriver(
  489. cmMakefile*)
  490. {
  491. this->DefaultPlatformToolset = "WindowsKernelModeDriver10.0";
  492. return true;
  493. }
  494. bool cmGlobalVisualStudio10Generator::InitializeTegraAndroid(cmMakefile* mf)
  495. {
  496. std::string v =
  497. cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion();
  498. if (v.empty()) {
  499. mf->IssueMessage(MessageType::FATAL_ERROR,
  500. "CMAKE_SYSTEM_NAME is 'Android' but "
  501. "'NVIDIA Nsight Tegra Visual Studio Edition' "
  502. "is not installed.");
  503. return false;
  504. }
  505. this->DefaultPlatformName = "Tegra-Android";
  506. this->DefaultPlatformToolset = "Default";
  507. this->NsightTegraVersion = v;
  508. mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v);
  509. return true;
  510. }
  511. bool cmGlobalVisualStudio10Generator::InitializeAndroid(cmMakefile* mf)
  512. {
  513. mf->IssueMessage(MessageType::FATAL_ERROR,
  514. cmStrCat(this->GetName(), " does not support Android."));
  515. return false;
  516. }
  517. bool cmGlobalVisualStudio10Generator::InitializePlatform(cmMakefile* mf)
  518. {
  519. if (this->SystemName == "Windows"_s ||
  520. this->SystemName == "WindowsStore"_s) {
  521. if (!this->InitializePlatformWindows(mf)) {
  522. return false;
  523. }
  524. } else if (!this->SystemName.empty() &&
  525. !this->VerifyNoGeneratorPlatformVersion(mf)) {
  526. return false;
  527. }
  528. return this->cmGlobalVisualStudio8Generator::InitializePlatform(mf);
  529. }
  530. bool cmGlobalVisualStudio10Generator::InitializePlatformWindows(cmMakefile*)
  531. {
  532. return true;
  533. }
  534. bool cmGlobalVisualStudio10Generator::VerifyNoGeneratorPlatformVersion(
  535. cmMakefile*) const
  536. {
  537. return true;
  538. }
  539. bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
  540. std::string& toolset) const
  541. {
  542. toolset.clear();
  543. return false;
  544. }
  545. bool cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset(
  546. std::string& toolset) const
  547. {
  548. toolset.clear();
  549. return false;
  550. }
  551. std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const
  552. {
  553. if (this->SystemVersion == "8.0"_s) {
  554. return "CE800";
  555. }
  556. return "";
  557. }
  558. //! Create a local generator appropriate to this Global Generator
  559. std::unique_ptr<cmLocalGenerator>
  560. cmGlobalVisualStudio10Generator::CreateLocalGenerator(cmMakefile* mf)
  561. {
  562. return std::unique_ptr<cmLocalGenerator>(
  563. cm::make_unique<cmLocalVisualStudio10Generator>(this, mf));
  564. }
  565. void cmGlobalVisualStudio10Generator::Generate()
  566. {
  567. this->LongestSource = LongestSourcePath();
  568. this->cmGlobalVisualStudio8Generator::Generate();
  569. if (!this->AndroidExecutableWarnings.empty() &&
  570. !this->CMakeInstance->GetIsInTryCompile()) {
  571. std::ostringstream e;
  572. /* clang-format off */
  573. e <<
  574. "You are using Visual Studio tools for Android, which does not support "
  575. "standalone executables. However, the following executable targets do "
  576. "not have the ANDROID_GUI property set, and thus will not be built as "
  577. "expected. They will be built as shared libraries with executable "
  578. "filenames:\n"
  579. " ";
  580. /* clang-format on */
  581. bool first = true;
  582. for (auto const& name : this->AndroidExecutableWarnings) {
  583. if (!first) {
  584. e << ", ";
  585. }
  586. first = false;
  587. e << name;
  588. }
  589. this->CMakeInstance->IssueMessage(MessageType::WARNING, e.str());
  590. }
  591. if (this->LongestSource.Length > 0) {
  592. cmLocalGenerator* lg = this->LongestSource.Target->GetLocalGenerator();
  593. lg->IssueMessage(
  594. MessageType::WARNING,
  595. cmStrCat(
  596. "The binary and/or source directory paths may be too long to generate "
  597. "Visual Studio 10 files for this project. "
  598. "Consider choosing shorter directory names to build this project with "
  599. "Visual Studio 10. "
  600. "A more detailed explanation follows."
  601. "\n"
  602. "There is a bug in the VS 10 IDE that renders property dialog fields "
  603. "blank for files referenced by full path in the project file. "
  604. "However, CMake must reference at least one file by full path:\n"
  605. " ",
  606. this->LongestSource.SourceFile->GetFullPath(),
  607. "\n"
  608. "This is because some Visual Studio tools would append the relative "
  609. "path to the end of the referencing directory path, as in:\n"
  610. " ",
  611. lg->GetCurrentBinaryDirectory(), '/', this->LongestSource.SourceRel,
  612. "\n"
  613. "and then incorrectly complain that the file does not exist because "
  614. "the path length is too long for some internal buffer or API. "
  615. "To avoid this problem CMake must use a full path for this file "
  616. "which then triggers the VS 10 property dialog bug."));
  617. }
  618. if (cmValue cached = this->CMakeInstance->GetState()->GetCacheEntryValue(
  619. "CMAKE_VS_NUGET_PACKAGE_RESTORE")) {
  620. this->CMakeInstance->MarkCliAsUsed("CMAKE_VS_NUGET_PACKAGE_RESTORE");
  621. }
  622. }
  623. void cmGlobalVisualStudio10Generator::EnableLanguage(
  624. std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
  625. {
  626. for (std::string const& it : lang) {
  627. if (it == "ASM_NASM"_s) {
  628. this->NasmEnabled = true;
  629. }
  630. if (it == "CUDA"_s) {
  631. this->CudaEnabled = true;
  632. }
  633. }
  634. this->AddPlatformDefinitions(mf);
  635. cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
  636. }
  637. char const* cmGlobalVisualStudio10Generator::GetCustomVCTargetsPath() const
  638. {
  639. if (this->CustomVCTargetsPath.empty()) {
  640. return nullptr;
  641. }
  642. return this->CustomVCTargetsPath.c_str();
  643. }
  644. char const* cmGlobalVisualStudio10Generator::GetPlatformToolset() const
  645. {
  646. std::string const& toolset = this->GetPlatformToolsetString();
  647. if (toolset.empty()) {
  648. return nullptr;
  649. }
  650. return toolset.c_str();
  651. }
  652. std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString()
  653. const
  654. {
  655. if (!this->GeneratorToolset.empty()) {
  656. return this->GeneratorToolset;
  657. }
  658. if (this->SystemIsAndroid) {
  659. if (!this->DefaultAndroidToolset.empty()) {
  660. return this->DefaultAndroidToolset;
  661. }
  662. } else {
  663. if (!this->DefaultPlatformToolset.empty()) {
  664. return this->DefaultPlatformToolset;
  665. }
  666. }
  667. static std::string const empty;
  668. return empty;
  669. }
  670. std::string const&
  671. cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionProps() const
  672. {
  673. return this->GeneratorToolsetVersionProps;
  674. }
  675. char const*
  676. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const
  677. {
  678. std::string const& hostArch =
  679. this->GetPlatformToolsetHostArchitectureString();
  680. if (hostArch.empty()) {
  681. return nullptr;
  682. }
  683. return hostArch.c_str();
  684. }
  685. std::string const&
  686. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitectureString()
  687. const
  688. {
  689. if (!this->GeneratorToolsetHostArchitecture.empty()) {
  690. return this->GeneratorToolsetHostArchitecture;
  691. }
  692. if (!this->DefaultPlatformToolsetHostArchitecture.empty()) {
  693. return this->DefaultPlatformToolsetHostArchitecture;
  694. }
  695. static std::string const empty;
  696. return empty;
  697. }
  698. char const* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
  699. {
  700. if (!this->GeneratorToolsetCuda.empty()) {
  701. return this->GeneratorToolsetCuda.c_str();
  702. }
  703. return nullptr;
  704. }
  705. std::string const&
  706. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaString() const
  707. {
  708. return this->GeneratorToolsetCuda;
  709. }
  710. char const* cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDir()
  711. const
  712. {
  713. if (!this->GeneratorToolsetCudaCustomDir.empty()) {
  714. return this->GeneratorToolsetCudaCustomDir.c_str();
  715. }
  716. return nullptr;
  717. }
  718. std::string const&
  719. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDirString() const
  720. {
  721. return this->GeneratorToolsetCudaCustomDir;
  722. }
  723. std::string const&
  724. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaNvccSubdirString() const
  725. {
  726. return this->GeneratorToolsetCudaNvccSubdir;
  727. }
  728. std::string const& cmGlobalVisualStudio10Generator::
  729. GetPlatformToolsetCudaVSIntegrationSubdirString() const
  730. {
  731. return this->GeneratorToolsetCudaVSIntegrationSubdir;
  732. }
  733. cm::optional<std::string>
  734. cmGlobalVisualStudio10Generator::GetPlatformToolsetFortran() const
  735. {
  736. if (this->GeneratorToolsetFortran) {
  737. return this->GeneratorToolsetFortran;
  738. }
  739. return this->DefaultToolsetFortran;
  740. }
  741. cmGlobalVisualStudio10Generator::AuxToolset
  742. cmGlobalVisualStudio10Generator::FindAuxToolset(std::string&,
  743. std::string&) const
  744. {
  745. return AuxToolset::None;
  746. }
  747. bool cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf)
  748. {
  749. if (!this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf)) {
  750. return false;
  751. }
  752. mf->AddDefinition("CMAKE_VS_MSBUILD_COMMAND", this->GetMSBuildCommand());
  753. return true;
  754. }
  755. std::string const& cmGlobalVisualStudio10Generator::GetMSBuildCommand()
  756. {
  757. if (!this->MSBuildCommandInitialized) {
  758. this->MSBuildCommandInitialized = true;
  759. this->MSBuildCommand = this->FindMSBuildCommand();
  760. }
  761. return this->MSBuildCommand;
  762. }
  763. cm::optional<std::string>
  764. cmGlobalVisualStudio10Generator::FindMSBuildCommandEarly(cmMakefile*)
  765. {
  766. return this->GetMSBuildCommand();
  767. }
  768. std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand()
  769. {
  770. std::string msbuild;
  771. std::string mskey;
  772. // Search in standard location.
  773. mskey =
  774. cmStrCat(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\)",
  775. this->GetToolsVersion(), ";MSBuildToolsPath");
  776. if (cmSystemTools::ReadRegistryValue(mskey, msbuild,
  777. cmSystemTools::KeyWOW64_32)) {
  778. cmSystemTools::ConvertToUnixSlashes(msbuild);
  779. msbuild += "/MSBuild.exe";
  780. if (cmSystemTools::FileExists(msbuild, true)) {
  781. return msbuild;
  782. }
  783. }
  784. msbuild = "MSBuild.exe";
  785. return msbuild;
  786. }
  787. std::string cmGlobalVisualStudio10Generator::FindDevEnvCommand()
  788. {
  789. if (this->ExpressEdition) {
  790. // Visual Studio Express >= 10 do not have "devenv.com" or
  791. // "VCExpress.exe" that we can use to build reliably.
  792. // Tell the caller it needs to use MSBuild instead.
  793. return "";
  794. }
  795. // Skip over the cmGlobalVisualStudio8Generator implementation because
  796. // we expect a real devenv and do not want to look for VCExpress.
  797. // NOLINTNEXTLINE(bugprone-parent-virtual-call)
  798. return this->cmGlobalVisualStudio7Generator::FindDevEnvCommand();
  799. }
  800. bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
  801. {
  802. // Skip this in special cases within our own test suite.
  803. if (this->GetPlatformName() == "Test Platform"_s ||
  804. this->GetPlatformToolsetString() == "Test Toolset"_s) {
  805. return true;
  806. }
  807. std::string wd;
  808. if (!this->ConfiguredFilesPath.empty()) {
  809. // In a try-compile we are given the outer CMakeFiles directory.
  810. wd = this->ConfiguredFilesPath;
  811. } else {
  812. wd = cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(),
  813. "/CMakeFiles");
  814. }
  815. wd += '/';
  816. wd += cmVersion::GetCMakeVersion();
  817. // We record the result persistently in a file.
  818. std::string const txt = cmStrCat(wd, "/VCTargetsPath.txt");
  819. // If we have a recorded result, use it.
  820. {
  821. cmsys::ifstream fin(txt.c_str());
  822. if (fin && cmSystemTools::GetLineFromStream(fin, this->VCTargetsPath) &&
  823. cmSystemTools::FileIsDirectory(this->VCTargetsPath)) {
  824. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  825. return true;
  826. }
  827. }
  828. // Prepare the work directory.
  829. if (!cmSystemTools::MakeDirectory(wd)) {
  830. mf->IssueMessage(MessageType::FATAL_ERROR,
  831. cmStrCat("Failed to make directory:\n ", wd));
  832. cmSystemTools::SetFatalErrorOccurred();
  833. return false;
  834. }
  835. // Generate a project file for MSBuild to tell us the VCTargetsPath value.
  836. std::string const vcxproj = "VCTargetsPath.vcxproj";
  837. {
  838. std::string const vcxprojAbs = cmStrCat(wd, '/', vcxproj);
  839. cmsys::ofstream fout(vcxprojAbs.c_str());
  840. cmXMLWriter xw(fout);
  841. cmXMLDocument doc(xw);
  842. cmXMLElement eprj(doc, "Project");
  843. eprj.Attribute("DefaultTargets", "Build");
  844. eprj.Attribute("ToolsVersion", "4.0");
  845. eprj.Attribute("xmlns",
  846. "http://schemas.microsoft.com/developer/msbuild/2003");
  847. if (this->IsNsightTegra()) {
  848. cmXMLElement epg(eprj, "PropertyGroup");
  849. epg.Attribute("Label", "NsightTegraProject");
  850. cmXMLElement(epg, "NsightTegraProjectRevisionNumber").Content("6");
  851. }
  852. {
  853. cmXMLElement eig(eprj, "ItemGroup");
  854. eig.Attribute("Label", "ProjectConfigurations");
  855. cmXMLElement epc(eig, "ProjectConfiguration");
  856. epc.Attribute("Include", cmStrCat("Debug|", this->GetPlatformName()));
  857. cmXMLElement(epc, "Configuration").Content("Debug");
  858. cmXMLElement(epc, "Platform").Content(this->GetPlatformName());
  859. }
  860. {
  861. cmXMLElement epg(eprj, "PropertyGroup");
  862. epg.Attribute("Label", "Globals");
  863. cmXMLElement(epg, "ProjectGuid")
  864. .Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}");
  865. cmXMLElement(epg, "Keyword")
  866. .Content(mf->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Android"_s
  867. ? "Android"
  868. : "Win32Proj");
  869. cmXMLElement(epg, "Platform").Content(this->GetPlatformName());
  870. if (this->GetSystemName() == "WindowsPhone"_s) {
  871. cmXMLElement(epg, "ApplicationType").Content("Windows Phone");
  872. cmXMLElement(epg, "ApplicationTypeRevision")
  873. .Content(this->GetApplicationTypeRevision());
  874. } else if (this->GetSystemName() == "WindowsStore"_s) {
  875. cmXMLElement(epg, "ApplicationType").Content("Windows Store");
  876. cmXMLElement(epg, "ApplicationTypeRevision")
  877. .Content(this->GetApplicationTypeRevision());
  878. } else if (this->GetSystemName() == "Android"_s) {
  879. cmXMLElement(epg, "ApplicationType").Content("Android");
  880. cmXMLElement(epg, "ApplicationTypeRevision")
  881. .Content(this->GetApplicationTypeRevision());
  882. }
  883. if (!this->WindowsTargetPlatformVersion.empty()) {
  884. cmXMLElement(epg, "WindowsTargetPlatformVersion")
  885. .Content(this->WindowsTargetPlatformVersion);
  886. }
  887. if (this->GetSystemName() != "Android"_s) {
  888. if (this->GetPlatformName() == "ARM64"_s) {
  889. cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true");
  890. } else if (this->GetPlatformName() == "ARM"_s) {
  891. cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true");
  892. }
  893. }
  894. }
  895. cmXMLElement(eprj, "Import")
  896. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  897. if (char const* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  898. cmXMLElement epg(eprj, "PropertyGroup");
  899. cmXMLElement(epg, "PreferredToolArchitecture").Content(hostArch);
  900. }
  901. {
  902. cmXMLElement epg(eprj, "PropertyGroup");
  903. epg.Attribute("Label", "Configuration");
  904. {
  905. // noqa: spellcheck off
  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. // noqa: spellcheck on
  914. }
  915. cmXMLElement(epg, "CharacterSet").Content("MultiByte");
  916. if (this->IsNsightTegra()) {
  917. cmXMLElement(epg, "NdkToolchainVersion")
  918. .Content(this->GetPlatformToolsetString());
  919. } else {
  920. cmXMLElement(epg, "PlatformToolset")
  921. .Content(this->GetPlatformToolsetString());
  922. }
  923. }
  924. cmXMLElement(eprj, "Import")
  925. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  926. {
  927. cmXMLElement eidg(eprj, "ItemDefinitionGroup");
  928. cmXMLElement epbe(eidg, "PostBuildEvent");
  929. cmXMLElement(epbe, "Command")
  930. .Content("echo VCTargetsPath=$(VCTargetsPath)");
  931. }
  932. cmXMLElement(eprj, "Import")
  933. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  934. }
  935. std::vector<std::string> cmd;
  936. cmd.push_back(this->GetMSBuildCommand());
  937. cmd.push_back(vcxproj);
  938. cmd.emplace_back("/p:Configuration=Debug");
  939. cmd.emplace_back(cmStrCat("/p:Platform=", this->GetPlatformName()));
  940. cmd.emplace_back(cmStrCat("/p:VisualStudioVersion=", this->GetIDEVersion()));
  941. std::string out;
  942. int ret = 0;
  943. cmsys::RegularExpression regex("\n *VCTargetsPath=([^%\r\n]+)[\r\n]");
  944. if (!cmSystemTools::RunSingleCommand(cmd, &out, &out, &ret, wd.c_str(),
  945. cmSystemTools::OUTPUT_NONE) ||
  946. ret != 0 || !regex.find(out)) {
  947. cmSystemTools::ReplaceString(out, "\n", "\n ");
  948. std::ostringstream e;
  949. /* clang-format off */
  950. e <<
  951. "Failed to run MSBuild command:\n"
  952. " " << cmd[0] << "\n"
  953. "to get the value of VCTargetsPath:\n"
  954. " " << out << '\n'
  955. ;
  956. /* clang-format on */
  957. if (ret != 0) {
  958. e << "Exit code: " << ret << '\n';
  959. }
  960. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  961. cmSystemTools::SetFatalErrorOccurred();
  962. return false;
  963. }
  964. this->VCTargetsPath = regex.match(1);
  965. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  966. {
  967. cmsys::ofstream fout(txt.c_str());
  968. fout << this->VCTargetsPath << '\n';
  969. }
  970. return true;
  971. }
  972. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  973. cmGlobalVisualStudio10Generator::GenerateBuildCommand(
  974. std::string const& makeProgram, std::string const& projectName,
  975. std::string const& projectDir, std::vector<std::string> const& targetNames,
  976. std::string const& config, int jobs, bool verbose,
  977. cmBuildOptions buildOptions, 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. bool const 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 (auto const& 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:", 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. char const* cmGlobalVisualStudio10Generator::GetToolsVersion() const
  1172. {
  1173. switch (this->Version) {
  1174. case cmGlobalVisualStudioGenerator::VSVersion::VS14:
  1175. return "14.0";
  1176. case cmGlobalVisualStudioGenerator::VSVersion::VS15:
  1177. return "15.0";
  1178. case cmGlobalVisualStudioGenerator::VSVersion::VS16:
  1179. return "16.0";
  1180. case cmGlobalVisualStudioGenerator::VSVersion::VS17:
  1181. return "17.0";
  1182. case cmGlobalVisualStudioGenerator::VSVersion::VS18:
  1183. return "18.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, char const* 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. char const* 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. bool cmGlobalVisualStudio10Generator::SupportsShortObjectNames() const
  1442. {
  1443. return true;
  1444. }
  1445. std::string cmGlobalVisualStudio10Generator::GetClFlagTableName() const
  1446. {
  1447. std::string const& toolset = this->GetPlatformToolsetString();
  1448. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1449. if (toolset == "v142"_s) {
  1450. return "v142";
  1451. }
  1452. if (toolset == "v141"_s) {
  1453. return "v141";
  1454. }
  1455. if (useToolset == "v140"_s) {
  1456. return "v140";
  1457. }
  1458. if (useToolset == "v120"_s) {
  1459. return "v12";
  1460. }
  1461. if (useToolset == "v110"_s) {
  1462. return "v11";
  1463. }
  1464. if (useToolset == "v100"_s) {
  1465. return "v10";
  1466. }
  1467. return "";
  1468. }
  1469. std::string cmGlobalVisualStudio10Generator::GetCSharpFlagTableName() const
  1470. {
  1471. std::string const& toolset = this->GetPlatformToolsetString();
  1472. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1473. if (useToolset == "v142"_s) {
  1474. return "v142";
  1475. }
  1476. if (useToolset == "v141"_s) {
  1477. return "v141";
  1478. }
  1479. if (useToolset == "v140"_s) {
  1480. return "v140";
  1481. }
  1482. if (useToolset == "v120"_s) {
  1483. return "v12";
  1484. }
  1485. if (useToolset == "v110"_s) {
  1486. return "v11";
  1487. }
  1488. if (useToolset == "v100"_s) {
  1489. return "v10";
  1490. }
  1491. return "";
  1492. }
  1493. std::string cmGlobalVisualStudio10Generator::GetRcFlagTableName() const
  1494. {
  1495. std::string const& toolset = this->GetPlatformToolsetString();
  1496. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1497. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1498. (useToolset == "v142"_s)) {
  1499. return "v14";
  1500. }
  1501. if (useToolset == "v120"_s) {
  1502. return "v12";
  1503. }
  1504. if (useToolset == "v110"_s) {
  1505. return "v11";
  1506. }
  1507. if (useToolset == "v100"_s) {
  1508. return "v10";
  1509. }
  1510. return "";
  1511. }
  1512. std::string cmGlobalVisualStudio10Generator::GetLibFlagTableName() const
  1513. {
  1514. std::string const& toolset = this->GetPlatformToolsetString();
  1515. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1516. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1517. (useToolset == "v142"_s)) {
  1518. return "v14";
  1519. }
  1520. if (useToolset == "v120"_s) {
  1521. return "v12";
  1522. }
  1523. if (useToolset == "v110"_s) {
  1524. return "v11";
  1525. }
  1526. if (useToolset == "v100"_s) {
  1527. return "v10";
  1528. }
  1529. return "";
  1530. }
  1531. std::string cmGlobalVisualStudio10Generator::GetLinkFlagTableName() const
  1532. {
  1533. std::string const& toolset = this->GetPlatformToolsetString();
  1534. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1535. if (useToolset == "v142"_s) {
  1536. return "v142";
  1537. }
  1538. if (useToolset == "v141"_s) {
  1539. return "v141";
  1540. }
  1541. if (useToolset == "v140"_s) {
  1542. return "v140";
  1543. }
  1544. if (useToolset == "v120"_s) {
  1545. return "v12";
  1546. }
  1547. if (useToolset == "v110"_s) {
  1548. return "v11";
  1549. }
  1550. if (useToolset == "v100"_s) {
  1551. return "v10";
  1552. }
  1553. return "";
  1554. }
  1555. std::string cmGlobalVisualStudio10Generator::GetMasmFlagTableName() const
  1556. {
  1557. std::string const& toolset = this->GetPlatformToolsetString();
  1558. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1559. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1560. (useToolset == "v142"_s)) {
  1561. return "v14";
  1562. }
  1563. if (useToolset == "v120"_s) {
  1564. return "v12";
  1565. }
  1566. if (useToolset == "v110"_s) {
  1567. return "v11";
  1568. }
  1569. if (useToolset == "v100"_s) {
  1570. return "v10";
  1571. }
  1572. return "";
  1573. }
  1574. std::string cmGlobalVisualStudio10Generator::CanonicalToolsetName(
  1575. std::string const& toolset) const
  1576. {
  1577. std::size_t length = toolset.length();
  1578. if (cmHasLiteralSuffix(toolset, "_xp")) {
  1579. length -= 3;
  1580. }
  1581. return toolset.substr(0, length);
  1582. }