cmVisualStudio10TargetGenerator.cxx 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712
  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. case cmTarget::GLOBAL_TARGET:
  381. case cmTarget::UNKNOWN_LIBRARY:
  382. break;
  383. }
  384. configType += "</ConfigurationType>\n";
  385. this->WriteString(configType.c_str(), 2);
  386. const char* mfcFlag =
  387. this->Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG");
  388. std::string mfcFlagValue = mfcFlag ? mfcFlag : "0";
  389. std::string useOfMfcValue = "false";
  390. if(mfcFlagValue == "1")
  391. {
  392. useOfMfcValue = "Static";
  393. }
  394. else if(mfcFlagValue == "2")
  395. {
  396. useOfMfcValue = "Dynamic";
  397. }
  398. std::string mfcLine = "<UseOfMfc>";
  399. mfcLine += useOfMfcValue + "</UseOfMfc>\n";
  400. this->WriteString(mfcLine.c_str(), 2);
  401. if((this->Target->GetType() <= cmTarget::OBJECT_LIBRARY &&
  402. this->ClOptions[*i]->UsingUnicode()) ||
  403. this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  404. {
  405. this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
  406. }
  407. else if (this->Target->GetType() <= cmTarget::MODULE_LIBRARY &&
  408. this->ClOptions[*i]->UsingSBCS())
  409. {
  410. this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
  411. }
  412. else
  413. {
  414. this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
  415. }
  416. if(const char* toolset = gg->GetPlatformToolset())
  417. {
  418. std::string pts = "<PlatformToolset>";
  419. pts += toolset;
  420. pts += "</PlatformToolset>\n";
  421. this->WriteString(pts.c_str(), 2);
  422. }
  423. if(this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  424. {
  425. this->WriteString("<WindowsAppContainer>true"
  426. "</WindowsAppContainer>\n", 2);
  427. }
  428. this->WriteString("</PropertyGroup>\n", 1);
  429. }
  430. }
  431. void cmVisualStudio10TargetGenerator::WriteCustomCommands()
  432. {
  433. this->SourcesVisited.clear();
  434. for(std::vector<cmSourceFile*>::const_iterator
  435. si = this->GeneratorTarget->CustomCommands.begin();
  436. si != this->GeneratorTarget->CustomCommands.end(); ++si)
  437. {
  438. this->WriteCustomCommand(*si);
  439. }
  440. }
  441. //----------------------------------------------------------------------------
  442. void cmVisualStudio10TargetGenerator::WriteCustomCommand(cmSourceFile* sf)
  443. {
  444. if(this->SourcesVisited.insert(sf).second)
  445. {
  446. if(std::vector<cmSourceFile*> const* depends =
  447. this->Target->GetSourceDepends(sf))
  448. {
  449. for(std::vector<cmSourceFile*>::const_iterator di = depends->begin();
  450. di != depends->end(); ++di)
  451. {
  452. this->WriteCustomCommand(*di);
  453. }
  454. }
  455. if(cmCustomCommand const* command = sf->GetCustomCommand())
  456. {
  457. this->WriteString("<ItemGroup>\n", 1);
  458. this->WriteCustomRule(sf, *command);
  459. this->WriteString("</ItemGroup>\n", 1);
  460. }
  461. }
  462. }
  463. void
  464. cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source,
  465. cmCustomCommand const &
  466. command)
  467. {
  468. std::string sourcePath = source->GetFullPath();
  469. // VS 10 will always rebuild a custom command attached to a .rule
  470. // file that doesn't exist so create the file explicitly.
  471. if (source->GetPropertyAsBool("__CMAKE_RULE"))
  472. {
  473. if(!cmSystemTools::FileExists(sourcePath.c_str()))
  474. {
  475. // Make sure the path exists for the file
  476. std::string path = cmSystemTools::GetFilenamePath(sourcePath);
  477. cmSystemTools::MakeDirectory(path.c_str());
  478. std::ofstream fout(sourcePath.c_str());
  479. if(fout)
  480. {
  481. fout << "# generated from CMake\n";
  482. fout.flush();
  483. fout.close();
  484. }
  485. else
  486. {
  487. std::string error = "Could not create file: [";
  488. error += sourcePath;
  489. error += "] ";
  490. cmSystemTools::Error
  491. (error.c_str(), cmSystemTools::GetLastSystemError().c_str());
  492. }
  493. }
  494. }
  495. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  496. std::string comment = lg->ConstructComment(command);
  497. comment = cmVS10EscapeComment(comment);
  498. std::vector<std::string> *configs =
  499. static_cast<cmGlobalVisualStudio7Generator *>
  500. (this->GlobalGenerator)->GetConfigurations();
  501. this->WriteSource("CustomBuild", source, ">\n");
  502. for(std::vector<std::string>::iterator i = configs->begin();
  503. i != configs->end(); ++i)
  504. {
  505. std::string script =
  506. cmVS10EscapeXML(lg->ConstructScript(command, i->c_str()));
  507. this->WritePlatformConfigTag("Message",i->c_str(), 3);
  508. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  509. this->WritePlatformConfigTag("Command", i->c_str(), 3);
  510. (*this->BuildFileStream ) << script << "</Command>\n";
  511. this->WritePlatformConfigTag("AdditionalInputs", i->c_str(), 3);
  512. (*this->BuildFileStream ) << source->GetFullPath();
  513. for(std::vector<std::string>::const_iterator d =
  514. command.GetDepends().begin();
  515. d != command.GetDepends().end();
  516. ++d)
  517. {
  518. std::string dep;
  519. if(this->LocalGenerator->GetRealDependency(d->c_str(), i->c_str(), dep))
  520. {
  521. this->ConvertToWindowsSlash(dep);
  522. (*this->BuildFileStream ) << ";" << dep;
  523. }
  524. }
  525. (*this->BuildFileStream ) << ";%(AdditionalInputs)</AdditionalInputs>\n";
  526. this->WritePlatformConfigTag("Outputs", i->c_str(), 3);
  527. const char* sep = "";
  528. for(std::vector<std::string>::const_iterator o =
  529. command.GetOutputs().begin();
  530. o != command.GetOutputs().end();
  531. ++o)
  532. {
  533. std::string out = *o;
  534. this->ConvertToWindowsSlash(out);
  535. (*this->BuildFileStream ) << sep << out;
  536. sep = ";";
  537. }
  538. (*this->BuildFileStream ) << "</Outputs>\n";
  539. if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
  540. {
  541. // VS >= 11 let us turn off linking of custom command outputs.
  542. this->WritePlatformConfigTag("LinkObjects", i->c_str(), 3);
  543. (*this->BuildFileStream ) << "false</LinkObjects>\n";
  544. }
  545. }
  546. this->WriteString("</CustomBuild>\n", 2);
  547. }
  548. std::string
  549. cmVisualStudio10TargetGenerator::ConvertPath(std::string const& path,
  550. bool forceRelative)
  551. {
  552. return forceRelative
  553. ? cmSystemTools::RelativePath(
  554. this->Makefile->GetCurrentOutputDirectory(), path.c_str())
  555. : this->LocalGenerator->Convert(path.c_str(),
  556. cmLocalGenerator::START_OUTPUT,
  557. cmLocalGenerator::UNCHANGED);
  558. }
  559. void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s)
  560. {
  561. // first convert all of the slashes
  562. std::string::size_type pos = 0;
  563. while((pos = s.find('/', pos)) != std::string::npos)
  564. {
  565. s[pos] = '\\';
  566. pos++;
  567. }
  568. }
  569. void cmVisualStudio10TargetGenerator::WriteGroups()
  570. {
  571. // collect up group information
  572. std::vector<cmSourceGroup> sourceGroups =
  573. this->Makefile->GetSourceGroups();
  574. std::vector<cmSourceFile*> classes = this->Target->GetSourceFiles();
  575. std::set<cmSourceGroup*> groupsUsed;
  576. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  577. s != classes.end(); s++)
  578. {
  579. cmSourceFile* sf = *s;
  580. std::string const& source = sf->GetFullPath();
  581. cmSourceGroup& sourceGroup =
  582. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  583. groupsUsed.insert(&sourceGroup);
  584. }
  585. this->AddMissingSourceGroups(groupsUsed, sourceGroups);
  586. // Write out group file
  587. std::string path = this->Makefile->GetStartOutputDirectory();
  588. path += "/";
  589. path += this->Name;
  590. path += ".vcxproj.filters";
  591. cmGeneratedFileStream fout(path.c_str());
  592. fout.SetCopyIfDifferent(true);
  593. char magic[] = {0xEF,0xBB, 0xBF};
  594. fout.write(magic, 3);
  595. cmGeneratedFileStream* save = this->BuildFileStream;
  596. this->BuildFileStream = & fout;
  597. this->WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  598. "<Project "
  599. "ToolsVersion=\"4.0\" "
  600. "xmlns=\"http://schemas.microsoft.com/"
  601. "developer/msbuild/2003\">\n",
  602. 0);
  603. for(ToolSourceMap::const_iterator ti = this->Tools.begin();
  604. ti != this->Tools.end(); ++ti)
  605. {
  606. this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups);
  607. }
  608. // Add object library contents as external objects.
  609. std::vector<std::string> objs;
  610. this->GeneratorTarget->UseObjectLibraries(objs);
  611. if(!objs.empty())
  612. {
  613. this->WriteString("<ItemGroup>\n", 1);
  614. for(std::vector<std::string>::const_iterator
  615. oi = objs.begin(); oi != objs.end(); ++oi)
  616. {
  617. std::string obj = *oi;
  618. this->WriteString("<Object Include=\"", 2);
  619. this->ConvertToWindowsSlash(obj);
  620. (*this->BuildFileStream ) << obj << "\">\n";
  621. this->WriteString("<Filter>Object Libraries</Filter>\n", 3);
  622. this->WriteString("</Object>\n", 2);
  623. }
  624. this->WriteString("</ItemGroup>\n", 1);
  625. }
  626. this->WriteString("<ItemGroup>\n", 1);
  627. for(std::set<cmSourceGroup*>::iterator g = groupsUsed.begin();
  628. g != groupsUsed.end(); ++g)
  629. {
  630. cmSourceGroup* sg = *g;
  631. const char* name = sg->GetFullName();
  632. if(strlen(name) != 0)
  633. {
  634. this->WriteString("<Filter Include=\"", 2);
  635. (*this->BuildFileStream) << name << "\">\n";
  636. std::string guidName = "SG_Filter_";
  637. guidName += name;
  638. this->GlobalGenerator->CreateGUID(guidName.c_str());
  639. this->WriteString("<UniqueIdentifier>", 3);
  640. std::string guid
  641. = this->GlobalGenerator->GetGUID(guidName.c_str());
  642. (*this->BuildFileStream)
  643. << "{"
  644. << guid << "}"
  645. << "</UniqueIdentifier>\n";
  646. this->WriteString("</Filter>\n", 2);
  647. }
  648. }
  649. if(!objs.empty())
  650. {
  651. this->WriteString("<Filter Include=\"Object Libraries\">\n", 2);
  652. std::string guidName = "SG_Filter_Object Libraries";
  653. this->GlobalGenerator->CreateGUID(guidName.c_str());
  654. this->WriteString("<UniqueIdentifier>", 3);
  655. std::string guid =
  656. this->GlobalGenerator->GetGUID(guidName.c_str());
  657. (*this->BuildFileStream) << "{" << guid << "}"
  658. << "</UniqueIdentifier>\n";
  659. this->WriteString("</Filter>\n", 2);
  660. }
  661. this->WriteString("</ItemGroup>\n", 1);
  662. this->WriteString("</Project>\n", 0);
  663. // restore stream pointer
  664. this->BuildFileStream = save;
  665. if (fout.Close())
  666. {
  667. this->GlobalGenerator->FileReplacedDuringGenerate(path);
  668. }
  669. }
  670. // Add to groupsUsed empty source groups that have non-empty children.
  671. void
  672. cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
  673. std::set<cmSourceGroup*>& groupsUsed,
  674. const std::vector<cmSourceGroup>& allGroups
  675. )
  676. {
  677. for(std::vector<cmSourceGroup>::const_iterator current = allGroups.begin();
  678. current != allGroups.end(); ++current)
  679. {
  680. std::vector<cmSourceGroup> const& children = current->GetGroupChildren();
  681. if(children.empty())
  682. {
  683. continue; // the group is really empty
  684. }
  685. this->AddMissingSourceGroups(groupsUsed, children);
  686. cmSourceGroup* current_ptr = const_cast<cmSourceGroup*>(&(*current));
  687. if(groupsUsed.find(current_ptr) != groupsUsed.end())
  688. {
  689. continue; // group has already been added to set
  690. }
  691. // check if it least one of the group's descendants is not empty
  692. // (at least one child must already have been added)
  693. std::vector<cmSourceGroup>::const_iterator child_it = children.begin();
  694. while(child_it != children.end())
  695. {
  696. cmSourceGroup* child_ptr = const_cast<cmSourceGroup*>(&(*child_it));
  697. if(groupsUsed.find(child_ptr) != groupsUsed.end())
  698. {
  699. break; // found a child that was already added => add current group too
  700. }
  701. child_it++;
  702. }
  703. if(child_it == children.end())
  704. {
  705. continue; // no descendants have source files => ignore this group
  706. }
  707. groupsUsed.insert(current_ptr);
  708. }
  709. }
  710. void
  711. cmVisualStudio10TargetGenerator::
  712. WriteGroupSources(const char* name,
  713. ToolSources const& sources,
  714. std::vector<cmSourceGroup>& sourceGroups)
  715. {
  716. this->WriteString("<ItemGroup>\n", 1);
  717. for(ToolSources::const_iterator s = sources.begin();
  718. s != sources.end(); ++s)
  719. {
  720. cmSourceFile* sf = s->SourceFile;
  721. std::string const& source = sf->GetFullPath();
  722. cmSourceGroup& sourceGroup =
  723. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  724. const char* filter = sourceGroup.GetFullName();
  725. this->WriteString("<", 2);
  726. std::string path = this->ConvertPath(source, s->RelativePath);
  727. this->ConvertToWindowsSlash(path);
  728. (*this->BuildFileStream) << name << " Include=\""
  729. << path;
  730. if(strlen(filter))
  731. {
  732. (*this->BuildFileStream) << "\">\n";
  733. this->WriteString("<Filter>", 3);
  734. (*this->BuildFileStream) << filter << "</Filter>\n";
  735. this->WriteString("</", 2);
  736. (*this->BuildFileStream) << name << ">\n";
  737. }
  738. else
  739. {
  740. (*this->BuildFileStream) << "\" />\n";
  741. }
  742. }
  743. this->WriteString("</ItemGroup>\n", 1);
  744. }
  745. void cmVisualStudio10TargetGenerator::WriteSource(
  746. const char* tool, cmSourceFile* sf, const char* end)
  747. {
  748. // Visual Studio tools append relative paths to the current dir, as in:
  749. //
  750. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  751. //
  752. // and fail if this exceeds the maximum allowed path length. Our path
  753. // conversion uses full paths outside the build tree to allow deeper trees.
  754. bool forceRelative = false;
  755. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), false);
  756. if(this->LocalGenerator->GetVersion() == cmLocalVisualStudioGenerator::VS10
  757. && cmSystemTools::FileIsFullPath(sourceFile.c_str()))
  758. {
  759. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  760. // refuses to show the property page in the IDE for a source file with a
  761. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  762. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  763. // full path except for custom commands. Custom commands do not work
  764. // without a relative path, but they do not seem to be involved in tools
  765. // with the above behavior. For other sources we now use a relative path
  766. // when the combined path will not be too long so property pages appear.
  767. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  768. size_t const maxLen = 250;
  769. if(sf->GetCustomCommand() ||
  770. ((strlen(this->Makefile->GetCurrentOutputDirectory()) + 1 +
  771. sourceRel.length()) <= maxLen))
  772. {
  773. forceRelative = true;
  774. sourceFile = sourceRel;
  775. }
  776. else
  777. {
  778. this->GlobalGenerator->PathTooLong(this->Target, sf, sourceRel);
  779. }
  780. }
  781. this->ConvertToWindowsSlash(sourceFile);
  782. this->WriteString("<", 2);
  783. (*this->BuildFileStream ) << tool <<
  784. " Include=\"" << sourceFile << "\"" << (end? end : " />\n");
  785. ToolSource toolSource = {sf, forceRelative};
  786. this->Tools[tool].push_back(toolSource);
  787. }
  788. void cmVisualStudio10TargetGenerator::WriteSources(
  789. const char* tool, std::vector<cmSourceFile*> const& sources)
  790. {
  791. for(std::vector<cmSourceFile*>::const_iterator
  792. si = sources.begin(); si != sources.end(); ++si)
  793. {
  794. this->WriteSource(tool, *si);
  795. }
  796. }
  797. void cmVisualStudio10TargetGenerator::WriteAllSources()
  798. {
  799. if(this->Target->GetType() > cmTarget::UTILITY)
  800. {
  801. return;
  802. }
  803. this->WriteString("<ItemGroup>\n", 1);
  804. this->WriteSources("ClInclude", this->GeneratorTarget->HeaderSources);
  805. this->WriteSources("Midl", this->GeneratorTarget->IDLSources);
  806. for(std::vector<cmSourceFile*>::const_iterator
  807. si = this->GeneratorTarget->ObjectSources.begin();
  808. si != this->GeneratorTarget->ObjectSources.end(); ++si)
  809. {
  810. const char* lang = (*si)->GetLanguage();
  811. bool cl = strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0;
  812. bool rc = strcmp(lang, "RC") == 0;
  813. const char* tool = cl? "ClCompile" : (rc? "ResourceCompile" : "None");
  814. this->WriteSource(tool, *si, " ");
  815. // ouput any flags specific to this source file
  816. if(cl && this->OutputSourceSpecificFlags(*si))
  817. {
  818. // if the source file has specific flags the tag
  819. // is ended on a new line
  820. this->WriteString("</ClCompile>\n", 2);
  821. }
  822. else if(rc && this->OutputSourceSpecificFlags(*si))
  823. {
  824. this->WriteString("</ResourceCompile>\n", 2);
  825. }
  826. else
  827. {
  828. (*this->BuildFileStream ) << " />\n";
  829. }
  830. }
  831. if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
  832. {
  833. // For VS >= 11 we use LinkObjects to avoid linking custom command
  834. // outputs. Use Object for all external objects, generated or not.
  835. this->WriteSources("Object", this->GeneratorTarget->ExternalObjects);
  836. }
  837. else
  838. {
  839. // If an object file is generated in this target, then vs10 will use
  840. // it in the build, and we have to list it as None instead of Object.
  841. for(std::vector<cmSourceFile*>::const_iterator
  842. si = this->GeneratorTarget->ExternalObjects.begin();
  843. si != this->GeneratorTarget->ExternalObjects.end(); ++si)
  844. {
  845. std::vector<cmSourceFile*> const* d=this->Target->GetSourceDepends(*si);
  846. this->WriteSource((d && !d->empty())? "None":"Object", *si);
  847. }
  848. }
  849. this->WriteSources("None", this->GeneratorTarget->ExtraSources);
  850. // Add object library contents as external objects.
  851. std::vector<std::string> objs;
  852. this->GeneratorTarget->UseObjectLibraries(objs);
  853. for(std::vector<std::string>::const_iterator
  854. oi = objs.begin(); oi != objs.end(); ++oi)
  855. {
  856. std::string obj = *oi;
  857. this->WriteString("<Object Include=\"", 2);
  858. this->ConvertToWindowsSlash(obj);
  859. (*this->BuildFileStream ) << obj << "\" />\n";
  860. }
  861. this->WriteString("</ItemGroup>\n", 1);
  862. }
  863. bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  864. cmSourceFile* source)
  865. {
  866. cmSourceFile& sf = *source;
  867. std::string objectName;
  868. if(this->GeneratorTarget->ExplicitObjectName.find(&sf)
  869. != this->GeneratorTarget->ExplicitObjectName.end())
  870. {
  871. objectName = this->GeneratorTarget->Objects[&sf];
  872. }
  873. std::string flags;
  874. std::string defines;
  875. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  876. {
  877. flags += cflags;
  878. }
  879. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  880. {
  881. defines += cdefs;
  882. }
  883. const char* lang =
  884. this->GlobalGenerator->GetLanguageFromExtension
  885. (sf.GetExtension().c_str());
  886. const char* sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  887. const char* linkLanguage = this->Target->GetLinkerLanguage();
  888. bool needForceLang = false;
  889. // source file does not match its extension language
  890. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  891. {
  892. needForceLang = true;
  893. lang = sourceLang;
  894. }
  895. // if the source file does not match the linker language
  896. // then force c or c++
  897. if(needForceLang || (linkLanguage && lang
  898. && strcmp(lang, linkLanguage) != 0))
  899. {
  900. if(strcmp(lang, "CXX") == 0)
  901. {
  902. // force a C++ file type
  903. flags += " /TP ";
  904. }
  905. else if(strcmp(lang, "C") == 0)
  906. {
  907. // force to c
  908. flags += " /TC ";
  909. }
  910. }
  911. bool hasFlags = false;
  912. // for the first time we need a new line if there is something
  913. // produced here.
  914. const char* firstString = ">\n";
  915. if(objectName.size())
  916. {
  917. (*this->BuildFileStream ) << firstString;
  918. firstString = "";
  919. hasFlags = true;
  920. this->WriteString("<ObjectFileName>", 3);
  921. (*this->BuildFileStream )
  922. << "$(IntDir)/" << objectName << "</ObjectFileName>\n";
  923. }
  924. std::vector<std::string> *configs =
  925. static_cast<cmGlobalVisualStudio7Generator *>
  926. (this->GlobalGenerator)->GetConfigurations();
  927. for( std::vector<std::string>::iterator config = configs->begin();
  928. config != configs->end(); ++config)
  929. {
  930. std::string configUpper = cmSystemTools::UpperCase(*config);
  931. std::string configDefines = defines;
  932. std::string defPropName = "COMPILE_DEFINITIONS_";
  933. defPropName += configUpper;
  934. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  935. {
  936. if(configDefines.size())
  937. {
  938. configDefines += ";";
  939. }
  940. configDefines += ccdefs;
  941. }
  942. // if we have flags or defines for this config then
  943. // use them
  944. if(flags.size() || configDefines.size())
  945. {
  946. (*this->BuildFileStream ) << firstString;
  947. firstString = ""; // only do firstString once
  948. hasFlags = true;
  949. cmVisualStudioGeneratorOptions
  950. clOptions(this->LocalGenerator,
  951. cmVisualStudioGeneratorOptions::Compiler,
  952. cmVSGetCLFlagTable(this->LocalGenerator), 0, this);
  953. clOptions.Parse(flags.c_str());
  954. clOptions.AddDefines(configDefines.c_str());
  955. clOptions.SetConfiguration((*config).c_str());
  956. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  957. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  958. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream,
  959. " ", "\n", lang);
  960. }
  961. }
  962. return hasFlags;
  963. }
  964. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
  965. {
  966. cmTarget::TargetType ttype = this->Target->GetType();
  967. if(ttype > cmTarget::GLOBAL_TARGET)
  968. {
  969. return;
  970. }
  971. this->WriteString("<PropertyGroup>\n", 2);
  972. this->WriteString("<_ProjectFileVersion>10.0.20506.1"
  973. "</_ProjectFileVersion>\n", 3);
  974. std::vector<std::string> *configs =
  975. static_cast<cmGlobalVisualStudio7Generator *>
  976. (this->GlobalGenerator)->GetConfigurations();
  977. for(std::vector<std::string>::iterator config = configs->begin();
  978. config != configs->end(); ++config)
  979. {
  980. if(ttype >= cmTarget::UTILITY)
  981. {
  982. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  983. *this->BuildFileStream
  984. << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
  985. << "</IntDir>\n";
  986. }
  987. else
  988. {
  989. std::string intermediateDir = this->LocalGenerator->
  990. GetTargetDirectory(*this->Target);
  991. intermediateDir += "/";
  992. intermediateDir += *config;
  993. intermediateDir += "/";
  994. std::string outDir;
  995. std::string targetNameFull;
  996. if(ttype == cmTarget::OBJECT_LIBRARY)
  997. {
  998. outDir = intermediateDir;
  999. targetNameFull = this->Target->GetName();
  1000. targetNameFull += ".lib";
  1001. }
  1002. else
  1003. {
  1004. outDir = this->Target->GetDirectory(config->c_str()) + "/";
  1005. targetNameFull = this->Target->GetFullName(config->c_str());
  1006. }
  1007. this->ConvertToWindowsSlash(intermediateDir);
  1008. this->ConvertToWindowsSlash(outDir);
  1009. this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
  1010. *this->BuildFileStream << outDir
  1011. << "</OutDir>\n";
  1012. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1013. *this->BuildFileStream << intermediateDir
  1014. << "</IntDir>\n";
  1015. this->WritePlatformConfigTag("TargetName", config->c_str(), 3);
  1016. *this->BuildFileStream
  1017. << cmSystemTools::GetFilenameWithoutLastExtension(
  1018. targetNameFull.c_str())
  1019. << "</TargetName>\n";
  1020. this->WritePlatformConfigTag("TargetExt", config->c_str(), 3);
  1021. *this->BuildFileStream
  1022. << cmSystemTools::GetFilenameLastExtension(targetNameFull.c_str())
  1023. << "</TargetExt>\n";
  1024. this->OutputLinkIncremental(*config);
  1025. }
  1026. }
  1027. this->WriteString("</PropertyGroup>\n", 2);
  1028. }
  1029. void
  1030. cmVisualStudio10TargetGenerator::
  1031. OutputLinkIncremental(std::string const& configName)
  1032. {
  1033. // static libraries and things greater than modules do not need
  1034. // to set this option
  1035. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
  1036. || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
  1037. {
  1038. return;
  1039. }
  1040. Options& linkOptions = *(this->LinkOptions[configName]);
  1041. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  1042. this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 3);
  1043. *this->BuildFileStream << (incremental?incremental:"true")
  1044. << "</LinkIncremental>\n";
  1045. linkOptions.RemoveFlag("LinkIncremental");
  1046. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  1047. this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 3);
  1048. *this->BuildFileStream << (manifest?manifest:"true")
  1049. << "</GenerateManifest>\n";
  1050. linkOptions.RemoveFlag("GenerateManifest");
  1051. // Some link options belong here. Use them now and remove them so that
  1052. // WriteLinkOptions does not use them.
  1053. const char* flags[] = {
  1054. "LinkDelaySign",
  1055. "LinkKeyFile",
  1056. 0};
  1057. for(const char** f = flags; *f; ++f)
  1058. {
  1059. const char* flag = *f;
  1060. if(const char* value = linkOptions.GetFlag(flag))
  1061. {
  1062. this->WritePlatformConfigTag(flag, configName.c_str(), 3);
  1063. *this->BuildFileStream << value << "</" << flag << ">\n";
  1064. linkOptions.RemoveFlag(flag);
  1065. }
  1066. }
  1067. }
  1068. //----------------------------------------------------------------------------
  1069. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  1070. {
  1071. std::vector<std::string> const* configs =
  1072. this->GlobalGenerator->GetConfigurations();
  1073. for(std::vector<std::string>::const_iterator i = configs->begin();
  1074. i != configs->end(); ++i)
  1075. {
  1076. if(!this->ComputeClOptions(*i))
  1077. {
  1078. return false;
  1079. }
  1080. }
  1081. return true;
  1082. }
  1083. //----------------------------------------------------------------------------
  1084. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  1085. std::string const& configName)
  1086. {
  1087. // much of this was copied from here:
  1088. // copied from cmLocalVisualStudio7Generator.cxx 805
  1089. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  1090. cmsys::auto_ptr<Options> pOptions(
  1091. new Options(this->LocalGenerator, Options::Compiler,
  1092. cmVSGetCLFlagTable(this->LocalGenerator)));
  1093. Options& clOptions = *pOptions;
  1094. std::string flags;
  1095. // collect up flags for
  1096. if(this->Target->GetType() < cmTarget::UTILITY)
  1097. {
  1098. const char* linkLanguage =
  1099. this->Target->GetLinkerLanguage(configName.c_str());
  1100. if(!linkLanguage)
  1101. {
  1102. cmSystemTools::Error
  1103. ("CMake can not determine linker language for target:",
  1104. this->Name.c_str());
  1105. return false;
  1106. }
  1107. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0
  1108. || strcmp(linkLanguage, "Fortran") == 0)
  1109. {
  1110. std::string baseFlagVar = "CMAKE_";
  1111. baseFlagVar += linkLanguage;
  1112. baseFlagVar += "_FLAGS";
  1113. flags = this->
  1114. Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
  1115. std::string flagVar = baseFlagVar + std::string("_") +
  1116. cmSystemTools::UpperCase(configName);
  1117. flags += " ";
  1118. flags += this->
  1119. Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
  1120. }
  1121. // set the correct language
  1122. if(strcmp(linkLanguage, "C") == 0)
  1123. {
  1124. flags += " /TC ";
  1125. }
  1126. if(strcmp(linkLanguage, "CXX") == 0)
  1127. {
  1128. flags += " /TP ";
  1129. }
  1130. }
  1131. // Add the target-specific flags.
  1132. if(const char* targetFlags = this->Target->GetProperty("COMPILE_FLAGS"))
  1133. {
  1134. flags += " ";
  1135. flags += targetFlags;
  1136. }
  1137. // Get preprocessor definitions for this directory.
  1138. std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags();
  1139. clOptions.FixExceptionHandlingDefault();
  1140. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  1141. clOptions.Parse(flags.c_str());
  1142. clOptions.Parse(defineFlags.c_str());
  1143. clOptions.AddDefines(this->Target->GetCompileDefinitions(
  1144. configName.c_str()).c_str());
  1145. clOptions.SetVerboseMakefile(
  1146. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  1147. // Add a definition for the configuration name.
  1148. std::string configDefine = "CMAKE_INTDIR=\"";
  1149. configDefine += configName;
  1150. configDefine += "\"";
  1151. clOptions.AddDefine(configDefine);
  1152. if(const char* exportMacro = this->Target->GetExportMacro())
  1153. {
  1154. clOptions.AddDefine(exportMacro);
  1155. }
  1156. this->ClOptions[configName] = pOptions.release();
  1157. return true;
  1158. }
  1159. //----------------------------------------------------------------------------
  1160. void cmVisualStudio10TargetGenerator::WriteClOptions(
  1161. std::string const& configName,
  1162. std::vector<std::string> const& includes)
  1163. {
  1164. Options& clOptions = *(this->ClOptions[configName]);
  1165. this->WriteString("<ClCompile>\n", 2);
  1166. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1167. this->OutputIncludes(includes);
  1168. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1169. // If not in debug mode, write the DebugInformationFormat field
  1170. // without value so PDBs don't get generated uselessly.
  1171. if(!clOptions.IsDebug())
  1172. {
  1173. this->WriteString("<DebugInformationFormat>"
  1174. "</DebugInformationFormat>\n", 3);
  1175. }
  1176. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1177. "\n", "CXX");
  1178. this->WriteString("<AssemblerListingLocation>", 3);
  1179. *this->BuildFileStream << configName
  1180. << "</AssemblerListingLocation>\n";
  1181. this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
  1182. this->WriteString("</ClCompile>\n", 2);
  1183. }
  1184. void cmVisualStudio10TargetGenerator::
  1185. OutputIncludes(std::vector<std::string> const & includes)
  1186. {
  1187. this->WriteString("<AdditionalIncludeDirectories>", 3);
  1188. for(std::vector<std::string>::const_iterator i = includes.begin();
  1189. i != includes.end(); ++i)
  1190. {
  1191. *this->BuildFileStream << *i << ";";
  1192. }
  1193. this->WriteString("%(AdditionalIncludeDirectories)"
  1194. "</AdditionalIncludeDirectories>\n", 0);
  1195. }
  1196. void cmVisualStudio10TargetGenerator::
  1197. WriteRCOptions(std::string const& configName,
  1198. std::vector<std::string> const & includes)
  1199. {
  1200. this->WriteString("<ResourceCompile>\n", 2);
  1201. Options& clOptions = *(this->ClOptions[configName]);
  1202. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1203. "\n", "RC");
  1204. this->OutputIncludes(includes);
  1205. this->WriteString("</ResourceCompile>\n", 2);
  1206. }
  1207. void
  1208. cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
  1209. {
  1210. if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
  1211. {
  1212. return;
  1213. }
  1214. const char* libflags = this->Target->GetProperty("STATIC_LIBRARY_FLAGS");
  1215. std::string flagsConfigVar = "STATIC_LIBRARY_FLAGS_";
  1216. flagsConfigVar += cmSystemTools::UpperCase(config);
  1217. const char* libflagsConfig =
  1218. this->Target->GetProperty(flagsConfigVar.c_str());
  1219. if(libflags || libflagsConfig)
  1220. {
  1221. this->WriteString("<Lib>\n", 2);
  1222. cmVisualStudioGeneratorOptions
  1223. libOptions(this->LocalGenerator,
  1224. cmVisualStudioGeneratorOptions::Linker,
  1225. cmVSGetLibFlagTable(this->LocalGenerator), 0, this);
  1226. libOptions.Parse(libflags?libflags:"");
  1227. libOptions.Parse(libflagsConfig?libflagsConfig:"");
  1228. libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1229. libOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1230. this->WriteString("</Lib>\n", 2);
  1231. }
  1232. }
  1233. //----------------------------------------------------------------------------
  1234. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  1235. {
  1236. if(this->Target->GetType() == cmTarget::EXECUTABLE ||
  1237. this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  1238. this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  1239. {
  1240. std::vector<std::string> const* configs =
  1241. this->GlobalGenerator->GetConfigurations();
  1242. for(std::vector<std::string>::const_iterator i = configs->begin();
  1243. i != configs->end(); ++i)
  1244. {
  1245. if(!this->ComputeLinkOptions(*i))
  1246. {
  1247. return false;
  1248. }
  1249. }
  1250. }
  1251. return true;
  1252. }
  1253. //----------------------------------------------------------------------------
  1254. bool
  1255. cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
  1256. {
  1257. cmsys::auto_ptr<Options> pOptions(
  1258. new Options(this->LocalGenerator, Options::Linker,
  1259. cmVSGetLinkFlagTable(this->LocalGenerator), 0, this));
  1260. Options& linkOptions = *pOptions;
  1261. const char* linkLanguage =
  1262. this->Target->GetLinkerLanguage(config.c_str());
  1263. if(!linkLanguage)
  1264. {
  1265. cmSystemTools::Error
  1266. ("CMake can not determine linker language for target:",
  1267. this->Name.c_str());
  1268. return false;
  1269. }
  1270. std::string CONFIG = cmSystemTools::UpperCase(config);
  1271. const char* linkType = "SHARED";
  1272. if(this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  1273. {
  1274. linkType = "MODULE";
  1275. }
  1276. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  1277. {
  1278. linkType = "EXE";
  1279. }
  1280. std::string stackVar = "CMAKE_";
  1281. stackVar += linkLanguage;
  1282. stackVar += "_STACK_SIZE";
  1283. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1284. std::string flags;
  1285. if(stackVal)
  1286. {
  1287. flags += " /STACK:";
  1288. flags += stackVal;
  1289. }
  1290. std::string linkFlagVarBase = "CMAKE_";
  1291. linkFlagVarBase += linkType;
  1292. linkFlagVarBase += "_LINKER_FLAGS";
  1293. flags += " ";
  1294. flags += this->
  1295. Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
  1296. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  1297. flags += " ";
  1298. flags += this->
  1299. Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
  1300. const char* targetLinkFlags = this->Target->GetProperty("LINK_FLAGS");
  1301. if(targetLinkFlags)
  1302. {
  1303. flags += " ";
  1304. flags += targetLinkFlags;
  1305. }
  1306. std::string flagsProp = "LINK_FLAGS_";
  1307. flagsProp += CONFIG;
  1308. if(const char* flagsConfig = this->Target->GetProperty(flagsProp.c_str()))
  1309. {
  1310. flags += " ";
  1311. flags += flagsConfig;
  1312. }
  1313. if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
  1314. {
  1315. flags += " /SUBSYSTEM:WINDOWS";
  1316. }
  1317. else
  1318. {
  1319. flags += " /SUBSYSTEM:CONSOLE";
  1320. }
  1321. std::string standardLibsVar = "CMAKE_";
  1322. standardLibsVar += linkLanguage;
  1323. standardLibsVar += "_STANDARD_LIBRARIES";
  1324. std::string
  1325. libs = this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1326. // Remove trailing spaces from libs
  1327. std::string::size_type pos = libs.size()-1;
  1328. if(libs.size() != 0)
  1329. {
  1330. while(libs[pos] == ' ')
  1331. {
  1332. pos--;
  1333. }
  1334. }
  1335. if(pos != libs.size()-1)
  1336. {
  1337. libs = libs.substr(0, pos+1);
  1338. }
  1339. // Replace spaces in libs with ;
  1340. cmSystemTools::ReplaceString(libs, " ", ";");
  1341. cmComputeLinkInformation* pcli =
  1342. this->Target->GetLinkInformation(config.c_str());
  1343. if(!pcli)
  1344. {
  1345. cmSystemTools::Error
  1346. ("CMake can not compute cmComputeLinkInformation for target:",
  1347. this->Name.c_str());
  1348. return false;
  1349. }
  1350. // add the libraries for the target to libs string
  1351. cmComputeLinkInformation& cli = *pcli;
  1352. this->AddLibraries(cli, libs);
  1353. linkOptions.AddFlag("AdditionalDependencies", libs.c_str());
  1354. std::vector<std::string> const& ldirs = cli.GetDirectories();
  1355. const char* sep = "";
  1356. std::string linkDirs;
  1357. for(std::vector<std::string>::const_iterator d = ldirs.begin();
  1358. d != ldirs.end(); ++d)
  1359. {
  1360. // first just full path
  1361. linkDirs += sep;
  1362. linkDirs += *d;
  1363. sep = ";";
  1364. linkDirs += sep;
  1365. // next path with configuration type Debug, Release, etc
  1366. linkDirs += *d;
  1367. linkDirs += "/$(Configuration)";
  1368. linkDirs += sep;
  1369. }
  1370. linkDirs += "%(AdditionalLibraryDirectories)";
  1371. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs.c_str());
  1372. linkOptions.AddFlag("AdditionalDependencies", libs.c_str());
  1373. linkOptions.AddFlag("Version", "");
  1374. if(linkOptions.IsDebug() || flags.find("/debug") != flags.npos)
  1375. {
  1376. linkOptions.AddFlag("GenerateDebugInformation", "true");
  1377. }
  1378. else
  1379. {
  1380. linkOptions.AddFlag("GenerateDebugInformation", "false");
  1381. }
  1382. std::string targetName;
  1383. std::string targetNameSO;
  1384. std::string targetNameFull;
  1385. std::string targetNameImport;
  1386. std::string targetNamePDB;
  1387. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  1388. {
  1389. this->Target->GetExecutableNames(targetName, targetNameFull,
  1390. targetNameImport, targetNamePDB,
  1391. config.c_str());
  1392. }
  1393. else
  1394. {
  1395. this->Target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1396. targetNameImport, targetNamePDB,
  1397. config.c_str());
  1398. }
  1399. std::string pdb = this->Target->GetPDBDirectory(config.c_str());
  1400. pdb += "/";
  1401. pdb += targetNamePDB;
  1402. std::string imLib = this->Target->GetDirectory(config.c_str(), true);
  1403. imLib += "/";
  1404. imLib += targetNameImport;
  1405. linkOptions.AddFlag("ImportLibrary", imLib.c_str());
  1406. linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
  1407. linkOptions.Parse(flags.c_str());
  1408. if(!this->GeneratorTarget->ModuleDefinitionFile.empty())
  1409. {
  1410. linkOptions.AddFlag("ModuleDefinitionFile",
  1411. this->GeneratorTarget->ModuleDefinitionFile.c_str());
  1412. }
  1413. this->LinkOptions[config] = pOptions.release();
  1414. return true;
  1415. }
  1416. //----------------------------------------------------------------------------
  1417. void
  1418. cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
  1419. {
  1420. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
  1421. || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
  1422. {
  1423. return;
  1424. }
  1425. Options& linkOptions = *(this->LinkOptions[config]);
  1426. this->WriteString("<Link>\n", 2);
  1427. linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1428. linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1429. this->WriteString("</Link>\n", 2);
  1430. if(!this->GlobalGenerator->NeedLinkLibraryDependencies(*this->Target))
  1431. {
  1432. this->WriteString("<ProjectReference>\n", 2);
  1433. this->WriteString(
  1434. " <LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 2);
  1435. this->WriteString("</ProjectReference>\n", 2);
  1436. }
  1437. }
  1438. void cmVisualStudio10TargetGenerator::AddLibraries(
  1439. cmComputeLinkInformation& cli,
  1440. std::string& libstring)
  1441. {
  1442. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1443. ItemVector libs = cli.GetItems();
  1444. const char* sep = ";";
  1445. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1446. {
  1447. if(l->IsPath)
  1448. {
  1449. std::string path = this->LocalGenerator->
  1450. Convert(l->Value.c_str(),
  1451. cmLocalGenerator::START_OUTPUT,
  1452. cmLocalGenerator::UNCHANGED);
  1453. this->ConvertToWindowsSlash(path);
  1454. libstring += sep;
  1455. libstring += path;
  1456. }
  1457. else
  1458. {
  1459. libstring += sep;
  1460. libstring += l->Value;
  1461. }
  1462. }
  1463. }
  1464. void cmVisualStudio10TargetGenerator::
  1465. WriteMidlOptions(std::string const& /*config*/,
  1466. std::vector<std::string> const & includes)
  1467. {
  1468. this->WriteString("<Midl>\n", 2);
  1469. this->OutputIncludes(includes);
  1470. this->WriteString("<OutputDirectory>$(IntDir)</OutputDirectory>\n", 3);
  1471. this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
  1472. this->WriteString(
  1473. "<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
  1474. this->WriteString(
  1475. "<InterfaceIdentifierFileName>"
  1476. "%(Filename)_i.c</InterfaceIdentifierFileName>\n", 3);
  1477. this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n",3);
  1478. this->WriteString("</Midl>\n", 2);
  1479. }
  1480. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
  1481. {
  1482. std::vector<std::string> *configs =
  1483. static_cast<cmGlobalVisualStudio7Generator *>
  1484. (this->GlobalGenerator)->GetConfigurations();
  1485. for(std::vector<std::string>::iterator i = configs->begin();
  1486. i != configs->end(); ++i)
  1487. {
  1488. std::vector<std::string> includes;
  1489. this->LocalGenerator->GetIncludeDirectories(includes,
  1490. this->GeneratorTarget,
  1491. "C", i->c_str());
  1492. this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
  1493. *this->BuildFileStream << "\n";
  1494. // output cl compile flags <ClCompile></ClCompile>
  1495. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
  1496. {
  1497. this->WriteClOptions(*i, includes);
  1498. // output rc compile flags <ResourceCompile></ResourceCompile>
  1499. this->WriteRCOptions(*i, includes);
  1500. }
  1501. // output midl flags <Midl></Midl>
  1502. this->WriteMidlOptions(*i, includes);
  1503. // write events
  1504. this->WriteEvents(*i);
  1505. // output link flags <Link></Link>
  1506. this->WriteLinkOptions(*i);
  1507. // output lib flags <Lib></Lib>
  1508. this->WriteLibOptions(*i);
  1509. this->WriteString("</ItemDefinitionGroup>\n", 1);
  1510. }
  1511. }
  1512. void
  1513. cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
  1514. {
  1515. this->WriteEvent("PreLinkEvent",
  1516. this->Target->GetPreLinkCommands(), configName);
  1517. this->WriteEvent("PreBuildEvent",
  1518. this->Target->GetPreBuildCommands(), configName);
  1519. this->WriteEvent("PostBuildEvent",
  1520. this->Target->GetPostBuildCommands(), configName);
  1521. }
  1522. void cmVisualStudio10TargetGenerator::WriteEvent(
  1523. const char* name,
  1524. std::vector<cmCustomCommand> & commands,
  1525. std::string const& configName)
  1526. {
  1527. if(commands.size() == 0)
  1528. {
  1529. return;
  1530. }
  1531. this->WriteString("<", 2);
  1532. (*this->BuildFileStream ) << name << ">\n";
  1533. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1534. std::string script;
  1535. const char* pre = "";
  1536. std::string comment;
  1537. for(std::vector<cmCustomCommand>::iterator i = commands.begin();
  1538. i != commands.end(); ++i)
  1539. {
  1540. cmCustomCommand& command = *i;
  1541. comment += pre;
  1542. comment += lg->ConstructComment(command);
  1543. script += pre;
  1544. pre = "\n";
  1545. script +=
  1546. cmVS10EscapeXML(lg->ConstructScript(command, configName.c_str()));
  1547. }
  1548. comment = cmVS10EscapeComment(comment);
  1549. this->WriteString("<Message>",3);
  1550. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  1551. this->WriteString("<Command>", 3);
  1552. (*this->BuildFileStream ) << script;
  1553. (*this->BuildFileStream ) << "</Command>" << "\n";
  1554. this->WriteString("</", 2);
  1555. (*this->BuildFileStream ) << name << ">\n";
  1556. }
  1557. void cmVisualStudio10TargetGenerator::WriteProjectReferences()
  1558. {
  1559. cmGlobalGenerator::TargetDependSet const& unordered
  1560. = this->GlobalGenerator->GetTargetDirectDepends(*this->Target);
  1561. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  1562. OrderedTargetDependSet;
  1563. OrderedTargetDependSet depends(unordered);
  1564. this->WriteString("<ItemGroup>\n", 1);
  1565. for( OrderedTargetDependSet::const_iterator i = depends.begin();
  1566. i != depends.end(); ++i)
  1567. {
  1568. cmTarget* dt = *i;
  1569. // skip fortran targets as they can not be processed by MSBuild
  1570. // the only reference will be in the .sln file
  1571. if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  1572. ->TargetIsFortranOnly(*dt))
  1573. {
  1574. continue;
  1575. }
  1576. this->WriteString("<ProjectReference Include=\"", 2);
  1577. cmMakefile* mf = dt->GetMakefile();
  1578. std::string name = dt->GetName();
  1579. std::string path;
  1580. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  1581. if(p)
  1582. {
  1583. path = p;
  1584. }
  1585. else
  1586. {
  1587. path = mf->GetStartOutputDirectory();
  1588. path += "/";
  1589. path += dt->GetName();
  1590. path += ".vcxproj";
  1591. }
  1592. (*this->BuildFileStream) << path << "\">\n";
  1593. this->WriteString("<Project>", 3);
  1594. (*this->BuildFileStream)
  1595. << this->GlobalGenerator->GetGUID(name.c_str())
  1596. << "</Project>\n";
  1597. this->WriteString("</ProjectReference>\n", 2);
  1598. }
  1599. this->WriteString("</ItemGroup>\n", 1);
  1600. }