cmVisualStudio10TargetGenerator.cxx 126 KB

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