cmVisualStudio10TargetGenerator.cxx 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmVisualStudio10TargetGenerator.h"
  11. #include "cmGlobalVisualStudio10Generator.h"
  12. #include "cmGeneratorTarget.h"
  13. #include "cmTarget.h"
  14. #include "cmComputeLinkInformation.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmMakefile.h"
  17. #include "cmSourceFile.h"
  18. #include "cmVisualStudioGeneratorOptions.h"
  19. #include "cmLocalVisualStudio7Generator.h"
  20. #include "cmVS10CLFlagTable.h"
  21. #include "cmVS10LinkFlagTable.h"
  22. #include "cmVS10LibFlagTable.h"
  23. #include <cmsys/auto_ptr.hxx>
  24. static std::string cmVS10EscapeXML(std::string arg)
  25. {
  26. cmSystemTools::ReplaceString(arg, "&", "&amp;");
  27. cmSystemTools::ReplaceString(arg, "<", "&lt;");
  28. cmSystemTools::ReplaceString(arg, ">", "&gt;");
  29. return arg;
  30. }
  31. static std::string cmVS10EscapeComment(std::string comment)
  32. {
  33. // MSBuild takes the CDATA of a <Message></Message> element and just
  34. // does "echo $CDATA" with no escapes. We must encode the string.
  35. // http://technet.microsoft.com/en-us/library/cc772462%28WS.10%29.aspx
  36. std::string echoable;
  37. for(std::string::iterator c = comment.begin(); c != comment.end(); ++c)
  38. {
  39. switch (*c)
  40. {
  41. case '\r': break;
  42. case '\n': echoable += '\t'; break;
  43. case '"': /* no break */
  44. case '|': /* no break */
  45. case '&': /* no break */
  46. case '<': /* no break */
  47. case '>': /* no break */
  48. case '^': echoable += '^'; /* no break */
  49. default: echoable += *c; break;
  50. }
  51. }
  52. return echoable;
  53. }
  54. cmVisualStudio10TargetGenerator::
  55. cmVisualStudio10TargetGenerator(cmTarget* target,
  56. cmGlobalVisualStudio10Generator* gg)
  57. {
  58. this->GlobalGenerator = gg;
  59. this->Target = target;
  60. this->GeneratorTarget = gg->GetGeneratorTarget(target);
  61. this->Makefile = target->GetMakefile();
  62. this->LocalGenerator =
  63. (cmLocalVisualStudio7Generator*)
  64. this->Makefile->GetLocalGenerator();
  65. this->Name = this->Target->GetName();
  66. this->GlobalGenerator->CreateGUID(this->Name.c_str());
  67. this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
  68. this->Platform = gg->GetPlatformName();
  69. this->BuildFileStream = 0;
  70. }
  71. cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
  72. {
  73. for(OptionsMap::iterator i = this->ClOptions.begin();
  74. i != this->ClOptions.end(); ++i)
  75. {
  76. delete i->second;
  77. }
  78. if(!this->BuildFileStream)
  79. {
  80. return;
  81. }
  82. if (this->BuildFileStream->Close())
  83. {
  84. this->GlobalGenerator
  85. ->FileReplacedDuringGenerate(this->PathToVcxproj);
  86. }
  87. delete this->BuildFileStream;
  88. }
  89. void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
  90. const char* tag,
  91. const char* config,
  92. int indentLevel,
  93. const char* attribute,
  94. const char* end,
  95. std::ostream* stream)
  96. {
  97. if(!stream)
  98. {
  99. stream = this->BuildFileStream;
  100. }
  101. stream->fill(' ');
  102. stream->width(indentLevel*2 );
  103. (*stream ) << "";
  104. (*stream ) << "<" << tag
  105. << " Condition=\"'$(Configuration)|$(Platform)'=='";
  106. (*stream ) << config << "|" << this->Platform << "'\"";
  107. if(attribute)
  108. {
  109. (*stream ) << attribute;
  110. }
  111. // close the tag
  112. (*stream ) << ">";
  113. if(end)
  114. {
  115. (*stream ) << end;
  116. }
  117. }
  118. void cmVisualStudio10TargetGenerator::WriteString(const char* line,
  119. int indentLevel)
  120. {
  121. this->BuildFileStream->fill(' ');
  122. this->BuildFileStream->width(indentLevel*2 );
  123. // write an empty string to get the fill level indent to print
  124. (*this->BuildFileStream ) << "";
  125. (*this->BuildFileStream ) << line;
  126. }
  127. #define VS10_USER_PROPS "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props"
  128. void cmVisualStudio10TargetGenerator::Generate()
  129. {
  130. // do not generate external ms projects
  131. if(this->Target->GetProperty("EXTERNAL_MSPROJECT"))
  132. {
  133. return;
  134. }
  135. // Tell the global generator the name of the project file
  136. this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
  137. this->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
  138. ".vcxproj");
  139. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
  140. {
  141. if(!this->ComputeClOptions())
  142. {
  143. return;
  144. }
  145. }
  146. cmMakefile* mf = this->Target->GetMakefile();
  147. std::string path = mf->GetStartOutputDirectory();
  148. path += "/";
  149. path += this->Name;
  150. path += ".vcxproj";
  151. this->BuildFileStream =
  152. new cmGeneratedFileStream(path.c_str());
  153. this->PathToVcxproj = path;
  154. this->BuildFileStream->SetCopyIfDifferent(true);
  155. // Write the encoding header into the file
  156. char magic[] = {0xEF,0xBB, 0xBF};
  157. this->BuildFileStream->write(magic, 3);
  158. this->WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",0);
  159. this->WriteString("<Project DefaultTargets=\"Build\" "
  160. "ToolsVersion=\"4.0\" "
  161. "xmlns=\"http://schemas.microsoft.com/"
  162. "developer/msbuild/2003\">\n",
  163. 0);
  164. this->WriteProjectConfigurations();
  165. this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1);
  166. this->WriteString("<ProjectGUID>", 2);
  167. (*this->BuildFileStream) << "{" << this->GUID << "}</ProjectGUID>\n";
  168. const char* vsProjectTypes =
  169. this->Target->GetProperty("VS_GLOBAL_PROJECT_TYPES");
  170. if(vsProjectTypes)
  171. {
  172. this->WriteString("<ProjectTypes>", 2);
  173. (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectTypes) <<
  174. "</ProjectTypes>\n";
  175. }
  176. const char* vsProjectName = this->Target->GetProperty("VS_SCC_PROJECTNAME");
  177. const char* vsLocalPath = this->Target->GetProperty("VS_SCC_LOCALPATH");
  178. const char* vsProvider = this->Target->GetProperty("VS_SCC_PROVIDER");
  179. if( vsProjectName && vsLocalPath && vsProvider )
  180. {
  181. this->WriteString("<SccProjectName>", 2);
  182. (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectName) <<
  183. "</SccProjectName>\n";
  184. this->WriteString("<SccLocalPath>", 2);
  185. (*this->BuildFileStream) << cmVS10EscapeXML(vsLocalPath) <<
  186. "</SccLocalPath>\n";
  187. this->WriteString("<SccProvider>", 2);
  188. (*this->BuildFileStream) << cmVS10EscapeXML(vsProvider) <<
  189. "</SccProvider>\n";
  190. const char* vsAuxPath = this->Target->GetProperty("VS_SCC_AUXPATH");
  191. if( vsAuxPath )
  192. {
  193. this->WriteString("<SccAuxPath>", 2);
  194. (*this->BuildFileStream) << cmVS10EscapeXML(vsAuxPath) <<
  195. "</SccAuxPath>\n";
  196. }
  197. }
  198. const char* vsGlobalKeyword =
  199. this->Target->GetProperty("VS_GLOBAL_KEYWORD");
  200. if(!vsGlobalKeyword)
  201. {
  202. this->WriteString("<Keyword>Win32Proj</Keyword>\n", 2);
  203. }
  204. else
  205. {
  206. this->WriteString("<Keyword>", 2);
  207. (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalKeyword) <<
  208. "</Keyword>\n";
  209. }
  210. this->WriteString("<Platform>", 2);
  211. (*this->BuildFileStream) << this->Platform << "</Platform>\n";
  212. const char* projLabel = this->Target->GetProperty("PROJECT_LABEL");
  213. if(!projLabel)
  214. {
  215. projLabel = this->Name.c_str();
  216. }
  217. this->WriteString("<ProjectName>", 2);
  218. (*this->BuildFileStream) << projLabel << "</ProjectName>\n";
  219. this->WriteString("</PropertyGroup>\n", 1);
  220. this->WriteString("<Import Project="
  221. "\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n",
  222. 1);
  223. this->WriteProjectConfigurationValues();
  224. this->WriteString(
  225. "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n", 1);
  226. this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1);
  227. this->WriteString("</ImportGroup>\n", 1);
  228. this->WriteString("<ImportGroup Label=\"PropertySheets\">\n", 1);
  229. this->WriteString("<Import Project=\"" VS10_USER_PROPS "\""
  230. " Condition=\"exists('" VS10_USER_PROPS "')\""
  231. " Label=\"LocalAppDataPlatform\" />", 2);
  232. this->WriteString("</ImportGroup>\n", 1);
  233. this->WriteString("<PropertyGroup Label=\"UserMacros\" />\n", 1);
  234. this->WritePathAndIncrementalLinkOptions();
  235. this->WriteItemDefinitionGroups();
  236. this->WriteCustomCommands();
  237. this->WriteAllSources();
  238. this->WriteDotNetReferences();
  239. this->WriteWinRTReferences();
  240. this->WriteProjectReferences();
  241. this->WriteString(
  242. "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\""
  243. " />\n", 1);
  244. this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
  245. this->WriteString("</ImportGroup>\n", 1);
  246. this->WriteString("</Project>", 0);
  247. // The groups are stored in a separate file for VS 10
  248. this->WriteGroups();
  249. }
  250. void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
  251. {
  252. std::vector<std::string> references;
  253. if(const char* vsDotNetReferences =
  254. this->Target->GetProperty("VS_DOTNET_REFERENCES"))
  255. {
  256. cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
  257. }
  258. if(!references.empty())
  259. {
  260. this->WriteString("<ItemGroup>\n", 1);
  261. for(std::vector<std::string>::iterator ri = references.begin();
  262. ri != references.end(); ++ri)
  263. {
  264. this->WriteString("<Reference Include=\"", 2);
  265. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
  266. this->WriteString("<CopyLocalSatelliteAssemblies>true"
  267. "</CopyLocalSatelliteAssemblies>\n", 3);
  268. this->WriteString("<ReferenceOutputAssembly>true"
  269. "</ReferenceOutputAssembly>\n", 3);
  270. this->WriteString("</Reference>\n", 2);
  271. }
  272. this->WriteString("</ItemGroup>\n", 1);
  273. }
  274. }
  275. void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
  276. {
  277. std::vector<std::string> references;
  278. if(const char* vsWinRTReferences =
  279. this->Target->GetProperty("VS_WINRT_REFERENCES"))
  280. {
  281. cmSystemTools::ExpandListArgument(vsWinRTReferences, references);
  282. }
  283. if(!references.empty())
  284. {
  285. this->WriteString("<ItemGroup>\n", 1);
  286. for(std::vector<std::string>::iterator ri = references.begin();
  287. ri != references.end(); ++ri)
  288. {
  289. this->WriteString("<Reference Include=\"", 2);
  290. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
  291. this->WriteString("<IsWinMDFile>true</IsWinMDFile>\n", 3);
  292. this->WriteString("</Reference>\n", 2);
  293. }
  294. this->WriteString("</ItemGroup>\n", 1);
  295. }
  296. }
  297. // ConfigurationType Application, Utility StaticLibrary DynamicLibrary
  298. void cmVisualStudio10TargetGenerator::WriteProjectConfigurations()
  299. {
  300. this->WriteString("<ItemGroup Label=\"ProjectConfigurations\">\n", 1);
  301. std::vector<std::string> *configs =
  302. static_cast<cmGlobalVisualStudio7Generator *>
  303. (this->GlobalGenerator)->GetConfigurations();
  304. for(std::vector<std::string>::iterator i = configs->begin();
  305. i != configs->end(); ++i)
  306. {
  307. this->WriteString("<ProjectConfiguration Include=\"", 2);
  308. (*this->BuildFileStream ) << *i << "|" << this->Platform << "\">\n";
  309. this->WriteString("<Configuration>", 3);
  310. (*this->BuildFileStream ) << *i << "</Configuration>\n";
  311. this->WriteString("<Platform>", 3);
  312. (*this->BuildFileStream) << this->Platform << "</Platform>\n";
  313. this->WriteString("</ProjectConfiguration>\n", 2);
  314. }
  315. this->WriteString("</ItemGroup>\n", 1);
  316. }
  317. void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
  318. {
  319. cmGlobalVisualStudio10Generator* gg =
  320. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  321. std::vector<std::string> *configs =
  322. static_cast<cmGlobalVisualStudio7Generator *>
  323. (this->GlobalGenerator)->GetConfigurations();
  324. for(std::vector<std::string>::iterator i = configs->begin();
  325. i != configs->end(); ++i)
  326. {
  327. this->WritePlatformConfigTag("PropertyGroup",
  328. i->c_str(),
  329. 1, " Label=\"Configuration\"", "\n");
  330. std::string configType = "<ConfigurationType>";
  331. switch(this->Target->GetType())
  332. {
  333. case cmTarget::SHARED_LIBRARY:
  334. case cmTarget::MODULE_LIBRARY:
  335. configType += "DynamicLibrary";
  336. break;
  337. case cmTarget::OBJECT_LIBRARY:
  338. case cmTarget::STATIC_LIBRARY:
  339. configType += "StaticLibrary";
  340. break;
  341. case cmTarget::EXECUTABLE:
  342. configType += "Application";
  343. break;
  344. case cmTarget::UTILITY:
  345. configType += "Utility";
  346. break;
  347. }
  348. configType += "</ConfigurationType>\n";
  349. this->WriteString(configType.c_str(), 2);
  350. const char* mfcFlag =
  351. this->Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG");
  352. std::string mfcFlagValue = mfcFlag ? mfcFlag : "0";
  353. std::string useOfMfcValue = "false";
  354. if(mfcFlagValue == "1")
  355. {
  356. useOfMfcValue = "Static";
  357. }
  358. else if(mfcFlagValue == "2")
  359. {
  360. useOfMfcValue = "Dynamic";
  361. }
  362. std::string mfcLine = "<UseOfMfc>";
  363. mfcLine += useOfMfcValue + "</UseOfMfc>\n";
  364. this->WriteString(mfcLine.c_str(), 2);
  365. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY &&
  366. this->ClOptions[*i]->UsingUnicode() ||
  367. this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  368. {
  369. this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
  370. }
  371. else if (this->Target->GetType() <= cmTarget::MODULE_LIBRARY &&
  372. this->ClOptions[*i]->UsingSBCS())
  373. {
  374. this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
  375. }
  376. else
  377. {
  378. this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
  379. }
  380. if(const char* toolset = gg->GetPlatformToolset())
  381. {
  382. std::string pts = "<PlatformToolset>";
  383. pts += toolset;
  384. pts += "</PlatformToolset>\n";
  385. this->WriteString(pts.c_str(), 2);
  386. }
  387. if(this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  388. {
  389. this->WriteString("<Immersive>true</Immersive>\n", 2);
  390. }
  391. this->WriteString("</PropertyGroup>\n", 1);
  392. }
  393. }
  394. void cmVisualStudio10TargetGenerator::WriteCustomCommands()
  395. {
  396. this->SourcesVisited.clear();
  397. for(std::vector<cmSourceFile*>::const_iterator
  398. si = this->GeneratorTarget->CustomCommands.begin();
  399. si != this->GeneratorTarget->CustomCommands.end(); ++si)
  400. {
  401. this->WriteCustomCommand(*si);
  402. }
  403. }
  404. //----------------------------------------------------------------------------
  405. void cmVisualStudio10TargetGenerator::WriteCustomCommand(cmSourceFile* sf)
  406. {
  407. if(this->SourcesVisited.insert(sf).second)
  408. {
  409. if(std::vector<cmSourceFile*> const* depends =
  410. this->Target->GetSourceDepends(sf))
  411. {
  412. for(std::vector<cmSourceFile*>::const_iterator di = depends->begin();
  413. di != depends->end(); ++di)
  414. {
  415. this->WriteCustomCommand(*di);
  416. }
  417. }
  418. if(cmCustomCommand const* command = sf->GetCustomCommand())
  419. {
  420. this->WriteString("<ItemGroup>\n", 1);
  421. this->WriteCustomRule(sf, *command);
  422. this->WriteString("</ItemGroup>\n", 1);
  423. }
  424. }
  425. }
  426. void
  427. cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source,
  428. cmCustomCommand const &
  429. command)
  430. {
  431. std::string sourcePath = source->GetFullPath();
  432. // VS 10 will always rebuild a custom command attached to a .rule
  433. // file that doesn't exist so create the file explicitly.
  434. if (source->GetPropertyAsBool("__CMAKE_RULE"))
  435. {
  436. if(!cmSystemTools::FileExists(sourcePath.c_str()))
  437. {
  438. // Make sure the path exists for the file
  439. std::string path = cmSystemTools::GetFilenamePath(sourcePath);
  440. cmSystemTools::MakeDirectory(path.c_str());
  441. std::ofstream fout(sourcePath.c_str());
  442. if(fout)
  443. {
  444. fout << "# generated from CMake\n";
  445. fout.flush();
  446. fout.close();
  447. }
  448. else
  449. {
  450. std::string error = "Could not create file: [";
  451. error += sourcePath;
  452. error += "] ";
  453. cmSystemTools::Error
  454. (error.c_str(), cmSystemTools::GetLastSystemError().c_str());
  455. }
  456. }
  457. }
  458. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  459. std::string comment = lg->ConstructComment(command);
  460. comment = cmVS10EscapeComment(comment);
  461. std::vector<std::string> *configs =
  462. static_cast<cmGlobalVisualStudio7Generator *>
  463. (this->GlobalGenerator)->GetConfigurations();
  464. this->WriteSource("CustomBuild", source, ">\n");
  465. for(std::vector<std::string>::iterator i = configs->begin();
  466. i != configs->end(); ++i)
  467. {
  468. std::string script =
  469. cmVS10EscapeXML(lg->ConstructScript(command, i->c_str()));
  470. this->WritePlatformConfigTag("Message",i->c_str(), 3);
  471. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  472. this->WritePlatformConfigTag("Command", i->c_str(), 3);
  473. (*this->BuildFileStream ) << script << "</Command>\n";
  474. this->WritePlatformConfigTag("AdditionalInputs", i->c_str(), 3);
  475. (*this->BuildFileStream ) << source->GetFullPath();
  476. for(std::vector<std::string>::const_iterator d =
  477. command.GetDepends().begin();
  478. d != command.GetDepends().end();
  479. ++d)
  480. {
  481. std::string dep;
  482. if(this->LocalGenerator->GetRealDependency(d->c_str(), i->c_str(), dep))
  483. {
  484. this->ConvertToWindowsSlash(dep);
  485. (*this->BuildFileStream ) << ";" << dep;
  486. }
  487. }
  488. (*this->BuildFileStream ) << ";%(AdditionalInputs)</AdditionalInputs>\n";
  489. this->WritePlatformConfigTag("Outputs", i->c_str(), 3);
  490. const char* sep = "";
  491. for(std::vector<std::string>::const_iterator o =
  492. command.GetOutputs().begin();
  493. o != command.GetOutputs().end();
  494. ++o)
  495. {
  496. std::string out = *o;
  497. this->ConvertToWindowsSlash(out);
  498. (*this->BuildFileStream ) << sep << out;
  499. sep = ";";
  500. }
  501. (*this->BuildFileStream ) << "</Outputs>\n";
  502. }
  503. this->WriteString("</CustomBuild>\n", 2);
  504. }
  505. std::string
  506. cmVisualStudio10TargetGenerator::ConvertPath(std::string const& path,
  507. bool forceRelative)
  508. {
  509. return forceRelative
  510. ? cmSystemTools::RelativePath(
  511. this->Makefile->GetCurrentOutputDirectory(), path.c_str())
  512. : this->LocalGenerator->Convert(path.c_str(),
  513. cmLocalGenerator::START_OUTPUT,
  514. cmLocalGenerator::UNCHANGED);
  515. }
  516. void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s)
  517. {
  518. // first convert all of the slashes
  519. std::string::size_type pos = 0;
  520. while((pos = s.find('/', pos)) != std::string::npos)
  521. {
  522. s[pos] = '\\';
  523. pos++;
  524. }
  525. }
  526. void cmVisualStudio10TargetGenerator::WriteGroups()
  527. {
  528. // collect up group information
  529. std::vector<cmSourceGroup> sourceGroups =
  530. this->Makefile->GetSourceGroups();
  531. std::vector<cmSourceFile*> classes = this->Target->GetSourceFiles();
  532. std::set<cmSourceGroup*> groupsUsed;
  533. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  534. s != classes.end(); s++)
  535. {
  536. cmSourceFile* sf = *s;
  537. std::string const& source = sf->GetFullPath();
  538. cmSourceGroup& sourceGroup =
  539. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  540. groupsUsed.insert(&sourceGroup);
  541. }
  542. this->AddMissingSourceGroups(groupsUsed, sourceGroups);
  543. // Write out group file
  544. std::string path = this->Makefile->GetStartOutputDirectory();
  545. path += "/";
  546. path += this->Name;
  547. path += ".vcxproj.filters";
  548. cmGeneratedFileStream fout(path.c_str());
  549. fout.SetCopyIfDifferent(true);
  550. char magic[] = {0xEF,0xBB, 0xBF};
  551. fout.write(magic, 3);
  552. cmGeneratedFileStream* save = this->BuildFileStream;
  553. this->BuildFileStream = & fout;
  554. this->WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  555. "<Project "
  556. "ToolsVersion=\"4.0\" "
  557. "xmlns=\"http://schemas.microsoft.com/"
  558. "developer/msbuild/2003\">\n",
  559. 0);
  560. for(ToolSourceMap::const_iterator ti = this->Tools.begin();
  561. ti != this->Tools.end(); ++ti)
  562. {
  563. this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups);
  564. }
  565. // Add object library contents as external objects.
  566. std::vector<std::string> objs;
  567. this->GeneratorTarget->UseObjectLibraries(objs);
  568. if(!objs.empty())
  569. {
  570. this->WriteString("<ItemGroup>\n", 1);
  571. for(std::vector<std::string>::const_iterator
  572. oi = objs.begin(); oi != objs.end(); ++oi)
  573. {
  574. std::string obj = *oi;
  575. this->WriteString("<Object Include=\"", 2);
  576. this->ConvertToWindowsSlash(obj);
  577. (*this->BuildFileStream ) << obj << "\">\n";
  578. this->WriteString("<Filter>Object Libraries</Filter>\n", 3);
  579. this->WriteString("</Object>\n", 2);
  580. }
  581. this->WriteString("</ItemGroup>\n", 1);
  582. }
  583. this->WriteString("<ItemGroup>\n", 1);
  584. for(std::set<cmSourceGroup*>::iterator g = groupsUsed.begin();
  585. g != groupsUsed.end(); ++g)
  586. {
  587. cmSourceGroup* sg = *g;
  588. const char* name = sg->GetFullName();
  589. if(strlen(name) != 0)
  590. {
  591. this->WriteString("<Filter Include=\"", 2);
  592. (*this->BuildFileStream) << name << "\">\n";
  593. std::string guidName = "SG_Filter_";
  594. guidName += name;
  595. this->GlobalGenerator->CreateGUID(guidName.c_str());
  596. this->WriteString("<UniqueIdentifier>", 3);
  597. std::string guid
  598. = this->GlobalGenerator->GetGUID(guidName.c_str());
  599. (*this->BuildFileStream)
  600. << "{"
  601. << guid << "}"
  602. << "</UniqueIdentifier>\n";
  603. this->WriteString("</Filter>\n", 2);
  604. }
  605. }
  606. if(!objs.empty())
  607. {
  608. this->WriteString("<Filter Include=\"Object Libraries\">\n", 2);
  609. std::string guidName = "SG_Filter_Object Libraries";
  610. this->GlobalGenerator->CreateGUID(guidName.c_str());
  611. this->WriteString("<UniqueIdentifier>", 3);
  612. std::string guid =
  613. this->GlobalGenerator->GetGUID(guidName.c_str());
  614. (*this->BuildFileStream) << "{" << guid << "}"
  615. << "</UniqueIdentifier>\n";
  616. this->WriteString("</Filter>\n", 2);
  617. }
  618. this->WriteString("</ItemGroup>\n", 1);
  619. this->WriteString("</Project>\n", 0);
  620. // restore stream pointer
  621. this->BuildFileStream = save;
  622. if (fout.Close())
  623. {
  624. this->GlobalGenerator->FileReplacedDuringGenerate(path);
  625. }
  626. }
  627. // Add to groupsUsed empty source groups that have non-empty children.
  628. void
  629. cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
  630. std::set<cmSourceGroup*>& groupsUsed,
  631. const std::vector<cmSourceGroup>& allGroups
  632. )
  633. {
  634. for(std::vector<cmSourceGroup>::const_iterator current = allGroups.begin();
  635. current != allGroups.end(); ++current)
  636. {
  637. std::vector<cmSourceGroup> const& children = current->GetGroupChildren();
  638. if(children.empty())
  639. {
  640. continue; // the group is really empty
  641. }
  642. this->AddMissingSourceGroups(groupsUsed, children);
  643. cmSourceGroup* current_ptr = const_cast<cmSourceGroup*>(&(*current));
  644. if(groupsUsed.find(current_ptr) != groupsUsed.end())
  645. {
  646. continue; // group has already been added to set
  647. }
  648. // check if it least one of the group's descendants is not empty
  649. // (at least one child must already have been added)
  650. std::vector<cmSourceGroup>::const_iterator child_it = children.begin();
  651. while(child_it != children.end())
  652. {
  653. cmSourceGroup* child_ptr = const_cast<cmSourceGroup*>(&(*child_it));
  654. if(groupsUsed.find(child_ptr) != groupsUsed.end())
  655. {
  656. break; // found a child that was already added => add current group too
  657. }
  658. child_it++;
  659. }
  660. if(child_it == children.end())
  661. {
  662. continue; // no descendants have source files => ignore this group
  663. }
  664. groupsUsed.insert(current_ptr);
  665. }
  666. }
  667. void
  668. cmVisualStudio10TargetGenerator::
  669. WriteGroupSources(const char* name,
  670. ToolSources const& sources,
  671. std::vector<cmSourceGroup>& sourceGroups)
  672. {
  673. this->WriteString("<ItemGroup>\n", 1);
  674. for(ToolSources::const_iterator s = sources.begin();
  675. s != sources.end(); ++s)
  676. {
  677. cmSourceFile* sf = s->SourceFile;
  678. std::string const& source = sf->GetFullPath();
  679. cmSourceGroup& sourceGroup =
  680. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  681. const char* filter = sourceGroup.GetFullName();
  682. this->WriteString("<", 2);
  683. std::string path = this->ConvertPath(source, s->RelativePath);
  684. this->ConvertToWindowsSlash(path);
  685. (*this->BuildFileStream) << name << " Include=\""
  686. << path;
  687. if(strlen(filter))
  688. {
  689. (*this->BuildFileStream) << "\">\n";
  690. this->WriteString("<Filter>", 3);
  691. (*this->BuildFileStream) << filter << "</Filter>\n";
  692. this->WriteString("</", 2);
  693. (*this->BuildFileStream) << name << ">\n";
  694. }
  695. else
  696. {
  697. (*this->BuildFileStream) << "\" />\n";
  698. }
  699. }
  700. this->WriteString("</ItemGroup>\n", 1);
  701. }
  702. void cmVisualStudio10TargetGenerator::WriteSource(
  703. const char* tool, cmSourceFile* sf, const char* end)
  704. {
  705. // Visual Studio tools append relative paths to the current dir, as in:
  706. //
  707. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  708. //
  709. // and fail if this exceeds the maximum allowed path length. Our path
  710. // conversion uses full paths outside the build tree to allow deeper trees.
  711. bool forceRelative = false;
  712. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), false);
  713. if(this->LocalGenerator->GetVersion() == cmLocalVisualStudioGenerator::VS10
  714. && cmSystemTools::FileIsFullPath(sourceFile.c_str()))
  715. {
  716. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  717. // refuses to show the property page in the IDE for a source file with a
  718. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  719. // relative path but to allow deeper build trees now CMake uses a full
  720. // path except for custom commands which work only as relative paths.
  721. if(sf->GetCustomCommand())
  722. {
  723. forceRelative = true;
  724. sourceFile = this->ConvertPath(sf->GetFullPath(), forceRelative);
  725. }
  726. }
  727. this->ConvertToWindowsSlash(sourceFile);
  728. this->WriteString("<", 2);
  729. (*this->BuildFileStream ) << tool <<
  730. " Include=\"" << sourceFile << "\"" << (end? end : " />\n");
  731. ToolSource toolSource = {sf, forceRelative};
  732. this->Tools[tool].push_back(toolSource);
  733. }
  734. void cmVisualStudio10TargetGenerator::WriteSources(
  735. const char* tool, std::vector<cmSourceFile*> const& sources)
  736. {
  737. for(std::vector<cmSourceFile*>::const_iterator
  738. si = sources.begin(); si != sources.end(); ++si)
  739. {
  740. this->WriteSource(tool, *si);
  741. }
  742. }
  743. void cmVisualStudio10TargetGenerator::WriteAllSources()
  744. {
  745. if(this->Target->GetType() > cmTarget::UTILITY)
  746. {
  747. return;
  748. }
  749. this->WriteString("<ItemGroup>\n", 1);
  750. this->WriteSources("ClInclude", this->GeneratorTarget->HeaderSources);
  751. this->WriteSources("Midl", this->GeneratorTarget->IDLSources);
  752. for(std::vector<cmSourceFile*>::const_iterator
  753. si = this->GeneratorTarget->ObjectSources.begin();
  754. si != this->GeneratorTarget->ObjectSources.end(); ++si)
  755. {
  756. const char* lang = (*si)->GetLanguage();
  757. bool cl = strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0;
  758. bool rc = strcmp(lang, "RC") == 0;
  759. const char* tool = cl? "ClCompile" : (rc? "ResourceCompile" : "None");
  760. this->WriteSource(tool, *si, " ");
  761. // ouput any flags specific to this source file
  762. if(cl && this->OutputSourceSpecificFlags(*si))
  763. {
  764. // if the source file has specific flags the tag
  765. // is ended on a new line
  766. this->WriteString("</ClCompile>\n", 2);
  767. }
  768. else if(rc && this->OutputSourceSpecificFlags(*si))
  769. {
  770. this->WriteString("</ResourceCompile>\n", 2);
  771. }
  772. else
  773. {
  774. (*this->BuildFileStream ) << " />\n";
  775. }
  776. }
  777. for(std::vector<cmSourceFile*>::const_iterator
  778. si = this->GeneratorTarget->ExternalObjects.begin();
  779. si != this->GeneratorTarget->ExternalObjects.end(); ++si)
  780. {
  781. // If an object file is generated in this target, then vs10 will use
  782. // it in the build, and we have to list it as None instead of Object.
  783. std::vector<cmSourceFile*> const* d = this->Target->GetSourceDepends(*si);
  784. this->WriteSource((d && !d->empty())? "None":"Object", *si);
  785. }
  786. this->WriteSources("None", this->GeneratorTarget->ExtraSources);
  787. // Add object library contents as external objects.
  788. std::vector<std::string> objs;
  789. this->GeneratorTarget->UseObjectLibraries(objs);
  790. for(std::vector<std::string>::const_iterator
  791. oi = objs.begin(); oi != objs.end(); ++oi)
  792. {
  793. std::string obj = *oi;
  794. this->WriteString("<Object Include=\"", 2);
  795. this->ConvertToWindowsSlash(obj);
  796. (*this->BuildFileStream ) << obj << "\" />\n";
  797. }
  798. this->WriteString("</ItemGroup>\n", 1);
  799. }
  800. bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  801. cmSourceFile* source)
  802. {
  803. cmSourceFile& sf = *source;
  804. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  805. std::string objectName;
  806. if(this->GeneratorTarget->ExplicitObjectName.find(&sf)
  807. != this->GeneratorTarget->ExplicitObjectName.end())
  808. {
  809. objectName = this->GeneratorTarget->Objects[&sf];
  810. }
  811. std::string flags;
  812. std::string defines;
  813. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  814. {
  815. flags += cflags;
  816. }
  817. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  818. {
  819. defines += cdefs;
  820. }
  821. const char* lang =
  822. this->GlobalGenerator->GetLanguageFromExtension
  823. (sf.GetExtension().c_str());
  824. const char* sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  825. const char* linkLanguage = this->Target->GetLinkerLanguage();
  826. bool needForceLang = false;
  827. // source file does not match its extension language
  828. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  829. {
  830. needForceLang = true;
  831. lang = sourceLang;
  832. }
  833. // if the source file does not match the linker language
  834. // then force c or c++
  835. if(needForceLang || (linkLanguage && lang
  836. && strcmp(lang, linkLanguage) != 0))
  837. {
  838. if(strcmp(lang, "CXX") == 0)
  839. {
  840. // force a C++ file type
  841. flags += " /TP ";
  842. }
  843. else if(strcmp(lang, "C") == 0)
  844. {
  845. // force to c
  846. flags += " /TC ";
  847. }
  848. }
  849. bool hasFlags = false;
  850. // for the first time we need a new line if there is something
  851. // produced here.
  852. const char* firstString = ">\n";
  853. if(objectName.size())
  854. {
  855. (*this->BuildFileStream ) << firstString;
  856. firstString = "";
  857. hasFlags = true;
  858. this->WriteString("<ObjectFileName>", 3);
  859. (*this->BuildFileStream )
  860. << "$(IntDir)/" << objectName << "</ObjectFileName>\n";
  861. }
  862. std::vector<std::string> *configs =
  863. static_cast<cmGlobalVisualStudio7Generator *>
  864. (this->GlobalGenerator)->GetConfigurations();
  865. for( std::vector<std::string>::iterator config = configs->begin();
  866. config != configs->end(); ++config)
  867. {
  868. std::string configUpper = cmSystemTools::UpperCase(*config);
  869. std::string configDefines = defines;
  870. std::string defPropName = "COMPILE_DEFINITIONS_";
  871. defPropName += configUpper;
  872. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  873. {
  874. if(configDefines.size())
  875. {
  876. configDefines += ";";
  877. }
  878. configDefines += ccdefs;
  879. }
  880. // if we have flags or defines for this config then
  881. // use them
  882. if(flags.size() || configDefines.size())
  883. {
  884. (*this->BuildFileStream ) << firstString;
  885. firstString = ""; // only do firstString once
  886. hasFlags = true;
  887. cmVisualStudioGeneratorOptions
  888. clOptions(this->LocalGenerator,
  889. cmVisualStudioGeneratorOptions::Compiler,
  890. cmVS10CLFlagTable, 0, this);
  891. clOptions.Parse(flags.c_str());
  892. clOptions.AddDefines(configDefines.c_str());
  893. clOptions.SetConfiguration((*config).c_str());
  894. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  895. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  896. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream,
  897. " ", "\n", lang);
  898. }
  899. }
  900. return hasFlags;
  901. }
  902. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
  903. {
  904. cmTarget::TargetType ttype = this->Target->GetType();
  905. if(ttype > cmTarget::GLOBAL_TARGET)
  906. {
  907. return;
  908. }
  909. this->WriteString("<PropertyGroup>\n", 2);
  910. this->WriteString("<_ProjectFileVersion>10.0.20506.1"
  911. "</_ProjectFileVersion>\n", 3);
  912. std::vector<std::string> *configs =
  913. static_cast<cmGlobalVisualStudio7Generator *>
  914. (this->GlobalGenerator)->GetConfigurations();
  915. for(std::vector<std::string>::iterator config = configs->begin();
  916. config != configs->end(); ++config)
  917. {
  918. if(ttype >= cmTarget::UTILITY)
  919. {
  920. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  921. *this->BuildFileStream
  922. << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
  923. << "</IntDir>\n";
  924. }
  925. else
  926. {
  927. std::string intermediateDir = this->LocalGenerator->
  928. GetTargetDirectory(*this->Target);
  929. intermediateDir += "/";
  930. intermediateDir += *config;
  931. intermediateDir += "/";
  932. std::string outDir;
  933. std::string targetNameFull;
  934. if(ttype == cmTarget::OBJECT_LIBRARY)
  935. {
  936. outDir = intermediateDir;
  937. targetNameFull = this->Target->GetName();
  938. targetNameFull += ".lib";
  939. }
  940. else
  941. {
  942. outDir = this->Target->GetDirectory(config->c_str()) + "/";
  943. targetNameFull = this->Target->GetFullName(config->c_str());
  944. }
  945. this->ConvertToWindowsSlash(intermediateDir);
  946. this->ConvertToWindowsSlash(outDir);
  947. this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
  948. *this->BuildFileStream << outDir
  949. << "</OutDir>\n";
  950. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  951. *this->BuildFileStream << intermediateDir
  952. << "</IntDir>\n";
  953. this->WritePlatformConfigTag("TargetName", config->c_str(), 3);
  954. *this->BuildFileStream
  955. << cmSystemTools::GetFilenameWithoutLastExtension(
  956. targetNameFull.c_str())
  957. << "</TargetName>\n";
  958. this->WritePlatformConfigTag("TargetExt", config->c_str(), 3);
  959. *this->BuildFileStream
  960. << cmSystemTools::GetFilenameLastExtension(targetNameFull.c_str())
  961. << "</TargetExt>\n";
  962. this->OutputLinkIncremental(*config);
  963. }
  964. }
  965. this->WriteString("</PropertyGroup>\n", 2);
  966. }
  967. void
  968. cmVisualStudio10TargetGenerator::
  969. OutputLinkIncremental(std::string const& configName)
  970. {
  971. std::string CONFIG = cmSystemTools::UpperCase(configName);
  972. // static libraries and things greater than modules do not need
  973. // to set this option
  974. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
  975. || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
  976. {
  977. return;
  978. }
  979. const char* linkType = "SHARED";
  980. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  981. {
  982. linkType = "EXE";
  983. }
  984. // assume incremental linking
  985. const char* incremental = "true";
  986. const char* linkLanguage =
  987. this->Target->GetLinkerLanguage(configName.c_str());
  988. if(!linkLanguage)
  989. {
  990. cmSystemTools::Error
  991. ("CMake can not determine linker language for target:",
  992. this->Name.c_str());
  993. return;
  994. }
  995. std::string linkFlagVarBase = "CMAKE_";
  996. linkFlagVarBase += linkType;
  997. linkFlagVarBase += "_LINKER_FLAGS";
  998. std::string flags = this->
  999. Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
  1000. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  1001. flags += this->
  1002. Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
  1003. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0
  1004. || strcmp(linkLanguage, "Fortran") == 0)
  1005. {
  1006. std::string baseFlagVar = "CMAKE_";
  1007. baseFlagVar += linkLanguage;
  1008. baseFlagVar += "_FLAGS";
  1009. flags += this->
  1010. Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
  1011. std::string flagVar = baseFlagVar + std::string("_") + CONFIG;
  1012. flags +=
  1013. Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
  1014. }
  1015. const char* targetLinkFlags = this->Target->GetProperty("LINK_FLAGS");
  1016. if(targetLinkFlags)
  1017. {
  1018. flags += " ";
  1019. flags += targetLinkFlags;
  1020. }
  1021. std::string flagsProp = "LINK_FLAGS_";
  1022. flagsProp += CONFIG;
  1023. if(const char* flagsConfig = this->Target->GetProperty(flagsProp.c_str()))
  1024. {
  1025. flags += " ";
  1026. flags += flagsConfig;
  1027. }
  1028. if(flags.find("INCREMENTAL:NO") != flags.npos)
  1029. {
  1030. incremental = "false";
  1031. }
  1032. this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 3);
  1033. *this->BuildFileStream << incremental
  1034. << "</LinkIncremental>\n";
  1035. const char* manifest = "true";
  1036. if(flags.find("MANIFEST:NO") != flags.npos)
  1037. {
  1038. manifest = "false";
  1039. }
  1040. this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 3);
  1041. *this->BuildFileStream << manifest
  1042. << "</GenerateManifest>\n";
  1043. }
  1044. //----------------------------------------------------------------------------
  1045. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  1046. {
  1047. std::vector<std::string> const* configs =
  1048. this->GlobalGenerator->GetConfigurations();
  1049. for(std::vector<std::string>::const_iterator i = configs->begin();
  1050. i != configs->end(); ++i)
  1051. {
  1052. if(!this->ComputeClOptions(*i))
  1053. {
  1054. return false;
  1055. }
  1056. }
  1057. return true;
  1058. }
  1059. //----------------------------------------------------------------------------
  1060. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  1061. std::string const& configName)
  1062. {
  1063. // much of this was copied from here:
  1064. // copied from cmLocalVisualStudio7Generator.cxx 805
  1065. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  1066. cmsys::auto_ptr<Options> pOptions(
  1067. new Options(this->LocalGenerator, Options::Compiler,
  1068. cmVS10CLFlagTable));
  1069. Options& clOptions = *pOptions;
  1070. std::string flags;
  1071. // collect up flags for
  1072. if(this->Target->GetType() < cmTarget::UTILITY)
  1073. {
  1074. const char* linkLanguage =
  1075. this->Target->GetLinkerLanguage(configName.c_str());
  1076. if(!linkLanguage)
  1077. {
  1078. cmSystemTools::Error
  1079. ("CMake can not determine linker language for target:",
  1080. this->Name.c_str());
  1081. return false;
  1082. }
  1083. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0
  1084. || strcmp(linkLanguage, "Fortran") == 0)
  1085. {
  1086. std::string baseFlagVar = "CMAKE_";
  1087. baseFlagVar += linkLanguage;
  1088. baseFlagVar += "_FLAGS";
  1089. flags = this->
  1090. Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
  1091. std::string flagVar = baseFlagVar + std::string("_") +
  1092. cmSystemTools::UpperCase(configName);
  1093. flags += " ";
  1094. flags += this->
  1095. Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
  1096. }
  1097. // set the correct language
  1098. if(strcmp(linkLanguage, "C") == 0)
  1099. {
  1100. flags += " /TC ";
  1101. }
  1102. if(strcmp(linkLanguage, "CXX") == 0)
  1103. {
  1104. flags += " /TP ";
  1105. }
  1106. }
  1107. // Add the target-specific flags.
  1108. if(const char* targetFlags = this->Target->GetProperty("COMPILE_FLAGS"))
  1109. {
  1110. flags += " ";
  1111. flags += targetFlags;
  1112. }
  1113. std::string configUpper = cmSystemTools::UpperCase(configName);
  1114. std::string defPropName = "COMPILE_DEFINITIONS_";
  1115. defPropName += configUpper;
  1116. // Get preprocessor definitions for this directory.
  1117. std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags();
  1118. clOptions.FixExceptionHandlingDefault();
  1119. clOptions.Parse(flags.c_str());
  1120. clOptions.Parse(defineFlags.c_str());
  1121. clOptions.AddDefines
  1122. (this->Makefile->GetProperty("COMPILE_DEFINITIONS"));
  1123. clOptions.AddDefines(this->Target->GetProperty("COMPILE_DEFINITIONS"));
  1124. clOptions.AddDefines(this->Makefile->GetProperty(defPropName.c_str()));
  1125. clOptions.AddDefines(this->Target->GetProperty(defPropName.c_str()));
  1126. clOptions.SetVerboseMakefile(
  1127. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  1128. // Add a definition for the configuration name.
  1129. std::string configDefine = "CMAKE_INTDIR=\"";
  1130. configDefine += configName;
  1131. configDefine += "\"";
  1132. clOptions.AddDefine(configDefine);
  1133. if(const char* exportMacro = this->Target->GetExportMacro())
  1134. {
  1135. clOptions.AddDefine(exportMacro);
  1136. }
  1137. this->ClOptions[configName] = pOptions.release();
  1138. return true;
  1139. }
  1140. //----------------------------------------------------------------------------
  1141. void cmVisualStudio10TargetGenerator::WriteClOptions(
  1142. std::string const& configName,
  1143. std::vector<std::string> const& includes)
  1144. {
  1145. Options& clOptions = *(this->ClOptions[configName]);
  1146. this->WriteString("<ClCompile>\n", 2);
  1147. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1148. this->OutputIncludes(includes);
  1149. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1150. // If not in debug mode, write the DebugInformationFormat field
  1151. // without value so PDBs don't get generated uselessly.
  1152. if(!clOptions.IsDebug())
  1153. {
  1154. this->WriteString("<DebugInformationFormat>"
  1155. "</DebugInformationFormat>\n", 3);
  1156. }
  1157. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1158. "\n", "CXX");
  1159. this->WriteString("<AssemblerListingLocation>", 3);
  1160. *this->BuildFileStream << configName
  1161. << "</AssemblerListingLocation>\n";
  1162. this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
  1163. if(this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
  1164. {
  1165. // TODO: PDB for object library?
  1166. this->WriteString("<ProgramDataBaseFileName>", 3);
  1167. *this->BuildFileStream << this->Target->GetDirectory(configName.c_str())
  1168. << "/"
  1169. << this->Target->GetPDBName(configName.c_str())
  1170. << "</ProgramDataBaseFileName>\n";
  1171. }
  1172. this->WriteString("</ClCompile>\n", 2);
  1173. }
  1174. void cmVisualStudio10TargetGenerator::
  1175. OutputIncludes(std::vector<std::string> const & includes)
  1176. {
  1177. this->WriteString("<AdditionalIncludeDirectories>", 3);
  1178. for(std::vector<std::string>::const_iterator i = includes.begin();
  1179. i != includes.end(); ++i)
  1180. {
  1181. *this->BuildFileStream << *i << ";";
  1182. }
  1183. this->WriteString("%(AdditionalIncludeDirectories)"
  1184. "</AdditionalIncludeDirectories>\n", 0);
  1185. }
  1186. void cmVisualStudio10TargetGenerator::
  1187. WriteRCOptions(std::string const& configName,
  1188. std::vector<std::string> const & includes)
  1189. {
  1190. this->WriteString("<ResourceCompile>\n", 2);
  1191. Options& clOptions = *(this->ClOptions[configName]);
  1192. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1193. "\n", "RC");
  1194. this->OutputIncludes(includes);
  1195. this->WriteString("</ResourceCompile>\n", 2);
  1196. }
  1197. void
  1198. cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
  1199. {
  1200. if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
  1201. {
  1202. return;
  1203. }
  1204. const char* libflags = this->Target->GetProperty("STATIC_LIBRARY_FLAGS");
  1205. std::string flagsConfigVar = "STATIC_LIBRARY_FLAGS_";
  1206. flagsConfigVar += cmSystemTools::UpperCase(config);
  1207. const char* libflagsConfig =
  1208. this->Target->GetProperty(flagsConfigVar.c_str());
  1209. if(libflags || libflagsConfig)
  1210. {
  1211. this->WriteString("<Lib>\n", 2);
  1212. cmVisualStudioGeneratorOptions
  1213. libOptions(this->LocalGenerator,
  1214. cmVisualStudioGeneratorOptions::Linker,
  1215. cmVS10LibFlagTable, 0, this);
  1216. libOptions.Parse(libflags?libflags:"");
  1217. libOptions.Parse(libflagsConfig?libflagsConfig:"");
  1218. libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1219. libOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1220. this->WriteString("</Lib>\n", 2);
  1221. }
  1222. }
  1223. void cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const&
  1224. config)
  1225. {
  1226. // static libraries and things greater than modules do not need
  1227. // to set this option
  1228. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
  1229. || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
  1230. {
  1231. return;
  1232. }
  1233. const char* linkLanguage =
  1234. this->Target->GetLinkerLanguage(config.c_str());
  1235. if(!linkLanguage)
  1236. {
  1237. cmSystemTools::Error
  1238. ("CMake can not determine linker language for target:",
  1239. this->Name.c_str());
  1240. return;
  1241. }
  1242. this->WriteString("<Link>\n", 2);
  1243. std::string CONFIG = cmSystemTools::UpperCase(config);
  1244. const char* linkType = "SHARED";
  1245. if(this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  1246. {
  1247. linkType = "MODULE";
  1248. }
  1249. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  1250. {
  1251. linkType = "EXE";
  1252. }
  1253. std::string stackVar = "CMAKE_";
  1254. stackVar += linkLanguage;
  1255. stackVar += "_STACK_SIZE";
  1256. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1257. std::string flags;
  1258. if(stackVal)
  1259. {
  1260. flags += " ";
  1261. flags += stackVal;
  1262. }
  1263. // assume incremental linking
  1264. std::string linkFlagVarBase = "CMAKE_";
  1265. linkFlagVarBase += linkType;
  1266. linkFlagVarBase += "_LINKER_FLAGS";
  1267. flags += " ";
  1268. flags += this->
  1269. Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
  1270. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  1271. flags += " ";
  1272. flags += this->
  1273. Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
  1274. const char* targetLinkFlags = this->Target->GetProperty("LINK_FLAGS");
  1275. if(targetLinkFlags)
  1276. {
  1277. flags += " ";
  1278. flags += targetLinkFlags;
  1279. }
  1280. std::string flagsProp = "LINK_FLAGS_";
  1281. flagsProp += CONFIG;
  1282. if(const char* flagsConfig = this->Target->GetProperty(flagsProp.c_str()))
  1283. {
  1284. flags += " ";
  1285. flags += flagsConfig;
  1286. }
  1287. cmVisualStudioGeneratorOptions
  1288. linkOptions(this->LocalGenerator,
  1289. cmVisualStudioGeneratorOptions::Linker,
  1290. cmVS10LinkFlagTable, 0, this);
  1291. if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
  1292. {
  1293. flags += " /SUBSYSTEM:WINDOWS";
  1294. }
  1295. else
  1296. {
  1297. flags += " /SUBSYSTEM:CONSOLE";
  1298. }
  1299. cmSystemTools::ReplaceString(flags, "/INCREMENTAL:YES", "");
  1300. cmSystemTools::ReplaceString(flags, "/INCREMENTAL:NO", "");
  1301. std::string standardLibsVar = "CMAKE_";
  1302. standardLibsVar += linkLanguage;
  1303. standardLibsVar += "_STANDARD_LIBRARIES";
  1304. std::string
  1305. libs = this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1306. // Remove trailing spaces from libs
  1307. std::string::size_type pos = libs.size()-1;
  1308. if(libs.size() != 0)
  1309. {
  1310. while(libs[pos] == ' ')
  1311. {
  1312. pos--;
  1313. }
  1314. }
  1315. if(pos != libs.size()-1)
  1316. {
  1317. libs = libs.substr(0, pos+1);
  1318. }
  1319. // Replace spaces in libs with ;
  1320. cmSystemTools::ReplaceString(libs, " ", ";");
  1321. cmComputeLinkInformation* pcli =
  1322. this->Target->GetLinkInformation(config.c_str());
  1323. if(!pcli)
  1324. {
  1325. cmSystemTools::Error
  1326. ("CMake can not compute cmComputeLinkInformation for target:",
  1327. this->Name.c_str());
  1328. return;
  1329. }
  1330. // add the libraries for the target to libs string
  1331. cmComputeLinkInformation& cli = *pcli;
  1332. this->AddLibraries(cli, libs);
  1333. linkOptions.AddFlag("AdditionalDependencies", libs.c_str());
  1334. std::vector<std::string> const& ldirs = cli.GetDirectories();
  1335. const char* sep = "";
  1336. std::string linkDirs;
  1337. for(std::vector<std::string>::const_iterator d = ldirs.begin();
  1338. d != ldirs.end(); ++d)
  1339. {
  1340. // first just full path
  1341. linkDirs += sep;
  1342. linkDirs += *d;
  1343. sep = ";";
  1344. linkDirs += sep;
  1345. // next path with configuration type Debug, Release, etc
  1346. linkDirs += *d;
  1347. linkDirs += "/$(Configuration)";
  1348. linkDirs += sep;
  1349. }
  1350. linkDirs += "%(AdditionalLibraryDirectories)";
  1351. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs.c_str());
  1352. linkOptions.AddFlag("AdditionalDependencies", libs.c_str());
  1353. linkOptions.AddFlag("Version", "");
  1354. if(linkOptions.IsDebug() || flags.find("/debug") != flags.npos)
  1355. {
  1356. linkOptions.AddFlag("GenerateDebugInformation", "true");
  1357. }
  1358. else
  1359. {
  1360. linkOptions.AddFlag("GenerateDebugInformation", "false");
  1361. }
  1362. std::string targetName;
  1363. std::string targetNameSO;
  1364. std::string targetNameFull;
  1365. std::string targetNameImport;
  1366. std::string targetNamePDB;
  1367. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  1368. {
  1369. this->Target->GetExecutableNames(targetName, targetNameFull,
  1370. targetNameImport, targetNamePDB,
  1371. config.c_str());
  1372. }
  1373. else
  1374. {
  1375. this->Target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1376. targetNameImport, targetNamePDB,
  1377. config.c_str());
  1378. }
  1379. std::string dir = this->Target->GetDirectory(config.c_str());
  1380. dir += "/";
  1381. std::string pdb = dir;
  1382. pdb += targetNamePDB;
  1383. std::string imLib = this->Target->GetDirectory(config.c_str(), true);
  1384. imLib += "/";
  1385. imLib += targetNameImport;
  1386. linkOptions.AddFlag("ImportLibrary", imLib.c_str());
  1387. linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
  1388. linkOptions.Parse(flags.c_str());
  1389. if(!this->GeneratorTarget->ModuleDefinitionFile.empty())
  1390. {
  1391. linkOptions.AddFlag("ModuleDefinitionFile",
  1392. this->GeneratorTarget->ModuleDefinitionFile.c_str());
  1393. }
  1394. linkOptions.RemoveFlag("GenerateManifest");
  1395. linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1396. linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1397. this->WriteString("</Link>\n", 2);
  1398. if(!this->GlobalGenerator->NeedLinkLibraryDependencies(*this->Target))
  1399. {
  1400. this->WriteString("<ProjectReference>\n", 2);
  1401. this->WriteString(
  1402. " <LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 2);
  1403. this->WriteString("</ProjectReference>\n", 2);
  1404. }
  1405. }
  1406. void cmVisualStudio10TargetGenerator::AddLibraries(
  1407. cmComputeLinkInformation& cli,
  1408. std::string& libstring)
  1409. {
  1410. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1411. ItemVector libs = cli.GetItems();
  1412. const char* sep = ";";
  1413. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1414. {
  1415. if(l->IsPath)
  1416. {
  1417. std::string path = this->LocalGenerator->
  1418. Convert(l->Value.c_str(),
  1419. cmLocalGenerator::START_OUTPUT,
  1420. cmLocalGenerator::UNCHANGED);
  1421. this->ConvertToWindowsSlash(path);
  1422. libstring += sep;
  1423. libstring += path;
  1424. }
  1425. else
  1426. {
  1427. libstring += sep;
  1428. libstring += l->Value;
  1429. }
  1430. }
  1431. }
  1432. void cmVisualStudio10TargetGenerator::
  1433. WriteMidlOptions(std::string const& /*config*/,
  1434. std::vector<std::string> const & includes)
  1435. {
  1436. this->WriteString("<Midl>\n", 2);
  1437. this->OutputIncludes(includes);
  1438. this->WriteString("<OutputDirectory>$(IntDir)</OutputDirectory>\n", 3);
  1439. this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
  1440. this->WriteString(
  1441. "<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
  1442. this->WriteString(
  1443. "<InterfaceIdentifierFileName>"
  1444. "%(Filename)_i.c</InterfaceIdentifierFileName>\n", 3);
  1445. this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n",3);
  1446. this->WriteString("</Midl>\n", 2);
  1447. }
  1448. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
  1449. {
  1450. std::vector<std::string> *configs =
  1451. static_cast<cmGlobalVisualStudio7Generator *>
  1452. (this->GlobalGenerator)->GetConfigurations();
  1453. std::vector<std::string> includes;
  1454. this->LocalGenerator->GetIncludeDirectories(includes, this->Target);
  1455. for(std::vector<std::string>::iterator i = configs->begin();
  1456. i != configs->end(); ++i)
  1457. {
  1458. this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
  1459. *this->BuildFileStream << "\n";
  1460. // output cl compile flags <ClCompile></ClCompile>
  1461. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
  1462. {
  1463. this->WriteClOptions(*i, includes);
  1464. // output rc compile flags <ResourceCompile></ResourceCompile>
  1465. this->WriteRCOptions(*i, includes);
  1466. }
  1467. // output midl flags <Midl></Midl>
  1468. this->WriteMidlOptions(*i, includes);
  1469. // write events
  1470. this->WriteEvents(*i);
  1471. // output link flags <Link></Link>
  1472. this->WriteLinkOptions(*i);
  1473. // output lib flags <Lib></Lib>
  1474. this->WriteLibOptions(*i);
  1475. this->WriteString("</ItemDefinitionGroup>\n", 1);
  1476. }
  1477. }
  1478. void
  1479. cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
  1480. {
  1481. this->WriteEvent("PreLinkEvent",
  1482. this->Target->GetPreLinkCommands(), configName);
  1483. this->WriteEvent("PreBuildEvent",
  1484. this->Target->GetPreBuildCommands(), configName);
  1485. this->WriteEvent("PostBuildEvent",
  1486. this->Target->GetPostBuildCommands(), configName);
  1487. }
  1488. void cmVisualStudio10TargetGenerator::WriteEvent(
  1489. const char* name,
  1490. std::vector<cmCustomCommand> & commands,
  1491. std::string const& configName)
  1492. {
  1493. if(commands.size() == 0)
  1494. {
  1495. return;
  1496. }
  1497. this->WriteString("<", 2);
  1498. (*this->BuildFileStream ) << name << ">\n";
  1499. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1500. std::string script;
  1501. const char* pre = "";
  1502. std::string comment;
  1503. for(std::vector<cmCustomCommand>::iterator i = commands.begin();
  1504. i != commands.end(); ++i)
  1505. {
  1506. cmCustomCommand& command = *i;
  1507. comment += pre;
  1508. comment += lg->ConstructComment(command);
  1509. script += pre;
  1510. pre = "\n";
  1511. script +=
  1512. cmVS10EscapeXML(lg->ConstructScript(command, configName.c_str()));
  1513. }
  1514. comment = cmVS10EscapeComment(comment);
  1515. this->WriteString("<Message>",3);
  1516. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  1517. this->WriteString("<Command>", 3);
  1518. (*this->BuildFileStream ) << script;
  1519. (*this->BuildFileStream ) << "</Command>" << "\n";
  1520. this->WriteString("</", 2);
  1521. (*this->BuildFileStream ) << name << ">\n";
  1522. }
  1523. void cmVisualStudio10TargetGenerator::WriteProjectReferences()
  1524. {
  1525. cmGlobalGenerator::TargetDependSet const& unordered
  1526. = this->GlobalGenerator->GetTargetDirectDepends(*this->Target);
  1527. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  1528. OrderedTargetDependSet;
  1529. OrderedTargetDependSet depends(unordered);
  1530. this->WriteString("<ItemGroup>\n", 1);
  1531. for( OrderedTargetDependSet::const_iterator i = depends.begin();
  1532. i != depends.end(); ++i)
  1533. {
  1534. cmTarget* dt = *i;
  1535. // skip fortran targets as they can not be processed by MSBuild
  1536. // the only reference will be in the .sln file
  1537. if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  1538. ->TargetIsFortranOnly(*dt))
  1539. {
  1540. continue;
  1541. }
  1542. this->WriteString("<ProjectReference Include=\"", 2);
  1543. cmMakefile* mf = dt->GetMakefile();
  1544. std::string name = dt->GetName();
  1545. std::string path;
  1546. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  1547. if(p)
  1548. {
  1549. path = p;
  1550. }
  1551. else
  1552. {
  1553. path = mf->GetStartOutputDirectory();
  1554. path += "/";
  1555. path += dt->GetName();
  1556. path += ".vcxproj";
  1557. }
  1558. (*this->BuildFileStream) << path << "\">\n";
  1559. this->WriteString("<Project>", 3);
  1560. (*this->BuildFileStream)
  1561. << this->GlobalGenerator->GetGUID(name.c_str())
  1562. << "</Project>\n";
  1563. this->WriteString("</ProjectReference>\n", 2);
  1564. }
  1565. this->WriteString("</ItemGroup>\n", 1);
  1566. }