cmGlobalVisualStudio10Generator.cxx 39 KB

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