cmGlobalVisualStudio10Generator.cxx 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  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. cmGlobalVisualStudio10Generator::AuxToolset
  735. cmGlobalVisualStudio10Generator::FindAuxToolset(std::string&,
  736. std::string&) const
  737. {
  738. return AuxToolset::None;
  739. }
  740. bool cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf)
  741. {
  742. if (!this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf)) {
  743. return false;
  744. }
  745. mf->AddDefinition("CMAKE_VS_MSBUILD_COMMAND", this->GetMSBuildCommand());
  746. return true;
  747. }
  748. std::string const& cmGlobalVisualStudio10Generator::GetMSBuildCommand()
  749. {
  750. if (!this->MSBuildCommandInitialized) {
  751. this->MSBuildCommandInitialized = true;
  752. this->MSBuildCommand = this->FindMSBuildCommand();
  753. }
  754. return this->MSBuildCommand;
  755. }
  756. cm::optional<std::string>
  757. cmGlobalVisualStudio10Generator::FindMSBuildCommandEarly(cmMakefile*)
  758. {
  759. return this->GetMSBuildCommand();
  760. }
  761. std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand()
  762. {
  763. std::string msbuild;
  764. std::string mskey;
  765. // Search in standard location.
  766. mskey =
  767. cmStrCat(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\)",
  768. this->GetToolsVersion(), ";MSBuildToolsPath");
  769. if (cmSystemTools::ReadRegistryValue(mskey, msbuild,
  770. cmSystemTools::KeyWOW64_32)) {
  771. cmSystemTools::ConvertToUnixSlashes(msbuild);
  772. msbuild += "/MSBuild.exe";
  773. if (cmSystemTools::FileExists(msbuild, true)) {
  774. return msbuild;
  775. }
  776. }
  777. msbuild = "MSBuild.exe";
  778. return msbuild;
  779. }
  780. std::string cmGlobalVisualStudio10Generator::FindDevEnvCommand()
  781. {
  782. if (this->ExpressEdition) {
  783. // Visual Studio Express >= 10 do not have "devenv.com" or
  784. // "VCExpress.exe" that we can use to build reliably.
  785. // Tell the caller it needs to use MSBuild instead.
  786. return "";
  787. }
  788. // Skip over the cmGlobalVisualStudio8Generator implementation because
  789. // we expect a real devenv and do not want to look for VCExpress.
  790. // NOLINTNEXTLINE(bugprone-parent-virtual-call)
  791. return this->cmGlobalVisualStudio71Generator::FindDevEnvCommand();
  792. }
  793. bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
  794. {
  795. // Skip this in special cases within our own test suite.
  796. if (this->GetPlatformName() == "Test Platform"_s ||
  797. this->GetPlatformToolsetString() == "Test Toolset"_s) {
  798. return true;
  799. }
  800. std::string wd;
  801. if (!this->ConfiguredFilesPath.empty()) {
  802. // In a try-compile we are given the outer CMakeFiles directory.
  803. wd = this->ConfiguredFilesPath;
  804. } else {
  805. wd = cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(),
  806. "/CMakeFiles");
  807. }
  808. wd += '/';
  809. wd += cmVersion::GetCMakeVersion();
  810. // We record the result persistently in a file.
  811. std::string const txt = cmStrCat(wd, "/VCTargetsPath.txt");
  812. // If we have a recorded result, use it.
  813. {
  814. cmsys::ifstream fin(txt.c_str());
  815. if (fin && cmSystemTools::GetLineFromStream(fin, this->VCTargetsPath) &&
  816. cmSystemTools::FileIsDirectory(this->VCTargetsPath)) {
  817. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  818. return true;
  819. }
  820. }
  821. // Prepare the work directory.
  822. if (!cmSystemTools::MakeDirectory(wd)) {
  823. mf->IssueMessage(MessageType::FATAL_ERROR,
  824. cmStrCat("Failed to make directory:\n ", wd));
  825. cmSystemTools::SetFatalErrorOccurred();
  826. return false;
  827. }
  828. // Generate a project file for MSBuild to tell us the VCTargetsPath value.
  829. std::string const vcxproj = "VCTargetsPath.vcxproj";
  830. {
  831. std::string const vcxprojAbs = cmStrCat(wd, '/', vcxproj);
  832. cmsys::ofstream fout(vcxprojAbs.c_str());
  833. cmXMLWriter xw(fout);
  834. cmXMLDocument doc(xw);
  835. cmXMLElement eprj(doc, "Project");
  836. eprj.Attribute("DefaultTargets", "Build");
  837. eprj.Attribute("ToolsVersion", "4.0");
  838. eprj.Attribute("xmlns",
  839. "http://schemas.microsoft.com/developer/msbuild/2003");
  840. if (this->IsNsightTegra()) {
  841. cmXMLElement epg(eprj, "PropertyGroup");
  842. epg.Attribute("Label", "NsightTegraProject");
  843. cmXMLElement(epg, "NsightTegraProjectRevisionNumber").Content("6");
  844. }
  845. {
  846. cmXMLElement eig(eprj, "ItemGroup");
  847. eig.Attribute("Label", "ProjectConfigurations");
  848. cmXMLElement epc(eig, "ProjectConfiguration");
  849. epc.Attribute("Include", cmStrCat("Debug|", this->GetPlatformName()));
  850. cmXMLElement(epc, "Configuration").Content("Debug");
  851. cmXMLElement(epc, "Platform").Content(this->GetPlatformName());
  852. }
  853. {
  854. cmXMLElement epg(eprj, "PropertyGroup");
  855. epg.Attribute("Label", "Globals");
  856. cmXMLElement(epg, "ProjectGuid")
  857. .Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}");
  858. cmXMLElement(epg, "Keyword")
  859. .Content(mf->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Android"_s
  860. ? "Android"
  861. : "Win32Proj");
  862. cmXMLElement(epg, "Platform").Content(this->GetPlatformName());
  863. if (this->GetSystemName() == "WindowsPhone"_s) {
  864. cmXMLElement(epg, "ApplicationType").Content("Windows Phone");
  865. cmXMLElement(epg, "ApplicationTypeRevision")
  866. .Content(this->GetApplicationTypeRevision());
  867. } else if (this->GetSystemName() == "WindowsStore"_s) {
  868. cmXMLElement(epg, "ApplicationType").Content("Windows Store");
  869. cmXMLElement(epg, "ApplicationTypeRevision")
  870. .Content(this->GetApplicationTypeRevision());
  871. } else if (this->GetSystemName() == "Android"_s) {
  872. cmXMLElement(epg, "ApplicationType").Content("Android");
  873. cmXMLElement(epg, "ApplicationTypeRevision")
  874. .Content(this->GetApplicationTypeRevision());
  875. }
  876. if (!this->WindowsTargetPlatformVersion.empty()) {
  877. cmXMLElement(epg, "WindowsTargetPlatformVersion")
  878. .Content(this->WindowsTargetPlatformVersion);
  879. }
  880. if (this->GetSystemName() != "Android"_s) {
  881. if (this->GetPlatformName() == "ARM64"_s) {
  882. cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true");
  883. } else if (this->GetPlatformName() == "ARM"_s) {
  884. cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true");
  885. }
  886. }
  887. }
  888. cmXMLElement(eprj, "Import")
  889. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  890. if (char const* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  891. cmXMLElement epg(eprj, "PropertyGroup");
  892. cmXMLElement(epg, "PreferredToolArchitecture").Content(hostArch);
  893. }
  894. {
  895. cmXMLElement epg(eprj, "PropertyGroup");
  896. epg.Attribute("Label", "Configuration");
  897. {
  898. // noqa: spellcheck off
  899. cmXMLElement ect(epg, "ConfigurationType");
  900. if (this->IsNsightTegra()) {
  901. // Tegra-Android platform does not understand "Utility".
  902. ect.Content("StaticLibrary");
  903. } else {
  904. ect.Content("Utility");
  905. }
  906. // noqa: spellcheck on
  907. }
  908. cmXMLElement(epg, "CharacterSet").Content("MultiByte");
  909. if (this->IsNsightTegra()) {
  910. cmXMLElement(epg, "NdkToolchainVersion")
  911. .Content(this->GetPlatformToolsetString());
  912. } else {
  913. cmXMLElement(epg, "PlatformToolset")
  914. .Content(this->GetPlatformToolsetString());
  915. }
  916. }
  917. cmXMLElement(eprj, "Import")
  918. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  919. {
  920. cmXMLElement eidg(eprj, "ItemDefinitionGroup");
  921. cmXMLElement epbe(eidg, "PostBuildEvent");
  922. cmXMLElement(epbe, "Command")
  923. .Content("echo VCTargetsPath=$(VCTargetsPath)");
  924. }
  925. cmXMLElement(eprj, "Import")
  926. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  927. }
  928. std::vector<std::string> cmd;
  929. cmd.push_back(this->GetMSBuildCommand());
  930. cmd.push_back(vcxproj);
  931. cmd.emplace_back("/p:Configuration=Debug");
  932. cmd.emplace_back(cmStrCat("/p:Platform=", this->GetPlatformName()));
  933. cmd.emplace_back(cmStrCat("/p:VisualStudioVersion=", this->GetIDEVersion()));
  934. std::string out;
  935. int ret = 0;
  936. cmsys::RegularExpression regex("\n *VCTargetsPath=([^%\r\n]+)[\r\n]");
  937. if (!cmSystemTools::RunSingleCommand(cmd, &out, &out, &ret, wd.c_str(),
  938. cmSystemTools::OUTPUT_NONE) ||
  939. ret != 0 || !regex.find(out)) {
  940. cmSystemTools::ReplaceString(out, "\n", "\n ");
  941. std::ostringstream e;
  942. /* clang-format off */
  943. e <<
  944. "Failed to run MSBuild command:\n"
  945. " " << cmd[0] << "\n"
  946. "to get the value of VCTargetsPath:\n"
  947. " " << out << '\n'
  948. ;
  949. /* clang-format on */
  950. if (ret != 0) {
  951. e << "Exit code: " << ret << '\n';
  952. }
  953. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  954. cmSystemTools::SetFatalErrorOccurred();
  955. return false;
  956. }
  957. this->VCTargetsPath = regex.match(1);
  958. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  959. {
  960. cmsys::ofstream fout(txt.c_str());
  961. fout << this->VCTargetsPath << '\n';
  962. }
  963. return true;
  964. }
  965. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  966. cmGlobalVisualStudio10Generator::GenerateBuildCommand(
  967. std::string const& makeProgram, std::string const& projectName,
  968. std::string const& projectDir, std::vector<std::string> const& targetNames,
  969. std::string const& config, int jobs, bool verbose,
  970. cmBuildOptions buildOptions, std::vector<std::string> const& makeOptions)
  971. {
  972. std::vector<GeneratedMakeCommand> makeCommands;
  973. // Select the caller- or user-preferred make program, else MSBuild.
  974. std::string makeProgramSelected =
  975. this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand());
  976. // Check if the caller explicitly requested a devenv tool.
  977. std::string makeProgramLower = makeProgramSelected;
  978. cmSystemTools::LowerCase(makeProgramLower);
  979. bool useDevEnv = (makeProgramLower.find("devenv") != std::string::npos ||
  980. makeProgramLower.find("vcexpress") != std::string::npos);
  981. // Workaround to convince VCExpress.exe to produce output.
  982. bool const requiresOutputForward =
  983. (makeProgramLower.find("vcexpress") != std::string::npos);
  984. // MSBuild is preferred (and required for VS Express), but if the .sln has
  985. // an Intel Fortran .vfproj then we have to use devenv. Parse it to find out.
  986. cmSlnData slnData;
  987. {
  988. std::string slnFile;
  989. if (!projectDir.empty()) {
  990. slnFile = cmStrCat(projectDir, '/');
  991. }
  992. slnFile += projectName;
  993. slnFile += ".sln";
  994. cmVisualStudioSlnParser parser;
  995. if (parser.ParseFile(slnFile, slnData,
  996. cmVisualStudioSlnParser::DataGroupAll)) {
  997. std::vector<cmSlnProjectEntry> slnProjects = slnData.GetProjects();
  998. for (cmSlnProjectEntry const& project : slnProjects) {
  999. if (useDevEnv) {
  1000. break;
  1001. }
  1002. std::string proj = project.GetRelativePath();
  1003. if (proj.size() > 7 && proj.substr(proj.size() - 7) == ".vfproj"_s) {
  1004. useDevEnv = true;
  1005. }
  1006. }
  1007. }
  1008. }
  1009. if (useDevEnv) {
  1010. // Use devenv to build solutions containing Intel Fortran projects.
  1011. return cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  1012. makeProgram, projectName, projectDir, targetNames, config, jobs, verbose,
  1013. buildOptions, makeOptions);
  1014. }
  1015. std::vector<std::string> realTargetNames = targetNames;
  1016. if (targetNames.empty() ||
  1017. ((targetNames.size() == 1) && targetNames.front().empty())) {
  1018. realTargetNames = { "ALL_BUILD" };
  1019. }
  1020. for (auto const& tname : realTargetNames) {
  1021. // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug
  1022. // /target:ALL_BUILD
  1023. // /m
  1024. if (tname.empty()) {
  1025. continue;
  1026. }
  1027. GeneratedMakeCommand makeCommand;
  1028. makeCommand.RequiresOutputForward = requiresOutputForward;
  1029. makeCommand.Add(makeProgramSelected);
  1030. cm::optional<cmSlnProjectEntry> proj = cm::nullopt;
  1031. if (tname == "clean"_s) {
  1032. makeCommand.Add(cmStrCat(projectName, ".sln"));
  1033. makeCommand.Add("/t:Clean");
  1034. } else {
  1035. std::string targetProject = cmStrCat(tname, ".vcxproj");
  1036. proj = slnData.GetProjectByName(tname);
  1037. if (targetProject.find('/') == std::string::npos) {
  1038. // it might be in a subdir
  1039. if (proj) {
  1040. targetProject = proj->GetRelativePath();
  1041. cmSystemTools::ConvertToUnixSlashes(targetProject);
  1042. }
  1043. }
  1044. makeCommand.Add(targetProject);
  1045. // Check if we do need a restore at all (i.e. if there are package
  1046. // references and restore has not been disabled by a command line option.
  1047. PackageResolveMode restoreMode = buildOptions.ResolveMode;
  1048. bool requiresRestore = true;
  1049. if (restoreMode == PackageResolveMode::Disable) {
  1050. requiresRestore = false;
  1051. } else if (cmValue cached =
  1052. this->CMakeInstance->GetState()->GetCacheEntryValue(
  1053. cmStrCat(tname, "_REQUIRES_VS_PACKAGE_RESTORE"))) {
  1054. requiresRestore = cached.IsOn();
  1055. } else {
  1056. // There are no package references defined.
  1057. requiresRestore = false;
  1058. }
  1059. // If a restore is required, evaluate the restore mode.
  1060. if (requiresRestore) {
  1061. if (restoreMode == PackageResolveMode::OnlyResolve) {
  1062. // Only invoke the restore target on the project.
  1063. makeCommand.Add("/t:Restore");
  1064. } else {
  1065. // Invoke restore target, unless it has been explicitly disabled.
  1066. bool restorePackages = true;
  1067. if (this->Version < VSVersion::VS15) {
  1068. // Package restore is only supported starting from Visual Studio
  1069. // 2017. Package restore must be executed manually using NuGet
  1070. // shell for older versions.
  1071. this->CMakeInstance->IssueMessage(
  1072. MessageType::WARNING,
  1073. "Restoring package references is only supported for Visual "
  1074. "Studio 2017 and later. You have to manually restore the "
  1075. "packages using NuGet before building the project.");
  1076. restorePackages = false;
  1077. } else if (restoreMode == PackageResolveMode::Default) {
  1078. // Decide if a restore is performed, based on a cache variable.
  1079. if (cmValue cached =
  1080. this->CMakeInstance->GetState()->GetCacheEntryValue(
  1081. "CMAKE_VS_NUGET_PACKAGE_RESTORE")) {
  1082. restorePackages = cached.IsOn();
  1083. }
  1084. }
  1085. if (restorePackages) {
  1086. if (this->IsMsBuildRestoreSupported()) {
  1087. makeCommand.Add("/restore");
  1088. } else {
  1089. GeneratedMakeCommand restoreCommand;
  1090. restoreCommand.Add(makeProgramSelected);
  1091. restoreCommand.Add(targetProject);
  1092. restoreCommand.Add("/t:Restore");
  1093. makeCommands.emplace_back(restoreCommand);
  1094. }
  1095. }
  1096. }
  1097. }
  1098. }
  1099. std::string plainConfig = config;
  1100. if (config.empty()) {
  1101. plainConfig = "Debug";
  1102. }
  1103. std::string platform = GetPlatformName();
  1104. if (proj) {
  1105. std::string extension =
  1106. cmSystemTools::GetFilenameLastExtension(proj->GetRelativePath());
  1107. extension = cmSystemTools::LowerCase(extension);
  1108. if (extension == ".csproj"_s) {
  1109. // Use correct platform name
  1110. platform =
  1111. slnData.GetConfigurationTarget(tname, plainConfig, platform);
  1112. }
  1113. }
  1114. makeCommand.Add(cmStrCat("/p:Configuration=", plainConfig));
  1115. makeCommand.Add(cmStrCat("/p:Platform=", platform));
  1116. makeCommand.Add(
  1117. cmStrCat("/p:VisualStudioVersion=", this->GetIDEVersion()));
  1118. if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
  1119. if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
  1120. makeCommand.Add("/m");
  1121. } else {
  1122. makeCommand.Add(cmStrCat("/m:", jobs));
  1123. }
  1124. }
  1125. // Respect the verbosity: 'n' normal will show build commands
  1126. // 'm' minimal only the build step's title
  1127. makeCommand.Add(cmStrCat("/v:", ((verbose) ? 'n' : 'm')));
  1128. makeCommand.Add(makeOptions.begin(), makeOptions.end());
  1129. makeCommands.emplace_back(std::move(makeCommand));
  1130. }
  1131. return makeCommands;
  1132. }
  1133. std::string cmGlobalVisualStudio10Generator::GenerateRuleFile(
  1134. std::string const& output) const
  1135. {
  1136. // The VS 10 generator needs to create the .rule files on disk.
  1137. // Hide them away under the CMakeFiles directory.
  1138. cmCryptoHash hasher(cmCryptoHash::AlgoMD5);
  1139. std::string ruleDir = cmStrCat(
  1140. this->GetCMakeInstance()->GetHomeOutputDirectory(), "/CMakeFiles/",
  1141. hasher.HashString(cmSystemTools::GetFilenamePath(output)));
  1142. std::string ruleFile =
  1143. cmStrCat(ruleDir, '/', cmSystemTools::GetFilenameName(output), ".rule");
  1144. return ruleFile;
  1145. }
  1146. void cmGlobalVisualStudio10Generator::PathTooLong(cmGeneratorTarget* target,
  1147. cmSourceFile const* sf,
  1148. std::string const& sfRel)
  1149. {
  1150. size_t len =
  1151. (target->GetLocalGenerator()->GetCurrentBinaryDirectory().length() + 1 +
  1152. sfRel.length());
  1153. if (len > this->LongestSource.Length) {
  1154. this->LongestSource.Length = len;
  1155. this->LongestSource.Target = target;
  1156. this->LongestSource.SourceFile = sf;
  1157. this->LongestSource.SourceRel = sfRel;
  1158. }
  1159. }
  1160. std::string cmGlobalVisualStudio10Generator::Encoding()
  1161. {
  1162. return "utf-8";
  1163. }
  1164. char const* cmGlobalVisualStudio10Generator::GetToolsVersion() const
  1165. {
  1166. switch (this->Version) {
  1167. case cmGlobalVisualStudioGenerator::VSVersion::VS14:
  1168. return "14.0";
  1169. case cmGlobalVisualStudioGenerator::VSVersion::VS15:
  1170. return "15.0";
  1171. case cmGlobalVisualStudioGenerator::VSVersion::VS16:
  1172. return "16.0";
  1173. case cmGlobalVisualStudioGenerator::VSVersion::VS17:
  1174. return "17.0";
  1175. }
  1176. return "";
  1177. }
  1178. bool cmGlobalVisualStudio10Generator::IsNsightTegra() const
  1179. {
  1180. return !this->NsightTegraVersion.empty();
  1181. }
  1182. std::string cmGlobalVisualStudio10Generator::GetNsightTegraVersion() const
  1183. {
  1184. return this->NsightTegraVersion;
  1185. }
  1186. std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
  1187. {
  1188. std::string version;
  1189. cmSystemTools::ReadRegistryValue(
  1190. "HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;"
  1191. "Version",
  1192. version, cmSystemTools::KeyWOW64_32);
  1193. return version;
  1194. }
  1195. std::string cmGlobalVisualStudio10Generator::GetApplicationTypeRevision() const
  1196. {
  1197. if (this->GetSystemName() == "Android"_s) {
  1198. return this->GetAndroidApplicationTypeRevision();
  1199. }
  1200. // Return the first two '.'-separated components of the Windows version.
  1201. std::string::size_type end1 = this->SystemVersion.find('.');
  1202. std::string::size_type end2 =
  1203. end1 == std::string::npos ? end1 : this->SystemVersion.find('.', end1 + 1);
  1204. return this->SystemVersion.substr(0, end2);
  1205. }
  1206. static std::string cmLoadFlagTableString(Json::Value entry, char const* field)
  1207. {
  1208. if (entry.isMember(field)) {
  1209. auto string = entry[field];
  1210. if (string.isConvertibleTo(Json::ValueType::stringValue)) {
  1211. return string.asString();
  1212. }
  1213. }
  1214. return "";
  1215. }
  1216. static unsigned int cmLoadFlagTableSpecial(Json::Value entry,
  1217. char const* field)
  1218. {
  1219. unsigned int value = 0;
  1220. if (entry.isMember(field)) {
  1221. auto specials = entry[field];
  1222. if (specials.isArray()) {
  1223. for (auto const& special : specials) {
  1224. std::string s = special.asString();
  1225. if (s == "UserValue"_s) {
  1226. value |= cmIDEFlagTable::UserValue;
  1227. } else if (s == "UserIgnored"_s) {
  1228. value |= cmIDEFlagTable::UserIgnored;
  1229. } else if (s == "UserRequired"_s) {
  1230. value |= cmIDEFlagTable::UserRequired;
  1231. } else if (s == "Continue"_s) {
  1232. value |= cmIDEFlagTable::Continue;
  1233. } else if (s == "SemicolonAppendable"_s) {
  1234. value |= cmIDEFlagTable::SemicolonAppendable;
  1235. } else if (s == "UserFollowing"_s) {
  1236. value |= cmIDEFlagTable::UserFollowing;
  1237. } else if (s == "CaseInsensitive"_s) {
  1238. value |= cmIDEFlagTable::CaseInsensitive;
  1239. } else if (s == "SpaceAppendable"_s) {
  1240. value |= cmIDEFlagTable::SpaceAppendable;
  1241. } else if (s == "CommaAppendable"_s) {
  1242. value |= cmIDEFlagTable::CommaAppendable;
  1243. }
  1244. }
  1245. }
  1246. }
  1247. return value;
  1248. }
  1249. namespace {
  1250. cmIDEFlagTable const* cmLoadFlagTableJson(std::string const& flagJsonPath,
  1251. cm::optional<std::string> vsVer)
  1252. {
  1253. cmIDEFlagTable* ret = nullptr;
  1254. auto savedFlagIterator = loadedFlagJsonFiles.find(flagJsonPath);
  1255. if (savedFlagIterator != loadedFlagJsonFiles.end()) {
  1256. ret = savedFlagIterator->second.data();
  1257. } else {
  1258. Json::Reader reader;
  1259. cmsys::ifstream stream;
  1260. stream.open(flagJsonPath.c_str(), std::ios_base::in);
  1261. if (stream) {
  1262. Json::Value flags;
  1263. if (reader.parse(stream, flags, false) && flags.isArray()) {
  1264. std::vector<cmIDEFlagTable> flagTable;
  1265. for (auto const& flag : flags) {
  1266. Json::Value const& vsminJson = flag["vsmin"];
  1267. if (vsminJson.isString()) {
  1268. std::string const& vsmin = vsminJson.asString();
  1269. if (!vsmin.empty()) {
  1270. if (!vsVer ||
  1271. cmSystemTools::VersionCompareGreater(vsmin, *vsVer)) {
  1272. continue;
  1273. }
  1274. }
  1275. }
  1276. cmIDEFlagTable flagEntry;
  1277. flagEntry.IDEName = cmLoadFlagTableString(flag, "name");
  1278. flagEntry.commandFlag = cmLoadFlagTableString(flag, "switch");
  1279. flagEntry.comment = cmLoadFlagTableString(flag, "comment");
  1280. flagEntry.value = cmLoadFlagTableString(flag, "value");
  1281. flagEntry.special = cmLoadFlagTableSpecial(flag, "flags");
  1282. flagTable.push_back(flagEntry);
  1283. }
  1284. cmIDEFlagTable endFlag{ "", "", "", "", 0 };
  1285. flagTable.push_back(endFlag);
  1286. loadedFlagJsonFiles[flagJsonPath] = flagTable;
  1287. ret = loadedFlagJsonFiles[flagJsonPath].data();
  1288. }
  1289. }
  1290. }
  1291. return ret;
  1292. }
  1293. }
  1294. cm::optional<std::string> cmGlobalVisualStudio10Generator::FindFlagTable(
  1295. cm::string_view toolsetName, cm::string_view table) const
  1296. {
  1297. if (!this->CustomFlagTableDir.empty()) {
  1298. std::string customFlagTableFile =
  1299. cmStrCat(this->CustomFlagTableDir, '/', this->GetPlatformName(), '_',
  1300. toolsetName, '_', table, ".json");
  1301. if (cmSystemTools::FileExists(customFlagTableFile)) {
  1302. return customFlagTableFile;
  1303. }
  1304. customFlagTableFile =
  1305. cmStrCat(this->CustomFlagTableDir, '/', this->GetPlatformName(), '_',
  1306. table, ".json");
  1307. if (cmSystemTools::FileExists(customFlagTableFile)) {
  1308. return customFlagTableFile;
  1309. }
  1310. }
  1311. std::string fullPath =
  1312. cmStrCat(cmSystemTools::GetCMakeRoot(), "/Templates/MSBuild/FlagTables/",
  1313. toolsetName, '_', table, ".json");
  1314. if (cmSystemTools::FileExists(fullPath)) {
  1315. return fullPath;
  1316. }
  1317. return {};
  1318. }
  1319. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable(
  1320. std::string const& toolSpecificName, std::string const& defaultName,
  1321. std::string const& table) const
  1322. {
  1323. cmMakefile* mf = this->GetCurrentMakefile();
  1324. std::string filename;
  1325. if (!toolSpecificName.empty()) {
  1326. if (cm::optional<std::string> found =
  1327. this->FindFlagTable(toolSpecificName, table)) {
  1328. filename = std::move(*found);
  1329. } else {
  1330. mf->IssueMessage(MessageType::FATAL_ERROR,
  1331. cmStrCat("JSON flag table for ", table,
  1332. " not found for toolset ", toolSpecificName));
  1333. return nullptr;
  1334. }
  1335. } else {
  1336. std::string const& genericName =
  1337. this->CanonicalToolsetName(this->GetPlatformToolsetString());
  1338. cm::optional<std::string> found = this->FindFlagTable(genericName, table);
  1339. if (!found) {
  1340. found = this->FindFlagTable(defaultName, table);
  1341. }
  1342. if (found) {
  1343. filename = std::move(*found);
  1344. } else {
  1345. mf->IssueMessage(MessageType::FATAL_ERROR,
  1346. cmStrCat("JSON flag table for ", table,
  1347. " not found for toolset ", genericName, ' ',
  1348. defaultName));
  1349. return nullptr;
  1350. }
  1351. }
  1352. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1353. if (cmIDEFlagTable const* ret = cmLoadFlagTableJson(filename, vsVer)) {
  1354. return ret;
  1355. }
  1356. mf->IssueMessage(
  1357. MessageType::FATAL_ERROR,
  1358. cmStrCat("JSON flag table could not be loaded:\n ", filename));
  1359. return nullptr;
  1360. }
  1361. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const
  1362. {
  1363. return LoadFlagTable(this->GetClFlagTableName(),
  1364. this->DefaultCLFlagTableName, "CL");
  1365. }
  1366. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable()
  1367. const
  1368. {
  1369. return LoadFlagTable(this->GetCSharpFlagTableName(),
  1370. this->DefaultCSharpFlagTableName, "CSharp");
  1371. }
  1372. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const
  1373. {
  1374. return LoadFlagTable(this->GetRcFlagTableName(),
  1375. this->DefaultRCFlagTableName, "RC");
  1376. }
  1377. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const
  1378. {
  1379. return LoadFlagTable(this->GetLibFlagTableName(),
  1380. this->DefaultLibFlagTableName, "LIB");
  1381. }
  1382. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const
  1383. {
  1384. return LoadFlagTable(this->GetLinkFlagTableName(),
  1385. this->DefaultLinkFlagTableName, "Link");
  1386. }
  1387. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaFlagTable() const
  1388. {
  1389. return LoadFlagTable(std::string(), this->DefaultCudaFlagTableName, "Cuda");
  1390. }
  1391. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaHostFlagTable()
  1392. const
  1393. {
  1394. return LoadFlagTable(std::string(), this->DefaultCudaHostFlagTableName,
  1395. "CudaHost");
  1396. }
  1397. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMarmasmFlagTable()
  1398. const
  1399. {
  1400. return LoadFlagTable(std::string(), this->DefaultMarmasmFlagTableName,
  1401. "MARMASM");
  1402. }
  1403. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const
  1404. {
  1405. return LoadFlagTable(this->GetMasmFlagTableName(),
  1406. this->DefaultMasmFlagTableName, "MASM");
  1407. }
  1408. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const
  1409. {
  1410. return LoadFlagTable(std::string(), this->DefaultNasmFlagTableName, "NASM");
  1411. }
  1412. bool cmGlobalVisualStudio10Generator::IsMsBuildRestoreSupported() const
  1413. {
  1414. if (this->Version >= VSVersion::VS16) {
  1415. return true;
  1416. }
  1417. static std::string const vsVer15_7_5 = "15.7.27703.2042";
  1418. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1419. return (vsVer &&
  1420. cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer15_7_5));
  1421. }
  1422. bool cmGlobalVisualStudio10Generator::IsBuildInParallelSupported() const
  1423. {
  1424. if (this->Version >= VSVersion::VS16) {
  1425. return true;
  1426. }
  1427. static std::string const vsVer15_8_0 = "15.8.27705.0";
  1428. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1429. return (vsVer &&
  1430. cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer15_8_0));
  1431. }
  1432. bool cmGlobalVisualStudio10Generator::SupportsShortObjectNames() const
  1433. {
  1434. return true;
  1435. }
  1436. std::string cmGlobalVisualStudio10Generator::GetClFlagTableName() const
  1437. {
  1438. std::string const& toolset = this->GetPlatformToolsetString();
  1439. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1440. if (toolset == "v142"_s) {
  1441. return "v142";
  1442. }
  1443. if (toolset == "v141"_s) {
  1444. return "v141";
  1445. }
  1446. if (useToolset == "v140"_s) {
  1447. return "v140";
  1448. }
  1449. if (useToolset == "v120"_s) {
  1450. return "v12";
  1451. }
  1452. if (useToolset == "v110"_s) {
  1453. return "v11";
  1454. }
  1455. if (useToolset == "v100"_s) {
  1456. return "v10";
  1457. }
  1458. return "";
  1459. }
  1460. std::string cmGlobalVisualStudio10Generator::GetCSharpFlagTableName() const
  1461. {
  1462. std::string const& toolset = this->GetPlatformToolsetString();
  1463. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1464. if (useToolset == "v142"_s) {
  1465. return "v142";
  1466. }
  1467. if (useToolset == "v141"_s) {
  1468. return "v141";
  1469. }
  1470. if (useToolset == "v140"_s) {
  1471. return "v140";
  1472. }
  1473. if (useToolset == "v120"_s) {
  1474. return "v12";
  1475. }
  1476. if (useToolset == "v110"_s) {
  1477. return "v11";
  1478. }
  1479. if (useToolset == "v100"_s) {
  1480. return "v10";
  1481. }
  1482. return "";
  1483. }
  1484. std::string cmGlobalVisualStudio10Generator::GetRcFlagTableName() const
  1485. {
  1486. std::string const& toolset = this->GetPlatformToolsetString();
  1487. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1488. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1489. (useToolset == "v142"_s)) {
  1490. return "v14";
  1491. }
  1492. if (useToolset == "v120"_s) {
  1493. return "v12";
  1494. }
  1495. if (useToolset == "v110"_s) {
  1496. return "v11";
  1497. }
  1498. if (useToolset == "v100"_s) {
  1499. return "v10";
  1500. }
  1501. return "";
  1502. }
  1503. std::string cmGlobalVisualStudio10Generator::GetLibFlagTableName() const
  1504. {
  1505. std::string const& toolset = this->GetPlatformToolsetString();
  1506. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1507. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1508. (useToolset == "v142"_s)) {
  1509. return "v14";
  1510. }
  1511. if (useToolset == "v120"_s) {
  1512. return "v12";
  1513. }
  1514. if (useToolset == "v110"_s) {
  1515. return "v11";
  1516. }
  1517. if (useToolset == "v100"_s) {
  1518. return "v10";
  1519. }
  1520. return "";
  1521. }
  1522. std::string cmGlobalVisualStudio10Generator::GetLinkFlagTableName() const
  1523. {
  1524. std::string const& toolset = this->GetPlatformToolsetString();
  1525. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1526. if (useToolset == "v142"_s) {
  1527. return "v142";
  1528. }
  1529. if (useToolset == "v141"_s) {
  1530. return "v141";
  1531. }
  1532. if (useToolset == "v140"_s) {
  1533. return "v140";
  1534. }
  1535. if (useToolset == "v120"_s) {
  1536. return "v12";
  1537. }
  1538. if (useToolset == "v110"_s) {
  1539. return "v11";
  1540. }
  1541. if (useToolset == "v100"_s) {
  1542. return "v10";
  1543. }
  1544. return "";
  1545. }
  1546. std::string cmGlobalVisualStudio10Generator::GetMasmFlagTableName() const
  1547. {
  1548. std::string const& toolset = this->GetPlatformToolsetString();
  1549. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1550. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1551. (useToolset == "v142"_s)) {
  1552. return "v14";
  1553. }
  1554. if (useToolset == "v120"_s) {
  1555. return "v12";
  1556. }
  1557. if (useToolset == "v110"_s) {
  1558. return "v11";
  1559. }
  1560. if (useToolset == "v100"_s) {
  1561. return "v10";
  1562. }
  1563. return "";
  1564. }
  1565. std::string cmGlobalVisualStudio10Generator::CanonicalToolsetName(
  1566. std::string const& toolset) const
  1567. {
  1568. std::size_t length = toolset.length();
  1569. if (cmHasLiteralSuffix(toolset, "_xp")) {
  1570. length -= 3;
  1571. }
  1572. return toolset.substr(0, length);
  1573. }