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