cmVisualStudio10TargetGenerator.cxx 56 KB

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