cmGlobalVisualStudio10Generator.cxx 39 KB

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