cmVisualStudio10TargetGenerator.cxx 125 KB

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