cmVisualStudio10TargetGenerator.cxx 56 KB

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