cmGlobalVisualStudio10Generator.cxx 46 KB

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