cmGlobalVisualStudio10Generator.cxx 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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. void cmGlobalVisualStudio10Generator::WriteSLNHeader(std::ostream& fout)
  446. {
  447. fout << "Microsoft Visual Studio Solution File, Format Version 11.00\n";
  448. if (this->ExpressEdition) {
  449. fout << "# Visual C++ Express 2010\n";
  450. } else {
  451. fout << "# Visual Studio 2010\n";
  452. }
  453. }
  454. ///! Create a local generator appropriate to this Global Generator
  455. cmLocalGenerator* cmGlobalVisualStudio10Generator::CreateLocalGenerator(
  456. cmMakefile* mf)
  457. {
  458. return new cmLocalVisualStudio10Generator(this, mf);
  459. }
  460. void cmGlobalVisualStudio10Generator::Generate()
  461. {
  462. this->LongestSource = LongestSourcePath();
  463. this->cmGlobalVisualStudio8Generator::Generate();
  464. if (this->LongestSource.Length > 0) {
  465. cmLocalGenerator* lg = this->LongestSource.Target->GetLocalGenerator();
  466. std::ostringstream e;
  467. /* clang-format off */
  468. e <<
  469. "The binary and/or source directory paths may be too long to generate "
  470. "Visual Studio 10 files for this project. "
  471. "Consider choosing shorter directory names to build this project with "
  472. "Visual Studio 10. "
  473. "A more detailed explanation follows."
  474. "\n"
  475. "There is a bug in the VS 10 IDE that renders property dialog fields "
  476. "blank for files referenced by full path in the project file. "
  477. "However, CMake must reference at least one file by full path:\n"
  478. " " << this->LongestSource.SourceFile->GetFullPath() << "\n"
  479. "This is because some Visual Studio tools would append the relative "
  480. "path to the end of the referencing directory path, as in:\n"
  481. " " << lg->GetCurrentBinaryDirectory() << "/"
  482. << this->LongestSource.SourceRel << "\n"
  483. "and then incorrectly complain that the file does not exist because "
  484. "the path length is too long for some internal buffer or API. "
  485. "To avoid this problem CMake must use a full path for this file "
  486. "which then triggers the VS 10 property dialog bug.";
  487. /* clang-format on */
  488. lg->IssueMessage(cmake::WARNING, e.str().c_str());
  489. }
  490. }
  491. void cmGlobalVisualStudio10Generator::EnableLanguage(
  492. std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
  493. {
  494. for (std::string const& it : lang) {
  495. if (it == "ASM_NASM") {
  496. this->NasmEnabled = true;
  497. }
  498. if (it == "CUDA") {
  499. this->CudaEnabled = true;
  500. }
  501. }
  502. this->AddPlatformDefinitions(mf);
  503. cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
  504. }
  505. const char* cmGlobalVisualStudio10Generator::GetPlatformToolset() const
  506. {
  507. std::string const& toolset = this->GetPlatformToolsetString();
  508. if (toolset.empty()) {
  509. return nullptr;
  510. }
  511. return toolset.c_str();
  512. }
  513. std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString()
  514. const
  515. {
  516. if (!this->GeneratorToolset.empty()) {
  517. return this->GeneratorToolset;
  518. }
  519. if (!this->DefaultPlatformToolset.empty()) {
  520. return this->DefaultPlatformToolset;
  521. }
  522. static std::string const empty;
  523. return empty;
  524. }
  525. const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetVersion() const
  526. {
  527. std::string const& version = this->GetPlatformToolsetVersionString();
  528. if (version.empty()) {
  529. return nullptr;
  530. }
  531. return version.c_str();
  532. }
  533. std::string const&
  534. cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionString() const
  535. {
  536. if (!this->GeneratorToolsetVersion.empty()) {
  537. return this->GeneratorToolsetVersion;
  538. }
  539. static std::string const empty;
  540. return empty;
  541. }
  542. const char*
  543. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const
  544. {
  545. if (!this->GeneratorToolsetHostArchitecture.empty()) {
  546. return this->GeneratorToolsetHostArchitecture.c_str();
  547. }
  548. return nullptr;
  549. }
  550. const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
  551. {
  552. if (!this->GeneratorToolsetCuda.empty()) {
  553. return this->GeneratorToolsetCuda.c_str();
  554. }
  555. return nullptr;
  556. }
  557. std::string const&
  558. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaString() const
  559. {
  560. return this->GeneratorToolsetCuda;
  561. }
  562. bool cmGlobalVisualStudio10Generator::IsDefaultToolset(
  563. const std::string&) const
  564. {
  565. return true;
  566. }
  567. std::string cmGlobalVisualStudio10Generator::GetAuxiliaryToolset() const
  568. {
  569. return {};
  570. }
  571. bool cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf)
  572. {
  573. if (!this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf)) {
  574. return false;
  575. }
  576. mf->AddDefinition("CMAKE_VS_MSBUILD_COMMAND",
  577. this->GetMSBuildCommand().c_str());
  578. return true;
  579. }
  580. std::string const& cmGlobalVisualStudio10Generator::GetMSBuildCommand()
  581. {
  582. if (!this->MSBuildCommandInitialized) {
  583. this->MSBuildCommandInitialized = true;
  584. this->MSBuildCommand = this->FindMSBuildCommand();
  585. }
  586. return this->MSBuildCommand;
  587. }
  588. std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand()
  589. {
  590. std::string msbuild;
  591. std::string mskey;
  592. // Search in standard location.
  593. mskey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\";
  594. mskey += this->GetToolsVersion();
  595. mskey += ";MSBuildToolsPath";
  596. if (cmSystemTools::ReadRegistryValue(mskey.c_str(), msbuild,
  597. cmSystemTools::KeyWOW64_32)) {
  598. cmSystemTools::ConvertToUnixSlashes(msbuild);
  599. msbuild += "/MSBuild.exe";
  600. if (cmSystemTools::FileExists(msbuild, true)) {
  601. return msbuild;
  602. }
  603. }
  604. msbuild = "MSBuild.exe";
  605. return msbuild;
  606. }
  607. std::string cmGlobalVisualStudio10Generator::FindDevEnvCommand()
  608. {
  609. if (this->ExpressEdition) {
  610. // Visual Studio Express >= 10 do not have "devenv.com" or
  611. // "VCExpress.exe" that we can use to build reliably.
  612. // Tell the caller it needs to use MSBuild instead.
  613. return "";
  614. }
  615. // Skip over the cmGlobalVisualStudio8Generator implementation because
  616. // we expect a real devenv and do not want to look for VCExpress.
  617. return this->cmGlobalVisualStudio71Generator::FindDevEnvCommand();
  618. }
  619. bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
  620. {
  621. // Skip this in special cases within our own test suite.
  622. if (this->GetPlatformName() == "Test Platform" ||
  623. this->GetPlatformToolsetString() == "Test Toolset") {
  624. return true;
  625. }
  626. std::string wd;
  627. if (!this->ConfiguredFilesPath.empty()) {
  628. // In a try-compile we are given the outer CMakeFiles directory.
  629. wd = this->ConfiguredFilesPath;
  630. } else {
  631. wd = this->GetCMakeInstance()->GetHomeOutputDirectory();
  632. wd += cmake::GetCMakeFilesDirectory();
  633. }
  634. wd += "/";
  635. wd += cmVersion::GetCMakeVersion();
  636. // We record the result persistently in a file.
  637. std::string const txt = wd + "/VCTargetsPath.txt";
  638. // If we have a recorded result, use it.
  639. {
  640. cmsys::ifstream fin(txt.c_str());
  641. if (fin && cmSystemTools::GetLineFromStream(fin, this->VCTargetsPath) &&
  642. cmSystemTools::FileIsDirectory(this->VCTargetsPath)) {
  643. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  644. return true;
  645. }
  646. }
  647. // Prepare the work directory.
  648. if (!cmSystemTools::MakeDirectory(wd)) {
  649. std::string e = "Failed to make directory:\n " + wd;
  650. mf->IssueMessage(cmake::FATAL_ERROR, e.c_str());
  651. cmSystemTools::SetFatalErrorOccured();
  652. return false;
  653. }
  654. // Generate a project file for MSBuild to tell us the VCTargetsPath value.
  655. std::string const vcxproj = "VCTargetsPath.vcxproj";
  656. {
  657. std::string const vcxprojAbs = wd + "/" + vcxproj;
  658. cmsys::ofstream fout(vcxprojAbs.c_str());
  659. cmXMLWriter xw(fout);
  660. cmXMLDocument doc(xw);
  661. cmXMLElement eprj(doc, "Project");
  662. eprj.Attribute("DefaultTargets", "Build");
  663. eprj.Attribute("ToolsVersion", "4.0");
  664. eprj.Attribute("xmlns",
  665. "http://schemas.microsoft.com/developer/msbuild/2003");
  666. if (this->IsNsightTegra()) {
  667. cmXMLElement epg(eprj, "PropertyGroup");
  668. epg.Attribute("Label", "NsightTegraProject");
  669. cmXMLElement(epg, "NsightTegraProjectRevisionNumber").Content("6");
  670. }
  671. {
  672. cmXMLElement eig(eprj, "ItemGroup");
  673. eig.Attribute("Label", "ProjectConfigurations");
  674. cmXMLElement epc(eig, "ProjectConfiguration");
  675. epc.Attribute("Include", "Debug|" + this->GetPlatformName());
  676. cmXMLElement(epc, "Configuration").Content("Debug");
  677. cmXMLElement(epc, "Platform").Content(this->GetPlatformName());
  678. }
  679. {
  680. cmXMLElement epg(eprj, "PropertyGroup");
  681. epg.Attribute("Label", "Globals");
  682. cmXMLElement(epg, "ProjectGuid")
  683. .Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}");
  684. cmXMLElement(epg, "Keyword").Content("Win32Proj");
  685. cmXMLElement(epg, "Platform").Content(this->GetPlatformName());
  686. if (this->GetSystemName() == "WindowsPhone") {
  687. cmXMLElement(epg, "ApplicationType").Content("Windows Phone");
  688. cmXMLElement(epg, "ApplicationTypeRevision")
  689. .Content(this->GetSystemVersion());
  690. } else if (this->GetSystemName() == "WindowsStore") {
  691. cmXMLElement(epg, "ApplicationType").Content("Windows Store");
  692. cmXMLElement(epg, "ApplicationTypeRevision")
  693. .Content(this->GetSystemVersion());
  694. }
  695. if (!this->WindowsTargetPlatformVersion.empty()) {
  696. cmXMLElement(epg, "WindowsTargetPlatformVersion")
  697. .Content(this->WindowsTargetPlatformVersion);
  698. }
  699. if (this->GetPlatformName() == "ARM64") {
  700. cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true");
  701. } else if (this->GetPlatformName() == "ARM") {
  702. cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true");
  703. }
  704. }
  705. cmXMLElement(eprj, "Import")
  706. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  707. if (!this->GeneratorToolsetHostArchitecture.empty()) {
  708. cmXMLElement epg(eprj, "PropertyGroup");
  709. cmXMLElement(epg, "PreferredToolArchitecture")
  710. .Content(this->GeneratorToolsetHostArchitecture);
  711. }
  712. {
  713. cmXMLElement epg(eprj, "PropertyGroup");
  714. epg.Attribute("Label", "Configuration");
  715. {
  716. cmXMLElement ect(epg, "ConfigurationType");
  717. if (this->IsNsightTegra()) {
  718. // Tegra-Android platform does not understand "Utility".
  719. ect.Content("StaticLibrary");
  720. } else {
  721. ect.Content("Utility");
  722. }
  723. }
  724. cmXMLElement(epg, "CharacterSet").Content("MultiByte");
  725. if (this->IsNsightTegra()) {
  726. cmXMLElement(epg, "NdkToolchainVersion")
  727. .Content(this->GetPlatformToolsetString());
  728. } else {
  729. cmXMLElement(epg, "PlatformToolset")
  730. .Content(this->GetPlatformToolsetString());
  731. }
  732. }
  733. cmXMLElement(eprj, "Import")
  734. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  735. {
  736. cmXMLElement eidg(eprj, "ItemDefinitionGroup");
  737. cmXMLElement epbe(eidg, "PostBuildEvent");
  738. cmXMLElement(epbe, "Command")
  739. .Content("echo VCTargetsPath=$(VCTargetsPath)");
  740. }
  741. cmXMLElement(eprj, "Import")
  742. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  743. }
  744. std::vector<std::string> cmd;
  745. cmd.push_back(this->GetMSBuildCommand());
  746. cmd.push_back(vcxproj);
  747. cmd.push_back("/p:Configuration=Debug");
  748. cmd.push_back(std::string("/p:VisualStudioVersion=") +
  749. this->GetIDEVersion());
  750. std::string out;
  751. int ret = 0;
  752. cmsys::RegularExpression regex("\n *VCTargetsPath=([^%\r\n]+)[\r\n]");
  753. if (!cmSystemTools::RunSingleCommand(cmd, &out, &out, &ret, wd.c_str(),
  754. cmSystemTools::OUTPUT_NONE) ||
  755. ret != 0 || !regex.find(out)) {
  756. cmSystemTools::ReplaceString(out, "\n", "\n ");
  757. std::ostringstream e;
  758. /* clang-format off */
  759. e <<
  760. "Failed to run MSBuild command:\n"
  761. " " << cmd[0] << "\n"
  762. "to get the value of VCTargetsPath:\n"
  763. " " << out << "\n"
  764. ;
  765. /* clang-format on */
  766. if (ret != 0) {
  767. e << "Exit code: " << ret << "\n";
  768. }
  769. mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  770. cmSystemTools::SetFatalErrorOccured();
  771. return false;
  772. }
  773. this->VCTargetsPath = regex.match(1);
  774. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  775. {
  776. cmsys::ofstream fout(txt.c_str());
  777. fout << this->VCTargetsPath << "\n";
  778. }
  779. return true;
  780. }
  781. void cmGlobalVisualStudio10Generator::GenerateBuildCommand(
  782. std::vector<std::string>& makeCommand, const std::string& makeProgram,
  783. const std::string& projectName, const std::string& projectDir,
  784. const std::string& targetName, const std::string& config, bool fast,
  785. int jobs, bool verbose, std::vector<std::string> const& makeOptions)
  786. {
  787. // Select the caller- or user-preferred make program, else MSBuild.
  788. std::string makeProgramSelected =
  789. this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand());
  790. // Check if the caller explicitly requested a devenv tool.
  791. std::string makeProgramLower = makeProgramSelected;
  792. cmSystemTools::LowerCase(makeProgramLower);
  793. bool useDevEnv = (makeProgramLower.find("devenv") != std::string::npos ||
  794. makeProgramLower.find("vcexpress") != std::string::npos);
  795. // MSBuild is preferred (and required for VS Express), but if the .sln has
  796. // an Intel Fortran .vfproj then we have to use devenv. Parse it to find out.
  797. cmSlnData slnData;
  798. {
  799. std::string slnFile;
  800. if (!projectDir.empty()) {
  801. slnFile = projectDir;
  802. slnFile += "/";
  803. }
  804. slnFile += projectName;
  805. slnFile += ".sln";
  806. cmVisualStudioSlnParser parser;
  807. if (parser.ParseFile(slnFile, slnData,
  808. cmVisualStudioSlnParser::DataGroupProjects)) {
  809. std::vector<cmSlnProjectEntry> slnProjects = slnData.GetProjects();
  810. for (std::vector<cmSlnProjectEntry>::const_iterator i =
  811. slnProjects.cbegin();
  812. !useDevEnv && i != slnProjects.cend(); ++i) {
  813. std::string proj = i->GetRelativePath();
  814. if (proj.size() > 7 && proj.substr(proj.size() - 7) == ".vfproj") {
  815. useDevEnv = true;
  816. }
  817. }
  818. }
  819. }
  820. if (useDevEnv) {
  821. // Use devenv to build solutions containing Intel Fortran projects.
  822. cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  823. makeCommand, makeProgram, projectName, projectDir, targetName, config,
  824. fast, jobs, verbose, makeOptions);
  825. return;
  826. }
  827. makeCommand.push_back(makeProgramSelected);
  828. std::string realTarget = targetName;
  829. // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug /target:ALL_BUILD
  830. // /m
  831. if (realTarget.empty()) {
  832. realTarget = "ALL_BUILD";
  833. }
  834. if (realTarget == "clean") {
  835. makeCommand.push_back(std::string(projectName) + ".sln");
  836. makeCommand.push_back("/t:Clean");
  837. } else {
  838. std::string targetProject(realTarget);
  839. targetProject += ".vcxproj";
  840. if (targetProject.find('/') == std::string::npos) {
  841. // it might be in a subdir
  842. if (cmSlnProjectEntry const* proj =
  843. slnData.GetProjectByName(realTarget)) {
  844. targetProject = proj->GetRelativePath();
  845. cmSystemTools::ConvertToUnixSlashes(targetProject);
  846. }
  847. }
  848. makeCommand.push_back(targetProject);
  849. }
  850. std::string configArg = "/p:Configuration=";
  851. if (!config.empty()) {
  852. configArg += config;
  853. } else {
  854. configArg += "Debug";
  855. }
  856. makeCommand.push_back(configArg);
  857. makeCommand.push_back("/p:Platform=" + this->GetPlatformName());
  858. makeCommand.push_back(std::string("/p:VisualStudioVersion=") +
  859. this->GetIDEVersion());
  860. if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
  861. if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
  862. makeCommand.push_back("/m");
  863. } else {
  864. makeCommand.push_back(std::string("/m:") + std::to_string(jobs));
  865. }
  866. // Having msbuild.exe and cl.exe using multiple jobs is discouraged
  867. makeCommand.push_back("/p:CL_MPCount=1");
  868. }
  869. makeCommand.insert(makeCommand.end(), makeOptions.begin(),
  870. makeOptions.end());
  871. }
  872. bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
  873. {
  874. if (this->DefaultPlatformToolset == "v100") {
  875. // The v100 64-bit toolset does not exist in the express edition.
  876. this->DefaultPlatformToolset.clear();
  877. }
  878. if (this->GetPlatformToolset()) {
  879. return true;
  880. }
  881. // This edition does not come with 64-bit tools. Look for them.
  882. //
  883. // TODO: Detect available tools? x64\v100 exists but does not work?
  884. // HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0;VCTargetsPath
  885. // c:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/Platforms/
  886. // {Itanium,Win32,x64}/PlatformToolsets/{v100,v90,Windows7.1SDK}
  887. std::string winSDK_7_1;
  888. if (cmSystemTools::ReadRegistryValue(
  889. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\"
  890. "Windows\\v7.1;InstallationFolder",
  891. winSDK_7_1)) {
  892. std::ostringstream m;
  893. m << "Found Windows SDK v7.1: " << winSDK_7_1;
  894. mf->DisplayStatus(m.str().c_str(), -1);
  895. this->DefaultPlatformToolset = "Windows7.1SDK";
  896. return true;
  897. } else {
  898. std::ostringstream e;
  899. /* clang-format off */
  900. e << "Cannot enable 64-bit tools with Visual Studio 2010 Express.\n"
  901. << "Install the Microsoft Windows SDK v7.1 to get 64-bit tools:\n"
  902. << " http://msdn.microsoft.com/en-us/windows/bb980924.aspx";
  903. /* clang-format on */
  904. mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  905. cmSystemTools::SetFatalErrorOccured();
  906. return false;
  907. }
  908. }
  909. std::string cmGlobalVisualStudio10Generator::GenerateRuleFile(
  910. std::string const& output) const
  911. {
  912. // The VS 10 generator needs to create the .rule files on disk.
  913. // Hide them away under the CMakeFiles directory.
  914. std::string ruleDir = this->GetCMakeInstance()->GetHomeOutputDirectory();
  915. ruleDir += cmake::GetCMakeFilesDirectory();
  916. ruleDir += "/";
  917. ruleDir += cmSystemTools::ComputeStringMD5(
  918. cmSystemTools::GetFilenamePath(output).c_str());
  919. std::string ruleFile = ruleDir + "/";
  920. ruleFile += cmSystemTools::GetFilenameName(output);
  921. ruleFile += ".rule";
  922. return ruleFile;
  923. }
  924. void cmGlobalVisualStudio10Generator::PathTooLong(cmGeneratorTarget* target,
  925. cmSourceFile const* sf,
  926. std::string const& sfRel)
  927. {
  928. size_t len =
  929. (target->GetLocalGenerator()->GetCurrentBinaryDirectory().length() + 1 +
  930. sfRel.length());
  931. if (len > this->LongestSource.Length) {
  932. this->LongestSource.Length = len;
  933. this->LongestSource.Target = target;
  934. this->LongestSource.SourceFile = sf;
  935. this->LongestSource.SourceRel = sfRel;
  936. }
  937. }
  938. std::string cmGlobalVisualStudio10Generator::Encoding()
  939. {
  940. return "utf-8";
  941. }
  942. bool cmGlobalVisualStudio10Generator::IsNsightTegra() const
  943. {
  944. return !this->NsightTegraVersion.empty();
  945. }
  946. std::string cmGlobalVisualStudio10Generator::GetNsightTegraVersion() const
  947. {
  948. return this->NsightTegraVersion;
  949. }
  950. std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
  951. {
  952. std::string version;
  953. cmSystemTools::ReadRegistryValue(
  954. "HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;"
  955. "Version",
  956. version, cmSystemTools::KeyWOW64_32);
  957. return version;
  958. }
  959. static std::string cmLoadFlagTableString(Json::Value entry, const char* field)
  960. {
  961. if (entry.isMember(field)) {
  962. auto string = entry[field];
  963. if (string.isConvertibleTo(Json::ValueType::stringValue)) {
  964. return string.asString();
  965. }
  966. }
  967. return "";
  968. }
  969. static unsigned int cmLoadFlagTableSpecial(Json::Value entry,
  970. const char* field)
  971. {
  972. unsigned int value = 0;
  973. if (entry.isMember(field)) {
  974. auto specials = entry[field];
  975. if (specials.isArray()) {
  976. for (auto const& special : specials) {
  977. std::string s = special.asString();
  978. if (s == "UserValue") {
  979. value |= cmIDEFlagTable::UserValue;
  980. } else if (s == "UserIgnored") {
  981. value |= cmIDEFlagTable::UserIgnored;
  982. } else if (s == "UserRequired") {
  983. value |= cmIDEFlagTable::UserRequired;
  984. } else if (s == "Continue") {
  985. value |= cmIDEFlagTable::Continue;
  986. } else if (s == "SemicolonAppendable") {
  987. value |= cmIDEFlagTable::SemicolonAppendable;
  988. } else if (s == "UserFollowing") {
  989. value |= cmIDEFlagTable::UserFollowing;
  990. } else if (s == "CaseInsensitive") {
  991. value |= cmIDEFlagTable::CaseInsensitive;
  992. } else if (s == "SpaceAppendable") {
  993. value |= cmIDEFlagTable::SpaceAppendable;
  994. }
  995. }
  996. }
  997. }
  998. return value;
  999. }
  1000. static cmIDEFlagTable const* cmLoadFlagTableJson(
  1001. std::string const& flagJsonPath)
  1002. {
  1003. cmIDEFlagTable* ret = nullptr;
  1004. auto savedFlagIterator = loadedFlagJsonFiles.find(flagJsonPath);
  1005. if (savedFlagIterator != loadedFlagJsonFiles.end()) {
  1006. ret = savedFlagIterator->second.data();
  1007. } else {
  1008. Json::Reader reader;
  1009. cmsys::ifstream stream;
  1010. stream.open(flagJsonPath.c_str(), std::ios_base::in);
  1011. if (stream) {
  1012. Json::Value flags;
  1013. if (reader.parse(stream, flags, false) && flags.isArray()) {
  1014. std::vector<cmIDEFlagTable> flagTable;
  1015. for (auto const& flag : flags) {
  1016. cmIDEFlagTable flagEntry;
  1017. flagEntry.IDEName = cmLoadFlagTableString(flag, "name");
  1018. flagEntry.commandFlag = cmLoadFlagTableString(flag, "switch");
  1019. flagEntry.comment = cmLoadFlagTableString(flag, "comment");
  1020. flagEntry.value = cmLoadFlagTableString(flag, "value");
  1021. flagEntry.special = cmLoadFlagTableSpecial(flag, "flags");
  1022. flagTable.push_back(flagEntry);
  1023. }
  1024. cmIDEFlagTable endFlag{ "", "", "", "", 0 };
  1025. flagTable.push_back(endFlag);
  1026. loadedFlagJsonFiles[flagJsonPath] = flagTable;
  1027. ret = loadedFlagJsonFiles[flagJsonPath].data();
  1028. }
  1029. }
  1030. }
  1031. return ret;
  1032. }
  1033. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable(
  1034. std::string const& flagTableName, std::string const& table) const
  1035. {
  1036. cmIDEFlagTable const* ret = nullptr;
  1037. std::string filename = cmSystemTools::GetCMakeRoot() +
  1038. "/Templates/MSBuild/FlagTables/" + flagTableName + "_" + table + ".json";
  1039. ret = cmLoadFlagTableJson(filename);
  1040. if (!ret) {
  1041. cmMakefile* mf = this->GetCurrentMakefile();
  1042. std::ostringstream e;
  1043. /* clang-format off */
  1044. e << "JSON flag table \"" << filename <<
  1045. "\" could not be loaded.\n";
  1046. /* clang-format on */
  1047. mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  1048. }
  1049. return ret;
  1050. }
  1051. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const
  1052. {
  1053. std::string flagTableName = this->ToolsetOptions.GetClFlagTableName(
  1054. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1055. this->DefaultCLFlagTableName);
  1056. return LoadFlagTable(flagTableName, "CL");
  1057. }
  1058. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable()
  1059. const
  1060. {
  1061. std::string flagTableName = this->ToolsetOptions.GetCSharpFlagTableName(
  1062. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1063. this->DefaultCSharpFlagTableName);
  1064. return LoadFlagTable(flagTableName, "CSharp");
  1065. }
  1066. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const
  1067. {
  1068. std::string flagTableName = this->ToolsetOptions.GetRcFlagTableName(
  1069. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1070. this->DefaultRCFlagTableName);
  1071. return LoadFlagTable(flagTableName, "RC");
  1072. }
  1073. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const
  1074. {
  1075. std::string flagTableName = this->ToolsetOptions.GetLibFlagTableName(
  1076. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1077. this->DefaultLibFlagTableName);
  1078. return LoadFlagTable(flagTableName, "LIB");
  1079. }
  1080. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const
  1081. {
  1082. std::string flagTableName = this->ToolsetOptions.GetLinkFlagTableName(
  1083. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1084. this->DefaultLinkFlagTableName);
  1085. return LoadFlagTable(flagTableName, "Link");
  1086. }
  1087. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaFlagTable() const
  1088. {
  1089. return LoadFlagTable(this->DefaultCudaFlagTableName, "Cuda");
  1090. }
  1091. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaHostFlagTable()
  1092. const
  1093. {
  1094. return LoadFlagTable(this->DefaultCudaHostFlagTableName, "CudaHost");
  1095. }
  1096. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const
  1097. {
  1098. std::string flagTableName = this->ToolsetOptions.GetMasmFlagTableName(
  1099. this->GetPlatformName(), this->GetPlatformToolsetString(),
  1100. this->DefaultMasmFlagTableName);
  1101. return LoadFlagTable(flagTableName, "MASM");
  1102. }
  1103. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const
  1104. {
  1105. return LoadFlagTable(this->DefaultNasmFlagTableName, "NASM");
  1106. }