cmVisualStudio10TargetGenerator.cxx 56 KB

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