cmVisualStudio10TargetGenerator.cxx 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260
  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 "cmVS10MASMFlagTable.h"
  26. #include "cmVS11CLFlagTable.h"
  27. #include "cmVS11RCFlagTable.h"
  28. #include "cmVS11LinkFlagTable.h"
  29. #include "cmVS11LibFlagTable.h"
  30. #include "cmVS11MASMFlagTable.h"
  31. #include "cmVS12CLFlagTable.h"
  32. #include "cmVS12RCFlagTable.h"
  33. #include "cmVS12LinkFlagTable.h"
  34. #include "cmVS12LibFlagTable.h"
  35. #include "cmVS12MASMFlagTable.h"
  36. #include "cmVS14CLFlagTable.h"
  37. #include "cmVS14RCFlagTable.h"
  38. #include "cmVS14LinkFlagTable.h"
  39. #include "cmVS14LibFlagTable.h"
  40. #include "cmVS14MASMFlagTable.h"
  41. #include <cmsys/auto_ptr.hxx>
  42. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetClFlagTable() const
  43. {
  44. if(this->MSTools)
  45. {
  46. cmGlobalVisualStudioGenerator::VSVersion
  47. v = this->LocalGenerator->GetVersion();
  48. if(v >= cmGlobalVisualStudioGenerator::VS14)
  49. { return cmVS14CLFlagTable; }
  50. else if(v >= cmGlobalVisualStudioGenerator::VS12)
  51. { return cmVS12CLFlagTable; }
  52. else if(v == cmGlobalVisualStudioGenerator::VS11)
  53. { return cmVS11CLFlagTable; }
  54. else
  55. { return cmVS10CLFlagTable; }
  56. }
  57. return 0;
  58. }
  59. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetRcFlagTable() const
  60. {
  61. if(this->MSTools)
  62. {
  63. cmGlobalVisualStudioGenerator::VSVersion
  64. v = this->LocalGenerator->GetVersion();
  65. if(v >= cmGlobalVisualStudioGenerator::VS14)
  66. { return cmVS14RCFlagTable; }
  67. else if(v >= cmGlobalVisualStudioGenerator::VS12)
  68. { return cmVS12RCFlagTable; }
  69. else if(v == cmGlobalVisualStudioGenerator::VS11)
  70. { return cmVS11RCFlagTable; }
  71. else
  72. { return cmVS10RCFlagTable; }
  73. }
  74. return 0;
  75. }
  76. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLibFlagTable() const
  77. {
  78. if(this->MSTools)
  79. {
  80. cmGlobalVisualStudioGenerator::VSVersion
  81. v = this->LocalGenerator->GetVersion();
  82. if(v >= cmGlobalVisualStudioGenerator::VS14)
  83. { return cmVS14LibFlagTable; }
  84. else if(v >= cmGlobalVisualStudioGenerator::VS12)
  85. { return cmVS12LibFlagTable; }
  86. else if(v == cmGlobalVisualStudioGenerator::VS11)
  87. { return cmVS11LibFlagTable; }
  88. else
  89. { return cmVS10LibFlagTable; }
  90. }
  91. return 0;
  92. }
  93. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLinkFlagTable() const
  94. {
  95. if(this->MSTools)
  96. {
  97. cmGlobalVisualStudioGenerator::VSVersion
  98. v = this->LocalGenerator->GetVersion();
  99. if(v >= cmGlobalVisualStudioGenerator::VS14)
  100. { return cmVS14LinkFlagTable; }
  101. else if(v >= cmGlobalVisualStudioGenerator::VS12)
  102. { return cmVS12LinkFlagTable; }
  103. else if(v == cmGlobalVisualStudioGenerator::VS11)
  104. { return cmVS11LinkFlagTable; }
  105. else
  106. { return cmVS10LinkFlagTable; }
  107. }
  108. return 0;
  109. }
  110. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetMasmFlagTable() const
  111. {
  112. if(this->MSTools)
  113. {
  114. cmGlobalVisualStudioGenerator::VSVersion
  115. v = this->LocalGenerator->GetVersion();
  116. if(v >= cmGlobalVisualStudioGenerator::VS14)
  117. { return cmVS14MASMFlagTable; }
  118. else if(v >= cmGlobalVisualStudioGenerator::VS12)
  119. { return cmVS12MASMFlagTable; }
  120. else if(v == cmGlobalVisualStudioGenerator::VS11)
  121. { return cmVS11MASMFlagTable; }
  122. else
  123. { return cmVS10MASMFlagTable; }
  124. }
  125. return 0;
  126. }
  127. static std::string cmVS10EscapeXML(std::string arg)
  128. {
  129. cmSystemTools::ReplaceString(arg, "&", "&amp;");
  130. cmSystemTools::ReplaceString(arg, "<", "&lt;");
  131. cmSystemTools::ReplaceString(arg, ">", "&gt;");
  132. return arg;
  133. }
  134. static std::string cmVS10EscapeComment(std::string comment)
  135. {
  136. // MSBuild takes the CDATA of a <Message></Message> element and just
  137. // does "echo $CDATA" with no escapes. We must encode the string.
  138. // http://technet.microsoft.com/en-us/library/cc772462%28WS.10%29.aspx
  139. std::string echoable;
  140. for(std::string::iterator c = comment.begin(); c != comment.end(); ++c)
  141. {
  142. switch (*c)
  143. {
  144. case '\r': break;
  145. case '\n': echoable += '\t'; break;
  146. case '"': /* no break */
  147. case '|': /* no break */
  148. case '&': /* no break */
  149. case '<': /* no break */
  150. case '>': /* no break */
  151. case '^': echoable += '^'; /* no break */
  152. default: echoable += *c; break;
  153. }
  154. }
  155. return echoable;
  156. }
  157. cmVisualStudio10TargetGenerator::
  158. cmVisualStudio10TargetGenerator(cmTarget* target,
  159. cmGlobalVisualStudio10Generator* gg)
  160. {
  161. this->GlobalGenerator = gg;
  162. this->Target = target;
  163. this->GeneratorTarget = gg->GetGeneratorTarget(target);
  164. this->Makefile = target->GetMakefile();
  165. this->Makefile->GetConfigurations(this->Configurations);
  166. this->LocalGenerator =
  167. (cmLocalVisualStudio7Generator*)
  168. this->GeneratorTarget->GetLocalGenerator();
  169. this->Name = this->Target->GetName();
  170. this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
  171. this->Platform = gg->GetPlatformName();
  172. this->NsightTegra = gg->IsNsightTegra();
  173. for(int i =
  174. sscanf(gg->GetNsightTegraVersion().c_str(), "%u.%u.%u.%u",
  175. &this->NsightTegraVersion[0], &this->NsightTegraVersion[1],
  176. &this->NsightTegraVersion[2], &this->NsightTegraVersion[3]);
  177. i < 4; ++i)
  178. {
  179. this->NsightTegraVersion[i] = 0;
  180. }
  181. this->MSTools = !this->NsightTegra;
  182. this->TargetCompileAsWinRT = false;
  183. this->BuildFileStream = 0;
  184. this->IsMissingFiles = false;
  185. this->DefaultArtifactDir =
  186. this->Makefile->GetCurrentBinaryDirectory() + std::string("/") +
  187. this->LocalGenerator->GetTargetDirectory(*this->Target);
  188. }
  189. cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
  190. {
  191. for(OptionsMap::iterator i = this->ClOptions.begin();
  192. i != this->ClOptions.end(); ++i)
  193. {
  194. delete i->second;
  195. }
  196. for(OptionsMap::iterator i = this->LinkOptions.begin();
  197. i != this->LinkOptions.end(); ++i)
  198. {
  199. delete i->second;
  200. }
  201. if(!this->BuildFileStream)
  202. {
  203. return;
  204. }
  205. if (this->BuildFileStream->Close())
  206. {
  207. this->GlobalGenerator
  208. ->FileReplacedDuringGenerate(this->PathToVcxproj);
  209. }
  210. delete this->BuildFileStream;
  211. }
  212. void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
  213. const char* tag,
  214. const std::string& config,
  215. int indentLevel,
  216. const char* attribute,
  217. const char* end,
  218. std::ostream* stream)
  219. {
  220. if(!stream)
  221. {
  222. stream = this->BuildFileStream;
  223. }
  224. stream->fill(' ');
  225. stream->width(indentLevel*2 );
  226. (*stream ) << "";
  227. (*stream ) << "<" << tag
  228. << " Condition=\"'$(Configuration)|$(Platform)'=='";
  229. (*stream ) << config << "|" << this->Platform << "'\"";
  230. if(attribute)
  231. {
  232. (*stream ) << attribute;
  233. }
  234. // close the tag
  235. (*stream ) << ">";
  236. if(end)
  237. {
  238. (*stream ) << end;
  239. }
  240. }
  241. void cmVisualStudio10TargetGenerator::WriteString(const char* line,
  242. int indentLevel)
  243. {
  244. this->BuildFileStream->fill(' ');
  245. this->BuildFileStream->width(indentLevel*2 );
  246. // write an empty string to get the fill level indent to print
  247. (*this->BuildFileStream ) << "";
  248. (*this->BuildFileStream ) << line;
  249. }
  250. #define VS10_USER_PROPS "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props"
  251. void cmVisualStudio10TargetGenerator::Generate()
  252. {
  253. // do not generate external ms projects
  254. if(this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
  255. || this->Target->GetProperty("EXTERNAL_MSPROJECT"))
  256. {
  257. return;
  258. }
  259. // Tell the global generator the name of the project file
  260. this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
  261. this->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
  262. ".vcxproj");
  263. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
  264. {
  265. if(!this->ComputeClOptions())
  266. {
  267. return;
  268. }
  269. if(!this->ComputeRcOptions())
  270. {
  271. return;
  272. }
  273. if(!this->ComputeMasmOptions())
  274. {
  275. return;
  276. }
  277. if(!this->ComputeLinkOptions())
  278. {
  279. return;
  280. }
  281. }
  282. cmMakefile* mf = this->Target->GetMakefile();
  283. std::string path = mf->GetCurrentBinaryDirectory();
  284. path += "/";
  285. path += this->Name;
  286. path += ".vcxproj";
  287. this->BuildFileStream =
  288. new cmGeneratedFileStream(path.c_str());
  289. this->PathToVcxproj = path;
  290. this->BuildFileStream->SetCopyIfDifferent(true);
  291. // Write the encoding header into the file
  292. char magic[] = {char(0xEF), char(0xBB), char(0xBF)};
  293. this->BuildFileStream->write(magic, 3);
  294. //get the tools version to use
  295. const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
  296. std::string project_defaults=
  297. "<?xml version=\"1.0\" encoding=\"" +
  298. this->GlobalGenerator->Encoding() + "\"?>\n";
  299. project_defaults.append("<Project DefaultTargets=\"Build\" ToolsVersion=\"");
  300. project_defaults.append(toolsVer +"\" ");
  301. project_defaults.append(
  302. "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
  303. this->WriteString(project_defaults.c_str(),0);
  304. if(this->NsightTegra)
  305. {
  306. this->WriteString("<PropertyGroup Label=\"NsightTegraProject\">\n", 1);
  307. if(this->NsightTegraVersion[0] >= 2)
  308. {
  309. // Nsight Tegra 2.0 uses project revision 9.
  310. this->WriteString("<NsightTegraProjectRevisionNumber>"
  311. "9"
  312. "</NsightTegraProjectRevisionNumber>\n", 2);
  313. // Tell newer versions to upgrade silently when loading.
  314. this->WriteString("<NsightTegraUpgradeOnceWithoutPrompt>"
  315. "true"
  316. "</NsightTegraUpgradeOnceWithoutPrompt>\n", 2);
  317. }
  318. else
  319. {
  320. // Require Nsight Tegra 1.6 for JCompile support.
  321. this->WriteString("<NsightTegraProjectRevisionNumber>"
  322. "7"
  323. "</NsightTegraProjectRevisionNumber>\n", 2);
  324. }
  325. this->WriteString("</PropertyGroup>\n", 1);
  326. }
  327. this->WriteProjectConfigurations();
  328. this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1);
  329. this->WriteString("<ProjectGUID>", 2);
  330. (*this->BuildFileStream) << "{" << this->GUID << "}</ProjectGUID>\n";
  331. if(this->MSTools && this->Target->GetType() <= cmTarget::GLOBAL_TARGET)
  332. {
  333. this->WriteApplicationTypeSettings();
  334. this->VerifyNecessaryFiles();
  335. }
  336. const char* vsProjectTypes =
  337. this->Target->GetProperty("VS_GLOBAL_PROJECT_TYPES");
  338. if(vsProjectTypes)
  339. {
  340. this->WriteString("<ProjectTypes>", 2);
  341. (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectTypes) <<
  342. "</ProjectTypes>\n";
  343. }
  344. const char* vsProjectName = this->Target->GetProperty("VS_SCC_PROJECTNAME");
  345. const char* vsLocalPath = this->Target->GetProperty("VS_SCC_LOCALPATH");
  346. const char* vsProvider = this->Target->GetProperty("VS_SCC_PROVIDER");
  347. if( vsProjectName && vsLocalPath && vsProvider )
  348. {
  349. this->WriteString("<SccProjectName>", 2);
  350. (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectName) <<
  351. "</SccProjectName>\n";
  352. this->WriteString("<SccLocalPath>", 2);
  353. (*this->BuildFileStream) << cmVS10EscapeXML(vsLocalPath) <<
  354. "</SccLocalPath>\n";
  355. this->WriteString("<SccProvider>", 2);
  356. (*this->BuildFileStream) << cmVS10EscapeXML(vsProvider) <<
  357. "</SccProvider>\n";
  358. const char* vsAuxPath = this->Target->GetProperty("VS_SCC_AUXPATH");
  359. if( vsAuxPath )
  360. {
  361. this->WriteString("<SccAuxPath>", 2);
  362. (*this->BuildFileStream) << cmVS10EscapeXML(vsAuxPath) <<
  363. "</SccAuxPath>\n";
  364. }
  365. }
  366. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
  367. {
  368. this->WriteString("<WinMDAssembly>true</WinMDAssembly>\n", 2);
  369. }
  370. const char* vsGlobalKeyword =
  371. this->Target->GetProperty("VS_GLOBAL_KEYWORD");
  372. if(!vsGlobalKeyword)
  373. {
  374. this->WriteString("<Keyword>Win32Proj</Keyword>\n", 2);
  375. }
  376. else
  377. {
  378. this->WriteString("<Keyword>", 2);
  379. (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalKeyword) <<
  380. "</Keyword>\n";
  381. }
  382. const char* vsGlobalRootNamespace =
  383. this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
  384. if(vsGlobalRootNamespace)
  385. {
  386. this->WriteString("<RootNamespace>", 2);
  387. (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalRootNamespace) <<
  388. "</RootNamespace>\n";
  389. }
  390. this->WriteString("<Platform>", 2);
  391. (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
  392. << "</Platform>\n";
  393. const char* projLabel = this->Target->GetProperty("PROJECT_LABEL");
  394. if(!projLabel)
  395. {
  396. projLabel = this->Name.c_str();
  397. }
  398. this->WriteString("<ProjectName>", 2);
  399. (*this->BuildFileStream) << cmVS10EscapeXML(projLabel) << "</ProjectName>\n";
  400. if(const char* targetFrameworkVersion = this->Target->GetProperty(
  401. "VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
  402. {
  403. this->WriteString("<TargetFrameworkVersion>", 2);
  404. (*this->BuildFileStream) << cmVS10EscapeXML(targetFrameworkVersion)
  405. << "</TargetFrameworkVersion>\n";
  406. }
  407. this->WriteString("</PropertyGroup>\n", 1);
  408. this->WriteString("<Import Project="
  409. "\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n",
  410. 1);
  411. this->WriteProjectConfigurationValues();
  412. this->WriteString(
  413. "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n", 1);
  414. this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1);
  415. if (this->GlobalGenerator->IsMasmEnabled())
  416. {
  417. this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
  418. "BuildCustomizations\\masm.props\" />\n", 2);
  419. }
  420. this->WriteString("</ImportGroup>\n", 1);
  421. this->WriteString("<ImportGroup Label=\"PropertySheets\">\n", 1);
  422. this->WriteString("<Import Project=\"" VS10_USER_PROPS "\""
  423. " Condition=\"exists('" VS10_USER_PROPS "')\""
  424. " Label=\"LocalAppDataPlatform\" />\n", 2);
  425. this->WriteString("</ImportGroup>\n", 1);
  426. this->WriteString("<PropertyGroup Label=\"UserMacros\" />\n", 1);
  427. this->WriteWinRTPackageCertificateKeyFile();
  428. this->WritePathAndIncrementalLinkOptions();
  429. this->WriteItemDefinitionGroups();
  430. this->WriteCustomCommands();
  431. this->WriteAllSources();
  432. this->WriteDotNetReferences();
  433. this->WriteEmbeddedResourceGroup();
  434. this->WriteXamlFilesGroup();
  435. this->WriteWinRTReferences();
  436. this->WriteProjectReferences();
  437. this->WriteString(
  438. "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\""
  439. " />\n", 1);
  440. this->WriteTargetSpecificReferences();
  441. this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
  442. if (this->GlobalGenerator->IsMasmEnabled())
  443. {
  444. this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
  445. "BuildCustomizations\\masm.targets\" />\n", 2);
  446. }
  447. this->WriteString("</ImportGroup>\n", 1);
  448. this->WriteString("</Project>", 0);
  449. // The groups are stored in a separate file for VS 10
  450. this->WriteGroups();
  451. }
  452. void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
  453. {
  454. std::vector<std::string> references;
  455. if(const char* vsDotNetReferences =
  456. this->Target->GetProperty("VS_DOTNET_REFERENCES"))
  457. {
  458. cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
  459. }
  460. if(!references.empty())
  461. {
  462. this->WriteString("<ItemGroup>\n", 1);
  463. for(std::vector<std::string>::iterator ri = references.begin();
  464. ri != references.end(); ++ri)
  465. {
  466. this->WriteString("<Reference Include=\"", 2);
  467. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
  468. this->WriteString("<CopyLocalSatelliteAssemblies>true"
  469. "</CopyLocalSatelliteAssemblies>\n", 3);
  470. this->WriteString("<ReferenceOutputAssembly>true"
  471. "</ReferenceOutputAssembly>\n", 3);
  472. this->WriteString("</Reference>\n", 2);
  473. }
  474. this->WriteString("</ItemGroup>\n", 1);
  475. }
  476. }
  477. void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
  478. {
  479. std::vector<cmSourceFile const*> resxObjs;
  480. this->GeneratorTarget->GetResxSources(resxObjs, "");
  481. if(!resxObjs.empty())
  482. {
  483. this->WriteString("<ItemGroup>\n", 1);
  484. for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
  485. oi != resxObjs.end(); ++oi)
  486. {
  487. std::string obj = (*oi)->GetFullPath();
  488. this->WriteString("<EmbeddedResource Include=\"", 2);
  489. this->ConvertToWindowsSlash(obj);
  490. (*this->BuildFileStream ) << obj << "\">\n";
  491. this->WriteString("<DependentUpon>", 3);
  492. std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h";
  493. (*this->BuildFileStream) << hFileName << "</DependentUpon>\n";
  494. for(std::vector<std::string>::const_iterator
  495. i = this->Configurations.begin();
  496. i != this->Configurations.end(); ++i)
  497. {
  498. this->WritePlatformConfigTag("LogicalName", i->c_str(), 3);
  499. if(this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE"))
  500. {
  501. (*this->BuildFileStream ) << "$(RootNamespace).";
  502. }
  503. (*this->BuildFileStream ) << "%(Filename)";
  504. (*this->BuildFileStream ) << ".resources";
  505. (*this->BuildFileStream ) << "</LogicalName>\n";
  506. }
  507. this->WriteString("</EmbeddedResource>\n", 2);
  508. }
  509. this->WriteString("</ItemGroup>\n", 1);
  510. }
  511. }
  512. void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup()
  513. {
  514. std::vector<cmSourceFile const*> xamlObjs;
  515. this->GeneratorTarget->GetXamlSources(xamlObjs, "");
  516. if (!xamlObjs.empty())
  517. {
  518. this->WriteString("<ItemGroup>\n", 1);
  519. for (std::vector<cmSourceFile const*>::const_iterator
  520. oi = xamlObjs.begin(); oi != xamlObjs.end(); ++oi)
  521. {
  522. std::string obj = (*oi)->GetFullPath();
  523. std::string xamlType;
  524. const char * xamlTypeProperty = (*oi)->GetProperty("VS_XAML_TYPE");
  525. if (xamlTypeProperty)
  526. {
  527. xamlType = xamlTypeProperty;
  528. }
  529. else
  530. {
  531. xamlType = "Page";
  532. }
  533. this->WriteSource(xamlType, *oi, ">\n");
  534. this->WriteString("<SubType>Designer</SubType>\n", 3);
  535. this->WriteString("</", 2);
  536. (*this->BuildFileStream) << xamlType << ">\n";
  537. }
  538. this->WriteString("</ItemGroup>\n", 1);
  539. }
  540. }
  541. void cmVisualStudio10TargetGenerator::WriteTargetSpecificReferences()
  542. {
  543. if(this->MSTools)
  544. {
  545. if(this->GlobalGenerator->TargetsWindowsPhone() &&
  546. this->GlobalGenerator->GetSystemVersion() == "8.0")
  547. {
  548. this->WriteString(
  549. "<Import Project=\""
  550. "$(MSBuildExtensionsPath)\\Microsoft\\WindowsPhone\\v"
  551. "$(TargetPlatformVersion)\\Microsoft.Cpp.WindowsPhone."
  552. "$(TargetPlatformVersion).targets\" />\n", 1);
  553. }
  554. }
  555. }
  556. void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
  557. {
  558. std::vector<std::string> references;
  559. if(const char* vsWinRTReferences =
  560. this->Target->GetProperty("VS_WINRT_REFERENCES"))
  561. {
  562. cmSystemTools::ExpandListArgument(vsWinRTReferences, references);
  563. }
  564. if(this->GlobalGenerator->TargetsWindowsPhone() &&
  565. this->GlobalGenerator->GetSystemVersion() == "8.0" &&
  566. references.empty())
  567. {
  568. references.push_back("platform.winmd");
  569. }
  570. if(!references.empty())
  571. {
  572. this->WriteString("<ItemGroup>\n", 1);
  573. for(std::vector<std::string>::iterator ri = references.begin();
  574. ri != references.end(); ++ri)
  575. {
  576. this->WriteString("<Reference Include=\"", 2);
  577. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
  578. this->WriteString("<IsWinMDFile>true</IsWinMDFile>\n", 3);
  579. this->WriteString("</Reference>\n", 2);
  580. }
  581. this->WriteString("</ItemGroup>\n", 1);
  582. }
  583. }
  584. // ConfigurationType Application, Utility StaticLibrary DynamicLibrary
  585. void cmVisualStudio10TargetGenerator::WriteProjectConfigurations()
  586. {
  587. this->WriteString("<ItemGroup Label=\"ProjectConfigurations\">\n", 1);
  588. for(std::vector<std::string>::const_iterator
  589. i = this->Configurations.begin();
  590. i != this->Configurations.end(); ++i)
  591. {
  592. this->WriteString("<ProjectConfiguration Include=\"", 2);
  593. (*this->BuildFileStream ) << *i << "|" << this->Platform << "\">\n";
  594. this->WriteString("<Configuration>", 3);
  595. (*this->BuildFileStream ) << *i << "</Configuration>\n";
  596. this->WriteString("<Platform>", 3);
  597. (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
  598. << "</Platform>\n";
  599. this->WriteString("</ProjectConfiguration>\n", 2);
  600. }
  601. this->WriteString("</ItemGroup>\n", 1);
  602. }
  603. void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
  604. {
  605. for(std::vector<std::string>::const_iterator
  606. i = this->Configurations.begin();
  607. i != this->Configurations.end(); ++i)
  608. {
  609. this->WritePlatformConfigTag("PropertyGroup",
  610. i->c_str(),
  611. 1, " Label=\"Configuration\"", "\n");
  612. std::string configType = "<ConfigurationType>";
  613. switch(this->Target->GetType())
  614. {
  615. case cmTarget::SHARED_LIBRARY:
  616. case cmTarget::MODULE_LIBRARY:
  617. configType += "DynamicLibrary";
  618. break;
  619. case cmTarget::OBJECT_LIBRARY:
  620. case cmTarget::STATIC_LIBRARY:
  621. configType += "StaticLibrary";
  622. break;
  623. case cmTarget::EXECUTABLE:
  624. if(this->NsightTegra &&
  625. !this->Target->GetPropertyAsBool("ANDROID_GUI"))
  626. {
  627. // Android executables are .so too.
  628. configType += "DynamicLibrary";
  629. }
  630. else
  631. {
  632. configType += "Application";
  633. }
  634. break;
  635. case cmTarget::UTILITY:
  636. case cmTarget::GLOBAL_TARGET:
  637. if(this->NsightTegra)
  638. {
  639. // Tegra-Android platform does not understand "Utility".
  640. configType += "StaticLibrary";
  641. }
  642. else
  643. {
  644. configType += "Utility";
  645. }
  646. break;
  647. case cmTarget::UNKNOWN_LIBRARY:
  648. case cmTarget::INTERFACE_LIBRARY:
  649. break;
  650. }
  651. configType += "</ConfigurationType>\n";
  652. this->WriteString(configType.c_str(), 2);
  653. if(this->MSTools)
  654. {
  655. this->WriteMSToolConfigurationValues(*i);
  656. }
  657. else if(this->NsightTegra)
  658. {
  659. this->WriteNsightTegraConfigurationValues(*i);
  660. }
  661. this->WriteString("</PropertyGroup>\n", 1);
  662. }
  663. }
  664. //----------------------------------------------------------------------------
  665. void cmVisualStudio10TargetGenerator
  666. ::WriteMSToolConfigurationValues(std::string const& config)
  667. {
  668. cmGlobalVisualStudio10Generator* gg =
  669. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  670. const char* mfcFlag =
  671. this->Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG");
  672. std::string mfcFlagValue = mfcFlag ? mfcFlag : "0";
  673. std::string useOfMfcValue = "false";
  674. if(mfcFlagValue == "1")
  675. {
  676. useOfMfcValue = "Static";
  677. }
  678. else if(mfcFlagValue == "2")
  679. {
  680. useOfMfcValue = "Dynamic";
  681. }
  682. std::string mfcLine = "<UseOfMfc>";
  683. mfcLine += useOfMfcValue + "</UseOfMfc>\n";
  684. this->WriteString(mfcLine.c_str(), 2);
  685. if((this->Target->GetType() <= cmTarget::OBJECT_LIBRARY &&
  686. this->ClOptions[config]->UsingUnicode()) ||
  687. this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  688. this->GlobalGenerator->TargetsWindowsPhone() ||
  689. this->GlobalGenerator->TargetsWindowsStore() ||
  690. this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  691. {
  692. this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
  693. }
  694. else if (this->Target->GetType() <= cmTarget::MODULE_LIBRARY &&
  695. this->ClOptions[config]->UsingSBCS())
  696. {
  697. this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
  698. }
  699. else
  700. {
  701. this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
  702. }
  703. if(const char* toolset = gg->GetPlatformToolset())
  704. {
  705. std::string pts = "<PlatformToolset>";
  706. pts += toolset;
  707. pts += "</PlatformToolset>\n";
  708. this->WriteString(pts.c_str(), 2);
  709. }
  710. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  711. this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  712. {
  713. this->WriteString("<WindowsAppContainer>true"
  714. "</WindowsAppContainer>\n", 2);
  715. }
  716. }
  717. //----------------------------------------------------------------------------
  718. void cmVisualStudio10TargetGenerator
  719. ::WriteNsightTegraConfigurationValues(std::string const&)
  720. {
  721. cmGlobalVisualStudio10Generator* gg =
  722. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  723. const char* toolset = gg->GetPlatformToolset();
  724. std::string ntv = "<NdkToolchainVersion>";
  725. ntv += toolset? toolset : "Default";
  726. ntv += "</NdkToolchainVersion>\n";
  727. this->WriteString(ntv.c_str(), 2);
  728. if(const char* minApi = this->Target->GetProperty("ANDROID_API_MIN"))
  729. {
  730. this->WriteString("<AndroidMinAPI>", 2);
  731. (*this->BuildFileStream ) <<
  732. "android-" << cmVS10EscapeXML(minApi) << "</AndroidMinAPI>\n";
  733. }
  734. if(const char* api = this->Target->GetProperty("ANDROID_API"))
  735. {
  736. this->WriteString("<AndroidTargetAPI>", 2);
  737. (*this->BuildFileStream ) <<
  738. "android-" << cmVS10EscapeXML(api) << "</AndroidTargetAPI>\n";
  739. }
  740. }
  741. void cmVisualStudio10TargetGenerator::WriteCustomCommands()
  742. {
  743. this->SourcesVisited.clear();
  744. std::vector<cmSourceFile const*> customCommands;
  745. this->GeneratorTarget->GetCustomCommands(customCommands, "");
  746. for(std::vector<cmSourceFile const*>::const_iterator
  747. si = customCommands.begin();
  748. si != customCommands.end(); ++si)
  749. {
  750. this->WriteCustomCommand(*si);
  751. }
  752. }
  753. //----------------------------------------------------------------------------
  754. void cmVisualStudio10TargetGenerator
  755. ::WriteCustomCommand(cmSourceFile const* sf)
  756. {
  757. if(this->SourcesVisited.insert(sf).second)
  758. {
  759. if(std::vector<cmSourceFile*> const* depends =
  760. this->GeneratorTarget->GetSourceDepends(sf))
  761. {
  762. for(std::vector<cmSourceFile*>::const_iterator di = depends->begin();
  763. di != depends->end(); ++di)
  764. {
  765. this->WriteCustomCommand(*di);
  766. }
  767. }
  768. if(cmCustomCommand const* command = sf->GetCustomCommand())
  769. {
  770. this->WriteString("<ItemGroup>\n", 1);
  771. this->WriteCustomRule(sf, *command);
  772. this->WriteString("</ItemGroup>\n", 1);
  773. }
  774. }
  775. }
  776. void
  777. cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source,
  778. cmCustomCommand const &
  779. command)
  780. {
  781. std::string sourcePath = source->GetFullPath();
  782. // VS 10 will always rebuild a custom command attached to a .rule
  783. // file that doesn't exist so create the file explicitly.
  784. if (source->GetPropertyAsBool("__CMAKE_RULE"))
  785. {
  786. if(!cmSystemTools::FileExists(sourcePath.c_str()))
  787. {
  788. // Make sure the path exists for the file
  789. std::string path = cmSystemTools::GetFilenamePath(sourcePath);
  790. cmSystemTools::MakeDirectory(path.c_str());
  791. cmsys::ofstream fout(sourcePath.c_str());
  792. if(fout)
  793. {
  794. fout << "# generated from CMake\n";
  795. fout.flush();
  796. fout.close();
  797. }
  798. else
  799. {
  800. std::string error = "Could not create file: [";
  801. error += sourcePath;
  802. error += "] ";
  803. cmSystemTools::Error
  804. (error.c_str(), cmSystemTools::GetLastSystemError().c_str());
  805. }
  806. }
  807. }
  808. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  809. this->WriteSource("CustomBuild", source, ">\n");
  810. for(std::vector<std::string>::const_iterator
  811. i = this->Configurations.begin();
  812. i != this->Configurations.end(); ++i)
  813. {
  814. cmCustomCommandGenerator ccg(command, *i, this->Makefile);
  815. std::string comment = lg->ConstructComment(ccg);
  816. comment = cmVS10EscapeComment(comment);
  817. std::string script =
  818. cmVS10EscapeXML(lg->ConstructScript(ccg));
  819. this->WritePlatformConfigTag("Message",i->c_str(), 3);
  820. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  821. this->WritePlatformConfigTag("Command", i->c_str(), 3);
  822. (*this->BuildFileStream ) << script << "</Command>\n";
  823. this->WritePlatformConfigTag("AdditionalInputs", i->c_str(), 3);
  824. (*this->BuildFileStream ) << cmVS10EscapeXML(source->GetFullPath());
  825. for(std::vector<std::string>::const_iterator d =
  826. ccg.GetDepends().begin();
  827. d != ccg.GetDepends().end();
  828. ++d)
  829. {
  830. std::string dep;
  831. if(this->LocalGenerator->GetRealDependency(d->c_str(), i->c_str(), dep))
  832. {
  833. this->ConvertToWindowsSlash(dep);
  834. (*this->BuildFileStream ) << ";" << cmVS10EscapeXML(dep);
  835. }
  836. }
  837. (*this->BuildFileStream ) << ";%(AdditionalInputs)</AdditionalInputs>\n";
  838. this->WritePlatformConfigTag("Outputs", i->c_str(), 3);
  839. const char* sep = "";
  840. for(std::vector<std::string>::const_iterator o =
  841. ccg.GetOutputs().begin();
  842. o != ccg.GetOutputs().end();
  843. ++o)
  844. {
  845. std::string out = *o;
  846. this->ConvertToWindowsSlash(out);
  847. (*this->BuildFileStream ) << sep << cmVS10EscapeXML(out);
  848. sep = ";";
  849. }
  850. (*this->BuildFileStream ) << "</Outputs>\n";
  851. if(this->LocalGenerator->GetVersion()
  852. > cmGlobalVisualStudioGenerator::VS10)
  853. {
  854. // VS >= 11 let us turn off linking of custom command outputs.
  855. this->WritePlatformConfigTag("LinkObjects", i->c_str(), 3);
  856. (*this->BuildFileStream ) << "false</LinkObjects>\n";
  857. }
  858. }
  859. this->WriteString("</CustomBuild>\n", 2);
  860. }
  861. std::string
  862. cmVisualStudio10TargetGenerator::ConvertPath(std::string const& path,
  863. bool forceRelative)
  864. {
  865. return forceRelative
  866. ? cmSystemTools::RelativePath(
  867. this->Makefile->GetCurrentBinaryDirectory(), path.c_str())
  868. : path.c_str();
  869. }
  870. void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s)
  871. {
  872. // first convert all of the slashes
  873. std::string::size_type pos = 0;
  874. while((pos = s.find('/', pos)) != std::string::npos)
  875. {
  876. s[pos] = '\\';
  877. pos++;
  878. }
  879. }
  880. void cmVisualStudio10TargetGenerator::WriteGroups()
  881. {
  882. // collect up group information
  883. std::vector<cmSourceGroup> sourceGroups =
  884. this->Makefile->GetSourceGroups();
  885. std::vector<cmSourceFile*> classes;
  886. if (!this->Target->GetConfigCommonSourceFiles(classes))
  887. {
  888. return;
  889. }
  890. std::set<cmSourceGroup*> groupsUsed;
  891. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  892. s != classes.end(); s++)
  893. {
  894. cmSourceFile* sf = *s;
  895. std::string const& source = sf->GetFullPath();
  896. cmSourceGroup* sourceGroup =
  897. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  898. groupsUsed.insert(sourceGroup);
  899. }
  900. this->AddMissingSourceGroups(groupsUsed, sourceGroups);
  901. // Write out group file
  902. std::string path = this->Makefile->GetCurrentBinaryDirectory();
  903. path += "/";
  904. path += this->Name;
  905. path += ".vcxproj.filters";
  906. cmGeneratedFileStream fout(path.c_str());
  907. fout.SetCopyIfDifferent(true);
  908. char magic[] = {char(0xEF), char(0xBB), char(0xBF)};
  909. fout.write(magic, 3);
  910. cmGeneratedFileStream* save = this->BuildFileStream;
  911. this->BuildFileStream = & fout;
  912. //get the tools version to use
  913. const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
  914. std::string project_defaults=
  915. "<?xml version=\"1.0\" encoding=\"" +
  916. this->GlobalGenerator->Encoding() + "\"?>\n";
  917. project_defaults.append("<Project ToolsVersion=\"");
  918. project_defaults.append(toolsVer +"\" ");
  919. project_defaults.append(
  920. "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
  921. this->WriteString(project_defaults.c_str(),0);
  922. for(ToolSourceMap::const_iterator ti = this->Tools.begin();
  923. ti != this->Tools.end(); ++ti)
  924. {
  925. this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups);
  926. }
  927. // Added files are images and the manifest.
  928. if (!this->AddedFiles.empty())
  929. {
  930. this->WriteString("<ItemGroup>\n", 1);
  931. for(std::vector<std::string>::const_iterator
  932. oi = this->AddedFiles.begin(); oi != this->AddedFiles.end(); ++oi)
  933. {
  934. std::string fileName = cmSystemTools::LowerCase(
  935. cmSystemTools::GetFilenameName(*oi));
  936. if (fileName == "wmappmanifest.xml")
  937. {
  938. this->WriteString("<XML Include=\"", 2);
  939. (*this->BuildFileStream) << *oi << "\">\n";
  940. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  941. this->WriteString("</XML>\n", 2);
  942. }
  943. else if(cmSystemTools::GetFilenameExtension(fileName) ==
  944. ".appxmanifest")
  945. {
  946. this->WriteString("<AppxManifest Include=\"", 2);
  947. (*this->BuildFileStream) << *oi << "\">\n";
  948. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  949. this->WriteString("</AppxManifest>\n", 2);
  950. }
  951. else if(cmSystemTools::GetFilenameExtension(fileName) ==
  952. ".pfx")
  953. {
  954. this->WriteString("<None Include=\"", 2);
  955. (*this->BuildFileStream) << *oi << "\">\n";
  956. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  957. this->WriteString("</None>\n", 2);
  958. }
  959. else
  960. {
  961. this->WriteString("<Image Include=\"", 2);
  962. (*this->BuildFileStream) << *oi << "\">\n";
  963. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  964. this->WriteString("</Image>\n", 2);
  965. }
  966. }
  967. this->WriteString("</ItemGroup>\n", 1);
  968. }
  969. std::vector<cmSourceFile const*> resxObjs;
  970. this->GeneratorTarget->GetResxSources(resxObjs, "");
  971. if(!resxObjs.empty())
  972. {
  973. this->WriteString("<ItemGroup>\n", 1);
  974. for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
  975. oi != resxObjs.end(); ++oi)
  976. {
  977. std::string obj = (*oi)->GetFullPath();
  978. this->WriteString("<EmbeddedResource Include=\"", 2);
  979. this->ConvertToWindowsSlash(obj);
  980. (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\">\n";
  981. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  982. this->WriteString("</EmbeddedResource>\n", 2);
  983. }
  984. this->WriteString("</ItemGroup>\n", 1);
  985. }
  986. // Add object library contents as external objects.
  987. std::vector<std::string> objs;
  988. this->GeneratorTarget->UseObjectLibraries(objs, "");
  989. if(!objs.empty())
  990. {
  991. this->WriteString("<ItemGroup>\n", 1);
  992. for(std::vector<std::string>::const_iterator
  993. oi = objs.begin(); oi != objs.end(); ++oi)
  994. {
  995. std::string obj = *oi;
  996. this->WriteString("<Object Include=\"", 2);
  997. this->ConvertToWindowsSlash(obj);
  998. (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\">\n";
  999. this->WriteString("<Filter>Object Libraries</Filter>\n", 3);
  1000. this->WriteString("</Object>\n", 2);
  1001. }
  1002. this->WriteString("</ItemGroup>\n", 1);
  1003. }
  1004. this->WriteString("<ItemGroup>\n", 1);
  1005. for(std::set<cmSourceGroup*>::iterator g = groupsUsed.begin();
  1006. g != groupsUsed.end(); ++g)
  1007. {
  1008. cmSourceGroup* sg = *g;
  1009. const char* name = sg->GetFullName();
  1010. if(strlen(name) != 0)
  1011. {
  1012. this->WriteString("<Filter Include=\"", 2);
  1013. (*this->BuildFileStream) << name << "\">\n";
  1014. std::string guidName = "SG_Filter_";
  1015. guidName += name;
  1016. this->WriteString("<UniqueIdentifier>", 3);
  1017. std::string guid
  1018. = this->GlobalGenerator->GetGUID(guidName.c_str());
  1019. (*this->BuildFileStream)
  1020. << "{"
  1021. << guid << "}"
  1022. << "</UniqueIdentifier>\n";
  1023. this->WriteString("</Filter>\n", 2);
  1024. }
  1025. }
  1026. if(!objs.empty())
  1027. {
  1028. this->WriteString("<Filter Include=\"Object Libraries\">\n", 2);
  1029. std::string guidName = "SG_Filter_Object Libraries";
  1030. this->WriteString("<UniqueIdentifier>", 3);
  1031. std::string guid =
  1032. this->GlobalGenerator->GetGUID(guidName.c_str());
  1033. (*this->BuildFileStream) << "{" << guid << "}"
  1034. << "</UniqueIdentifier>\n";
  1035. this->WriteString("</Filter>\n", 2);
  1036. }
  1037. if(!resxObjs.empty() || !this->AddedFiles.empty())
  1038. {
  1039. this->WriteString("<Filter Include=\"Resource Files\">\n", 2);
  1040. std::string guidName = "SG_Filter_Resource Files";
  1041. this->WriteString("<UniqueIdentifier>", 3);
  1042. std::string guid =
  1043. this->GlobalGenerator->GetGUID(guidName.c_str());
  1044. (*this->BuildFileStream) << "{" << guid << "}"
  1045. << "</UniqueIdentifier>\n";
  1046. this->WriteString("<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;", 3);
  1047. (*this->BuildFileStream) << "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;";
  1048. (*this->BuildFileStream) << "mfcribbon-ms</Extensions>\n";
  1049. this->WriteString("</Filter>\n", 2);
  1050. }
  1051. this->WriteString("</ItemGroup>\n", 1);
  1052. this->WriteString("</Project>\n", 0);
  1053. // restore stream pointer
  1054. this->BuildFileStream = save;
  1055. if (fout.Close())
  1056. {
  1057. this->GlobalGenerator->FileReplacedDuringGenerate(path);
  1058. }
  1059. }
  1060. // Add to groupsUsed empty source groups that have non-empty children.
  1061. void
  1062. cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
  1063. std::set<cmSourceGroup*>& groupsUsed,
  1064. const std::vector<cmSourceGroup>& allGroups
  1065. )
  1066. {
  1067. for(std::vector<cmSourceGroup>::const_iterator current = allGroups.begin();
  1068. current != allGroups.end(); ++current)
  1069. {
  1070. std::vector<cmSourceGroup> const& children = current->GetGroupChildren();
  1071. if(children.empty())
  1072. {
  1073. continue; // the group is really empty
  1074. }
  1075. this->AddMissingSourceGroups(groupsUsed, children);
  1076. cmSourceGroup* current_ptr = const_cast<cmSourceGroup*>(&(*current));
  1077. if(groupsUsed.find(current_ptr) != groupsUsed.end())
  1078. {
  1079. continue; // group has already been added to set
  1080. }
  1081. // check if it least one of the group's descendants is not empty
  1082. // (at least one child must already have been added)
  1083. std::vector<cmSourceGroup>::const_iterator child_it = children.begin();
  1084. while(child_it != children.end())
  1085. {
  1086. cmSourceGroup* child_ptr = const_cast<cmSourceGroup*>(&(*child_it));
  1087. if(groupsUsed.find(child_ptr) != groupsUsed.end())
  1088. {
  1089. break; // found a child that was already added => add current group too
  1090. }
  1091. child_it++;
  1092. }
  1093. if(child_it == children.end())
  1094. {
  1095. continue; // no descendants have source files => ignore this group
  1096. }
  1097. groupsUsed.insert(current_ptr);
  1098. }
  1099. }
  1100. void
  1101. cmVisualStudio10TargetGenerator::
  1102. WriteGroupSources(const char* name,
  1103. ToolSources const& sources,
  1104. std::vector<cmSourceGroup>& sourceGroups)
  1105. {
  1106. this->WriteString("<ItemGroup>\n", 1);
  1107. for(ToolSources::const_iterator s = sources.begin();
  1108. s != sources.end(); ++s)
  1109. {
  1110. cmSourceFile const* sf = s->SourceFile;
  1111. std::string const& source = sf->GetFullPath();
  1112. cmSourceGroup* sourceGroup =
  1113. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1114. const char* filter = sourceGroup->GetFullName();
  1115. this->WriteString("<", 2);
  1116. std::string path = this->ConvertPath(source, s->RelativePath);
  1117. this->ConvertToWindowsSlash(path);
  1118. (*this->BuildFileStream) << name << " Include=\""
  1119. << cmVS10EscapeXML(path);
  1120. if(strlen(filter))
  1121. {
  1122. (*this->BuildFileStream) << "\">\n";
  1123. this->WriteString("<Filter>", 3);
  1124. (*this->BuildFileStream) << filter << "</Filter>\n";
  1125. this->WriteString("</", 2);
  1126. (*this->BuildFileStream) << name << ">\n";
  1127. }
  1128. else
  1129. {
  1130. (*this->BuildFileStream) << "\" />\n";
  1131. }
  1132. }
  1133. this->WriteString("</ItemGroup>\n", 1);
  1134. }
  1135. void cmVisualStudio10TargetGenerator::WriteHeaderSource(cmSourceFile const* sf)
  1136. {
  1137. std::string const& fileName = sf->GetFullPath();
  1138. if (this->IsResxHeader(fileName))
  1139. {
  1140. this->WriteSource("ClInclude", sf, ">\n");
  1141. this->WriteString("<FileType>CppForm</FileType>\n", 3);
  1142. this->WriteString("</ClInclude>\n", 2);
  1143. }
  1144. else if (this->IsXamlHeader(fileName))
  1145. {
  1146. this->WriteSource("ClInclude", sf, ">\n");
  1147. this->WriteString("<DependentUpon>", 3);
  1148. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1149. (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
  1150. this->WriteString("</ClInclude>\n", 2);
  1151. }
  1152. else
  1153. {
  1154. this->WriteSource("ClInclude", sf);
  1155. }
  1156. }
  1157. void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
  1158. {
  1159. bool toolHasSettings = false;
  1160. std::string tool = "None";
  1161. std::string shaderType;
  1162. std::string shaderEntryPoint;
  1163. std::string shaderModel;
  1164. std::string shaderAdditionalFlags;
  1165. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1166. if(ext == "hlsl")
  1167. {
  1168. tool = "FXCompile";
  1169. // Figure out the type of shader compiler to use.
  1170. if(const char* st = sf->GetProperty("VS_SHADER_TYPE"))
  1171. {
  1172. shaderType = st;
  1173. toolHasSettings = true;
  1174. }
  1175. // Figure out which entry point to use if any
  1176. if (const char* se = sf->GetProperty("VS_SHADER_ENTRYPOINT"))
  1177. {
  1178. shaderEntryPoint = se;
  1179. toolHasSettings = true;
  1180. }
  1181. // Figure out which shader model to use if any
  1182. if (const char* sm = sf->GetProperty("VS_SHADER_MODEL"))
  1183. {
  1184. shaderModel = sm;
  1185. toolHasSettings = true;
  1186. }
  1187. // Figure out if there's any additional flags to use
  1188. if (const char* saf = sf->GetProperty("VS_SHADER_FLAGS"))
  1189. {
  1190. shaderAdditionalFlags = saf;
  1191. toolHasSettings = true;
  1192. }
  1193. }
  1194. else if(ext == "jpg" ||
  1195. ext == "png")
  1196. {
  1197. tool = "Image";
  1198. }
  1199. else if(ext == "xml")
  1200. {
  1201. tool = "XML";
  1202. }
  1203. if(this->NsightTegra)
  1204. {
  1205. // Nsight Tegra needs specific file types to check up-to-dateness.
  1206. std::string name =
  1207. cmSystemTools::LowerCase(sf->GetLocation().GetName());
  1208. if(name == "androidmanifest.xml" ||
  1209. name == "build.xml" ||
  1210. name == "proguard.cfg" ||
  1211. name == "proguard-project.txt" ||
  1212. ext == "properties")
  1213. {
  1214. tool = "AndroidBuild";
  1215. }
  1216. else if(ext == "java")
  1217. {
  1218. tool = "JCompile";
  1219. }
  1220. else if(ext == "asm" || ext == "s")
  1221. {
  1222. tool = "ClCompile";
  1223. }
  1224. }
  1225. std::string deployContent;
  1226. std::string deployLocation;
  1227. if(this->GlobalGenerator->TargetsWindowsPhone() ||
  1228. this->GlobalGenerator->TargetsWindowsStore())
  1229. {
  1230. const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
  1231. if(content && *content)
  1232. {
  1233. toolHasSettings = true;
  1234. deployContent = content;
  1235. const char* location = sf->GetProperty("VS_DEPLOYMENT_LOCATION");
  1236. if(location && *location)
  1237. {
  1238. deployLocation = location;
  1239. }
  1240. }
  1241. }
  1242. if(toolHasSettings)
  1243. {
  1244. this->WriteSource(tool, sf, ">\n");
  1245. if(!deployContent.empty())
  1246. {
  1247. cmGeneratorExpression ge;
  1248. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1249. ge.Parse(deployContent);
  1250. // Deployment location cannot be set on a configuration basis
  1251. if(!deployLocation.empty())
  1252. {
  1253. this->WriteString("<Link>", 3);
  1254. (*this->BuildFileStream) << deployLocation
  1255. << "\\%(FileName)%(Extension)";
  1256. this->WriteString("</Link>\n", 0);
  1257. }
  1258. for(size_t i = 0; i != this->Configurations.size(); ++i)
  1259. {
  1260. if(0 == strcmp(cge->Evaluate(this->Makefile,
  1261. this->Configurations[i]), "1"))
  1262. {
  1263. this->WriteString("<DeploymentContent Condition=\""
  1264. "'$(Configuration)|$(Platform)'=='", 3);
  1265. (*this->BuildFileStream) << this->Configurations[i] << "|"
  1266. << this->Platform << "'\">true";
  1267. this->WriteString("</DeploymentContent>\n", 0);
  1268. }
  1269. else
  1270. {
  1271. this->WriteString("<ExcludedFromBuild Condition=\""
  1272. "'$(Configuration)|$(Platform)'=='", 3);
  1273. (*this->BuildFileStream) << this->Configurations[i] << "|"
  1274. << this->Platform << "'\">true";
  1275. this->WriteString("</ExcludedFromBuild>\n", 0);
  1276. }
  1277. }
  1278. }
  1279. if(!shaderType.empty())
  1280. {
  1281. this->WriteString("<ShaderType>", 3);
  1282. (*this->BuildFileStream) << cmVS10EscapeXML(shaderType)
  1283. << "</ShaderType>\n";
  1284. }
  1285. if(!shaderEntryPoint.empty())
  1286. {
  1287. this->WriteString("<EntryPointName>", 3);
  1288. (*this->BuildFileStream) << cmVS10EscapeXML(shaderEntryPoint)
  1289. << "</EntryPointName>\n";
  1290. }
  1291. if(!shaderModel.empty())
  1292. {
  1293. this->WriteString("<ShaderModel>", 3);
  1294. (*this->BuildFileStream) << cmVS10EscapeXML(shaderModel)
  1295. << "</ShaderModel>\n";
  1296. }
  1297. if(!shaderAdditionalFlags.empty())
  1298. {
  1299. this->WriteString("<AdditionalOptions>", 3);
  1300. (*this->BuildFileStream) << cmVS10EscapeXML(shaderAdditionalFlags)
  1301. << "</AdditionalOptions>\n";
  1302. }
  1303. this->WriteString("</", 2);
  1304. (*this->BuildFileStream) << tool << ">\n";
  1305. }
  1306. else
  1307. {
  1308. this->WriteSource(tool, sf);
  1309. }
  1310. }
  1311. void cmVisualStudio10TargetGenerator::WriteSource(
  1312. std::string const& tool, cmSourceFile const* sf, const char* end)
  1313. {
  1314. // Visual Studio tools append relative paths to the current dir, as in:
  1315. //
  1316. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  1317. //
  1318. // and fail if this exceeds the maximum allowed path length. Our path
  1319. // conversion uses full paths when possible to allow deeper trees.
  1320. bool forceRelative = false;
  1321. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), false);
  1322. if(this->LocalGenerator->GetVersion() == cmGlobalVisualStudioGenerator::VS10
  1323. && cmSystemTools::FileIsFullPath(sourceFile.c_str()))
  1324. {
  1325. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  1326. // refuses to show the property page in the IDE for a source file with a
  1327. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  1328. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  1329. // full path except for custom commands. Custom commands do not work
  1330. // without a relative path, but they do not seem to be involved in tools
  1331. // with the above behavior. For other sources we now use a relative path
  1332. // when the combined path will not be too long so property pages appear.
  1333. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  1334. size_t const maxLen = 250;
  1335. if(sf->GetCustomCommand() ||
  1336. ((strlen(this->Makefile->GetCurrentBinaryDirectory()) + 1 +
  1337. sourceRel.length()) <= maxLen))
  1338. {
  1339. forceRelative = true;
  1340. sourceFile = sourceRel;
  1341. }
  1342. else
  1343. {
  1344. this->GlobalGenerator->PathTooLong(this->Target, sf, sourceRel);
  1345. }
  1346. }
  1347. this->ConvertToWindowsSlash(sourceFile);
  1348. this->WriteString("<", 2);
  1349. (*this->BuildFileStream ) << tool << " Include=\""
  1350. << cmVS10EscapeXML(sourceFile) << "\""
  1351. << (end? end : " />\n");
  1352. ToolSource toolSource = {sf, forceRelative};
  1353. this->Tools[tool].push_back(toolSource);
  1354. }
  1355. void cmVisualStudio10TargetGenerator::WriteSources(
  1356. std::string const& tool, std::vector<cmSourceFile const*> const& sources)
  1357. {
  1358. for(std::vector<cmSourceFile const*>::const_iterator
  1359. si = sources.begin(); si != sources.end(); ++si)
  1360. {
  1361. this->WriteSource(tool, *si);
  1362. }
  1363. }
  1364. void cmVisualStudio10TargetGenerator::WriteAllSources()
  1365. {
  1366. if(this->Target->GetType() > cmTarget::UTILITY)
  1367. {
  1368. return;
  1369. }
  1370. this->WriteString("<ItemGroup>\n", 1);
  1371. std::vector<cmSourceFile const*> headerSources;
  1372. this->GeneratorTarget->GetHeaderSources(headerSources, "");
  1373. for(std::vector<cmSourceFile const*>::const_iterator
  1374. si = headerSources.begin(); si != headerSources.end(); ++si)
  1375. {
  1376. this->WriteHeaderSource(*si);
  1377. }
  1378. std::vector<cmSourceFile const*> idlSources;
  1379. this->GeneratorTarget->GetIDLSources(idlSources, "");
  1380. this->WriteSources("Midl", idlSources);
  1381. std::vector<cmSourceFile const*> objectSources;
  1382. this->GeneratorTarget->GetObjectSources(objectSources, "");
  1383. for(std::vector<cmSourceFile const*>::const_iterator
  1384. si = objectSources.begin();
  1385. si != objectSources.end(); ++si)
  1386. {
  1387. const std::string& lang = (*si)->GetLanguage();
  1388. std::string tool;
  1389. if (lang == "C"|| lang == "CXX")
  1390. {
  1391. tool = "ClCompile";
  1392. }
  1393. else if (lang == "ASM_MASM" &&
  1394. this->GlobalGenerator->IsMasmEnabled())
  1395. {
  1396. tool = "MASM";
  1397. }
  1398. else if (lang == "RC")
  1399. {
  1400. tool = "ResourceCompile";
  1401. }
  1402. if (!tool.empty())
  1403. {
  1404. this->WriteSource(tool, *si, " ");
  1405. if (this->OutputSourceSpecificFlags(*si))
  1406. {
  1407. this->WriteString("</", 2);
  1408. (*this->BuildFileStream ) << tool << ">\n";
  1409. }
  1410. else
  1411. {
  1412. (*this->BuildFileStream ) << " />\n";
  1413. }
  1414. }
  1415. else
  1416. {
  1417. this->WriteSource("None", *si);
  1418. }
  1419. }
  1420. std::vector<cmSourceFile const*> manifestSources;
  1421. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  1422. this->WriteSources("AppxManifest", manifestSources);
  1423. std::vector<cmSourceFile const*> certificateSources;
  1424. this->GeneratorTarget->GetCertificates(certificateSources, "");
  1425. this->WriteSources("None", certificateSources);
  1426. std::vector<cmSourceFile const*> externalObjects;
  1427. this->GeneratorTarget->GetExternalObjects(externalObjects, "");
  1428. for(std::vector<cmSourceFile const*>::iterator
  1429. si = externalObjects.begin();
  1430. si != externalObjects.end(); )
  1431. {
  1432. if (!(*si)->GetObjectLibrary().empty())
  1433. {
  1434. si = externalObjects.erase(si);
  1435. }
  1436. else
  1437. {
  1438. ++si;
  1439. }
  1440. }
  1441. if(this->LocalGenerator->GetVersion() > cmGlobalVisualStudioGenerator::VS10)
  1442. {
  1443. // For VS >= 11 we use LinkObjects to avoid linking custom command
  1444. // outputs. Use Object for all external objects, generated or not.
  1445. this->WriteSources("Object", externalObjects);
  1446. }
  1447. else
  1448. {
  1449. // If an object file is generated in this target, then vs10 will use
  1450. // it in the build, and we have to list it as None instead of Object.
  1451. for(std::vector<cmSourceFile const*>::const_iterator
  1452. si = externalObjects.begin();
  1453. si != externalObjects.end(); ++si)
  1454. {
  1455. std::vector<cmSourceFile*> const* d =
  1456. this->GeneratorTarget->GetSourceDepends(*si);
  1457. this->WriteSource((d && !d->empty())? "None":"Object", *si);
  1458. }
  1459. }
  1460. std::vector<cmSourceFile const*> extraSources;
  1461. this->GeneratorTarget->GetExtraSources(extraSources, "");
  1462. for(std::vector<cmSourceFile const*>::const_iterator
  1463. si = extraSources.begin(); si != extraSources.end(); ++si)
  1464. {
  1465. this->WriteExtraSource(*si);
  1466. }
  1467. // Add object library contents as external objects.
  1468. std::vector<std::string> objs;
  1469. this->GeneratorTarget->UseObjectLibraries(objs, "");
  1470. for(std::vector<std::string>::const_iterator
  1471. oi = objs.begin(); oi != objs.end(); ++oi)
  1472. {
  1473. std::string obj = *oi;
  1474. this->WriteString("<Object Include=\"", 2);
  1475. this->ConvertToWindowsSlash(obj);
  1476. (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\" />\n";
  1477. }
  1478. if (this->IsMissingFiles)
  1479. {
  1480. this->WriteMissingFiles();
  1481. }
  1482. this->WriteString("</ItemGroup>\n", 1);
  1483. }
  1484. bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  1485. cmSourceFile const* source)
  1486. {
  1487. cmSourceFile const& sf = *source;
  1488. std::string objectName;
  1489. if(this->GeneratorTarget->HasExplicitObjectName(&sf))
  1490. {
  1491. objectName = this->GeneratorTarget->GetObjectName(&sf);
  1492. }
  1493. std::string flags;
  1494. std::string defines;
  1495. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1496. {
  1497. flags += cflags;
  1498. }
  1499. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1500. {
  1501. defines += cdefs;
  1502. }
  1503. std::string lang =
  1504. this->GlobalGenerator->GetLanguageFromExtension
  1505. (sf.GetExtension().c_str());
  1506. std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  1507. const std::string& linkLanguage = this->Target->GetLinkerLanguage();
  1508. bool needForceLang = false;
  1509. // source file does not match its extension language
  1510. if(lang != sourceLang)
  1511. {
  1512. needForceLang = true;
  1513. lang = sourceLang;
  1514. }
  1515. // if the source file does not match the linker language
  1516. // then force c or c++
  1517. const char* compileAs = 0;
  1518. if(needForceLang || (linkLanguage != lang))
  1519. {
  1520. if(lang == "CXX")
  1521. {
  1522. // force a C++ file type
  1523. compileAs = "CompileAsCpp";
  1524. }
  1525. else if(lang == "C")
  1526. {
  1527. // force to c
  1528. compileAs = "CompileAsC";
  1529. }
  1530. }
  1531. bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
  1532. bool hasFlags = false;
  1533. // for the first time we need a new line if there is something
  1534. // produced here.
  1535. const char* firstString = ">\n";
  1536. if(objectName.size())
  1537. {
  1538. (*this->BuildFileStream ) << firstString;
  1539. firstString = "";
  1540. hasFlags = true;
  1541. this->WriteString("<ObjectFileName>", 3);
  1542. (*this->BuildFileStream )
  1543. << "$(IntDir)/" << objectName << "</ObjectFileName>\n";
  1544. }
  1545. for(std::vector<std::string>::const_iterator
  1546. config = this->Configurations.begin();
  1547. config != this->Configurations.end(); ++config)
  1548. {
  1549. std::string configUpper = cmSystemTools::UpperCase(*config);
  1550. std::string configDefines = defines;
  1551. std::string defPropName = "COMPILE_DEFINITIONS_";
  1552. defPropName += configUpper;
  1553. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1554. {
  1555. if(configDefines.size())
  1556. {
  1557. configDefines += ";";
  1558. }
  1559. configDefines += ccdefs;
  1560. }
  1561. // if we have flags or defines for this config then
  1562. // use them
  1563. if(!flags.empty() || !configDefines.empty() || compileAs || noWinRT)
  1564. {
  1565. (*this->BuildFileStream ) << firstString;
  1566. firstString = ""; // only do firstString once
  1567. hasFlags = true;
  1568. cmVisualStudioGeneratorOptions
  1569. clOptions(this->LocalGenerator,
  1570. cmVisualStudioGeneratorOptions::Compiler,
  1571. this->GetClFlagTable(), 0, this);
  1572. if(compileAs)
  1573. {
  1574. clOptions.AddFlag("CompileAs", compileAs);
  1575. }
  1576. if(noWinRT)
  1577. {
  1578. clOptions.AddFlag("CompileAsWinRT", "false");
  1579. }
  1580. clOptions.Parse(flags.c_str());
  1581. if(clOptions.HasFlag("AdditionalIncludeDirectories"))
  1582. {
  1583. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1584. "%(AdditionalIncludeDirectories)");
  1585. }
  1586. if(clOptions.HasFlag("DisableSpecificWarnings"))
  1587. {
  1588. clOptions.AppendFlag("DisableSpecificWarnings",
  1589. "%(DisableSpecificWarnings)");
  1590. }
  1591. clOptions.AddDefines(configDefines.c_str());
  1592. clOptions.SetConfiguration((*config).c_str());
  1593. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1594. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1595. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream,
  1596. " ", "\n", lang);
  1597. }
  1598. }
  1599. if (this->IsXamlSource(source->GetFullPath()))
  1600. {
  1601. (*this->BuildFileStream) << firstString;
  1602. firstString = ""; // only do firstString once
  1603. hasFlags = true;
  1604. this->WriteString("<DependentUpon>", 3);
  1605. const std::string& fileName = source->GetFullPath();
  1606. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1607. (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
  1608. }
  1609. return hasFlags;
  1610. }
  1611. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
  1612. {
  1613. cmTarget::TargetType ttype = this->Target->GetType();
  1614. if(ttype > cmTarget::GLOBAL_TARGET)
  1615. {
  1616. return;
  1617. }
  1618. this->WriteString("<PropertyGroup>\n", 2);
  1619. this->WriteString("<_ProjectFileVersion>10.0.20506.1"
  1620. "</_ProjectFileVersion>\n", 3);
  1621. for(std::vector<std::string>::const_iterator
  1622. config = this->Configurations.begin();
  1623. config != this->Configurations.end(); ++config)
  1624. {
  1625. if(ttype >= cmTarget::UTILITY)
  1626. {
  1627. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1628. *this->BuildFileStream
  1629. << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
  1630. << "</IntDir>\n";
  1631. }
  1632. else
  1633. {
  1634. std::string intermediateDir = this->LocalGenerator->
  1635. GetTargetDirectory(*this->Target);
  1636. intermediateDir += "/";
  1637. intermediateDir += *config;
  1638. intermediateDir += "/";
  1639. std::string outDir;
  1640. std::string targetNameFull;
  1641. if(ttype == cmTarget::OBJECT_LIBRARY)
  1642. {
  1643. outDir = intermediateDir;
  1644. targetNameFull = this->Target->GetName();
  1645. targetNameFull += ".lib";
  1646. }
  1647. else
  1648. {
  1649. outDir = this->Target->GetDirectory(config->c_str()) + "/";
  1650. targetNameFull = this->Target->GetFullName(config->c_str());
  1651. }
  1652. this->ConvertToWindowsSlash(intermediateDir);
  1653. this->ConvertToWindowsSlash(outDir);
  1654. this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
  1655. *this->BuildFileStream << cmVS10EscapeXML(outDir)
  1656. << "</OutDir>\n";
  1657. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1658. *this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
  1659. << "</IntDir>\n";
  1660. std::string name =
  1661. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  1662. this->WritePlatformConfigTag("TargetName", config->c_str(), 3);
  1663. *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n";
  1664. std::string ext =
  1665. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  1666. if(ext.empty())
  1667. {
  1668. // An empty TargetExt causes a default extension to be used.
  1669. // A single "." appears to be treated as an empty extension.
  1670. ext = ".";
  1671. }
  1672. this->WritePlatformConfigTag("TargetExt", config->c_str(), 3);
  1673. *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n";
  1674. this->OutputLinkIncremental(*config);
  1675. }
  1676. }
  1677. this->WriteString("</PropertyGroup>\n", 2);
  1678. }
  1679. void
  1680. cmVisualStudio10TargetGenerator::
  1681. OutputLinkIncremental(std::string const& configName)
  1682. {
  1683. if(!this->MSTools)
  1684. {
  1685. return;
  1686. }
  1687. // static libraries and things greater than modules do not need
  1688. // to set this option
  1689. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
  1690. || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
  1691. {
  1692. return;
  1693. }
  1694. Options& linkOptions = *(this->LinkOptions[configName]);
  1695. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  1696. this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 3);
  1697. *this->BuildFileStream << (incremental?incremental:"true")
  1698. << "</LinkIncremental>\n";
  1699. linkOptions.RemoveFlag("LinkIncremental");
  1700. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  1701. this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 3);
  1702. *this->BuildFileStream << (manifest?manifest:"true")
  1703. << "</GenerateManifest>\n";
  1704. linkOptions.RemoveFlag("GenerateManifest");
  1705. // Some link options belong here. Use them now and remove them so that
  1706. // WriteLinkOptions does not use them.
  1707. const char* flags[] = {
  1708. "LinkDelaySign",
  1709. "LinkKeyFile",
  1710. 0};
  1711. for(const char** f = flags; *f; ++f)
  1712. {
  1713. const char* flag = *f;
  1714. if(const char* value = linkOptions.GetFlag(flag))
  1715. {
  1716. this->WritePlatformConfigTag(flag, configName.c_str(), 3);
  1717. *this->BuildFileStream << value << "</" << flag << ">\n";
  1718. linkOptions.RemoveFlag(flag);
  1719. }
  1720. }
  1721. }
  1722. //----------------------------------------------------------------------------
  1723. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  1724. {
  1725. for(std::vector<std::string>::const_iterator
  1726. i = this->Configurations.begin();
  1727. i != this->Configurations.end(); ++i)
  1728. {
  1729. if(!this->ComputeClOptions(*i))
  1730. {
  1731. return false;
  1732. }
  1733. }
  1734. return true;
  1735. }
  1736. //----------------------------------------------------------------------------
  1737. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  1738. std::string const& configName)
  1739. {
  1740. // much of this was copied from here:
  1741. // copied from cmLocalVisualStudio7Generator.cxx 805
  1742. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  1743. cmsys::auto_ptr<Options> pOptions(
  1744. new Options(this->LocalGenerator, Options::Compiler,
  1745. this->GetClFlagTable()));
  1746. Options& clOptions = *pOptions;
  1747. std::string flags;
  1748. const std::string& linkLanguage =
  1749. this->Target->GetLinkerLanguage(configName.c_str());
  1750. if(linkLanguage.empty())
  1751. {
  1752. cmSystemTools::Error
  1753. ("CMake can not determine linker language for target: ",
  1754. this->Name.c_str());
  1755. return false;
  1756. }
  1757. if(linkLanguage == "C" || linkLanguage == "CXX"
  1758. || linkLanguage == "Fortran")
  1759. {
  1760. std::string baseFlagVar = "CMAKE_";
  1761. baseFlagVar += linkLanguage;
  1762. baseFlagVar += "_FLAGS";
  1763. flags = this->
  1764. Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
  1765. std::string flagVar = baseFlagVar + std::string("_") +
  1766. cmSystemTools::UpperCase(configName);
  1767. flags += " ";
  1768. flags += this->
  1769. Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
  1770. }
  1771. // set the correct language
  1772. if(linkLanguage == "C")
  1773. {
  1774. clOptions.AddFlag("CompileAs", "CompileAsC");
  1775. }
  1776. if(linkLanguage == "CXX")
  1777. {
  1778. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  1779. }
  1780. this->LocalGenerator->AddCompileOptions(flags, this->Target,
  1781. linkLanguage, configName.c_str());
  1782. // Get preprocessor definitions for this directory.
  1783. std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags();
  1784. if(this->MSTools)
  1785. {
  1786. clOptions.FixExceptionHandlingDefault();
  1787. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  1788. std::string asmLocation = configName + "/";
  1789. clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  1790. }
  1791. clOptions.Parse(flags.c_str());
  1792. clOptions.Parse(defineFlags.c_str());
  1793. std::vector<std::string> targetDefines;
  1794. this->Target->GetCompileDefinitions(targetDefines,
  1795. configName.c_str(), "CXX");
  1796. clOptions.AddDefines(targetDefines);
  1797. if(this->MSTools)
  1798. {
  1799. clOptions.SetVerboseMakefile(
  1800. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  1801. }
  1802. // Add a definition for the configuration name.
  1803. std::string configDefine = "CMAKE_INTDIR=\"";
  1804. configDefine += configName;
  1805. configDefine += "\"";
  1806. clOptions.AddDefine(configDefine);
  1807. if(const char* exportMacro = this->Target->GetExportMacro())
  1808. {
  1809. clOptions.AddDefine(exportMacro);
  1810. }
  1811. if (this->MSTools)
  1812. {
  1813. // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
  1814. if (this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
  1815. {
  1816. clOptions.AddFlag("CompileAsWinRT", "true");
  1817. // For WinRT components, add the _WINRT_DLL define to produce a lib
  1818. if (this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  1819. this->Target->GetType() == cmTarget::MODULE_LIBRARY )
  1820. {
  1821. clOptions.AddDefine("_WINRT_DLL");
  1822. }
  1823. }
  1824. else if (this->GlobalGenerator->TargetsWindowsStore() ||
  1825. this->GlobalGenerator->TargetsWindowsPhone())
  1826. {
  1827. if (!clOptions.IsWinRt())
  1828. {
  1829. clOptions.AddFlag("CompileAsWinRT", "false");
  1830. }
  1831. }
  1832. if(const char* winRT = clOptions.GetFlag("CompileAsWinRT"))
  1833. {
  1834. if(cmSystemTools::IsOn(winRT))
  1835. {
  1836. this->TargetCompileAsWinRT = true;
  1837. }
  1838. }
  1839. }
  1840. this->ClOptions[configName] = pOptions.release();
  1841. return true;
  1842. }
  1843. //----------------------------------------------------------------------------
  1844. void cmVisualStudio10TargetGenerator::WriteClOptions(
  1845. std::string const& configName,
  1846. std::vector<std::string> const& includes)
  1847. {
  1848. Options& clOptions = *(this->ClOptions[configName]);
  1849. this->WriteString("<ClCompile>\n", 2);
  1850. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1851. clOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  1852. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1853. "%(AdditionalIncludeDirectories)");
  1854. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1855. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1856. "\n", "CXX");
  1857. if(this->MSTools)
  1858. {
  1859. this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
  1860. // If not in debug mode, write the DebugInformationFormat field
  1861. // without value so PDBs don't get generated uselessly.
  1862. if(!clOptions.IsDebug())
  1863. {
  1864. this->WriteString("<DebugInformationFormat>"
  1865. "</DebugInformationFormat>\n", 3);
  1866. }
  1867. // Specify the compiler program database file if configured.
  1868. std::string pdb = this->Target->GetCompilePDBPath(configName.c_str());
  1869. if(!pdb.empty())
  1870. {
  1871. this->ConvertToWindowsSlash(pdb);
  1872. this->WriteString("<ProgramDataBaseFileName>", 3);
  1873. *this->BuildFileStream << cmVS10EscapeXML(pdb)
  1874. << "</ProgramDataBaseFileName>\n";
  1875. }
  1876. }
  1877. this->WriteString("</ClCompile>\n", 2);
  1878. }
  1879. //----------------------------------------------------------------------------
  1880. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  1881. {
  1882. for(std::vector<std::string>::const_iterator
  1883. i = this->Configurations.begin();
  1884. i != this->Configurations.end(); ++i)
  1885. {
  1886. if(!this->ComputeRcOptions(*i))
  1887. {
  1888. return false;
  1889. }
  1890. }
  1891. return true;
  1892. }
  1893. //----------------------------------------------------------------------------
  1894. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  1895. std::string const& configName)
  1896. {
  1897. cmsys::auto_ptr<Options> pOptions(
  1898. new Options(this->LocalGenerator, Options::ResourceCompiler,
  1899. this->GetRcFlagTable()));
  1900. Options& rcOptions = *pOptions;
  1901. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1902. std::string rcConfigFlagsVar = std::string("CMAKE_RC_FLAGS_") + CONFIG;
  1903. std::string flags =
  1904. std::string(this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS")) +
  1905. std::string(" ") +
  1906. std::string(this->Makefile->GetSafeDefinition(rcConfigFlagsVar));
  1907. rcOptions.Parse(flags.c_str());
  1908. this->RcOptions[configName] = pOptions.release();
  1909. return true;
  1910. }
  1911. void cmVisualStudio10TargetGenerator::
  1912. WriteRCOptions(std::string const& configName,
  1913. std::vector<std::string> const & includes)
  1914. {
  1915. if(!this->MSTools)
  1916. {
  1917. return;
  1918. }
  1919. this->WriteString("<ResourceCompile>\n", 2);
  1920. // Preprocessor definitions and includes are shared with clOptions.
  1921. Options& clOptions = *(this->ClOptions[configName]);
  1922. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1923. "\n", "RC");
  1924. Options& rcOptions = *(this->RcOptions[configName]);
  1925. rcOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  1926. rcOptions.AppendFlag("AdditionalIncludeDirectories",
  1927. "%(AdditionalIncludeDirectories)");
  1928. rcOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1929. rcOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1930. this->WriteString("</ResourceCompile>\n", 2);
  1931. }
  1932. //----------------------------------------------------------------------------
  1933. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
  1934. {
  1935. if(!this->GlobalGenerator->IsMasmEnabled())
  1936. {
  1937. return true;
  1938. }
  1939. for(std::vector<std::string>::const_iterator
  1940. i = this->Configurations.begin();
  1941. i != this->Configurations.end(); ++i)
  1942. {
  1943. if(!this->ComputeMasmOptions(*i))
  1944. {
  1945. return false;
  1946. }
  1947. }
  1948. return true;
  1949. }
  1950. //----------------------------------------------------------------------------
  1951. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
  1952. std::string const& configName)
  1953. {
  1954. cmsys::auto_ptr<Options> pOptions(
  1955. new Options(this->LocalGenerator, Options::MasmCompiler,
  1956. this->GetMasmFlagTable()));
  1957. Options& masmOptions = *pOptions;
  1958. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1959. std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG;
  1960. std::string flags =
  1961. std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS")) +
  1962. std::string(" ") +
  1963. std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
  1964. masmOptions.Parse(flags.c_str());
  1965. this->MasmOptions[configName] = pOptions.release();
  1966. return true;
  1967. }
  1968. void cmVisualStudio10TargetGenerator::
  1969. WriteMasmOptions(std::string const& configName,
  1970. std::vector<std::string> const& includes)
  1971. {
  1972. if(!this->MSTools || !this->GlobalGenerator->IsMasmEnabled())
  1973. {
  1974. return;
  1975. }
  1976. this->WriteString("<MASM>\n", 2);
  1977. // Preprocessor definitions and includes are shared with clOptions.
  1978. Options& clOptions = *(this->ClOptions[configName]);
  1979. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1980. "\n", "ASM_MASM");
  1981. Options& masmOptions = *(this->MasmOptions[configName]);
  1982. masmOptions.AppendFlag("IncludePaths", includes);
  1983. masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)");
  1984. masmOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1985. masmOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1986. this->WriteString("</MASM>\n", 2);
  1987. }
  1988. void
  1989. cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
  1990. {
  1991. if(this->Target->GetType() != cmTarget::STATIC_LIBRARY &&
  1992. this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
  1993. {
  1994. return;
  1995. }
  1996. std::string libflags;
  1997. this->LocalGenerator->GetStaticLibraryFlags(libflags,
  1998. cmSystemTools::UpperCase(config), this->Target);
  1999. if(!libflags.empty())
  2000. {
  2001. this->WriteString("<Lib>\n", 2);
  2002. cmVisualStudioGeneratorOptions
  2003. libOptions(this->LocalGenerator,
  2004. cmVisualStudioGeneratorOptions::Linker,
  2005. this->GetLibFlagTable(), 0, this);
  2006. libOptions.Parse(libflags.c_str());
  2007. libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2008. libOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2009. this->WriteString("</Lib>\n", 2);
  2010. }
  2011. // We cannot generate metadata for static libraries. WindowsPhone
  2012. // and WindowsStore tools look at GenerateWindowsMetadata in the
  2013. // Link tool options even for static libraries.
  2014. if(this->GlobalGenerator->TargetsWindowsPhone() ||
  2015. this->GlobalGenerator->TargetsWindowsStore())
  2016. {
  2017. this->WriteString("<Link>\n", 2);
  2018. this->WriteString("<GenerateWindowsMetadata>false"
  2019. "</GenerateWindowsMetadata>\n", 3);
  2020. this->WriteString("</Link>\n", 2);
  2021. }
  2022. }
  2023. //----------------------------------------------------------------------------
  2024. void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
  2025. std::string const&)
  2026. {
  2027. // Look through the sources for AndroidManifest.xml and use
  2028. // its location as the root source directory.
  2029. std::string rootDir = this->Makefile->GetCurrentSourceDirectory();
  2030. {
  2031. std::vector<cmSourceFile const*> extraSources;
  2032. this->GeneratorTarget->GetExtraSources(extraSources, "");
  2033. for(std::vector<cmSourceFile const*>::const_iterator si =
  2034. extraSources.begin(); si != extraSources.end(); ++si)
  2035. {
  2036. if("androidmanifest.xml" == cmSystemTools::LowerCase(
  2037. (*si)->GetLocation().GetName()))
  2038. {
  2039. rootDir = (*si)->GetLocation().GetDirectory();
  2040. break;
  2041. }
  2042. }
  2043. }
  2044. // Tell MSBuild to launch Ant.
  2045. {
  2046. std::string antBuildPath = rootDir;
  2047. this->WriteString("<AntBuild>\n", 2);
  2048. this->WriteString("<AntBuildPath>", 3);
  2049. this->ConvertToWindowsSlash(antBuildPath);
  2050. (*this->BuildFileStream) <<
  2051. cmVS10EscapeXML(antBuildPath) << "</AntBuildPath>\n";
  2052. }
  2053. {
  2054. std::string manifest_xml = rootDir + "/AndroidManifest.xml";
  2055. this->ConvertToWindowsSlash(manifest_xml);
  2056. this->WriteString("<AndroidManifestLocation>", 3);
  2057. (*this->BuildFileStream) <<
  2058. cmVS10EscapeXML(manifest_xml) << "</AndroidManifestLocation>\n";
  2059. }
  2060. this->WriteString("</AntBuild>\n", 2);
  2061. }
  2062. //----------------------------------------------------------------------------
  2063. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  2064. {
  2065. if(this->Target->GetType() == cmTarget::EXECUTABLE ||
  2066. this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  2067. this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  2068. {
  2069. for(std::vector<std::string>::const_iterator
  2070. i = this->Configurations.begin();
  2071. i != this->Configurations.end(); ++i)
  2072. {
  2073. if(!this->ComputeLinkOptions(*i))
  2074. {
  2075. return false;
  2076. }
  2077. }
  2078. }
  2079. return true;
  2080. }
  2081. //----------------------------------------------------------------------------
  2082. bool
  2083. cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
  2084. {
  2085. cmsys::auto_ptr<Options> pOptions(
  2086. new Options(this->LocalGenerator, Options::Linker,
  2087. this->GetLinkFlagTable(), 0, this));
  2088. Options& linkOptions = *pOptions;
  2089. const std::string& linkLanguage =
  2090. this->Target->GetLinkerLanguage(config.c_str());
  2091. if(linkLanguage.empty())
  2092. {
  2093. cmSystemTools::Error
  2094. ("CMake can not determine linker language for target: ",
  2095. this->Name.c_str());
  2096. return false;
  2097. }
  2098. std::string CONFIG = cmSystemTools::UpperCase(config);
  2099. const char* linkType = "SHARED";
  2100. if(this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  2101. {
  2102. linkType = "MODULE";
  2103. }
  2104. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  2105. {
  2106. linkType = "EXE";
  2107. }
  2108. std::string flags;
  2109. std::string linkFlagVarBase = "CMAKE_";
  2110. linkFlagVarBase += linkType;
  2111. linkFlagVarBase += "_LINKER_FLAGS";
  2112. flags += " ";
  2113. flags += this->
  2114. Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
  2115. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  2116. flags += " ";
  2117. flags += this->
  2118. Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
  2119. const char* targetLinkFlags = this->Target->GetProperty("LINK_FLAGS");
  2120. if(targetLinkFlags)
  2121. {
  2122. flags += " ";
  2123. flags += targetLinkFlags;
  2124. }
  2125. std::string flagsProp = "LINK_FLAGS_";
  2126. flagsProp += CONFIG;
  2127. if(const char* flagsConfig = this->Target->GetProperty(flagsProp.c_str()))
  2128. {
  2129. flags += " ";
  2130. flags += flagsConfig;
  2131. }
  2132. std::string standardLibsVar = "CMAKE_";
  2133. standardLibsVar += linkLanguage;
  2134. standardLibsVar += "_STANDARD_LIBRARIES";
  2135. std::string
  2136. libs = this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  2137. // Remove trailing spaces from libs
  2138. std::string::size_type pos = libs.size()-1;
  2139. if(libs.size() != 0)
  2140. {
  2141. while(libs[pos] == ' ')
  2142. {
  2143. pos--;
  2144. }
  2145. }
  2146. if(pos != libs.size()-1)
  2147. {
  2148. libs = libs.substr(0, pos+1);
  2149. }
  2150. // Replace spaces in libs with ;
  2151. cmSystemTools::ReplaceString(libs, " ", ";");
  2152. std::vector<std::string> libVec;
  2153. cmSystemTools::ExpandListArgument(libs, libVec);
  2154. cmComputeLinkInformation* pcli =
  2155. this->Target->GetLinkInformation(config.c_str());
  2156. if(!pcli)
  2157. {
  2158. cmSystemTools::Error
  2159. ("CMake can not compute cmComputeLinkInformation for target: ",
  2160. this->Name.c_str());
  2161. return false;
  2162. }
  2163. // add the libraries for the target to libs string
  2164. cmComputeLinkInformation& cli = *pcli;
  2165. this->AddLibraries(cli, libVec);
  2166. linkOptions.AddFlag("AdditionalDependencies", libVec);
  2167. std::vector<std::string> const& ldirs = cli.GetDirectories();
  2168. std::vector<std::string> linkDirs;
  2169. for(std::vector<std::string>::const_iterator d = ldirs.begin();
  2170. d != ldirs.end(); ++d)
  2171. {
  2172. // first just full path
  2173. linkDirs.push_back(*d);
  2174. // next path with configuration type Debug, Release, etc
  2175. linkDirs.push_back(*d + "/$(Configuration)");
  2176. }
  2177. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  2178. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  2179. std::string targetName;
  2180. std::string targetNameSO;
  2181. std::string targetNameFull;
  2182. std::string targetNameImport;
  2183. std::string targetNamePDB;
  2184. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  2185. {
  2186. this->Target->GetExecutableNames(targetName, targetNameFull,
  2187. targetNameImport, targetNamePDB,
  2188. config.c_str());
  2189. }
  2190. else
  2191. {
  2192. this->Target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
  2193. targetNameImport, targetNamePDB,
  2194. config.c_str());
  2195. }
  2196. if(this->MSTools)
  2197. {
  2198. linkOptions.AddFlag("Version", "");
  2199. if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
  2200. {
  2201. if (this->GlobalGenerator->TargetsWindowsCE())
  2202. {
  2203. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2204. if (this->Target->GetType() == cmTarget::EXECUTABLE)
  2205. {
  2206. if (this->ClOptions[config]->UsingUnicode())
  2207. {
  2208. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  2209. }
  2210. else
  2211. {
  2212. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  2213. }
  2214. }
  2215. }
  2216. else
  2217. {
  2218. linkOptions.AddFlag("SubSystem", "Windows");
  2219. }
  2220. }
  2221. else
  2222. {
  2223. if (this->GlobalGenerator->TargetsWindowsCE())
  2224. {
  2225. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2226. if (this->Target->GetType() == cmTarget::EXECUTABLE)
  2227. {
  2228. if (this->ClOptions[config]->UsingUnicode())
  2229. {
  2230. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  2231. }
  2232. else
  2233. {
  2234. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  2235. }
  2236. }
  2237. }
  2238. else
  2239. {
  2240. linkOptions.AddFlag("SubSystem", "Console");
  2241. };
  2242. }
  2243. if(const char* stackVal =
  2244. this->Makefile->GetDefinition("CMAKE_"+linkLanguage+"_STACK_SIZE"))
  2245. {
  2246. linkOptions.AddFlag("StackReserveSize", stackVal);
  2247. }
  2248. if(linkOptions.IsDebug() || flags.find("/debug") != flags.npos)
  2249. {
  2250. linkOptions.AddFlag("GenerateDebugInformation", "true");
  2251. }
  2252. else
  2253. {
  2254. linkOptions.AddFlag("GenerateDebugInformation", "false");
  2255. }
  2256. std::string pdb = this->Target->GetPDBDirectory(config.c_str());
  2257. pdb += "/";
  2258. pdb += targetNamePDB;
  2259. std::string imLib = this->Target->GetDirectory(config.c_str(), true);
  2260. imLib += "/";
  2261. imLib += targetNameImport;
  2262. linkOptions.AddFlag("ImportLibrary", imLib.c_str());
  2263. linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
  2264. // A Windows Runtime component uses internal .NET metadata,
  2265. // so does not have an import library.
  2266. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
  2267. {
  2268. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  2269. }
  2270. else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2271. this->GlobalGenerator->TargetsWindowsStore())
  2272. {
  2273. // WindowsPhone and WindowsStore components are in an app container
  2274. // and produce WindowsMetadata. If we are not producing a WINRT
  2275. // component, then do not generate the metadata here.
  2276. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  2277. }
  2278. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  2279. this->GlobalGenerator->GetSystemVersion() == "8.0")
  2280. {
  2281. // WindowsPhone 8.0 does not have ole32.
  2282. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  2283. }
  2284. }
  2285. else if(this->NsightTegra)
  2286. {
  2287. linkOptions.AddFlag("SoName", targetNameSO.c_str());
  2288. }
  2289. linkOptions.Parse(flags.c_str());
  2290. if(this->MSTools)
  2291. {
  2292. std::string def = this->GeneratorTarget->GetModuleDefinitionFile("");
  2293. if(!def.empty())
  2294. {
  2295. linkOptions.AddFlag("ModuleDefinitionFile", def.c_str());
  2296. }
  2297. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  2298. "%(IgnoreSpecificDefaultLibraries)");
  2299. }
  2300. this->LinkOptions[config] = pOptions.release();
  2301. return true;
  2302. }
  2303. //----------------------------------------------------------------------------
  2304. void
  2305. cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
  2306. {
  2307. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
  2308. || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
  2309. {
  2310. return;
  2311. }
  2312. Options& linkOptions = *(this->LinkOptions[config]);
  2313. this->WriteString("<Link>\n", 2);
  2314. linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2315. linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2316. this->WriteString("</Link>\n", 2);
  2317. if(!this->GlobalGenerator->NeedLinkLibraryDependencies(*this->Target))
  2318. {
  2319. this->WriteString("<ProjectReference>\n", 2);
  2320. this->WriteString(
  2321. " <LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 2);
  2322. this->WriteString("</ProjectReference>\n", 2);
  2323. }
  2324. }
  2325. void cmVisualStudio10TargetGenerator::AddLibraries(
  2326. cmComputeLinkInformation& cli,
  2327. std::vector<std::string>& libVec)
  2328. {
  2329. typedef cmComputeLinkInformation::ItemVector ItemVector;
  2330. ItemVector libs = cli.GetItems();
  2331. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  2332. {
  2333. if(l->IsPath)
  2334. {
  2335. std::string path = this->LocalGenerator->
  2336. Convert(l->Value.c_str(),
  2337. cmLocalGenerator::START_OUTPUT,
  2338. cmLocalGenerator::UNCHANGED);
  2339. this->ConvertToWindowsSlash(path);
  2340. libVec.push_back(path);
  2341. }
  2342. else if (!l->Target
  2343. || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  2344. {
  2345. libVec.push_back(l->Value);
  2346. }
  2347. }
  2348. }
  2349. void cmVisualStudio10TargetGenerator::
  2350. WriteMidlOptions(std::string const& /*config*/,
  2351. std::vector<std::string> const & includes)
  2352. {
  2353. if(!this->MSTools)
  2354. {
  2355. return;
  2356. }
  2357. // This processes *any* of the .idl files specified in the project's file
  2358. // list (and passed as the item metadata %(Filename) expressing the rule
  2359. // input filename) into output files at the per-config *build* dir
  2360. // ($(IntDir)) each.
  2361. //
  2362. // IOW, this MIDL section is intended to provide a fully generic syntax
  2363. // content suitable for most cases (read: if you get errors, then it's quite
  2364. // probable that the error is on your side of the .idl setup).
  2365. //
  2366. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  2367. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  2368. // project's file list, otherwise the compiler-side processing won't pick it
  2369. // up (for non-directory form, it ends up looking in project binary dir
  2370. // only). Perhaps there's something to be done to make this more automatic
  2371. // on the CMake side?
  2372. this->WriteString("<Midl>\n", 2);
  2373. this->WriteString("<AdditionalIncludeDirectories>", 3);
  2374. for(std::vector<std::string>::const_iterator i = includes.begin();
  2375. i != includes.end(); ++i)
  2376. {
  2377. *this->BuildFileStream << cmVS10EscapeXML(*i) << ";";
  2378. }
  2379. this->WriteString("%(AdditionalIncludeDirectories)"
  2380. "</AdditionalIncludeDirectories>\n", 0);
  2381. this->WriteString("<OutputDirectory>$(ProjectDir)/$(IntDir)"
  2382. "</OutputDirectory>\n", 3);
  2383. this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
  2384. this->WriteString(
  2385. "<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
  2386. this->WriteString(
  2387. "<InterfaceIdentifierFileName>"
  2388. "%(Filename)_i.c</InterfaceIdentifierFileName>\n", 3);
  2389. this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n",3);
  2390. this->WriteString("</Midl>\n", 2);
  2391. }
  2392. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
  2393. {
  2394. for(std::vector<std::string>::const_iterator
  2395. i = this->Configurations.begin();
  2396. i != this->Configurations.end(); ++i)
  2397. {
  2398. std::vector<std::string> includes;
  2399. this->LocalGenerator->GetIncludeDirectories(includes,
  2400. this->GeneratorTarget,
  2401. "C", i->c_str());
  2402. for(std::vector<std::string>::iterator ii = includes.begin();
  2403. ii != includes.end(); ++ii)
  2404. {
  2405. this->ConvertToWindowsSlash(*ii);
  2406. }
  2407. this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
  2408. *this->BuildFileStream << "\n";
  2409. // output cl compile flags <ClCompile></ClCompile>
  2410. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
  2411. {
  2412. this->WriteClOptions(*i, includes);
  2413. // output rc compile flags <ResourceCompile></ResourceCompile>
  2414. this->WriteRCOptions(*i, includes);
  2415. this->WriteMasmOptions(*i, includes);
  2416. }
  2417. // output midl flags <Midl></Midl>
  2418. this->WriteMidlOptions(*i, includes);
  2419. // write events
  2420. this->WriteEvents(*i);
  2421. // output link flags <Link></Link>
  2422. this->WriteLinkOptions(*i);
  2423. // output lib flags <Lib></Lib>
  2424. this->WriteLibOptions(*i);
  2425. if(this->NsightTegra &&
  2426. this->Target->GetType() == cmTarget::EXECUTABLE &&
  2427. this->Target->GetPropertyAsBool("ANDROID_GUI"))
  2428. {
  2429. this->WriteAntBuildOptions(*i);
  2430. }
  2431. this->WriteString("</ItemDefinitionGroup>\n", 1);
  2432. }
  2433. }
  2434. void
  2435. cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
  2436. {
  2437. this->WriteEvent("PreLinkEvent",
  2438. this->Target->GetPreLinkCommands(), configName);
  2439. this->WriteEvent("PreBuildEvent",
  2440. this->Target->GetPreBuildCommands(), configName);
  2441. this->WriteEvent("PostBuildEvent",
  2442. this->Target->GetPostBuildCommands(), configName);
  2443. }
  2444. void cmVisualStudio10TargetGenerator::WriteEvent(
  2445. const char* name,
  2446. std::vector<cmCustomCommand> const& commands,
  2447. std::string const& configName)
  2448. {
  2449. if(commands.size() == 0)
  2450. {
  2451. return;
  2452. }
  2453. this->WriteString("<", 2);
  2454. (*this->BuildFileStream ) << name << ">\n";
  2455. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  2456. std::string script;
  2457. const char* pre = "";
  2458. std::string comment;
  2459. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  2460. i != commands.end(); ++i)
  2461. {
  2462. cmCustomCommandGenerator ccg(*i, configName, this->Makefile);
  2463. comment += pre;
  2464. comment += lg->ConstructComment(ccg);
  2465. script += pre;
  2466. pre = "\n";
  2467. script += cmVS10EscapeXML(lg->ConstructScript(ccg));
  2468. }
  2469. comment = cmVS10EscapeComment(comment);
  2470. this->WriteString("<Message>",3);
  2471. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  2472. this->WriteString("<Command>", 3);
  2473. (*this->BuildFileStream ) << script;
  2474. (*this->BuildFileStream ) << "</Command>" << "\n";
  2475. this->WriteString("</", 2);
  2476. (*this->BuildFileStream ) << name << ">\n";
  2477. }
  2478. void cmVisualStudio10TargetGenerator::WriteProjectReferences()
  2479. {
  2480. cmGlobalGenerator::TargetDependSet const& unordered
  2481. = this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  2482. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  2483. OrderedTargetDependSet;
  2484. OrderedTargetDependSet depends(unordered);
  2485. this->WriteString("<ItemGroup>\n", 1);
  2486. for( OrderedTargetDependSet::const_iterator i = depends.begin();
  2487. i != depends.end(); ++i)
  2488. {
  2489. cmTarget const* dt = (*i)->Target;
  2490. if(dt->GetType() == cmTarget::INTERFACE_LIBRARY)
  2491. {
  2492. continue;
  2493. }
  2494. // skip fortran targets as they can not be processed by MSBuild
  2495. // the only reference will be in the .sln file
  2496. if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  2497. ->TargetIsFortranOnly(*dt))
  2498. {
  2499. continue;
  2500. }
  2501. this->WriteString("<ProjectReference Include=\"", 2);
  2502. cmMakefile* mf = dt->GetMakefile();
  2503. std::string name = dt->GetName();
  2504. std::string path;
  2505. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  2506. if(p)
  2507. {
  2508. path = p;
  2509. }
  2510. else
  2511. {
  2512. path = mf->GetCurrentBinaryDirectory();
  2513. path += "/";
  2514. path += dt->GetName();
  2515. path += ".vcxproj";
  2516. }
  2517. (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n";
  2518. this->WriteString("<Project>", 3);
  2519. (*this->BuildFileStream)
  2520. << this->GlobalGenerator->GetGUID(name.c_str())
  2521. << "</Project>\n";
  2522. this->WriteString("</ProjectReference>\n", 2);
  2523. }
  2524. this->WriteString("</ItemGroup>\n", 1);
  2525. }
  2526. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
  2527. {
  2528. if((this->GlobalGenerator->TargetsWindowsStore() ||
  2529. this->GlobalGenerator->TargetsWindowsPhone())
  2530. && (cmTarget::EXECUTABLE == this->Target->GetType()))
  2531. {
  2532. std::string pfxFile;
  2533. std::vector<cmSourceFile const*> certificates;
  2534. this->GeneratorTarget->GetCertificates(certificates, "");
  2535. for(std::vector<cmSourceFile const*>::const_iterator si =
  2536. certificates.begin(); si != certificates.end(); ++si)
  2537. {
  2538. pfxFile = this->ConvertPath((*si)->GetFullPath(), false);
  2539. this->ConvertToWindowsSlash(pfxFile);
  2540. break;
  2541. }
  2542. if(this->IsMissingFiles &&
  2543. !(this->GlobalGenerator->TargetsWindowsPhone() &&
  2544. this->GlobalGenerator->GetSystemVersion() == "8.0"))
  2545. {
  2546. // Move the manifest to a project directory to avoid clashes
  2547. std::string artifactDir =
  2548. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2549. this->ConvertToWindowsSlash(artifactDir);
  2550. this->WriteString("<PropertyGroup>\n", 1);
  2551. this->WriteString("<AppxPackageArtifactsDir>", 2);
  2552. (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir) <<
  2553. "\\</AppxPackageArtifactsDir>\n";
  2554. this->WriteString("<ProjectPriFullPath>"
  2555. "$(TargetDir)resources.pri</ProjectPriFullPath>", 2);
  2556. // If we are missing files and we don't have a certificate and
  2557. // aren't targeting WP8.0, add a default certificate
  2558. if(pfxFile.empty())
  2559. {
  2560. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  2561. "/Templates/Windows";
  2562. pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  2563. cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
  2564. pfxFile, false);
  2565. this->ConvertToWindowsSlash(pfxFile);
  2566. this->AddedFiles.push_back(pfxFile);
  2567. }
  2568. this->WriteString("<", 2);
  2569. (*this->BuildFileStream) << "PackageCertificateKeyFile>"
  2570. << pfxFile << "</PackageCertificateKeyFile>\n";
  2571. this->WriteString("</PropertyGroup>\n", 1);
  2572. }
  2573. else if(!pfxFile.empty())
  2574. {
  2575. this->WriteString("<PropertyGroup>\n", 1);
  2576. this->WriteString("<", 2);
  2577. (*this->BuildFileStream) << "PackageCertificateKeyFile>"
  2578. << pfxFile << "</PackageCertificateKeyFile>\n";
  2579. this->WriteString("</PropertyGroup>\n", 1);
  2580. }
  2581. }
  2582. }
  2583. bool cmVisualStudio10TargetGenerator::
  2584. IsResxHeader(const std::string& headerFile)
  2585. {
  2586. std::set<std::string> expectedResxHeaders;
  2587. this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
  2588. std::set<std::string>::const_iterator it =
  2589. expectedResxHeaders.find(headerFile);
  2590. return it != expectedResxHeaders.end();
  2591. }
  2592. bool cmVisualStudio10TargetGenerator::
  2593. IsXamlHeader(const std::string& headerFile)
  2594. {
  2595. std::set<std::string> expectedXamlHeaders;
  2596. this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
  2597. std::set<std::string>::const_iterator it =
  2598. expectedXamlHeaders.find(headerFile);
  2599. return it != expectedXamlHeaders.end();
  2600. }
  2601. bool cmVisualStudio10TargetGenerator::
  2602. IsXamlSource(const std::string& sourceFile)
  2603. {
  2604. std::set<std::string> expectedXamlSources;
  2605. this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
  2606. std::set<std::string>::const_iterator it =
  2607. expectedXamlSources.find(sourceFile);
  2608. return it != expectedXamlSources.end();
  2609. }
  2610. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
  2611. {
  2612. bool isAppContainer = false;
  2613. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  2614. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  2615. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2616. if(isWindowsPhone || isWindowsStore)
  2617. {
  2618. this->WriteString("<ApplicationType>", 2);
  2619. (*this->BuildFileStream) << (isWindowsPhone ?
  2620. "Windows Phone" : "Windows Store")
  2621. << "</ApplicationType>\n";
  2622. this->WriteString("<ApplicationTypeRevision>", 2);
  2623. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  2624. << "</ApplicationTypeRevision>\n";
  2625. this->WriteString("<DefaultLanguage>en-US"
  2626. "</DefaultLanguage>\n", 2);
  2627. if(v == "8.1")
  2628. {
  2629. // Visual Studio 12.0 is necessary for building 8.1 apps
  2630. this->WriteString("<MinimumVisualStudioVersion>12.0"
  2631. "</MinimumVisualStudioVersion>\n", 2);
  2632. if (this->Target->GetType() < cmTarget::UTILITY)
  2633. {
  2634. isAppContainer = true;
  2635. }
  2636. }
  2637. else if (v == "8.0")
  2638. {
  2639. // Visual Studio 11.0 is necessary for building 8.0 apps
  2640. this->WriteString("<MinimumVisualStudioVersion>11.0"
  2641. "</MinimumVisualStudioVersion>\n", 2);
  2642. if (isWindowsStore && this->Target->GetType() < cmTarget::UTILITY)
  2643. {
  2644. isAppContainer = true;
  2645. }
  2646. else if (isWindowsPhone &&
  2647. this->Target->GetType() == cmTarget::EXECUTABLE)
  2648. {
  2649. this->WriteString("<XapOutputs>true</XapOutputs>\n", 2);
  2650. this->WriteString("<XapFilename>", 2);
  2651. (*this->BuildFileStream) << cmVS10EscapeXML(this->Name.c_str()) <<
  2652. "_$(Configuration)_$(Platform).xap</XapFilename>\n";
  2653. }
  2654. }
  2655. }
  2656. if(isAppContainer)
  2657. {
  2658. this->WriteString("<AppContainerApplication>true"
  2659. "</AppContainerApplication>\n", 2);
  2660. }
  2661. else if (this->Platform == "ARM")
  2662. {
  2663. this->WriteString("<WindowsSDKDesktopARMSupport>true"
  2664. "</WindowsSDKDesktopARMSupport>\n", 2);
  2665. }
  2666. }
  2667. void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
  2668. {
  2669. // For Windows and Windows Phone executables, we will assume that if a
  2670. // manifest is not present that we need to add all the necessary files
  2671. if (this->Target->GetType() == cmTarget::EXECUTABLE)
  2672. {
  2673. std::vector<cmSourceFile const*> manifestSources;
  2674. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  2675. {
  2676. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2677. if(this->GlobalGenerator->TargetsWindowsPhone())
  2678. {
  2679. if (v == "8.0")
  2680. {
  2681. // Look through the sources for WMAppManifest.xml
  2682. std::vector<cmSourceFile const*> extraSources;
  2683. this->GeneratorTarget->GetExtraSources(extraSources, "");
  2684. bool foundManifest = false;
  2685. for(std::vector<cmSourceFile const*>::const_iterator si =
  2686. extraSources.begin(); si != extraSources.end(); ++si)
  2687. {
  2688. // Need to do a lowercase comparison on the filename
  2689. if("wmappmanifest.xml" == cmSystemTools::LowerCase(
  2690. (*si)->GetLocation().GetName()))
  2691. {
  2692. foundManifest = true;
  2693. break;
  2694. }
  2695. }
  2696. if (!foundManifest)
  2697. {
  2698. this->IsMissingFiles = true;
  2699. }
  2700. }
  2701. else if (v == "8.1")
  2702. {
  2703. if(manifestSources.empty())
  2704. {
  2705. this->IsMissingFiles = true;
  2706. }
  2707. }
  2708. }
  2709. else if (this->GlobalGenerator->TargetsWindowsStore())
  2710. {
  2711. if (manifestSources.empty())
  2712. {
  2713. if (v == "8.0")
  2714. {
  2715. this->IsMissingFiles = true;
  2716. }
  2717. else if (v == "8.1")
  2718. {
  2719. this->IsMissingFiles = true;
  2720. }
  2721. }
  2722. }
  2723. }
  2724. }
  2725. }
  2726. void cmVisualStudio10TargetGenerator::WriteMissingFiles()
  2727. {
  2728. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2729. if(this->GlobalGenerator->TargetsWindowsPhone())
  2730. {
  2731. if (v == "8.0")
  2732. {
  2733. this->WriteMissingFilesWP80();
  2734. }
  2735. else if (v == "8.1")
  2736. {
  2737. this->WriteMissingFilesWP81();
  2738. }
  2739. }
  2740. else if (this->GlobalGenerator->TargetsWindowsStore())
  2741. {
  2742. if (v == "8.0")
  2743. {
  2744. this->WriteMissingFilesWS80();
  2745. }
  2746. else if (v == "8.1")
  2747. {
  2748. this->WriteMissingFilesWS81();
  2749. }
  2750. }
  2751. }
  2752. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
  2753. {
  2754. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  2755. "/Templates/Windows";
  2756. // For WP80, the manifest needs to be in the same folder as the project
  2757. // this can cause an overwrite problem if projects aren't organized in
  2758. // folders
  2759. std::string manifestFile = this->Makefile->GetCurrentBinaryDirectory() +
  2760. std::string("/WMAppManifest.xml");
  2761. std::string artifactDir =
  2762. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2763. this->ConvertToWindowsSlash(artifactDir);
  2764. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2765. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  2766. cmGeneratedFileStream fout(manifestFile.c_str());
  2767. fout.SetCopyIfDifferent(true);
  2768. fout <<
  2769. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2770. "<Deployment"
  2771. " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
  2772. " AppPlatformVersion=\"8.0\">\n"
  2773. "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
  2774. "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
  2775. " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
  2776. " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
  2777. " Description=\"Default CMake App\" Publisher=\"CMake\""
  2778. " PublisherID=\"{" << this->GUID << "}\">\n"
  2779. "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
  2780. << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
  2781. "\t\t<Capabilities/>\n"
  2782. "\t\t<Tasks>\n"
  2783. "\t\t\t<DefaultTask Name=\"_default\""
  2784. " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
  2785. "\t\t</Tasks>\n"
  2786. "\t\t<Tokens>\n"
  2787. "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
  2788. " TaskName=\"_default\">\n"
  2789. "\t\t\t\t<TemplateFlip>\n"
  2790. "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
  2791. << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
  2792. "\t\t\t\t\t<Count>0</Count>\n"
  2793. "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
  2794. << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
  2795. "\t\t\t\t</TemplateFlip>\n"
  2796. "\t\t\t</PrimaryToken>\n"
  2797. "\t\t</Tokens>\n"
  2798. "\t\t<ScreenResolutions>\n"
  2799. "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
  2800. "\t\t</ScreenResolutions>\n"
  2801. "\t</App>\n"
  2802. "</Deployment>\n";
  2803. std::string sourceFile = this->ConvertPath(manifestFile, false);
  2804. this->ConvertToWindowsSlash(sourceFile);
  2805. this->WriteString("<Xml Include=\"", 2);
  2806. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  2807. this->WriteString("<SubType>Designer</SubType>\n", 3);
  2808. this->WriteString("</Xml>\n", 2);
  2809. this->AddedFiles.push_back(sourceFile);
  2810. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  2811. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png",
  2812. smallLogo, false);
  2813. this->ConvertToWindowsSlash(smallLogo);
  2814. this->WriteString("<Image Include=\"", 2);
  2815. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  2816. this->AddedFiles.push_back(smallLogo);
  2817. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  2818. cmSystemTools::CopyAFile(templateFolder + "/Logo.png",
  2819. logo, false);
  2820. this->ConvertToWindowsSlash(logo);
  2821. this->WriteString("<Image Include=\"", 2);
  2822. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  2823. this->AddedFiles.push_back(logo);
  2824. std::string applicationIcon =
  2825. this->DefaultArtifactDir + "/ApplicationIcon.png";
  2826. cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
  2827. applicationIcon, false);
  2828. this->ConvertToWindowsSlash(applicationIcon);
  2829. this->WriteString("<Image Include=\"", 2);
  2830. (*this->BuildFileStream) << cmVS10EscapeXML(applicationIcon) << "\" />\n";
  2831. this->AddedFiles.push_back(applicationIcon);
  2832. }
  2833. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
  2834. {
  2835. std::string manifestFile =
  2836. this->DefaultArtifactDir + "/package.appxManifest";
  2837. std::string artifactDir =
  2838. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2839. this->ConvertToWindowsSlash(artifactDir);
  2840. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2841. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  2842. cmGeneratedFileStream fout(manifestFile.c_str());
  2843. fout.SetCopyIfDifferent(true);
  2844. fout <<
  2845. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2846. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  2847. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
  2848. " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
  2849. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  2850. " Version=\"1.0.0.0\" />\n"
  2851. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
  2852. " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  2853. "\t<Properties>\n"
  2854. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  2855. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  2856. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  2857. "\t</Properties>\n"
  2858. "\t<Prerequisites>\n"
  2859. "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
  2860. "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
  2861. "\t</Prerequisites>\n"
  2862. "\t<Resources>\n"
  2863. "\t\t<Resource Language=\"x-generate\" />\n"
  2864. "\t</Resources>\n"
  2865. "\t<Applications>\n"
  2866. "\t\t<Application Id=\"App\""
  2867. " Executable=\"" << targetNameXML << ".exe\""
  2868. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  2869. "\t\t\t<m2:VisualElements\n"
  2870. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  2871. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  2872. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  2873. "\t\t\t\tForegroundText=\"light\"\n"
  2874. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  2875. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  2876. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  2877. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  2878. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  2879. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  2880. "\t\t\t\t</m2:DefaultTile>\n"
  2881. "\t\t\t\t<m2:SplashScreen"
  2882. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  2883. "\t\t\t</m2:VisualElements>\n"
  2884. "\t\t</Application>\n"
  2885. "\t</Applications>\n"
  2886. "</Package>\n";
  2887. this->WriteCommonMissingFiles(manifestFile);
  2888. }
  2889. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
  2890. {
  2891. std::string manifestFile =
  2892. this->DefaultArtifactDir + "/package.appxManifest";
  2893. std::string artifactDir =
  2894. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2895. this->ConvertToWindowsSlash(artifactDir);
  2896. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2897. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  2898. cmGeneratedFileStream fout(manifestFile.c_str());
  2899. fout.SetCopyIfDifferent(true);
  2900. fout <<
  2901. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2902. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
  2903. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  2904. " Version=\"1.0.0.0\" />\n"
  2905. "\t<Properties>\n"
  2906. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  2907. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  2908. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  2909. "\t</Properties>\n"
  2910. "\t<Prerequisites>\n"
  2911. "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
  2912. "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
  2913. "\t</Prerequisites>\n"
  2914. "\t<Resources>\n"
  2915. "\t\t<Resource Language=\"x-generate\" />\n"
  2916. "\t</Resources>\n"
  2917. "\t<Applications>\n"
  2918. "\t\t<Application Id=\"App\""
  2919. " Executable=\"" << targetNameXML << ".exe\""
  2920. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  2921. "\t\t\t<VisualElements"
  2922. " DisplayName=\"" << targetNameXML << "\""
  2923. " Description=\"" << targetNameXML << "\""
  2924. " BackgroundColor=\"#336699\" ForegroundText=\"light\""
  2925. " Logo=\"" << artifactDirXML << "\\Logo.png\""
  2926. " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  2927. "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
  2928. " ShortName=\"" << targetNameXML << "\" />\n"
  2929. "\t\t\t\t<SplashScreen"
  2930. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  2931. "\t\t\t</VisualElements>\n"
  2932. "\t\t</Application>\n"
  2933. "\t</Applications>\n"
  2934. "</Package>\n";
  2935. this->WriteCommonMissingFiles(manifestFile);
  2936. }
  2937. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
  2938. {
  2939. std::string manifestFile =
  2940. this->DefaultArtifactDir + "/package.appxManifest";
  2941. std::string artifactDir =
  2942. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2943. this->ConvertToWindowsSlash(artifactDir);
  2944. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2945. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  2946. cmGeneratedFileStream fout(manifestFile.c_str());
  2947. fout.SetCopyIfDifferent(true);
  2948. fout <<
  2949. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2950. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  2951. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
  2952. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  2953. " Version=\"1.0.0.0\" />\n"
  2954. "\t<Properties>\n"
  2955. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  2956. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  2957. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  2958. "\t</Properties>\n"
  2959. "\t<Prerequisites>\n"
  2960. "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
  2961. "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
  2962. "\t</Prerequisites>\n"
  2963. "\t<Resources>\n"
  2964. "\t\t<Resource Language=\"x-generate\" />\n"
  2965. "\t</Resources>\n"
  2966. "\t<Applications>\n"
  2967. "\t\t<Application Id=\"App\""
  2968. " Executable=\"" << targetNameXML << ".exe\""
  2969. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  2970. "\t\t\t<m2:VisualElements\n"
  2971. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  2972. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  2973. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  2974. "\t\t\t\tForegroundText=\"light\"\n"
  2975. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  2976. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  2977. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  2978. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  2979. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  2980. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  2981. "\t\t\t\t</m2:DefaultTile>\n"
  2982. "\t\t\t\t<m2:SplashScreen"
  2983. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  2984. "\t\t\t</m2:VisualElements>\n"
  2985. "\t\t</Application>\n"
  2986. "\t</Applications>\n"
  2987. "</Package>\n";
  2988. this->WriteCommonMissingFiles(manifestFile);
  2989. }
  2990. void
  2991. cmVisualStudio10TargetGenerator
  2992. ::WriteCommonMissingFiles(const std::string& manifestFile)
  2993. {
  2994. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  2995. "/Templates/Windows";
  2996. std::string sourceFile = this->ConvertPath(manifestFile, false);
  2997. this->ConvertToWindowsSlash(sourceFile);
  2998. this->WriteString("<AppxManifest Include=\"", 2);
  2999. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  3000. this->WriteString("<SubType>Designer</SubType>\n", 3);
  3001. this->WriteString("</AppxManifest>\n", 2);
  3002. this->AddedFiles.push_back(sourceFile);
  3003. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3004. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png",
  3005. smallLogo, false);
  3006. this->ConvertToWindowsSlash(smallLogo);
  3007. this->WriteString("<Image Include=\"", 2);
  3008. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  3009. this->AddedFiles.push_back(smallLogo);
  3010. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3011. cmSystemTools::CopyAFile(templateFolder + "/Logo.png",
  3012. logo, false);
  3013. this->ConvertToWindowsSlash(logo);
  3014. this->WriteString("<Image Include=\"", 2);
  3015. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  3016. this->AddedFiles.push_back(logo);
  3017. std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
  3018. cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png",
  3019. storeLogo, false);
  3020. this->ConvertToWindowsSlash(storeLogo);
  3021. this->WriteString("<Image Include=\"", 2);
  3022. (*this->BuildFileStream) << cmVS10EscapeXML(storeLogo) << "\" />\n";
  3023. this->AddedFiles.push_back(storeLogo);
  3024. std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
  3025. cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png",
  3026. splashScreen, false);
  3027. this->ConvertToWindowsSlash(splashScreen);
  3028. this->WriteString("<Image Include=\"", 2);
  3029. (*this->BuildFileStream) << cmVS10EscapeXML(splashScreen) << "\" />\n";
  3030. this->AddedFiles.push_back(splashScreen);
  3031. // This file has already been added to the build so don't copy it
  3032. std::string keyFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  3033. this->ConvertToWindowsSlash(keyFile);
  3034. this->WriteString("<None Include=\"", 2);
  3035. (*this->BuildFileStream) << cmVS10EscapeXML(keyFile) << "\" />\n";
  3036. }