cmGlobalVisualStudio10Generator.cxx 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  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::DataGroupAll)) {
  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. cm::optional<cmSlnProjectEntry> proj = cm::nullopt;
  1077. if (tname == "clean") {
  1078. makeCommand.Add(cmStrCat(projectName, ".sln"));
  1079. makeCommand.Add("/t:Clean");
  1080. } else {
  1081. std::string targetProject = cmStrCat(tname, ".vcxproj");
  1082. proj = slnData.GetProjectByName(tname);
  1083. if (targetProject.find('/') == std::string::npos) {
  1084. // it might be in a subdir
  1085. if (proj) {
  1086. targetProject = proj->GetRelativePath();
  1087. cmSystemTools::ConvertToUnixSlashes(targetProject);
  1088. }
  1089. }
  1090. makeCommand.Add(targetProject);
  1091. // Check if we do need a restore at all (i.e. if there are package
  1092. // references and restore has not been disabled by a command line option.
  1093. PackageResolveMode restoreMode = buildOptions.ResolveMode;
  1094. bool requiresRestore = true;
  1095. if (restoreMode == PackageResolveMode::Disable) {
  1096. requiresRestore = false;
  1097. } else if (cmValue cached =
  1098. this->CMakeInstance->GetState()->GetCacheEntryValue(
  1099. tname + "_REQUIRES_VS_PACKAGE_RESTORE")) {
  1100. requiresRestore = cached.IsOn();
  1101. } else {
  1102. // There are no package references defined.
  1103. requiresRestore = false;
  1104. }
  1105. // If a restore is required, evaluate the restore mode.
  1106. if (requiresRestore) {
  1107. if (restoreMode == PackageResolveMode::OnlyResolve) {
  1108. // Only invoke the restore target on the project.
  1109. makeCommand.Add("/t:Restore");
  1110. } else {
  1111. // Invoke restore target, unless it has been explicitly disabled.
  1112. bool restorePackages = true;
  1113. if (this->Version < VSVersion::VS15) {
  1114. // Package restore is only supported starting from Visual Studio
  1115. // 2017. Package restore must be executed manually using NuGet
  1116. // shell for older versions.
  1117. this->CMakeInstance->IssueMessage(
  1118. MessageType::WARNING,
  1119. "Restoring package references is only supported for Visual "
  1120. "Studio 2017 and later. You have to manually restore the "
  1121. "packages using NuGet before building the project.");
  1122. restorePackages = false;
  1123. } else if (restoreMode == PackageResolveMode::FromCacheVariable) {
  1124. // Decide if a restore is performed, based on a cache variable.
  1125. if (cmValue cached =
  1126. this->CMakeInstance->GetState()->GetCacheEntryValue(
  1127. "CMAKE_VS_NUGET_PACKAGE_RESTORE"))
  1128. restorePackages = cached.IsOn();
  1129. }
  1130. if (restorePackages) {
  1131. if (this->IsMsBuildRestoreSupported()) {
  1132. makeCommand.Add("/restore");
  1133. } else {
  1134. GeneratedMakeCommand restoreCommand;
  1135. restoreCommand.Add(makeProgramSelected);
  1136. restoreCommand.Add(targetProject);
  1137. restoreCommand.Add("/t:Restore");
  1138. makeCommands.emplace_back(restoreCommand);
  1139. }
  1140. }
  1141. }
  1142. }
  1143. }
  1144. std::string plainConfig = config;
  1145. if (config.empty()) {
  1146. plainConfig = "Debug";
  1147. }
  1148. std::string platform = GetPlatformName();
  1149. if (proj) {
  1150. std::string extension =
  1151. cmSystemTools::GetFilenameLastExtension(proj->GetRelativePath());
  1152. extension = cmSystemTools::LowerCase(extension);
  1153. if (extension.compare(".csproj") == 0) {
  1154. // Use correct platform name
  1155. platform =
  1156. slnData.GetConfigurationTarget(tname, plainConfig, platform);
  1157. }
  1158. }
  1159. makeCommand.Add(cmStrCat("/p:Configuration=", plainConfig));
  1160. makeCommand.Add(cmStrCat("/p:Platform=", platform));
  1161. makeCommand.Add(
  1162. cmStrCat("/p:VisualStudioVersion=", this->GetIDEVersion()));
  1163. if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
  1164. if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
  1165. makeCommand.Add("/m");
  1166. } else {
  1167. makeCommand.Add(cmStrCat("/m:", std::to_string(jobs)));
  1168. }
  1169. // Having msbuild.exe and cl.exe using multiple jobs is discouraged
  1170. makeCommand.Add("/p:CL_MPCount=1");
  1171. }
  1172. // Respect the verbosity: 'n' normal will show build commands
  1173. // 'm' minimal only the build step's title
  1174. makeCommand.Add(cmStrCat("/v:", ((verbose) ? "n" : "m")));
  1175. makeCommand.Add(makeOptions.begin(), makeOptions.end());
  1176. makeCommands.emplace_back(std::move(makeCommand));
  1177. }
  1178. return makeCommands;
  1179. }
  1180. bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
  1181. {
  1182. if (this->DefaultPlatformToolset == "v100") {
  1183. // The v100 64-bit toolset does not exist in the express edition.
  1184. this->DefaultPlatformToolset.clear();
  1185. }
  1186. if (this->GetPlatformToolset()) {
  1187. return true;
  1188. }
  1189. // This edition does not come with 64-bit tools. Look for them.
  1190. //
  1191. // TODO: Detect available tools? x64\v100 exists but does not work?
  1192. // HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0;VCTargetsPath
  1193. // c:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/Platforms/
  1194. // {Itanium,Win32,x64}/PlatformToolsets/{v100,v90,Windows7.1SDK}
  1195. std::string winSDK_7_1;
  1196. if (cmSystemTools::ReadRegistryValue(
  1197. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\"
  1198. "Windows\\v7.1;InstallationFolder",
  1199. winSDK_7_1)) {
  1200. std::ostringstream m;
  1201. m << "Found Windows SDK v7.1: " << winSDK_7_1;
  1202. mf->DisplayStatus(m.str(), -1);
  1203. this->DefaultPlatformToolset = "Windows7.1SDK";
  1204. return true;
  1205. } else {
  1206. std::ostringstream e;
  1207. /* clang-format off */
  1208. e << "Cannot enable 64-bit tools with Visual Studio 2010 Express.\n"
  1209. << "Install the Microsoft Windows SDK v7.1 to get 64-bit tools:\n"
  1210. << " http://msdn.microsoft.com/en-us/windows/bb980924.aspx";
  1211. /* clang-format on */
  1212. mf->IssueMessage(MessageType::FATAL_ERROR, e.str().c_str());
  1213. cmSystemTools::SetFatalErrorOccured();
  1214. return false;
  1215. }
  1216. }
  1217. std::string cmGlobalVisualStudio10Generator::GenerateRuleFile(
  1218. std::string const& output) const
  1219. {
  1220. // The VS 10 generator needs to create the .rule files on disk.
  1221. // Hide them away under the CMakeFiles directory.
  1222. std::string ruleDir = cmStrCat(
  1223. this->GetCMakeInstance()->GetHomeOutputDirectory(), "/CMakeFiles/",
  1224. cmSystemTools::ComputeStringMD5(cmSystemTools::GetFilenamePath(output)));
  1225. std::string ruleFile =
  1226. cmStrCat(ruleDir, '/', cmSystemTools::GetFilenameName(output), ".rule");
  1227. return ruleFile;
  1228. }
  1229. void cmGlobalVisualStudio10Generator::PathTooLong(cmGeneratorTarget* target,
  1230. cmSourceFile const* sf,
  1231. std::string const& sfRel)
  1232. {
  1233. size_t len =
  1234. (target->GetLocalGenerator()->GetCurrentBinaryDirectory().length() + 1 +
  1235. sfRel.length());
  1236. if (len > this->LongestSource.Length) {
  1237. this->LongestSource.Length = len;
  1238. this->LongestSource.Target = target;
  1239. this->LongestSource.SourceFile = sf;
  1240. this->LongestSource.SourceRel = sfRel;
  1241. }
  1242. }
  1243. std::string cmGlobalVisualStudio10Generator::Encoding()
  1244. {
  1245. return "utf-8";
  1246. }
  1247. const char* cmGlobalVisualStudio10Generator::GetToolsVersion() const
  1248. {
  1249. switch (this->Version) {
  1250. case cmGlobalVisualStudioGenerator::VSVersion::VS9:
  1251. case cmGlobalVisualStudioGenerator::VSVersion::VS10:
  1252. case cmGlobalVisualStudioGenerator::VSVersion::VS11:
  1253. return "4.0";
  1254. // in Visual Studio 2013 they detached the MSBuild tools version
  1255. // from the .Net Framework version and instead made it have it's own
  1256. // version number
  1257. case cmGlobalVisualStudioGenerator::VSVersion::VS12:
  1258. return "12.0";
  1259. case cmGlobalVisualStudioGenerator::VSVersion::VS14:
  1260. return "14.0";
  1261. case cmGlobalVisualStudioGenerator::VSVersion::VS15:
  1262. return "15.0";
  1263. case cmGlobalVisualStudioGenerator::VSVersion::VS16:
  1264. return "16.0";
  1265. case cmGlobalVisualStudioGenerator::VSVersion::VS17:
  1266. return "17.0";
  1267. }
  1268. return "";
  1269. }
  1270. bool cmGlobalVisualStudio10Generator::IsNsightTegra() const
  1271. {
  1272. return !this->NsightTegraVersion.empty();
  1273. }
  1274. std::string cmGlobalVisualStudio10Generator::GetNsightTegraVersion() const
  1275. {
  1276. return this->NsightTegraVersion;
  1277. }
  1278. std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
  1279. {
  1280. std::string version;
  1281. cmSystemTools::ReadRegistryValue(
  1282. "HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;"
  1283. "Version",
  1284. version, cmSystemTools::KeyWOW64_32);
  1285. return version;
  1286. }
  1287. std::string cmGlobalVisualStudio10Generator::GetApplicationTypeRevision() const
  1288. {
  1289. if (this->GetSystemName() == "Android") {
  1290. return this->GetAndroidApplicationTypeRevision();
  1291. }
  1292. // Return the first two '.'-separated components of the Windows version.
  1293. std::string::size_type end1 = this->SystemVersion.find('.');
  1294. std::string::size_type end2 =
  1295. end1 == std::string::npos ? end1 : this->SystemVersion.find('.', end1 + 1);
  1296. return this->SystemVersion.substr(0, end2);
  1297. }
  1298. static std::string cmLoadFlagTableString(Json::Value entry, const char* field)
  1299. {
  1300. if (entry.isMember(field)) {
  1301. auto string = entry[field];
  1302. if (string.isConvertibleTo(Json::ValueType::stringValue)) {
  1303. return string.asString();
  1304. }
  1305. }
  1306. return "";
  1307. }
  1308. static unsigned int cmLoadFlagTableSpecial(Json::Value entry,
  1309. const char* field)
  1310. {
  1311. unsigned int value = 0;
  1312. if (entry.isMember(field)) {
  1313. auto specials = entry[field];
  1314. if (specials.isArray()) {
  1315. for (auto const& special : specials) {
  1316. std::string s = special.asString();
  1317. if (s == "UserValue") {
  1318. value |= cmIDEFlagTable::UserValue;
  1319. } else if (s == "UserIgnored") {
  1320. value |= cmIDEFlagTable::UserIgnored;
  1321. } else if (s == "UserRequired") {
  1322. value |= cmIDEFlagTable::UserRequired;
  1323. } else if (s == "Continue") {
  1324. value |= cmIDEFlagTable::Continue;
  1325. } else if (s == "SemicolonAppendable") {
  1326. value |= cmIDEFlagTable::SemicolonAppendable;
  1327. } else if (s == "UserFollowing") {
  1328. value |= cmIDEFlagTable::UserFollowing;
  1329. } else if (s == "CaseInsensitive") {
  1330. value |= cmIDEFlagTable::CaseInsensitive;
  1331. } else if (s == "SpaceAppendable") {
  1332. value |= cmIDEFlagTable::SpaceAppendable;
  1333. } else if (s == "CommaAppendable") {
  1334. value |= cmIDEFlagTable::CommaAppendable;
  1335. }
  1336. }
  1337. }
  1338. }
  1339. return value;
  1340. }
  1341. namespace {
  1342. cmIDEFlagTable const* cmLoadFlagTableJson(std::string const& flagJsonPath,
  1343. cm::optional<std::string> vsVer)
  1344. {
  1345. cmIDEFlagTable* ret = nullptr;
  1346. auto savedFlagIterator = loadedFlagJsonFiles.find(flagJsonPath);
  1347. if (savedFlagIterator != loadedFlagJsonFiles.end()) {
  1348. ret = savedFlagIterator->second.data();
  1349. } else {
  1350. Json::Reader reader;
  1351. cmsys::ifstream stream;
  1352. stream.open(flagJsonPath.c_str(), std::ios_base::in);
  1353. if (stream) {
  1354. Json::Value flags;
  1355. if (reader.parse(stream, flags, false) && flags.isArray()) {
  1356. std::vector<cmIDEFlagTable> flagTable;
  1357. for (auto const& flag : flags) {
  1358. Json::Value const& vsminJson = flag["vsmin"];
  1359. if (vsminJson.isString()) {
  1360. std::string const& vsmin = vsminJson.asString();
  1361. if (!vsmin.empty()) {
  1362. if (!vsVer ||
  1363. cmSystemTools::VersionCompareGreater(vsmin, *vsVer)) {
  1364. continue;
  1365. }
  1366. }
  1367. }
  1368. cmIDEFlagTable flagEntry;
  1369. flagEntry.IDEName = cmLoadFlagTableString(flag, "name");
  1370. flagEntry.commandFlag = cmLoadFlagTableString(flag, "switch");
  1371. flagEntry.comment = cmLoadFlagTableString(flag, "comment");
  1372. flagEntry.value = cmLoadFlagTableString(flag, "value");
  1373. flagEntry.special = cmLoadFlagTableSpecial(flag, "flags");
  1374. flagTable.push_back(flagEntry);
  1375. }
  1376. cmIDEFlagTable endFlag{ "", "", "", "", 0 };
  1377. flagTable.push_back(endFlag);
  1378. loadedFlagJsonFiles[flagJsonPath] = flagTable;
  1379. ret = loadedFlagJsonFiles[flagJsonPath].data();
  1380. }
  1381. }
  1382. }
  1383. return ret;
  1384. }
  1385. }
  1386. cm::optional<std::string> cmGlobalVisualStudio10Generator::FindFlagTable(
  1387. cm::string_view toolsetName, cm::string_view table) const
  1388. {
  1389. if (!this->CustomFlagTableDir.empty()) {
  1390. std::string customFlagTableFile =
  1391. cmStrCat(this->CustomFlagTableDir, '/', this->GetPlatformName(), '_',
  1392. toolsetName, '_', table, ".json");
  1393. if (cmSystemTools::FileExists(customFlagTableFile)) {
  1394. return customFlagTableFile;
  1395. }
  1396. customFlagTableFile =
  1397. cmStrCat(this->CustomFlagTableDir, '/', this->GetPlatformName(), '_',
  1398. table, ".json");
  1399. if (cmSystemTools::FileExists(customFlagTableFile)) {
  1400. return customFlagTableFile;
  1401. }
  1402. }
  1403. std::string fullPath =
  1404. cmStrCat(cmSystemTools::GetCMakeRoot(), "/Templates/MSBuild/FlagTables/",
  1405. toolsetName, '_', table, ".json");
  1406. if (cmSystemTools::FileExists(fullPath)) {
  1407. return fullPath;
  1408. }
  1409. return {};
  1410. }
  1411. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable(
  1412. std::string const& toolSpecificName, std::string const& defaultName,
  1413. std::string const& table) const
  1414. {
  1415. cmMakefile* mf = this->GetCurrentMakefile();
  1416. std::string filename;
  1417. if (!toolSpecificName.empty()) {
  1418. if (cm::optional<std::string> found =
  1419. this->FindFlagTable(toolSpecificName, table)) {
  1420. filename = std::move(*found);
  1421. } else {
  1422. mf->IssueMessage(MessageType::FATAL_ERROR,
  1423. cmStrCat("JSON flag table for ", table,
  1424. " not found for toolset ", toolSpecificName));
  1425. return nullptr;
  1426. }
  1427. } else {
  1428. std::string const& genericName =
  1429. this->CanonicalToolsetName(this->GetPlatformToolsetString());
  1430. cm::optional<std::string> found = this->FindFlagTable(genericName, table);
  1431. if (!found) {
  1432. found = this->FindFlagTable(defaultName, table);
  1433. }
  1434. if (found) {
  1435. filename = std::move(*found);
  1436. } else {
  1437. mf->IssueMessage(MessageType::FATAL_ERROR,
  1438. cmStrCat("JSON flag table for ", table,
  1439. " not found for toolset ", genericName, " ",
  1440. defaultName));
  1441. return nullptr;
  1442. }
  1443. }
  1444. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1445. if (cmIDEFlagTable const* ret = cmLoadFlagTableJson(filename, vsVer)) {
  1446. return ret;
  1447. }
  1448. mf->IssueMessage(
  1449. MessageType::FATAL_ERROR,
  1450. cmStrCat("JSON flag table could not be loaded:\n ", filename));
  1451. return nullptr;
  1452. }
  1453. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const
  1454. {
  1455. return LoadFlagTable(this->GetClFlagTableName(),
  1456. this->DefaultCLFlagTableName, "CL");
  1457. }
  1458. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable()
  1459. const
  1460. {
  1461. return LoadFlagTable(this->GetCSharpFlagTableName(),
  1462. this->DefaultCSharpFlagTableName, "CSharp");
  1463. }
  1464. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const
  1465. {
  1466. return LoadFlagTable(this->GetRcFlagTableName(),
  1467. this->DefaultRCFlagTableName, "RC");
  1468. }
  1469. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const
  1470. {
  1471. return LoadFlagTable(this->GetLibFlagTableName(),
  1472. this->DefaultLibFlagTableName, "LIB");
  1473. }
  1474. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const
  1475. {
  1476. return LoadFlagTable(this->GetLinkFlagTableName(),
  1477. this->DefaultLinkFlagTableName, "Link");
  1478. }
  1479. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaFlagTable() const
  1480. {
  1481. return LoadFlagTable(std::string(), this->DefaultCudaFlagTableName, "Cuda");
  1482. }
  1483. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaHostFlagTable()
  1484. const
  1485. {
  1486. return LoadFlagTable(std::string(), this->DefaultCudaHostFlagTableName,
  1487. "CudaHost");
  1488. }
  1489. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const
  1490. {
  1491. return LoadFlagTable(this->GetMasmFlagTableName(),
  1492. this->DefaultMasmFlagTableName, "MASM");
  1493. }
  1494. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const
  1495. {
  1496. return LoadFlagTable(std::string(), this->DefaultNasmFlagTableName, "NASM");
  1497. }
  1498. bool cmGlobalVisualStudio10Generator::IsMsBuildRestoreSupported() const
  1499. {
  1500. if (this->Version >= VSVersion::VS16) {
  1501. return true;
  1502. }
  1503. static std::string const vsVer15_7_5 = "15.7.27703.2042";
  1504. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1505. return (vsVer &&
  1506. cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer15_7_5));
  1507. }
  1508. std::string cmGlobalVisualStudio10Generator::GetClFlagTableName() const
  1509. {
  1510. std::string const& toolset = this->GetPlatformToolsetString();
  1511. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1512. if (toolset == "v142") {
  1513. return "v142";
  1514. } else if (toolset == "v141") {
  1515. return "v141";
  1516. } else if (useToolset == "v140") {
  1517. return "v140";
  1518. } else if (useToolset == "v120") {
  1519. return "v12";
  1520. } else if (useToolset == "v110") {
  1521. return "v11";
  1522. } else if (useToolset == "v100") {
  1523. return "v10";
  1524. } else {
  1525. return "";
  1526. }
  1527. }
  1528. std::string cmGlobalVisualStudio10Generator::GetCSharpFlagTableName() const
  1529. {
  1530. std::string const& toolset = this->GetPlatformToolsetString();
  1531. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1532. if (useToolset == "v142") {
  1533. return "v142";
  1534. } else if (useToolset == "v141") {
  1535. return "v141";
  1536. } else if (useToolset == "v140") {
  1537. return "v140";
  1538. } else if (useToolset == "v120") {
  1539. return "v12";
  1540. } else if (useToolset == "v110") {
  1541. return "v11";
  1542. } else if (useToolset == "v100") {
  1543. return "v10";
  1544. } else {
  1545. return "";
  1546. }
  1547. }
  1548. std::string cmGlobalVisualStudio10Generator::GetRcFlagTableName() const
  1549. {
  1550. std::string const& toolset = this->GetPlatformToolsetString();
  1551. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1552. if ((useToolset == "v140") || (useToolset == "v141") ||
  1553. (useToolset == "v142")) {
  1554. return "v14";
  1555. } else if (useToolset == "v120") {
  1556. return "v12";
  1557. } else if (useToolset == "v110") {
  1558. return "v11";
  1559. } else if (useToolset == "v100") {
  1560. return "v10";
  1561. } else {
  1562. return "";
  1563. }
  1564. }
  1565. std::string cmGlobalVisualStudio10Generator::GetLibFlagTableName() const
  1566. {
  1567. std::string const& toolset = this->GetPlatformToolsetString();
  1568. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1569. if ((useToolset == "v140") || (useToolset == "v141") ||
  1570. (useToolset == "v142")) {
  1571. return "v14";
  1572. } else if (useToolset == "v120") {
  1573. return "v12";
  1574. } else if (useToolset == "v110") {
  1575. return "v11";
  1576. } else if (useToolset == "v100") {
  1577. return "v10";
  1578. } else {
  1579. return "";
  1580. }
  1581. }
  1582. std::string cmGlobalVisualStudio10Generator::GetLinkFlagTableName() const
  1583. {
  1584. std::string const& toolset = this->GetPlatformToolsetString();
  1585. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1586. if (useToolset == "v142") {
  1587. return "v142";
  1588. } else if (useToolset == "v141") {
  1589. return "v141";
  1590. } else if (useToolset == "v140") {
  1591. return "v140";
  1592. } else if (useToolset == "v120") {
  1593. return "v12";
  1594. } else if (useToolset == "v110") {
  1595. return "v11";
  1596. } else if (useToolset == "v100") {
  1597. return "v10";
  1598. } else {
  1599. return "";
  1600. }
  1601. }
  1602. std::string cmGlobalVisualStudio10Generator::GetMasmFlagTableName() const
  1603. {
  1604. std::string const& toolset = this->GetPlatformToolsetString();
  1605. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1606. if ((useToolset == "v140") || (useToolset == "v141") ||
  1607. (useToolset == "v142")) {
  1608. return "v14";
  1609. } else if (useToolset == "v120") {
  1610. return "v12";
  1611. } else if (useToolset == "v110") {
  1612. return "v11";
  1613. } else if (useToolset == "v100") {
  1614. return "v10";
  1615. } else {
  1616. return "";
  1617. }
  1618. }
  1619. std::string cmGlobalVisualStudio10Generator::CanonicalToolsetName(
  1620. std::string const& toolset) const
  1621. {
  1622. std::size_t length = toolset.length();
  1623. if (cmHasLiteralSuffix(toolset, "_xp")) {
  1624. length -= 3;
  1625. }
  1626. return toolset.substr(0, length);
  1627. }