cmGlobalVisualStudio10Generator.cxx 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGlobalVisualStudio10Generator.h"
  4. #include <algorithm>
  5. #include <cstring>
  6. #include <map>
  7. #include <sstream>
  8. #include <utility>
  9. #include <cm/memory>
  10. #include <cmext/string_view>
  11. #include <cm3p/json/reader.h>
  12. #include <cm3p/json/value.h>
  13. #include "cmsys/FStream.hxx"
  14. #include "cmsys/Glob.hxx"
  15. #include "cmsys/RegularExpression.hxx"
  16. #include "cmCryptoHash.h"
  17. #include "cmDocumentationEntry.h"
  18. #include "cmGeneratorTarget.h"
  19. #include "cmGlobalGenerator.h"
  20. #include "cmGlobalVisualStudio71Generator.h"
  21. #include "cmGlobalVisualStudio7Generator.h"
  22. #include "cmGlobalVisualStudioGenerator.h"
  23. #include "cmIDEFlagTable.h"
  24. #include "cmLocalGenerator.h"
  25. #include "cmLocalVisualStudio10Generator.h"
  26. #include "cmMakefile.h"
  27. #include "cmMessageType.h"
  28. #include "cmSourceFile.h"
  29. #include "cmStringAlgorithms.h"
  30. #include "cmSystemTools.h"
  31. #include "cmVersion.h"
  32. #include "cmVisualStudioSlnData.h"
  33. #include "cmVisualStudioSlnParser.h"
  34. #include "cmXMLWriter.h"
  35. #include "cmake.h"
  36. static std::map<std::string, std::vector<cmIDEFlagTable>> loadedFlagJsonFiles;
  37. static void ConvertToWindowsSlashes(std::string& s)
  38. {
  39. // first convert all of the slashes
  40. for (auto& ch : s) {
  41. if (ch == '/') {
  42. ch = '\\';
  43. }
  44. }
  45. }
  46. cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator(
  47. cmake* cm, const std::string& name,
  48. std::string const& platformInGeneratorName)
  49. : cmGlobalVisualStudio8Generator(cm, name, platformInGeneratorName)
  50. {
  51. this->DefaultCudaFlagTableName = "v10";
  52. this->DefaultCudaHostFlagTableName = "v10";
  53. this->DefaultMarmasmFlagTableName = "v10";
  54. this->DefaultNasmFlagTableName = "v10";
  55. }
  56. bool cmGlobalVisualStudio10Generator::SetSystemName(std::string const& s,
  57. cmMakefile* mf)
  58. {
  59. this->SystemName = s;
  60. this->SystemVersion = mf->GetSafeDefinition("CMAKE_SYSTEM_VERSION");
  61. if (!this->InitializeSystem(mf)) {
  62. return false;
  63. }
  64. return this->cmGlobalVisualStudio8Generator::SetSystemName(s, mf);
  65. }
  66. static void cmCudaToolVersion(std::string& s)
  67. {
  68. // "CUDA x.y.props" => "x.y"
  69. s = s.substr(5);
  70. s = s.substr(0, s.size() - 6);
  71. }
  72. bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
  73. std::string const& ts, bool build, cmMakefile* mf)
  74. {
  75. if (this->SystemIsWindowsCE && ts.empty() &&
  76. this->DefaultPlatformToolset.empty()) {
  77. mf->IssueMessage(
  78. MessageType::FATAL_ERROR,
  79. cmStrCat(this->GetName(), " Windows CE version '", this->SystemVersion,
  80. "' requires CMAKE_GENERATOR_TOOLSET to be set."));
  81. return false;
  82. }
  83. if (!this->ParseGeneratorToolset(ts, mf)) {
  84. return false;
  85. }
  86. if (build) {
  87. return true;
  88. }
  89. if (this->CustomVCTargetsPath.empty() && !this->FindVCTargetsPath(mf)) {
  90. return false;
  91. }
  92. if (!this->CustomFlagTableDir.empty() &&
  93. !(cmSystemTools::FileIsFullPath(this->CustomFlagTableDir) &&
  94. cmSystemTools::FileIsDirectory(this->CustomFlagTableDir))) {
  95. mf->IssueMessage(
  96. MessageType::FATAL_ERROR,
  97. cmStrCat("Generator\n"
  98. " ",
  99. this->GetName(),
  100. "\n"
  101. "given toolset\n"
  102. " customFlagTableDir=",
  103. this->CustomFlagTableDir,
  104. "\n"
  105. "that is not an absolute path to an existing directory."));
  106. cmSystemTools::SetFatalErrorOccurred();
  107. return false;
  108. }
  109. if (cmHasLiteralPrefix(this->GetPlatformToolsetString(), "v140")) {
  110. // The GenerateDebugInformation link setting for the v140 toolset
  111. // in VS 2015 was originally an enum with "No" and "Debug" values,
  112. // differing from the "false" and "true" values used in older toolsets.
  113. // A VS 2015 update changed it back. Parse the "link.xml" file to
  114. // discover which one we need.
  115. std::string const link_xml =
  116. cmStrCat(this->VCTargetsPath, "/1033/link.xml");
  117. cmsys::ifstream fin(link_xml.c_str());
  118. std::string line;
  119. while (fin && cmSystemTools::GetLineFromStream(fin, line)) {
  120. if (line.find(" Switch=\"DEBUG\" ") != std::string::npos) {
  121. this->PlatformToolsetNeedsDebugEnum =
  122. line.find(" Name=\"Debug\" ") != std::string::npos;
  123. break;
  124. }
  125. }
  126. }
  127. this->SupportsUnityBuilds =
  128. this->Version >= cmGlobalVisualStudioGenerator::VSVersion::VS16 ||
  129. (this->Version == cmGlobalVisualStudioGenerator::VSVersion::VS15 &&
  130. cmSystemTools::PathExists(
  131. cmStrCat(this->VCTargetsPath, "/Microsoft.Cpp.Unity.targets")));
  132. if (this->GeneratorToolsetCuda.empty()) {
  133. // Find the highest available version of the CUDA tools.
  134. std::vector<std::string> cudaTools;
  135. std::string bcDir;
  136. if (this->GeneratorToolsetCudaCustomDir.empty()) {
  137. bcDir = cmStrCat(this->VCTargetsPath, "/BuildCustomizations");
  138. } else {
  139. bcDir = cmStrCat(this->GetPlatformToolsetCudaCustomDirString(),
  140. this->GetPlatformToolsetCudaVSIntegrationSubdirString(),
  141. "extras\\visual_studio_integration\\MSBuildExtensions");
  142. cmSystemTools::ConvertToUnixSlashes(bcDir);
  143. }
  144. cmsys::Glob gl;
  145. gl.SetRelative(bcDir.c_str());
  146. if (gl.FindFiles(cmStrCat(bcDir, "/CUDA *.props"))) {
  147. cudaTools = gl.GetFiles();
  148. }
  149. if (!cudaTools.empty()) {
  150. std::for_each(cudaTools.begin(), cudaTools.end(), cmCudaToolVersion);
  151. std::sort(cudaTools.begin(), cudaTools.end(),
  152. cmSystemTools::VersionCompareGreater);
  153. this->GeneratorToolsetCuda = cudaTools.at(0);
  154. } else if (!this->GeneratorToolsetCudaCustomDir.empty()) {
  155. // Generate an error if Visual Studio integration files are not found
  156. // inside of custom cuda toolset.
  157. mf->IssueMessage(
  158. MessageType::FATAL_ERROR,
  159. cmStrCat("Generator\n"
  160. " ",
  161. this->GetName(),
  162. "\n"
  163. "given toolset\n"
  164. " cuda=",
  165. this->GeneratorToolsetCudaCustomDir,
  166. "\n"
  167. "cannot detect Visual Studio integration files in path\n"
  168. " ",
  169. bcDir));
  170. // Clear the configured tool-set
  171. this->GeneratorToolsetCuda.clear();
  172. }
  173. }
  174. if (this->GeneratorToolsetFortran) {
  175. if (*this->GeneratorToolsetFortran != "ifx" &&
  176. *this->GeneratorToolsetFortran != "ifort") {
  177. mf->IssueMessage(MessageType::FATAL_ERROR,
  178. cmStrCat("Generator\n"
  179. " ",
  180. this->GetName(),
  181. "\n"
  182. "given toolset\n"
  183. " fortran=",
  184. *this->GeneratorToolsetFortran,
  185. "\n"
  186. "but the value is not \"ifx\" or \"ifort\"."));
  187. this->GeneratorToolsetFortran = cm::nullopt;
  188. }
  189. }
  190. if (!this->GeneratorToolsetVersion.empty() &&
  191. this->GeneratorToolsetVersion != "Test Toolset Version"_s) {
  192. // If a specific minor version of the MSVC toolset is requested, verify
  193. // that it is compatible with the PlatformToolset version. The ability to
  194. // choose a minor version of MSVC has been available since v141.
  195. std::string const& platformToolset = this->GetPlatformToolsetString();
  196. cmsys::RegularExpression vcPlatformToolsetRegex("^v[0-9][0-9][0-9]$");
  197. if (vcPlatformToolsetRegex.find(platformToolset) ||
  198. platformToolset == "Test Toolset"_s) {
  199. std::string versionToolset = this->GeneratorToolsetVersion;
  200. cmsys::RegularExpression versionToolsetRegex(
  201. "^([0-9][0-9])\\.([0-9])[0-9](\\.|$)");
  202. if (versionToolsetRegex.find(versionToolset)) {
  203. versionToolset = cmStrCat('v', versionToolsetRegex.match(1),
  204. versionToolsetRegex.match(2));
  205. // Hard-code special cases for toolset versions whose first
  206. // three digits do not match their toolset name.
  207. // 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. " ", auxProps, "\n",
  277. "The toolset and version specification must resolve \n"
  278. "to a single installed toolset"));
  279. // Clear the configured tool-set
  280. this->GeneratorToolsetVersion.clear();
  281. this->GeneratorToolsetVersionProps = {};
  282. } break;
  283. }
  284. }
  285. if (const char* toolset = this->GetPlatformToolset()) {
  286. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET", toolset);
  287. }
  288. if (!this->GeneratorToolsetVersion.empty()) {
  289. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VERSION",
  290. this->GeneratorToolsetVersion);
  291. }
  292. if (const char* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  293. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE", hostArch);
  294. }
  295. if (const char* cuda = this->GetPlatformToolsetCuda()) {
  296. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA", cuda);
  297. }
  298. if (const char* cudaDir = this->GetPlatformToolsetCudaCustomDir()) {
  299. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR", cudaDir);
  300. }
  301. if (cm::optional<std::string> fortran = this->GetPlatformToolsetFortran()) {
  302. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_FORTRAN", *fortran);
  303. }
  304. if (const char* vcTargetsDir = this->GetCustomVCTargetsPath()) {
  305. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VCTARGETS_CUSTOM_DIR",
  306. vcTargetsDir);
  307. }
  308. return true;
  309. }
  310. bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset(
  311. std::string const& ts, cmMakefile* mf)
  312. {
  313. std::vector<std::string> const fields =
  314. cmTokenize(ts, ',', cmTokenizerMode::New);
  315. if (fields.empty()) {
  316. return true;
  317. }
  318. auto fi = fields.begin();
  319. // The first field may be the VS platform toolset.
  320. if (fi->find('=') == fi->npos) {
  321. this->GeneratorToolset = *fi;
  322. ++fi;
  323. }
  324. std::set<std::string> handled;
  325. // The rest of the fields must be key=value pairs.
  326. for (; fi != fields.end(); ++fi) {
  327. std::string::size_type pos = fi->find('=');
  328. if (pos == fi->npos) {
  329. mf->IssueMessage(
  330. MessageType::FATAL_ERROR,
  331. cmStrCat("Generator\n"
  332. " ",
  333. this->GetName(),
  334. "\n"
  335. "given toolset specification\n"
  336. " ",
  337. ts,
  338. "\n"
  339. "that contains a field after the first ',' with no '='."));
  340. return false;
  341. }
  342. std::string const key = fi->substr(0, pos);
  343. std::string const value = fi->substr(pos + 1);
  344. if (!handled.insert(key).second) {
  345. mf->IssueMessage(MessageType::FATAL_ERROR,
  346. cmStrCat("Generator\n"
  347. " ",
  348. this->GetName(),
  349. "\n"
  350. "given toolset specification\n"
  351. " ",
  352. ts,
  353. "\n"
  354. "that contains duplicate field key '",
  355. key, "'."));
  356. return false;
  357. }
  358. if (!this->ProcessGeneratorToolsetField(key, value)) {
  359. mf->IssueMessage(MessageType::FATAL_ERROR,
  360. cmStrCat("Generator\n"
  361. " ",
  362. this->GetName(),
  363. "\n"
  364. "given toolset specification\n"
  365. " ",
  366. ts,
  367. "\n"
  368. "that contains invalid field '",
  369. *fi, "'."));
  370. return false;
  371. }
  372. }
  373. return true;
  374. }
  375. bool cmGlobalVisualStudio10Generator::ProcessGeneratorToolsetField(
  376. std::string const& key, std::string const& value)
  377. {
  378. if (key == "cuda"_s) {
  379. /* test if cuda toolset is path to custom dir or cuda version */
  380. auto pos = value.find_first_not_of("0123456789.");
  381. if (pos != std::string::npos) {
  382. this->GeneratorToolsetCudaCustomDir = value;
  383. /* ensure trailing backslash for easy path joining */
  384. if (this->GeneratorToolsetCudaCustomDir.back() != '\\') {
  385. this->GeneratorToolsetCudaCustomDir.push_back('\\');
  386. }
  387. /* check for legacy toolkit folder structure */
  388. if (cmsys::SystemTools::FileIsDirectory(
  389. cmStrCat(this->GeneratorToolsetCudaCustomDir, "nvcc"))) {
  390. this->GeneratorToolsetCudaNvccSubdir = "nvcc\\";
  391. }
  392. if (cmsys::SystemTools::FileIsDirectory(
  393. cmStrCat(this->GeneratorToolsetCudaCustomDir,
  394. "CUDAVisualStudioIntegration"))) {
  395. this->GeneratorToolsetCudaVSIntegrationSubdir =
  396. "CUDAVisualStudioIntegration\\";
  397. }
  398. } else {
  399. this->GeneratorToolsetCuda = value;
  400. }
  401. return true;
  402. }
  403. if (key == "customFlagTableDir"_s) {
  404. this->CustomFlagTableDir = value;
  405. cmSystemTools::ConvertToUnixSlashes(this->CustomFlagTableDir);
  406. return true;
  407. }
  408. if (key == "fortran"_s) {
  409. this->GeneratorToolsetFortran = value;
  410. return true;
  411. }
  412. if (key == "version"_s) {
  413. this->GeneratorToolsetVersion = value;
  414. return true;
  415. }
  416. if (key == "VCTargetsPath"_s) {
  417. this->CustomVCTargetsPath = value;
  418. ConvertToWindowsSlashes(this->CustomVCTargetsPath);
  419. return true;
  420. }
  421. return false;
  422. }
  423. bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf)
  424. {
  425. if (this->SystemName == "Windows"_s) {
  426. if (!this->InitializeWindows(mf)) {
  427. return false;
  428. }
  429. } else if (this->SystemName == "WindowsCE"_s) {
  430. this->SystemIsWindowsCE = true;
  431. if (!this->InitializeWindowsCE(mf)) {
  432. return false;
  433. }
  434. } else if (this->SystemName == "WindowsPhone"_s) {
  435. this->SystemIsWindowsPhone = true;
  436. if (!this->InitializeWindowsPhone(mf)) {
  437. return false;
  438. }
  439. } else if (this->SystemName == "WindowsStore"_s) {
  440. this->SystemIsWindowsStore = true;
  441. if (!this->InitializeWindowsStore(mf)) {
  442. return false;
  443. }
  444. } else if (this->SystemName == "Android"_s) {
  445. if (this->PlatformInGeneratorName) {
  446. mf->IssueMessage(
  447. MessageType::FATAL_ERROR,
  448. cmStrCat("CMAKE_SYSTEM_NAME is 'Android' but CMAKE_GENERATOR ",
  449. "specifies a platform too: '", this->GetName(), '\''));
  450. return false;
  451. }
  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* mf)
  471. {
  472. if (this->PlatformInGeneratorName) {
  473. mf->IssueMessage(
  474. MessageType::FATAL_ERROR,
  475. cmStrCat("CMAKE_SYSTEM_NAME is 'WindowsCE' but CMAKE_GENERATOR ",
  476. "specifies a platform too: '", this->GetName(), '\''));
  477. return false;
  478. }
  479. this->DefaultPlatformToolset = this->SelectWindowsCEToolset();
  480. return true;
  481. }
  482. bool cmGlobalVisualStudio10Generator::InitializeWindowsPhone(cmMakefile* mf)
  483. {
  484. mf->IssueMessage(
  485. MessageType::FATAL_ERROR,
  486. cmStrCat(this->GetName(), " does not support Windows Phone."));
  487. return false;
  488. }
  489. bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf)
  490. {
  491. mf->IssueMessage(
  492. MessageType::FATAL_ERROR,
  493. cmStrCat(this->GetName(), " does not support Windows Store."));
  494. return false;
  495. }
  496. bool cmGlobalVisualStudio10Generator::InitializeTegraAndroid(cmMakefile* mf)
  497. {
  498. std::string v =
  499. cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion();
  500. if (v.empty()) {
  501. mf->IssueMessage(MessageType::FATAL_ERROR,
  502. "CMAKE_SYSTEM_NAME is 'Android' but "
  503. "'NVIDIA Nsight Tegra Visual Studio Edition' "
  504. "is not installed.");
  505. return false;
  506. }
  507. this->DefaultPlatformName = "Tegra-Android";
  508. this->DefaultPlatformToolset = "Default";
  509. this->NsightTegraVersion = v;
  510. mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v);
  511. return true;
  512. }
  513. bool cmGlobalVisualStudio10Generator::InitializeAndroid(cmMakefile* mf)
  514. {
  515. mf->IssueMessage(MessageType::FATAL_ERROR,
  516. cmStrCat(this->GetName(), " does not support Android."));
  517. return false;
  518. }
  519. bool cmGlobalVisualStudio10Generator::InitializePlatform(cmMakefile* mf)
  520. {
  521. if (this->SystemName == "Windows"_s ||
  522. this->SystemName == "WindowsStore"_s) {
  523. if (!this->InitializePlatformWindows(mf)) {
  524. return false;
  525. }
  526. } else if (!this->SystemName.empty() &&
  527. !this->VerifyNoGeneratorPlatformVersion(mf)) {
  528. return false;
  529. }
  530. return this->cmGlobalVisualStudio8Generator::InitializePlatform(mf);
  531. }
  532. bool cmGlobalVisualStudio10Generator::InitializePlatformWindows(cmMakefile*)
  533. {
  534. return true;
  535. }
  536. bool cmGlobalVisualStudio10Generator::VerifyNoGeneratorPlatformVersion(
  537. cmMakefile*) const
  538. {
  539. return true;
  540. }
  541. bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
  542. std::string& toolset) const
  543. {
  544. toolset.clear();
  545. return false;
  546. }
  547. bool cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset(
  548. std::string& toolset) const
  549. {
  550. toolset.clear();
  551. return false;
  552. }
  553. std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const
  554. {
  555. if (this->SystemVersion == "8.0"_s) {
  556. return "CE800";
  557. }
  558. return "";
  559. }
  560. //! Create a local generator appropriate to this Global Generator
  561. std::unique_ptr<cmLocalGenerator>
  562. cmGlobalVisualStudio10Generator::CreateLocalGenerator(cmMakefile* mf)
  563. {
  564. return std::unique_ptr<cmLocalGenerator>(
  565. cm::make_unique<cmLocalVisualStudio10Generator>(this, mf));
  566. }
  567. void cmGlobalVisualStudio10Generator::Generate()
  568. {
  569. this->LongestSource = LongestSourcePath();
  570. this->cmGlobalVisualStudio8Generator::Generate();
  571. if (!this->AndroidExecutableWarnings.empty() &&
  572. !this->CMakeInstance->GetIsInTryCompile()) {
  573. std::ostringstream e;
  574. /* clang-format off */
  575. e <<
  576. "You are using Visual Studio tools for Android, which does not support "
  577. "standalone executables. However, the following executable targets do "
  578. "not have the ANDROID_GUI property set, and thus will not be built as "
  579. "expected. They will be built as shared libraries with executable "
  580. "filenames:\n"
  581. " ";
  582. /* clang-format on */
  583. bool first = true;
  584. for (auto const& name : this->AndroidExecutableWarnings) {
  585. if (!first) {
  586. e << ", ";
  587. }
  588. first = false;
  589. e << name;
  590. }
  591. this->CMakeInstance->IssueMessage(MessageType::WARNING, e.str());
  592. }
  593. if (this->LongestSource.Length > 0) {
  594. cmLocalGenerator* lg = this->LongestSource.Target->GetLocalGenerator();
  595. lg->IssueMessage(
  596. MessageType::WARNING,
  597. cmStrCat(
  598. "The binary and/or source directory paths may be too long to generate "
  599. "Visual Studio 10 files for this project. "
  600. "Consider choosing shorter directory names to build this project with "
  601. "Visual Studio 10. "
  602. "A more detailed explanation follows."
  603. "\n"
  604. "There is a bug in the VS 10 IDE that renders property dialog fields "
  605. "blank for files referenced by full path in the project file. "
  606. "However, CMake must reference at least one file by full path:\n"
  607. " ",
  608. this->LongestSource.SourceFile->GetFullPath(),
  609. "\n"
  610. "This is because some Visual Studio tools would append the relative "
  611. "path to the end of the referencing directory path, as in:\n"
  612. " ",
  613. lg->GetCurrentBinaryDirectory(), '/', this->LongestSource.SourceRel,
  614. "\n"
  615. "and then incorrectly complain that the file does not exist because "
  616. "the path length is too long for some internal buffer or API. "
  617. "To avoid this problem CMake must use a full path for this file "
  618. "which then triggers the VS 10 property dialog bug."));
  619. }
  620. if (cmValue cached = this->CMakeInstance->GetState()->GetCacheEntryValue(
  621. "CMAKE_VS_NUGET_PACKAGE_RESTORE")) {
  622. this->CMakeInstance->MarkCliAsUsed("CMAKE_VS_NUGET_PACKAGE_RESTORE");
  623. }
  624. }
  625. void cmGlobalVisualStudio10Generator::EnableLanguage(
  626. std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
  627. {
  628. for (std::string const& it : lang) {
  629. if (it == "ASM_NASM"_s) {
  630. this->NasmEnabled = true;
  631. }
  632. if (it == "CUDA"_s) {
  633. this->CudaEnabled = true;
  634. }
  635. }
  636. this->AddPlatformDefinitions(mf);
  637. cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
  638. }
  639. const char* cmGlobalVisualStudio10Generator::GetCustomVCTargetsPath() const
  640. {
  641. if (this->CustomVCTargetsPath.empty()) {
  642. return nullptr;
  643. }
  644. return this->CustomVCTargetsPath.c_str();
  645. }
  646. const char* cmGlobalVisualStudio10Generator::GetPlatformToolset() const
  647. {
  648. std::string const& toolset = this->GetPlatformToolsetString();
  649. if (toolset.empty()) {
  650. return nullptr;
  651. }
  652. return toolset.c_str();
  653. }
  654. std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString()
  655. const
  656. {
  657. if (!this->GeneratorToolset.empty()) {
  658. return this->GeneratorToolset;
  659. }
  660. if (this->SystemIsAndroid) {
  661. if (!this->DefaultAndroidToolset.empty()) {
  662. return this->DefaultAndroidToolset;
  663. }
  664. } else {
  665. if (!this->DefaultPlatformToolset.empty()) {
  666. return this->DefaultPlatformToolset;
  667. }
  668. }
  669. static std::string const empty;
  670. return empty;
  671. }
  672. std::string const&
  673. cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionProps() const
  674. {
  675. return this->GeneratorToolsetVersionProps;
  676. }
  677. const char*
  678. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const
  679. {
  680. std::string const& hostArch =
  681. this->GetPlatformToolsetHostArchitectureString();
  682. if (hostArch.empty()) {
  683. return nullptr;
  684. }
  685. return hostArch.c_str();
  686. }
  687. std::string const&
  688. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitectureString()
  689. const
  690. {
  691. if (!this->GeneratorToolsetHostArchitecture.empty()) {
  692. return this->GeneratorToolsetHostArchitecture;
  693. }
  694. if (!this->DefaultPlatformToolsetHostArchitecture.empty()) {
  695. return this->DefaultPlatformToolsetHostArchitecture;
  696. }
  697. static std::string const empty;
  698. return empty;
  699. }
  700. const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
  701. {
  702. if (!this->GeneratorToolsetCuda.empty()) {
  703. return this->GeneratorToolsetCuda.c_str();
  704. }
  705. return nullptr;
  706. }
  707. std::string const&
  708. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaString() const
  709. {
  710. return this->GeneratorToolsetCuda;
  711. }
  712. const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDir()
  713. const
  714. {
  715. if (!this->GeneratorToolsetCudaCustomDir.empty()) {
  716. return this->GeneratorToolsetCudaCustomDir.c_str();
  717. }
  718. return nullptr;
  719. }
  720. std::string const&
  721. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDirString() const
  722. {
  723. return this->GeneratorToolsetCudaCustomDir;
  724. }
  725. std::string const&
  726. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaNvccSubdirString() const
  727. {
  728. return this->GeneratorToolsetCudaNvccSubdir;
  729. }
  730. std::string const& cmGlobalVisualStudio10Generator::
  731. GetPlatformToolsetCudaVSIntegrationSubdirString() const
  732. {
  733. return this->GeneratorToolsetCudaVSIntegrationSubdir;
  734. }
  735. cmGlobalVisualStudio10Generator::AuxToolset
  736. cmGlobalVisualStudio10Generator::FindAuxToolset(std::string&,
  737. std::string&) const
  738. {
  739. return AuxToolset::None;
  740. }
  741. bool cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf)
  742. {
  743. if (!this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf)) {
  744. return false;
  745. }
  746. mf->AddDefinition("CMAKE_VS_MSBUILD_COMMAND", this->GetMSBuildCommand());
  747. return true;
  748. }
  749. std::string const& cmGlobalVisualStudio10Generator::GetMSBuildCommand()
  750. {
  751. if (!this->MSBuildCommandInitialized) {
  752. this->MSBuildCommandInitialized = true;
  753. this->MSBuildCommand = this->FindMSBuildCommand();
  754. }
  755. return this->MSBuildCommand;
  756. }
  757. cm::optional<std::string>
  758. cmGlobalVisualStudio10Generator::FindMSBuildCommandEarly(cmMakefile*)
  759. {
  760. return this->GetMSBuildCommand();
  761. }
  762. std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand()
  763. {
  764. std::string msbuild;
  765. std::string mskey;
  766. // Search in standard location.
  767. mskey =
  768. cmStrCat(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\)",
  769. this->GetToolsVersion(), ";MSBuildToolsPath");
  770. if (cmSystemTools::ReadRegistryValue(mskey, msbuild,
  771. cmSystemTools::KeyWOW64_32)) {
  772. cmSystemTools::ConvertToUnixSlashes(msbuild);
  773. msbuild += "/MSBuild.exe";
  774. if (cmSystemTools::FileExists(msbuild, true)) {
  775. return msbuild;
  776. }
  777. }
  778. msbuild = "MSBuild.exe";
  779. return msbuild;
  780. }
  781. std::string cmGlobalVisualStudio10Generator::FindDevEnvCommand()
  782. {
  783. if (this->ExpressEdition) {
  784. // Visual Studio Express >= 10 do not have "devenv.com" or
  785. // "VCExpress.exe" that we can use to build reliably.
  786. // Tell the caller it needs to use MSBuild instead.
  787. return "";
  788. }
  789. // Skip over the cmGlobalVisualStudio8Generator implementation because
  790. // we expect a real devenv and do not want to look for VCExpress.
  791. // NOLINTNEXTLINE(bugprone-parent-virtual-call)
  792. return this->cmGlobalVisualStudio71Generator::FindDevEnvCommand();
  793. }
  794. bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
  795. {
  796. // Skip this in special cases within our own test suite.
  797. if (this->GetPlatformName() == "Test Platform"_s ||
  798. this->GetPlatformToolsetString() == "Test Toolset"_s) {
  799. return true;
  800. }
  801. std::string wd;
  802. if (!this->ConfiguredFilesPath.empty()) {
  803. // In a try-compile we are given the outer CMakeFiles directory.
  804. wd = this->ConfiguredFilesPath;
  805. } else {
  806. wd = cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(),
  807. "/CMakeFiles");
  808. }
  809. wd += '/';
  810. wd += cmVersion::GetCMakeVersion();
  811. // We record the result persistently in a file.
  812. std::string const txt = cmStrCat(wd, "/VCTargetsPath.txt");
  813. // If we have a recorded result, use it.
  814. {
  815. cmsys::ifstream fin(txt.c_str());
  816. if (fin && cmSystemTools::GetLineFromStream(fin, this->VCTargetsPath) &&
  817. cmSystemTools::FileIsDirectory(this->VCTargetsPath)) {
  818. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  819. return true;
  820. }
  821. }
  822. // Prepare the work directory.
  823. if (!cmSystemTools::MakeDirectory(wd)) {
  824. mf->IssueMessage(MessageType::FATAL_ERROR,
  825. cmStrCat("Failed to make directory:\n ", wd));
  826. cmSystemTools::SetFatalErrorOccurred();
  827. return false;
  828. }
  829. // Generate a project file for MSBuild to tell us the VCTargetsPath value.
  830. std::string const vcxproj = "VCTargetsPath.vcxproj";
  831. {
  832. std::string const vcxprojAbs = cmStrCat(wd, '/', vcxproj);
  833. cmsys::ofstream fout(vcxprojAbs.c_str());
  834. cmXMLWriter xw(fout);
  835. cmXMLDocument doc(xw);
  836. cmXMLElement eprj(doc, "Project");
  837. eprj.Attribute("DefaultTargets", "Build");
  838. eprj.Attribute("ToolsVersion", "4.0");
  839. eprj.Attribute("xmlns",
  840. "http://schemas.microsoft.com/developer/msbuild/2003");
  841. if (this->IsNsightTegra()) {
  842. cmXMLElement epg(eprj, "PropertyGroup");
  843. epg.Attribute("Label", "NsightTegraProject");
  844. cmXMLElement(epg, "NsightTegraProjectRevisionNumber").Content("6");
  845. }
  846. {
  847. cmXMLElement eig(eprj, "ItemGroup");
  848. eig.Attribute("Label", "ProjectConfigurations");
  849. cmXMLElement epc(eig, "ProjectConfiguration");
  850. epc.Attribute("Include", cmStrCat("Debug|", this->GetPlatformName()));
  851. cmXMLElement(epc, "Configuration").Content("Debug");
  852. cmXMLElement(epc, "Platform").Content(this->GetPlatformName());
  853. }
  854. {
  855. cmXMLElement epg(eprj, "PropertyGroup");
  856. epg.Attribute("Label", "Globals");
  857. cmXMLElement(epg, "ProjectGuid")
  858. .Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}");
  859. cmXMLElement(epg, "Keyword")
  860. .Content(mf->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Android"_s
  861. ? "Android"
  862. : "Win32Proj");
  863. cmXMLElement(epg, "Platform").Content(this->GetPlatformName());
  864. if (this->GetSystemName() == "WindowsPhone"_s) {
  865. cmXMLElement(epg, "ApplicationType").Content("Windows Phone");
  866. cmXMLElement(epg, "ApplicationTypeRevision")
  867. .Content(this->GetApplicationTypeRevision());
  868. } else if (this->GetSystemName() == "WindowsStore"_s) {
  869. cmXMLElement(epg, "ApplicationType").Content("Windows Store");
  870. cmXMLElement(epg, "ApplicationTypeRevision")
  871. .Content(this->GetApplicationTypeRevision());
  872. } else if (this->GetSystemName() == "Android"_s) {
  873. cmXMLElement(epg, "ApplicationType").Content("Android");
  874. cmXMLElement(epg, "ApplicationTypeRevision")
  875. .Content(this->GetApplicationTypeRevision());
  876. }
  877. if (!this->WindowsTargetPlatformVersion.empty()) {
  878. cmXMLElement(epg, "WindowsTargetPlatformVersion")
  879. .Content(this->WindowsTargetPlatformVersion);
  880. }
  881. if (this->GetSystemName() != "Android"_s) {
  882. if (this->GetPlatformName() == "ARM64"_s) {
  883. cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true");
  884. } else if (this->GetPlatformName() == "ARM"_s) {
  885. cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true");
  886. }
  887. }
  888. }
  889. cmXMLElement(eprj, "Import")
  890. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  891. if (const char* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  892. cmXMLElement epg(eprj, "PropertyGroup");
  893. cmXMLElement(epg, "PreferredToolArchitecture").Content(hostArch);
  894. }
  895. {
  896. cmXMLElement epg(eprj, "PropertyGroup");
  897. epg.Attribute("Label", "Configuration");
  898. {
  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. }
  907. cmXMLElement(epg, "CharacterSet").Content("MultiByte");
  908. if (this->IsNsightTegra()) {
  909. cmXMLElement(epg, "NdkToolchainVersion")
  910. .Content(this->GetPlatformToolsetString());
  911. } else {
  912. cmXMLElement(epg, "PlatformToolset")
  913. .Content(this->GetPlatformToolsetString());
  914. }
  915. }
  916. cmXMLElement(eprj, "Import")
  917. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  918. {
  919. cmXMLElement eidg(eprj, "ItemDefinitionGroup");
  920. cmXMLElement epbe(eidg, "PostBuildEvent");
  921. cmXMLElement(epbe, "Command")
  922. .Content("echo VCTargetsPath=$(VCTargetsPath)");
  923. }
  924. cmXMLElement(eprj, "Import")
  925. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  926. }
  927. std::vector<std::string> cmd;
  928. cmd.push_back(this->GetMSBuildCommand());
  929. cmd.push_back(vcxproj);
  930. cmd.emplace_back("/p:Configuration=Debug");
  931. cmd.emplace_back(cmStrCat("/p:Platform=", this->GetPlatformName()));
  932. cmd.emplace_back(cmStrCat("/p:VisualStudioVersion=", this->GetIDEVersion()));
  933. std::string out;
  934. int ret = 0;
  935. cmsys::RegularExpression regex("\n *VCTargetsPath=([^%\r\n]+)[\r\n]");
  936. if (!cmSystemTools::RunSingleCommand(cmd, &out, &out, &ret, wd.c_str(),
  937. cmSystemTools::OUTPUT_NONE) ||
  938. ret != 0 || !regex.find(out)) {
  939. cmSystemTools::ReplaceString(out, "\n", "\n ");
  940. std::ostringstream e;
  941. /* clang-format off */
  942. e <<
  943. "Failed to run MSBuild command:\n"
  944. " " << cmd[0] << "\n"
  945. "to get the value of VCTargetsPath:\n"
  946. " " << out << "\n"
  947. ;
  948. /* clang-format on */
  949. if (ret != 0) {
  950. e << "Exit code: " << ret << "\n";
  951. }
  952. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  953. cmSystemTools::SetFatalErrorOccurred();
  954. return false;
  955. }
  956. this->VCTargetsPath = regex.match(1);
  957. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  958. {
  959. cmsys::ofstream fout(txt.c_str());
  960. fout << this->VCTargetsPath << "\n";
  961. }
  962. return true;
  963. }
  964. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  965. cmGlobalVisualStudio10Generator::GenerateBuildCommand(
  966. const std::string& makeProgram, const std::string& projectName,
  967. const std::string& projectDir, std::vector<std::string> const& targetNames,
  968. const std::string& config, int jobs, bool verbose,
  969. const cmBuildOptions& buildOptions,
  970. 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. const bool 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 (const auto& 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:", std::to_string(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. const char* 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, const char* 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. const char* 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. std::string cmGlobalVisualStudio10Generator::GetClFlagTableName() const
  1433. {
  1434. std::string const& toolset = this->GetPlatformToolsetString();
  1435. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1436. if (toolset == "v142"_s) {
  1437. return "v142";
  1438. }
  1439. if (toolset == "v141"_s) {
  1440. return "v141";
  1441. }
  1442. if (useToolset == "v140"_s) {
  1443. return "v140";
  1444. }
  1445. if (useToolset == "v120"_s) {
  1446. return "v12";
  1447. }
  1448. if (useToolset == "v110"_s) {
  1449. return "v11";
  1450. }
  1451. if (useToolset == "v100"_s) {
  1452. return "v10";
  1453. }
  1454. return "";
  1455. }
  1456. std::string cmGlobalVisualStudio10Generator::GetCSharpFlagTableName() const
  1457. {
  1458. std::string const& toolset = this->GetPlatformToolsetString();
  1459. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1460. if (useToolset == "v142"_s) {
  1461. return "v142";
  1462. }
  1463. if (useToolset == "v141"_s) {
  1464. return "v141";
  1465. }
  1466. if (useToolset == "v140"_s) {
  1467. return "v140";
  1468. }
  1469. if (useToolset == "v120"_s) {
  1470. return "v12";
  1471. }
  1472. if (useToolset == "v110"_s) {
  1473. return "v11";
  1474. }
  1475. if (useToolset == "v100"_s) {
  1476. return "v10";
  1477. }
  1478. return "";
  1479. }
  1480. std::string cmGlobalVisualStudio10Generator::GetRcFlagTableName() const
  1481. {
  1482. std::string const& toolset = this->GetPlatformToolsetString();
  1483. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1484. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1485. (useToolset == "v142"_s)) {
  1486. return "v14";
  1487. }
  1488. if (useToolset == "v120"_s) {
  1489. return "v12";
  1490. }
  1491. if (useToolset == "v110"_s) {
  1492. return "v11";
  1493. }
  1494. if (useToolset == "v100"_s) {
  1495. return "v10";
  1496. }
  1497. return "";
  1498. }
  1499. std::string cmGlobalVisualStudio10Generator::GetLibFlagTableName() const
  1500. {
  1501. std::string const& toolset = this->GetPlatformToolsetString();
  1502. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1503. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1504. (useToolset == "v142"_s)) {
  1505. return "v14";
  1506. }
  1507. if (useToolset == "v120"_s) {
  1508. return "v12";
  1509. }
  1510. if (useToolset == "v110"_s) {
  1511. return "v11";
  1512. }
  1513. if (useToolset == "v100"_s) {
  1514. return "v10";
  1515. }
  1516. return "";
  1517. }
  1518. std::string cmGlobalVisualStudio10Generator::GetLinkFlagTableName() const
  1519. {
  1520. std::string const& toolset = this->GetPlatformToolsetString();
  1521. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1522. if (useToolset == "v142"_s) {
  1523. return "v142";
  1524. }
  1525. if (useToolset == "v141"_s) {
  1526. return "v141";
  1527. }
  1528. if (useToolset == "v140"_s) {
  1529. return "v140";
  1530. }
  1531. if (useToolset == "v120"_s) {
  1532. return "v12";
  1533. }
  1534. if (useToolset == "v110"_s) {
  1535. return "v11";
  1536. }
  1537. if (useToolset == "v100"_s) {
  1538. return "v10";
  1539. }
  1540. return "";
  1541. }
  1542. std::string cmGlobalVisualStudio10Generator::GetMasmFlagTableName() const
  1543. {
  1544. std::string const& toolset = this->GetPlatformToolsetString();
  1545. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1546. if ((useToolset == "v140"_s) || (useToolset == "v141"_s) ||
  1547. (useToolset == "v142"_s)) {
  1548. return "v14";
  1549. }
  1550. if (useToolset == "v120"_s) {
  1551. return "v12";
  1552. }
  1553. if (useToolset == "v110"_s) {
  1554. return "v11";
  1555. }
  1556. if (useToolset == "v100"_s) {
  1557. return "v10";
  1558. }
  1559. return "";
  1560. }
  1561. std::string cmGlobalVisualStudio10Generator::CanonicalToolsetName(
  1562. std::string const& toolset) const
  1563. {
  1564. std::size_t length = toolset.length();
  1565. if (cmHasLiteralSuffix(toolset, "_xp")) {
  1566. length -= 3;
  1567. }
  1568. return toolset.substr(0, length);
  1569. }