cmVisualStudio10TargetGenerator.cxx 55 KB

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