cmVisualStudio10TargetGenerator.cxx 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713
  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->LocalGenerator->GetCurrentBinaryDirectory() + std::string("/") +
  188. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  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->GeneratorTarget->GetType() == cmState::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->GeneratorTarget->GetType() <= cmState::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. std::string path = this->LocalGenerator->GetCurrentBinaryDirectory();
  284. path += "/";
  285. path += this->Name;
  286. path += ".vcxproj";
  287. this->BuildFileStream =
  288. new cmGeneratedFileStream(path.c_str());
  289. this->PathToVcxproj = path;
  290. this->BuildFileStream->SetCopyIfDifferent(true);
  291. // Write the encoding header into the file
  292. char magic[] = {char(0xEF), char(0xBB), char(0xBF)};
  293. this->BuildFileStream->write(magic, 3);
  294. //get the tools version to use
  295. const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
  296. std::string project_defaults=
  297. "<?xml version=\"1.0\" encoding=\"" +
  298. this->GlobalGenerator->Encoding() + "\"?>\n";
  299. project_defaults.append("<Project DefaultTargets=\"Build\" ToolsVersion=\"");
  300. project_defaults.append(toolsVer +"\" ");
  301. project_defaults.append(
  302. "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
  303. this->WriteString(project_defaults.c_str(),0);
  304. if(this->NsightTegra)
  305. {
  306. this->WriteString("<PropertyGroup Label=\"NsightTegraProject\">\n", 1);
  307. const int nsightTegraMajorVersion = this->NsightTegraVersion[0];
  308. const int nsightTegraMinorVersion = this->NsightTegraVersion[1];
  309. if (nsightTegraMajorVersion >= 2)
  310. {
  311. this->WriteString("<NsightTegraProjectRevisionNumber>", 2);
  312. if (nsightTegraMajorVersion > 3 ||
  313. (nsightTegraMajorVersion == 3 && nsightTegraMinorVersion >= 1))
  314. {
  315. (*this->BuildFileStream) << "11";
  316. }
  317. else
  318. {
  319. // Nsight Tegra 2.0 uses project revision 9.
  320. (*this->BuildFileStream) << "9";
  321. }
  322. (*this->BuildFileStream) << "</NsightTegraProjectRevisionNumber>\n";
  323. // Tell newer versions to upgrade silently when loading.
  324. this->WriteString("<NsightTegraUpgradeOnceWithoutPrompt>"
  325. "true"
  326. "</NsightTegraUpgradeOnceWithoutPrompt>\n", 2);
  327. }
  328. else
  329. {
  330. // Require Nsight Tegra 1.6 for JCompile support.
  331. this->WriteString("<NsightTegraProjectRevisionNumber>"
  332. "7"
  333. "</NsightTegraProjectRevisionNumber>\n", 2);
  334. }
  335. this->WriteString("</PropertyGroup>\n", 1);
  336. }
  337. this->WriteProjectConfigurations();
  338. this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1);
  339. this->WriteString("<ProjectGUID>", 2);
  340. (*this->BuildFileStream) << "{" << this->GUID << "}</ProjectGUID>\n";
  341. if(this->MSTools
  342. && this->GeneratorTarget->GetType() <= cmState::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->GeneratorTarget->GetType())
  627. {
  628. case cmState::SHARED_LIBRARY:
  629. case cmState::MODULE_LIBRARY:
  630. configType += "DynamicLibrary";
  631. break;
  632. case cmState::OBJECT_LIBRARY:
  633. case cmState::STATIC_LIBRARY:
  634. configType += "StaticLibrary";
  635. break;
  636. case cmState::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 cmState::UTILITY:
  649. case cmState::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 cmState::UNKNOWN_LIBRARY:
  661. case cmState::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->GeneratorTarget->GetType() <= cmState::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->GeneratorTarget->GetType() <= cmState::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->LocalGenerator->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->LocalGenerator->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 == "xml")
  1228. {
  1229. tool = "XML";
  1230. }
  1231. if(this->NsightTegra)
  1232. {
  1233. // Nsight Tegra needs specific file types to check up-to-dateness.
  1234. std::string name =
  1235. cmSystemTools::LowerCase(sf->GetLocation().GetName());
  1236. if(name == "androidmanifest.xml" ||
  1237. name == "build.xml" ||
  1238. name == "proguard.cfg" ||
  1239. name == "proguard-project.txt" ||
  1240. ext == "properties")
  1241. {
  1242. tool = "AndroidBuild";
  1243. }
  1244. else if(ext == "java")
  1245. {
  1246. tool = "JCompile";
  1247. }
  1248. else if(ext == "asm" || ext == "s")
  1249. {
  1250. tool = "ClCompile";
  1251. }
  1252. }
  1253. std::string deployContent;
  1254. std::string deployLocation;
  1255. if(this->GlobalGenerator->TargetsWindowsPhone() ||
  1256. this->GlobalGenerator->TargetsWindowsStore())
  1257. {
  1258. const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
  1259. if(content && *content)
  1260. {
  1261. toolHasSettings = true;
  1262. deployContent = content;
  1263. const char* location = sf->GetProperty("VS_DEPLOYMENT_LOCATION");
  1264. if(location && *location)
  1265. {
  1266. deployLocation = location;
  1267. }
  1268. }
  1269. }
  1270. if(toolHasSettings)
  1271. {
  1272. this->WriteSource(tool, sf, ">\n");
  1273. if(!deployContent.empty())
  1274. {
  1275. cmGeneratorExpression ge;
  1276. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1277. ge.Parse(deployContent);
  1278. // Deployment location cannot be set on a configuration basis
  1279. if(!deployLocation.empty())
  1280. {
  1281. this->WriteString("<Link>", 3);
  1282. (*this->BuildFileStream) << deployLocation
  1283. << "\\%(FileName)%(Extension)";
  1284. this->WriteString("</Link>\n", 0);
  1285. }
  1286. for(size_t i = 0; i != this->Configurations.size(); ++i)
  1287. {
  1288. if(0 == strcmp(cge->Evaluate(this->LocalGenerator,
  1289. this->Configurations[i]), "1"))
  1290. {
  1291. this->WriteString("<DeploymentContent Condition=\""
  1292. "'$(Configuration)|$(Platform)'=='", 3);
  1293. (*this->BuildFileStream) << this->Configurations[i] << "|"
  1294. << this->Platform << "'\">true";
  1295. this->WriteString("</DeploymentContent>\n", 0);
  1296. }
  1297. else
  1298. {
  1299. this->WriteString("<ExcludedFromBuild Condition=\""
  1300. "'$(Configuration)|$(Platform)'=='", 3);
  1301. (*this->BuildFileStream) << this->Configurations[i] << "|"
  1302. << this->Platform << "'\">true";
  1303. this->WriteString("</ExcludedFromBuild>\n", 0);
  1304. }
  1305. }
  1306. }
  1307. if(!shaderType.empty())
  1308. {
  1309. this->WriteString("<ShaderType>", 3);
  1310. (*this->BuildFileStream) << cmVS10EscapeXML(shaderType)
  1311. << "</ShaderType>\n";
  1312. }
  1313. if(!shaderEntryPoint.empty())
  1314. {
  1315. this->WriteString("<EntryPointName>", 3);
  1316. (*this->BuildFileStream) << cmVS10EscapeXML(shaderEntryPoint)
  1317. << "</EntryPointName>\n";
  1318. }
  1319. if(!shaderModel.empty())
  1320. {
  1321. this->WriteString("<ShaderModel>", 3);
  1322. (*this->BuildFileStream) << cmVS10EscapeXML(shaderModel)
  1323. << "</ShaderModel>\n";
  1324. }
  1325. if(!shaderAdditionalFlags.empty())
  1326. {
  1327. this->WriteString("<AdditionalOptions>", 3);
  1328. (*this->BuildFileStream) << cmVS10EscapeXML(shaderAdditionalFlags)
  1329. << "</AdditionalOptions>\n";
  1330. }
  1331. this->WriteString("</", 2);
  1332. (*this->BuildFileStream) << tool << ">\n";
  1333. }
  1334. else
  1335. {
  1336. this->WriteSource(tool, sf);
  1337. }
  1338. }
  1339. void cmVisualStudio10TargetGenerator::WriteSource(
  1340. std::string const& tool, cmSourceFile const* sf, const char* end)
  1341. {
  1342. // Visual Studio tools append relative paths to the current dir, as in:
  1343. //
  1344. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  1345. //
  1346. // and fail if this exceeds the maximum allowed path length. Our path
  1347. // conversion uses full paths when possible to allow deeper trees.
  1348. bool forceRelative = false;
  1349. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), false);
  1350. if(this->LocalGenerator->GetVersion() == cmGlobalVisualStudioGenerator::VS10
  1351. && cmSystemTools::FileIsFullPath(sourceFile.c_str()))
  1352. {
  1353. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  1354. // refuses to show the property page in the IDE for a source file with a
  1355. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  1356. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  1357. // full path except for custom commands. Custom commands do not work
  1358. // without a relative path, but they do not seem to be involved in tools
  1359. // with the above behavior. For other sources we now use a relative path
  1360. // when the combined path will not be too long so property pages appear.
  1361. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  1362. size_t const maxLen = 250;
  1363. if(sf->GetCustomCommand() ||
  1364. ((strlen(this->LocalGenerator->GetCurrentBinaryDirectory()) + 1 +
  1365. sourceRel.length()) <= maxLen))
  1366. {
  1367. forceRelative = true;
  1368. sourceFile = sourceRel;
  1369. }
  1370. else
  1371. {
  1372. this->GlobalGenerator->PathTooLong(this->Target, sf, sourceRel);
  1373. }
  1374. }
  1375. this->ConvertToWindowsSlash(sourceFile);
  1376. this->WriteString("<", 2);
  1377. (*this->BuildFileStream ) << tool << " Include=\""
  1378. << cmVS10EscapeXML(sourceFile) << "\""
  1379. << (end? end : " />\n");
  1380. ToolSource toolSource = {sf, forceRelative};
  1381. this->Tools[tool].push_back(toolSource);
  1382. }
  1383. void cmVisualStudio10TargetGenerator::WriteSources(
  1384. std::string const& tool, std::vector<cmSourceFile const*> const& sources)
  1385. {
  1386. for(std::vector<cmSourceFile const*>::const_iterator
  1387. si = sources.begin(); si != sources.end(); ++si)
  1388. {
  1389. this->WriteSource(tool, *si);
  1390. }
  1391. }
  1392. void cmVisualStudio10TargetGenerator::WriteAllSources()
  1393. {
  1394. if(this->GeneratorTarget->GetType() > cmState::UTILITY)
  1395. {
  1396. return;
  1397. }
  1398. this->WriteString("<ItemGroup>\n", 1);
  1399. std::vector<cmSourceFile const*> headerSources;
  1400. this->GeneratorTarget->GetHeaderSources(headerSources, "");
  1401. for(std::vector<cmSourceFile const*>::const_iterator
  1402. si = headerSources.begin(); si != headerSources.end(); ++si)
  1403. {
  1404. this->WriteHeaderSource(*si);
  1405. }
  1406. std::vector<cmSourceFile const*> idlSources;
  1407. this->GeneratorTarget->GetIDLSources(idlSources, "");
  1408. this->WriteSources("Midl", idlSources);
  1409. std::vector<cmSourceFile const*> objectSources;
  1410. this->GeneratorTarget->GetObjectSources(objectSources, "");
  1411. for(std::vector<cmSourceFile const*>::const_iterator
  1412. si = objectSources.begin();
  1413. si != objectSources.end(); ++si)
  1414. {
  1415. const std::string& lang = (*si)->GetLanguage();
  1416. std::string tool;
  1417. if (lang == "C"|| lang == "CXX")
  1418. {
  1419. tool = "ClCompile";
  1420. }
  1421. else if (lang == "ASM_MASM" &&
  1422. this->GlobalGenerator->IsMasmEnabled())
  1423. {
  1424. tool = "MASM";
  1425. }
  1426. else if (lang == "RC")
  1427. {
  1428. tool = "ResourceCompile";
  1429. }
  1430. if (!tool.empty())
  1431. {
  1432. this->WriteSource(tool, *si, " ");
  1433. if (this->OutputSourceSpecificFlags(*si))
  1434. {
  1435. this->WriteString("</", 2);
  1436. (*this->BuildFileStream ) << tool << ">\n";
  1437. }
  1438. else
  1439. {
  1440. (*this->BuildFileStream ) << " />\n";
  1441. }
  1442. }
  1443. else
  1444. {
  1445. this->WriteSource("None", *si);
  1446. }
  1447. }
  1448. std::vector<cmSourceFile const*> manifestSources;
  1449. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  1450. this->WriteSources("AppxManifest", manifestSources);
  1451. std::vector<cmSourceFile const*> certificateSources;
  1452. this->GeneratorTarget->GetCertificates(certificateSources, "");
  1453. this->WriteSources("None", certificateSources);
  1454. std::vector<cmSourceFile const*> externalObjects;
  1455. this->GeneratorTarget->GetExternalObjects(externalObjects, "");
  1456. for(std::vector<cmSourceFile const*>::iterator
  1457. si = externalObjects.begin();
  1458. si != externalObjects.end(); )
  1459. {
  1460. if (!(*si)->GetObjectLibrary().empty())
  1461. {
  1462. si = externalObjects.erase(si);
  1463. }
  1464. else
  1465. {
  1466. ++si;
  1467. }
  1468. }
  1469. if(this->LocalGenerator->GetVersion() > cmGlobalVisualStudioGenerator::VS10)
  1470. {
  1471. // For VS >= 11 we use LinkObjects to avoid linking custom command
  1472. // outputs. Use Object for all external objects, generated or not.
  1473. this->WriteSources("Object", externalObjects);
  1474. }
  1475. else
  1476. {
  1477. // If an object file is generated in this target, then vs10 will use
  1478. // it in the build, and we have to list it as None instead of Object.
  1479. for(std::vector<cmSourceFile const*>::const_iterator
  1480. si = externalObjects.begin();
  1481. si != externalObjects.end(); ++si)
  1482. {
  1483. std::vector<cmSourceFile*> const* d =
  1484. this->GeneratorTarget->GetSourceDepends(*si);
  1485. this->WriteSource((d && !d->empty())? "None":"Object", *si);
  1486. }
  1487. }
  1488. std::vector<cmSourceFile const*> extraSources;
  1489. this->GeneratorTarget->GetExtraSources(extraSources, "");
  1490. for(std::vector<cmSourceFile const*>::const_iterator
  1491. si = extraSources.begin(); si != extraSources.end(); ++si)
  1492. {
  1493. this->WriteExtraSource(*si);
  1494. }
  1495. // Add object library contents as external objects.
  1496. std::vector<std::string> objs;
  1497. this->GeneratorTarget->UseObjectLibraries(objs, "");
  1498. for(std::vector<std::string>::const_iterator
  1499. oi = objs.begin(); oi != objs.end(); ++oi)
  1500. {
  1501. std::string obj = *oi;
  1502. this->WriteString("<Object Include=\"", 2);
  1503. this->ConvertToWindowsSlash(obj);
  1504. (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\" />\n";
  1505. }
  1506. if (this->IsMissingFiles)
  1507. {
  1508. this->WriteMissingFiles();
  1509. }
  1510. this->WriteString("</ItemGroup>\n", 1);
  1511. }
  1512. bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  1513. cmSourceFile const* source)
  1514. {
  1515. cmSourceFile const& sf = *source;
  1516. std::string objectName;
  1517. if(this->GeneratorTarget->HasExplicitObjectName(&sf))
  1518. {
  1519. objectName = this->GeneratorTarget->GetObjectName(&sf);
  1520. }
  1521. std::string flags;
  1522. std::string defines;
  1523. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1524. {
  1525. flags += cflags;
  1526. }
  1527. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1528. {
  1529. defines += cdefs;
  1530. }
  1531. std::string lang =
  1532. this->GlobalGenerator->GetLanguageFromExtension
  1533. (sf.GetExtension().c_str());
  1534. std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  1535. const std::string& linkLanguage = this->GeneratorTarget->GetLinkerLanguage();
  1536. bool needForceLang = false;
  1537. // source file does not match its extension language
  1538. if(lang != sourceLang)
  1539. {
  1540. needForceLang = true;
  1541. lang = sourceLang;
  1542. }
  1543. // if the source file does not match the linker language
  1544. // then force c or c++
  1545. const char* compileAs = 0;
  1546. if(needForceLang || (linkLanguage != lang))
  1547. {
  1548. if(lang == "CXX")
  1549. {
  1550. // force a C++ file type
  1551. compileAs = "CompileAsCpp";
  1552. }
  1553. else if(lang == "C")
  1554. {
  1555. // force to c
  1556. compileAs = "CompileAsC";
  1557. }
  1558. }
  1559. bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
  1560. bool hasFlags = false;
  1561. // for the first time we need a new line if there is something
  1562. // produced here.
  1563. const char* firstString = ">\n";
  1564. if(!objectName.empty())
  1565. {
  1566. (*this->BuildFileStream ) << firstString;
  1567. firstString = "";
  1568. hasFlags = true;
  1569. this->WriteString("<ObjectFileName>", 3);
  1570. (*this->BuildFileStream )
  1571. << "$(IntDir)/" << objectName << "</ObjectFileName>\n";
  1572. }
  1573. for(std::vector<std::string>::const_iterator
  1574. config = this->Configurations.begin();
  1575. config != this->Configurations.end(); ++config)
  1576. {
  1577. std::string configUpper = cmSystemTools::UpperCase(*config);
  1578. std::string configDefines = defines;
  1579. std::string defPropName = "COMPILE_DEFINITIONS_";
  1580. defPropName += configUpper;
  1581. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1582. {
  1583. if(!configDefines.empty())
  1584. {
  1585. configDefines += ";";
  1586. }
  1587. configDefines += ccdefs;
  1588. }
  1589. // if we have flags or defines for this config then
  1590. // use them
  1591. if(!flags.empty() || !configDefines.empty() || compileAs || noWinRT)
  1592. {
  1593. (*this->BuildFileStream ) << firstString;
  1594. firstString = ""; // only do firstString once
  1595. hasFlags = true;
  1596. cmVisualStudioGeneratorOptions
  1597. clOptions(this->LocalGenerator,
  1598. cmVisualStudioGeneratorOptions::Compiler,
  1599. this->GetClFlagTable(), 0, this);
  1600. if(compileAs)
  1601. {
  1602. clOptions.AddFlag("CompileAs", compileAs);
  1603. }
  1604. if(noWinRT)
  1605. {
  1606. clOptions.AddFlag("CompileAsWinRT", "false");
  1607. }
  1608. clOptions.Parse(flags.c_str());
  1609. if(clOptions.HasFlag("AdditionalIncludeDirectories"))
  1610. {
  1611. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1612. "%(AdditionalIncludeDirectories)");
  1613. }
  1614. if(clOptions.HasFlag("DisableSpecificWarnings"))
  1615. {
  1616. clOptions.AppendFlag("DisableSpecificWarnings",
  1617. "%(DisableSpecificWarnings)");
  1618. }
  1619. clOptions.AddDefines(configDefines.c_str());
  1620. clOptions.SetConfiguration((*config).c_str());
  1621. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1622. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1623. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream,
  1624. " ", "\n", lang);
  1625. }
  1626. }
  1627. if (this->IsXamlSource(source->GetFullPath()))
  1628. {
  1629. (*this->BuildFileStream) << firstString;
  1630. firstString = ""; // only do firstString once
  1631. hasFlags = true;
  1632. this->WriteString("<DependentUpon>", 3);
  1633. const std::string& fileName = source->GetFullPath();
  1634. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1635. (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
  1636. }
  1637. return hasFlags;
  1638. }
  1639. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
  1640. {
  1641. cmState::TargetType ttype = this->GeneratorTarget->GetType();
  1642. if(ttype > cmState::GLOBAL_TARGET)
  1643. {
  1644. return;
  1645. }
  1646. this->WriteString("<PropertyGroup>\n", 2);
  1647. this->WriteString("<_ProjectFileVersion>10.0.20506.1"
  1648. "</_ProjectFileVersion>\n", 3);
  1649. for(std::vector<std::string>::const_iterator
  1650. config = this->Configurations.begin();
  1651. config != this->Configurations.end(); ++config)
  1652. {
  1653. if(ttype >= cmState::UTILITY)
  1654. {
  1655. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1656. *this->BuildFileStream
  1657. << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
  1658. << "</IntDir>\n";
  1659. }
  1660. else
  1661. {
  1662. std::string intermediateDir = this->LocalGenerator->
  1663. GetTargetDirectory(this->GeneratorTarget);
  1664. intermediateDir += "/";
  1665. intermediateDir += *config;
  1666. intermediateDir += "/";
  1667. std::string outDir;
  1668. std::string targetNameFull;
  1669. if(ttype == cmState::OBJECT_LIBRARY)
  1670. {
  1671. outDir = intermediateDir;
  1672. targetNameFull = this->Target->GetName();
  1673. targetNameFull += ".lib";
  1674. }
  1675. else
  1676. {
  1677. outDir = this->GeneratorTarget->GetDirectory(config->c_str()) + "/";
  1678. targetNameFull = this->GeneratorTarget->GetFullName(config->c_str());
  1679. }
  1680. this->ConvertToWindowsSlash(intermediateDir);
  1681. this->ConvertToWindowsSlash(outDir);
  1682. this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
  1683. *this->BuildFileStream << cmVS10EscapeXML(outDir)
  1684. << "</OutDir>\n";
  1685. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1686. *this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
  1687. << "</IntDir>\n";
  1688. std::string name =
  1689. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  1690. this->WritePlatformConfigTag("TargetName", config->c_str(), 3);
  1691. *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n";
  1692. std::string ext =
  1693. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  1694. if(ext.empty())
  1695. {
  1696. // An empty TargetExt causes a default extension to be used.
  1697. // A single "." appears to be treated as an empty extension.
  1698. ext = ".";
  1699. }
  1700. this->WritePlatformConfigTag("TargetExt", config->c_str(), 3);
  1701. *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n";
  1702. this->OutputLinkIncremental(*config);
  1703. }
  1704. }
  1705. this->WriteString("</PropertyGroup>\n", 2);
  1706. }
  1707. void
  1708. cmVisualStudio10TargetGenerator::
  1709. OutputLinkIncremental(std::string const& configName)
  1710. {
  1711. if(!this->MSTools)
  1712. {
  1713. return;
  1714. }
  1715. // static libraries and things greater than modules do not need
  1716. // to set this option
  1717. if(this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY
  1718. || this->GeneratorTarget->GetType() > cmState::MODULE_LIBRARY)
  1719. {
  1720. return;
  1721. }
  1722. Options& linkOptions = *(this->LinkOptions[configName]);
  1723. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  1724. this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 3);
  1725. *this->BuildFileStream << (incremental?incremental:"true")
  1726. << "</LinkIncremental>\n";
  1727. linkOptions.RemoveFlag("LinkIncremental");
  1728. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  1729. this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 3);
  1730. *this->BuildFileStream << (manifest?manifest:"true")
  1731. << "</GenerateManifest>\n";
  1732. linkOptions.RemoveFlag("GenerateManifest");
  1733. // Some link options belong here. Use them now and remove them so that
  1734. // WriteLinkOptions does not use them.
  1735. const char* flags[] = {
  1736. "LinkDelaySign",
  1737. "LinkKeyFile",
  1738. 0};
  1739. for(const char** f = flags; *f; ++f)
  1740. {
  1741. const char* flag = *f;
  1742. if(const char* value = linkOptions.GetFlag(flag))
  1743. {
  1744. this->WritePlatformConfigTag(flag, configName.c_str(), 3);
  1745. *this->BuildFileStream << value << "</" << flag << ">\n";
  1746. linkOptions.RemoveFlag(flag);
  1747. }
  1748. }
  1749. }
  1750. //----------------------------------------------------------------------------
  1751. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  1752. {
  1753. for(std::vector<std::string>::const_iterator
  1754. i = this->Configurations.begin();
  1755. i != this->Configurations.end(); ++i)
  1756. {
  1757. if(!this->ComputeClOptions(*i))
  1758. {
  1759. return false;
  1760. }
  1761. }
  1762. return true;
  1763. }
  1764. //----------------------------------------------------------------------------
  1765. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  1766. std::string const& configName)
  1767. {
  1768. // much of this was copied from here:
  1769. // copied from cmLocalVisualStudio7Generator.cxx 805
  1770. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  1771. cmsys::auto_ptr<Options> pOptions(
  1772. new Options(this->LocalGenerator, Options::Compiler,
  1773. this->GetClFlagTable()));
  1774. Options& clOptions = *pOptions;
  1775. std::string flags;
  1776. const std::string& linkLanguage =
  1777. this->GeneratorTarget->GetLinkerLanguage(configName.c_str());
  1778. if(linkLanguage.empty())
  1779. {
  1780. cmSystemTools::Error
  1781. ("CMake can not determine linker language for target: ",
  1782. this->Name.c_str());
  1783. return false;
  1784. }
  1785. if(linkLanguage == "C" || linkLanguage == "CXX"
  1786. || linkLanguage == "Fortran")
  1787. {
  1788. std::string baseFlagVar = "CMAKE_";
  1789. baseFlagVar += linkLanguage;
  1790. baseFlagVar += "_FLAGS";
  1791. flags = this->
  1792. Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
  1793. std::string flagVar = baseFlagVar + std::string("_") +
  1794. cmSystemTools::UpperCase(configName);
  1795. flags += " ";
  1796. flags += this->
  1797. Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
  1798. }
  1799. // set the correct language
  1800. if(linkLanguage == "C")
  1801. {
  1802. clOptions.AddFlag("CompileAs", "CompileAsC");
  1803. }
  1804. if(linkLanguage == "CXX")
  1805. {
  1806. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  1807. }
  1808. this->LocalGenerator->AddCompileOptions(flags, this->Target,
  1809. linkLanguage, configName.c_str());
  1810. // Get preprocessor definitions for this directory.
  1811. std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags();
  1812. if(this->MSTools)
  1813. {
  1814. clOptions.FixExceptionHandlingDefault();
  1815. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  1816. std::string asmLocation = configName + "/";
  1817. clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  1818. }
  1819. clOptions.Parse(flags.c_str());
  1820. clOptions.Parse(defineFlags.c_str());
  1821. std::vector<std::string> targetDefines;
  1822. this->GeneratorTarget->GetCompileDefinitions(targetDefines,
  1823. configName.c_str(), "CXX");
  1824. clOptions.AddDefines(targetDefines);
  1825. if(this->MSTools)
  1826. {
  1827. clOptions.SetVerboseMakefile(
  1828. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  1829. }
  1830. // Add a definition for the configuration name.
  1831. std::string configDefine = "CMAKE_INTDIR=\"";
  1832. configDefine += configName;
  1833. configDefine += "\"";
  1834. clOptions.AddDefine(configDefine);
  1835. if(const char* exportMacro = this->Target->GetExportMacro())
  1836. {
  1837. clOptions.AddDefine(exportMacro);
  1838. }
  1839. if (this->MSTools)
  1840. {
  1841. // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
  1842. if (this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
  1843. {
  1844. clOptions.AddFlag("CompileAsWinRT", "true");
  1845. // For WinRT components, add the _WINRT_DLL define to produce a lib
  1846. if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
  1847. this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY )
  1848. {
  1849. clOptions.AddDefine("_WINRT_DLL");
  1850. }
  1851. }
  1852. else if (this->GlobalGenerator->TargetsWindowsStore() ||
  1853. this->GlobalGenerator->TargetsWindowsPhone())
  1854. {
  1855. if (!clOptions.IsWinRt())
  1856. {
  1857. clOptions.AddFlag("CompileAsWinRT", "false");
  1858. }
  1859. }
  1860. if(const char* winRT = clOptions.GetFlag("CompileAsWinRT"))
  1861. {
  1862. if(cmSystemTools::IsOn(winRT))
  1863. {
  1864. this->TargetCompileAsWinRT = true;
  1865. }
  1866. }
  1867. }
  1868. this->ClOptions[configName] = pOptions.release();
  1869. return true;
  1870. }
  1871. //----------------------------------------------------------------------------
  1872. void cmVisualStudio10TargetGenerator::WriteClOptions(
  1873. std::string const& configName,
  1874. std::vector<std::string> const& includes)
  1875. {
  1876. Options& clOptions = *(this->ClOptions[configName]);
  1877. this->WriteString("<ClCompile>\n", 2);
  1878. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1879. clOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  1880. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1881. "%(AdditionalIncludeDirectories)");
  1882. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1883. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1884. "\n", "CXX");
  1885. if(this->NsightTegra)
  1886. {
  1887. if(const char* processMax =
  1888. this->Target->GetProperty("ANDROID_PROCESS_MAX"))
  1889. {
  1890. this->WriteString("<ProcessMax>", 3);
  1891. *this->BuildFileStream << cmVS10EscapeXML(processMax) <<
  1892. "</ProcessMax>\n";
  1893. }
  1894. }
  1895. if(this->MSTools)
  1896. {
  1897. this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
  1898. // If not in debug mode, write the DebugInformationFormat field
  1899. // without value so PDBs don't get generated uselessly.
  1900. if(!clOptions.IsDebug())
  1901. {
  1902. this->WriteString("<DebugInformationFormat>"
  1903. "</DebugInformationFormat>\n", 3);
  1904. }
  1905. // Specify the compiler program database file if configured.
  1906. std::string pdb =
  1907. this->GeneratorTarget->GetCompilePDBPath(configName.c_str());
  1908. if(!pdb.empty())
  1909. {
  1910. this->ConvertToWindowsSlash(pdb);
  1911. this->WriteString("<ProgramDataBaseFileName>", 3);
  1912. *this->BuildFileStream << cmVS10EscapeXML(pdb)
  1913. << "</ProgramDataBaseFileName>\n";
  1914. }
  1915. }
  1916. this->WriteString("</ClCompile>\n", 2);
  1917. }
  1918. //----------------------------------------------------------------------------
  1919. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  1920. {
  1921. for(std::vector<std::string>::const_iterator
  1922. i = this->Configurations.begin();
  1923. i != this->Configurations.end(); ++i)
  1924. {
  1925. if(!this->ComputeRcOptions(*i))
  1926. {
  1927. return false;
  1928. }
  1929. }
  1930. return true;
  1931. }
  1932. //----------------------------------------------------------------------------
  1933. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  1934. std::string const& configName)
  1935. {
  1936. cmsys::auto_ptr<Options> pOptions(
  1937. new Options(this->LocalGenerator, Options::ResourceCompiler,
  1938. this->GetRcFlagTable()));
  1939. Options& rcOptions = *pOptions;
  1940. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1941. std::string rcConfigFlagsVar = std::string("CMAKE_RC_FLAGS_") + CONFIG;
  1942. std::string flags =
  1943. std::string(this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS")) +
  1944. std::string(" ") +
  1945. std::string(this->Makefile->GetSafeDefinition(rcConfigFlagsVar));
  1946. rcOptions.Parse(flags.c_str());
  1947. this->RcOptions[configName] = pOptions.release();
  1948. return true;
  1949. }
  1950. void cmVisualStudio10TargetGenerator::
  1951. WriteRCOptions(std::string const& configName,
  1952. std::vector<std::string> const & includes)
  1953. {
  1954. if(!this->MSTools)
  1955. {
  1956. return;
  1957. }
  1958. this->WriteString("<ResourceCompile>\n", 2);
  1959. // Preprocessor definitions and includes are shared with clOptions.
  1960. Options& clOptions = *(this->ClOptions[configName]);
  1961. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1962. "\n", "RC");
  1963. Options& rcOptions = *(this->RcOptions[configName]);
  1964. rcOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  1965. rcOptions.AppendFlag("AdditionalIncludeDirectories",
  1966. "%(AdditionalIncludeDirectories)");
  1967. rcOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1968. rcOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1969. this->WriteString("</ResourceCompile>\n", 2);
  1970. }
  1971. //----------------------------------------------------------------------------
  1972. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
  1973. {
  1974. if(!this->GlobalGenerator->IsMasmEnabled())
  1975. {
  1976. return true;
  1977. }
  1978. for(std::vector<std::string>::const_iterator
  1979. i = this->Configurations.begin();
  1980. i != this->Configurations.end(); ++i)
  1981. {
  1982. if(!this->ComputeMasmOptions(*i))
  1983. {
  1984. return false;
  1985. }
  1986. }
  1987. return true;
  1988. }
  1989. //----------------------------------------------------------------------------
  1990. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
  1991. std::string const& configName)
  1992. {
  1993. cmsys::auto_ptr<Options> pOptions(
  1994. new Options(this->LocalGenerator, Options::MasmCompiler,
  1995. this->GetMasmFlagTable()));
  1996. Options& masmOptions = *pOptions;
  1997. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1998. std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG;
  1999. std::string flags =
  2000. std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS")) +
  2001. std::string(" ") +
  2002. std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
  2003. masmOptions.Parse(flags.c_str());
  2004. this->MasmOptions[configName] = pOptions.release();
  2005. return true;
  2006. }
  2007. void cmVisualStudio10TargetGenerator::
  2008. WriteMasmOptions(std::string const& configName,
  2009. std::vector<std::string> const& includes)
  2010. {
  2011. if(!this->MSTools || !this->GlobalGenerator->IsMasmEnabled())
  2012. {
  2013. return;
  2014. }
  2015. this->WriteString("<MASM>\n", 2);
  2016. // Preprocessor definitions and includes are shared with clOptions.
  2017. Options& clOptions = *(this->ClOptions[configName]);
  2018. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  2019. "\n", "ASM_MASM");
  2020. Options& masmOptions = *(this->MasmOptions[configName]);
  2021. masmOptions.AppendFlag("IncludePaths", includes);
  2022. masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)");
  2023. masmOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2024. masmOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2025. this->WriteString("</MASM>\n", 2);
  2026. }
  2027. void
  2028. cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
  2029. {
  2030. if(this->GeneratorTarget->GetType() != cmState::STATIC_LIBRARY &&
  2031. this->GeneratorTarget->GetType() != cmState::OBJECT_LIBRARY)
  2032. {
  2033. return;
  2034. }
  2035. std::string libflags;
  2036. this->LocalGenerator->GetStaticLibraryFlags(libflags,
  2037. cmSystemTools::UpperCase(config), this->Target);
  2038. if(!libflags.empty())
  2039. {
  2040. this->WriteString("<Lib>\n", 2);
  2041. cmVisualStudioGeneratorOptions
  2042. libOptions(this->LocalGenerator,
  2043. cmVisualStudioGeneratorOptions::Linker,
  2044. this->GetLibFlagTable(), 0, this);
  2045. libOptions.Parse(libflags.c_str());
  2046. libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2047. libOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2048. this->WriteString("</Lib>\n", 2);
  2049. }
  2050. // We cannot generate metadata for static libraries. WindowsPhone
  2051. // and WindowsStore tools look at GenerateWindowsMetadata in the
  2052. // Link tool options even for static libraries.
  2053. if(this->GlobalGenerator->TargetsWindowsPhone() ||
  2054. this->GlobalGenerator->TargetsWindowsStore())
  2055. {
  2056. this->WriteString("<Link>\n", 2);
  2057. this->WriteString("<GenerateWindowsMetadata>false"
  2058. "</GenerateWindowsMetadata>\n", 3);
  2059. this->WriteString("</Link>\n", 2);
  2060. }
  2061. }
  2062. void cmVisualStudio10TargetGenerator::WriteManifestOptions(
  2063. std::string const& config)
  2064. {
  2065. if (this->GeneratorTarget->GetType() != cmState::EXECUTABLE &&
  2066. this->GeneratorTarget->GetType() != cmState::SHARED_LIBRARY &&
  2067. this->GeneratorTarget->GetType() != cmState::MODULE_LIBRARY)
  2068. {
  2069. return;
  2070. }
  2071. std::vector<cmSourceFile const*> manifest_srcs;
  2072. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  2073. if (!manifest_srcs.empty())
  2074. {
  2075. this->WriteString("<Manifest>\n", 2);
  2076. this->WriteString("<AdditionalManifestFiles>", 3);
  2077. for (std::vector<cmSourceFile const*>::const_iterator
  2078. mi = manifest_srcs.begin(); mi != manifest_srcs.end(); ++mi)
  2079. {
  2080. std::string m = this->ConvertPath((*mi)->GetFullPath(), false);
  2081. this->ConvertToWindowsSlash(m);
  2082. (*this->BuildFileStream) << m << ";";
  2083. }
  2084. (*this->BuildFileStream) << "</AdditionalManifestFiles>\n";
  2085. this->WriteString("</Manifest>\n", 2);
  2086. }
  2087. }
  2088. //----------------------------------------------------------------------------
  2089. void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
  2090. std::string const& configName)
  2091. {
  2092. // Look through the sources for AndroidManifest.xml and use
  2093. // its location as the root source directory.
  2094. std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory();
  2095. {
  2096. std::vector<cmSourceFile const*> extraSources;
  2097. this->GeneratorTarget->GetExtraSources(extraSources, "");
  2098. for(std::vector<cmSourceFile const*>::const_iterator si =
  2099. extraSources.begin(); si != extraSources.end(); ++si)
  2100. {
  2101. if("androidmanifest.xml" == cmSystemTools::LowerCase(
  2102. (*si)->GetLocation().GetName()))
  2103. {
  2104. rootDir = (*si)->GetLocation().GetDirectory();
  2105. break;
  2106. }
  2107. }
  2108. }
  2109. // Tell MSBuild to launch Ant.
  2110. {
  2111. std::string antBuildPath = rootDir;
  2112. this->WriteString("<AntBuild>\n", 2);
  2113. this->WriteString("<AntBuildPath>", 3);
  2114. this->ConvertToWindowsSlash(antBuildPath);
  2115. (*this->BuildFileStream) <<
  2116. cmVS10EscapeXML(antBuildPath) << "</AntBuildPath>\n";
  2117. }
  2118. if (this->Target->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP"))
  2119. {
  2120. this->WriteString("<SkipAntStep>true</SkipAntStep>\n", 3);
  2121. }
  2122. if (this->Target->GetPropertyAsBool("ANDROID_PROGUARD"))
  2123. {
  2124. this->WriteString("<EnableProGuard>true</EnableProGuard>\n", 3);
  2125. }
  2126. if (const char* proGuardConfigLocation =
  2127. this->Target->GetProperty("ANDROID_PROGUARD_CONFIG_PATH"))
  2128. {
  2129. this->WriteString("<ProGuardConfigLocation>", 3);
  2130. (*this->BuildFileStream) << cmVS10EscapeXML(proGuardConfigLocation) <<
  2131. "</ProGuardConfigLocation>\n";
  2132. }
  2133. if (const char* securePropertiesLocation =
  2134. this->Target->GetProperty("ANDROID_SECURE_PROPS_PATH"))
  2135. {
  2136. this->WriteString("<SecurePropertiesLocation>", 3);
  2137. (*this->BuildFileStream) << cmVS10EscapeXML(securePropertiesLocation) <<
  2138. "</SecurePropertiesLocation>\n";
  2139. }
  2140. if (const char* nativeLibDirectoriesExpression =
  2141. this->Target->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES"))
  2142. {
  2143. cmGeneratorExpression ge;
  2144. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2145. ge.Parse(nativeLibDirectoriesExpression);
  2146. std::string nativeLibDirs = cge->Evaluate(this->LocalGenerator,
  2147. configName);
  2148. this->WriteString("<NativeLibDirectories>", 3);
  2149. (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDirs) <<
  2150. "</NativeLibDirectories>\n";
  2151. }
  2152. if (const char* nativeLibDependenciesExpression =
  2153. this->Target->GetProperty("ANDROID_NATIVE_LIB_DEPENDENCIES"))
  2154. {
  2155. cmGeneratorExpression ge;
  2156. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2157. ge.Parse(nativeLibDependenciesExpression);
  2158. std::string nativeLibDeps = cge->Evaluate(this->LocalGenerator,
  2159. configName);
  2160. this->WriteString("<NativeLibDependencies>", 3);
  2161. (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDeps) <<
  2162. "</NativeLibDependencies>\n";
  2163. }
  2164. if (const char* javaSourceDir =
  2165. this->Target->GetProperty("ANDROID_JAVA_SOURCE_DIR"))
  2166. {
  2167. this->WriteString("<JavaSourceDir>", 3);
  2168. (*this->BuildFileStream) << cmVS10EscapeXML(javaSourceDir) <<
  2169. "</JavaSourceDir>\n";
  2170. }
  2171. if (const char* jarDirectoriesExpression =
  2172. this->Target->GetProperty("ANDROID_JAR_DIRECTORIES"))
  2173. {
  2174. cmGeneratorExpression ge;
  2175. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2176. ge.Parse(jarDirectoriesExpression);
  2177. std::string jarDirectories = cge->Evaluate(this->LocalGenerator,
  2178. configName);
  2179. this->WriteString("<JarDirectories>", 3);
  2180. (*this->BuildFileStream) << cmVS10EscapeXML(jarDirectories) <<
  2181. "</JarDirectories>\n";
  2182. }
  2183. if (const char* jarDeps =
  2184. this->Target->GetProperty("ANDROID_JAR_DEPENDENCIES"))
  2185. {
  2186. this->WriteString("<JarDependencies>", 3);
  2187. (*this->BuildFileStream) << cmVS10EscapeXML(jarDeps) <<
  2188. "</JarDependencies>\n";
  2189. }
  2190. if (const char* assetsDirectories =
  2191. this->Target->GetProperty("ANDROID_ASSETS_DIRECTORIES"))
  2192. {
  2193. this->WriteString("<AssetsDirectories>", 3);
  2194. (*this->BuildFileStream) << cmVS10EscapeXML(assetsDirectories) <<
  2195. "</AssetsDirectories>\n";
  2196. }
  2197. {
  2198. std::string manifest_xml = rootDir + "/AndroidManifest.xml";
  2199. this->ConvertToWindowsSlash(manifest_xml);
  2200. this->WriteString("<AndroidManifestLocation>", 3);
  2201. (*this->BuildFileStream) <<
  2202. cmVS10EscapeXML(manifest_xml) << "</AndroidManifestLocation>\n";
  2203. }
  2204. if (const char* antAdditionalOptions =
  2205. this->Target->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS"))
  2206. {
  2207. this->WriteString("<AdditionalOptions>", 3);
  2208. (*this->BuildFileStream) << cmVS10EscapeXML(antAdditionalOptions) <<
  2209. " %(AdditionalOptions)</AdditionalOptions>\n";
  2210. }
  2211. this->WriteString("</AntBuild>\n", 2);
  2212. }
  2213. //----------------------------------------------------------------------------
  2214. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  2215. {
  2216. if(this->GeneratorTarget->GetType() == cmState::EXECUTABLE ||
  2217. this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
  2218. this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY)
  2219. {
  2220. for(std::vector<std::string>::const_iterator
  2221. i = this->Configurations.begin();
  2222. i != this->Configurations.end(); ++i)
  2223. {
  2224. if(!this->ComputeLinkOptions(*i))
  2225. {
  2226. return false;
  2227. }
  2228. }
  2229. }
  2230. return true;
  2231. }
  2232. //----------------------------------------------------------------------------
  2233. bool
  2234. cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
  2235. {
  2236. cmsys::auto_ptr<Options> pOptions(
  2237. new Options(this->LocalGenerator, Options::Linker,
  2238. this->GetLinkFlagTable(), 0, this));
  2239. Options& linkOptions = *pOptions;
  2240. const std::string& linkLanguage =
  2241. this->GeneratorTarget->GetLinkerLanguage(config.c_str());
  2242. if(linkLanguage.empty())
  2243. {
  2244. cmSystemTools::Error
  2245. ("CMake can not determine linker language for target: ",
  2246. this->Name.c_str());
  2247. return false;
  2248. }
  2249. std::string CONFIG = cmSystemTools::UpperCase(config);
  2250. const char* linkType = "SHARED";
  2251. if(this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY)
  2252. {
  2253. linkType = "MODULE";
  2254. }
  2255. if(this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
  2256. {
  2257. linkType = "EXE";
  2258. }
  2259. std::string flags;
  2260. std::string linkFlagVarBase = "CMAKE_";
  2261. linkFlagVarBase += linkType;
  2262. linkFlagVarBase += "_LINKER_FLAGS";
  2263. flags += " ";
  2264. flags += this->
  2265. Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
  2266. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  2267. flags += " ";
  2268. flags += this->
  2269. Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
  2270. const char* targetLinkFlags = this->Target->GetProperty("LINK_FLAGS");
  2271. if(targetLinkFlags)
  2272. {
  2273. flags += " ";
  2274. flags += targetLinkFlags;
  2275. }
  2276. std::string flagsProp = "LINK_FLAGS_";
  2277. flagsProp += CONFIG;
  2278. if(const char* flagsConfig = this->Target->GetProperty(flagsProp.c_str()))
  2279. {
  2280. flags += " ";
  2281. flags += flagsConfig;
  2282. }
  2283. std::string standardLibsVar = "CMAKE_";
  2284. standardLibsVar += linkLanguage;
  2285. standardLibsVar += "_STANDARD_LIBRARIES";
  2286. std::string
  2287. libs = this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  2288. // Remove trailing spaces from libs
  2289. std::string::size_type pos = libs.size()-1;
  2290. if(!libs.empty())
  2291. {
  2292. while(libs[pos] == ' ')
  2293. {
  2294. pos--;
  2295. }
  2296. }
  2297. if(pos != libs.size()-1)
  2298. {
  2299. libs = libs.substr(0, pos+1);
  2300. }
  2301. // Replace spaces in libs with ;
  2302. cmSystemTools::ReplaceString(libs, " ", ";");
  2303. std::vector<std::string> libVec;
  2304. cmSystemTools::ExpandListArgument(libs, libVec);
  2305. cmComputeLinkInformation* pcli =
  2306. this->GeneratorTarget->GetLinkInformation(config.c_str());
  2307. if(!pcli)
  2308. {
  2309. cmSystemTools::Error
  2310. ("CMake can not compute cmComputeLinkInformation for target: ",
  2311. this->Name.c_str());
  2312. return false;
  2313. }
  2314. // add the libraries for the target to libs string
  2315. cmComputeLinkInformation& cli = *pcli;
  2316. this->AddLibraries(cli, libVec);
  2317. linkOptions.AddFlag("AdditionalDependencies", libVec);
  2318. std::vector<std::string> const& ldirs = cli.GetDirectories();
  2319. std::vector<std::string> linkDirs;
  2320. for(std::vector<std::string>::const_iterator d = ldirs.begin();
  2321. d != ldirs.end(); ++d)
  2322. {
  2323. // first just full path
  2324. linkDirs.push_back(*d);
  2325. // next path with configuration type Debug, Release, etc
  2326. linkDirs.push_back(*d + "/$(Configuration)");
  2327. }
  2328. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  2329. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  2330. std::string targetName;
  2331. std::string targetNameSO;
  2332. std::string targetNameFull;
  2333. std::string targetNameImport;
  2334. std::string targetNamePDB;
  2335. if(this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
  2336. {
  2337. this->GeneratorTarget->GetExecutableNames(targetName, targetNameFull,
  2338. targetNameImport, targetNamePDB,
  2339. config.c_str());
  2340. }
  2341. else
  2342. {
  2343. this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO,
  2344. targetNameFull,
  2345. targetNameImport, targetNamePDB,
  2346. config.c_str());
  2347. }
  2348. if(this->MSTools)
  2349. {
  2350. linkOptions.AddFlag("Version", "");
  2351. if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
  2352. {
  2353. if (this->GlobalGenerator->TargetsWindowsCE())
  2354. {
  2355. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2356. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
  2357. {
  2358. if (this->ClOptions[config]->UsingUnicode())
  2359. {
  2360. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  2361. }
  2362. else
  2363. {
  2364. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  2365. }
  2366. }
  2367. }
  2368. else
  2369. {
  2370. linkOptions.AddFlag("SubSystem", "Windows");
  2371. }
  2372. }
  2373. else
  2374. {
  2375. if (this->GlobalGenerator->TargetsWindowsCE())
  2376. {
  2377. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2378. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
  2379. {
  2380. if (this->ClOptions[config]->UsingUnicode())
  2381. {
  2382. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  2383. }
  2384. else
  2385. {
  2386. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  2387. }
  2388. }
  2389. }
  2390. else
  2391. {
  2392. linkOptions.AddFlag("SubSystem", "Console");
  2393. };
  2394. }
  2395. if(const char* stackVal =
  2396. this->Makefile->GetDefinition("CMAKE_"+linkLanguage+"_STACK_SIZE"))
  2397. {
  2398. linkOptions.AddFlag("StackReserveSize", stackVal);
  2399. }
  2400. if(linkOptions.IsDebug() || flags.find("/debug") != flags.npos)
  2401. {
  2402. linkOptions.AddFlag("GenerateDebugInformation", "true");
  2403. }
  2404. else
  2405. {
  2406. linkOptions.AddFlag("GenerateDebugInformation", "false");
  2407. }
  2408. std::string pdb = this->GeneratorTarget->GetPDBDirectory(config.c_str());
  2409. pdb += "/";
  2410. pdb += targetNamePDB;
  2411. std::string imLib =
  2412. this->GeneratorTarget->GetDirectory(config.c_str(), true);
  2413. imLib += "/";
  2414. imLib += targetNameImport;
  2415. linkOptions.AddFlag("ImportLibrary", imLib.c_str());
  2416. linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
  2417. // A Windows Runtime component uses internal .NET metadata,
  2418. // so does not have an import library.
  2419. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
  2420. this->GeneratorTarget->GetType() != cmState::EXECUTABLE)
  2421. {
  2422. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  2423. }
  2424. else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2425. this->GlobalGenerator->TargetsWindowsStore())
  2426. {
  2427. // WindowsPhone and WindowsStore components are in an app container
  2428. // and produce WindowsMetadata. If we are not producing a WINRT
  2429. // component, then do not generate the metadata here.
  2430. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  2431. }
  2432. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  2433. this->GlobalGenerator->GetSystemVersion() == "8.0")
  2434. {
  2435. // WindowsPhone 8.0 does not have ole32.
  2436. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  2437. }
  2438. }
  2439. else if(this->NsightTegra)
  2440. {
  2441. linkOptions.AddFlag("SoName", targetNameSO.c_str());
  2442. }
  2443. linkOptions.Parse(flags.c_str());
  2444. if(this->MSTools)
  2445. {
  2446. std::string def = this->GeneratorTarget->GetModuleDefinitionFile("");
  2447. if(!def.empty())
  2448. {
  2449. linkOptions.AddFlag("ModuleDefinitionFile", def.c_str());
  2450. }
  2451. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  2452. "%(IgnoreSpecificDefaultLibraries)");
  2453. }
  2454. if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY &&
  2455. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
  2456. {
  2457. if (this->Target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
  2458. {
  2459. linkOptions.AddFlag("ModuleDefinitionFile", "$(IntDir)exportall.def");
  2460. }
  2461. }
  2462. this->LinkOptions[config] = pOptions.release();
  2463. return true;
  2464. }
  2465. //----------------------------------------------------------------------------
  2466. void
  2467. cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
  2468. {
  2469. if(this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY
  2470. || this->GeneratorTarget->GetType() > cmState::MODULE_LIBRARY)
  2471. {
  2472. return;
  2473. }
  2474. Options& linkOptions = *(this->LinkOptions[config]);
  2475. this->WriteString("<Link>\n", 2);
  2476. linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2477. linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2478. this->WriteString("</Link>\n", 2);
  2479. if(!this->GlobalGenerator->NeedLinkLibraryDependencies(*this->Target))
  2480. {
  2481. this->WriteString("<ProjectReference>\n", 2);
  2482. this->WriteString(
  2483. "<LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 3);
  2484. this->WriteString("</ProjectReference>\n", 2);
  2485. }
  2486. }
  2487. void cmVisualStudio10TargetGenerator::AddLibraries(
  2488. cmComputeLinkInformation& cli,
  2489. std::vector<std::string>& libVec)
  2490. {
  2491. typedef cmComputeLinkInformation::ItemVector ItemVector;
  2492. ItemVector libs = cli.GetItems();
  2493. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  2494. {
  2495. if(l->IsPath)
  2496. {
  2497. std::string path = this->LocalGenerator->
  2498. Convert(l->Value.c_str(),
  2499. cmLocalGenerator::START_OUTPUT,
  2500. cmLocalGenerator::UNCHANGED);
  2501. this->ConvertToWindowsSlash(path);
  2502. libVec.push_back(path);
  2503. }
  2504. else if (!l->Target
  2505. || l->Target->GetType() != cmState::INTERFACE_LIBRARY)
  2506. {
  2507. libVec.push_back(l->Value);
  2508. }
  2509. }
  2510. }
  2511. void cmVisualStudio10TargetGenerator::
  2512. WriteMidlOptions(std::string const& /*config*/,
  2513. std::vector<std::string> const & includes)
  2514. {
  2515. if(!this->MSTools)
  2516. {
  2517. return;
  2518. }
  2519. // This processes *any* of the .idl files specified in the project's file
  2520. // list (and passed as the item metadata %(Filename) expressing the rule
  2521. // input filename) into output files at the per-config *build* dir
  2522. // ($(IntDir)) each.
  2523. //
  2524. // IOW, this MIDL section is intended to provide a fully generic syntax
  2525. // content suitable for most cases (read: if you get errors, then it's quite
  2526. // probable that the error is on your side of the .idl setup).
  2527. //
  2528. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  2529. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  2530. // project's file list, otherwise the compiler-side processing won't pick it
  2531. // up (for non-directory form, it ends up looking in project binary dir
  2532. // only). Perhaps there's something to be done to make this more automatic
  2533. // on the CMake side?
  2534. this->WriteString("<Midl>\n", 2);
  2535. this->WriteString("<AdditionalIncludeDirectories>", 3);
  2536. for(std::vector<std::string>::const_iterator i = includes.begin();
  2537. i != includes.end(); ++i)
  2538. {
  2539. *this->BuildFileStream << cmVS10EscapeXML(*i) << ";";
  2540. }
  2541. this->WriteString("%(AdditionalIncludeDirectories)"
  2542. "</AdditionalIncludeDirectories>\n", 0);
  2543. this->WriteString("<OutputDirectory>$(ProjectDir)/$(IntDir)"
  2544. "</OutputDirectory>\n", 3);
  2545. this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
  2546. this->WriteString(
  2547. "<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
  2548. this->WriteString(
  2549. "<InterfaceIdentifierFileName>"
  2550. "%(Filename)_i.c</InterfaceIdentifierFileName>\n", 3);
  2551. this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n",3);
  2552. this->WriteString("</Midl>\n", 2);
  2553. }
  2554. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
  2555. {
  2556. for(std::vector<std::string>::const_iterator
  2557. i = this->Configurations.begin();
  2558. i != this->Configurations.end(); ++i)
  2559. {
  2560. std::vector<std::string> includes;
  2561. this->LocalGenerator->GetIncludeDirectories(includes,
  2562. this->GeneratorTarget,
  2563. "C", i->c_str());
  2564. for(std::vector<std::string>::iterator ii = includes.begin();
  2565. ii != includes.end(); ++ii)
  2566. {
  2567. this->ConvertToWindowsSlash(*ii);
  2568. }
  2569. this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
  2570. *this->BuildFileStream << "\n";
  2571. // output cl compile flags <ClCompile></ClCompile>
  2572. if(this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY)
  2573. {
  2574. this->WriteClOptions(*i, includes);
  2575. // output rc compile flags <ResourceCompile></ResourceCompile>
  2576. this->WriteRCOptions(*i, includes);
  2577. this->WriteMasmOptions(*i, includes);
  2578. }
  2579. // output midl flags <Midl></Midl>
  2580. this->WriteMidlOptions(*i, includes);
  2581. // write events
  2582. this->WriteEvents(*i);
  2583. // output link flags <Link></Link>
  2584. this->WriteLinkOptions(*i);
  2585. // output lib flags <Lib></Lib>
  2586. this->WriteLibOptions(*i);
  2587. // output manifest flags <Manifest></Manifest>
  2588. this->WriteManifestOptions(*i);
  2589. if(this->NsightTegra &&
  2590. this->GeneratorTarget->GetType() == cmState::EXECUTABLE &&
  2591. this->Target->GetPropertyAsBool("ANDROID_GUI"))
  2592. {
  2593. this->WriteAntBuildOptions(*i);
  2594. }
  2595. this->WriteString("</ItemDefinitionGroup>\n", 1);
  2596. }
  2597. }
  2598. void
  2599. cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
  2600. {
  2601. bool addedPrelink = false;
  2602. if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY &&
  2603. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
  2604. {
  2605. if (this->Target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
  2606. {
  2607. addedPrelink = true;
  2608. std::vector<cmCustomCommand> commands =
  2609. this->Target->GetPreLinkCommands();
  2610. this->GlobalGenerator->AddSymbolExportCommand(
  2611. this->GeneratorTarget, commands, configName);
  2612. this->WriteEvent("PreLinkEvent", commands, configName);
  2613. }
  2614. }
  2615. if (!addedPrelink)
  2616. {
  2617. this->WriteEvent("PreLinkEvent",
  2618. this->Target->GetPreLinkCommands(), configName);
  2619. }
  2620. this->WriteEvent("PreBuildEvent",
  2621. this->Target->GetPreBuildCommands(), configName);
  2622. this->WriteEvent("PostBuildEvent",
  2623. this->Target->GetPostBuildCommands(), configName);
  2624. }
  2625. void cmVisualStudio10TargetGenerator::WriteEvent(
  2626. const char* name,
  2627. std::vector<cmCustomCommand> const& commands,
  2628. std::string const& configName)
  2629. {
  2630. if(commands.empty())
  2631. {
  2632. return;
  2633. }
  2634. this->WriteString("<", 2);
  2635. (*this->BuildFileStream ) << name << ">\n";
  2636. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  2637. std::string script;
  2638. const char* pre = "";
  2639. std::string comment;
  2640. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  2641. i != commands.end(); ++i)
  2642. {
  2643. cmCustomCommandGenerator ccg(*i, configName, this->LocalGenerator);
  2644. comment += pre;
  2645. comment += lg->ConstructComment(ccg);
  2646. script += pre;
  2647. pre = "\n";
  2648. script += cmVS10EscapeXML(lg->ConstructScript(ccg));
  2649. }
  2650. comment = cmVS10EscapeComment(comment);
  2651. this->WriteString("<Message>",3);
  2652. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  2653. this->WriteString("<Command>", 3);
  2654. (*this->BuildFileStream ) << script;
  2655. (*this->BuildFileStream ) << "</Command>" << "\n";
  2656. this->WriteString("</", 2);
  2657. (*this->BuildFileStream ) << name << ">\n";
  2658. }
  2659. void cmVisualStudio10TargetGenerator::WriteProjectReferences()
  2660. {
  2661. cmGlobalGenerator::TargetDependSet const& unordered
  2662. = this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  2663. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  2664. OrderedTargetDependSet;
  2665. OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  2666. this->WriteString("<ItemGroup>\n", 1);
  2667. for( OrderedTargetDependSet::const_iterator i = depends.begin();
  2668. i != depends.end(); ++i)
  2669. {
  2670. cmTarget const* dt = (*i)->Target;
  2671. if(dt->GetType() == cmState::INTERFACE_LIBRARY)
  2672. {
  2673. continue;
  2674. }
  2675. // skip fortran targets as they can not be processed by MSBuild
  2676. // the only reference will be in the .sln file
  2677. if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  2678. ->TargetIsFortranOnly(*dt))
  2679. {
  2680. continue;
  2681. }
  2682. this->WriteString("<ProjectReference Include=\"", 2);
  2683. cmMakefile* mf = dt->GetMakefile();
  2684. std::string name = dt->GetName();
  2685. std::string path;
  2686. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  2687. if(p)
  2688. {
  2689. path = p;
  2690. }
  2691. else
  2692. {
  2693. path = mf->GetCurrentBinaryDirectory();
  2694. path += "/";
  2695. path += dt->GetName();
  2696. path += ".vcxproj";
  2697. }
  2698. (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n";
  2699. this->WriteString("<Project>", 3);
  2700. (*this->BuildFileStream)
  2701. << this->GlobalGenerator->GetGUID(name.c_str())
  2702. << "</Project>\n";
  2703. this->WriteString("</ProjectReference>\n", 2);
  2704. }
  2705. this->WriteString("</ItemGroup>\n", 1);
  2706. }
  2707. void cmVisualStudio10TargetGenerator::WritePlatformExtensions()
  2708. {
  2709. // This only applies to Windows 10 apps
  2710. if (this->GlobalGenerator->TargetsWindowsStore() &&
  2711. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0"))
  2712. {
  2713. const char* desktopExtensionsVersion =
  2714. this->Target->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  2715. if (desktopExtensionsVersion)
  2716. {
  2717. this->WriteSinglePlatformExtension("WindowsDesktop",
  2718. desktopExtensionsVersion);
  2719. }
  2720. const char* mobileExtensionsVersion =
  2721. this->Target->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  2722. if (mobileExtensionsVersion)
  2723. {
  2724. this->WriteSinglePlatformExtension("WindowsMobile",
  2725. mobileExtensionsVersion);
  2726. }
  2727. }
  2728. }
  2729. void cmVisualStudio10TargetGenerator::WriteSinglePlatformExtension(
  2730. std::string const& extension,
  2731. std::string const& version
  2732. )
  2733. {
  2734. this->WriteString("<Import Project=", 2);
  2735. (*this->BuildFileStream)
  2736. << "\"$([Microsoft.Build.Utilities.ToolLocationHelper]"
  2737. << "::GetPlatformExtensionSDKLocation(`"
  2738. << extension <<", Version=" << version
  2739. << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  2740. << "$(ExtensionSDKDirectoryRoot), null))"
  2741. << "\\DesignTime\\CommonConfiguration\\Neutral\\"
  2742. << extension << ".props\" "
  2743. << "Condition=\"exists('$("
  2744. << "[Microsoft.Build.Utilities.ToolLocationHelper]"
  2745. << "::GetPlatformExtensionSDKLocation(`"
  2746. << extension << ", Version=" << version
  2747. << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  2748. << "$(ExtensionSDKDirectoryRoot), null))"
  2749. << "\\DesignTime\\CommonConfiguration\\Neutral\\"
  2750. << extension << ".props')\" />\n";
  2751. }
  2752. void cmVisualStudio10TargetGenerator::WriteSDKReferences()
  2753. {
  2754. // This only applies to Windows 10 apps
  2755. if (this->GlobalGenerator->TargetsWindowsStore() &&
  2756. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0"))
  2757. {
  2758. const char* desktopExtensionsVersion =
  2759. this->Target->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  2760. const char* mobileExtensionsVersion =
  2761. this->Target->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  2762. const char* iotExtensionsVersion =
  2763. this->Target->GetProperty("VS_IOT_EXTENSIONS_VERSION");
  2764. if(desktopExtensionsVersion || mobileExtensionsVersion ||
  2765. iotExtensionsVersion)
  2766. {
  2767. this->WriteString("<ItemGroup>\n", 1);
  2768. if(desktopExtensionsVersion)
  2769. {
  2770. this->WriteSingleSDKReference("WindowsDesktop",
  2771. desktopExtensionsVersion);
  2772. }
  2773. if(mobileExtensionsVersion)
  2774. {
  2775. this->WriteSingleSDKReference("WindowsMobile",
  2776. mobileExtensionsVersion);
  2777. }
  2778. if(iotExtensionsVersion)
  2779. {
  2780. this->WriteSingleSDKReference("WindowsIoT",
  2781. iotExtensionsVersion);
  2782. }
  2783. this->WriteString("</ItemGroup>\n", 1);
  2784. }
  2785. }
  2786. }
  2787. void cmVisualStudio10TargetGenerator::WriteSingleSDKReference(
  2788. std::string const& extension,
  2789. std::string const& version
  2790. )
  2791. {
  2792. this->WriteString("<SDKReference Include=\"", 2);
  2793. (*this->BuildFileStream) << extension
  2794. << ", Version=" << version << "\" />\n";
  2795. }
  2796. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
  2797. {
  2798. if((this->GlobalGenerator->TargetsWindowsStore() ||
  2799. this->GlobalGenerator->TargetsWindowsPhone())
  2800. && (cmState::EXECUTABLE == this->GeneratorTarget->GetType()))
  2801. {
  2802. std::string pfxFile;
  2803. std::vector<cmSourceFile const*> certificates;
  2804. this->GeneratorTarget->GetCertificates(certificates, "");
  2805. for(std::vector<cmSourceFile const*>::const_iterator si =
  2806. certificates.begin(); si != certificates.end(); ++si)
  2807. {
  2808. pfxFile = this->ConvertPath((*si)->GetFullPath(), false);
  2809. this->ConvertToWindowsSlash(pfxFile);
  2810. break;
  2811. }
  2812. if(this->IsMissingFiles &&
  2813. !(this->GlobalGenerator->TargetsWindowsPhone() &&
  2814. this->GlobalGenerator->GetSystemVersion() == "8.0"))
  2815. {
  2816. // Move the manifest to a project directory to avoid clashes
  2817. std::string artifactDir =
  2818. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  2819. this->ConvertToWindowsSlash(artifactDir);
  2820. this->WriteString("<PropertyGroup>\n", 1);
  2821. this->WriteString("<AppxPackageArtifactsDir>", 2);
  2822. (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir) <<
  2823. "\\</AppxPackageArtifactsDir>\n";
  2824. this->WriteString("<ProjectPriFullPath>"
  2825. "$(TargetDir)resources.pri</ProjectPriFullPath>\n", 2);
  2826. // If we are missing files and we don't have a certificate and
  2827. // aren't targeting WP8.0, add a default certificate
  2828. if(pfxFile.empty())
  2829. {
  2830. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  2831. "/Templates/Windows";
  2832. pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  2833. cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
  2834. pfxFile, false);
  2835. this->ConvertToWindowsSlash(pfxFile);
  2836. this->AddedFiles.push_back(pfxFile);
  2837. }
  2838. this->WriteString("<", 2);
  2839. (*this->BuildFileStream) << "PackageCertificateKeyFile>"
  2840. << pfxFile << "</PackageCertificateKeyFile>\n";
  2841. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  2842. if (!thumb.empty())
  2843. {
  2844. this->WriteString("<PackageCertificateThumbprint>", 2);
  2845. (*this->BuildFileStream) << thumb
  2846. << "</PackageCertificateThumbprint>\n";
  2847. }
  2848. this->WriteString("</PropertyGroup>\n", 1);
  2849. }
  2850. else if(!pfxFile.empty())
  2851. {
  2852. this->WriteString("<PropertyGroup>\n", 1);
  2853. this->WriteString("<", 2);
  2854. (*this->BuildFileStream) << "PackageCertificateKeyFile>"
  2855. << pfxFile << "</PackageCertificateKeyFile>\n";
  2856. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  2857. if (!thumb.empty())
  2858. {
  2859. this->WriteString("<PackageCertificateThumbprint>", 2);
  2860. (*this->BuildFileStream) << thumb
  2861. << "</PackageCertificateThumbprint>\n";
  2862. }
  2863. this->WriteString("</PropertyGroup>\n", 1);
  2864. }
  2865. }
  2866. }
  2867. bool cmVisualStudio10TargetGenerator::
  2868. IsResxHeader(const std::string& headerFile)
  2869. {
  2870. std::set<std::string> expectedResxHeaders;
  2871. this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
  2872. std::set<std::string>::const_iterator it =
  2873. expectedResxHeaders.find(headerFile);
  2874. return it != expectedResxHeaders.end();
  2875. }
  2876. bool cmVisualStudio10TargetGenerator::
  2877. IsXamlHeader(const std::string& headerFile)
  2878. {
  2879. std::set<std::string> expectedXamlHeaders;
  2880. this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
  2881. std::set<std::string>::const_iterator it =
  2882. expectedXamlHeaders.find(headerFile);
  2883. return it != expectedXamlHeaders.end();
  2884. }
  2885. bool cmVisualStudio10TargetGenerator::
  2886. IsXamlSource(const std::string& sourceFile)
  2887. {
  2888. std::set<std::string> expectedXamlSources;
  2889. this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
  2890. std::set<std::string>::const_iterator it =
  2891. expectedXamlSources.find(sourceFile);
  2892. return it != expectedXamlSources.end();
  2893. }
  2894. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
  2895. {
  2896. cmGlobalVisualStudio10Generator* gg =
  2897. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2898. bool isAppContainer = false;
  2899. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  2900. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  2901. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2902. if(isWindowsPhone || isWindowsStore)
  2903. {
  2904. this->WriteString("<ApplicationType>", 2);
  2905. (*this->BuildFileStream) << (isWindowsPhone ?
  2906. "Windows Phone" : "Windows Store")
  2907. << "</ApplicationType>\n";
  2908. this->WriteString("<DefaultLanguage>en-US"
  2909. "</DefaultLanguage>\n", 2);
  2910. if (cmHasLiteralPrefix(v, "10.0"))
  2911. {
  2912. this->WriteString("<ApplicationTypeRevision>", 2);
  2913. (*this->BuildFileStream) << cmVS10EscapeXML("10.0")
  2914. << "</ApplicationTypeRevision>\n";
  2915. // Visual Studio 14.0 is necessary for building 10.0 apps
  2916. this->WriteString("<MinimumVisualStudioVersion>14.0"
  2917. "</MinimumVisualStudioVersion>\n", 2);
  2918. if(this->GeneratorTarget->GetType() < cmState::UTILITY)
  2919. {
  2920. isAppContainer = true;
  2921. }
  2922. }
  2923. else if(v == "8.1")
  2924. {
  2925. this->WriteString("<ApplicationTypeRevision>", 2);
  2926. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  2927. << "</ApplicationTypeRevision>\n";
  2928. // Visual Studio 12.0 is necessary for building 8.1 apps
  2929. this->WriteString("<MinimumVisualStudioVersion>12.0"
  2930. "</MinimumVisualStudioVersion>\n", 2);
  2931. if (this->GeneratorTarget->GetType() < cmState::UTILITY)
  2932. {
  2933. isAppContainer = true;
  2934. }
  2935. }
  2936. else if (v == "8.0")
  2937. {
  2938. this->WriteString("<ApplicationTypeRevision>", 2);
  2939. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  2940. << "</ApplicationTypeRevision>\n";
  2941. // Visual Studio 11.0 is necessary for building 8.0 apps
  2942. this->WriteString("<MinimumVisualStudioVersion>11.0"
  2943. "</MinimumVisualStudioVersion>\n", 2);
  2944. if (isWindowsStore
  2945. && this->GeneratorTarget->GetType() < cmState::UTILITY)
  2946. {
  2947. isAppContainer = true;
  2948. }
  2949. else if (isWindowsPhone &&
  2950. this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
  2951. {
  2952. this->WriteString("<XapOutputs>true</XapOutputs>\n", 2);
  2953. this->WriteString("<XapFilename>", 2);
  2954. (*this->BuildFileStream) << cmVS10EscapeXML(this->Name.c_str()) <<
  2955. "_$(Configuration)_$(Platform).xap</XapFilename>\n";
  2956. }
  2957. }
  2958. }
  2959. if(isAppContainer)
  2960. {
  2961. this->WriteString("<AppContainerApplication>true"
  2962. "</AppContainerApplication>\n", 2);
  2963. }
  2964. else if (this->Platform == "ARM")
  2965. {
  2966. this->WriteString("<WindowsSDKDesktopARMSupport>true"
  2967. "</WindowsSDKDesktopARMSupport>\n", 2);
  2968. }
  2969. std::string const& targetPlatformVersion =
  2970. gg->GetWindowsTargetPlatformVersion();
  2971. if (!targetPlatformVersion.empty())
  2972. {
  2973. this->WriteString("<WindowsTargetPlatformVersion>", 2);
  2974. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion) <<
  2975. "</WindowsTargetPlatformVersion>\n";
  2976. }
  2977. const char* targetPlatformMinVersion =
  2978. this->Target->GetProperty("VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
  2979. if(targetPlatformMinVersion)
  2980. {
  2981. this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
  2982. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformMinVersion) <<
  2983. "</WindowsTargetPlatformMinVersion>\n";
  2984. }
  2985. else if (isWindowsStore && cmHasLiteralPrefix(v, "10.0"))
  2986. {
  2987. // If the min version is not set, then use the TargetPlatformVersion
  2988. if (!targetPlatformVersion.empty())
  2989. {
  2990. this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
  2991. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion) <<
  2992. "</WindowsTargetPlatformMinVersion>\n";
  2993. }
  2994. }
  2995. // Added IoT Startup Task support
  2996. if(this->Target->GetPropertyAsBool("VS_IOT_STARTUP_TASK"))
  2997. {
  2998. this->WriteString("<ContainsStartupTask>true</ContainsStartupTask>\n", 2);
  2999. }
  3000. }
  3001. void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
  3002. {
  3003. // For Windows and Windows Phone executables, we will assume that if a
  3004. // manifest is not present that we need to add all the necessary files
  3005. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE)
  3006. {
  3007. std::vector<cmSourceFile const*> manifestSources;
  3008. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  3009. {
  3010. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3011. if(this->GlobalGenerator->TargetsWindowsPhone())
  3012. {
  3013. if (v == "8.0")
  3014. {
  3015. // Look through the sources for WMAppManifest.xml
  3016. std::vector<cmSourceFile const*> extraSources;
  3017. this->GeneratorTarget->GetExtraSources(extraSources, "");
  3018. bool foundManifest = false;
  3019. for(std::vector<cmSourceFile const*>::const_iterator si =
  3020. extraSources.begin(); si != extraSources.end(); ++si)
  3021. {
  3022. // Need to do a lowercase comparison on the filename
  3023. if("wmappmanifest.xml" == cmSystemTools::LowerCase(
  3024. (*si)->GetLocation().GetName()))
  3025. {
  3026. foundManifest = true;
  3027. break;
  3028. }
  3029. }
  3030. if (!foundManifest)
  3031. {
  3032. this->IsMissingFiles = true;
  3033. }
  3034. }
  3035. else if (v == "8.1")
  3036. {
  3037. if(manifestSources.empty())
  3038. {
  3039. this->IsMissingFiles = true;
  3040. }
  3041. }
  3042. }
  3043. else if (this->GlobalGenerator->TargetsWindowsStore())
  3044. {
  3045. if (manifestSources.empty())
  3046. {
  3047. if (v == "8.0")
  3048. {
  3049. this->IsMissingFiles = true;
  3050. }
  3051. else if (v == "8.1" || cmHasLiteralPrefix(v, "10.0"))
  3052. {
  3053. this->IsMissingFiles = true;
  3054. }
  3055. }
  3056. }
  3057. }
  3058. }
  3059. }
  3060. void cmVisualStudio10TargetGenerator::WriteMissingFiles()
  3061. {
  3062. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3063. if(this->GlobalGenerator->TargetsWindowsPhone())
  3064. {
  3065. if (v == "8.0")
  3066. {
  3067. this->WriteMissingFilesWP80();
  3068. }
  3069. else if (v == "8.1")
  3070. {
  3071. this->WriteMissingFilesWP81();
  3072. }
  3073. }
  3074. else if (this->GlobalGenerator->TargetsWindowsStore())
  3075. {
  3076. if (v == "8.0")
  3077. {
  3078. this->WriteMissingFilesWS80();
  3079. }
  3080. else if (v == "8.1")
  3081. {
  3082. this->WriteMissingFilesWS81();
  3083. }
  3084. else if (cmHasLiteralPrefix(v, "10.0"))
  3085. {
  3086. this->WriteMissingFilesWS10_0();
  3087. }
  3088. }
  3089. }
  3090. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
  3091. {
  3092. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  3093. "/Templates/Windows";
  3094. // For WP80, the manifest needs to be in the same folder as the project
  3095. // this can cause an overwrite problem if projects aren't organized in
  3096. // folders
  3097. std::string manifestFile =
  3098. this->LocalGenerator->GetCurrentBinaryDirectory() +
  3099. std::string("/WMAppManifest.xml");
  3100. std::string artifactDir =
  3101. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3102. this->ConvertToWindowsSlash(artifactDir);
  3103. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3104. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  3105. cmGeneratedFileStream fout(manifestFile.c_str());
  3106. fout.SetCopyIfDifferent(true);
  3107. fout <<
  3108. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3109. "<Deployment"
  3110. " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
  3111. " AppPlatformVersion=\"8.0\">\n"
  3112. "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
  3113. "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
  3114. " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
  3115. " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
  3116. " Description=\"Default CMake App\" Publisher=\"CMake\""
  3117. " PublisherID=\"{" << this->GUID << "}\">\n"
  3118. "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
  3119. << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
  3120. "\t\t<Capabilities/>\n"
  3121. "\t\t<Tasks>\n"
  3122. "\t\t\t<DefaultTask Name=\"_default\""
  3123. " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
  3124. "\t\t</Tasks>\n"
  3125. "\t\t<Tokens>\n"
  3126. "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
  3127. " TaskName=\"_default\">\n"
  3128. "\t\t\t\t<TemplateFlip>\n"
  3129. "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
  3130. << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
  3131. "\t\t\t\t\t<Count>0</Count>\n"
  3132. "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
  3133. << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
  3134. "\t\t\t\t</TemplateFlip>\n"
  3135. "\t\t\t</PrimaryToken>\n"
  3136. "\t\t</Tokens>\n"
  3137. "\t\t<ScreenResolutions>\n"
  3138. "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
  3139. "\t\t</ScreenResolutions>\n"
  3140. "\t</App>\n"
  3141. "</Deployment>\n";
  3142. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3143. this->ConvertToWindowsSlash(sourceFile);
  3144. this->WriteString("<Xml Include=\"", 2);
  3145. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  3146. this->WriteString("<SubType>Designer</SubType>\n", 3);
  3147. this->WriteString("</Xml>\n", 2);
  3148. this->AddedFiles.push_back(sourceFile);
  3149. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3150. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png",
  3151. smallLogo, false);
  3152. this->ConvertToWindowsSlash(smallLogo);
  3153. this->WriteString("<Image Include=\"", 2);
  3154. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  3155. this->AddedFiles.push_back(smallLogo);
  3156. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3157. cmSystemTools::CopyAFile(templateFolder + "/Logo.png",
  3158. logo, false);
  3159. this->ConvertToWindowsSlash(logo);
  3160. this->WriteString("<Image Include=\"", 2);
  3161. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  3162. this->AddedFiles.push_back(logo);
  3163. std::string applicationIcon =
  3164. this->DefaultArtifactDir + "/ApplicationIcon.png";
  3165. cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
  3166. applicationIcon, false);
  3167. this->ConvertToWindowsSlash(applicationIcon);
  3168. this->WriteString("<Image Include=\"", 2);
  3169. (*this->BuildFileStream) << cmVS10EscapeXML(applicationIcon) << "\" />\n";
  3170. this->AddedFiles.push_back(applicationIcon);
  3171. }
  3172. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
  3173. {
  3174. std::string manifestFile =
  3175. this->DefaultArtifactDir + "/package.appxManifest";
  3176. std::string artifactDir =
  3177. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3178. this->ConvertToWindowsSlash(artifactDir);
  3179. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3180. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  3181. cmGeneratedFileStream fout(manifestFile.c_str());
  3182. fout.SetCopyIfDifferent(true);
  3183. fout <<
  3184. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3185. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  3186. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
  3187. " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
  3188. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3189. " Version=\"1.0.0.0\" />\n"
  3190. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
  3191. " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  3192. "\t<Properties>\n"
  3193. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3194. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3195. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3196. "\t</Properties>\n"
  3197. "\t<Prerequisites>\n"
  3198. "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
  3199. "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
  3200. "\t</Prerequisites>\n"
  3201. "\t<Resources>\n"
  3202. "\t\t<Resource Language=\"x-generate\" />\n"
  3203. "\t</Resources>\n"
  3204. "\t<Applications>\n"
  3205. "\t\t<Application Id=\"App\""
  3206. " Executable=\"" << targetNameXML << ".exe\""
  3207. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3208. "\t\t\t<m2:VisualElements\n"
  3209. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3210. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3211. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3212. "\t\t\t\tForegroundText=\"light\"\n"
  3213. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3214. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3215. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  3216. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  3217. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  3218. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  3219. "\t\t\t\t</m2:DefaultTile>\n"
  3220. "\t\t\t\t<m2:SplashScreen"
  3221. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3222. "\t\t\t</m2:VisualElements>\n"
  3223. "\t\t</Application>\n"
  3224. "\t</Applications>\n"
  3225. "</Package>\n";
  3226. this->WriteCommonMissingFiles(manifestFile);
  3227. }
  3228. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
  3229. {
  3230. std::string manifestFile =
  3231. this->DefaultArtifactDir + "/package.appxManifest";
  3232. std::string artifactDir =
  3233. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3234. this->ConvertToWindowsSlash(artifactDir);
  3235. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3236. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  3237. cmGeneratedFileStream fout(manifestFile.c_str());
  3238. fout.SetCopyIfDifferent(true);
  3239. fout <<
  3240. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3241. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
  3242. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3243. " Version=\"1.0.0.0\" />\n"
  3244. "\t<Properties>\n"
  3245. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3246. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3247. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3248. "\t</Properties>\n"
  3249. "\t<Prerequisites>\n"
  3250. "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
  3251. "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
  3252. "\t</Prerequisites>\n"
  3253. "\t<Resources>\n"
  3254. "\t\t<Resource Language=\"x-generate\" />\n"
  3255. "\t</Resources>\n"
  3256. "\t<Applications>\n"
  3257. "\t\t<Application Id=\"App\""
  3258. " Executable=\"" << targetNameXML << ".exe\""
  3259. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3260. "\t\t\t<VisualElements"
  3261. " DisplayName=\"" << targetNameXML << "\""
  3262. " Description=\"" << targetNameXML << "\""
  3263. " BackgroundColor=\"#336699\" ForegroundText=\"light\""
  3264. " Logo=\"" << artifactDirXML << "\\Logo.png\""
  3265. " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3266. "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
  3267. " ShortName=\"" << targetNameXML << "\" />\n"
  3268. "\t\t\t\t<SplashScreen"
  3269. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3270. "\t\t\t</VisualElements>\n"
  3271. "\t\t</Application>\n"
  3272. "\t</Applications>\n"
  3273. "</Package>\n";
  3274. this->WriteCommonMissingFiles(manifestFile);
  3275. }
  3276. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
  3277. {
  3278. std::string manifestFile =
  3279. this->DefaultArtifactDir + "/package.appxManifest";
  3280. std::string artifactDir =
  3281. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3282. this->ConvertToWindowsSlash(artifactDir);
  3283. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3284. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  3285. cmGeneratedFileStream fout(manifestFile.c_str());
  3286. fout.SetCopyIfDifferent(true);
  3287. fout <<
  3288. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3289. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  3290. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
  3291. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3292. " Version=\"1.0.0.0\" />\n"
  3293. "\t<Properties>\n"
  3294. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3295. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3296. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3297. "\t</Properties>\n"
  3298. "\t<Prerequisites>\n"
  3299. "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
  3300. "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
  3301. "\t</Prerequisites>\n"
  3302. "\t<Resources>\n"
  3303. "\t\t<Resource Language=\"x-generate\" />\n"
  3304. "\t</Resources>\n"
  3305. "\t<Applications>\n"
  3306. "\t\t<Application Id=\"App\""
  3307. " Executable=\"" << targetNameXML << ".exe\""
  3308. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3309. "\t\t\t<m2:VisualElements\n"
  3310. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3311. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3312. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3313. "\t\t\t\tForegroundText=\"light\"\n"
  3314. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3315. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3316. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  3317. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  3318. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  3319. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  3320. "\t\t\t\t</m2:DefaultTile>\n"
  3321. "\t\t\t\t<m2:SplashScreen"
  3322. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3323. "\t\t\t</m2:VisualElements>\n"
  3324. "\t\t</Application>\n"
  3325. "\t</Applications>\n"
  3326. "</Package>\n";
  3327. this->WriteCommonMissingFiles(manifestFile);
  3328. }
  3329. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0()
  3330. {
  3331. std::string manifestFile =
  3332. this->DefaultArtifactDir + "/package.appxManifest";
  3333. std::string artifactDir =
  3334. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3335. this->ConvertToWindowsSlash(artifactDir);
  3336. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3337. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  3338. cmGeneratedFileStream fout(manifestFile.c_str());
  3339. fout.SetCopyIfDifferent(true);
  3340. fout <<
  3341. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3342. "<Package\n\t"
  3343. "xmlns=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10\""
  3344. "\txmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\"\n"
  3345. "\txmlns:uap=\"http://schemas.microsoft.com/appx/manifest/uap/windows10\""
  3346. "\n\tIgnorableNamespaces=\"uap mp\">\n\n"
  3347. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3348. " Version=\"1.0.0.0\" />\n"
  3349. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID <<
  3350. "\" PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  3351. "\t<Properties>\n"
  3352. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3353. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3354. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3355. "\t</Properties>\n"
  3356. "\t<Dependencies>\n"
  3357. "\t\t<TargetDeviceFamily Name=\"Windows.Universal\" "
  3358. "MinVersion=\"10.0.0.0\" MaxVersionTested=\"10.0.0.0\" />\n"
  3359. "\t</Dependencies>\n"
  3360. "\t<Resources>\n"
  3361. "\t\t<Resource Language=\"x-generate\" />\n"
  3362. "\t</Resources>\n"
  3363. "\t<Applications>\n"
  3364. "\t\t<Application Id=\"App\""
  3365. " Executable=\"" << targetNameXML << ".exe\""
  3366. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3367. "\t\t\t<uap:VisualElements\n"
  3368. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3369. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3370. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3371. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3372. "\t\t\t\tSquare44x44Logo=\"" << artifactDirXML <<
  3373. "\\SmallLogo44x44.png\">\n"
  3374. "\t\t\t\t<uap:SplashScreen"
  3375. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3376. "\t\t\t</uap:VisualElements>\n"
  3377. "\t\t</Application>\n"
  3378. "\t</Applications>\n"
  3379. "</Package>\n";
  3380. this->WriteCommonMissingFiles(manifestFile);
  3381. }
  3382. void
  3383. cmVisualStudio10TargetGenerator
  3384. ::WriteCommonMissingFiles(const std::string& manifestFile)
  3385. {
  3386. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  3387. "/Templates/Windows";
  3388. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3389. this->ConvertToWindowsSlash(sourceFile);
  3390. this->WriteString("<AppxManifest Include=\"", 2);
  3391. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  3392. this->WriteString("<SubType>Designer</SubType>\n", 3);
  3393. this->WriteString("</AppxManifest>\n", 2);
  3394. this->AddedFiles.push_back(sourceFile);
  3395. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3396. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png",
  3397. smallLogo, false);
  3398. this->ConvertToWindowsSlash(smallLogo);
  3399. this->WriteString("<Image Include=\"", 2);
  3400. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  3401. this->AddedFiles.push_back(smallLogo);
  3402. std::string smallLogo44 = this->DefaultArtifactDir + "/SmallLogo44x44.png";
  3403. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo44x44.png",
  3404. smallLogo44, false);
  3405. this->ConvertToWindowsSlash(smallLogo44);
  3406. this->WriteString("<Image Include=\"", 2);
  3407. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo44) << "\" />\n";
  3408. this->AddedFiles.push_back(smallLogo44);
  3409. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3410. cmSystemTools::CopyAFile(templateFolder + "/Logo.png",
  3411. logo, false);
  3412. this->ConvertToWindowsSlash(logo);
  3413. this->WriteString("<Image Include=\"", 2);
  3414. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  3415. this->AddedFiles.push_back(logo);
  3416. std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
  3417. cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png",
  3418. storeLogo, false);
  3419. this->ConvertToWindowsSlash(storeLogo);
  3420. this->WriteString("<Image Include=\"", 2);
  3421. (*this->BuildFileStream) << cmVS10EscapeXML(storeLogo) << "\" />\n";
  3422. this->AddedFiles.push_back(storeLogo);
  3423. std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
  3424. cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png",
  3425. splashScreen, false);
  3426. this->ConvertToWindowsSlash(splashScreen);
  3427. this->WriteString("<Image Include=\"", 2);
  3428. (*this->BuildFileStream) << cmVS10EscapeXML(splashScreen) << "\" />\n";
  3429. this->AddedFiles.push_back(splashScreen);
  3430. // This file has already been added to the build so don't copy it
  3431. std::string keyFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  3432. this->ConvertToWindowsSlash(keyFile);
  3433. this->WriteString("<None Include=\"", 2);
  3434. (*this->BuildFileStream) << cmVS10EscapeXML(keyFile) << "\" />\n";
  3435. }
  3436. bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
  3437. {
  3438. HANDLE h = CreateFileW(
  3439. cmSystemTools::ConvertToWindowsExtendedPath(source).c_str(),
  3440. FILE_WRITE_ATTRIBUTES,
  3441. FILE_SHARE_WRITE, 0, OPEN_EXISTING,
  3442. FILE_FLAG_BACKUP_SEMANTICS, 0);
  3443. if (!h)
  3444. {
  3445. return false;
  3446. }
  3447. FILETIME const ftime_20010101 = { 3365781504u, 29389701u };
  3448. if (!SetFileTime(h, &ftime_20010101, &ftime_20010101, &ftime_20010101))
  3449. {
  3450. CloseHandle(h);
  3451. return false;
  3452. }
  3453. CloseHandle(h);
  3454. return true;
  3455. }