cmVisualStudio10TargetGenerator.cxx 55 KB

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