cmGlobalVisualStudio10Generator.cxx 43 KB

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