cmGlobalVisualStudio10Generator.cxx 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  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 <cstring>
  6. #include <map>
  7. #include <sstream>
  8. #include <utility>
  9. #include <cm/memory>
  10. #include <cm3p/json/reader.h>
  11. #include <cm3p/json/value.h>
  12. #include "cmsys/FStream.hxx"
  13. #include "cmsys/Glob.hxx"
  14. #include "cmsys/RegularExpression.hxx"
  15. #include "cmDocumentationEntry.h"
  16. #include "cmGeneratorTarget.h"
  17. #include "cmGlobalGenerator.h"
  18. #include "cmGlobalGeneratorFactory.h"
  19. #include "cmGlobalVisualStudio71Generator.h"
  20. #include "cmGlobalVisualStudio7Generator.h"
  21. #include "cmGlobalVisualStudioGenerator.h"
  22. #include "cmIDEFlagTable.h"
  23. #include "cmLocalGenerator.h"
  24. #include "cmLocalVisualStudio10Generator.h"
  25. #include "cmMakefile.h"
  26. #include "cmMessageType.h"
  27. #include "cmSourceFile.h"
  28. #include "cmStringAlgorithms.h"
  29. #include "cmSystemTools.h"
  30. #include "cmVersion.h"
  31. #include "cmVisualStudioSlnData.h"
  32. #include "cmVisualStudioSlnParser.h"
  33. #include "cmXMLWriter.h"
  34. #include "cmake.h"
  35. static const char vs10generatorName[] = "Visual Studio 10 2010";
  36. static std::map<std::string, std::vector<cmIDEFlagTable>> loadedFlagJsonFiles;
  37. static void ConvertToWindowsSlashes(std::string& s)
  38. {
  39. // first convert all of the slashes
  40. for (auto& ch : s) {
  41. if (ch == '/') {
  42. ch = '\\';
  43. }
  44. }
  45. }
  46. // Map generator name without year to name with year.
  47. static const char* cmVS10GenName(const std::string& name, std::string& genName)
  48. {
  49. if (strncmp(name.c_str(), vs10generatorName,
  50. sizeof(vs10generatorName) - 6) != 0) {
  51. return 0;
  52. }
  53. const char* p = name.c_str() + sizeof(vs10generatorName) - 6;
  54. if (cmHasLiteralPrefix(p, " 2010")) {
  55. p += 5;
  56. }
  57. genName = std::string(vs10generatorName) + p;
  58. return p;
  59. }
  60. class cmGlobalVisualStudio10Generator::Factory
  61. : public cmGlobalGeneratorFactory
  62. {
  63. public:
  64. std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
  65. const std::string& name, bool allowArch, cmake* cm) const override
  66. {
  67. std::string genName;
  68. const char* p = cmVS10GenName(name, genName);
  69. if (!p) {
  70. return std::unique_ptr<cmGlobalGenerator>();
  71. }
  72. if (!*p) {
  73. return std::unique_ptr<cmGlobalGenerator>(
  74. new cmGlobalVisualStudio10Generator(cm, genName, ""));
  75. }
  76. if (!allowArch || *p++ != ' ') {
  77. return std::unique_ptr<cmGlobalGenerator>();
  78. }
  79. if (strcmp(p, "Win64") == 0) {
  80. return std::unique_ptr<cmGlobalGenerator>(
  81. new cmGlobalVisualStudio10Generator(cm, genName, "x64"));
  82. }
  83. if (strcmp(p, "IA64") == 0) {
  84. return std::unique_ptr<cmGlobalGenerator>(
  85. new cmGlobalVisualStudio10Generator(cm, genName, "Itanium"));
  86. }
  87. return std::unique_ptr<cmGlobalGenerator>();
  88. }
  89. void GetDocumentation(cmDocumentationEntry& entry) const override
  90. {
  91. entry.Name = std::string(vs10generatorName) + " [arch]";
  92. entry.Brief = "Deprecated. Generates Visual Studio 2010 project files. "
  93. "Optional [arch] can be \"Win64\" or \"IA64\".";
  94. }
  95. std::vector<std::string> GetGeneratorNames() const override
  96. {
  97. std::vector<std::string> names;
  98. names.push_back(vs10generatorName);
  99. return names;
  100. }
  101. std::vector<std::string> GetGeneratorNamesWithPlatform() const override
  102. {
  103. std::vector<std::string> names;
  104. names.push_back(vs10generatorName + std::string(" IA64"));
  105. names.push_back(vs10generatorName + std::string(" Win64"));
  106. return names;
  107. }
  108. bool SupportsToolset() const override { return true; }
  109. bool SupportsPlatform() const override { return true; }
  110. std::vector<std::string> GetKnownPlatforms() const override
  111. {
  112. std::vector<std::string> platforms;
  113. platforms.emplace_back("x64");
  114. platforms.emplace_back("Win32");
  115. platforms.emplace_back("Itanium");
  116. return platforms;
  117. }
  118. std::string GetDefaultPlatformName() const override { return "Win32"; }
  119. };
  120. std::unique_ptr<cmGlobalGeneratorFactory>
  121. cmGlobalVisualStudio10Generator::NewFactory()
  122. {
  123. return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory);
  124. }
  125. cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator(
  126. cmake* cm, const std::string& name,
  127. std::string const& platformInGeneratorName)
  128. : cmGlobalVisualStudio8Generator(cm, name, platformInGeneratorName)
  129. {
  130. std::string vc10Express;
  131. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  132. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\10.0\\Setup\\VC;"
  133. "ProductDir",
  134. vc10Express, cmSystemTools::KeyWOW64_32);
  135. this->CudaEnabled = false;
  136. {
  137. std::string envPlatformToolset;
  138. if (cmSystemTools::GetEnv("PlatformToolset", envPlatformToolset) &&
  139. envPlatformToolset == "Windows7.1SDK") {
  140. // We are running from a Windows7.1SDK command prompt.
  141. this->DefaultPlatformToolset = "Windows7.1SDK";
  142. } else {
  143. this->DefaultPlatformToolset = "v100";
  144. }
  145. }
  146. this->DefaultCLFlagTableName = "v10";
  147. this->DefaultCSharpFlagTableName = "v10";
  148. this->DefaultLibFlagTableName = "v10";
  149. this->DefaultLinkFlagTableName = "v10";
  150. this->DefaultCudaFlagTableName = "v10";
  151. this->DefaultCudaHostFlagTableName = "v10";
  152. this->DefaultMasmFlagTableName = "v10";
  153. this->DefaultNasmFlagTableName = "v10";
  154. this->DefaultRCFlagTableName = "v10";
  155. this->Version = VS10;
  156. this->PlatformToolsetNeedsDebugEnum = false;
  157. }
  158. bool cmGlobalVisualStudio10Generator::MatchesGeneratorName(
  159. const std::string& name) const
  160. {
  161. std::string genName;
  162. if (cmVS10GenName(name, genName)) {
  163. return genName == this->GetName();
  164. }
  165. return false;
  166. }
  167. bool cmGlobalVisualStudio10Generator::SetSystemName(std::string const& s,
  168. cmMakefile* mf)
  169. {
  170. this->SystemName = s;
  171. this->SystemVersion = mf->GetSafeDefinition("CMAKE_SYSTEM_VERSION");
  172. if (!this->InitializeSystem(mf)) {
  173. return false;
  174. }
  175. return this->cmGlobalVisualStudio8Generator::SetSystemName(s, mf);
  176. }
  177. bool cmGlobalVisualStudio10Generator::SetGeneratorPlatform(
  178. std::string const& p, cmMakefile* mf)
  179. {
  180. if (!this->cmGlobalVisualStudio8Generator::SetGeneratorPlatform(p, mf)) {
  181. return false;
  182. }
  183. if (this->GetPlatformName() == "Itanium" ||
  184. this->GetPlatformName() == "x64") {
  185. if (this->IsExpressEdition() && !this->Find64BitTools(mf)) {
  186. return false;
  187. }
  188. }
  189. return true;
  190. }
  191. static void cmCudaToolVersion(std::string& s)
  192. {
  193. // "CUDA x.y.props" => "x.y"
  194. s = s.substr(5);
  195. s = s.substr(0, s.size() - 6);
  196. }
  197. bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
  198. std::string const& ts, bool build, cmMakefile* mf)
  199. {
  200. if (this->SystemIsWindowsCE && ts.empty() &&
  201. this->DefaultPlatformToolset.empty()) {
  202. std::ostringstream e;
  203. e << this->GetName() << " Windows CE version '" << this->SystemVersion
  204. << "' requires CMAKE_GENERATOR_TOOLSET to be set.";
  205. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  206. return false;
  207. }
  208. if (!this->ParseGeneratorToolset(ts, mf)) {
  209. return false;
  210. }
  211. if (build) {
  212. return true;
  213. }
  214. if (this->CustomVCTargetsPath.empty() && !this->FindVCTargetsPath(mf)) {
  215. return false;
  216. }
  217. if (!this->CustomFlagTableDir.empty() &&
  218. !(cmSystemTools::FileIsFullPath(this->CustomFlagTableDir) &&
  219. cmSystemTools::FileIsDirectory(this->CustomFlagTableDir))) {
  220. std::ostringstream e;
  221. /* clang-format off */
  222. e <<
  223. "Generator\n"
  224. " " << this->GetName() << "\n"
  225. "given toolset\n"
  226. " customFlagTableDir=" << this->CustomFlagTableDir << "\n"
  227. "that is not an absolute path to an existing directory.";
  228. /* clang-format on */
  229. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  230. cmSystemTools::SetFatalErrorOccured();
  231. return false;
  232. }
  233. if (cmHasLiteralPrefix(this->GetPlatformToolsetString(), "v140")) {
  234. // The GenerateDebugInformation link setting for the v140 toolset
  235. // in VS 2015 was originally an enum with "No" and "Debug" values,
  236. // differing from the "false" and "true" values used in older toolsets.
  237. // A VS 2015 update changed it back. Parse the "link.xml" file to
  238. // discover which one we need.
  239. std::string const link_xml = this->VCTargetsPath + "/1033/link.xml";
  240. cmsys::ifstream fin(link_xml.c_str());
  241. std::string line;
  242. while (fin && cmSystemTools::GetLineFromStream(fin, line)) {
  243. if (line.find(" Switch=\"DEBUG\" ") != std::string::npos) {
  244. this->PlatformToolsetNeedsDebugEnum =
  245. line.find(" Name=\"Debug\" ") != std::string::npos;
  246. break;
  247. }
  248. }
  249. }
  250. this->SupportsUnityBuilds =
  251. this->Version >= cmGlobalVisualStudioGenerator::VS16 ||
  252. (this->Version == cmGlobalVisualStudioGenerator::VS15 &&
  253. cmSystemTools::PathExists(this->VCTargetsPath +
  254. "/Microsoft.Cpp.Unity.targets"));
  255. if (this->GeneratorToolsetCuda.empty()) {
  256. // Find the highest available version of the CUDA tools.
  257. std::vector<std::string> cudaTools;
  258. std::string bcDir;
  259. if (this->GeneratorToolsetCudaCustomDir.empty()) {
  260. bcDir = this->VCTargetsPath + "/BuildCustomizations";
  261. } else {
  262. bcDir = this->GetPlatformToolsetCudaCustomDirString() +
  263. this->GetPlatformToolsetCudaVSIntegrationSubdirString() +
  264. "extras\\visual_studio_integration\\MSBuildExtensions";
  265. cmSystemTools::ConvertToUnixSlashes(bcDir);
  266. }
  267. cmsys::Glob gl;
  268. gl.SetRelative(bcDir.c_str());
  269. if (gl.FindFiles(bcDir + "/CUDA *.props")) {
  270. cudaTools = gl.GetFiles();
  271. }
  272. if (!cudaTools.empty()) {
  273. std::for_each(cudaTools.begin(), cudaTools.end(), cmCudaToolVersion);
  274. std::sort(cudaTools.begin(), cudaTools.end(),
  275. cmSystemTools::VersionCompareGreater);
  276. this->GeneratorToolsetCuda = cudaTools.at(0);
  277. } else if (!this->GeneratorToolsetCudaCustomDir.empty()) {
  278. // Generate an error if Visual Studio integration files are not found
  279. // inside of custom cuda toolset.
  280. std::ostringstream e;
  281. /* clang-format off */
  282. e <<
  283. "Generator\n"
  284. " " << this->GetName() << "\n"
  285. "given toolset\n"
  286. " cuda=" << this->GeneratorToolsetCudaCustomDir << "\n"
  287. "cannot detect Visual Studio integration files in path\n"
  288. " " << bcDir;
  289. /* clang-format on */
  290. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  291. // Clear the configured tool-set
  292. this->GeneratorToolsetCuda.clear();
  293. }
  294. }
  295. if (!this->GeneratorToolsetVersion.empty() &&
  296. this->GeneratorToolsetVersion != "Test Toolset Version") {
  297. // If a specific minor version of the toolset was requested, verify that it
  298. // is compatible to the major version and that is exists on disk.
  299. // If not clear the value.
  300. std::string versionToolset = this->GeneratorToolsetVersion;
  301. cmsys::RegularExpression regex("[0-9][0-9]\\.[0-9][0-9]");
  302. if (regex.find(versionToolset)) {
  303. versionToolset = "v" + versionToolset.erase(2, 1);
  304. } else {
  305. // Version not recognized. Clear it.
  306. versionToolset.clear();
  307. }
  308. if (!cmHasPrefix(versionToolset, this->GetPlatformToolsetString())) {
  309. std::ostringstream e;
  310. /* clang-format off */
  311. e <<
  312. "Generator\n"
  313. " " << this->GetName() << "\n"
  314. "given toolset and version specification\n"
  315. " " << this->GetPlatformToolsetString() << ",version=" <<
  316. this->GeneratorToolsetVersion << "\n"
  317. "contains an invalid version specification."
  318. ;
  319. /* clang-format on */
  320. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  321. // Clear the configured tool-set
  322. this->GeneratorToolsetVersion.clear();
  323. }
  324. std::string auxProps;
  325. switch (this->FindAuxToolset(this->GeneratorToolsetVersion, auxProps)) {
  326. case AuxToolset::None:
  327. this->GeneratorToolsetVersionProps = {};
  328. break;
  329. case AuxToolset::Default:
  330. // The given version is the default toolset. Remove the setting.
  331. this->GeneratorToolsetVersion.clear();
  332. this->GeneratorToolsetVersionProps = {};
  333. break;
  334. case AuxToolset::PropsExist:
  335. this->GeneratorToolsetVersionProps = std::move(auxProps);
  336. break;
  337. case AuxToolset::PropsMissing: {
  338. std::ostringstream e;
  339. /* clang-format off */
  340. e <<
  341. "Generator\n"
  342. " " << this->GetName() << "\n"
  343. "given toolset and version specification\n"
  344. " " << this->GetPlatformToolsetString() << ",version=" <<
  345. this->GeneratorToolsetVersion << "\n"
  346. "does not seem to be installed at\n" <<
  347. " " << auxProps;
  348. ;
  349. /* clang-format on */
  350. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  351. // Clear the configured tool-set
  352. this->GeneratorToolsetVersion.clear();
  353. this->GeneratorToolsetVersionProps = {};
  354. } break;
  355. }
  356. }
  357. if (const char* toolset = this->GetPlatformToolset()) {
  358. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET", toolset);
  359. }
  360. if (!this->GeneratorToolsetVersion.empty()) {
  361. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VERSION",
  362. this->GeneratorToolsetVersion);
  363. }
  364. if (const char* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  365. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE", hostArch);
  366. }
  367. if (const char* cuda = this->GetPlatformToolsetCuda()) {
  368. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA", cuda);
  369. }
  370. if (const char* cudaDir = this->GetPlatformToolsetCudaCustomDir()) {
  371. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR", cudaDir);
  372. }
  373. if (const char* vcTargetsDir = this->GetCustomVCTargetsPath()) {
  374. mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VCTARGETS_CUSTOM_DIR",
  375. vcTargetsDir);
  376. }
  377. return true;
  378. }
  379. bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset(
  380. std::string const& ts, cmMakefile* mf)
  381. {
  382. std::vector<std::string> const fields = cmTokenize(ts, ",");
  383. std::vector<std::string>::const_iterator fi = fields.begin();
  384. if (fi == fields.end()) {
  385. return true;
  386. }
  387. // The first field may be the VS platform toolset.
  388. if (fi->find('=') == fi->npos) {
  389. this->GeneratorToolset = *fi;
  390. ++fi;
  391. }
  392. std::set<std::string> handled;
  393. // The rest of the fields must be key=value pairs.
  394. for (; fi != fields.end(); ++fi) {
  395. std::string::size_type pos = fi->find('=');
  396. if (pos == fi->npos) {
  397. std::ostringstream e;
  398. /* clang-format off */
  399. e <<
  400. "Generator\n"
  401. " " << this->GetName() << "\n"
  402. "given toolset specification\n"
  403. " " << ts << "\n"
  404. "that contains a field after the first ',' with no '='."
  405. ;
  406. /* clang-format on */
  407. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  408. return false;
  409. }
  410. std::string const key = fi->substr(0, pos);
  411. std::string const value = fi->substr(pos + 1);
  412. if (!handled.insert(key).second) {
  413. std::ostringstream e;
  414. /* clang-format off */
  415. e <<
  416. "Generator\n"
  417. " " << this->GetName() << "\n"
  418. "given toolset specification\n"
  419. " " << ts << "\n"
  420. "that contains duplicate field key '" << key << "'."
  421. ;
  422. /* clang-format on */
  423. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  424. return false;
  425. }
  426. if (!this->ProcessGeneratorToolsetField(key, value)) {
  427. std::ostringstream e;
  428. /* clang-format off */
  429. e <<
  430. "Generator\n"
  431. " " << this->GetName() << "\n"
  432. "given toolset specification\n"
  433. " " << ts << "\n"
  434. "that contains invalid field '" << *fi << "'."
  435. ;
  436. /* clang-format on */
  437. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  438. return false;
  439. }
  440. }
  441. return true;
  442. }
  443. bool cmGlobalVisualStudio10Generator::ProcessGeneratorToolsetField(
  444. std::string const& key, std::string const& value)
  445. {
  446. if (key == "cuda") {
  447. /* test if cuda toolset is path to custom dir or cuda version */
  448. auto pos = value.find_first_not_of("0123456789.");
  449. if (pos != std::string::npos) {
  450. this->GeneratorToolsetCudaCustomDir = value;
  451. /* ensure trailing backslash for easy path joining */
  452. if (this->GeneratorToolsetCudaCustomDir.back() != '\\') {
  453. this->GeneratorToolsetCudaCustomDir.push_back('\\');
  454. }
  455. /* check for legacy toolkit folder structure */
  456. if (cmsys::SystemTools::FileIsDirectory(
  457. cmStrCat(this->GeneratorToolsetCudaCustomDir, "nvcc"))) {
  458. this->GeneratorToolsetCudaNvccSubdir = "nvcc\\";
  459. }
  460. if (cmsys::SystemTools::FileIsDirectory(
  461. cmStrCat(this->GeneratorToolsetCudaCustomDir,
  462. "CUDAVisualStudioIntegration"))) {
  463. this->GeneratorToolsetCudaVSIntegrationSubdir =
  464. "CUDAVisualStudioIntegration\\";
  465. }
  466. } else {
  467. this->GeneratorToolsetCuda = value;
  468. }
  469. return true;
  470. }
  471. if (key == "customFlagTableDir") {
  472. this->CustomFlagTableDir = value;
  473. cmSystemTools::ConvertToUnixSlashes(this->CustomFlagTableDir);
  474. return true;
  475. }
  476. if (key == "version") {
  477. this->GeneratorToolsetVersion = value;
  478. return true;
  479. }
  480. if (key == "VCTargetsPath") {
  481. this->CustomVCTargetsPath = value;
  482. ConvertToWindowsSlashes(this->CustomVCTargetsPath);
  483. return true;
  484. }
  485. return false;
  486. }
  487. bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf)
  488. {
  489. if (this->SystemName == "Windows") {
  490. if (!this->InitializeWindows(mf)) {
  491. return false;
  492. }
  493. } else if (this->SystemName == "WindowsCE") {
  494. this->SystemIsWindowsCE = true;
  495. if (!this->InitializeWindowsCE(mf)) {
  496. return false;
  497. }
  498. } else if (this->SystemName == "WindowsPhone") {
  499. this->SystemIsWindowsPhone = true;
  500. if (!this->InitializeWindowsPhone(mf)) {
  501. return false;
  502. }
  503. } else if (this->SystemName == "WindowsStore") {
  504. this->SystemIsWindowsStore = true;
  505. if (!this->InitializeWindowsStore(mf)) {
  506. return false;
  507. }
  508. } else if (this->SystemName == "Android") {
  509. if (this->PlatformInGeneratorName) {
  510. std::ostringstream e;
  511. e << "CMAKE_SYSTEM_NAME is 'Android' but CMAKE_GENERATOR "
  512. << "specifies a platform too: '" << this->GetName() << "'";
  513. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  514. return false;
  515. }
  516. if (mf->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM") == "Tegra-Android") {
  517. if (!this->InitializeTegraAndroid(mf)) {
  518. return false;
  519. }
  520. } else {
  521. this->SystemIsAndroid = true;
  522. if (!this->InitializeAndroid(mf)) {
  523. return false;
  524. }
  525. }
  526. }
  527. return true;
  528. }
  529. bool cmGlobalVisualStudio10Generator::InitializeWindows(cmMakefile*)
  530. {
  531. return true;
  532. }
  533. bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile* mf)
  534. {
  535. if (this->PlatformInGeneratorName) {
  536. std::ostringstream e;
  537. e << "CMAKE_SYSTEM_NAME is 'WindowsCE' but CMAKE_GENERATOR "
  538. << "specifies a platform too: '" << this->GetName() << "'";
  539. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  540. return false;
  541. }
  542. this->DefaultPlatformToolset = this->SelectWindowsCEToolset();
  543. if (this->GetVersion() == cmGlobalVisualStudioGenerator::VS12) {
  544. // VS 12 .NET CF defaults to .NET framework 3.9 for Windows CE.
  545. this->DefaultTargetFrameworkVersion = "v3.9";
  546. this->DefaultTargetFrameworkIdentifier = "WindowsEmbeddedCompact";
  547. this->DefaultTargetFrameworkTargetsVersion = "v8.0";
  548. }
  549. return true;
  550. }
  551. bool cmGlobalVisualStudio10Generator::InitializeWindowsPhone(cmMakefile* mf)
  552. {
  553. std::ostringstream e;
  554. e << this->GetName() << " does not support Windows Phone.";
  555. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  556. return false;
  557. }
  558. bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf)
  559. {
  560. std::ostringstream e;
  561. e << this->GetName() << " does not support Windows Store.";
  562. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  563. return false;
  564. }
  565. bool cmGlobalVisualStudio10Generator::InitializeTegraAndroid(cmMakefile* mf)
  566. {
  567. std::string v = this->GetInstalledNsightTegraVersion();
  568. if (v.empty()) {
  569. mf->IssueMessage(MessageType::FATAL_ERROR,
  570. "CMAKE_SYSTEM_NAME is 'Android' but "
  571. "'NVIDIA Nsight Tegra Visual Studio Edition' "
  572. "is not installed.");
  573. return false;
  574. }
  575. this->DefaultPlatformName = "Tegra-Android";
  576. this->DefaultPlatformToolset = "Default";
  577. this->NsightTegraVersion = v;
  578. mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v);
  579. return true;
  580. }
  581. bool cmGlobalVisualStudio10Generator::InitializeAndroid(cmMakefile* mf)
  582. {
  583. std::ostringstream e;
  584. e << this->GetName() << " does not support Android.";
  585. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  586. return false;
  587. }
  588. bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
  589. std::string& toolset) const
  590. {
  591. toolset.clear();
  592. return false;
  593. }
  594. bool cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset(
  595. std::string& toolset) const
  596. {
  597. toolset.clear();
  598. return false;
  599. }
  600. std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const
  601. {
  602. if (this->SystemVersion == "8.0") {
  603. return "CE800";
  604. }
  605. return "";
  606. }
  607. //! Create a local generator appropriate to this Global Generator
  608. std::unique_ptr<cmLocalGenerator>
  609. cmGlobalVisualStudio10Generator::CreateLocalGenerator(cmMakefile* mf)
  610. {
  611. return std::unique_ptr<cmLocalGenerator>(
  612. cm::make_unique<cmLocalVisualStudio10Generator>(this, mf));
  613. }
  614. void cmGlobalVisualStudio10Generator::Generate()
  615. {
  616. this->LongestSource = LongestSourcePath();
  617. this->cmGlobalVisualStudio8Generator::Generate();
  618. if (!this->AndroidExecutableWarnings.empty() &&
  619. !this->CMakeInstance->GetIsInTryCompile()) {
  620. std::ostringstream e;
  621. /* clang-format off */
  622. e <<
  623. "You are using Visual Studio tools for Android, which does not support "
  624. "standalone executables. However, the following executable targets do "
  625. "not have the ANDROID_GUI property set, and thus will not be built as "
  626. "expected. They will be built as shared libraries with executable "
  627. "filenames:\n"
  628. " ";
  629. /* clang-format on */
  630. bool first = true;
  631. for (auto const& name : this->AndroidExecutableWarnings) {
  632. if (!first) {
  633. e << ", ";
  634. }
  635. first = false;
  636. e << name;
  637. }
  638. this->CMakeInstance->IssueMessage(MessageType::WARNING, e.str());
  639. }
  640. if (this->LongestSource.Length > 0) {
  641. cmLocalGenerator* lg = this->LongestSource.Target->GetLocalGenerator();
  642. std::ostringstream e;
  643. /* clang-format off */
  644. e <<
  645. "The binary and/or source directory paths may be too long to generate "
  646. "Visual Studio 10 files for this project. "
  647. "Consider choosing shorter directory names to build this project with "
  648. "Visual Studio 10. "
  649. "A more detailed explanation follows."
  650. "\n"
  651. "There is a bug in the VS 10 IDE that renders property dialog fields "
  652. "blank for files referenced by full path in the project file. "
  653. "However, CMake must reference at least one file by full path:\n"
  654. " " << this->LongestSource.SourceFile->GetFullPath() << "\n"
  655. "This is because some Visual Studio tools would append the relative "
  656. "path to the end of the referencing directory path, as in:\n"
  657. " " << lg->GetCurrentBinaryDirectory() << "/"
  658. << this->LongestSource.SourceRel << "\n"
  659. "and then incorrectly complain that the file does not exist because "
  660. "the path length is too long for some internal buffer or API. "
  661. "To avoid this problem CMake must use a full path for this file "
  662. "which then triggers the VS 10 property dialog bug.";
  663. /* clang-format on */
  664. lg->IssueMessage(MessageType::WARNING, e.str());
  665. }
  666. }
  667. void cmGlobalVisualStudio10Generator::EnableLanguage(
  668. std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
  669. {
  670. for (std::string const& it : lang) {
  671. if (it == "ASM_NASM") {
  672. this->NasmEnabled = true;
  673. }
  674. if (it == "CUDA") {
  675. this->CudaEnabled = true;
  676. }
  677. }
  678. this->AddPlatformDefinitions(mf);
  679. cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
  680. }
  681. const char* cmGlobalVisualStudio10Generator::GetCustomVCTargetsPath() const
  682. {
  683. if (this->CustomVCTargetsPath.empty()) {
  684. return nullptr;
  685. }
  686. return this->CustomVCTargetsPath.c_str();
  687. }
  688. const char* cmGlobalVisualStudio10Generator::GetPlatformToolset() const
  689. {
  690. std::string const& toolset = this->GetPlatformToolsetString();
  691. if (toolset.empty()) {
  692. return nullptr;
  693. }
  694. return toolset.c_str();
  695. }
  696. std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString()
  697. const
  698. {
  699. if (!this->GeneratorToolset.empty()) {
  700. return this->GeneratorToolset;
  701. }
  702. if (this->SystemIsAndroid) {
  703. if (!this->DefaultAndroidToolset.empty()) {
  704. return this->DefaultAndroidToolset;
  705. }
  706. } else {
  707. if (!this->DefaultPlatformToolset.empty()) {
  708. return this->DefaultPlatformToolset;
  709. }
  710. }
  711. static std::string const empty;
  712. return empty;
  713. }
  714. std::string const&
  715. cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionProps() const
  716. {
  717. return this->GeneratorToolsetVersionProps;
  718. }
  719. const char*
  720. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const
  721. {
  722. std::string const& hostArch =
  723. this->GetPlatformToolsetHostArchitectureString();
  724. if (hostArch.empty()) {
  725. return nullptr;
  726. }
  727. return hostArch.c_str();
  728. }
  729. std::string const&
  730. cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitectureString()
  731. const
  732. {
  733. if (!this->GeneratorToolsetHostArchitecture.empty()) {
  734. return this->GeneratorToolsetHostArchitecture;
  735. }
  736. if (!this->DefaultPlatformToolsetHostArchitecture.empty()) {
  737. return this->DefaultPlatformToolsetHostArchitecture;
  738. }
  739. static std::string const empty;
  740. return empty;
  741. }
  742. const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
  743. {
  744. if (!this->GeneratorToolsetCuda.empty()) {
  745. return this->GeneratorToolsetCuda.c_str();
  746. }
  747. return nullptr;
  748. }
  749. std::string const&
  750. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaString() const
  751. {
  752. return this->GeneratorToolsetCuda;
  753. }
  754. const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDir()
  755. const
  756. {
  757. if (!this->GeneratorToolsetCudaCustomDir.empty()) {
  758. return this->GeneratorToolsetCudaCustomDir.c_str();
  759. }
  760. return nullptr;
  761. }
  762. std::string const&
  763. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDirString() const
  764. {
  765. return this->GeneratorToolsetCudaCustomDir;
  766. }
  767. std::string const&
  768. cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaNvccSubdirString() const
  769. {
  770. return this->GeneratorToolsetCudaNvccSubdir;
  771. }
  772. std::string const& cmGlobalVisualStudio10Generator::
  773. GetPlatformToolsetCudaVSIntegrationSubdirString() const
  774. {
  775. return this->GeneratorToolsetCudaVSIntegrationSubdir;
  776. }
  777. cmGlobalVisualStudio10Generator::AuxToolset
  778. cmGlobalVisualStudio10Generator::FindAuxToolset(std::string&,
  779. std::string&) const
  780. {
  781. return AuxToolset::None;
  782. }
  783. bool cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf)
  784. {
  785. if (!this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf)) {
  786. return false;
  787. }
  788. mf->AddDefinition("CMAKE_VS_MSBUILD_COMMAND", this->GetMSBuildCommand());
  789. return true;
  790. }
  791. std::string const& cmGlobalVisualStudio10Generator::GetMSBuildCommand()
  792. {
  793. if (!this->MSBuildCommandInitialized) {
  794. this->MSBuildCommandInitialized = true;
  795. this->MSBuildCommand = this->FindMSBuildCommand();
  796. }
  797. return this->MSBuildCommand;
  798. }
  799. cm::optional<std::string>
  800. cmGlobalVisualStudio10Generator::FindMSBuildCommandEarly(cmMakefile*)
  801. {
  802. return this->GetMSBuildCommand();
  803. }
  804. std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand()
  805. {
  806. std::string msbuild;
  807. std::string mskey;
  808. // Search in standard location.
  809. mskey = cmStrCat(
  810. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\",
  811. this->GetToolsVersion(), ";MSBuildToolsPath");
  812. if (cmSystemTools::ReadRegistryValue(mskey.c_str(), msbuild,
  813. cmSystemTools::KeyWOW64_32)) {
  814. cmSystemTools::ConvertToUnixSlashes(msbuild);
  815. msbuild += "/MSBuild.exe";
  816. if (cmSystemTools::FileExists(msbuild, true)) {
  817. return msbuild;
  818. }
  819. }
  820. msbuild = "MSBuild.exe";
  821. return msbuild;
  822. }
  823. std::string cmGlobalVisualStudio10Generator::FindDevEnvCommand()
  824. {
  825. if (this->ExpressEdition) {
  826. // Visual Studio Express >= 10 do not have "devenv.com" or
  827. // "VCExpress.exe" that we can use to build reliably.
  828. // Tell the caller it needs to use MSBuild instead.
  829. return "";
  830. }
  831. // Skip over the cmGlobalVisualStudio8Generator implementation because
  832. // we expect a real devenv and do not want to look for VCExpress.
  833. return this->cmGlobalVisualStudio71Generator::FindDevEnvCommand();
  834. }
  835. bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
  836. {
  837. // Skip this in special cases within our own test suite.
  838. if (this->GetPlatformName() == "Test Platform" ||
  839. this->GetPlatformToolsetString() == "Test Toolset") {
  840. return true;
  841. }
  842. std::string wd;
  843. if (!this->ConfiguredFilesPath.empty()) {
  844. // In a try-compile we are given the outer CMakeFiles directory.
  845. wd = this->ConfiguredFilesPath;
  846. } else {
  847. wd = cmStrCat(this->GetCMakeInstance()->GetHomeOutputDirectory(),
  848. "/CMakeFiles");
  849. }
  850. wd += "/";
  851. wd += cmVersion::GetCMakeVersion();
  852. // We record the result persistently in a file.
  853. std::string const txt = wd + "/VCTargetsPath.txt";
  854. // If we have a recorded result, use it.
  855. {
  856. cmsys::ifstream fin(txt.c_str());
  857. if (fin && cmSystemTools::GetLineFromStream(fin, this->VCTargetsPath) &&
  858. cmSystemTools::FileIsDirectory(this->VCTargetsPath)) {
  859. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  860. return true;
  861. }
  862. }
  863. // Prepare the work directory.
  864. if (!cmSystemTools::MakeDirectory(wd)) {
  865. std::string e = "Failed to make directory:\n " + wd;
  866. mf->IssueMessage(MessageType::FATAL_ERROR, e);
  867. cmSystemTools::SetFatalErrorOccured();
  868. return false;
  869. }
  870. // Generate a project file for MSBuild to tell us the VCTargetsPath value.
  871. std::string const vcxproj = "VCTargetsPath.vcxproj";
  872. {
  873. std::string const vcxprojAbs = wd + "/" + vcxproj;
  874. cmsys::ofstream fout(vcxprojAbs.c_str());
  875. cmXMLWriter xw(fout);
  876. cmXMLDocument doc(xw);
  877. cmXMLElement eprj(doc, "Project");
  878. eprj.Attribute("DefaultTargets", "Build");
  879. eprj.Attribute("ToolsVersion", "4.0");
  880. eprj.Attribute("xmlns",
  881. "http://schemas.microsoft.com/developer/msbuild/2003");
  882. if (this->IsNsightTegra()) {
  883. cmXMLElement epg(eprj, "PropertyGroup");
  884. epg.Attribute("Label", "NsightTegraProject");
  885. cmXMLElement(epg, "NsightTegraProjectRevisionNumber").Content("6");
  886. }
  887. {
  888. cmXMLElement eig(eprj, "ItemGroup");
  889. eig.Attribute("Label", "ProjectConfigurations");
  890. cmXMLElement epc(eig, "ProjectConfiguration");
  891. epc.Attribute("Include", "Debug|" + this->GetPlatformName());
  892. cmXMLElement(epc, "Configuration").Content("Debug");
  893. cmXMLElement(epc, "Platform").Content(this->GetPlatformName());
  894. }
  895. {
  896. cmXMLElement epg(eprj, "PropertyGroup");
  897. epg.Attribute("Label", "Globals");
  898. cmXMLElement(epg, "ProjectGuid")
  899. .Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}");
  900. cmXMLElement(epg, "Keyword")
  901. .Content(mf->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Android"
  902. ? "Android"
  903. : "Win32Proj");
  904. cmXMLElement(epg, "Platform").Content(this->GetPlatformName());
  905. if (this->GetSystemName() == "WindowsPhone") {
  906. cmXMLElement(epg, "ApplicationType").Content("Windows Phone");
  907. cmXMLElement(epg, "ApplicationTypeRevision")
  908. .Content(this->GetApplicationTypeRevision());
  909. } else if (this->GetSystemName() == "WindowsStore") {
  910. cmXMLElement(epg, "ApplicationType").Content("Windows Store");
  911. cmXMLElement(epg, "ApplicationTypeRevision")
  912. .Content(this->GetApplicationTypeRevision());
  913. } else if (this->GetSystemName() == "Android") {
  914. cmXMLElement(epg, "ApplicationType").Content("Android");
  915. cmXMLElement(epg, "ApplicationTypeRevision")
  916. .Content(this->GetApplicationTypeRevision());
  917. }
  918. if (!this->WindowsTargetPlatformVersion.empty()) {
  919. cmXMLElement(epg, "WindowsTargetPlatformVersion")
  920. .Content(this->WindowsTargetPlatformVersion);
  921. }
  922. if (this->GetSystemName() != "Android") {
  923. if (this->GetPlatformName() == "ARM64") {
  924. cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true");
  925. } else if (this->GetPlatformName() == "ARM") {
  926. cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true");
  927. }
  928. }
  929. }
  930. cmXMLElement(eprj, "Import")
  931. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  932. if (const char* hostArch = this->GetPlatformToolsetHostArchitecture()) {
  933. cmXMLElement epg(eprj, "PropertyGroup");
  934. cmXMLElement(epg, "PreferredToolArchitecture").Content(hostArch);
  935. }
  936. {
  937. cmXMLElement epg(eprj, "PropertyGroup");
  938. epg.Attribute("Label", "Configuration");
  939. {
  940. cmXMLElement ect(epg, "ConfigurationType");
  941. if (this->IsNsightTegra()) {
  942. // Tegra-Android platform does not understand "Utility".
  943. ect.Content("StaticLibrary");
  944. } else {
  945. ect.Content("Utility");
  946. }
  947. }
  948. cmXMLElement(epg, "CharacterSet").Content("MultiByte");
  949. if (this->IsNsightTegra()) {
  950. cmXMLElement(epg, "NdkToolchainVersion")
  951. .Content(this->GetPlatformToolsetString());
  952. } else {
  953. cmXMLElement(epg, "PlatformToolset")
  954. .Content(this->GetPlatformToolsetString());
  955. }
  956. }
  957. cmXMLElement(eprj, "Import")
  958. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  959. {
  960. cmXMLElement eidg(eprj, "ItemDefinitionGroup");
  961. cmXMLElement epbe(eidg, "PostBuildEvent");
  962. cmXMLElement(epbe, "Command")
  963. .Content("echo VCTargetsPath=$(VCTargetsPath)");
  964. }
  965. cmXMLElement(eprj, "Import")
  966. .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  967. }
  968. std::vector<std::string> cmd;
  969. cmd.push_back(this->GetMSBuildCommand());
  970. cmd.push_back(vcxproj);
  971. cmd.push_back("/p:Configuration=Debug");
  972. cmd.push_back(cmStrCat("/p:Platform=", this->GetPlatformName()));
  973. cmd.push_back(std::string("/p:VisualStudioVersion=") +
  974. this->GetIDEVersion());
  975. std::string out;
  976. int ret = 0;
  977. cmsys::RegularExpression regex("\n *VCTargetsPath=([^%\r\n]+)[\r\n]");
  978. if (!cmSystemTools::RunSingleCommand(cmd, &out, &out, &ret, wd.c_str(),
  979. cmSystemTools::OUTPUT_NONE) ||
  980. ret != 0 || !regex.find(out)) {
  981. cmSystemTools::ReplaceString(out, "\n", "\n ");
  982. std::ostringstream e;
  983. /* clang-format off */
  984. e <<
  985. "Failed to run MSBuild command:\n"
  986. " " << cmd[0] << "\n"
  987. "to get the value of VCTargetsPath:\n"
  988. " " << out << "\n"
  989. ;
  990. /* clang-format on */
  991. if (ret != 0) {
  992. e << "Exit code: " << ret << "\n";
  993. }
  994. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  995. cmSystemTools::SetFatalErrorOccured();
  996. return false;
  997. }
  998. this->VCTargetsPath = regex.match(1);
  999. cmSystemTools::ConvertToUnixSlashes(this->VCTargetsPath);
  1000. {
  1001. cmsys::ofstream fout(txt.c_str());
  1002. fout << this->VCTargetsPath << "\n";
  1003. }
  1004. return true;
  1005. }
  1006. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  1007. cmGlobalVisualStudio10Generator::GenerateBuildCommand(
  1008. const std::string& makeProgram, const std::string& projectName,
  1009. const std::string& projectDir, std::vector<std::string> const& targetNames,
  1010. const std::string& config, int jobs, bool verbose,
  1011. const cmBuildOptions& buildOptions,
  1012. std::vector<std::string> const& makeOptions)
  1013. {
  1014. std::vector<GeneratedMakeCommand> makeCommands;
  1015. // Select the caller- or user-preferred make program, else MSBuild.
  1016. std::string makeProgramSelected =
  1017. this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand());
  1018. // Check if the caller explicitly requested a devenv tool.
  1019. std::string makeProgramLower = makeProgramSelected;
  1020. cmSystemTools::LowerCase(makeProgramLower);
  1021. bool useDevEnv = (makeProgramLower.find("devenv") != std::string::npos ||
  1022. makeProgramLower.find("vcexpress") != std::string::npos);
  1023. // Workaround to convince VCExpress.exe to produce output.
  1024. const bool requiresOutputForward =
  1025. (makeProgramLower.find("vcexpress") != std::string::npos);
  1026. // MSBuild is preferred (and required for VS Express), but if the .sln has
  1027. // an Intel Fortran .vfproj then we have to use devenv. Parse it to find out.
  1028. cmSlnData slnData;
  1029. {
  1030. std::string slnFile;
  1031. if (!projectDir.empty()) {
  1032. slnFile = cmStrCat(projectDir, '/');
  1033. }
  1034. slnFile += projectName;
  1035. slnFile += ".sln";
  1036. cmVisualStudioSlnParser parser;
  1037. if (parser.ParseFile(slnFile, slnData,
  1038. cmVisualStudioSlnParser::DataGroupProjects)) {
  1039. std::vector<cmSlnProjectEntry> slnProjects = slnData.GetProjects();
  1040. for (cmSlnProjectEntry const& project : slnProjects) {
  1041. if (useDevEnv) {
  1042. break;
  1043. }
  1044. std::string proj = project.GetRelativePath();
  1045. if (proj.size() > 7 && proj.substr(proj.size() - 7) == ".vfproj") {
  1046. useDevEnv = true;
  1047. }
  1048. }
  1049. }
  1050. }
  1051. if (useDevEnv) {
  1052. // Use devenv to build solutions containing Intel Fortran projects.
  1053. return cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  1054. makeProgram, projectName, projectDir, targetNames, config, jobs, verbose,
  1055. buildOptions, makeOptions);
  1056. }
  1057. std::vector<std::string> realTargetNames = targetNames;
  1058. if (targetNames.empty() ||
  1059. ((targetNames.size() == 1) && targetNames.front().empty())) {
  1060. realTargetNames = { "ALL_BUILD" };
  1061. }
  1062. for (const auto& tname : realTargetNames) {
  1063. // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug
  1064. // /target:ALL_BUILD
  1065. // /m
  1066. if (tname.empty()) {
  1067. continue;
  1068. }
  1069. GeneratedMakeCommand makeCommand;
  1070. makeCommand.RequiresOutputForward = requiresOutputForward;
  1071. makeCommand.Add(makeProgramSelected);
  1072. if (tname == "clean") {
  1073. makeCommand.Add(std::string(projectName) + ".sln");
  1074. makeCommand.Add("/t:Clean");
  1075. } else {
  1076. std::string targetProject = cmStrCat(tname, ".vcxproj");
  1077. if (targetProject.find('/') == std::string::npos) {
  1078. // it might be in a subdir
  1079. if (cmSlnProjectEntry const* proj = slnData.GetProjectByName(tname)) {
  1080. targetProject = proj->GetRelativePath();
  1081. cmSystemTools::ConvertToUnixSlashes(targetProject);
  1082. }
  1083. }
  1084. makeCommand.Add(targetProject);
  1085. // Check if we do need a restore at all (i.e. if there are package
  1086. // references and restore has not been disabled by a command line option.
  1087. PackageResolveMode restoreMode = buildOptions.ResolveMode;
  1088. bool requiresRestore = true;
  1089. if (restoreMode == PackageResolveMode::Disable) {
  1090. requiresRestore = false;
  1091. } else if (cmValue cached =
  1092. this->CMakeInstance->GetState()->GetCacheEntryValue(
  1093. tname + "_REQUIRES_VS_PACKAGE_RESTORE")) {
  1094. requiresRestore = cached.IsOn();
  1095. } else {
  1096. // There are no package references defined.
  1097. requiresRestore = false;
  1098. }
  1099. // If a restore is required, evaluate the restore mode.
  1100. if (requiresRestore) {
  1101. if (restoreMode == PackageResolveMode::OnlyResolve) {
  1102. // Only invoke the restore target on the project.
  1103. makeCommand.Add("/t:Restore");
  1104. } else {
  1105. // Invoke restore target, unless it has been explicitly disabled.
  1106. bool restorePackages = true;
  1107. if (this->Version < VS15) {
  1108. // Package restore is only supported starting from Visual Studio
  1109. // 2017. Package restore must be executed manually using NuGet
  1110. // shell for older versions.
  1111. this->CMakeInstance->IssueMessage(
  1112. MessageType::WARNING,
  1113. "Restoring package references is only supported for Visual "
  1114. "Studio 2017 and later. You have to manually restore the "
  1115. "packages using NuGet before building the project.");
  1116. restorePackages = false;
  1117. } else if (restoreMode == PackageResolveMode::FromCacheVariable) {
  1118. // Decide if a restore is performed, based on a cache variable.
  1119. if (cmValue cached =
  1120. this->CMakeInstance->GetState()->GetCacheEntryValue(
  1121. "CMAKE_VS_NUGET_PACKAGE_RESTORE"))
  1122. restorePackages = cached.IsOn();
  1123. }
  1124. if (restorePackages) {
  1125. if (this->IsMsBuildRestoreSupported()) {
  1126. makeCommand.Add("/restore");
  1127. } else {
  1128. GeneratedMakeCommand restoreCommand;
  1129. restoreCommand.Add(makeProgramSelected);
  1130. restoreCommand.Add(targetProject);
  1131. restoreCommand.Add("/t:Restore");
  1132. makeCommands.emplace_back(restoreCommand);
  1133. }
  1134. }
  1135. }
  1136. }
  1137. }
  1138. std::string configArg = "/p:Configuration=";
  1139. if (!config.empty()) {
  1140. configArg += config;
  1141. } else {
  1142. configArg += "Debug";
  1143. }
  1144. makeCommand.Add(configArg);
  1145. makeCommand.Add(std::string("/p:Platform=") + this->GetPlatformName());
  1146. makeCommand.Add(std::string("/p:VisualStudioVersion=") +
  1147. this->GetIDEVersion());
  1148. if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
  1149. if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
  1150. makeCommand.Add("/m");
  1151. } else {
  1152. makeCommand.Add(std::string("/m:") + std::to_string(jobs));
  1153. }
  1154. // Having msbuild.exe and cl.exe using multiple jobs is discouraged
  1155. makeCommand.Add("/p:CL_MPCount=1");
  1156. }
  1157. // Respect the verbosity: 'n' normal will show build commands
  1158. // 'm' minimal only the build step's title
  1159. makeCommand.Add(std::string("/v:") + ((verbose) ? "n" : "m"));
  1160. makeCommand.Add(makeOptions.begin(), makeOptions.end());
  1161. makeCommands.emplace_back(std::move(makeCommand));
  1162. }
  1163. return makeCommands;
  1164. }
  1165. bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
  1166. {
  1167. if (this->DefaultPlatformToolset == "v100") {
  1168. // The v100 64-bit toolset does not exist in the express edition.
  1169. this->DefaultPlatformToolset.clear();
  1170. }
  1171. if (this->GetPlatformToolset()) {
  1172. return true;
  1173. }
  1174. // This edition does not come with 64-bit tools. Look for them.
  1175. //
  1176. // TODO: Detect available tools? x64\v100 exists but does not work?
  1177. // HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0;VCTargetsPath
  1178. // c:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/Platforms/
  1179. // {Itanium,Win32,x64}/PlatformToolsets/{v100,v90,Windows7.1SDK}
  1180. std::string winSDK_7_1;
  1181. if (cmSystemTools::ReadRegistryValue(
  1182. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\"
  1183. "Windows\\v7.1;InstallationFolder",
  1184. winSDK_7_1)) {
  1185. std::ostringstream m;
  1186. m << "Found Windows SDK v7.1: " << winSDK_7_1;
  1187. mf->DisplayStatus(m.str(), -1);
  1188. this->DefaultPlatformToolset = "Windows7.1SDK";
  1189. return true;
  1190. } else {
  1191. std::ostringstream e;
  1192. /* clang-format off */
  1193. e << "Cannot enable 64-bit tools with Visual Studio 2010 Express.\n"
  1194. << "Install the Microsoft Windows SDK v7.1 to get 64-bit tools:\n"
  1195. << " http://msdn.microsoft.com/en-us/windows/bb980924.aspx";
  1196. /* clang-format on */
  1197. mf->IssueMessage(MessageType::FATAL_ERROR, e.str().c_str());
  1198. cmSystemTools::SetFatalErrorOccured();
  1199. return false;
  1200. }
  1201. }
  1202. std::string cmGlobalVisualStudio10Generator::GenerateRuleFile(
  1203. std::string const& output) const
  1204. {
  1205. // The VS 10 generator needs to create the .rule files on disk.
  1206. // Hide them away under the CMakeFiles directory.
  1207. std::string ruleDir = cmStrCat(
  1208. this->GetCMakeInstance()->GetHomeOutputDirectory(), "/CMakeFiles/",
  1209. cmSystemTools::ComputeStringMD5(cmSystemTools::GetFilenamePath(output)));
  1210. std::string ruleFile =
  1211. cmStrCat(ruleDir, '/', cmSystemTools::GetFilenameName(output), ".rule");
  1212. return ruleFile;
  1213. }
  1214. void cmGlobalVisualStudio10Generator::PathTooLong(cmGeneratorTarget* target,
  1215. cmSourceFile const* sf,
  1216. std::string const& sfRel)
  1217. {
  1218. size_t len =
  1219. (target->GetLocalGenerator()->GetCurrentBinaryDirectory().length() + 1 +
  1220. sfRel.length());
  1221. if (len > this->LongestSource.Length) {
  1222. this->LongestSource.Length = len;
  1223. this->LongestSource.Target = target;
  1224. this->LongestSource.SourceFile = sf;
  1225. this->LongestSource.SourceRel = sfRel;
  1226. }
  1227. }
  1228. std::string cmGlobalVisualStudio10Generator::Encoding()
  1229. {
  1230. return "utf-8";
  1231. }
  1232. const char* cmGlobalVisualStudio10Generator::GetToolsVersion() const
  1233. {
  1234. switch (this->Version) {
  1235. case cmGlobalVisualStudioGenerator::VS9:
  1236. case cmGlobalVisualStudioGenerator::VS10:
  1237. case cmGlobalVisualStudioGenerator::VS11:
  1238. return "4.0";
  1239. // in Visual Studio 2013 they detached the MSBuild tools version
  1240. // from the .Net Framework version and instead made it have it's own
  1241. // version number
  1242. case cmGlobalVisualStudioGenerator::VS12:
  1243. return "12.0";
  1244. case cmGlobalVisualStudioGenerator::VS14:
  1245. return "14.0";
  1246. case cmGlobalVisualStudioGenerator::VS15:
  1247. return "15.0";
  1248. case cmGlobalVisualStudioGenerator::VS16:
  1249. return "16.0";
  1250. case cmGlobalVisualStudioGenerator::VS17:
  1251. return "17.0";
  1252. }
  1253. return "";
  1254. }
  1255. bool cmGlobalVisualStudio10Generator::IsNsightTegra() const
  1256. {
  1257. return !this->NsightTegraVersion.empty();
  1258. }
  1259. std::string cmGlobalVisualStudio10Generator::GetNsightTegraVersion() const
  1260. {
  1261. return this->NsightTegraVersion;
  1262. }
  1263. std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
  1264. {
  1265. std::string version;
  1266. cmSystemTools::ReadRegistryValue(
  1267. "HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;"
  1268. "Version",
  1269. version, cmSystemTools::KeyWOW64_32);
  1270. return version;
  1271. }
  1272. std::string cmGlobalVisualStudio10Generator::GetApplicationTypeRevision() const
  1273. {
  1274. if (this->GetSystemName() == "Android") {
  1275. return this->GetAndroidApplicationTypeRevision();
  1276. }
  1277. // Return the first two '.'-separated components of the Windows version.
  1278. std::string::size_type end1 = this->SystemVersion.find('.');
  1279. std::string::size_type end2 =
  1280. end1 == std::string::npos ? end1 : this->SystemVersion.find('.', end1 + 1);
  1281. return this->SystemVersion.substr(0, end2);
  1282. }
  1283. static std::string cmLoadFlagTableString(Json::Value entry, const char* field)
  1284. {
  1285. if (entry.isMember(field)) {
  1286. auto string = entry[field];
  1287. if (string.isConvertibleTo(Json::ValueType::stringValue)) {
  1288. return string.asString();
  1289. }
  1290. }
  1291. return "";
  1292. }
  1293. static unsigned int cmLoadFlagTableSpecial(Json::Value entry,
  1294. const char* field)
  1295. {
  1296. unsigned int value = 0;
  1297. if (entry.isMember(field)) {
  1298. auto specials = entry[field];
  1299. if (specials.isArray()) {
  1300. for (auto const& special : specials) {
  1301. std::string s = special.asString();
  1302. if (s == "UserValue") {
  1303. value |= cmIDEFlagTable::UserValue;
  1304. } else if (s == "UserIgnored") {
  1305. value |= cmIDEFlagTable::UserIgnored;
  1306. } else if (s == "UserRequired") {
  1307. value |= cmIDEFlagTable::UserRequired;
  1308. } else if (s == "Continue") {
  1309. value |= cmIDEFlagTable::Continue;
  1310. } else if (s == "SemicolonAppendable") {
  1311. value |= cmIDEFlagTable::SemicolonAppendable;
  1312. } else if (s == "UserFollowing") {
  1313. value |= cmIDEFlagTable::UserFollowing;
  1314. } else if (s == "CaseInsensitive") {
  1315. value |= cmIDEFlagTable::CaseInsensitive;
  1316. } else if (s == "SpaceAppendable") {
  1317. value |= cmIDEFlagTable::SpaceAppendable;
  1318. } else if (s == "CommaAppendable") {
  1319. value |= cmIDEFlagTable::CommaAppendable;
  1320. }
  1321. }
  1322. }
  1323. }
  1324. return value;
  1325. }
  1326. namespace {
  1327. cmIDEFlagTable const* cmLoadFlagTableJson(std::string const& flagJsonPath,
  1328. cm::optional<std::string> vsVer)
  1329. {
  1330. cmIDEFlagTable* ret = nullptr;
  1331. auto savedFlagIterator = loadedFlagJsonFiles.find(flagJsonPath);
  1332. if (savedFlagIterator != loadedFlagJsonFiles.end()) {
  1333. ret = savedFlagIterator->second.data();
  1334. } else {
  1335. Json::Reader reader;
  1336. cmsys::ifstream stream;
  1337. stream.open(flagJsonPath.c_str(), std::ios_base::in);
  1338. if (stream) {
  1339. Json::Value flags;
  1340. if (reader.parse(stream, flags, false) && flags.isArray()) {
  1341. std::vector<cmIDEFlagTable> flagTable;
  1342. for (auto const& flag : flags) {
  1343. Json::Value const& vsminJson = flag["vsmin"];
  1344. if (vsminJson.isString()) {
  1345. std::string const& vsmin = vsminJson.asString();
  1346. if (!vsmin.empty()) {
  1347. if (!vsVer ||
  1348. cmSystemTools::VersionCompareGreater(vsmin, *vsVer)) {
  1349. continue;
  1350. }
  1351. }
  1352. }
  1353. cmIDEFlagTable flagEntry;
  1354. flagEntry.IDEName = cmLoadFlagTableString(flag, "name");
  1355. flagEntry.commandFlag = cmLoadFlagTableString(flag, "switch");
  1356. flagEntry.comment = cmLoadFlagTableString(flag, "comment");
  1357. flagEntry.value = cmLoadFlagTableString(flag, "value");
  1358. flagEntry.special = cmLoadFlagTableSpecial(flag, "flags");
  1359. flagTable.push_back(flagEntry);
  1360. }
  1361. cmIDEFlagTable endFlag{ "", "", "", "", 0 };
  1362. flagTable.push_back(endFlag);
  1363. loadedFlagJsonFiles[flagJsonPath] = flagTable;
  1364. ret = loadedFlagJsonFiles[flagJsonPath].data();
  1365. }
  1366. }
  1367. }
  1368. return ret;
  1369. }
  1370. }
  1371. cm::optional<std::string> cmGlobalVisualStudio10Generator::FindFlagTable(
  1372. cm::string_view toolsetName, cm::string_view table) const
  1373. {
  1374. if (!this->CustomFlagTableDir.empty()) {
  1375. std::string customFlagTableFile =
  1376. cmStrCat(this->CustomFlagTableDir, '/', this->GetPlatformName(), '_',
  1377. toolsetName, '_', table, ".json");
  1378. if (cmSystemTools::FileExists(customFlagTableFile)) {
  1379. return customFlagTableFile;
  1380. }
  1381. customFlagTableFile =
  1382. cmStrCat(this->CustomFlagTableDir, '/', this->GetPlatformName(), '_',
  1383. table, ".json");
  1384. if (cmSystemTools::FileExists(customFlagTableFile)) {
  1385. return customFlagTableFile;
  1386. }
  1387. }
  1388. std::string fullPath =
  1389. cmStrCat(cmSystemTools::GetCMakeRoot(), "/Templates/MSBuild/FlagTables/",
  1390. toolsetName, '_', table, ".json");
  1391. if (cmSystemTools::FileExists(fullPath)) {
  1392. return fullPath;
  1393. }
  1394. return {};
  1395. }
  1396. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable(
  1397. std::string const& toolSpecificName, std::string const& defaultName,
  1398. std::string const& table) const
  1399. {
  1400. cmMakefile* mf = this->GetCurrentMakefile();
  1401. std::string filename;
  1402. if (!toolSpecificName.empty()) {
  1403. if (cm::optional<std::string> found =
  1404. this->FindFlagTable(toolSpecificName, table)) {
  1405. filename = std::move(*found);
  1406. } else {
  1407. mf->IssueMessage(MessageType::FATAL_ERROR,
  1408. cmStrCat("JSON flag table for ", table,
  1409. " not found for toolset ", toolSpecificName));
  1410. return nullptr;
  1411. }
  1412. } else {
  1413. std::string const& genericName =
  1414. this->CanonicalToolsetName(this->GetPlatformToolsetString());
  1415. cm::optional<std::string> found = this->FindFlagTable(genericName, table);
  1416. if (!found) {
  1417. found = this->FindFlagTable(defaultName, table);
  1418. }
  1419. if (found) {
  1420. filename = std::move(*found);
  1421. } else {
  1422. mf->IssueMessage(MessageType::FATAL_ERROR,
  1423. cmStrCat("JSON flag table for ", table,
  1424. " not found for toolset ", genericName, " ",
  1425. defaultName));
  1426. return nullptr;
  1427. }
  1428. }
  1429. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1430. if (cmIDEFlagTable const* ret = cmLoadFlagTableJson(filename, vsVer)) {
  1431. return ret;
  1432. }
  1433. mf->IssueMessage(
  1434. MessageType::FATAL_ERROR,
  1435. cmStrCat("JSON flag table could not be loaded:\n ", filename));
  1436. return nullptr;
  1437. }
  1438. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const
  1439. {
  1440. return LoadFlagTable(this->GetClFlagTableName(),
  1441. this->DefaultCLFlagTableName, "CL");
  1442. }
  1443. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable()
  1444. const
  1445. {
  1446. return LoadFlagTable(this->GetCSharpFlagTableName(),
  1447. this->DefaultCSharpFlagTableName, "CSharp");
  1448. }
  1449. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const
  1450. {
  1451. return LoadFlagTable(this->GetRcFlagTableName(),
  1452. this->DefaultRCFlagTableName, "RC");
  1453. }
  1454. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const
  1455. {
  1456. return LoadFlagTable(this->GetLibFlagTableName(),
  1457. this->DefaultLibFlagTableName, "LIB");
  1458. }
  1459. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const
  1460. {
  1461. return LoadFlagTable(this->GetLinkFlagTableName(),
  1462. this->DefaultLinkFlagTableName, "Link");
  1463. }
  1464. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaFlagTable() const
  1465. {
  1466. return LoadFlagTable(std::string(), this->DefaultCudaFlagTableName, "Cuda");
  1467. }
  1468. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaHostFlagTable()
  1469. const
  1470. {
  1471. return LoadFlagTable(std::string(), this->DefaultCudaHostFlagTableName,
  1472. "CudaHost");
  1473. }
  1474. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const
  1475. {
  1476. return LoadFlagTable(this->GetMasmFlagTableName(),
  1477. this->DefaultMasmFlagTableName, "MASM");
  1478. }
  1479. cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const
  1480. {
  1481. return LoadFlagTable(std::string(), this->DefaultNasmFlagTableName, "NASM");
  1482. }
  1483. bool cmGlobalVisualStudio10Generator::IsMsBuildRestoreSupported() const
  1484. {
  1485. if (this->Version >= VS16) {
  1486. return true;
  1487. }
  1488. static std::string const vsVer15_7_5 = "15.7.27703.2042";
  1489. cm::optional<std::string> vsVer = this->GetVSInstanceVersion();
  1490. return (vsVer &&
  1491. cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer15_7_5));
  1492. }
  1493. std::string cmGlobalVisualStudio10Generator::GetClFlagTableName() const
  1494. {
  1495. std::string const& toolset = this->GetPlatformToolsetString();
  1496. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1497. if (toolset == "v142") {
  1498. return "v142";
  1499. } else if (toolset == "v141") {
  1500. return "v141";
  1501. } else if (useToolset == "v140") {
  1502. return "v140";
  1503. } else if (useToolset == "v120") {
  1504. return "v12";
  1505. } else if (useToolset == "v110") {
  1506. return "v11";
  1507. } else if (useToolset == "v100") {
  1508. return "v10";
  1509. } else {
  1510. return "";
  1511. }
  1512. }
  1513. std::string cmGlobalVisualStudio10Generator::GetCSharpFlagTableName() const
  1514. {
  1515. std::string const& toolset = this->GetPlatformToolsetString();
  1516. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1517. if (useToolset == "v142") {
  1518. return "v142";
  1519. } else if (useToolset == "v141") {
  1520. return "v141";
  1521. } else if (useToolset == "v140") {
  1522. return "v140";
  1523. } else if (useToolset == "v120") {
  1524. return "v12";
  1525. } else if (useToolset == "v110") {
  1526. return "v11";
  1527. } else if (useToolset == "v100") {
  1528. return "v10";
  1529. } else {
  1530. return "";
  1531. }
  1532. }
  1533. std::string cmGlobalVisualStudio10Generator::GetRcFlagTableName() const
  1534. {
  1535. std::string const& toolset = this->GetPlatformToolsetString();
  1536. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1537. if ((useToolset == "v140") || (useToolset == "v141") ||
  1538. (useToolset == "v142")) {
  1539. return "v14";
  1540. } else if (useToolset == "v120") {
  1541. return "v12";
  1542. } else if (useToolset == "v110") {
  1543. return "v11";
  1544. } else if (useToolset == "v100") {
  1545. return "v10";
  1546. } else {
  1547. return "";
  1548. }
  1549. }
  1550. std::string cmGlobalVisualStudio10Generator::GetLibFlagTableName() const
  1551. {
  1552. std::string const& toolset = this->GetPlatformToolsetString();
  1553. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1554. if ((useToolset == "v140") || (useToolset == "v141") ||
  1555. (useToolset == "v142")) {
  1556. return "v14";
  1557. } else if (useToolset == "v120") {
  1558. return "v12";
  1559. } else if (useToolset == "v110") {
  1560. return "v11";
  1561. } else if (useToolset == "v100") {
  1562. return "v10";
  1563. } else {
  1564. return "";
  1565. }
  1566. }
  1567. std::string cmGlobalVisualStudio10Generator::GetLinkFlagTableName() const
  1568. {
  1569. std::string const& toolset = this->GetPlatformToolsetString();
  1570. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1571. if (useToolset == "v142") {
  1572. return "v142";
  1573. } else if (useToolset == "v141") {
  1574. return "v141";
  1575. } else if (useToolset == "v140") {
  1576. return "v140";
  1577. } else if (useToolset == "v120") {
  1578. return "v12";
  1579. } else if (useToolset == "v110") {
  1580. return "v11";
  1581. } else if (useToolset == "v100") {
  1582. return "v10";
  1583. } else {
  1584. return "";
  1585. }
  1586. }
  1587. std::string cmGlobalVisualStudio10Generator::GetMasmFlagTableName() const
  1588. {
  1589. std::string const& toolset = this->GetPlatformToolsetString();
  1590. std::string const useToolset = this->CanonicalToolsetName(toolset);
  1591. if ((useToolset == "v140") || (useToolset == "v141") ||
  1592. (useToolset == "v142")) {
  1593. return "v14";
  1594. } else if (useToolset == "v120") {
  1595. return "v12";
  1596. } else if (useToolset == "v110") {
  1597. return "v11";
  1598. } else if (useToolset == "v100") {
  1599. return "v10";
  1600. } else {
  1601. return "";
  1602. }
  1603. }
  1604. std::string cmGlobalVisualStudio10Generator::CanonicalToolsetName(
  1605. std::string const& toolset) const
  1606. {
  1607. std::size_t length = toolset.length();
  1608. if (cmHasLiteralSuffix(toolset, "_xp")) {
  1609. length -= 3;
  1610. }
  1611. return toolset.substr(0, length);
  1612. }