cmGlobalVisualStudio10Generator.cxx 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  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 "cmAlgorithms.h"
  5. #include "cmDocumentationEntry.h"
  6. #include "cmGeneratorTarget.h"
  7. #include "cmLocalVisualStudio10Generator.h"
  8. #include "cmMakefile.h"
  9. #include "cmSourceFile.h"
  10. #include "cmVersion.h"
  11. #include "cmVisualStudioSlnData.h"
  12. #include "cmVisualStudioSlnParser.h"
  13. #include "cmXMLWriter.h"
  14. #include "cm_jsoncpp_reader.h"
  15. #include "cmake.h"
  16. #include "cmsys/FStream.hxx"
  17. #include "cmsys/Glob.hxx"
  18. #include "cmsys/RegularExpression.hxx"
  19. #include <algorithm>
  20. static const char vs10generatorName[] = "Visual Studio 10 2010";
  21. static std::map<std::string, std::vector<cmIDEFlagTable>> loadedFlagJsonFiles;
  22. // Map generator name without year to name with year.
  23. static const char* cmVS10GenName(const std::string& name, std::string& genName)
  24. {
  25. if (strncmp(name.c_str(), vs10generatorName,
  26. sizeof(vs10generatorName) - 6) != 0) {
  27. return 0;
  28. }
  29. const char* p = name.c_str() + sizeof(vs10generatorName) - 6;
  30. if (cmHasLiteralPrefix(p, " 2010")) {
  31. p += 5;
  32. }
  33. genName = std::string(vs10generatorName) + p;
  34. return p;
  35. }
  36. class cmGlobalVisualStudio10Generator::Factory
  37. : public cmGlobalGeneratorFactory
  38. {
  39. public:
  40. cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
  41. cmake* cm) const override
  42. {
  43. std::string genName;
  44. const char* p = cmVS10GenName(name, genName);
  45. if (!p) {
  46. return 0;
  47. }
  48. if (!*p) {
  49. return new cmGlobalVisualStudio10Generator(cm, genName, "");
  50. }
  51. if (*p++ != ' ') {
  52. return 0;
  53. }
  54. if (strcmp(p, "Win64") == 0) {
  55. return new cmGlobalVisualStudio10Generator(cm, genName, "x64");
  56. }
  57. if (strcmp(p, "IA64") == 0) {
  58. return new cmGlobalVisualStudio10Generator(cm, genName, "Itanium");
  59. }
  60. return 0;
  61. }
  62. void GetDocumentation(cmDocumentationEntry& entry) const override
  63. {
  64. entry.Name = std::string(vs10generatorName) + " [arch]";
  65. entry.Brief = "Generates Visual Studio 2010 project files. "
  66. "Optional [arch] can be \"Win64\" or \"IA64\".";
  67. }
  68. void GetGenerators(std::vector<std::string>& names) const override
  69. {
  70. names.push_back(vs10generatorName);
  71. names.push_back(vs10generatorName + std::string(" IA64"));
  72. names.push_back(vs10generatorName + std::string(" Win64"));
  73. }
  74. bool SupportsToolset() const override { return true; }
  75. bool SupportsPlatform() const override { return true; }
  76. };
  77. cmGlobalGeneratorFactory* cmGlobalVisualStudio10Generator::NewFactory()
  78. {
  79. return new Factory;
  80. }
  81. cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator(
  82. cmake* cm, const std::string& name, const std::string& platformName)
  83. : cmGlobalVisualStudio8Generator(cm, name, platformName)
  84. {
  85. std::string vc10Express;
  86. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  87. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\10.0\\Setup\\VC;"
  88. "ProductDir",
  89. vc10Express, cmSystemTools::KeyWOW64_32);
  90. this->CudaEnabled = false;
  91. this->SystemIsWindowsCE = false;
  92. this->SystemIsWindowsPhone = false;
  93. this->SystemIsWindowsStore = false;
  94. this->MSBuildCommandInitialized = false;
  95. {
  96. std::string envPlatformToolset;
  97. if (cmSystemTools::GetEnv("PlatformToolset", envPlatformToolset) &&
  98. envPlatformToolset == "Windows7.1SDK") {
  99. // We are running from a Windows7.1SDK command prompt.
  100. this->DefaultPlatformToolset = "Windows7.1SDK";
  101. } else {
  102. this->DefaultPlatformToolset = "v100";
  103. }
  104. }
  105. this->DefaultCLFlagTableName = "v10";
  106. this->DefaultCSharpFlagTableName = "v10";
  107. this->DefaultLibFlagTableName = "v10";
  108. this->DefaultLinkFlagTableName = "v10";
  109. this->DefaultCudaFlagTableName = "v10";
  110. this->DefaultCudaHostFlagTableName = "v10";
  111. this->DefaultMasmFlagTableName = "v10";
  112. this->DefaultNasmFlagTableName = "v10";
  113. this->DefaultRCFlagTableName = "v10";
  114. this->Version = VS10;
  115. this->PlatformToolsetNeedsDebugEnum = false;
  116. }
  117. bool cmGlobalVisualStudio10Generator::MatchesGeneratorName(
  118. const std::string& name) const
  119. {
  120. std::string genName;
  121. if (cmVS10GenName(name, genName)) {
  122. return genName == this->GetName();
  123. }
  124. return false;
  125. }
  126. bool cmGlobalVisualStudio10Generator::SetSystemName(std::string const& s,
  127. cmMakefile* mf)
  128. {
  129. this->SystemName = s;
  130. this->SystemVersion = mf->GetSafeDefinition("CMAKE_SYSTEM_VERSION");
  131. if (!this->InitializeSystem(mf)) {
  132. return false;
  133. }
  134. return this->cmGlobalVisualStudio8Generator::SetSystemName(s, mf);
  135. }
  136. bool cmGlobalVisualStudio10Generator::SetGeneratorPlatform(
  137. std::string const& p, cmMakefile* mf)
  138. {
  139. if (!this->cmGlobalVisualStudio8Generator::SetGeneratorPlatform(p, mf)) {
  140. return false;
  141. }
  142. if (this->GetPlatformName() == "Itanium" ||
  143. this->GetPlatformName() == "x64") {
  144. if (this->IsExpressEdition() && !this->Find64BitTools(mf)) {
  145. return false;
  146. }
  147. }
  148. return true;
  149. }
  150. static void cmCudaToolVersion(std::string& s)
  151. {
  152. // "CUDA x.y.props" => "x.y"
  153. s = s.substr(5);
  154. s = s.substr(0, s.size() - 6);
  155. }
  156. bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
  157. std::string const& ts, cmMakefile* mf)
  158. {
  159. if (this->SystemIsWindowsCE && ts.empty() &&
  160. this->DefaultPlatformToolset.empty()) {
  161. std::ostringstream e;
  162. e << this->GetName() << " Windows CE version '" << this->SystemVersion
  163. << "' requires CMAKE_GENERATOR_TOOLSET to be set.";
  164. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  165. return false;
  166. }
  167. if (!this->ParseGeneratorToolset(ts, mf)) {
  168. return false;
  169. }
  170. if (!this->FindVCTargetsPath(mf)) {
  171. return false;
  172. }
  173. if (cmHasLiteralPrefix(this->GetPlatformToolsetString(), "v140")) {
  174. // The GenerateDebugInformation link setting for the v140 toolset
  175. // in VS 2015 was originally an enum with "No" and "Debug" values,
  176. // differing from the "false" and "true" values used in older toolsets.
  177. // A VS 2015 update changed it back. Parse the "link.xml" file to
  178. // discover which one we need.
  179. std::string const link_xml = this->VCTargetsPath + "/1033/link.xml";
  180. cmsys::ifstream fin(link_xml.c_str());
  181. std::string line;
  182. while (fin && cmSystemTools::GetLineFromStream(fin, line)) {
  183. if (line.find(" Switch=\"DEBUG\" ") != std::string::npos) {
  184. this->PlatformToolsetNeedsDebugEnum =
  185. line.find(" Name=\"Debug\" ") != std::string::npos;
  186. break;
  187. }
  188. }
  189. }
  190. if (this->GeneratorToolsetCuda.empty()) {
  191. // Find the highest available version of the CUDA tools.
  192. std::vector<std::string> cudaTools;
  193. std::string const bcDir = this->VCTargetsPath + "/BuildCustomizations";
  194. cmsys::Glob gl;
  195. gl.SetRelative(bcDir.c_str());
  196. if (gl.FindFiles(bcDir + "/CUDA *.props")) {
  197. cudaTools = gl.GetFiles();
  198. }
  199. if (!cudaTools.empty()) {
  200. std::for_each(cudaTools.begin(), cudaTools.end(), cmCudaToolVersion);
  201. std::sort(cudaTools.begin(), cudaTools.end(),
  202. cmSystemTools::VersionCompareGreater);
  203. this->GeneratorToolsetCuda = cudaTools.at(0);
  204. }
  205. }
  206. if (!this->GeneratorToolsetVersion.empty() &&
  207. this->GeneratorToolsetVersion != "Test Toolset Version") {
  208. // If a specific minor version of the toolset was requested, verify that it
  209. // is compatible to the major version and that is exists on disk.
  210. // If not clear the value.
  211. std::string version = this->GeneratorToolsetVersion;
  212. cmsys::RegularExpression regex("[0-9][0-9]\\.[0-9][0-9]");
  213. if (regex.find(version)) {
  214. version = "v" + version.erase(2, 1);
  215. } else {
  216. // Version not recognized. Clear it.
  217. version.clear();
  218. }
  219. if (version.find(this->GetPlatformToolsetString()) != 0) {
  220. std::ostringstream e;
  221. /* clang-format off */
  222. e <<
  223. "Generator\n"
  224. " " << this->GetName() << "\n"
  225. "given toolset and version specification\n"
  226. " " << this->GetPlatformToolsetString() << ",version=" <<
  227. this->GeneratorToolsetVersion << "\n"
  228. "contains an invalid version specification."
  229. ;
  230. /* clang-format on */
  231. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  232. // Clear the configured tool-set
  233. this->GeneratorToolsetVersion.clear();
  234. }
  235. bool const isDefaultToolset =
  236. this->IsDefaultToolset(this->GeneratorToolsetVersion);
  237. if (isDefaultToolset) {
  238. // If the given version is the default toolset, remove the setting
  239. this->GeneratorToolsetVersion.clear();
  240. } else {
  241. std::string const toolsetPath = this->GetAuxiliaryToolset();
  242. if (!toolsetPath.empty() && !cmSystemTools::FileExists(toolsetPath)) {
  243. std::ostringstream e;
  244. /* clang-format off */
  245. e <<
  246. "Generator\n"
  247. " " << this->GetName() << "\n"
  248. "given toolset and version specification\n"
  249. " " << this->GetPlatformToolsetString() << ",version=" <<
  250. this->GeneratorToolsetVersion << "\n"
  251. "does not seem to be installed at\n" <<
  252. " " << toolsetPath;
  253. ;
  254. /* clang-format on */
  255. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  256. // Clear the configured tool-set
  257. this->GeneratorToolsetVersion.clear();
  258. }
  259. }
  260. }
  261. if (const char* toolset = this->GetPlatformToolset()) {
  262. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET", toolset);
  263. }
  264. if (const char* version = this->GetPlatformToolsetVersion()) {
  265. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VERSION", version);
  266. }
  267. if (const char* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  268. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE", hostArch);
  269. }
  270. if (const char* cuda = this->GetPlatformToolsetCuda()) {
  271. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA", cuda);
  272. }
  273. return true;
  274. }
  275. bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset(
  276. std::string const& ts, cmMakefile* mf)
  277. {
  278. std::vector<std::string> const fields = cmSystemTools::tokenize(ts, ",");
  279. std::vector<std::string>::const_iterator fi = fields.begin();
  280. if (fi == fields.end()) {
  281. return true;
  282. }
  283. // The first field may be the VS platform toolset.
  284. if (fi->find('=') == fi->npos) {
  285. this->GeneratorToolset = *fi;
  286. ++fi;
  287. }
  288. std::set<std::string> handled;
  289. // The rest of the fields must be key=value pairs.
  290. for (; fi != fields.end(); ++fi) {
  291. std::string::size_type pos = fi->find('=');
  292. if (pos == fi->npos) {
  293. std::ostringstream e;
  294. /* clang-format off */
  295. e <<
  296. "Generator\n"
  297. " " << this->GetName() << "\n"
  298. "given toolset specification\n"
  299. " " << ts << "\n"
  300. "that contains a field after the first ',' with no '='."
  301. ;
  302. /* clang-format on */
  303. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  304. return false;
  305. }
  306. std::string const key = fi->substr(0, pos);
  307. std::string const value = fi->substr(pos + 1);
  308. if (!handled.insert(key).second) {
  309. std::ostringstream e;
  310. /* clang-format off */
  311. e <<
  312. "Generator\n"
  313. " " << this->GetName() << "\n"
  314. "given toolset specification\n"
  315. " " << ts << "\n"
  316. "that contains duplicate field key '" << key << "'."
  317. ;
  318. /* clang-format on */
  319. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  320. return false;
  321. }
  322. if (!this->ProcessGeneratorToolsetField(key, value)) {
  323. std::ostringstream e;
  324. /* clang-format off */
  325. e <<
  326. "Generator\n"
  327. " " << this->GetName() << "\n"
  328. "given toolset specification\n"
  329. " " << ts << "\n"
  330. "that contains invalid field '" << *fi << "'."
  331. ;
  332. /* clang-format on */
  333. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  334. return false;
  335. }
  336. }
  337. return true;
  338. }
  339. bool cmGlobalVisualStudio10Generator::ProcessGeneratorToolsetField(
  340. std::string const& key, std::string const& value)
  341. {
  342. if (key == "cuda") {
  343. this->GeneratorToolsetCuda = value;
  344. return true;
  345. }
  346. if (key == "version") {
  347. this->GeneratorToolsetVersion = value;
  348. return true;
  349. }
  350. return false;
  351. }
  352. bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf)
  353. {
  354. if (this->SystemName == "Windows") {
  355. if (!this->InitializeWindows(mf)) {
  356. return false;
  357. }
  358. } else if (this->SystemName == "WindowsCE") {
  359. this->SystemIsWindowsCE = true;
  360. if (!this->InitializeWindowsCE(mf)) {
  361. return false;
  362. }
  363. } else if (this->SystemName == "WindowsPhone") {
  364. this->SystemIsWindowsPhone = true;
  365. if (!this->InitializeWindowsPhone(mf)) {
  366. return false;
  367. }
  368. } else if (this->SystemName == "WindowsStore") {
  369. this->SystemIsWindowsStore = true;
  370. if (!this->InitializeWindowsStore(mf)) {
  371. return false;
  372. }
  373. } else if (this->SystemName == "Android") {
  374. if (this->DefaultPlatformName != "Win32") {
  375. std::ostringstream e;
  376. e << "CMAKE_SYSTEM_NAME is 'Android' but CMAKE_GENERATOR "
  377. << "specifies a platform too: '" << this->GetName() << "'";
  378. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  379. return false;
  380. }
  381. std::string v = this->GetInstalledNsightTegraVersion();
  382. if (v.empty()) {
  383. mf->IssueMessage(cmake::FATAL_ERROR,
  384. "CMAKE_SYSTEM_NAME is 'Android' but "
  385. "'NVIDIA Nsight Tegra Visual Studio Edition' "
  386. "is not installed.");
  387. return false;
  388. }
  389. this->DefaultPlatformName = "Tegra-Android";
  390. this->DefaultPlatformToolset = "Default";
  391. this->NsightTegraVersion = v;
  392. mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v.c_str());
  393. }
  394. return true;
  395. }
  396. bool cmGlobalVisualStudio10Generator::InitializeWindows(cmMakefile*)
  397. {
  398. return true;
  399. }
  400. bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile* mf)
  401. {
  402. if (this->DefaultPlatformName != "Win32") {
  403. std::ostringstream e;
  404. e << "CMAKE_SYSTEM_NAME is 'WindowsCE' but CMAKE_GENERATOR "
  405. << "specifies a platform too: '" << this->GetName() << "'";
  406. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  407. return false;
  408. }
  409. this->DefaultPlatformToolset = this->SelectWindowsCEToolset();
  410. return true;
  411. }
  412. bool cmGlobalVisualStudio10Generator::InitializeWindowsPhone(cmMakefile* mf)
  413. {
  414. std::ostringstream e;
  415. e << this->GetName() << " does not support Windows Phone.";
  416. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  417. return false;
  418. }
  419. bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf)
  420. {
  421. std::ostringstream e;
  422. e << this->GetName() << " does not support Windows Store.";
  423. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  424. return false;
  425. }
  426. bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
  427. std::string& toolset) const
  428. {
  429. toolset.clear();
  430. return false;
  431. }
  432. bool cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset(
  433. std::string& toolset) const
  434. {
  435. toolset.clear();
  436. return false;
  437. }
  438. std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const
  439. {
  440. if (this->SystemVersion == "8.0") {
  441. return "CE800";
  442. }
  443. return "";
  444. }
  445. ///! Create a local generator appropriate to this Global Generator
  446. cmLocalGenerator* cmGlobalVisualStudio10Generator::CreateLocalGenerator(
  447. cmMakefile* mf)
  448. {
  449. return new cmLocalVisualStudio10Generator(this, mf);
  450. }
  451. void cmGlobalVisualStudio10Generator::Generate()
  452. {
  453. this->LongestSource = LongestSourcePath();
  454. this->cmGlobalVisualStudio8Generator::Generate();
  455. if (this->LongestSource.Length > 0) {
  456. cmLocalGenerator* lg = this->LongestSource.Target->GetLocalGenerator();
  457. std::ostringstream e;
  458. /* clang-format off */
  459. e <<
  460. "The binary and/or source directory paths may be too long to generate "
  461. "Visual Studio 10 files for this project. "
  462. "Consider choosing shorter directory names to build this project with "
  463. "Visual Studio 10. "
  464. "A more detailed explanation follows."
  465. "\n"
  466. "There is a bug in the VS 10 IDE that renders property dialog fields "
  467. "blank for files referenced by full path in the project file. "
  468. "However, CMake must reference at least one file by full path:\n"
  469. " " << this->LongestSource.SourceFile->GetFullPath() << "\n"
  470. "This is because some Visual Studio tools would append the relative "
  471. "path to the end of the referencing directory path, as in:\n"
  472. " " << lg->GetCurrentBinaryDirectory() << "/"
  473. << this->LongestSource.SourceRel << "\n"
  474. "and then incorrectly complain that the file does not exist because "
  475. "the path length is too long for some internal buffer or API. "
  476. "To avoid this problem CMake must use a full path for this file "
  477. "which then triggers the VS 10 property dialog bug.";
  478. /* clang-format on */
  479. lg->IssueMessage(cmake::WARNING, e.str().c_str());
  480. }
  481. }
  482. void cmGlobalVisualStudio10Generator::EnableLanguage(
  483. std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
  484. {
  485. for (std::string const& it : lang) {
  486. if (it == "ASM_NASM") {
  487. this->NasmEnabled = true;
  488. }
  489. if (it == "CUDA") {
  490. this->CudaEnabled = true;
  491. }
  492. }
  493. this->AddPlatformDefinitions(mf);
  494. cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
  495. }
  496. const char* cmGlobalVisualStudio10Generator::GetPlatformToolset() const
  497. {
  498. std::string const& toolset = this->GetPlatformToolsetString();
  499. if (toolset.empty()) {
  500. return nullptr;
  501. }
  502. return toolset.c_str();
  503. }
  504. std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString()
  505. const
  506. {
  507. if (!this->GeneratorToolset.empty()) {
  508. return this->GeneratorToolset;
  509. }
  510. if (!this->DefaultPlatformToolset.empty()) {
  511. return this->DefaultPlatformToolset;
  512. }
  513. static std::string const empty;
  514. return empty;
  515. }
  516. const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetVersion() const
  517. {
  518. std::string const& version = this->GetPlatformToolsetVersionString();
  519. if (version.empty()) {
  520. return nullptr;
  521. }
  522. return version.c_str();
  523. }
  524. std::string const&
  525. cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionString() const
  526. {
  527. if (!this->GeneratorToolsetVersion.empty()) {
  528. return this->GeneratorToolsetVersion;
  529. }
  530. static std::string const empty;
  531. return empty;
  532. }
  533. const char*
  534. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const
  535. {
  536. if (!this->GeneratorToolsetHostArchitecture.empty()) {
  537. return this->GeneratorToolsetHostArchitecture.c_str();
  538. }
  539. return nullptr;
  540. }
  541. const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
  542. {
  543. if (!this->GeneratorToolsetCuda.empty()) {
  544. return this->GeneratorToolsetCuda.c_str();
  545. }
  546. return nullptr;
  547. }
  548. std::string const&
  549. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaString() const
  550. {
  551. return this->GeneratorToolsetCuda;
  552. }
  553. bool cmGlobalVisualStudio10Generator::IsDefaultToolset(
  554. const std::string&) const
  555. {
  556. return true;
  557. }
  558. std::string cmGlobalVisualStudio10Generator::GetAuxiliaryToolset() const
  559. {
  560. return {};
  561. }
  562. bool cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf)
  563. {
  564. if (!this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf)) {
  565. return false;
  566. }
  567. mf->AddDefinition("CMAKE_VS_MSBUILD_COMMAND",
  568. this->GetMSBuildCommand().c_str());
  569. return true;
  570. }
  571. std::string const& cmGlobalVisualStudio10Generator::GetMSBuildCommand()
  572. {
  573. if (!this->MSBuildCommandInitialized) {
  574. this->MSBuildCommandInitialized = true;
  575. this->MSBuildCommand = this->FindMSBuildCommand();
  576. }
  577. return this->MSBuildCommand;
  578. }
  579. std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand()
  580. {
  581. std::string msbuild;
  582. std::string mskey;
  583. // Search in standard location.
  584. mskey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\";
  585. mskey += this->GetToolsVersion();
  586. mskey += ";MSBuildToolsPath";
  587. if (cmSystemTools::ReadRegistryValue(mskey.c_str(), msbuild,
  588. cmSystemTools::KeyWOW64_32)) {
  589. cmSystemTools::ConvertToUnixSlashes(msbuild);
  590. msbuild += "/MSBuild.exe";
  591. if (cmSystemTools::FileExists(msbuild, true)) {
  592. return msbuild;
  593. }
  594. }
  595. msbuild = "MSBuild.exe";
  596. return msbuild;
  597. }
  598. std::string cmGlobalVisualStudio10Generator::FindDevEnvCommand()
  599. {
  600. if (this->ExpressEdition) {
  601. // Visual Studio Express >= 10 do not have "devenv.com" or
  602. // "VCExpress.exe" that we can use to build reliably.
  603. // Tell the caller it needs to use MSBuild instead.
  604. return "";
  605. }
  606. // Skip over the cmGlobalVisualStudio8Generator implementation because
  607. // we expect a real devenv and do not want to look for VCExpress.
  608. return this->cmGlobalVisualStudio71Generator::FindDevEnvCommand();
  609. }
  610. bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
  611. {
  612. // Skip this in special cases within our own test suite.
  613. if (this->GetPlatformName() == "Test Platform" ||
  614. this->GetPlatformToolsetString() == "Test Toolset") {
  615. return true;
  616. }
  617. std::string wd;
  618. if (!this->ConfiguredFilesPath.empty()) {
  619. // In a try-compile we are given the outer CMakeFiles directory.
  620. wd = this->ConfiguredFilesPath;
  621. } else {
  622. wd = this->GetCMakeInstance()->GetHomeOutputDirectory();
  623. wd += cmake::GetCMakeFilesDirectory();
  624. }
  625. wd += "/";
  626. wd += cmVersion::GetCMakeVersion();
  627. // We record the result persistently in a file.
  628. std::string const txt = wd + "/VCTargetsPath.txt";
  629. // If we have a recorded result, use it.
  630. {
  631. cmsys::ifstream fin(txt.c_str());
  632. if (fin && cmSystemTools::GetLineFromStream(fin, this->VCTargetsPath) &&
  633. cmSystemTools::FileIsDirectory(this->VCTargetsPath)) {
  634. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  635. return true;
  636. }
  637. }
  638. // Prepare the work directory.
  639. if (!cmSystemTools::MakeDirectory(wd)) {
  640. std::string e = "Failed to make directory:\n " + wd;
  641. mf->IssueMessage(cmake::FATAL_ERROR, e.c_str());
  642. cmSystemTools::SetFatalErrorOccured();
  643. return false;
  644. }
  645. // Generate a project file for MSBuild to tell us the VCTargetsPath value.
  646. std::string const vcxproj = "VCTargetsPath.vcxproj";
  647. {
  648. std::string const vcxprojAbs = wd + "/" + vcxproj;
  649. cmsys::ofstream fout(vcxprojAbs.c_str());
  650. cmXMLWriter xw(fout);
  651. cmXMLDocument doc(xw);
  652. cmXMLElement eprj(doc, "Project");
  653. eprj.Attribute("DefaultTargets", "Build");
  654. eprj.Attribute("ToolsVersion", "4.0");
  655. eprj.Attribute("xmlns",
  656. "http://schemas.microsoft.com/developer/msbuild/2003");
  657. if (this->IsNsightTegra()) {
  658. cmXMLElement epg(eprj, "PropertyGroup");
  659. epg.Attribute("Label", "NsightTegraProject");
  660. cmXMLElement(epg, "NsightTegraProjectRevisionNumber").Content("6");
  661. }
  662. {
  663. cmXMLElement eig(eprj, "ItemGroup");
  664. eig.Attribute("Label", "ProjectConfigurations");
  665. cmXMLElement epc(eig, "ProjectConfiguration");
  666. epc.Attribute("Include", "Debug|" + this->GetPlatformName());
  667. cmXMLElement(epc, "Configuration").Content("Debug");
  668. cmXMLElement(epc, "Platform").Content(this->GetPlatformName());
  669. }
  670. {
  671. cmXMLElement epg(eprj, "PropertyGroup");
  672. epg.Attribute("Label", "Globals");
  673. cmXMLElement(epg, "ProjectGuid")
  674. .Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}");
  675. cmXMLElement(epg, "Keyword").Content("Win32Proj");
  676. cmXMLElement(epg, "Platform").Content(this->GetPlatformName());
  677. if (this->GetSystemName() == "WindowsPhone") {
  678. cmXMLElement(epg, "ApplicationType").Content("Windows Phone");
  679. cmXMLElement(epg, "ApplicationTypeRevision")
  680. .Content(this->GetSystemVersion());
  681. } else if (this->GetSystemName() == "WindowsStore") {
  682. cmXMLElement(epg, "ApplicationType").Content("Windows Store");
  683. cmXMLElement(epg, "ApplicationTypeRevision")
  684. .Content(this->GetSystemVersion());
  685. }
  686. if (!this->WindowsTargetPlatformVersion.empty()) {
  687. cmXMLElement(epg, "WindowsTargetPlatformVersion")
  688. .Content(this->WindowsTargetPlatformVersion);
  689. }
  690. if (this->GetPlatformName() == "ARM64") {
  691. cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true");
  692. } else if (this->GetPlatformName() == "ARM") {
  693. cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true");
  694. }
  695. }
  696. cmXMLElement(eprj, "Import")
  697. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  698. if (!this->GeneratorToolsetHostArchitecture.empty()) {
  699. cmXMLElement epg(eprj, "PropertyGroup");
  700. cmXMLElement(epg, "PreferredToolArchitecture")
  701. .Content(this->GeneratorToolsetHostArchitecture);
  702. }
  703. {
  704. cmXMLElement epg(eprj, "PropertyGroup");
  705. epg.Attribute("Label", "Configuration");
  706. {
  707. cmXMLElement ect(epg, "ConfigurationType");
  708. if (this->IsNsightTegra()) {
  709. // Tegra-Android platform does not understand "Utility".
  710. ect.Content("StaticLibrary");
  711. } else {
  712. ect.Content("Utility");
  713. }
  714. }
  715. cmXMLElement(epg, "CharacterSet").Content("MultiByte");
  716. if (this->IsNsightTegra()) {
  717. cmXMLElement(epg, "NdkToolchainVersion")
  718. .Content(this->GetPlatformToolsetString());
  719. } else {
  720. cmXMLElement(epg, "PlatformToolset")
  721. .Content(this->GetPlatformToolsetString());
  722. }
  723. }
  724. cmXMLElement(eprj, "Import")
  725. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  726. {
  727. cmXMLElement eidg(eprj, "ItemDefinitionGroup");
  728. cmXMLElement epbe(eidg, "PostBuildEvent");
  729. cmXMLElement(epbe, "Command")
  730. .Content("echo VCTargetsPath=$(VCTargetsPath)");
  731. }
  732. cmXMLElement(eprj, "Import")
  733. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  734. }
  735. std::vector<std::string> cmd;
  736. cmd.push_back(this->GetMSBuildCommand());
  737. cmd.push_back(vcxproj);
  738. cmd.push_back("/p:Configuration=Debug");
  739. cmd.push_back(std::string("/p:VisualStudioVersion=") +
  740. this->GetIDEVersion());
  741. std::string out;
  742. int ret = 0;
  743. cmsys::RegularExpression regex("\n *VCTargetsPath=([^%\r\n]+)[\r\n]");
  744. if (!cmSystemTools::RunSingleCommand(cmd, &out, &out, &ret, wd.c_str(),
  745. cmSystemTools::OUTPUT_NONE) ||
  746. ret != 0 || !regex.find(out)) {
  747. cmSystemTools::ReplaceString(out, "\n", "\n ");
  748. std::ostringstream e;
  749. /* clang-format off */
  750. e <<
  751. "Failed to run MSBuild command:\n"
  752. " " << cmd[0] << "\n"
  753. "to get the value of VCTargetsPath:\n"
  754. " " << out << "\n"
  755. ;
  756. /* clang-format on */
  757. if (ret != 0) {
  758. e << "Exit code: " << ret << "\n";
  759. }
  760. mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  761. cmSystemTools::SetFatalErrorOccured();
  762. return false;
  763. }
  764. this->VCTargetsPath = regex.match(1);
  765. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  766. {
  767. cmsys::ofstream fout(txt.c_str());
  768. fout << this->VCTargetsPath << "\n";
  769. }
  770. return true;
  771. }
  772. void cmGlobalVisualStudio10Generator::GenerateBuildCommand(
  773. std::vector<std::string>& makeCommand, const std::string& makeProgram,
  774. const std::string& projectName, const std::string& projectDir,
  775. const std::string& targetName, const std::string& config, bool fast,
  776. int jobs, bool verbose, std::vector<std::string> const& makeOptions)
  777. {
  778. // Select the caller- or user-preferred make program, else MSBuild.
  779. std::string makeProgramSelected =
  780. this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand());
  781. // Check if the caller explicitly requested a devenv tool.
  782. std::string makeProgramLower = makeProgramSelected;
  783. cmSystemTools::LowerCase(makeProgramLower);
  784. bool useDevEnv = (makeProgramLower.find("devenv") != std::string::npos ||
  785. makeProgramLower.find("vcexpress") != std::string::npos);
  786. // MSBuild is preferred (and required for VS Express), but if the .sln has
  787. // an Intel Fortran .vfproj then we have to use devenv. Parse it to find out.
  788. cmSlnData slnData;
  789. {
  790. std::string slnFile;
  791. if (!projectDir.empty()) {
  792. slnFile = projectDir;
  793. slnFile += "/";
  794. }
  795. slnFile += projectName;
  796. slnFile += ".sln";
  797. cmVisualStudioSlnParser parser;
  798. if (parser.ParseFile(slnFile, slnData,
  799. cmVisualStudioSlnParser::DataGroupProjects)) {
  800. std::vector<cmSlnProjectEntry> slnProjects = slnData.GetProjects();
  801. for (std::vector<cmSlnProjectEntry>::const_iterator i =
  802. slnProjects.cbegin();
  803. !useDevEnv && i != slnProjects.cend(); ++i) {
  804. std::string proj = i->GetRelativePath();
  805. if (proj.size() > 7 && proj.substr(proj.size() - 7) == ".vfproj") {
  806. useDevEnv = true;
  807. }
  808. }
  809. }
  810. }
  811. if (useDevEnv) {
  812. // Use devenv to build solutions containing Intel Fortran projects.
  813. cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  814. makeCommand, makeProgram, projectName, projectDir, targetName, config,
  815. fast, jobs, verbose, makeOptions);
  816. return;
  817. }
  818. makeCommand.push_back(makeProgramSelected);
  819. std::string realTarget = targetName;
  820. // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug /target:ALL_BUILD
  821. // /m
  822. if (realTarget.empty()) {
  823. realTarget = "ALL_BUILD";
  824. }
  825. if (realTarget == "clean") {
  826. makeCommand.push_back(std::string(projectName) + ".sln");
  827. makeCommand.push_back("/t:Clean");
  828. } else {
  829. std::string targetProject(realTarget);
  830. targetProject += ".vcxproj";
  831. if (targetProject.find('/') == std::string::npos) {
  832. // it might be in a subdir
  833. if (cmSlnProjectEntry const* proj =
  834. slnData.GetProjectByName(realTarget)) {
  835. targetProject = proj->GetRelativePath();
  836. cmSystemTools::ConvertToUnixSlashes(targetProject);
  837. }
  838. }
  839. makeCommand.push_back(targetProject);
  840. }
  841. std::string configArg = "/p:Configuration=";
  842. if (!config.empty()) {
  843. configArg += config;
  844. } else {
  845. configArg += "Debug";
  846. }
  847. makeCommand.push_back(configArg);
  848. makeCommand.push_back("/p:Platform=" + this->GetPlatformName());
  849. makeCommand.push_back(std::string("/p:VisualStudioVersion=") +
  850. this->GetIDEVersion());
  851. if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
  852. if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
  853. makeCommand.push_back("/m");
  854. } else {
  855. makeCommand.push_back(std::string("/m:") + std::to_string(jobs));
  856. }
  857. // Having msbuild.exe and cl.exe using multiple jobs is discouraged
  858. makeCommand.push_back("/p:CL_MPCount=1");
  859. }
  860. makeCommand.insert(makeCommand.end(), makeOptions.begin(),
  861. makeOptions.end());
  862. }
  863. bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
  864. {
  865. if (this->DefaultPlatformToolset == "v100") {
  866. // The v100 64-bit toolset does not exist in the express edition.
  867. this->DefaultPlatformToolset.clear();
  868. }
  869. if (this->GetPlatformToolset()) {
  870. return true;
  871. }
  872. // This edition does not come with 64-bit tools. Look for them.
  873. //
  874. // TODO: Detect available tools? x64\v100 exists but does not work?
  875. // HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0;VCTargetsPath
  876. // c:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/Platforms/
  877. // {Itanium,Win32,x64}/PlatformToolsets/{v100,v90,Windows7.1SDK}
  878. std::string winSDK_7_1;
  879. if (cmSystemTools::ReadRegistryValue(
  880. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\"
  881. "Windows\\v7.1;InstallationFolder",
  882. winSDK_7_1)) {
  883. std::ostringstream m;
  884. m << "Found Windows SDK v7.1: " << winSDK_7_1;
  885. mf->DisplayStatus(m.str().c_str(), -1);
  886. this->DefaultPlatformToolset = "Windows7.1SDK";
  887. return true;
  888. } else {
  889. std::ostringstream e;
  890. /* clang-format off */
  891. e << "Cannot enable 64-bit tools with Visual Studio 2010 Express.\n"
  892. << "Install the Microsoft Windows SDK v7.1 to get 64-bit tools:\n"
  893. << " http://msdn.microsoft.com/en-us/windows/bb980924.aspx";
  894. /* clang-format on */
  895. mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  896. cmSystemTools::SetFatalErrorOccured();
  897. return false;
  898. }
  899. }
  900. std::string cmGlobalVisualStudio10Generator::GenerateRuleFile(
  901. std::string const& output) const
  902. {
  903. // The VS 10 generator needs to create the .rule files on disk.
  904. // Hide them away under the CMakeFiles directory.
  905. std::string ruleDir = this->GetCMakeInstance()->GetHomeOutputDirectory();
  906. ruleDir += cmake::GetCMakeFilesDirectory();
  907. ruleDir += "/";
  908. ruleDir += cmSystemTools::ComputeStringMD5(
  909. cmSystemTools::GetFilenamePath(output).c_str());
  910. std::string ruleFile = ruleDir + "/";
  911. ruleFile += cmSystemTools::GetFilenameName(output);
  912. ruleFile += ".rule";
  913. return ruleFile;
  914. }
  915. void cmGlobalVisualStudio10Generator::PathTooLong(cmGeneratorTarget* target,
  916. cmSourceFile const* sf,
  917. std::string const& sfRel)
  918. {
  919. size_t len =
  920. (target->GetLocalGenerator()->GetCurrentBinaryDirectory().length() + 1 +
  921. sfRel.length());
  922. if (len > this->LongestSource.Length) {
  923. this->LongestSource.Length = len;
  924. this->LongestSource.Target = target;
  925. this->LongestSource.SourceFile = sf;
  926. this->LongestSource.SourceRel = sfRel;
  927. }
  928. }
  929. std::string cmGlobalVisualStudio10Generator::Encoding()
  930. {
  931. return "utf-8";
  932. }
  933. const char* cmGlobalVisualStudio10Generator::GetToolsVersion() const
  934. {
  935. switch (this->Version) {
  936. case cmGlobalVisualStudioGenerator::VS9:
  937. case cmGlobalVisualStudioGenerator::VS10:
  938. case cmGlobalVisualStudioGenerator::VS11:
  939. return "4.0";
  940. // in Visual Studio 2013 they detached the MSBuild tools version
  941. // from the .Net Framework version and instead made it have it's own
  942. // version number
  943. case cmGlobalVisualStudioGenerator::VS12:
  944. return "12.0";
  945. case cmGlobalVisualStudioGenerator::VS14:
  946. return "14.0";
  947. case cmGlobalVisualStudioGenerator::VS15:
  948. return "15.0";
  949. }
  950. return "";
  951. }
  952. bool cmGlobalVisualStudio10Generator::IsNsightTegra() const
  953. {
  954. return !this->NsightTegraVersion.empty();
  955. }
  956. std::string cmGlobalVisualStudio10Generator::GetNsightTegraVersion() const
  957. {
  958. return this->NsightTegraVersion;
  959. }
  960. std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
  961. {
  962. std::string version;
  963. cmSystemTools::ReadRegistryValue(
  964. "HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;"
  965. "Version",
  966. version, cmSystemTools::KeyWOW64_32);
  967. return version;
  968. }
  969. static std::string cmLoadFlagTableString(Json::Value entry, const char* field)
  970. {
  971. if (entry.isMember(field)) {
  972. auto string = entry[field];
  973. if (string.isConvertibleTo(Json::ValueType::stringValue)) {
  974. return string.asString();
  975. }
  976. }
  977. return "";
  978. }
  979. static unsigned int cmLoadFlagTableSpecial(Json::Value entry,
  980. const char* field)
  981. {
  982. unsigned int value = 0;
  983. if (entry.isMember(field)) {
  984. auto specials = entry[field];
  985. if (specials.isArray()) {
  986. for (auto const& special : specials) {
  987. std::string s = special.asString();
  988. if (s == "UserValue") {
  989. value |= cmIDEFlagTable::UserValue;
  990. } else if (s == "UserIgnored") {
  991. value |= cmIDEFlagTable::UserIgnored;
  992. } else if (s == "UserRequired") {
  993. value |= cmIDEFlagTable::UserRequired;
  994. } else if (s == "Continue") {
  995. value |= cmIDEFlagTable::Continue;
  996. } else if (s == "SemicolonAppendable") {
  997. value |= cmIDEFlagTable::SemicolonAppendable;
  998. } else if (s == "UserFollowing") {
  999. value |= cmIDEFlagTable::UserFollowing;
  1000. } else if (s == "CaseInsensitive") {
  1001. value |= cmIDEFlagTable::CaseInsensitive;
  1002. } else if (s == "SpaceAppendable") {
  1003. value |= cmIDEFlagTable::SpaceAppendable;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. return value;
  1009. }
  1010. static cmIDEFlagTable const* cmLoadFlagTableJson(
  1011. std::string const& flagJsonPath)
  1012. {
  1013. cmIDEFlagTable* ret = nullptr;
  1014. auto savedFlagIterator = loadedFlagJsonFiles.find(flagJsonPath);
  1015. if (savedFlagIterator != loadedFlagJsonFiles.end()) {
  1016. ret = savedFlagIterator->second.data();
  1017. } else {
  1018. Json::Reader reader;
  1019. cmsys::ifstream stream;
  1020. stream.open(flagJsonPath.c_str(), std::ios_base::in);
  1021. if (stream) {
  1022. Json::Value flags;
  1023. if (reader.parse(stream, flags, false) && flags.isArray()) {
  1024. std::vector<cmIDEFlagTable> flagTable;
  1025. for (auto const& flag : flags) {
  1026. cmIDEFlagTable flagEntry;
  1027. flagEntry.IDEName = cmLoadFlagTableString(flag, "name");
  1028. flagEntry.commandFlag = cmLoadFlagTableString(flag, "switch");
  1029. flagEntry.comment = cmLoadFlagTableString(flag, "comment");
  1030. flagEntry.value = cmLoadFlagTableString(flag, "value");
  1031. flagEntry.special = cmLoadFlagTableSpecial(flag, "flags");
  1032. flagTable.push_back(flagEntry);
  1033. }
  1034. cmIDEFlagTable endFlag{ "", "", "", "", 0 };
  1035. flagTable.push_back(endFlag);
  1036. loadedFlagJsonFiles[flagJsonPath] = flagTable;
  1037. ret = loadedFlagJsonFiles[flagJsonPath].data();
  1038. }
  1039. }
  1040. }
  1041. return ret;
  1042. }
  1043. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable(
  1044. std::string const& flagTableName, std::string const& table) const
  1045. {
  1046. cmIDEFlagTable const* ret = nullptr;
  1047. std::string filename = cmSystemTools::GetCMakeRoot() +
  1048. "/Templates/MSBuild/FlagTables/" + flagTableName + "_" + table + ".json";
  1049. ret = cmLoadFlagTableJson(filename);
  1050. if (!ret) {
  1051. cmMakefile* mf = this->GetCurrentMakefile();
  1052. std::ostringstream e;
  1053. /* clang-format off */
  1054. e << "JSON flag table \"" << filename <<
  1055. "\" could not be loaded.\n";
  1056. /* clang-format on */
  1057. mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  1058. }
  1059. return ret;
  1060. }
  1061. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const
  1062. {
  1063. std::string flagTableName = this->ToolsetOptions.GetClFlagTableName(
  1064. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1065. this->DefaultCLFlagTableName);
  1066. return LoadFlagTable(flagTableName, "CL");
  1067. }
  1068. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable()
  1069. const
  1070. {
  1071. std::string flagTableName = this->ToolsetOptions.GetCSharpFlagTableName(
  1072. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1073. this->DefaultCSharpFlagTableName);
  1074. return LoadFlagTable(flagTableName, "CSharp");
  1075. }
  1076. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const
  1077. {
  1078. std::string flagTableName = this->ToolsetOptions.GetRcFlagTableName(
  1079. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1080. this->DefaultRCFlagTableName);
  1081. return LoadFlagTable(flagTableName, "RC");
  1082. }
  1083. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const
  1084. {
  1085. std::string flagTableName = this->ToolsetOptions.GetLibFlagTableName(
  1086. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1087. this->DefaultLibFlagTableName);
  1088. return LoadFlagTable(flagTableName, "LIB");
  1089. }
  1090. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const
  1091. {
  1092. std::string flagTableName = this->ToolsetOptions.GetLinkFlagTableName(
  1093. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1094. this->DefaultLinkFlagTableName);
  1095. return LoadFlagTable(flagTableName, "Link");
  1096. }
  1097. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaFlagTable() const
  1098. {
  1099. return LoadFlagTable(this->DefaultCudaFlagTableName, "Cuda");
  1100. }
  1101. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaHostFlagTable()
  1102. const
  1103. {
  1104. return LoadFlagTable(this->DefaultCudaHostFlagTableName, "CudaHost");
  1105. }
  1106. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const
  1107. {
  1108. std::string flagTableName = this->ToolsetOptions.GetMasmFlagTableName(
  1109. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1110. this->DefaultMasmFlagTableName);
  1111. return LoadFlagTable(flagTableName, "MASM");
  1112. }
  1113. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const
  1114. {
  1115. return LoadFlagTable(this->DefaultNasmFlagTableName, "NASM");
  1116. }