cmGlobalVisualStudio10Generator.cxx 54 KB

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