cmVisualStudio10TargetGenerator.cxx 56 KB

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