cmGlobalVisualStudio10Generator.cxx 57 KB

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