cmGlobalVisualStudio10Generator.cxx 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728
  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 "cmGlobalVisualStudio71Generator.h"
  22. #include "cmGlobalVisualStudio7Generator.h"
  23. #include "cmGlobalVisualStudioGenerator.h"
  24. #include "cmIDEFlagTable.h"
  25. #include "cmLocalGenerator.h"
  26. #include "cmLocalVisualStudio10Generator.h"
  27. #include "cmMakefile.h"
  28. #include "cmMessageType.h"
  29. #include "cmSourceFile.h"
  30. #include "cmStringAlgorithms.h"
  31. #include "cmSystemTools.h"
  32. #include "cmVersion.h"
  33. #include "cmVisualStudioSlnData.h"
  34. #include "cmVisualStudioSlnParser.h"
  35. #include "cmXMLWriter.h"
  36. #include "cmake.h"
  37. static std::map<std::string, std::vector<cmIDEFlagTable>> loadedFlagJsonFiles;
  38. static void ConvertToWindowsSlashes(std::string& s)
  39. {
  40. // first convert all of the slashes
  41. for (auto& ch : s) {
  42. if (ch == '/') {
  43. ch = '\\';
  44. }
  45. }
  46. }
  47. cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator(
  48. cmake* cm, std::string const& name)
  49. : cmGlobalVisualStudio8Generator(cm, name)
  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. // The v143 toolset reserves versions 14.30 through 14.49.
  208. if (platformToolset == "v143"_s && versionToolset == "v144"_s) {
  209. versionToolset = "v143";
  210. }
  211. } else {
  212. // Version not recognized. Clear it.
  213. versionToolset.clear();
  214. }
  215. if (versionToolset != platformToolset) {
  216. mf->IssueMessage(
  217. MessageType::FATAL_ERROR,
  218. cmStrCat("Generator\n"
  219. " ",
  220. this->GetName(),
  221. "\n"
  222. "given toolset and version specification\n"
  223. " ",
  224. this->GetPlatformToolsetString(),
  225. ",version=", this->GeneratorToolsetVersion,
  226. "\n"
  227. "contains an invalid version specification."));
  228. // Clear the configured tool-set
  229. this->GeneratorToolsetVersion.clear();
  230. }
  231. }
  232. std::string auxProps;
  233. switch (this->FindAuxToolset(this->GeneratorToolsetVersion, auxProps)) {
  234. case AuxToolset::None:
  235. this->GeneratorToolsetVersionProps = {};
  236. break;
  237. case AuxToolset::Default:
  238. // The given version is the default toolset. Remove the setting.
  239. this->GeneratorToolsetVersion.clear();
  240. this->GeneratorToolsetVersionProps = {};
  241. break;
  242. case AuxToolset::PropsExist:
  243. this->GeneratorToolsetVersionProps = std::move(auxProps);
  244. break;
  245. case AuxToolset::PropsMissing: {
  246. mf->IssueMessage(MessageType::FATAL_ERROR,
  247. cmStrCat("Generator\n"
  248. " ",
  249. this->GetName(),
  250. "\n"
  251. "given toolset and version specification\n"
  252. " ",
  253. this->GetPlatformToolsetString(),
  254. ",version=", this->GeneratorToolsetVersion,
  255. "\n"
  256. "does not seem to be installed at\n"
  257. " ",
  258. auxProps));
  259. // Clear the configured tool-set
  260. this->GeneratorToolsetVersion.clear();
  261. this->GeneratorToolsetVersionProps = {};
  262. } break;
  263. case AuxToolset::PropsIndeterminate: {
  264. mf->IssueMessage(
  265. MessageType::FATAL_ERROR,
  266. cmStrCat("Generator\n"
  267. " ",
  268. this->GetName(),
  269. "\n"
  270. "given toolset and version specification\n"
  271. " ",
  272. this->GetPlatformToolsetString(),
  273. ",version=", this->GeneratorToolsetVersion,
  274. "\n"
  275. "has multiple matches installed at\n"
  276. " ",
  277. auxProps,
  278. "\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 (char const* 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 (char const* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  295. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE", hostArch);
  296. }
  297. if (char const* cuda = this->GetPlatformToolsetCuda()) {
  298. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA", cuda);
  299. }
  300. if (char const* 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 (char const* 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 =
  316. cmTokenize(ts, ',', cmTokenizerMode::New);
  317. if (fields.empty()) {
  318. return true;
  319. }
  320. auto fi = fields.begin();
  321. // The first field may be the VS platform toolset.
  322. if (fi->find('=') == fi->npos) {
  323. this->GeneratorToolset = *fi;
  324. ++fi;
  325. }
  326. std::set<std::string> handled;
  327. // The rest of the fields must be key=value pairs.
  328. for (; fi != fields.end(); ++fi) {
  329. std::string::size_type pos = fi->find('=');
  330. if (pos == fi->npos) {
  331. mf->IssueMessage(
  332. MessageType::FATAL_ERROR,
  333. cmStrCat("Generator\n"
  334. " ",
  335. this->GetName(),
  336. "\n"
  337. "given toolset specification\n"
  338. " ",
  339. ts,
  340. "\n"
  341. "that contains a field after the first ',' with no '='."));
  342. return false;
  343. }
  344. std::string const key = fi->substr(0, pos);
  345. std::string const value = fi->substr(pos + 1);
  346. if (!handled.insert(key).second) {
  347. mf->IssueMessage(MessageType::FATAL_ERROR,
  348. cmStrCat("Generator\n"
  349. " ",
  350. this->GetName(),
  351. "\n"
  352. "given toolset specification\n"
  353. " ",
  354. ts,
  355. "\n"
  356. "that contains duplicate field key '",
  357. key, "'."));
  358. return false;
  359. }
  360. if (!this->ProcessGeneratorToolsetField(key, value)) {
  361. mf->IssueMessage(MessageType::FATAL_ERROR,
  362. cmStrCat("Generator\n"
  363. " ",
  364. this->GetName(),
  365. "\n"
  366. "given toolset specification\n"
  367. " ",
  368. ts,
  369. "\n"
  370. "that contains invalid field '",
  371. *fi, "'."));
  372. return false;
  373. }
  374. }
  375. return true;
  376. }
  377. bool cmGlobalVisualStudio10Generator::ProcessGeneratorToolsetField(
  378. std::string const& key, std::string const& value)
  379. {
  380. if (key == "cuda"_s) {
  381. /* test if cuda toolset is path to custom dir or cuda version */
  382. auto pos = value.find_first_not_of("0123456789.");
  383. if (pos != std::string::npos) {
  384. this->GeneratorToolsetCudaCustomDir = value;
  385. /* ensure trailing backslash for easy path joining */
  386. if (this->GeneratorToolsetCudaCustomDir.back() != '\\') {
  387. this->GeneratorToolsetCudaCustomDir.push_back('\\');
  388. }
  389. /* check for legacy toolkit folder structure */
  390. if (cmsys::SystemTools::FileIsDirectory(
  391. cmStrCat(this->GeneratorToolsetCudaCustomDir, "nvcc"))) {
  392. this->GeneratorToolsetCudaNvccSubdir = "nvcc\\";
  393. }
  394. if (cmsys::SystemTools::FileIsDirectory(
  395. cmStrCat(this->GeneratorToolsetCudaCustomDir,
  396. "CUDAVisualStudioIntegration"))) {
  397. this->GeneratorToolsetCudaVSIntegrationSubdir =
  398. "CUDAVisualStudioIntegration\\";
  399. }
  400. } else {
  401. this->GeneratorToolsetCuda = value;
  402. }
  403. return true;
  404. }
  405. if (key == "customFlagTableDir"_s) {
  406. this->CustomFlagTableDir = value;
  407. cmSystemTools::ConvertToUnixSlashes(this->CustomFlagTableDir);
  408. return true;
  409. }
  410. if (key == "fortran"_s) {
  411. this->GeneratorToolsetFortran = value;
  412. return true;
  413. }
  414. if (key == "version"_s) {
  415. this->GeneratorToolsetVersion = value;
  416. return true;
  417. }
  418. if (key == "VCTargetsPath"_s) {
  419. this->CustomVCTargetsPath = value;
  420. ConvertToWindowsSlashes(this->CustomVCTargetsPath);
  421. return true;
  422. }
  423. return false;
  424. }
  425. bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf)
  426. {
  427. if (this->SystemName == "Windows"_s) {
  428. if (!this->InitializeWindows(mf)) {
  429. return false;
  430. }
  431. } else if (this->SystemName == "WindowsCE"_s) {
  432. this->SystemIsWindowsCE = true;
  433. if (!this->InitializeWindowsCE(mf)) {
  434. return false;
  435. }
  436. } else if (this->SystemName == "WindowsPhone"_s) {
  437. this->SystemIsWindowsPhone = true;
  438. if (!this->InitializeWindowsPhone(mf)) {
  439. return false;
  440. }
  441. } else if (this->SystemName == "WindowsStore"_s) {
  442. this->SystemIsWindowsStore = true;
  443. if (!this->InitializeWindowsStore(mf)) {
  444. return false;
  445. }
  446. } else if (this->SystemName == "WindowsKernelModeDriver"_s) {
  447. this->SystemIsWindowsKernelModeDriver = true;
  448. if (!this->InitializeWindowsKernelModeDriver(mf)) {
  449. return false;
  450. }
  451. } else if (this->SystemName == "Android"_s) {
  452. if (mf->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM") ==
  453. "Tegra-Android"_s) {
  454. if (!this->InitializeTegraAndroid(mf)) {
  455. return false;
  456. }
  457. } else {
  458. this->SystemIsAndroid = true;
  459. if (!this->InitializeAndroid(mf)) {
  460. return false;
  461. }
  462. }
  463. }
  464. return true;
  465. }
  466. bool cmGlobalVisualStudio10Generator::InitializeWindows(cmMakefile*)
  467. {
  468. return true;
  469. }
  470. bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile*)
  471. {
  472. this->DefaultPlatformToolset = this->SelectWindowsCEToolset();
  473. return true;
  474. }
  475. bool cmGlobalVisualStudio10Generator::InitializeWindowsPhone(cmMakefile* mf)
  476. {
  477. mf->IssueMessage(
  478. MessageType::FATAL_ERROR,
  479. cmStrCat(this->GetName(), " does not support Windows Phone."));
  480. return false;
  481. }
  482. bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf)
  483. {
  484. mf->IssueMessage(
  485. MessageType::FATAL_ERROR,
  486. cmStrCat(this->GetName(), " does not support Windows Store."));
  487. return false;
  488. }
  489. bool cmGlobalVisualStudio10Generator::InitializeWindowsKernelModeDriver(
  490. cmMakefile*)
  491. {
  492. this->DefaultPlatformToolset = "WindowsKernelModeDriver10.0";
  493. return true;
  494. }
  495. bool cmGlobalVisualStudio10Generator::InitializeTegraAndroid(cmMakefile* mf)
  496. {
  497. std::string v =
  498. cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion();
  499. if (v.empty()) {
  500. mf->IssueMessage(MessageType::FATAL_ERROR,
  501. "CMAKE_SYSTEM_NAME is 'Android' but "
  502. "'NVIDIA Nsight Tegra Visual Studio Edition' "
  503. "is not installed.");
  504. return false;
  505. }
  506. this->DefaultPlatformName = "Tegra-Android";
  507. this->DefaultPlatformToolset = "Default";
  508. this->NsightTegraVersion = v;
  509. mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v);
  510. return true;
  511. }
  512. bool cmGlobalVisualStudio10Generator::InitializeAndroid(cmMakefile* mf)
  513. {
  514. mf->IssueMessage(MessageType::FATAL_ERROR,
  515. cmStrCat(this->GetName(), " does not support Android."));
  516. return false;
  517. }
  518. bool cmGlobalVisualStudio10Generator::InitializePlatform(cmMakefile* mf)
  519. {
  520. if (this->SystemName == "Windows"_s ||
  521. this->SystemName == "WindowsStore"_s) {
  522. if (!this->InitializePlatformWindows(mf)) {
  523. return false;
  524. }
  525. } else if (!this->SystemName.empty() &&
  526. !this->VerifyNoGeneratorPlatformVersion(mf)) {
  527. return false;
  528. }
  529. return this->cmGlobalVisualStudio8Generator::InitializePlatform(mf);
  530. }
  531. bool cmGlobalVisualStudio10Generator::InitializePlatformWindows(cmMakefile*)
  532. {
  533. return true;
  534. }
  535. bool cmGlobalVisualStudio10Generator::VerifyNoGeneratorPlatformVersion(
  536. cmMakefile*) const
  537. {
  538. return true;
  539. }
  540. bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
  541. std::string& toolset) const
  542. {
  543. toolset.clear();
  544. return false;
  545. }
  546. bool cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset(
  547. std::string& toolset) const
  548. {
  549. toolset.clear();
  550. return false;
  551. }
  552. std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const
  553. {
  554. if (this->SystemVersion == "8.0"_s) {
  555. return "CE800";
  556. }
  557. return "";
  558. }
  559. //! Create a local generator appropriate to this Global Generator
  560. std::unique_ptr<cmLocalGenerator>
  561. cmGlobalVisualStudio10Generator::CreateLocalGenerator(cmMakefile* mf)
  562. {
  563. return std::unique_ptr<cmLocalGenerator>(
  564. cm::make_unique<cmLocalVisualStudio10Generator>(this, mf));
  565. }
  566. void cmGlobalVisualStudio10Generator::Generate()
  567. {
  568. this->LongestSource = LongestSourcePath();
  569. this->cmGlobalVisualStudio8Generator::Generate();
  570. if (!this->AndroidExecutableWarnings.empty() &&
  571. !this->CMakeInstance->GetIsInTryCompile()) {
  572. std::ostringstream e;
  573. /* clang-format off */
  574. e <<
  575. "You are using Visual Studio tools for Android, which does not support "
  576. "standalone executables. However, the following executable targets do "
  577. "not have the ANDROID_GUI property set, and thus will not be built as "
  578. "expected. They will be built as shared libraries with executable "
  579. "filenames:\n"
  580. " ";
  581. /* clang-format on */
  582. bool first = true;
  583. for (auto const& name : this->AndroidExecutableWarnings) {
  584. if (!first) {
  585. e << ", ";
  586. }
  587. first = false;
  588. e << name;
  589. }
  590. this->CMakeInstance->IssueMessage(MessageType::WARNING, e.str());
  591. }
  592. if (this->LongestSource.Length > 0) {
  593. cmLocalGenerator* lg = this->LongestSource.Target->GetLocalGenerator();
  594. lg->IssueMessage(
  595. MessageType::WARNING,
  596. cmStrCat(
  597. "The binary and/or source directory paths may be too long to generate "
  598. "Visual Studio 10 files for this project. "
  599. "Consider choosing shorter directory names to build this project with "
  600. "Visual Studio 10. "
  601. "A more detailed explanation follows."
  602. "\n"
  603. "There is a bug in the VS 10 IDE that renders property dialog fields "
  604. "blank for files referenced by full path in the project file. "
  605. "However, CMake must reference at least one file by full path:\n"
  606. " ",
  607. this->LongestSource.SourceFile->GetFullPath(),
  608. "\n"
  609. "This is because some Visual Studio tools would append the relative "
  610. "path to the end of the referencing directory path, as in:\n"
  611. " ",
  612. lg->GetCurrentBinaryDirectory(), '/', this->LongestSource.SourceRel,
  613. "\n"
  614. "and then incorrectly complain that the file does not exist because "
  615. "the path length is too long for some internal buffer or API. "
  616. "To avoid this problem CMake must use a full path for this file "
  617. "which then triggers the VS 10 property dialog bug."));
  618. }
  619. if (cmValue cached = this->CMakeInstance->GetState()->GetCacheEntryValue(
  620. "CMAKE_VS_NUGET_PACKAGE_RESTORE")) {
  621. this->CMakeInstance->MarkCliAsUsed("CMAKE_VS_NUGET_PACKAGE_RESTORE");
  622. }
  623. }
  624. void cmGlobalVisualStudio10Generator::EnableLanguage(
  625. std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
  626. {
  627. for (std::string const& it : lang) {
  628. if (it == "ASM_NASM"_s) {
  629. this->NasmEnabled = true;
  630. }
  631. if (it == "CUDA"_s) {
  632. this->CudaEnabled = true;
  633. }
  634. }
  635. this->AddPlatformDefinitions(mf);
  636. cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
  637. }
  638. char const* cmGlobalVisualStudio10Generator::GetCustomVCTargetsPath() const
  639. {
  640. if (this->CustomVCTargetsPath.empty()) {
  641. return nullptr;
  642. }
  643. return this->CustomVCTargetsPath.c_str();
  644. }
  645. char const* cmGlobalVisualStudio10Generator::GetPlatformToolset() const
  646. {
  647. std::string const& toolset = this->GetPlatformToolsetString();
  648. if (toolset.empty()) {
  649. return nullptr;
  650. }
  651. return toolset.c_str();
  652. }
  653. std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString()
  654. const
  655. {
  656. if (!this->GeneratorToolset.empty()) {
  657. return this->GeneratorToolset;
  658. }
  659. if (this->SystemIsAndroid) {
  660. if (!this->DefaultAndroidToolset.empty()) {
  661. return this->DefaultAndroidToolset;
  662. }
  663. } else {
  664. if (!this->DefaultPlatformToolset.empty()) {
  665. return this->DefaultPlatformToolset;
  666. }
  667. }
  668. static std::string const empty;
  669. return empty;
  670. }
  671. std::string const&
  672. cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionProps() const
  673. {
  674. return this->GeneratorToolsetVersionProps;
  675. }
  676. char const*
  677. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const
  678. {
  679. std::string const& hostArch =
  680. this->GetPlatformToolsetHostArchitectureString();
  681. if (hostArch.empty()) {
  682. return nullptr;
  683. }
  684. return hostArch.c_str();
  685. }
  686. std::string const&
  687. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitectureString()
  688. const
  689. {
  690. if (!this->GeneratorToolsetHostArchitecture.empty()) {
  691. return this->GeneratorToolsetHostArchitecture;
  692. }
  693. if (!this->DefaultPlatformToolsetHostArchitecture.empty()) {
  694. return this->DefaultPlatformToolsetHostArchitecture;
  695. }
  696. static std::string const empty;
  697. return empty;
  698. }
  699. char const* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
  700. {
  701. if (!this->GeneratorToolsetCuda.empty()) {
  702. return this->GeneratorToolsetCuda.c_str();
  703. }
  704. return nullptr;
  705. }
  706. std::string const&
  707. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaString() const
  708. {
  709. return this->GeneratorToolsetCuda;
  710. }
  711. char const* cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDir()
  712. const
  713. {
  714. if (!this->GeneratorToolsetCudaCustomDir.empty()) {
  715. return this->GeneratorToolsetCudaCustomDir.c_str();
  716. }
  717. return nullptr;
  718. }
  719. std::string const&
  720. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDirString() const
  721. {
  722. return this->GeneratorToolsetCudaCustomDir;
  723. }
  724. std::string const&
  725. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaNvccSubdirString() const
  726. {
  727. return this->GeneratorToolsetCudaNvccSubdir;
  728. }
  729. std::string const& cmGlobalVisualStudio10Generator::
  730. GetPlatformToolsetCudaVSIntegrationSubdirString() const
  731. {
  732. return this->GeneratorToolsetCudaVSIntegrationSubdir;
  733. }
  734. cm::optional<std::string>
  735. cmGlobalVisualStudio10Generator::GetPlatformToolsetFortran() const
  736. {
  737. if (this->GeneratorToolsetFortran) {
  738. return this->GeneratorToolsetFortran;
  739. }
  740. return this->DefaultToolsetFortran;
  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 (char const* 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. // noqa: spellcheck off
  907. cmXMLElement ect(epg, "ConfigurationType");
  908. if (this->IsNsightTegra()) {
  909. // Tegra-Android platform does not understand "Utility".
  910. ect.Content("StaticLibrary");
  911. } else {
  912. ect.Content("Utility");
  913. }
  914. // noqa: spellcheck on
  915. }
  916. cmXMLElement(epg, "CharacterSet").Content("MultiByte");
  917. if (this->IsNsightTegra()) {
  918. cmXMLElement(epg, "NdkToolchainVersion")
  919. .Content(this->GetPlatformToolsetString());
  920. } else {
  921. cmXMLElement(epg, "PlatformToolset")
  922. .Content(this->GetPlatformToolsetString());
  923. }
  924. }
  925. cmXMLElement(eprj, "Import")
  926. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  927. {
  928. cmXMLElement eidg(eprj, "ItemDefinitionGroup");
  929. cmXMLElement epbe(eidg, "PostBuildEvent");
  930. cmXMLElement(epbe, "Command")
  931. .Content("echo VCTargetsPath=$(VCTargetsPath)");
  932. }
  933. cmXMLElement(eprj, "Import")
  934. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  935. }
  936. std::vector<std::string> cmd;
  937. cmd.push_back(this->GetMSBuildCommand());
  938. cmd.push_back(vcxproj);
  939. cmd.emplace_back("/p:Configuration=Debug");
  940. cmd.emplace_back(cmStrCat("/p:Platform=", this->GetPlatformName()));
  941. cmd.emplace_back(cmStrCat("/p:VisualStudioVersion=", this->GetIDEVersion()));
  942. std::string out;
  943. int ret = 0;
  944. cmsys::RegularExpression regex("\n *VCTargetsPath=([^%\r\n]+)[\r\n]");
  945. if (!cmSystemTools::RunSingleCommand(cmd, &out, &out, &ret, wd.c_str(),
  946. cmSystemTools::OUTPUT_NONE) ||
  947. ret != 0 || !regex.find(out)) {
  948. cmSystemTools::ReplaceString(out, "\n", "\n ");
  949. std::ostringstream e;
  950. /* clang-format off */
  951. e <<
  952. "Failed to run MSBuild command:\n"
  953. " " << cmd[0] << "\n"
  954. "to get the value of VCTargetsPath:\n"
  955. " " << out << '\n'
  956. ;
  957. /* clang-format on */
  958. if (ret != 0) {
  959. e << "Exit code: " << ret << '\n';
  960. }
  961. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  962. cmSystemTools::SetFatalErrorOccurred();
  963. return false;
  964. }
  965. this->VCTargetsPath = regex.match(1);
  966. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  967. {
  968. cmsys::ofstream fout(txt.c_str());
  969. fout << this->VCTargetsPath << '\n';
  970. }
  971. return true;
  972. }
  973. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  974. cmGlobalVisualStudio10Generator::GenerateBuildCommand(
  975. std::string const& makeProgram, std::string const& projectName,
  976. std::string const& projectDir, std::vector<std::string> const& targetNames,
  977. std::string const& config, int jobs, bool verbose,
  978. cmBuildOptions const& buildOptions,
  979. std::vector<std::string> const& makeOptions)
  980. {
  981. std::vector<GeneratedMakeCommand> makeCommands;
  982. // Select the caller- or user-preferred make program, else MSBuild.
  983. std::string makeProgramSelected =
  984. this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand());
  985. // Check if the caller explicitly requested a devenv tool.
  986. std::string makeProgramLower = makeProgramSelected;
  987. cmSystemTools::LowerCase(makeProgramLower);
  988. bool useDevEnv = (makeProgramLower.find("devenv") != std::string::npos ||
  989. makeProgramLower.find("vcexpress") != std::string::npos);
  990. // Workaround to convince VCExpress.exe to produce output.
  991. bool const requiresOutputForward =
  992. (makeProgramLower.find("vcexpress") != std::string::npos);
  993. // MSBuild is preferred (and required for VS Express), but if the .sln has
  994. // an Intel Fortran .vfproj then we have to use devenv. Parse it to find out.
  995. cmSlnData slnData;
  996. {
  997. std::string slnFile;
  998. if (!projectDir.empty()) {
  999. slnFile = cmStrCat(projectDir, '/');
  1000. }
  1001. slnFile += projectName;
  1002. slnFile += ".sln";
  1003. cmVisualStudioSlnParser parser;
  1004. if (parser.ParseFile(slnFile, slnData,
  1005. cmVisualStudioSlnParser::DataGroupAll)) {
  1006. std::vector<cmSlnProjectEntry> slnProjects = slnData.GetProjects();
  1007. for (cmSlnProjectEntry const& project : slnProjects) {
  1008. if (useDevEnv) {
  1009. break;
  1010. }
  1011. std::string proj = project.GetRelativePath();
  1012. if (proj.size() > 7 && proj.substr(proj.size() - 7) == ".vfproj"_s) {
  1013. useDevEnv = true;
  1014. }
  1015. }
  1016. }
  1017. }
  1018. if (useDevEnv) {
  1019. // Use devenv to build solutions containing Intel Fortran projects.
  1020. return cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  1021. makeProgram, projectName, projectDir, targetNames, config, jobs, verbose,
  1022. buildOptions, makeOptions);
  1023. }
  1024. std::vector<std::string> realTargetNames = targetNames;
  1025. if (targetNames.empty() ||
  1026. ((targetNames.size() == 1) && targetNames.front().empty())) {
  1027. realTargetNames = { "ALL_BUILD" };
  1028. }
  1029. for (auto const& tname : realTargetNames) {
  1030. // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug
  1031. // /target:ALL_BUILD
  1032. // /m
  1033. if (tname.empty()) {
  1034. continue;
  1035. }
  1036. GeneratedMakeCommand makeCommand;
  1037. makeCommand.RequiresOutputForward = requiresOutputForward;
  1038. makeCommand.Add(makeProgramSelected);
  1039. cm::optional<cmSlnProjectEntry> proj = cm::nullopt;
  1040. if (tname == "clean"_s) {
  1041. makeCommand.Add(cmStrCat(projectName, ".sln"));
  1042. makeCommand.Add("/t:Clean");
  1043. } else {
  1044. std::string targetProject = cmStrCat(tname, ".vcxproj");
  1045. proj = slnData.GetProjectByName(tname);
  1046. if (targetProject.find('/') == std::string::npos) {
  1047. // it might be in a subdir
  1048. if (proj) {
  1049. targetProject = proj->GetRelativePath();
  1050. cmSystemTools::ConvertToUnixSlashes(targetProject);
  1051. }
  1052. }
  1053. makeCommand.Add(targetProject);
  1054. // Check if we do need a restore at all (i.e. if there are package
  1055. // references and restore has not been disabled by a command line option.
  1056. PackageResolveMode restoreMode = buildOptions.ResolveMode;
  1057. bool requiresRestore = true;
  1058. if (restoreMode == PackageResolveMode::Disable) {
  1059. requiresRestore = false;
  1060. } else if (cmValue cached =
  1061. this->CMakeInstance->GetState()->GetCacheEntryValue(
  1062. cmStrCat(tname, "_REQUIRES_VS_PACKAGE_RESTORE"))) {
  1063. requiresRestore = cached.IsOn();
  1064. } else {
  1065. // There are no package references defined.
  1066. requiresRestore = false;
  1067. }
  1068. // If a restore is required, evaluate the restore mode.
  1069. if (requiresRestore) {
  1070. if (restoreMode == PackageResolveMode::OnlyResolve) {
  1071. // Only invoke the restore target on the project.
  1072. makeCommand.Add("/t:Restore");
  1073. } else {
  1074. // Invoke restore target, unless it has been explicitly disabled.
  1075. bool restorePackages = true;
  1076. if (this->Version < VSVersion::VS15) {
  1077. // Package restore is only supported starting from Visual Studio
  1078. // 2017. Package restore must be executed manually using NuGet
  1079. // shell for older versions.
  1080. this->CMakeInstance->IssueMessage(
  1081. MessageType::WARNING,
  1082. "Restoring package references is only supported for Visual "
  1083. "Studio 2017 and later. You have to manually restore the "
  1084. "packages using NuGet before building the project.");
  1085. restorePackages = false;
  1086. } else if (restoreMode == PackageResolveMode::Default) {
  1087. // Decide if a restore is performed, based on a cache variable.
  1088. if (cmValue cached =
  1089. this->CMakeInstance->GetState()->GetCacheEntryValue(
  1090. "CMAKE_VS_NUGET_PACKAGE_RESTORE")) {
  1091. restorePackages = cached.IsOn();
  1092. }
  1093. }
  1094. if (restorePackages) {
  1095. if (this->IsMsBuildRestoreSupported()) {
  1096. makeCommand.Add("/restore");
  1097. } else {
  1098. GeneratedMakeCommand restoreCommand;
  1099. restoreCommand.Add(makeProgramSelected);
  1100. restoreCommand.Add(targetProject);
  1101. restoreCommand.Add("/t:Restore");
  1102. makeCommands.emplace_back(restoreCommand);
  1103. }
  1104. }
  1105. }
  1106. }
  1107. }
  1108. std::string plainConfig = config;
  1109. if (config.empty()) {
  1110. plainConfig = "Debug";
  1111. }
  1112. std::string platform = GetPlatformName();
  1113. if (proj) {
  1114. std::string extension =
  1115. cmSystemTools::GetFilenameLastExtension(proj->GetRelativePath());
  1116. extension = cmSystemTools::LowerCase(extension);
  1117. if (extension == ".csproj"_s) {
  1118. // Use correct platform name
  1119. platform =
  1120. slnData.GetConfigurationTarget(tname, plainConfig, platform);
  1121. }
  1122. }
  1123. makeCommand.Add(cmStrCat("/p:Configuration=", plainConfig));
  1124. makeCommand.Add(cmStrCat("/p:Platform=", platform));
  1125. makeCommand.Add(
  1126. cmStrCat("/p:VisualStudioVersion=", this->GetIDEVersion()));
  1127. if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
  1128. if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
  1129. makeCommand.Add("/m");
  1130. } else {
  1131. makeCommand.Add(cmStrCat("/m:", jobs));
  1132. }
  1133. }
  1134. // Respect the verbosity: 'n' normal will show build commands
  1135. // 'm' minimal only the build step's title
  1136. makeCommand.Add(cmStrCat("/v:", ((verbose) ? 'n' : 'm')));
  1137. makeCommand.Add(makeOptions.begin(), makeOptions.end());
  1138. makeCommands.emplace_back(std::move(makeCommand));
  1139. }
  1140. return makeCommands;
  1141. }
  1142. std::string cmGlobalVisualStudio10Generator::GenerateRuleFile(
  1143. std::string const& output) const
  1144. {
  1145. // The VS 10 generator needs to create the .rule files on disk.
  1146. // Hide them away under the CMakeFiles directory.
  1147. cmCryptoHash hasher(cmCryptoHash::AlgoMD5);
  1148. std::string ruleDir = cmStrCat(
  1149. this->GetCMakeInstance()->GetHomeOutputDirectory(), "/CMakeFiles/",
  1150. hasher.HashString(cmSystemTools::GetFilenamePath(output)));
  1151. std::string ruleFile =
  1152. cmStrCat(ruleDir, '/', cmSystemTools::GetFilenameName(output), ".rule");
  1153. return ruleFile;
  1154. }
  1155. void cmGlobalVisualStudio10Generator::PathTooLong(cmGeneratorTarget* target,
  1156. cmSourceFile const* sf,
  1157. std::string const& sfRel)
  1158. {
  1159. size_t len =
  1160. (target->GetLocalGenerator()->GetCurrentBinaryDirectory().length() + 1 +
  1161. sfRel.length());
  1162. if (len > this->LongestSource.Length) {
  1163. this->LongestSource.Length = len;
  1164. this->LongestSource.Target = target;
  1165. this->LongestSource.SourceFile = sf;
  1166. this->LongestSource.SourceRel = sfRel;
  1167. }
  1168. }
  1169. std::string cmGlobalVisualStudio10Generator::Encoding()
  1170. {
  1171. return "utf-8";
  1172. }
  1173. char const* cmGlobalVisualStudio10Generator::GetToolsVersion() const
  1174. {
  1175. switch (this->Version) {
  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. case cmGlobalVisualStudioGenerator::VSVersion::VS18:
  1185. return "18.0";
  1186. }
  1187. return "";
  1188. }
  1189. bool cmGlobalVisualStudio10Generator::IsNsightTegra() const
  1190. {
  1191. return !this->NsightTegraVersion.empty();
  1192. }
  1193. std::string cmGlobalVisualStudio10Generator::GetNsightTegraVersion() const
  1194. {
  1195. return this->NsightTegraVersion;
  1196. }
  1197. std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
  1198. {
  1199. std::string version;
  1200. cmSystemTools::ReadRegistryValue(
  1201. "HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;"
  1202. "Version",
  1203. version, cmSystemTools::KeyWOW64_32);
  1204. return version;
  1205. }
  1206. std::string cmGlobalVisualStudio10Generator::GetApplicationTypeRevision() const
  1207. {
  1208. if (this->GetSystemName() == "Android"_s) {
  1209. return this->GetAndroidApplicationTypeRevision();
  1210. }
  1211. // Return the first two '.'-separated components of the Windows version.
  1212. std::string::size_type end1 = this->SystemVersion.find('.');
  1213. std::string::size_type end2 =
  1214. end1 == std::string::npos ? end1 : this->SystemVersion.find('.', end1 + 1);
  1215. return this->SystemVersion.substr(0, end2);
  1216. }
  1217. static std::string cmLoadFlagTableString(Json::Value entry, char const* field)
  1218. {
  1219. if (entry.isMember(field)) {
  1220. auto string = entry[field];
  1221. if (string.isConvertibleTo(Json::ValueType::stringValue)) {
  1222. return string.asString();
  1223. }
  1224. }
  1225. return "";
  1226. }
  1227. static unsigned int cmLoadFlagTableSpecial(Json::Value entry,
  1228. char const* field)
  1229. {
  1230. unsigned int value = 0;
  1231. if (entry.isMember(field)) {
  1232. auto specials = entry[field];
  1233. if (specials.isArray()) {
  1234. for (auto const& special : specials) {
  1235. std::string s = special.asString();
  1236. if (s == "UserValue"_s) {
  1237. value |= cmIDEFlagTable::UserValue;
  1238. } else if (s == "UserIgnored"_s) {
  1239. value |= cmIDEFlagTable::UserIgnored;
  1240. } else if (s == "UserRequired"_s) {
  1241. value |= cmIDEFlagTable::UserRequired;
  1242. } else if (s == "Continue"_s) {
  1243. value |= cmIDEFlagTable::Continue;
  1244. } else if (s == "SemicolonAppendable"_s) {
  1245. value |= cmIDEFlagTable::SemicolonAppendable;
  1246. } else if (s == "UserFollowing"_s) {
  1247. value |= cmIDEFlagTable::UserFollowing;
  1248. } else if (s == "CaseInsensitive"_s) {
  1249. value |= cmIDEFlagTable::CaseInsensitive;
  1250. } else if (s == "SpaceAppendable"_s) {
  1251. value |= cmIDEFlagTable::SpaceAppendable;
  1252. } else if (s == "CommaAppendable"_s) {
  1253. value |= cmIDEFlagTable::CommaAppendable;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. return value;
  1259. }
  1260. namespace {
  1261. cmIDEFlagTable const* cmLoadFlagTableJson(std::string const& flagJsonPath,
  1262. cm::optional<std::string> vsVer)
  1263. {
  1264. cmIDEFlagTable* ret = nullptr;
  1265. auto savedFlagIterator = loadedFlagJsonFiles.find(flagJsonPath);
  1266. if (savedFlagIterator != loadedFlagJsonFiles.end()) {
  1267. ret = savedFlagIterator->second.data();
  1268. } else {
  1269. Json::Reader reader;
  1270. cmsys::ifstream stream;
  1271. stream.open(flagJsonPath.c_str(), std::ios_base::in);
  1272. if (stream) {
  1273. Json::Value flags;
  1274. if (reader.parse(stream, flags, false) && flags.isArray()) {
  1275. std::vector<cmIDEFlagTable> flagTable;
  1276. for (auto const& flag : flags) {
  1277. Json::Value const& vsminJson = flag["vsmin"];
  1278. if (vsminJson.isString()) {
  1279. std::string const& vsmin = vsminJson.asString();
  1280. if (!vsmin.empty()) {
  1281. if (!vsVer ||
  1282. cmSystemTools::VersionCompareGreater(vsmin, *vsVer)) {
  1283. continue;
  1284. }
  1285. }
  1286. }
  1287. cmIDEFlagTable flagEntry;
  1288. flagEntry.IDEName = cmLoadFlagTableString(flag, "name");
  1289. flagEntry.commandFlag = cmLoadFlagTableString(flag, "switch");
  1290. flagEntry.comment = cmLoadFlagTableString(flag, "comment");
  1291. flagEntry.value = cmLoadFlagTableString(flag, "value");
  1292. flagEntry.special = cmLoadFlagTableSpecial(flag, "flags");
  1293. flagTable.push_back(flagEntry);
  1294. }
  1295. cmIDEFlagTable endFlag{ "", "", "", "", 0 };
  1296. flagTable.push_back(endFlag);
  1297. loadedFlagJsonFiles[flagJsonPath] = flagTable;
  1298. ret = loadedFlagJsonFiles[flagJsonPath].data();
  1299. }
  1300. }
  1301. }
  1302. return ret;
  1303. }
  1304. }
  1305. cm::optional<std::string> cmGlobalVisualStudio10Generator::FindFlagTable(
  1306. cm::string_view toolsetName, cm::string_view table) const
  1307. {
  1308. if (!this->CustomFlagTableDir.empty()) {
  1309. std::string customFlagTableFile =
  1310. cmStrCat(this->CustomFlagTableDir, '/', this->GetPlatformName(), '_',
  1311. toolsetName, '_', table, ".json");
  1312. if (cmSystemTools::FileExists(customFlagTableFile)) {
  1313. return customFlagTableFile;
  1314. }
  1315. customFlagTableFile =
  1316. cmStrCat(this->CustomFlagTableDir, '/', this->GetPlatformName(), '_',
  1317. table, ".json");
  1318. if (cmSystemTools::FileExists(customFlagTableFile)) {
  1319. return customFlagTableFile;
  1320. }
  1321. }
  1322. std::string fullPath =
  1323. cmStrCat(cmSystemTools::GetCMakeRoot(), "/Templates/MSBuild/FlagTables/",
  1324. toolsetName, '_', table, ".json");
  1325. if (cmSystemTools::FileExists(fullPath)) {
  1326. return fullPath;
  1327. }
  1328. return {};
  1329. }
  1330. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable(
  1331. std::string const& toolSpecificName, std::string const& defaultName,
  1332. std::string const& table) const
  1333. {
  1334. cmMakefile* mf = this->GetCurrentMakefile();
  1335. std::string filename;
  1336. if (!toolSpecificName.empty()) {
  1337. if (cm::optional<std::string> found =
  1338. this->FindFlagTable(toolSpecificName, table)) {
  1339. filename = std::move(*found);
  1340. } else {
  1341. mf->IssueMessage(MessageType::FATAL_ERROR,
  1342. cmStrCat("JSON flag table for ", table,
  1343. " not found for toolset ", toolSpecificName));
  1344. return nullptr;
  1345. }
  1346. } else {
  1347. std::string const& genericName =
  1348. this->CanonicalToolsetName(this->GetPlatformToolsetString());
  1349. cm::optional<std::string> found = this->FindFlagTable(genericName, table);
  1350. if (!found) {
  1351. found = this->FindFlagTable(defaultName, table);
  1352. }
  1353. if (found) {
  1354. filename = std::move(*found);
  1355. } else {
  1356. mf->IssueMessage(MessageType::FATAL_ERROR,
  1357. cmStrCat("JSON flag table for ", table,
  1358. " not found for toolset ", genericName, ' ',
  1359. defaultName));
  1360. return nullptr;
  1361. }
  1362. }
  1363. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1364. if (cmIDEFlagTable const* ret = cmLoadFlagTableJson(filename, vsVer)) {
  1365. return ret;
  1366. }
  1367. mf->IssueMessage(
  1368. MessageType::FATAL_ERROR,
  1369. cmStrCat("JSON flag table could not be loaded:\n ", filename));
  1370. return nullptr;
  1371. }
  1372. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const
  1373. {
  1374. return LoadFlagTable(this->GetClFlagTableName(),
  1375. this->DefaultCLFlagTableName, "CL");
  1376. }
  1377. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable()
  1378. const
  1379. {
  1380. return LoadFlagTable(this->GetCSharpFlagTableName(),
  1381. this->DefaultCSharpFlagTableName, "CSharp");
  1382. }
  1383. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const
  1384. {
  1385. return LoadFlagTable(this->GetRcFlagTableName(),
  1386. this->DefaultRCFlagTableName, "RC");
  1387. }
  1388. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const
  1389. {
  1390. return LoadFlagTable(this->GetLibFlagTableName(),
  1391. this->DefaultLibFlagTableName, "LIB");
  1392. }
  1393. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const
  1394. {
  1395. return LoadFlagTable(this->GetLinkFlagTableName(),
  1396. this->DefaultLinkFlagTableName, "Link");
  1397. }
  1398. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaFlagTable() const
  1399. {
  1400. return LoadFlagTable(std::string(), this->DefaultCudaFlagTableName, "Cuda");
  1401. }
  1402. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaHostFlagTable()
  1403. const
  1404. {
  1405. return LoadFlagTable(std::string(), this->DefaultCudaHostFlagTableName,
  1406. "CudaHost");
  1407. }
  1408. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMarmasmFlagTable()
  1409. const
  1410. {
  1411. return LoadFlagTable(std::string(), this->DefaultMarmasmFlagTableName,
  1412. "MARMASM");
  1413. }
  1414. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const
  1415. {
  1416. return LoadFlagTable(this->GetMasmFlagTableName(),
  1417. this->DefaultMasmFlagTableName, "MASM");
  1418. }
  1419. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const
  1420. {
  1421. return LoadFlagTable(std::string(), this->DefaultNasmFlagTableName, "NASM");
  1422. }
  1423. bool cmGlobalVisualStudio10Generator::IsMsBuildRestoreSupported() const
  1424. {
  1425. if (this->Version >= VSVersion::VS16) {
  1426. return true;
  1427. }
  1428. static std::string const vsVer15_7_5 = "15.7.27703.2042";
  1429. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1430. return (vsVer &&
  1431. cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer15_7_5));
  1432. }
  1433. bool cmGlobalVisualStudio10Generator::IsBuildInParallelSupported() const
  1434. {
  1435. if (this->Version >= VSVersion::VS16) {
  1436. return true;
  1437. }
  1438. static std::string const vsVer15_8_0 = "15.8.27705.0";
  1439. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1440. return (vsVer &&
  1441. cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer15_8_0));
  1442. }
  1443. std::string cmGlobalVisualStudio10Generator::GetClFlagTableName() const
  1444. {
  1445. std::string const& toolset = this->GetPlatformToolsetString();
  1446. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1447. if (toolset == "v142"_s) {
  1448. return "v142";
  1449. }
  1450. if (toolset == "v141"_s) {
  1451. return "v141";
  1452. }
  1453. if (useToolset == "v140"_s) {
  1454. return "v140";
  1455. }
  1456. if (useToolset == "v120"_s) {
  1457. return "v12";
  1458. }
  1459. if (useToolset == "v110"_s) {
  1460. return "v11";
  1461. }
  1462. if (useToolset == "v100"_s) {
  1463. return "v10";
  1464. }
  1465. return "";
  1466. }
  1467. std::string cmGlobalVisualStudio10Generator::GetCSharpFlagTableName() const
  1468. {
  1469. std::string const& toolset = this->GetPlatformToolsetString();
  1470. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1471. if (useToolset == "v142"_s) {
  1472. return "v142";
  1473. }
  1474. if (useToolset == "v141"_s) {
  1475. return "v141";
  1476. }
  1477. if (useToolset == "v140"_s) {
  1478. return "v140";
  1479. }
  1480. if (useToolset == "v120"_s) {
  1481. return "v12";
  1482. }
  1483. if (useToolset == "v110"_s) {
  1484. return "v11";
  1485. }
  1486. if (useToolset == "v100"_s) {
  1487. return "v10";
  1488. }
  1489. return "";
  1490. }
  1491. std::string cmGlobalVisualStudio10Generator::GetRcFlagTableName() const
  1492. {
  1493. std::string const& toolset = this->GetPlatformToolsetString();
  1494. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1495. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1496. (useToolset == "v142"_s)) {
  1497. return "v14";
  1498. }
  1499. if (useToolset == "v120"_s) {
  1500. return "v12";
  1501. }
  1502. if (useToolset == "v110"_s) {
  1503. return "v11";
  1504. }
  1505. if (useToolset == "v100"_s) {
  1506. return "v10";
  1507. }
  1508. return "";
  1509. }
  1510. std::string cmGlobalVisualStudio10Generator::GetLibFlagTableName() const
  1511. {
  1512. std::string const& toolset = this->GetPlatformToolsetString();
  1513. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1514. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1515. (useToolset == "v142"_s)) {
  1516. return "v14";
  1517. }
  1518. if (useToolset == "v120"_s) {
  1519. return "v12";
  1520. }
  1521. if (useToolset == "v110"_s) {
  1522. return "v11";
  1523. }
  1524. if (useToolset == "v100"_s) {
  1525. return "v10";
  1526. }
  1527. return "";
  1528. }
  1529. std::string cmGlobalVisualStudio10Generator::GetLinkFlagTableName() const
  1530. {
  1531. std::string const& toolset = this->GetPlatformToolsetString();
  1532. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1533. if (useToolset == "v142"_s) {
  1534. return "v142";
  1535. }
  1536. if (useToolset == "v141"_s) {
  1537. return "v141";
  1538. }
  1539. if (useToolset == "v140"_s) {
  1540. return "v140";
  1541. }
  1542. if (useToolset == "v120"_s) {
  1543. return "v12";
  1544. }
  1545. if (useToolset == "v110"_s) {
  1546. return "v11";
  1547. }
  1548. if (useToolset == "v100"_s) {
  1549. return "v10";
  1550. }
  1551. return "";
  1552. }
  1553. std::string cmGlobalVisualStudio10Generator::GetMasmFlagTableName() const
  1554. {
  1555. std::string const& toolset = this->GetPlatformToolsetString();
  1556. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1557. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1558. (useToolset == "v142"_s)) {
  1559. return "v14";
  1560. }
  1561. if (useToolset == "v120"_s) {
  1562. return "v12";
  1563. }
  1564. if (useToolset == "v110"_s) {
  1565. return "v11";
  1566. }
  1567. if (useToolset == "v100"_s) {
  1568. return "v10";
  1569. }
  1570. return "";
  1571. }
  1572. std::string cmGlobalVisualStudio10Generator::CanonicalToolsetName(
  1573. std::string const& toolset) const
  1574. {
  1575. std::size_t length = toolset.length();
  1576. if (cmHasLiteralSuffix(toolset, "_xp")) {
  1577. length -= 3;
  1578. }
  1579. return toolset.substr(0, length);
  1580. }