cmVisualStudio10TargetGenerator.cxx 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264
  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 "cmCustomCommandGenerator.h"
  21. #include "cmVS10CLFlagTable.h"
  22. #include "cmVS10RCFlagTable.h"
  23. #include "cmVS10LinkFlagTable.h"
  24. #include "cmVS10LibFlagTable.h"
  25. #include "cmVS11CLFlagTable.h"
  26. #include "cmVS11RCFlagTable.h"
  27. #include "cmVS11LinkFlagTable.h"
  28. #include "cmVS11LibFlagTable.h"
  29. #include "cmVS12CLFlagTable.h"
  30. #include "cmVS12RCFlagTable.h"
  31. #include "cmVS12LinkFlagTable.h"
  32. #include "cmVS12LibFlagTable.h"
  33. #include "cmVS14CLFlagTable.h"
  34. #include "cmVS14RCFlagTable.h"
  35. #include "cmVS14LinkFlagTable.h"
  36. #include "cmVS14LibFlagTable.h"
  37. #include <cmsys/auto_ptr.hxx>
  38. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetClFlagTable() const
  39. {
  40. if(this->MSTools)
  41. {
  42. cmLocalVisualStudioGenerator::VSVersion
  43. v = this->LocalGenerator->GetVersion();
  44. if(v >= cmLocalVisualStudioGenerator::VS14)
  45. { return cmVS14CLFlagTable; }
  46. else if(v >= cmLocalVisualStudioGenerator::VS12)
  47. { return cmVS12CLFlagTable; }
  48. else if(v == cmLocalVisualStudioGenerator::VS11)
  49. { return cmVS11CLFlagTable; }
  50. else
  51. { return cmVS10CLFlagTable; }
  52. }
  53. return 0;
  54. }
  55. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetRcFlagTable() const
  56. {
  57. if(this->MSTools)
  58. {
  59. cmLocalVisualStudioGenerator::VSVersion
  60. v = this->LocalGenerator->GetVersion();
  61. if(v >= cmLocalVisualStudioGenerator::VS14)
  62. { return cmVS14RCFlagTable; }
  63. else if(v >= cmLocalVisualStudioGenerator::VS12)
  64. { return cmVS12RCFlagTable; }
  65. else if(v == cmLocalVisualStudioGenerator::VS11)
  66. { return cmVS11RCFlagTable; }
  67. else
  68. { return cmVS10RCFlagTable; }
  69. }
  70. return 0;
  71. }
  72. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLibFlagTable() const
  73. {
  74. if(this->MSTools)
  75. {
  76. cmLocalVisualStudioGenerator::VSVersion
  77. v = this->LocalGenerator->GetVersion();
  78. if(v >= cmLocalVisualStudioGenerator::VS14)
  79. { return cmVS14LibFlagTable; }
  80. else if(v >= cmLocalVisualStudioGenerator::VS12)
  81. { return cmVS12LibFlagTable; }
  82. else if(v == cmLocalVisualStudioGenerator::VS11)
  83. { return cmVS11LibFlagTable; }
  84. else
  85. { return cmVS10LibFlagTable; }
  86. }
  87. return 0;
  88. }
  89. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLinkFlagTable() const
  90. {
  91. if(this->MSTools)
  92. {
  93. cmLocalVisualStudioGenerator::VSVersion
  94. v = this->LocalGenerator->GetVersion();
  95. if(v >= cmLocalVisualStudioGenerator::VS14)
  96. { return cmVS14LinkFlagTable; }
  97. else if(v >= cmLocalVisualStudioGenerator::VS12)
  98. { return cmVS12LinkFlagTable; }
  99. else if(v == cmLocalVisualStudioGenerator::VS11)
  100. { return cmVS11LinkFlagTable; }
  101. else
  102. { return cmVS10LinkFlagTable; }
  103. }
  104. return 0;
  105. }
  106. static std::string cmVS10EscapeXML(std::string arg)
  107. {
  108. cmSystemTools::ReplaceString(arg, "&", "&amp;");
  109. cmSystemTools::ReplaceString(arg, "<", "&lt;");
  110. cmSystemTools::ReplaceString(arg, ">", "&gt;");
  111. return arg;
  112. }
  113. static std::string cmVS10EscapeComment(std::string comment)
  114. {
  115. // MSBuild takes the CDATA of a <Message></Message> element and just
  116. // does "echo $CDATA" with no escapes. We must encode the string.
  117. // http://technet.microsoft.com/en-us/library/cc772462%28WS.10%29.aspx
  118. std::string echoable;
  119. for(std::string::iterator c = comment.begin(); c != comment.end(); ++c)
  120. {
  121. switch (*c)
  122. {
  123. case '\r': break;
  124. case '\n': echoable += '\t'; break;
  125. case '"': /* no break */
  126. case '|': /* no break */
  127. case '&': /* no break */
  128. case '<': /* no break */
  129. case '>': /* no break */
  130. case '^': echoable += '^'; /* no break */
  131. default: echoable += *c; break;
  132. }
  133. }
  134. return echoable;
  135. }
  136. cmVisualStudio10TargetGenerator::
  137. cmVisualStudio10TargetGenerator(cmTarget* target,
  138. cmGlobalVisualStudio10Generator* gg)
  139. {
  140. this->GlobalGenerator = gg;
  141. this->Target = target;
  142. this->GeneratorTarget = gg->GetGeneratorTarget(target);
  143. this->Makefile = target->GetMakefile();
  144. this->LocalGenerator =
  145. (cmLocalVisualStudio7Generator*)
  146. this->Makefile->GetLocalGenerator();
  147. this->Name = this->Target->GetName();
  148. this->GlobalGenerator->CreateGUID(this->Name.c_str());
  149. this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
  150. this->Platform = gg->GetPlatformName();
  151. this->MSTools = true;
  152. this->BuildFileStream = 0;
  153. }
  154. cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
  155. {
  156. for(OptionsMap::iterator i = this->ClOptions.begin();
  157. i != this->ClOptions.end(); ++i)
  158. {
  159. delete i->second;
  160. }
  161. for(OptionsMap::iterator i = this->LinkOptions.begin();
  162. i != this->LinkOptions.end(); ++i)
  163. {
  164. delete i->second;
  165. }
  166. if(!this->BuildFileStream)
  167. {
  168. return;
  169. }
  170. if (this->BuildFileStream->Close())
  171. {
  172. this->GlobalGenerator
  173. ->FileReplacedDuringGenerate(this->PathToVcxproj);
  174. }
  175. delete this->BuildFileStream;
  176. }
  177. void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
  178. const char* tag,
  179. const std::string& config,
  180. int indentLevel,
  181. const char* attribute,
  182. const char* end,
  183. std::ostream* stream)
  184. {
  185. if(!stream)
  186. {
  187. stream = this->BuildFileStream;
  188. }
  189. stream->fill(' ');
  190. stream->width(indentLevel*2 );
  191. (*stream ) << "";
  192. (*stream ) << "<" << tag
  193. << " Condition=\"'$(Configuration)|$(Platform)'=='";
  194. (*stream ) << config << "|" << this->Platform << "'\"";
  195. if(attribute)
  196. {
  197. (*stream ) << attribute;
  198. }
  199. // close the tag
  200. (*stream ) << ">";
  201. if(end)
  202. {
  203. (*stream ) << end;
  204. }
  205. }
  206. void cmVisualStudio10TargetGenerator::WriteString(const char* line,
  207. int indentLevel)
  208. {
  209. this->BuildFileStream->fill(' ');
  210. this->BuildFileStream->width(indentLevel*2 );
  211. // write an empty string to get the fill level indent to print
  212. (*this->BuildFileStream ) << "";
  213. (*this->BuildFileStream ) << line;
  214. }
  215. #define VS10_USER_PROPS "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props"
  216. void cmVisualStudio10TargetGenerator::Generate()
  217. {
  218. // do not generate external ms projects
  219. if(this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
  220. || this->Target->GetProperty("EXTERNAL_MSPROJECT"))
  221. {
  222. return;
  223. }
  224. // Tell the global generator the name of the project file
  225. this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
  226. this->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
  227. ".vcxproj");
  228. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
  229. {
  230. if(!this->ComputeClOptions())
  231. {
  232. return;
  233. }
  234. if(!this->ComputeRcOptions())
  235. {
  236. return;
  237. }
  238. if(!this->ComputeLinkOptions())
  239. {
  240. return;
  241. }
  242. }
  243. cmMakefile* mf = this->Target->GetMakefile();
  244. std::string path = mf->GetStartOutputDirectory();
  245. path += "/";
  246. path += this->Name;
  247. path += ".vcxproj";
  248. this->BuildFileStream =
  249. new cmGeneratedFileStream(path.c_str());
  250. this->PathToVcxproj = path;
  251. this->BuildFileStream->SetCopyIfDifferent(true);
  252. // Write the encoding header into the file
  253. char magic[] = {0xEF,0xBB, 0xBF};
  254. this->BuildFileStream->write(magic, 3);
  255. //get the tools version to use
  256. const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
  257. std::string project_defaults=
  258. "<?xml version=\"1.0\" encoding=\"" +
  259. this->GlobalGenerator->Encoding() + "\"?>\n";
  260. project_defaults.append("<Project DefaultTargets=\"Build\" ToolsVersion=\"");
  261. project_defaults.append(toolsVer +"\" ");
  262. project_defaults.append(
  263. "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
  264. this->WriteString(project_defaults.c_str(),0);
  265. this->WriteProjectConfigurations();
  266. this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1);
  267. this->WriteString("<ProjectGUID>", 2);
  268. (*this->BuildFileStream) << "{" << this->GUID << "}</ProjectGUID>\n";
  269. if(this->MSTools && this->Target->GetType() <= cmTarget::GLOBAL_TARGET)
  270. {
  271. this->WriteApplicationTypeSettings();
  272. }
  273. const char* vsProjectTypes =
  274. this->Target->GetProperty("VS_GLOBAL_PROJECT_TYPES");
  275. if(vsProjectTypes)
  276. {
  277. this->WriteString("<ProjectTypes>", 2);
  278. (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectTypes) <<
  279. "</ProjectTypes>\n";
  280. }
  281. const char* vsProjectName = this->Target->GetProperty("VS_SCC_PROJECTNAME");
  282. const char* vsLocalPath = this->Target->GetProperty("VS_SCC_LOCALPATH");
  283. const char* vsProvider = this->Target->GetProperty("VS_SCC_PROVIDER");
  284. if( vsProjectName && vsLocalPath && vsProvider )
  285. {
  286. this->WriteString("<SccProjectName>", 2);
  287. (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectName) <<
  288. "</SccProjectName>\n";
  289. this->WriteString("<SccLocalPath>", 2);
  290. (*this->BuildFileStream) << cmVS10EscapeXML(vsLocalPath) <<
  291. "</SccLocalPath>\n";
  292. this->WriteString("<SccProvider>", 2);
  293. (*this->BuildFileStream) << cmVS10EscapeXML(vsProvider) <<
  294. "</SccProvider>\n";
  295. const char* vsAuxPath = this->Target->GetProperty("VS_SCC_AUXPATH");
  296. if( vsAuxPath )
  297. {
  298. this->WriteString("<SccAuxPath>", 2);
  299. (*this->BuildFileStream) << cmVS10EscapeXML(vsAuxPath) <<
  300. "</SccAuxPath>\n";
  301. }
  302. }
  303. const char* vsGlobalKeyword =
  304. this->Target->GetProperty("VS_GLOBAL_KEYWORD");
  305. if(!vsGlobalKeyword)
  306. {
  307. this->WriteString("<Keyword>Win32Proj</Keyword>\n", 2);
  308. }
  309. else
  310. {
  311. this->WriteString("<Keyword>", 2);
  312. (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalKeyword) <<
  313. "</Keyword>\n";
  314. }
  315. const char* vsGlobalRootNamespace =
  316. this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
  317. if(vsGlobalRootNamespace)
  318. {
  319. this->WriteString("<RootNamespace>", 2);
  320. (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalRootNamespace) <<
  321. "</RootNamespace>\n";
  322. }
  323. this->WriteString("<Platform>", 2);
  324. (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
  325. << "</Platform>\n";
  326. const char* projLabel = this->Target->GetProperty("PROJECT_LABEL");
  327. if(!projLabel)
  328. {
  329. projLabel = this->Name.c_str();
  330. }
  331. this->WriteString("<ProjectName>", 2);
  332. (*this->BuildFileStream) << cmVS10EscapeXML(projLabel) << "</ProjectName>\n";
  333. if(const char* targetFrameworkVersion = this->Target->GetProperty(
  334. "VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
  335. {
  336. this->WriteString("<TargetFrameworkVersion>", 2);
  337. (*this->BuildFileStream) << cmVS10EscapeXML(targetFrameworkVersion)
  338. << "</TargetFrameworkVersion>\n";
  339. }
  340. this->WriteString("</PropertyGroup>\n", 1);
  341. this->WriteString("<Import Project="
  342. "\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n",
  343. 1);
  344. this->WriteProjectConfigurationValues();
  345. this->WriteString(
  346. "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n", 1);
  347. this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1);
  348. if (this->GlobalGenerator->IsMasmEnabled())
  349. {
  350. this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
  351. "BuildCustomizations\\masm.props\" />\n", 2);
  352. }
  353. this->WriteString("</ImportGroup>\n", 1);
  354. this->WriteString("<ImportGroup Label=\"PropertySheets\">\n", 1);
  355. this->WriteString("<Import Project=\"" VS10_USER_PROPS "\""
  356. " Condition=\"exists('" VS10_USER_PROPS "')\""
  357. " Label=\"LocalAppDataPlatform\" />\n", 2);
  358. this->WriteString("</ImportGroup>\n", 1);
  359. this->WriteString("<PropertyGroup Label=\"UserMacros\" />\n", 1);
  360. this->WriteWinRTPackageCertificateKeyFile();
  361. this->WritePathAndIncrementalLinkOptions();
  362. this->WriteItemDefinitionGroups();
  363. this->WriteCustomCommands();
  364. this->WriteAllSources();
  365. this->WriteDotNetReferences();
  366. this->WriteEmbeddedResourceGroup();
  367. this->WriteWinRTReferences();
  368. this->WriteProjectReferences();
  369. this->WriteString(
  370. "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\""
  371. " />\n", 1);
  372. this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
  373. if (this->GlobalGenerator->IsMasmEnabled())
  374. {
  375. this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
  376. "BuildCustomizations\\masm.targets\" />\n", 2);
  377. }
  378. this->WriteString("</ImportGroup>\n", 1);
  379. this->WriteString("</Project>", 0);
  380. // The groups are stored in a separate file for VS 10
  381. this->WriteGroups();
  382. }
  383. void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
  384. {
  385. std::vector<std::string> references;
  386. if(const char* vsDotNetReferences =
  387. this->Target->GetProperty("VS_DOTNET_REFERENCES"))
  388. {
  389. cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
  390. }
  391. if(!references.empty())
  392. {
  393. this->WriteString("<ItemGroup>\n", 1);
  394. for(std::vector<std::string>::iterator ri = references.begin();
  395. ri != references.end(); ++ri)
  396. {
  397. this->WriteString("<Reference Include=\"", 2);
  398. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
  399. this->WriteString("<CopyLocalSatelliteAssemblies>true"
  400. "</CopyLocalSatelliteAssemblies>\n", 3);
  401. this->WriteString("<ReferenceOutputAssembly>true"
  402. "</ReferenceOutputAssembly>\n", 3);
  403. this->WriteString("</Reference>\n", 2);
  404. }
  405. this->WriteString("</ItemGroup>\n", 1);
  406. }
  407. }
  408. void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
  409. {
  410. std::vector<cmSourceFile const*> resxObjs;
  411. this->GeneratorTarget->GetResxSources(resxObjs, "");
  412. if(!resxObjs.empty())
  413. {
  414. this->WriteString("<ItemGroup>\n", 1);
  415. for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
  416. oi != resxObjs.end(); ++oi)
  417. {
  418. std::string obj = (*oi)->GetFullPath();
  419. this->WriteString("<EmbeddedResource Include=\"", 2);
  420. this->ConvertToWindowsSlash(obj);
  421. (*this->BuildFileStream ) << obj << "\">\n";
  422. this->WriteString("<DependentUpon>", 3);
  423. std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h";
  424. (*this->BuildFileStream ) << hFileName;
  425. this->WriteString("</DependentUpon>\n", 3);
  426. std::vector<std::string> const * configs =
  427. this->GlobalGenerator->GetConfigurations();
  428. for(std::vector<std::string>::const_iterator i = configs->begin();
  429. i != configs->end(); ++i)
  430. {
  431. this->WritePlatformConfigTag("LogicalName", i->c_str(), 3);
  432. if(this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE"))
  433. {
  434. (*this->BuildFileStream ) << "$(RootNamespace).";
  435. }
  436. (*this->BuildFileStream ) << "%(Filename)";
  437. (*this->BuildFileStream ) << ".resources";
  438. (*this->BuildFileStream ) << "</LogicalName>\n";
  439. }
  440. this->WriteString("</EmbeddedResource>\n", 2);
  441. }
  442. this->WriteString("</ItemGroup>\n", 1);
  443. }
  444. }
  445. void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
  446. {
  447. std::vector<std::string> references;
  448. if(const char* vsWinRTReferences =
  449. this->Target->GetProperty("VS_WINRT_REFERENCES"))
  450. {
  451. cmSystemTools::ExpandListArgument(vsWinRTReferences, references);
  452. }
  453. if(!references.empty())
  454. {
  455. this->WriteString("<ItemGroup>\n", 1);
  456. for(std::vector<std::string>::iterator ri = references.begin();
  457. ri != references.end(); ++ri)
  458. {
  459. this->WriteString("<Reference Include=\"", 2);
  460. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
  461. this->WriteString("<IsWinMDFile>true</IsWinMDFile>\n", 3);
  462. this->WriteString("</Reference>\n", 2);
  463. }
  464. this->WriteString("</ItemGroup>\n", 1);
  465. }
  466. }
  467. // ConfigurationType Application, Utility StaticLibrary DynamicLibrary
  468. void cmVisualStudio10TargetGenerator::WriteProjectConfigurations()
  469. {
  470. this->WriteString("<ItemGroup Label=\"ProjectConfigurations\">\n", 1);
  471. std::vector<std::string> *configs =
  472. static_cast<cmGlobalVisualStudio7Generator *>
  473. (this->GlobalGenerator)->GetConfigurations();
  474. for(std::vector<std::string>::iterator i = configs->begin();
  475. i != configs->end(); ++i)
  476. {
  477. this->WriteString("<ProjectConfiguration Include=\"", 2);
  478. (*this->BuildFileStream ) << *i << "|" << this->Platform << "\">\n";
  479. this->WriteString("<Configuration>", 3);
  480. (*this->BuildFileStream ) << *i << "</Configuration>\n";
  481. this->WriteString("<Platform>", 3);
  482. (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
  483. << "</Platform>\n";
  484. this->WriteString("</ProjectConfiguration>\n", 2);
  485. }
  486. this->WriteString("</ItemGroup>\n", 1);
  487. }
  488. void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
  489. {
  490. std::vector<std::string> *configs =
  491. static_cast<cmGlobalVisualStudio7Generator *>
  492. (this->GlobalGenerator)->GetConfigurations();
  493. for(std::vector<std::string>::iterator i = configs->begin();
  494. i != configs->end(); ++i)
  495. {
  496. this->WritePlatformConfigTag("PropertyGroup",
  497. i->c_str(),
  498. 1, " Label=\"Configuration\"", "\n");
  499. std::string configType = "<ConfigurationType>";
  500. switch(this->Target->GetType())
  501. {
  502. case cmTarget::SHARED_LIBRARY:
  503. case cmTarget::MODULE_LIBRARY:
  504. configType += "DynamicLibrary";
  505. break;
  506. case cmTarget::OBJECT_LIBRARY:
  507. case cmTarget::STATIC_LIBRARY:
  508. configType += "StaticLibrary";
  509. break;
  510. case cmTarget::EXECUTABLE:
  511. configType += "Application";
  512. break;
  513. case cmTarget::UTILITY:
  514. case cmTarget::GLOBAL_TARGET:
  515. configType += "Utility";
  516. break;
  517. case cmTarget::UNKNOWN_LIBRARY:
  518. case cmTarget::INTERFACE_LIBRARY:
  519. break;
  520. }
  521. configType += "</ConfigurationType>\n";
  522. this->WriteString(configType.c_str(), 2);
  523. if(this->MSTools)
  524. {
  525. this->WriteMSToolConfigurationValues(*i);
  526. }
  527. this->WriteString("</PropertyGroup>\n", 1);
  528. }
  529. }
  530. //----------------------------------------------------------------------------
  531. void cmVisualStudio10TargetGenerator
  532. ::WriteMSToolConfigurationValues(std::string const& config)
  533. {
  534. cmGlobalVisualStudio10Generator* gg =
  535. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  536. const char* mfcFlag =
  537. this->Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG");
  538. std::string mfcFlagValue = mfcFlag ? mfcFlag : "0";
  539. std::string useOfMfcValue = "false";
  540. if(mfcFlagValue == "1")
  541. {
  542. useOfMfcValue = "Static";
  543. }
  544. else if(mfcFlagValue == "2")
  545. {
  546. useOfMfcValue = "Dynamic";
  547. }
  548. std::string mfcLine = "<UseOfMfc>";
  549. mfcLine += useOfMfcValue + "</UseOfMfc>\n";
  550. this->WriteString(mfcLine.c_str(), 2);
  551. if((this->Target->GetType() <= cmTarget::OBJECT_LIBRARY &&
  552. this->ClOptions[config]->UsingUnicode()) ||
  553. this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  554. this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  555. {
  556. this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
  557. }
  558. else if (this->Target->GetType() <= cmTarget::MODULE_LIBRARY &&
  559. this->ClOptions[config]->UsingSBCS())
  560. {
  561. this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
  562. }
  563. else
  564. {
  565. this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
  566. }
  567. if(const char* toolset = gg->GetPlatformToolset())
  568. {
  569. std::string pts = "<PlatformToolset>";
  570. pts += toolset;
  571. pts += "</PlatformToolset>\n";
  572. this->WriteString(pts.c_str(), 2);
  573. }
  574. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  575. this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  576. {
  577. this->WriteString("<WindowsAppContainer>true"
  578. "</WindowsAppContainer>\n", 2);
  579. }
  580. }
  581. void cmVisualStudio10TargetGenerator::WriteCustomCommands()
  582. {
  583. this->SourcesVisited.clear();
  584. std::vector<cmSourceFile const*> customCommands;
  585. this->GeneratorTarget->GetCustomCommands(customCommands, "");
  586. for(std::vector<cmSourceFile const*>::const_iterator
  587. si = customCommands.begin();
  588. si != customCommands.end(); ++si)
  589. {
  590. this->WriteCustomCommand(*si);
  591. }
  592. }
  593. //----------------------------------------------------------------------------
  594. void cmVisualStudio10TargetGenerator
  595. ::WriteCustomCommand(cmSourceFile const* sf)
  596. {
  597. if(this->SourcesVisited.insert(sf).second)
  598. {
  599. if(std::vector<cmSourceFile*> const* depends =
  600. this->GeneratorTarget->GetSourceDepends(sf))
  601. {
  602. for(std::vector<cmSourceFile*>::const_iterator di = depends->begin();
  603. di != depends->end(); ++di)
  604. {
  605. this->WriteCustomCommand(*di);
  606. }
  607. }
  608. if(cmCustomCommand const* command = sf->GetCustomCommand())
  609. {
  610. this->WriteString("<ItemGroup>\n", 1);
  611. this->WriteCustomRule(sf, *command);
  612. this->WriteString("</ItemGroup>\n", 1);
  613. }
  614. }
  615. }
  616. void
  617. cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source,
  618. cmCustomCommand const &
  619. command)
  620. {
  621. std::string sourcePath = source->GetFullPath();
  622. // VS 10 will always rebuild a custom command attached to a .rule
  623. // file that doesn't exist so create the file explicitly.
  624. if (source->GetPropertyAsBool("__CMAKE_RULE"))
  625. {
  626. if(!cmSystemTools::FileExists(sourcePath.c_str()))
  627. {
  628. // Make sure the path exists for the file
  629. std::string path = cmSystemTools::GetFilenamePath(sourcePath);
  630. cmSystemTools::MakeDirectory(path.c_str());
  631. cmsys::ofstream fout(sourcePath.c_str());
  632. if(fout)
  633. {
  634. fout << "# generated from CMake\n";
  635. fout.flush();
  636. fout.close();
  637. }
  638. else
  639. {
  640. std::string error = "Could not create file: [";
  641. error += sourcePath;
  642. error += "] ";
  643. cmSystemTools::Error
  644. (error.c_str(), cmSystemTools::GetLastSystemError().c_str());
  645. }
  646. }
  647. }
  648. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  649. std::vector<std::string> *configs =
  650. static_cast<cmGlobalVisualStudio7Generator *>
  651. (this->GlobalGenerator)->GetConfigurations();
  652. this->WriteSource("CustomBuild", source, ">\n");
  653. for(std::vector<std::string>::iterator i = configs->begin();
  654. i != configs->end(); ++i)
  655. {
  656. cmCustomCommandGenerator ccg(command, *i, this->Makefile);
  657. std::string comment = lg->ConstructComment(ccg);
  658. comment = cmVS10EscapeComment(comment);
  659. std::string script =
  660. cmVS10EscapeXML(lg->ConstructScript(ccg));
  661. this->WritePlatformConfigTag("Message",i->c_str(), 3);
  662. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  663. this->WritePlatformConfigTag("Command", i->c_str(), 3);
  664. (*this->BuildFileStream ) << script << "</Command>\n";
  665. this->WritePlatformConfigTag("AdditionalInputs", i->c_str(), 3);
  666. (*this->BuildFileStream ) << cmVS10EscapeXML(source->GetFullPath());
  667. for(std::vector<std::string>::const_iterator d =
  668. ccg.GetDepends().begin();
  669. d != ccg.GetDepends().end();
  670. ++d)
  671. {
  672. std::string dep;
  673. if(this->LocalGenerator->GetRealDependency(d->c_str(), i->c_str(), dep))
  674. {
  675. this->ConvertToWindowsSlash(dep);
  676. (*this->BuildFileStream ) << ";" << cmVS10EscapeXML(dep);
  677. }
  678. }
  679. (*this->BuildFileStream ) << ";%(AdditionalInputs)</AdditionalInputs>\n";
  680. this->WritePlatformConfigTag("Outputs", i->c_str(), 3);
  681. const char* sep = "";
  682. for(std::vector<std::string>::const_iterator o =
  683. ccg.GetOutputs().begin();
  684. o != ccg.GetOutputs().end();
  685. ++o)
  686. {
  687. std::string out = *o;
  688. this->ConvertToWindowsSlash(out);
  689. (*this->BuildFileStream ) << sep << cmVS10EscapeXML(out);
  690. sep = ";";
  691. }
  692. (*this->BuildFileStream ) << "</Outputs>\n";
  693. if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
  694. {
  695. // VS >= 11 let us turn off linking of custom command outputs.
  696. this->WritePlatformConfigTag("LinkObjects", i->c_str(), 3);
  697. (*this->BuildFileStream ) << "false</LinkObjects>\n";
  698. }
  699. }
  700. this->WriteString("</CustomBuild>\n", 2);
  701. }
  702. std::string
  703. cmVisualStudio10TargetGenerator::ConvertPath(std::string const& path,
  704. bool forceRelative)
  705. {
  706. return forceRelative
  707. ? cmSystemTools::RelativePath(
  708. this->Makefile->GetCurrentOutputDirectory(), path.c_str())
  709. : this->LocalGenerator->Convert(path.c_str(),
  710. cmLocalGenerator::START_OUTPUT,
  711. cmLocalGenerator::UNCHANGED,
  712. /* optional = */ true);
  713. }
  714. void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s)
  715. {
  716. // first convert all of the slashes
  717. std::string::size_type pos = 0;
  718. while((pos = s.find('/', pos)) != std::string::npos)
  719. {
  720. s[pos] = '\\';
  721. pos++;
  722. }
  723. }
  724. void cmVisualStudio10TargetGenerator::WriteGroups()
  725. {
  726. // collect up group information
  727. std::vector<cmSourceGroup> sourceGroups =
  728. this->Makefile->GetSourceGroups();
  729. std::vector<cmSourceFile*> classes;
  730. if (!this->Target->GetConfigCommonSourceFiles(classes))
  731. {
  732. return;
  733. }
  734. std::set<cmSourceGroup*> groupsUsed;
  735. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  736. s != classes.end(); s++)
  737. {
  738. cmSourceFile* sf = *s;
  739. std::string const& source = sf->GetFullPath();
  740. cmSourceGroup* sourceGroup =
  741. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  742. groupsUsed.insert(sourceGroup);
  743. }
  744. this->AddMissingSourceGroups(groupsUsed, sourceGroups);
  745. // Write out group file
  746. std::string path = this->Makefile->GetStartOutputDirectory();
  747. path += "/";
  748. path += this->Name;
  749. path += ".vcxproj.filters";
  750. cmGeneratedFileStream fout(path.c_str());
  751. fout.SetCopyIfDifferent(true);
  752. char magic[] = {0xEF,0xBB, 0xBF};
  753. fout.write(magic, 3);
  754. cmGeneratedFileStream* save = this->BuildFileStream;
  755. this->BuildFileStream = & fout;
  756. //get the tools version to use
  757. const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
  758. std::string project_defaults=
  759. "<?xml version=\"1.0\" encoding=\"" +
  760. this->GlobalGenerator->Encoding() + "\"?>\n";
  761. project_defaults.append("<Project ToolsVersion=\"");
  762. project_defaults.append(toolsVer +"\" ");
  763. project_defaults.append(
  764. "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
  765. this->WriteString(project_defaults.c_str(),0);
  766. for(ToolSourceMap::const_iterator ti = this->Tools.begin();
  767. ti != this->Tools.end(); ++ti)
  768. {
  769. this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups);
  770. }
  771. std::vector<cmSourceFile const*> resxObjs;
  772. this->GeneratorTarget->GetResxSources(resxObjs, "");
  773. if(!resxObjs.empty())
  774. {
  775. this->WriteString("<ItemGroup>\n", 1);
  776. for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
  777. oi != resxObjs.end(); ++oi)
  778. {
  779. std::string obj = (*oi)->GetFullPath();
  780. this->WriteString("<EmbeddedResource Include=\"", 2);
  781. this->ConvertToWindowsSlash(obj);
  782. (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\">\n";
  783. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  784. this->WriteString("</EmbeddedResource>\n", 2);
  785. }
  786. this->WriteString("</ItemGroup>\n", 1);
  787. }
  788. // Add object library contents as external objects.
  789. std::vector<std::string> objs;
  790. this->GeneratorTarget->UseObjectLibraries(objs, "");
  791. if(!objs.empty())
  792. {
  793. this->WriteString("<ItemGroup>\n", 1);
  794. for(std::vector<std::string>::const_iterator
  795. oi = objs.begin(); oi != objs.end(); ++oi)
  796. {
  797. std::string obj = *oi;
  798. this->WriteString("<Object Include=\"", 2);
  799. this->ConvertToWindowsSlash(obj);
  800. (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\">\n";
  801. this->WriteString("<Filter>Object Libraries</Filter>\n", 3);
  802. this->WriteString("</Object>\n", 2);
  803. }
  804. this->WriteString("</ItemGroup>\n", 1);
  805. }
  806. this->WriteString("<ItemGroup>\n", 1);
  807. for(std::set<cmSourceGroup*>::iterator g = groupsUsed.begin();
  808. g != groupsUsed.end(); ++g)
  809. {
  810. cmSourceGroup* sg = *g;
  811. const char* name = sg->GetFullName();
  812. if(strlen(name) != 0)
  813. {
  814. this->WriteString("<Filter Include=\"", 2);
  815. (*this->BuildFileStream) << name << "\">\n";
  816. std::string guidName = "SG_Filter_";
  817. guidName += name;
  818. this->GlobalGenerator->CreateGUID(guidName.c_str());
  819. this->WriteString("<UniqueIdentifier>", 3);
  820. std::string guid
  821. = this->GlobalGenerator->GetGUID(guidName.c_str());
  822. (*this->BuildFileStream)
  823. << "{"
  824. << guid << "}"
  825. << "</UniqueIdentifier>\n";
  826. this->WriteString("</Filter>\n", 2);
  827. }
  828. }
  829. if(!objs.empty())
  830. {
  831. this->WriteString("<Filter Include=\"Object Libraries\">\n", 2);
  832. std::string guidName = "SG_Filter_Object Libraries";
  833. this->GlobalGenerator->CreateGUID(guidName.c_str());
  834. this->WriteString("<UniqueIdentifier>", 3);
  835. std::string guid =
  836. this->GlobalGenerator->GetGUID(guidName.c_str());
  837. (*this->BuildFileStream) << "{" << guid << "}"
  838. << "</UniqueIdentifier>\n";
  839. this->WriteString("</Filter>\n", 2);
  840. }
  841. if(!resxObjs.empty())
  842. {
  843. this->WriteString("<Filter Include=\"Resource Files\">\n", 2);
  844. std::string guidName = "SG_Filter_Resource Files";
  845. this->GlobalGenerator->CreateGUID(guidName.c_str());
  846. this->WriteString("<UniqueIdentifier>", 3);
  847. std::string guid =
  848. this->GlobalGenerator->GetGUID(guidName.c_str());
  849. (*this->BuildFileStream) << "{" << guid << "}"
  850. << "</UniqueIdentifier>\n";
  851. this->WriteString("<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;", 3);
  852. (*this->BuildFileStream) << "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;";
  853. (*this->BuildFileStream) << "mfcribbon-ms</Extensions>\n";
  854. this->WriteString("</Filter>\n", 2);
  855. }
  856. this->WriteString("</ItemGroup>\n", 1);
  857. this->WriteString("</Project>\n", 0);
  858. // restore stream pointer
  859. this->BuildFileStream = save;
  860. if (fout.Close())
  861. {
  862. this->GlobalGenerator->FileReplacedDuringGenerate(path);
  863. }
  864. }
  865. // Add to groupsUsed empty source groups that have non-empty children.
  866. void
  867. cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
  868. std::set<cmSourceGroup*>& groupsUsed,
  869. const std::vector<cmSourceGroup>& allGroups
  870. )
  871. {
  872. for(std::vector<cmSourceGroup>::const_iterator current = allGroups.begin();
  873. current != allGroups.end(); ++current)
  874. {
  875. std::vector<cmSourceGroup> const& children = current->GetGroupChildren();
  876. if(children.empty())
  877. {
  878. continue; // the group is really empty
  879. }
  880. this->AddMissingSourceGroups(groupsUsed, children);
  881. cmSourceGroup* current_ptr = const_cast<cmSourceGroup*>(&(*current));
  882. if(groupsUsed.find(current_ptr) != groupsUsed.end())
  883. {
  884. continue; // group has already been added to set
  885. }
  886. // check if it least one of the group's descendants is not empty
  887. // (at least one child must already have been added)
  888. std::vector<cmSourceGroup>::const_iterator child_it = children.begin();
  889. while(child_it != children.end())
  890. {
  891. cmSourceGroup* child_ptr = const_cast<cmSourceGroup*>(&(*child_it));
  892. if(groupsUsed.find(child_ptr) != groupsUsed.end())
  893. {
  894. break; // found a child that was already added => add current group too
  895. }
  896. child_it++;
  897. }
  898. if(child_it == children.end())
  899. {
  900. continue; // no descendants have source files => ignore this group
  901. }
  902. groupsUsed.insert(current_ptr);
  903. }
  904. }
  905. void
  906. cmVisualStudio10TargetGenerator::
  907. WriteGroupSources(const char* name,
  908. ToolSources const& sources,
  909. std::vector<cmSourceGroup>& sourceGroups)
  910. {
  911. this->WriteString("<ItemGroup>\n", 1);
  912. for(ToolSources::const_iterator s = sources.begin();
  913. s != sources.end(); ++s)
  914. {
  915. cmSourceFile const* sf = s->SourceFile;
  916. std::string const& source = sf->GetFullPath();
  917. cmSourceGroup* sourceGroup =
  918. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  919. const char* filter = sourceGroup->GetFullName();
  920. this->WriteString("<", 2);
  921. std::string path = this->ConvertPath(source, s->RelativePath);
  922. this->ConvertToWindowsSlash(path);
  923. (*this->BuildFileStream) << name << " Include=\""
  924. << cmVS10EscapeXML(path);
  925. if(strlen(filter))
  926. {
  927. (*this->BuildFileStream) << "\">\n";
  928. this->WriteString("<Filter>", 3);
  929. (*this->BuildFileStream) << filter << "</Filter>\n";
  930. this->WriteString("</", 2);
  931. (*this->BuildFileStream) << name << ">\n";
  932. }
  933. else
  934. {
  935. (*this->BuildFileStream) << "\" />\n";
  936. }
  937. }
  938. this->WriteString("</ItemGroup>\n", 1);
  939. }
  940. void cmVisualStudio10TargetGenerator::WriteHeaderSource(cmSourceFile const* sf)
  941. {
  942. if(this->IsResxHeader(sf->GetFullPath()))
  943. {
  944. this->WriteSource("ClInclude", sf, ">\n");
  945. this->WriteString("<FileType>CppForm</FileType>\n", 3);
  946. this->WriteString("</ClInclude>\n", 2);
  947. }
  948. else
  949. {
  950. this->WriteSource("ClInclude", sf);
  951. }
  952. }
  953. void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
  954. {
  955. bool toolHasSettings = false;
  956. std::string tool = "None";
  957. std::string shaderType;
  958. std::string const& ext = sf->GetExtension();
  959. if(ext == "hlsl")
  960. {
  961. tool = "FXCompile";
  962. // Figure out the type of shader compiler to use.
  963. if(const char* st = sf->GetProperty("VS_SHADER_TYPE"))
  964. {
  965. shaderType = st;
  966. toolHasSettings = true;
  967. }
  968. }
  969. else if(ext == "jpg" ||
  970. ext == "png")
  971. {
  972. tool = "Image";
  973. }
  974. else if(ext == "xml")
  975. {
  976. tool = "XML";
  977. }
  978. std::string deployContent;
  979. if(this->GlobalGenerator->TargetsWindowsPhone() ||
  980. this->GlobalGenerator->TargetsWindowsStore())
  981. {
  982. const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
  983. if(content && *content)
  984. {
  985. toolHasSettings = true;
  986. deployContent = content;
  987. }
  988. }
  989. if(toolHasSettings)
  990. {
  991. this->WriteSource(tool, sf, ">\n");
  992. if(!deployContent.empty())
  993. {
  994. std::vector<std::string> const* configs =
  995. this->GlobalGenerator->GetConfigurations();
  996. cmGeneratorExpression ge;
  997. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  998. ge.Parse(deployContent);
  999. for(size_t i = 0; i != configs->size(); ++i)
  1000. {
  1001. if(0 == strcmp(cge->Evaluate(this->Makefile, (*configs)[i]), "1"))
  1002. {
  1003. this->WriteString("<DeploymentContent Condition=\""
  1004. "'$(Configuration)|$(Platform)'=='", 3);
  1005. (*this->BuildFileStream) << (*configs)[i] << "|"
  1006. << this->Platform << "'\">true";
  1007. this->WriteString("</DeploymentContent>\n", 0);
  1008. }
  1009. else
  1010. {
  1011. this->WriteString("<ExcludedFromBuild Condition=\""
  1012. "'$(Configuration)|$(Platform)'=='", 3);
  1013. (*this->BuildFileStream) << (*configs)[i] << "|"
  1014. << this->Platform << "'\">true";
  1015. this->WriteString("</ExcludedFromBuild>\n", 0);
  1016. }
  1017. }
  1018. }
  1019. if(!shaderType.empty())
  1020. {
  1021. this->WriteString("<ShaderType>", 3);
  1022. (*this->BuildFileStream) << cmVS10EscapeXML(shaderType)
  1023. << "</ShaderType>\n";
  1024. }
  1025. this->WriteString("</", 2);
  1026. (*this->BuildFileStream) << tool << ">\n";
  1027. }
  1028. else
  1029. {
  1030. this->WriteSource(tool, sf);
  1031. }
  1032. }
  1033. void cmVisualStudio10TargetGenerator::WriteSource(
  1034. std::string const& tool, cmSourceFile const* sf, const char* end)
  1035. {
  1036. // Visual Studio tools append relative paths to the current dir, as in:
  1037. //
  1038. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  1039. //
  1040. // and fail if this exceeds the maximum allowed path length. Our path
  1041. // conversion uses full paths when possible to allow deeper trees.
  1042. bool forceRelative = false;
  1043. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), false);
  1044. if(this->LocalGenerator->GetVersion() == cmLocalVisualStudioGenerator::VS10
  1045. && cmSystemTools::FileIsFullPath(sourceFile.c_str()))
  1046. {
  1047. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  1048. // refuses to show the property page in the IDE for a source file with a
  1049. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  1050. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  1051. // full path except for custom commands. Custom commands do not work
  1052. // without a relative path, but they do not seem to be involved in tools
  1053. // with the above behavior. For other sources we now use a relative path
  1054. // when the combined path will not be too long so property pages appear.
  1055. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  1056. size_t const maxLen = 250;
  1057. if(sf->GetCustomCommand() ||
  1058. ((strlen(this->Makefile->GetCurrentOutputDirectory()) + 1 +
  1059. sourceRel.length()) <= maxLen))
  1060. {
  1061. forceRelative = true;
  1062. sourceFile = sourceRel;
  1063. }
  1064. else
  1065. {
  1066. this->GlobalGenerator->PathTooLong(this->Target, sf, sourceRel);
  1067. }
  1068. }
  1069. this->ConvertToWindowsSlash(sourceFile);
  1070. this->WriteString("<", 2);
  1071. (*this->BuildFileStream ) << tool << " Include=\""
  1072. << cmVS10EscapeXML(sourceFile) << "\""
  1073. << (end? end : " />\n");
  1074. ToolSource toolSource = {sf, forceRelative};
  1075. this->Tools[tool].push_back(toolSource);
  1076. }
  1077. void cmVisualStudio10TargetGenerator::WriteSources(
  1078. std::string const& tool, std::vector<cmSourceFile const*> const& sources)
  1079. {
  1080. for(std::vector<cmSourceFile const*>::const_iterator
  1081. si = sources.begin(); si != sources.end(); ++si)
  1082. {
  1083. this->WriteSource(tool, *si);
  1084. }
  1085. }
  1086. void cmVisualStudio10TargetGenerator::WriteAllSources()
  1087. {
  1088. if(this->Target->GetType() > cmTarget::UTILITY)
  1089. {
  1090. return;
  1091. }
  1092. this->WriteString("<ItemGroup>\n", 1);
  1093. std::vector<cmSourceFile const*> headerSources;
  1094. this->GeneratorTarget->GetHeaderSources(headerSources, "");
  1095. for(std::vector<cmSourceFile const*>::const_iterator
  1096. si = headerSources.begin(); si != headerSources.end(); ++si)
  1097. {
  1098. this->WriteHeaderSource(*si);
  1099. }
  1100. std::vector<cmSourceFile const*> idlSources;
  1101. this->GeneratorTarget->GetIDLSources(idlSources, "");
  1102. this->WriteSources("Midl", idlSources);
  1103. std::vector<cmSourceFile const*> objectSources;
  1104. this->GeneratorTarget->GetObjectSources(objectSources, "");
  1105. for(std::vector<cmSourceFile const*>::const_iterator
  1106. si = objectSources.begin();
  1107. si != objectSources.end(); ++si)
  1108. {
  1109. const std::string& lang = (*si)->GetLanguage();
  1110. std::string tool;
  1111. if (lang == "C"|| lang == "CXX")
  1112. {
  1113. tool = "ClCompile";
  1114. }
  1115. else if (lang == "ASM_NASM" &&
  1116. this->GlobalGenerator->IsMasmEnabled())
  1117. {
  1118. tool = "MASM";
  1119. }
  1120. else if (lang == "RC")
  1121. {
  1122. tool = "ResourceCompile";
  1123. }
  1124. if (!tool.empty())
  1125. {
  1126. this->WriteSource(tool, *si, " ");
  1127. if (this->OutputSourceSpecificFlags(*si))
  1128. {
  1129. this->WriteString("</", 2);
  1130. (*this->BuildFileStream ) << tool << ">\n";
  1131. }
  1132. else
  1133. {
  1134. (*this->BuildFileStream ) << " />\n";
  1135. }
  1136. }
  1137. else
  1138. {
  1139. this->WriteSource("None", *si);
  1140. }
  1141. }
  1142. std::vector<cmSourceFile const*> manifestSources;
  1143. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  1144. this->WriteSources("AppxManifest", manifestSources);
  1145. std::vector<cmSourceFile const*> externalObjects;
  1146. this->GeneratorTarget->GetExternalObjects(externalObjects, "");
  1147. for(std::vector<cmSourceFile const*>::iterator
  1148. si = externalObjects.begin();
  1149. si != externalObjects.end(); )
  1150. {
  1151. if (!(*si)->GetObjectLibrary().empty())
  1152. {
  1153. si = externalObjects.erase(si);
  1154. }
  1155. else
  1156. {
  1157. ++si;
  1158. }
  1159. }
  1160. if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
  1161. {
  1162. // For VS >= 11 we use LinkObjects to avoid linking custom command
  1163. // outputs. Use Object for all external objects, generated or not.
  1164. this->WriteSources("Object", externalObjects);
  1165. }
  1166. else
  1167. {
  1168. // If an object file is generated in this target, then vs10 will use
  1169. // it in the build, and we have to list it as None instead of Object.
  1170. for(std::vector<cmSourceFile const*>::const_iterator
  1171. si = externalObjects.begin();
  1172. si != externalObjects.end(); ++si)
  1173. {
  1174. std::vector<cmSourceFile*> const* d =
  1175. this->GeneratorTarget->GetSourceDepends(*si);
  1176. this->WriteSource((d && !d->empty())? "None":"Object", *si);
  1177. }
  1178. }
  1179. std::vector<cmSourceFile const*> extraSources;
  1180. this->GeneratorTarget->GetExtraSources(extraSources, "");
  1181. for(std::vector<cmSourceFile const*>::const_iterator
  1182. si = extraSources.begin(); si != extraSources.end(); ++si)
  1183. {
  1184. this->WriteExtraSource(*si);
  1185. }
  1186. // Add object library contents as external objects.
  1187. std::vector<std::string> objs;
  1188. this->GeneratorTarget->UseObjectLibraries(objs, "");
  1189. for(std::vector<std::string>::const_iterator
  1190. oi = objs.begin(); oi != objs.end(); ++oi)
  1191. {
  1192. std::string obj = *oi;
  1193. this->WriteString("<Object Include=\"", 2);
  1194. this->ConvertToWindowsSlash(obj);
  1195. (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\" />\n";
  1196. }
  1197. this->WriteString("</ItemGroup>\n", 1);
  1198. }
  1199. bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  1200. cmSourceFile const* source)
  1201. {
  1202. cmSourceFile const& sf = *source;
  1203. std::string objectName;
  1204. if(this->GeneratorTarget->HasExplicitObjectName(&sf))
  1205. {
  1206. objectName = this->GeneratorTarget->GetObjectName(&sf);
  1207. }
  1208. std::string flags;
  1209. std::string defines;
  1210. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1211. {
  1212. flags += cflags;
  1213. }
  1214. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1215. {
  1216. defines += cdefs;
  1217. }
  1218. std::string lang =
  1219. this->GlobalGenerator->GetLanguageFromExtension
  1220. (sf.GetExtension().c_str());
  1221. std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  1222. const std::string& linkLanguage = this->Target->GetLinkerLanguage();
  1223. bool needForceLang = false;
  1224. // source file does not match its extension language
  1225. if(lang != sourceLang)
  1226. {
  1227. needForceLang = true;
  1228. lang = sourceLang;
  1229. }
  1230. // if the source file does not match the linker language
  1231. // then force c or c++
  1232. const char* compileAs = 0;
  1233. if(needForceLang || (linkLanguage != lang))
  1234. {
  1235. if(lang == "CXX")
  1236. {
  1237. // force a C++ file type
  1238. compileAs = "CompileAsCpp";
  1239. }
  1240. else if(lang == "C")
  1241. {
  1242. // force to c
  1243. compileAs = "CompileAsC";
  1244. }
  1245. }
  1246. bool hasFlags = false;
  1247. // for the first time we need a new line if there is something
  1248. // produced here.
  1249. const char* firstString = ">\n";
  1250. if(objectName.size())
  1251. {
  1252. (*this->BuildFileStream ) << firstString;
  1253. firstString = "";
  1254. hasFlags = true;
  1255. this->WriteString("<ObjectFileName>", 3);
  1256. (*this->BuildFileStream )
  1257. << "$(IntDir)/" << objectName << "</ObjectFileName>\n";
  1258. }
  1259. std::vector<std::string> *configs =
  1260. static_cast<cmGlobalVisualStudio7Generator *>
  1261. (this->GlobalGenerator)->GetConfigurations();
  1262. for( std::vector<std::string>::iterator config = configs->begin();
  1263. config != configs->end(); ++config)
  1264. {
  1265. std::string configUpper = cmSystemTools::UpperCase(*config);
  1266. std::string configDefines = defines;
  1267. std::string defPropName = "COMPILE_DEFINITIONS_";
  1268. defPropName += configUpper;
  1269. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1270. {
  1271. if(configDefines.size())
  1272. {
  1273. configDefines += ";";
  1274. }
  1275. configDefines += ccdefs;
  1276. }
  1277. // if we have flags or defines for this config then
  1278. // use them
  1279. if(!flags.empty() || !configDefines.empty() || compileAs)
  1280. {
  1281. (*this->BuildFileStream ) << firstString;
  1282. firstString = ""; // only do firstString once
  1283. hasFlags = true;
  1284. cmVisualStudioGeneratorOptions
  1285. clOptions(this->LocalGenerator,
  1286. cmVisualStudioGeneratorOptions::Compiler,
  1287. this->GetClFlagTable(), 0, this);
  1288. if(compileAs)
  1289. {
  1290. clOptions.AddFlag("CompileAs", compileAs);
  1291. }
  1292. clOptions.Parse(flags.c_str());
  1293. clOptions.AddDefines(configDefines.c_str());
  1294. clOptions.SetConfiguration((*config).c_str());
  1295. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1296. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1297. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream,
  1298. " ", "\n", lang);
  1299. }
  1300. }
  1301. return hasFlags;
  1302. }
  1303. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
  1304. {
  1305. cmTarget::TargetType ttype = this->Target->GetType();
  1306. if(ttype > cmTarget::GLOBAL_TARGET)
  1307. {
  1308. return;
  1309. }
  1310. this->WriteString("<PropertyGroup>\n", 2);
  1311. this->WriteString("<_ProjectFileVersion>10.0.20506.1"
  1312. "</_ProjectFileVersion>\n", 3);
  1313. std::vector<std::string> *configs =
  1314. static_cast<cmGlobalVisualStudio7Generator *>
  1315. (this->GlobalGenerator)->GetConfigurations();
  1316. for(std::vector<std::string>::iterator config = configs->begin();
  1317. config != configs->end(); ++config)
  1318. {
  1319. if(ttype >= cmTarget::UTILITY)
  1320. {
  1321. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1322. *this->BuildFileStream
  1323. << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
  1324. << "</IntDir>\n";
  1325. }
  1326. else
  1327. {
  1328. std::string intermediateDir = this->LocalGenerator->
  1329. GetTargetDirectory(*this->Target);
  1330. intermediateDir += "/";
  1331. intermediateDir += *config;
  1332. intermediateDir += "/";
  1333. std::string outDir;
  1334. std::string targetNameFull;
  1335. if(ttype == cmTarget::OBJECT_LIBRARY)
  1336. {
  1337. outDir = intermediateDir;
  1338. targetNameFull = this->Target->GetName();
  1339. targetNameFull += ".lib";
  1340. }
  1341. else
  1342. {
  1343. outDir = this->Target->GetDirectory(config->c_str()) + "/";
  1344. targetNameFull = this->Target->GetFullName(config->c_str());
  1345. }
  1346. this->ConvertToWindowsSlash(intermediateDir);
  1347. this->ConvertToWindowsSlash(outDir);
  1348. this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
  1349. *this->BuildFileStream << cmVS10EscapeXML(outDir)
  1350. << "</OutDir>\n";
  1351. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1352. *this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
  1353. << "</IntDir>\n";
  1354. std::string name =
  1355. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  1356. this->WritePlatformConfigTag("TargetName", config->c_str(), 3);
  1357. *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n";
  1358. std::string ext =
  1359. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  1360. if(ext.empty())
  1361. {
  1362. // An empty TargetExt causes a default extension to be used.
  1363. // A single "." appears to be treated as an empty extension.
  1364. ext = ".";
  1365. }
  1366. this->WritePlatformConfigTag("TargetExt", config->c_str(), 3);
  1367. *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n";
  1368. this->OutputLinkIncremental(*config);
  1369. }
  1370. }
  1371. this->WriteString("</PropertyGroup>\n", 2);
  1372. }
  1373. void
  1374. cmVisualStudio10TargetGenerator::
  1375. OutputLinkIncremental(std::string const& configName)
  1376. {
  1377. // static libraries and things greater than modules do not need
  1378. // to set this option
  1379. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
  1380. || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
  1381. {
  1382. return;
  1383. }
  1384. Options& linkOptions = *(this->LinkOptions[configName]);
  1385. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  1386. this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 3);
  1387. *this->BuildFileStream << (incremental?incremental:"true")
  1388. << "</LinkIncremental>\n";
  1389. linkOptions.RemoveFlag("LinkIncremental");
  1390. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  1391. this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 3);
  1392. *this->BuildFileStream << (manifest?manifest:"true")
  1393. << "</GenerateManifest>\n";
  1394. linkOptions.RemoveFlag("GenerateManifest");
  1395. // Some link options belong here. Use them now and remove them so that
  1396. // WriteLinkOptions does not use them.
  1397. const char* flags[] = {
  1398. "LinkDelaySign",
  1399. "LinkKeyFile",
  1400. 0};
  1401. for(const char** f = flags; *f; ++f)
  1402. {
  1403. const char* flag = *f;
  1404. if(const char* value = linkOptions.GetFlag(flag))
  1405. {
  1406. this->WritePlatformConfigTag(flag, configName.c_str(), 3);
  1407. *this->BuildFileStream << value << "</" << flag << ">\n";
  1408. linkOptions.RemoveFlag(flag);
  1409. }
  1410. }
  1411. }
  1412. //----------------------------------------------------------------------------
  1413. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  1414. {
  1415. std::vector<std::string> const* configs =
  1416. this->GlobalGenerator->GetConfigurations();
  1417. for(std::vector<std::string>::const_iterator i = configs->begin();
  1418. i != configs->end(); ++i)
  1419. {
  1420. if(!this->ComputeClOptions(*i))
  1421. {
  1422. return false;
  1423. }
  1424. }
  1425. return true;
  1426. }
  1427. //----------------------------------------------------------------------------
  1428. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  1429. std::string const& configName)
  1430. {
  1431. // much of this was copied from here:
  1432. // copied from cmLocalVisualStudio7Generator.cxx 805
  1433. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  1434. cmsys::auto_ptr<Options> pOptions(
  1435. new Options(this->LocalGenerator, Options::Compiler,
  1436. this->GetClFlagTable()));
  1437. Options& clOptions = *pOptions;
  1438. std::string flags;
  1439. const std::string& linkLanguage =
  1440. this->Target->GetLinkerLanguage(configName.c_str());
  1441. if(linkLanguage.empty())
  1442. {
  1443. cmSystemTools::Error
  1444. ("CMake can not determine linker language for target: ",
  1445. this->Name.c_str());
  1446. return false;
  1447. }
  1448. if(linkLanguage == "C" || linkLanguage == "CXX"
  1449. || linkLanguage == "Fortran")
  1450. {
  1451. std::string baseFlagVar = "CMAKE_";
  1452. baseFlagVar += linkLanguage;
  1453. baseFlagVar += "_FLAGS";
  1454. flags = this->
  1455. Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
  1456. std::string flagVar = baseFlagVar + std::string("_") +
  1457. cmSystemTools::UpperCase(configName);
  1458. flags += " ";
  1459. flags += this->
  1460. Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
  1461. }
  1462. // set the correct language
  1463. if(linkLanguage == "C")
  1464. {
  1465. clOptions.AddFlag("CompileAs", "CompileAsC");
  1466. }
  1467. if(linkLanguage == "CXX")
  1468. {
  1469. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  1470. }
  1471. this->LocalGenerator->AddCompileOptions(flags, this->Target,
  1472. linkLanguage, configName.c_str());
  1473. // Get preprocessor definitions for this directory.
  1474. std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags();
  1475. if(this->MSTools)
  1476. {
  1477. clOptions.FixExceptionHandlingDefault();
  1478. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  1479. std::string asmLocation = configName + "/";
  1480. clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  1481. }
  1482. clOptions.Parse(flags.c_str());
  1483. clOptions.Parse(defineFlags.c_str());
  1484. std::vector<std::string> targetDefines;
  1485. this->Target->GetCompileDefinitions(targetDefines, configName.c_str());
  1486. clOptions.AddDefines(targetDefines);
  1487. if(this->MSTools)
  1488. {
  1489. clOptions.SetVerboseMakefile(
  1490. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  1491. }
  1492. // Add a definition for the configuration name.
  1493. std::string configDefine = "CMAKE_INTDIR=\"";
  1494. configDefine += configName;
  1495. configDefine += "\"";
  1496. clOptions.AddDefine(configDefine);
  1497. if(const char* exportMacro = this->Target->GetExportMacro())
  1498. {
  1499. clOptions.AddDefine(exportMacro);
  1500. }
  1501. if (this->MSTools)
  1502. {
  1503. // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
  1504. if (this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
  1505. {
  1506. clOptions.AddFlag("CompileAsWinRT", "true");
  1507. // For WinRT components, add the _WINRT_DLL define to produce a lib
  1508. if (this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  1509. this->Target->GetType() == cmTarget::MODULE_LIBRARY )
  1510. {
  1511. clOptions.AddDefine("_WINRT_DLL");
  1512. }
  1513. }
  1514. else if (this->GlobalGenerator->TargetsWindowsStore() ||
  1515. this->GlobalGenerator->TargetsWindowsPhone())
  1516. {
  1517. if (!clOptions.IsWinRt())
  1518. {
  1519. clOptions.AddFlag("CompileAsWinRT", "false");
  1520. }
  1521. }
  1522. }
  1523. this->ClOptions[configName] = pOptions.release();
  1524. return true;
  1525. }
  1526. //----------------------------------------------------------------------------
  1527. void cmVisualStudio10TargetGenerator::WriteClOptions(
  1528. std::string const& configName,
  1529. std::vector<std::string> const& includes)
  1530. {
  1531. Options& clOptions = *(this->ClOptions[configName]);
  1532. this->WriteString("<ClCompile>\n", 2);
  1533. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1534. this->OutputIncludes(includes);
  1535. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1536. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1537. "\n", "CXX");
  1538. if(this->MSTools)
  1539. {
  1540. this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
  1541. // If not in debug mode, write the DebugInformationFormat field
  1542. // without value so PDBs don't get generated uselessly.
  1543. if(!clOptions.IsDebug())
  1544. {
  1545. this->WriteString("<DebugInformationFormat>"
  1546. "</DebugInformationFormat>\n", 3);
  1547. }
  1548. // Specify the compiler program database file if configured.
  1549. std::string pdb = this->Target->GetCompilePDBPath(configName.c_str());
  1550. if(!pdb.empty())
  1551. {
  1552. this->ConvertToWindowsSlash(pdb);
  1553. this->WriteString("<ProgramDataBaseFileName>", 3);
  1554. *this->BuildFileStream << cmVS10EscapeXML(pdb)
  1555. << "</ProgramDataBaseFileName>\n";
  1556. }
  1557. }
  1558. this->WriteString("</ClCompile>\n", 2);
  1559. }
  1560. void cmVisualStudio10TargetGenerator::
  1561. OutputIncludes(std::vector<std::string> const & includes)
  1562. {
  1563. this->WriteString("<AdditionalIncludeDirectories>", 3);
  1564. for(std::vector<std::string>::const_iterator i = includes.begin();
  1565. i != includes.end(); ++i)
  1566. {
  1567. std::string incDir = *i;
  1568. this->ConvertToWindowsSlash(incDir);
  1569. *this->BuildFileStream << cmVS10EscapeXML(incDir) << ";";
  1570. }
  1571. this->WriteString("%(AdditionalIncludeDirectories)"
  1572. "</AdditionalIncludeDirectories>\n", 0);
  1573. }
  1574. //----------------------------------------------------------------------------
  1575. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  1576. {
  1577. std::vector<std::string> const* configs =
  1578. this->GlobalGenerator->GetConfigurations();
  1579. for(std::vector<std::string>::const_iterator i = configs->begin();
  1580. i != configs->end(); ++i)
  1581. {
  1582. if(!this->ComputeRcOptions(*i))
  1583. {
  1584. return false;
  1585. }
  1586. }
  1587. return true;
  1588. }
  1589. //----------------------------------------------------------------------------
  1590. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  1591. std::string const& configName)
  1592. {
  1593. cmsys::auto_ptr<Options> pOptions(
  1594. new Options(this->LocalGenerator, Options::ResourceCompiler,
  1595. this->GetRcFlagTable()));
  1596. Options& rcOptions = *pOptions;
  1597. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1598. std::string rcConfigFlagsVar = std::string("CMAKE_RC_FLAGS_") + CONFIG;
  1599. std::string flags =
  1600. std::string(this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS")) +
  1601. std::string(" ") +
  1602. std::string(this->Makefile->GetSafeDefinition(rcConfigFlagsVar));
  1603. rcOptions.Parse(flags.c_str());
  1604. this->RcOptions[configName] = pOptions.release();
  1605. return true;
  1606. }
  1607. void cmVisualStudio10TargetGenerator::
  1608. WriteRCOptions(std::string const& configName,
  1609. std::vector<std::string> const & includes)
  1610. {
  1611. if(!this->MSTools)
  1612. {
  1613. return;
  1614. }
  1615. this->WriteString("<ResourceCompile>\n", 2);
  1616. // Preprocessor definitions and includes are shared with clOptions.
  1617. Options& clOptions = *(this->ClOptions[configName]);
  1618. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1619. "\n", "RC");
  1620. this->OutputIncludes(includes);
  1621. Options& rcOptions = *(this->RcOptions[configName]);
  1622. rcOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1623. rcOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1624. this->WriteString("</ResourceCompile>\n", 2);
  1625. }
  1626. void
  1627. cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
  1628. {
  1629. if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
  1630. {
  1631. return;
  1632. }
  1633. std::string libflags;
  1634. this->LocalGenerator->GetStaticLibraryFlags(libflags,
  1635. cmSystemTools::UpperCase(config), this->Target);
  1636. if(!libflags.empty())
  1637. {
  1638. this->WriteString("<Lib>\n", 2);
  1639. cmVisualStudioGeneratorOptions
  1640. libOptions(this->LocalGenerator,
  1641. cmVisualStudioGeneratorOptions::Linker,
  1642. this->GetLibFlagTable(), 0, this);
  1643. libOptions.Parse(libflags.c_str());
  1644. libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1645. libOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1646. this->WriteString("</Lib>\n", 2);
  1647. }
  1648. }
  1649. //----------------------------------------------------------------------------
  1650. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  1651. {
  1652. if(this->Target->GetType() == cmTarget::EXECUTABLE ||
  1653. this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  1654. this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  1655. {
  1656. std::vector<std::string> const* configs =
  1657. this->GlobalGenerator->GetConfigurations();
  1658. for(std::vector<std::string>::const_iterator i = configs->begin();
  1659. i != configs->end(); ++i)
  1660. {
  1661. if(!this->ComputeLinkOptions(*i))
  1662. {
  1663. return false;
  1664. }
  1665. }
  1666. }
  1667. return true;
  1668. }
  1669. //----------------------------------------------------------------------------
  1670. bool
  1671. cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
  1672. {
  1673. cmsys::auto_ptr<Options> pOptions(
  1674. new Options(this->LocalGenerator, Options::Linker,
  1675. this->GetLinkFlagTable(), 0, this));
  1676. Options& linkOptions = *pOptions;
  1677. const std::string& linkLanguage =
  1678. this->Target->GetLinkerLanguage(config.c_str());
  1679. if(linkLanguage.empty())
  1680. {
  1681. cmSystemTools::Error
  1682. ("CMake can not determine linker language for target: ",
  1683. this->Name.c_str());
  1684. return false;
  1685. }
  1686. std::string CONFIG = cmSystemTools::UpperCase(config);
  1687. const char* linkType = "SHARED";
  1688. if(this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  1689. {
  1690. linkType = "MODULE";
  1691. }
  1692. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  1693. {
  1694. linkType = "EXE";
  1695. }
  1696. std::string flags;
  1697. std::string linkFlagVarBase = "CMAKE_";
  1698. linkFlagVarBase += linkType;
  1699. linkFlagVarBase += "_LINKER_FLAGS";
  1700. flags += " ";
  1701. flags += this->
  1702. Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
  1703. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  1704. flags += " ";
  1705. flags += this->
  1706. Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
  1707. const char* targetLinkFlags = this->Target->GetProperty("LINK_FLAGS");
  1708. if(targetLinkFlags)
  1709. {
  1710. flags += " ";
  1711. flags += targetLinkFlags;
  1712. }
  1713. std::string flagsProp = "LINK_FLAGS_";
  1714. flagsProp += CONFIG;
  1715. if(const char* flagsConfig = this->Target->GetProperty(flagsProp.c_str()))
  1716. {
  1717. flags += " ";
  1718. flags += flagsConfig;
  1719. }
  1720. std::string standardLibsVar = "CMAKE_";
  1721. standardLibsVar += linkLanguage;
  1722. standardLibsVar += "_STANDARD_LIBRARIES";
  1723. std::string
  1724. libs = this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1725. // Remove trailing spaces from libs
  1726. std::string::size_type pos = libs.size()-1;
  1727. if(libs.size() != 0)
  1728. {
  1729. while(libs[pos] == ' ')
  1730. {
  1731. pos--;
  1732. }
  1733. }
  1734. if(pos != libs.size()-1)
  1735. {
  1736. libs = libs.substr(0, pos+1);
  1737. }
  1738. // Replace spaces in libs with ;
  1739. cmSystemTools::ReplaceString(libs, " ", ";");
  1740. std::vector<std::string> libVec;
  1741. cmSystemTools::ExpandListArgument(libs, libVec);
  1742. cmComputeLinkInformation* pcli =
  1743. this->Target->GetLinkInformation(config.c_str());
  1744. if(!pcli)
  1745. {
  1746. cmSystemTools::Error
  1747. ("CMake can not compute cmComputeLinkInformation for target: ",
  1748. this->Name.c_str());
  1749. return false;
  1750. }
  1751. // add the libraries for the target to libs string
  1752. cmComputeLinkInformation& cli = *pcli;
  1753. this->AddLibraries(cli, libVec);
  1754. linkOptions.AddFlag("AdditionalDependencies", libVec);
  1755. std::vector<std::string> const& ldirs = cli.GetDirectories();
  1756. std::vector<std::string> linkDirs;
  1757. for(std::vector<std::string>::const_iterator d = ldirs.begin();
  1758. d != ldirs.end(); ++d)
  1759. {
  1760. // first just full path
  1761. linkDirs.push_back(*d);
  1762. // next path with configuration type Debug, Release, etc
  1763. linkDirs.push_back(*d + "/$(Configuration)");
  1764. }
  1765. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  1766. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  1767. std::string targetName;
  1768. std::string targetNameSO;
  1769. std::string targetNameFull;
  1770. std::string targetNameImport;
  1771. std::string targetNamePDB;
  1772. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  1773. {
  1774. this->Target->GetExecutableNames(targetName, targetNameFull,
  1775. targetNameImport, targetNamePDB,
  1776. config.c_str());
  1777. }
  1778. else
  1779. {
  1780. this->Target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1781. targetNameImport, targetNamePDB,
  1782. config.c_str());
  1783. }
  1784. if(this->MSTools)
  1785. {
  1786. linkOptions.AddFlag("Version", "");
  1787. if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
  1788. {
  1789. linkOptions.AddFlag("SubSystem", "Windows");
  1790. }
  1791. else
  1792. {
  1793. linkOptions.AddFlag("SubSystem", "Console");
  1794. }
  1795. if(const char* stackVal =
  1796. this->Makefile->GetDefinition("CMAKE_"+linkLanguage+"_STACK_SIZE"))
  1797. {
  1798. linkOptions.AddFlag("StackReserveSize", stackVal);
  1799. }
  1800. if(linkOptions.IsDebug() || flags.find("/debug") != flags.npos)
  1801. {
  1802. linkOptions.AddFlag("GenerateDebugInformation", "true");
  1803. }
  1804. else
  1805. {
  1806. linkOptions.AddFlag("GenerateDebugInformation", "false");
  1807. }
  1808. std::string pdb = this->Target->GetPDBDirectory(config.c_str());
  1809. pdb += "/";
  1810. pdb += targetNamePDB;
  1811. std::string imLib = this->Target->GetDirectory(config.c_str(), true);
  1812. imLib += "/";
  1813. imLib += targetNameImport;
  1814. linkOptions.AddFlag("ImportLibrary", imLib.c_str());
  1815. linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
  1816. }
  1817. linkOptions.Parse(flags.c_str());
  1818. if(this->MSTools)
  1819. {
  1820. std::string def = this->GeneratorTarget->GetModuleDefinitionFile("");
  1821. if(!def.empty())
  1822. {
  1823. linkOptions.AddFlag("ModuleDefinitionFile", def.c_str());
  1824. }
  1825. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  1826. "%(IgnoreSpecificDefaultLibraries)");
  1827. }
  1828. this->LinkOptions[config] = pOptions.release();
  1829. return true;
  1830. }
  1831. //----------------------------------------------------------------------------
  1832. void
  1833. cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
  1834. {
  1835. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
  1836. || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
  1837. {
  1838. return;
  1839. }
  1840. Options& linkOptions = *(this->LinkOptions[config]);
  1841. this->WriteString("<Link>\n", 2);
  1842. linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1843. linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1844. this->WriteString("</Link>\n", 2);
  1845. if(!this->GlobalGenerator->NeedLinkLibraryDependencies(*this->Target))
  1846. {
  1847. this->WriteString("<ProjectReference>\n", 2);
  1848. this->WriteString(
  1849. " <LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 2);
  1850. this->WriteString("</ProjectReference>\n", 2);
  1851. }
  1852. }
  1853. void cmVisualStudio10TargetGenerator::AddLibraries(
  1854. cmComputeLinkInformation& cli,
  1855. std::vector<std::string>& libVec)
  1856. {
  1857. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1858. ItemVector libs = cli.GetItems();
  1859. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1860. {
  1861. if(l->IsPath)
  1862. {
  1863. std::string path = this->LocalGenerator->
  1864. Convert(l->Value.c_str(),
  1865. cmLocalGenerator::START_OUTPUT,
  1866. cmLocalGenerator::UNCHANGED);
  1867. this->ConvertToWindowsSlash(path);
  1868. libVec.push_back(path);
  1869. }
  1870. else if (!l->Target
  1871. || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1872. {
  1873. libVec.push_back(l->Value);
  1874. }
  1875. }
  1876. }
  1877. void cmVisualStudio10TargetGenerator::
  1878. WriteMidlOptions(std::string const& /*config*/,
  1879. std::vector<std::string> const & includes)
  1880. {
  1881. if(!this->MSTools)
  1882. {
  1883. return;
  1884. }
  1885. // This processes *any* of the .idl files specified in the project's file
  1886. // list (and passed as the item metadata %(Filename) expressing the rule
  1887. // input filename) into output files at the per-config *build* dir
  1888. // ($(IntDir)) each.
  1889. //
  1890. // IOW, this MIDL section is intended to provide a fully generic syntax
  1891. // content suitable for most cases (read: if you get errors, then it's quite
  1892. // probable that the error is on your side of the .idl setup).
  1893. //
  1894. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  1895. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  1896. // project's file list, otherwise the compiler-side processing won't pick it
  1897. // up (for non-directory form, it ends up looking in project binary dir
  1898. // only). Perhaps there's something to be done to make this more automatic
  1899. // on the CMake side?
  1900. this->WriteString("<Midl>\n", 2);
  1901. this->OutputIncludes(includes);
  1902. this->WriteString("<OutputDirectory>$(IntDir)</OutputDirectory>\n", 3);
  1903. this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
  1904. this->WriteString(
  1905. "<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
  1906. this->WriteString(
  1907. "<InterfaceIdentifierFileName>"
  1908. "%(Filename)_i.c</InterfaceIdentifierFileName>\n", 3);
  1909. this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n",3);
  1910. this->WriteString("</Midl>\n", 2);
  1911. }
  1912. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
  1913. {
  1914. std::vector<std::string> *configs =
  1915. static_cast<cmGlobalVisualStudio7Generator *>
  1916. (this->GlobalGenerator)->GetConfigurations();
  1917. for(std::vector<std::string>::iterator i = configs->begin();
  1918. i != configs->end(); ++i)
  1919. {
  1920. std::vector<std::string> includes;
  1921. this->LocalGenerator->GetIncludeDirectories(includes,
  1922. this->GeneratorTarget,
  1923. "C", i->c_str());
  1924. this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
  1925. *this->BuildFileStream << "\n";
  1926. // output cl compile flags <ClCompile></ClCompile>
  1927. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
  1928. {
  1929. this->WriteClOptions(*i, includes);
  1930. // output rc compile flags <ResourceCompile></ResourceCompile>
  1931. this->WriteRCOptions(*i, includes);
  1932. }
  1933. // output midl flags <Midl></Midl>
  1934. this->WriteMidlOptions(*i, includes);
  1935. // write events
  1936. this->WriteEvents(*i);
  1937. // output link flags <Link></Link>
  1938. this->WriteLinkOptions(*i);
  1939. // output lib flags <Lib></Lib>
  1940. this->WriteLibOptions(*i);
  1941. this->WriteString("</ItemDefinitionGroup>\n", 1);
  1942. }
  1943. }
  1944. void
  1945. cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
  1946. {
  1947. this->WriteEvent("PreLinkEvent",
  1948. this->Target->GetPreLinkCommands(), configName);
  1949. this->WriteEvent("PreBuildEvent",
  1950. this->Target->GetPreBuildCommands(), configName);
  1951. this->WriteEvent("PostBuildEvent",
  1952. this->Target->GetPostBuildCommands(), configName);
  1953. }
  1954. void cmVisualStudio10TargetGenerator::WriteEvent(
  1955. const char* name,
  1956. std::vector<cmCustomCommand> const& commands,
  1957. std::string const& configName)
  1958. {
  1959. if(commands.size() == 0)
  1960. {
  1961. return;
  1962. }
  1963. this->WriteString("<", 2);
  1964. (*this->BuildFileStream ) << name << ">\n";
  1965. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1966. std::string script;
  1967. const char* pre = "";
  1968. std::string comment;
  1969. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  1970. i != commands.end(); ++i)
  1971. {
  1972. cmCustomCommandGenerator ccg(*i, configName, this->Makefile);
  1973. comment += pre;
  1974. comment += lg->ConstructComment(ccg);
  1975. script += pre;
  1976. pre = "\n";
  1977. script += cmVS10EscapeXML(lg->ConstructScript(ccg));
  1978. }
  1979. comment = cmVS10EscapeComment(comment);
  1980. this->WriteString("<Message>",3);
  1981. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  1982. this->WriteString("<Command>", 3);
  1983. (*this->BuildFileStream ) << script;
  1984. (*this->BuildFileStream ) << "</Command>" << "\n";
  1985. this->WriteString("</", 2);
  1986. (*this->BuildFileStream ) << name << ">\n";
  1987. }
  1988. void cmVisualStudio10TargetGenerator::WriteProjectReferences()
  1989. {
  1990. cmGlobalGenerator::TargetDependSet const& unordered
  1991. = this->GlobalGenerator->GetTargetDirectDepends(*this->Target);
  1992. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  1993. OrderedTargetDependSet;
  1994. OrderedTargetDependSet depends(unordered);
  1995. this->WriteString("<ItemGroup>\n", 1);
  1996. for( OrderedTargetDependSet::const_iterator i = depends.begin();
  1997. i != depends.end(); ++i)
  1998. {
  1999. cmTarget const* dt = *i;
  2000. if(dt->GetType() == cmTarget::INTERFACE_LIBRARY)
  2001. {
  2002. continue;
  2003. }
  2004. // skip fortran targets as they can not be processed by MSBuild
  2005. // the only reference will be in the .sln file
  2006. if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  2007. ->TargetIsFortranOnly(*dt))
  2008. {
  2009. continue;
  2010. }
  2011. this->WriteString("<ProjectReference Include=\"", 2);
  2012. cmMakefile* mf = dt->GetMakefile();
  2013. std::string name = dt->GetName();
  2014. std::string path;
  2015. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  2016. if(p)
  2017. {
  2018. path = p;
  2019. }
  2020. else
  2021. {
  2022. path = mf->GetStartOutputDirectory();
  2023. path += "/";
  2024. path += dt->GetName();
  2025. path += ".vcxproj";
  2026. }
  2027. (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n";
  2028. this->WriteString("<Project>", 3);
  2029. (*this->BuildFileStream)
  2030. << this->GlobalGenerator->GetGUID(name.c_str())
  2031. << "</Project>\n";
  2032. this->WriteString("</ProjectReference>\n", 2);
  2033. }
  2034. this->WriteString("</ItemGroup>\n", 1);
  2035. }
  2036. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
  2037. {
  2038. if((this->GlobalGenerator->TargetsWindowsStore() ||
  2039. this->GlobalGenerator->TargetsWindowsPhone())
  2040. && (cmTarget::EXECUTABLE == this->Target->GetType()))
  2041. {
  2042. std::string pfxFile;
  2043. std::vector<cmSourceFile const*> certificates;
  2044. this->GeneratorTarget->GetCertificates(certificates, "");
  2045. for(std::vector<cmSourceFile const*>::const_iterator si =
  2046. certificates.begin(); si != certificates.end(); ++si)
  2047. {
  2048. pfxFile = this->ConvertPath((*si)->GetFullPath(), false);
  2049. this->ConvertToWindowsSlash(pfxFile);
  2050. break;
  2051. }
  2052. if(!pfxFile.empty())
  2053. {
  2054. this->WriteString("<PropertyGroup>\n", 1);
  2055. this->WriteString("<", 2);
  2056. (*this->BuildFileStream) << "PackageCertificateKeyFile>"
  2057. << pfxFile << "</PackageCertificateKeyFile>\n";
  2058. this->WriteString("</PropertyGroup>\n", 1);
  2059. }
  2060. }
  2061. }
  2062. bool cmVisualStudio10TargetGenerator::
  2063. IsResxHeader(const std::string& headerFile)
  2064. {
  2065. std::set<std::string> expectedResxHeaders;
  2066. this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
  2067. std::set<std::string>::const_iterator it =
  2068. expectedResxHeaders.find(headerFile);
  2069. return it != expectedResxHeaders.end();
  2070. }
  2071. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
  2072. {
  2073. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  2074. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  2075. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2076. if(isWindowsPhone || isWindowsStore)
  2077. {
  2078. this->WriteString("<ApplicationType>", 2);
  2079. (*this->BuildFileStream) << (isWindowsPhone ?
  2080. "Windows Phone" : "Windows Store")
  2081. << "</ApplicationType>\n";
  2082. this->WriteString("<ApplicationTypeRevision>", 2);
  2083. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  2084. << "</ApplicationTypeRevision>\n";
  2085. if(v == "8.1")
  2086. {
  2087. // Visual Studio 12.0 is necessary for building 8.1 apps
  2088. this->WriteString("<MinimumVisualStudioVersion>12.0"
  2089. "</MinimumVisualStudioVersion>\n", 2);
  2090. }
  2091. else if (v == "8.0")
  2092. {
  2093. // Visual Studio 11.0 is necessary for building 8.0 apps
  2094. this->WriteString("<MinimumVisualStudioVersion>11.0"
  2095. "</MinimumVisualStudioVersion>\n", 2);
  2096. }
  2097. }
  2098. if (this->Platform == "ARM")
  2099. {
  2100. this->WriteString("<WindowsSDKDesktopARMSupport>true"
  2101. "</WindowsSDKDesktopARMSupport>", 2);
  2102. }
  2103. }