cmVisualStudio10TargetGenerator.cxx 56 KB

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