cmVisualStudio10TargetGenerator.cxx 56 KB

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