cmGlobalVisualStudio10Generator.cxx 46 KB

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