cmVisualStudio10TargetGenerator.cxx 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714
  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->Target);
  189. }
  190. cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
  191. {
  192. for(OptionsMap::iterator i = this->ClOptions.begin();
  193. i != this->ClOptions.end(); ++i)
  194. {
  195. delete i->second;
  196. }
  197. for(OptionsMap::iterator i = this->LinkOptions.begin();
  198. i != this->LinkOptions.end(); ++i)
  199. {
  200. delete i->second;
  201. }
  202. if(!this->BuildFileStream)
  203. {
  204. return;
  205. }
  206. if (this->BuildFileStream->Close())
  207. {
  208. this->GlobalGenerator
  209. ->FileReplacedDuringGenerate(this->PathToVcxproj);
  210. }
  211. delete this->BuildFileStream;
  212. }
  213. void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
  214. const char* tag,
  215. const std::string& config,
  216. int indentLevel,
  217. const char* attribute,
  218. const char* end,
  219. std::ostream* stream)
  220. {
  221. if(!stream)
  222. {
  223. stream = this->BuildFileStream;
  224. }
  225. stream->fill(' ');
  226. stream->width(indentLevel*2 );
  227. (*stream ) << "";
  228. (*stream ) << "<" << tag
  229. << " Condition=\"'$(Configuration)|$(Platform)'=='";
  230. (*stream ) << config << "|" << this->Platform << "'\"";
  231. if(attribute)
  232. {
  233. (*stream ) << attribute;
  234. }
  235. // close the tag
  236. (*stream ) << ">";
  237. if(end)
  238. {
  239. (*stream ) << end;
  240. }
  241. }
  242. void cmVisualStudio10TargetGenerator::WriteString(const char* line,
  243. int indentLevel)
  244. {
  245. this->BuildFileStream->fill(' ');
  246. this->BuildFileStream->width(indentLevel*2 );
  247. // write an empty string to get the fill level indent to print
  248. (*this->BuildFileStream ) << "";
  249. (*this->BuildFileStream ) << line;
  250. }
  251. #define VS10_USER_PROPS "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props"
  252. void cmVisualStudio10TargetGenerator::Generate()
  253. {
  254. // do not generate external ms projects
  255. if(this->GeneratorTarget->GetType() == cmTarget::INTERFACE_LIBRARY
  256. || this->Target->GetProperty("EXTERNAL_MSPROJECT"))
  257. {
  258. return;
  259. }
  260. // Tell the global generator the name of the project file
  261. this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
  262. this->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
  263. ".vcxproj");
  264. if(this->GeneratorTarget->GetType() <= cmTarget::OBJECT_LIBRARY)
  265. {
  266. if(!this->ComputeClOptions())
  267. {
  268. return;
  269. }
  270. if(!this->ComputeRcOptions())
  271. {
  272. return;
  273. }
  274. if(!this->ComputeMasmOptions())
  275. {
  276. return;
  277. }
  278. if(!this->ComputeLinkOptions())
  279. {
  280. return;
  281. }
  282. }
  283. 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() <= cmTarget::GLOBAL_TARGET)
  343. {
  344. this->WriteApplicationTypeSettings();
  345. this->VerifyNecessaryFiles();
  346. }
  347. const char* vsProjectTypes =
  348. this->Target->GetProperty("VS_GLOBAL_PROJECT_TYPES");
  349. if(vsProjectTypes)
  350. {
  351. this->WriteString("<ProjectTypes>", 2);
  352. (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectTypes) <<
  353. "</ProjectTypes>\n";
  354. }
  355. const char* vsProjectName = this->Target->GetProperty("VS_SCC_PROJECTNAME");
  356. const char* vsLocalPath = this->Target->GetProperty("VS_SCC_LOCALPATH");
  357. const char* vsProvider = this->Target->GetProperty("VS_SCC_PROVIDER");
  358. if( vsProjectName && vsLocalPath && vsProvider )
  359. {
  360. this->WriteString("<SccProjectName>", 2);
  361. (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectName) <<
  362. "</SccProjectName>\n";
  363. this->WriteString("<SccLocalPath>", 2);
  364. (*this->BuildFileStream) << cmVS10EscapeXML(vsLocalPath) <<
  365. "</SccLocalPath>\n";
  366. this->WriteString("<SccProvider>", 2);
  367. (*this->BuildFileStream) << cmVS10EscapeXML(vsProvider) <<
  368. "</SccProvider>\n";
  369. const char* vsAuxPath = this->Target->GetProperty("VS_SCC_AUXPATH");
  370. if( vsAuxPath )
  371. {
  372. this->WriteString("<SccAuxPath>", 2);
  373. (*this->BuildFileStream) << cmVS10EscapeXML(vsAuxPath) <<
  374. "</SccAuxPath>\n";
  375. }
  376. }
  377. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
  378. {
  379. this->WriteString("<WinMDAssembly>true</WinMDAssembly>\n", 2);
  380. }
  381. const char* vsGlobalKeyword =
  382. this->Target->GetProperty("VS_GLOBAL_KEYWORD");
  383. if(!vsGlobalKeyword)
  384. {
  385. this->WriteString("<Keyword>Win32Proj</Keyword>\n", 2);
  386. }
  387. else
  388. {
  389. this->WriteString("<Keyword>", 2);
  390. (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalKeyword) <<
  391. "</Keyword>\n";
  392. }
  393. const char* vsGlobalRootNamespace =
  394. this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
  395. if(vsGlobalRootNamespace)
  396. {
  397. this->WriteString("<RootNamespace>", 2);
  398. (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalRootNamespace) <<
  399. "</RootNamespace>\n";
  400. }
  401. this->WriteString("<Platform>", 2);
  402. (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
  403. << "</Platform>\n";
  404. const char* projLabel = this->Target->GetProperty("PROJECT_LABEL");
  405. if(!projLabel)
  406. {
  407. projLabel = this->Name.c_str();
  408. }
  409. this->WriteString("<ProjectName>", 2);
  410. (*this->BuildFileStream) << cmVS10EscapeXML(projLabel) << "</ProjectName>\n";
  411. if(const char* targetFrameworkVersion = this->Target->GetProperty(
  412. "VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
  413. {
  414. this->WriteString("<TargetFrameworkVersion>", 2);
  415. (*this->BuildFileStream) << cmVS10EscapeXML(targetFrameworkVersion)
  416. << "</TargetFrameworkVersion>\n";
  417. }
  418. this->WriteString("</PropertyGroup>\n", 1);
  419. this->WriteString("<Import Project="
  420. "\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n",
  421. 1);
  422. this->WriteProjectConfigurationValues();
  423. this->WriteString(
  424. "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n", 1);
  425. this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1);
  426. if (this->GlobalGenerator->IsMasmEnabled())
  427. {
  428. this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
  429. "BuildCustomizations\\masm.props\" />\n", 2);
  430. }
  431. this->WriteString("</ImportGroup>\n", 1);
  432. this->WriteString("<ImportGroup Label=\"PropertySheets\">\n", 1);
  433. this->WriteString("<Import Project=\"" VS10_USER_PROPS "\""
  434. " Condition=\"exists('" VS10_USER_PROPS "')\""
  435. " Label=\"LocalAppDataPlatform\" />\n", 2);
  436. this->WritePlatformExtensions();
  437. this->WriteString("</ImportGroup>\n", 1);
  438. this->WriteString("<PropertyGroup Label=\"UserMacros\" />\n", 1);
  439. this->WriteWinRTPackageCertificateKeyFile();
  440. this->WritePathAndIncrementalLinkOptions();
  441. this->WriteItemDefinitionGroups();
  442. this->WriteCustomCommands();
  443. this->WriteAllSources();
  444. this->WriteDotNetReferences();
  445. this->WriteEmbeddedResourceGroup();
  446. this->WriteXamlFilesGroup();
  447. this->WriteWinRTReferences();
  448. this->WriteProjectReferences();
  449. this->WriteSDKReferences();
  450. this->WriteString(
  451. "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\""
  452. " />\n", 1);
  453. this->WriteTargetSpecificReferences();
  454. this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
  455. if (this->GlobalGenerator->IsMasmEnabled())
  456. {
  457. this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
  458. "BuildCustomizations\\masm.targets\" />\n", 2);
  459. }
  460. this->WriteString("</ImportGroup>\n", 1);
  461. this->WriteString("</Project>", 0);
  462. // The groups are stored in a separate file for VS 10
  463. this->WriteGroups();
  464. }
  465. void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
  466. {
  467. std::vector<std::string> references;
  468. if(const char* vsDotNetReferences =
  469. this->Target->GetProperty("VS_DOTNET_REFERENCES"))
  470. {
  471. cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
  472. }
  473. if(!references.empty())
  474. {
  475. this->WriteString("<ItemGroup>\n", 1);
  476. for(std::vector<std::string>::iterator ri = references.begin();
  477. ri != references.end(); ++ri)
  478. {
  479. this->WriteString("<Reference Include=\"", 2);
  480. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
  481. this->WriteString("<CopyLocalSatelliteAssemblies>true"
  482. "</CopyLocalSatelliteAssemblies>\n", 3);
  483. this->WriteString("<ReferenceOutputAssembly>true"
  484. "</ReferenceOutputAssembly>\n", 3);
  485. this->WriteString("</Reference>\n", 2);
  486. }
  487. this->WriteString("</ItemGroup>\n", 1);
  488. }
  489. }
  490. void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
  491. {
  492. std::vector<cmSourceFile const*> resxObjs;
  493. this->GeneratorTarget->GetResxSources(resxObjs, "");
  494. if(!resxObjs.empty())
  495. {
  496. this->WriteString("<ItemGroup>\n", 1);
  497. for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
  498. oi != resxObjs.end(); ++oi)
  499. {
  500. std::string obj = (*oi)->GetFullPath();
  501. this->WriteString("<EmbeddedResource Include=\"", 2);
  502. this->ConvertToWindowsSlash(obj);
  503. (*this->BuildFileStream ) << obj << "\">\n";
  504. this->WriteString("<DependentUpon>", 3);
  505. std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h";
  506. (*this->BuildFileStream) << hFileName << "</DependentUpon>\n";
  507. for(std::vector<std::string>::const_iterator
  508. i = this->Configurations.begin();
  509. i != this->Configurations.end(); ++i)
  510. {
  511. this->WritePlatformConfigTag("LogicalName", i->c_str(), 3);
  512. if(this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE"))
  513. {
  514. (*this->BuildFileStream ) << "$(RootNamespace).";
  515. }
  516. (*this->BuildFileStream ) << "%(Filename)";
  517. (*this->BuildFileStream ) << ".resources";
  518. (*this->BuildFileStream ) << "</LogicalName>\n";
  519. }
  520. this->WriteString("</EmbeddedResource>\n", 2);
  521. }
  522. this->WriteString("</ItemGroup>\n", 1);
  523. }
  524. }
  525. void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup()
  526. {
  527. std::vector<cmSourceFile const*> xamlObjs;
  528. this->GeneratorTarget->GetXamlSources(xamlObjs, "");
  529. if (!xamlObjs.empty())
  530. {
  531. this->WriteString("<ItemGroup>\n", 1);
  532. for (std::vector<cmSourceFile const*>::const_iterator
  533. oi = xamlObjs.begin(); oi != xamlObjs.end(); ++oi)
  534. {
  535. std::string obj = (*oi)->GetFullPath();
  536. std::string xamlType;
  537. const char * xamlTypeProperty = (*oi)->GetProperty("VS_XAML_TYPE");
  538. if (xamlTypeProperty)
  539. {
  540. xamlType = xamlTypeProperty;
  541. }
  542. else
  543. {
  544. xamlType = "Page";
  545. }
  546. this->WriteSource(xamlType, *oi, ">\n");
  547. this->WriteString("<SubType>Designer</SubType>\n", 3);
  548. this->WriteString("</", 2);
  549. (*this->BuildFileStream) << xamlType << ">\n";
  550. }
  551. this->WriteString("</ItemGroup>\n", 1);
  552. }
  553. }
  554. void cmVisualStudio10TargetGenerator::WriteTargetSpecificReferences()
  555. {
  556. if(this->MSTools)
  557. {
  558. if(this->GlobalGenerator->TargetsWindowsPhone() &&
  559. this->GlobalGenerator->GetSystemVersion() == "8.0")
  560. {
  561. this->WriteString(
  562. "<Import Project=\""
  563. "$(MSBuildExtensionsPath)\\Microsoft\\WindowsPhone\\v"
  564. "$(TargetPlatformVersion)\\Microsoft.Cpp.WindowsPhone."
  565. "$(TargetPlatformVersion).targets\" />\n", 1);
  566. }
  567. }
  568. }
  569. void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
  570. {
  571. std::vector<std::string> references;
  572. if(const char* vsWinRTReferences =
  573. this->Target->GetProperty("VS_WINRT_REFERENCES"))
  574. {
  575. cmSystemTools::ExpandListArgument(vsWinRTReferences, references);
  576. }
  577. if(this->GlobalGenerator->TargetsWindowsPhone() &&
  578. this->GlobalGenerator->GetSystemVersion() == "8.0" &&
  579. references.empty())
  580. {
  581. references.push_back("platform.winmd");
  582. }
  583. if(!references.empty())
  584. {
  585. this->WriteString("<ItemGroup>\n", 1);
  586. for(std::vector<std::string>::iterator ri = references.begin();
  587. ri != references.end(); ++ri)
  588. {
  589. this->WriteString("<Reference Include=\"", 2);
  590. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
  591. this->WriteString("<IsWinMDFile>true</IsWinMDFile>\n", 3);
  592. this->WriteString("</Reference>\n", 2);
  593. }
  594. this->WriteString("</ItemGroup>\n", 1);
  595. }
  596. }
  597. // ConfigurationType Application, Utility StaticLibrary DynamicLibrary
  598. void cmVisualStudio10TargetGenerator::WriteProjectConfigurations()
  599. {
  600. this->WriteString("<ItemGroup Label=\"ProjectConfigurations\">\n", 1);
  601. for(std::vector<std::string>::const_iterator
  602. i = this->Configurations.begin();
  603. i != this->Configurations.end(); ++i)
  604. {
  605. this->WriteString("<ProjectConfiguration Include=\"", 2);
  606. (*this->BuildFileStream ) << *i << "|" << this->Platform << "\">\n";
  607. this->WriteString("<Configuration>", 3);
  608. (*this->BuildFileStream ) << *i << "</Configuration>\n";
  609. this->WriteString("<Platform>", 3);
  610. (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
  611. << "</Platform>\n";
  612. this->WriteString("</ProjectConfiguration>\n", 2);
  613. }
  614. this->WriteString("</ItemGroup>\n", 1);
  615. }
  616. void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
  617. {
  618. for(std::vector<std::string>::const_iterator
  619. i = this->Configurations.begin();
  620. i != this->Configurations.end(); ++i)
  621. {
  622. this->WritePlatformConfigTag("PropertyGroup",
  623. i->c_str(),
  624. 1, " Label=\"Configuration\"", "\n");
  625. std::string configType = "<ConfigurationType>";
  626. switch(this->GeneratorTarget->GetType())
  627. {
  628. case cmTarget::SHARED_LIBRARY:
  629. case cmTarget::MODULE_LIBRARY:
  630. configType += "DynamicLibrary";
  631. break;
  632. case cmTarget::OBJECT_LIBRARY:
  633. case cmTarget::STATIC_LIBRARY:
  634. configType += "StaticLibrary";
  635. break;
  636. case cmTarget::EXECUTABLE:
  637. if(this->NsightTegra &&
  638. !this->Target->GetPropertyAsBool("ANDROID_GUI"))
  639. {
  640. // Android executables are .so too.
  641. configType += "DynamicLibrary";
  642. }
  643. else
  644. {
  645. configType += "Application";
  646. }
  647. break;
  648. case cmTarget::UTILITY:
  649. case cmTarget::GLOBAL_TARGET:
  650. if(this->NsightTegra)
  651. {
  652. // Tegra-Android platform does not understand "Utility".
  653. configType += "StaticLibrary";
  654. }
  655. else
  656. {
  657. configType += "Utility";
  658. }
  659. break;
  660. case cmTarget::UNKNOWN_LIBRARY:
  661. case cmTarget::INTERFACE_LIBRARY:
  662. break;
  663. }
  664. configType += "</ConfigurationType>\n";
  665. this->WriteString(configType.c_str(), 2);
  666. if(this->MSTools)
  667. {
  668. this->WriteMSToolConfigurationValues(*i);
  669. }
  670. else if(this->NsightTegra)
  671. {
  672. this->WriteNsightTegraConfigurationValues(*i);
  673. }
  674. this->WriteString("</PropertyGroup>\n", 1);
  675. }
  676. }
  677. //----------------------------------------------------------------------------
  678. void cmVisualStudio10TargetGenerator
  679. ::WriteMSToolConfigurationValues(std::string const& config)
  680. {
  681. cmGlobalVisualStudio10Generator* gg =
  682. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  683. const char* mfcFlag =
  684. this->Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG");
  685. std::string mfcFlagValue = mfcFlag ? mfcFlag : "0";
  686. std::string useOfMfcValue = "false";
  687. if(mfcFlagValue == "1")
  688. {
  689. useOfMfcValue = "Static";
  690. }
  691. else if(mfcFlagValue == "2")
  692. {
  693. useOfMfcValue = "Dynamic";
  694. }
  695. std::string mfcLine = "<UseOfMfc>";
  696. mfcLine += useOfMfcValue + "</UseOfMfc>\n";
  697. this->WriteString(mfcLine.c_str(), 2);
  698. if((this->GeneratorTarget->GetType() <= cmTarget::OBJECT_LIBRARY &&
  699. this->ClOptions[config]->UsingUnicode()) ||
  700. this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  701. this->GlobalGenerator->TargetsWindowsPhone() ||
  702. this->GlobalGenerator->TargetsWindowsStore() ||
  703. this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  704. {
  705. this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
  706. }
  707. else if (this->GeneratorTarget->GetType() <= cmTarget::MODULE_LIBRARY &&
  708. this->ClOptions[config]->UsingSBCS())
  709. {
  710. this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
  711. }
  712. else
  713. {
  714. this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
  715. }
  716. if(const char* toolset = gg->GetPlatformToolset())
  717. {
  718. std::string pts = "<PlatformToolset>";
  719. pts += toolset;
  720. pts += "</PlatformToolset>\n";
  721. this->WriteString(pts.c_str(), 2);
  722. }
  723. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  724. this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  725. {
  726. this->WriteString("<WindowsAppContainer>true"
  727. "</WindowsAppContainer>\n", 2);
  728. }
  729. }
  730. //----------------------------------------------------------------------------
  731. void cmVisualStudio10TargetGenerator
  732. ::WriteNsightTegraConfigurationValues(std::string const&)
  733. {
  734. cmGlobalVisualStudio10Generator* gg =
  735. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  736. const char* toolset = gg->GetPlatformToolset();
  737. std::string ntv = "<NdkToolchainVersion>";
  738. ntv += toolset? toolset : "Default";
  739. ntv += "</NdkToolchainVersion>\n";
  740. this->WriteString(ntv.c_str(), 2);
  741. if(const char* minApi = this->Target->GetProperty("ANDROID_API_MIN"))
  742. {
  743. this->WriteString("<AndroidMinAPI>", 2);
  744. (*this->BuildFileStream ) <<
  745. "android-" << cmVS10EscapeXML(minApi) << "</AndroidMinAPI>\n";
  746. }
  747. if(const char* api = this->Target->GetProperty("ANDROID_API"))
  748. {
  749. this->WriteString("<AndroidTargetAPI>", 2);
  750. (*this->BuildFileStream ) <<
  751. "android-" << cmVS10EscapeXML(api) << "</AndroidTargetAPI>\n";
  752. }
  753. if(const char* cpuArch = this->Target->GetProperty("ANDROID_ARCH"))
  754. {
  755. this->WriteString("<AndroidArch>", 2);
  756. (*this->BuildFileStream) << cmVS10EscapeXML(cpuArch) <<
  757. "</AndroidArch>\n";
  758. }
  759. if(const char* stlType = this->Target->GetProperty("ANDROID_STL_TYPE"))
  760. {
  761. this->WriteString("<AndroidStlType>", 2);
  762. (*this->BuildFileStream) << cmVS10EscapeXML(stlType) <<
  763. "</AndroidStlType>\n";
  764. }
  765. }
  766. void cmVisualStudio10TargetGenerator::WriteCustomCommands()
  767. {
  768. this->SourcesVisited.clear();
  769. std::vector<cmSourceFile const*> customCommands;
  770. this->GeneratorTarget->GetCustomCommands(customCommands, "");
  771. for(std::vector<cmSourceFile const*>::const_iterator
  772. si = customCommands.begin();
  773. si != customCommands.end(); ++si)
  774. {
  775. this->WriteCustomCommand(*si);
  776. }
  777. }
  778. //----------------------------------------------------------------------------
  779. void cmVisualStudio10TargetGenerator
  780. ::WriteCustomCommand(cmSourceFile const* sf)
  781. {
  782. if(this->SourcesVisited.insert(sf).second)
  783. {
  784. if(std::vector<cmSourceFile*> const* depends =
  785. this->GeneratorTarget->GetSourceDepends(sf))
  786. {
  787. for(std::vector<cmSourceFile*>::const_iterator di = depends->begin();
  788. di != depends->end(); ++di)
  789. {
  790. this->WriteCustomCommand(*di);
  791. }
  792. }
  793. if(cmCustomCommand const* command = sf->GetCustomCommand())
  794. {
  795. this->WriteString("<ItemGroup>\n", 1);
  796. this->WriteCustomRule(sf, *command);
  797. this->WriteString("</ItemGroup>\n", 1);
  798. }
  799. }
  800. }
  801. void
  802. cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source,
  803. cmCustomCommand const &
  804. command)
  805. {
  806. std::string sourcePath = source->GetFullPath();
  807. // VS 10 will always rebuild a custom command attached to a .rule
  808. // file that doesn't exist so create the file explicitly.
  809. if (source->GetPropertyAsBool("__CMAKE_RULE"))
  810. {
  811. if(!cmSystemTools::FileExists(sourcePath.c_str()))
  812. {
  813. // Make sure the path exists for the file
  814. std::string path = cmSystemTools::GetFilenamePath(sourcePath);
  815. cmSystemTools::MakeDirectory(path.c_str());
  816. cmsys::ofstream fout(sourcePath.c_str());
  817. if(fout)
  818. {
  819. fout << "# generated from CMake\n";
  820. fout.flush();
  821. fout.close();
  822. // Force given file to have a very old timestamp, thus
  823. // preventing dependent rebuilds.
  824. this->ForceOld(sourcePath);
  825. }
  826. else
  827. {
  828. std::string error = "Could not create file: [";
  829. error += sourcePath;
  830. error += "] ";
  831. cmSystemTools::Error
  832. (error.c_str(), cmSystemTools::GetLastSystemError().c_str());
  833. }
  834. }
  835. }
  836. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  837. this->WriteSource("CustomBuild", source, ">\n");
  838. for(std::vector<std::string>::const_iterator
  839. i = this->Configurations.begin();
  840. i != this->Configurations.end(); ++i)
  841. {
  842. cmCustomCommandGenerator ccg(command, *i, this->LocalGenerator);
  843. std::string comment = lg->ConstructComment(ccg);
  844. comment = cmVS10EscapeComment(comment);
  845. std::string script =
  846. cmVS10EscapeXML(lg->ConstructScript(ccg));
  847. this->WritePlatformConfigTag("Message",i->c_str(), 3);
  848. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  849. this->WritePlatformConfigTag("Command", i->c_str(), 3);
  850. (*this->BuildFileStream ) << script << "</Command>\n";
  851. this->WritePlatformConfigTag("AdditionalInputs", i->c_str(), 3);
  852. (*this->BuildFileStream ) << cmVS10EscapeXML(source->GetFullPath());
  853. for(std::vector<std::string>::const_iterator d =
  854. ccg.GetDepends().begin();
  855. d != ccg.GetDepends().end();
  856. ++d)
  857. {
  858. std::string dep;
  859. if(this->LocalGenerator->GetRealDependency(d->c_str(), i->c_str(), dep))
  860. {
  861. this->ConvertToWindowsSlash(dep);
  862. (*this->BuildFileStream ) << ";" << cmVS10EscapeXML(dep);
  863. }
  864. }
  865. (*this->BuildFileStream ) << ";%(AdditionalInputs)</AdditionalInputs>\n";
  866. this->WritePlatformConfigTag("Outputs", i->c_str(), 3);
  867. const char* sep = "";
  868. for(std::vector<std::string>::const_iterator o =
  869. ccg.GetOutputs().begin();
  870. o != ccg.GetOutputs().end();
  871. ++o)
  872. {
  873. std::string out = *o;
  874. this->ConvertToWindowsSlash(out);
  875. (*this->BuildFileStream ) << sep << cmVS10EscapeXML(out);
  876. sep = ";";
  877. }
  878. (*this->BuildFileStream ) << "</Outputs>\n";
  879. if(this->LocalGenerator->GetVersion()
  880. > cmGlobalVisualStudioGenerator::VS10)
  881. {
  882. // VS >= 11 let us turn off linking of custom command outputs.
  883. this->WritePlatformConfigTag("LinkObjects", i->c_str(), 3);
  884. (*this->BuildFileStream ) << "false</LinkObjects>\n";
  885. }
  886. }
  887. this->WriteString("</CustomBuild>\n", 2);
  888. }
  889. std::string
  890. cmVisualStudio10TargetGenerator::ConvertPath(std::string const& path,
  891. bool forceRelative)
  892. {
  893. return forceRelative
  894. ? cmSystemTools::RelativePath(
  895. this->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() > cmTarget::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. cmTarget::TargetType ttype =
  1642. (cmTarget::TargetType)this->GeneratorTarget->GetType();
  1643. if(ttype > cmTarget::GLOBAL_TARGET)
  1644. {
  1645. return;
  1646. }
  1647. this->WriteString("<PropertyGroup>\n", 2);
  1648. this->WriteString("<_ProjectFileVersion>10.0.20506.1"
  1649. "</_ProjectFileVersion>\n", 3);
  1650. for(std::vector<std::string>::const_iterator
  1651. config = this->Configurations.begin();
  1652. config != this->Configurations.end(); ++config)
  1653. {
  1654. if(ttype >= cmTarget::UTILITY)
  1655. {
  1656. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1657. *this->BuildFileStream
  1658. << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
  1659. << "</IntDir>\n";
  1660. }
  1661. else
  1662. {
  1663. std::string intermediateDir = this->LocalGenerator->
  1664. GetTargetDirectory(*this->Target);
  1665. intermediateDir += "/";
  1666. intermediateDir += *config;
  1667. intermediateDir += "/";
  1668. std::string outDir;
  1669. std::string targetNameFull;
  1670. if(ttype == cmTarget::OBJECT_LIBRARY)
  1671. {
  1672. outDir = intermediateDir;
  1673. targetNameFull = this->Target->GetName();
  1674. targetNameFull += ".lib";
  1675. }
  1676. else
  1677. {
  1678. outDir = this->GeneratorTarget->GetDirectory(config->c_str()) + "/";
  1679. targetNameFull = this->GeneratorTarget->GetFullName(config->c_str());
  1680. }
  1681. this->ConvertToWindowsSlash(intermediateDir);
  1682. this->ConvertToWindowsSlash(outDir);
  1683. this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
  1684. *this->BuildFileStream << cmVS10EscapeXML(outDir)
  1685. << "</OutDir>\n";
  1686. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1687. *this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
  1688. << "</IntDir>\n";
  1689. std::string name =
  1690. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  1691. this->WritePlatformConfigTag("TargetName", config->c_str(), 3);
  1692. *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n";
  1693. std::string ext =
  1694. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  1695. if(ext.empty())
  1696. {
  1697. // An empty TargetExt causes a default extension to be used.
  1698. // A single "." appears to be treated as an empty extension.
  1699. ext = ".";
  1700. }
  1701. this->WritePlatformConfigTag("TargetExt", config->c_str(), 3);
  1702. *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n";
  1703. this->OutputLinkIncremental(*config);
  1704. }
  1705. }
  1706. this->WriteString("</PropertyGroup>\n", 2);
  1707. }
  1708. void
  1709. cmVisualStudio10TargetGenerator::
  1710. OutputLinkIncremental(std::string const& configName)
  1711. {
  1712. if(!this->MSTools)
  1713. {
  1714. return;
  1715. }
  1716. // static libraries and things greater than modules do not need
  1717. // to set this option
  1718. if(this->GeneratorTarget->GetType() == cmTarget::STATIC_LIBRARY
  1719. || this->GeneratorTarget->GetType() > cmTarget::MODULE_LIBRARY)
  1720. {
  1721. return;
  1722. }
  1723. Options& linkOptions = *(this->LinkOptions[configName]);
  1724. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  1725. this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 3);
  1726. *this->BuildFileStream << (incremental?incremental:"true")
  1727. << "</LinkIncremental>\n";
  1728. linkOptions.RemoveFlag("LinkIncremental");
  1729. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  1730. this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 3);
  1731. *this->BuildFileStream << (manifest?manifest:"true")
  1732. << "</GenerateManifest>\n";
  1733. linkOptions.RemoveFlag("GenerateManifest");
  1734. // Some link options belong here. Use them now and remove them so that
  1735. // WriteLinkOptions does not use them.
  1736. const char* flags[] = {
  1737. "LinkDelaySign",
  1738. "LinkKeyFile",
  1739. 0};
  1740. for(const char** f = flags; *f; ++f)
  1741. {
  1742. const char* flag = *f;
  1743. if(const char* value = linkOptions.GetFlag(flag))
  1744. {
  1745. this->WritePlatformConfigTag(flag, configName.c_str(), 3);
  1746. *this->BuildFileStream << value << "</" << flag << ">\n";
  1747. linkOptions.RemoveFlag(flag);
  1748. }
  1749. }
  1750. }
  1751. //----------------------------------------------------------------------------
  1752. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  1753. {
  1754. for(std::vector<std::string>::const_iterator
  1755. i = this->Configurations.begin();
  1756. i != this->Configurations.end(); ++i)
  1757. {
  1758. if(!this->ComputeClOptions(*i))
  1759. {
  1760. return false;
  1761. }
  1762. }
  1763. return true;
  1764. }
  1765. //----------------------------------------------------------------------------
  1766. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  1767. std::string const& configName)
  1768. {
  1769. // much of this was copied from here:
  1770. // copied from cmLocalVisualStudio7Generator.cxx 805
  1771. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  1772. cmsys::auto_ptr<Options> pOptions(
  1773. new Options(this->LocalGenerator, Options::Compiler,
  1774. this->GetClFlagTable()));
  1775. Options& clOptions = *pOptions;
  1776. std::string flags;
  1777. const std::string& linkLanguage =
  1778. this->GeneratorTarget->GetLinkerLanguage(configName.c_str());
  1779. if(linkLanguage.empty())
  1780. {
  1781. cmSystemTools::Error
  1782. ("CMake can not determine linker language for target: ",
  1783. this->Name.c_str());
  1784. return false;
  1785. }
  1786. if(linkLanguage == "C" || linkLanguage == "CXX"
  1787. || linkLanguage == "Fortran")
  1788. {
  1789. std::string baseFlagVar = "CMAKE_";
  1790. baseFlagVar += linkLanguage;
  1791. baseFlagVar += "_FLAGS";
  1792. flags = this->
  1793. Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
  1794. std::string flagVar = baseFlagVar + std::string("_") +
  1795. cmSystemTools::UpperCase(configName);
  1796. flags += " ";
  1797. flags += this->
  1798. Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
  1799. }
  1800. // set the correct language
  1801. if(linkLanguage == "C")
  1802. {
  1803. clOptions.AddFlag("CompileAs", "CompileAsC");
  1804. }
  1805. if(linkLanguage == "CXX")
  1806. {
  1807. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  1808. }
  1809. this->LocalGenerator->AddCompileOptions(flags, this->Target,
  1810. linkLanguage, configName.c_str());
  1811. // Get preprocessor definitions for this directory.
  1812. std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags();
  1813. if(this->MSTools)
  1814. {
  1815. clOptions.FixExceptionHandlingDefault();
  1816. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  1817. std::string asmLocation = configName + "/";
  1818. clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  1819. }
  1820. clOptions.Parse(flags.c_str());
  1821. clOptions.Parse(defineFlags.c_str());
  1822. std::vector<std::string> targetDefines;
  1823. this->GeneratorTarget->GetCompileDefinitions(targetDefines,
  1824. configName.c_str(), "CXX");
  1825. clOptions.AddDefines(targetDefines);
  1826. if(this->MSTools)
  1827. {
  1828. clOptions.SetVerboseMakefile(
  1829. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  1830. }
  1831. // Add a definition for the configuration name.
  1832. std::string configDefine = "CMAKE_INTDIR=\"";
  1833. configDefine += configName;
  1834. configDefine += "\"";
  1835. clOptions.AddDefine(configDefine);
  1836. if(const char* exportMacro = this->Target->GetExportMacro())
  1837. {
  1838. clOptions.AddDefine(exportMacro);
  1839. }
  1840. if (this->MSTools)
  1841. {
  1842. // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
  1843. if (this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
  1844. {
  1845. clOptions.AddFlag("CompileAsWinRT", "true");
  1846. // For WinRT components, add the _WINRT_DLL define to produce a lib
  1847. if (this->GeneratorTarget->GetType() == cmTarget::SHARED_LIBRARY ||
  1848. this->GeneratorTarget->GetType() == cmTarget::MODULE_LIBRARY )
  1849. {
  1850. clOptions.AddDefine("_WINRT_DLL");
  1851. }
  1852. }
  1853. else if (this->GlobalGenerator->TargetsWindowsStore() ||
  1854. this->GlobalGenerator->TargetsWindowsPhone())
  1855. {
  1856. if (!clOptions.IsWinRt())
  1857. {
  1858. clOptions.AddFlag("CompileAsWinRT", "false");
  1859. }
  1860. }
  1861. if(const char* winRT = clOptions.GetFlag("CompileAsWinRT"))
  1862. {
  1863. if(cmSystemTools::IsOn(winRT))
  1864. {
  1865. this->TargetCompileAsWinRT = true;
  1866. }
  1867. }
  1868. }
  1869. this->ClOptions[configName] = pOptions.release();
  1870. return true;
  1871. }
  1872. //----------------------------------------------------------------------------
  1873. void cmVisualStudio10TargetGenerator::WriteClOptions(
  1874. std::string const& configName,
  1875. std::vector<std::string> const& includes)
  1876. {
  1877. Options& clOptions = *(this->ClOptions[configName]);
  1878. this->WriteString("<ClCompile>\n", 2);
  1879. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1880. clOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  1881. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1882. "%(AdditionalIncludeDirectories)");
  1883. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1884. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1885. "\n", "CXX");
  1886. if(this->NsightTegra)
  1887. {
  1888. if(const char* processMax =
  1889. this->Target->GetProperty("ANDROID_PROCESS_MAX"))
  1890. {
  1891. this->WriteString("<ProcessMax>", 3);
  1892. *this->BuildFileStream << cmVS10EscapeXML(processMax) <<
  1893. "</ProcessMax>\n";
  1894. }
  1895. }
  1896. if(this->MSTools)
  1897. {
  1898. this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
  1899. // If not in debug mode, write the DebugInformationFormat field
  1900. // without value so PDBs don't get generated uselessly.
  1901. if(!clOptions.IsDebug())
  1902. {
  1903. this->WriteString("<DebugInformationFormat>"
  1904. "</DebugInformationFormat>\n", 3);
  1905. }
  1906. // Specify the compiler program database file if configured.
  1907. std::string pdb =
  1908. this->GeneratorTarget->GetCompilePDBPath(configName.c_str());
  1909. if(!pdb.empty())
  1910. {
  1911. this->ConvertToWindowsSlash(pdb);
  1912. this->WriteString("<ProgramDataBaseFileName>", 3);
  1913. *this->BuildFileStream << cmVS10EscapeXML(pdb)
  1914. << "</ProgramDataBaseFileName>\n";
  1915. }
  1916. }
  1917. this->WriteString("</ClCompile>\n", 2);
  1918. }
  1919. //----------------------------------------------------------------------------
  1920. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  1921. {
  1922. for(std::vector<std::string>::const_iterator
  1923. i = this->Configurations.begin();
  1924. i != this->Configurations.end(); ++i)
  1925. {
  1926. if(!this->ComputeRcOptions(*i))
  1927. {
  1928. return false;
  1929. }
  1930. }
  1931. return true;
  1932. }
  1933. //----------------------------------------------------------------------------
  1934. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  1935. std::string const& configName)
  1936. {
  1937. cmsys::auto_ptr<Options> pOptions(
  1938. new Options(this->LocalGenerator, Options::ResourceCompiler,
  1939. this->GetRcFlagTable()));
  1940. Options& rcOptions = *pOptions;
  1941. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1942. std::string rcConfigFlagsVar = std::string("CMAKE_RC_FLAGS_") + CONFIG;
  1943. std::string flags =
  1944. std::string(this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS")) +
  1945. std::string(" ") +
  1946. std::string(this->Makefile->GetSafeDefinition(rcConfigFlagsVar));
  1947. rcOptions.Parse(flags.c_str());
  1948. this->RcOptions[configName] = pOptions.release();
  1949. return true;
  1950. }
  1951. void cmVisualStudio10TargetGenerator::
  1952. WriteRCOptions(std::string const& configName,
  1953. std::vector<std::string> const & includes)
  1954. {
  1955. if(!this->MSTools)
  1956. {
  1957. return;
  1958. }
  1959. this->WriteString("<ResourceCompile>\n", 2);
  1960. // Preprocessor definitions and includes are shared with clOptions.
  1961. Options& clOptions = *(this->ClOptions[configName]);
  1962. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1963. "\n", "RC");
  1964. Options& rcOptions = *(this->RcOptions[configName]);
  1965. rcOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  1966. rcOptions.AppendFlag("AdditionalIncludeDirectories",
  1967. "%(AdditionalIncludeDirectories)");
  1968. rcOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1969. rcOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1970. this->WriteString("</ResourceCompile>\n", 2);
  1971. }
  1972. //----------------------------------------------------------------------------
  1973. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
  1974. {
  1975. if(!this->GlobalGenerator->IsMasmEnabled())
  1976. {
  1977. return true;
  1978. }
  1979. for(std::vector<std::string>::const_iterator
  1980. i = this->Configurations.begin();
  1981. i != this->Configurations.end(); ++i)
  1982. {
  1983. if(!this->ComputeMasmOptions(*i))
  1984. {
  1985. return false;
  1986. }
  1987. }
  1988. return true;
  1989. }
  1990. //----------------------------------------------------------------------------
  1991. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
  1992. std::string const& configName)
  1993. {
  1994. cmsys::auto_ptr<Options> pOptions(
  1995. new Options(this->LocalGenerator, Options::MasmCompiler,
  1996. this->GetMasmFlagTable()));
  1997. Options& masmOptions = *pOptions;
  1998. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1999. std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG;
  2000. std::string flags =
  2001. std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS")) +
  2002. std::string(" ") +
  2003. std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
  2004. masmOptions.Parse(flags.c_str());
  2005. this->MasmOptions[configName] = pOptions.release();
  2006. return true;
  2007. }
  2008. void cmVisualStudio10TargetGenerator::
  2009. WriteMasmOptions(std::string const& configName,
  2010. std::vector<std::string> const& includes)
  2011. {
  2012. if(!this->MSTools || !this->GlobalGenerator->IsMasmEnabled())
  2013. {
  2014. return;
  2015. }
  2016. this->WriteString("<MASM>\n", 2);
  2017. // Preprocessor definitions and includes are shared with clOptions.
  2018. Options& clOptions = *(this->ClOptions[configName]);
  2019. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  2020. "\n", "ASM_MASM");
  2021. Options& masmOptions = *(this->MasmOptions[configName]);
  2022. masmOptions.AppendFlag("IncludePaths", includes);
  2023. masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)");
  2024. masmOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2025. masmOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2026. this->WriteString("</MASM>\n", 2);
  2027. }
  2028. void
  2029. cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
  2030. {
  2031. if(this->GeneratorTarget->GetType() != cmTarget::STATIC_LIBRARY &&
  2032. this->GeneratorTarget->GetType() != cmTarget::OBJECT_LIBRARY)
  2033. {
  2034. return;
  2035. }
  2036. std::string libflags;
  2037. this->LocalGenerator->GetStaticLibraryFlags(libflags,
  2038. cmSystemTools::UpperCase(config), this->Target);
  2039. if(!libflags.empty())
  2040. {
  2041. this->WriteString("<Lib>\n", 2);
  2042. cmVisualStudioGeneratorOptions
  2043. libOptions(this->LocalGenerator,
  2044. cmVisualStudioGeneratorOptions::Linker,
  2045. this->GetLibFlagTable(), 0, this);
  2046. libOptions.Parse(libflags.c_str());
  2047. libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2048. libOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2049. this->WriteString("</Lib>\n", 2);
  2050. }
  2051. // We cannot generate metadata for static libraries. WindowsPhone
  2052. // and WindowsStore tools look at GenerateWindowsMetadata in the
  2053. // Link tool options even for static libraries.
  2054. if(this->GlobalGenerator->TargetsWindowsPhone() ||
  2055. this->GlobalGenerator->TargetsWindowsStore())
  2056. {
  2057. this->WriteString("<Link>\n", 2);
  2058. this->WriteString("<GenerateWindowsMetadata>false"
  2059. "</GenerateWindowsMetadata>\n", 3);
  2060. this->WriteString("</Link>\n", 2);
  2061. }
  2062. }
  2063. void cmVisualStudio10TargetGenerator::WriteManifestOptions(
  2064. std::string const& config)
  2065. {
  2066. if (this->GeneratorTarget->GetType() != cmTarget::EXECUTABLE &&
  2067. this->GeneratorTarget->GetType() != cmTarget::SHARED_LIBRARY &&
  2068. this->GeneratorTarget->GetType() != cmTarget::MODULE_LIBRARY)
  2069. {
  2070. return;
  2071. }
  2072. std::vector<cmSourceFile const*> manifest_srcs;
  2073. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  2074. if (!manifest_srcs.empty())
  2075. {
  2076. this->WriteString("<Manifest>\n", 2);
  2077. this->WriteString("<AdditionalManifestFiles>", 3);
  2078. for (std::vector<cmSourceFile const*>::const_iterator
  2079. mi = manifest_srcs.begin(); mi != manifest_srcs.end(); ++mi)
  2080. {
  2081. std::string m = this->ConvertPath((*mi)->GetFullPath(), false);
  2082. this->ConvertToWindowsSlash(m);
  2083. (*this->BuildFileStream) << m << ";";
  2084. }
  2085. (*this->BuildFileStream) << "</AdditionalManifestFiles>\n";
  2086. this->WriteString("</Manifest>\n", 2);
  2087. }
  2088. }
  2089. //----------------------------------------------------------------------------
  2090. void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
  2091. std::string const& configName)
  2092. {
  2093. // Look through the sources for AndroidManifest.xml and use
  2094. // its location as the root source directory.
  2095. std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory();
  2096. {
  2097. std::vector<cmSourceFile const*> extraSources;
  2098. this->GeneratorTarget->GetExtraSources(extraSources, "");
  2099. for(std::vector<cmSourceFile const*>::const_iterator si =
  2100. extraSources.begin(); si != extraSources.end(); ++si)
  2101. {
  2102. if("androidmanifest.xml" == cmSystemTools::LowerCase(
  2103. (*si)->GetLocation().GetName()))
  2104. {
  2105. rootDir = (*si)->GetLocation().GetDirectory();
  2106. break;
  2107. }
  2108. }
  2109. }
  2110. // Tell MSBuild to launch Ant.
  2111. {
  2112. std::string antBuildPath = rootDir;
  2113. this->WriteString("<AntBuild>\n", 2);
  2114. this->WriteString("<AntBuildPath>", 3);
  2115. this->ConvertToWindowsSlash(antBuildPath);
  2116. (*this->BuildFileStream) <<
  2117. cmVS10EscapeXML(antBuildPath) << "</AntBuildPath>\n";
  2118. }
  2119. if (this->Target->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP"))
  2120. {
  2121. this->WriteString("<SkipAntStep>true</SkipAntStep>\n", 3);
  2122. }
  2123. if (this->Target->GetPropertyAsBool("ANDROID_PROGUARD"))
  2124. {
  2125. this->WriteString("<EnableProGuard>true</EnableProGuard>\n", 3);
  2126. }
  2127. if (const char* proGuardConfigLocation =
  2128. this->Target->GetProperty("ANDROID_PROGUARD_CONFIG_PATH"))
  2129. {
  2130. this->WriteString("<ProGuardConfigLocation>", 3);
  2131. (*this->BuildFileStream) << cmVS10EscapeXML(proGuardConfigLocation) <<
  2132. "</ProGuardConfigLocation>\n";
  2133. }
  2134. if (const char* securePropertiesLocation =
  2135. this->Target->GetProperty("ANDROID_SECURE_PROPS_PATH"))
  2136. {
  2137. this->WriteString("<SecurePropertiesLocation>", 3);
  2138. (*this->BuildFileStream) << cmVS10EscapeXML(securePropertiesLocation) <<
  2139. "</SecurePropertiesLocation>\n";
  2140. }
  2141. if (const char* nativeLibDirectoriesExpression =
  2142. this->Target->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES"))
  2143. {
  2144. cmGeneratorExpression ge;
  2145. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2146. ge.Parse(nativeLibDirectoriesExpression);
  2147. std::string nativeLibDirs = cge->Evaluate(this->LocalGenerator,
  2148. configName);
  2149. this->WriteString("<NativeLibDirectories>", 3);
  2150. (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDirs) <<
  2151. "</NativeLibDirectories>\n";
  2152. }
  2153. if (const char* nativeLibDependenciesExpression =
  2154. this->Target->GetProperty("ANDROID_NATIVE_LIB_DEPENDENCIES"))
  2155. {
  2156. cmGeneratorExpression ge;
  2157. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2158. ge.Parse(nativeLibDependenciesExpression);
  2159. std::string nativeLibDeps = cge->Evaluate(this->LocalGenerator,
  2160. configName);
  2161. this->WriteString("<NativeLibDependencies>", 3);
  2162. (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDeps) <<
  2163. "</NativeLibDependencies>\n";
  2164. }
  2165. if (const char* javaSourceDir =
  2166. this->Target->GetProperty("ANDROID_JAVA_SOURCE_DIR"))
  2167. {
  2168. this->WriteString("<JavaSourceDir>", 3);
  2169. (*this->BuildFileStream) << cmVS10EscapeXML(javaSourceDir) <<
  2170. "</JavaSourceDir>\n";
  2171. }
  2172. if (const char* jarDirectoriesExpression =
  2173. this->Target->GetProperty("ANDROID_JAR_DIRECTORIES"))
  2174. {
  2175. cmGeneratorExpression ge;
  2176. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2177. ge.Parse(jarDirectoriesExpression);
  2178. std::string jarDirectories = cge->Evaluate(this->LocalGenerator,
  2179. configName);
  2180. this->WriteString("<JarDirectories>", 3);
  2181. (*this->BuildFileStream) << cmVS10EscapeXML(jarDirectories) <<
  2182. "</JarDirectories>\n";
  2183. }
  2184. if (const char* jarDeps =
  2185. this->Target->GetProperty("ANDROID_JAR_DEPENDENCIES"))
  2186. {
  2187. this->WriteString("<JarDependencies>", 3);
  2188. (*this->BuildFileStream) << cmVS10EscapeXML(jarDeps) <<
  2189. "</JarDependencies>\n";
  2190. }
  2191. if (const char* assetsDirectories =
  2192. this->Target->GetProperty("ANDROID_ASSETS_DIRECTORIES"))
  2193. {
  2194. this->WriteString("<AssetsDirectories>", 3);
  2195. (*this->BuildFileStream) << cmVS10EscapeXML(assetsDirectories) <<
  2196. "</AssetsDirectories>\n";
  2197. }
  2198. {
  2199. std::string manifest_xml = rootDir + "/AndroidManifest.xml";
  2200. this->ConvertToWindowsSlash(manifest_xml);
  2201. this->WriteString("<AndroidManifestLocation>", 3);
  2202. (*this->BuildFileStream) <<
  2203. cmVS10EscapeXML(manifest_xml) << "</AndroidManifestLocation>\n";
  2204. }
  2205. if (const char* antAdditionalOptions =
  2206. this->Target->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS"))
  2207. {
  2208. this->WriteString("<AdditionalOptions>", 3);
  2209. (*this->BuildFileStream) << cmVS10EscapeXML(antAdditionalOptions) <<
  2210. " %(AdditionalOptions)</AdditionalOptions>\n";
  2211. }
  2212. this->WriteString("</AntBuild>\n", 2);
  2213. }
  2214. //----------------------------------------------------------------------------
  2215. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  2216. {
  2217. if(this->GeneratorTarget->GetType() == cmTarget::EXECUTABLE ||
  2218. this->GeneratorTarget->GetType() == cmTarget::SHARED_LIBRARY ||
  2219. this->GeneratorTarget->GetType() == cmTarget::MODULE_LIBRARY)
  2220. {
  2221. for(std::vector<std::string>::const_iterator
  2222. i = this->Configurations.begin();
  2223. i != this->Configurations.end(); ++i)
  2224. {
  2225. if(!this->ComputeLinkOptions(*i))
  2226. {
  2227. return false;
  2228. }
  2229. }
  2230. }
  2231. return true;
  2232. }
  2233. //----------------------------------------------------------------------------
  2234. bool
  2235. cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
  2236. {
  2237. cmsys::auto_ptr<Options> pOptions(
  2238. new Options(this->LocalGenerator, Options::Linker,
  2239. this->GetLinkFlagTable(), 0, this));
  2240. Options& linkOptions = *pOptions;
  2241. const std::string& linkLanguage =
  2242. this->GeneratorTarget->GetLinkerLanguage(config.c_str());
  2243. if(linkLanguage.empty())
  2244. {
  2245. cmSystemTools::Error
  2246. ("CMake can not determine linker language for target: ",
  2247. this->Name.c_str());
  2248. return false;
  2249. }
  2250. std::string CONFIG = cmSystemTools::UpperCase(config);
  2251. const char* linkType = "SHARED";
  2252. if(this->GeneratorTarget->GetType() == cmTarget::MODULE_LIBRARY)
  2253. {
  2254. linkType = "MODULE";
  2255. }
  2256. if(this->GeneratorTarget->GetType() == cmTarget::EXECUTABLE)
  2257. {
  2258. linkType = "EXE";
  2259. }
  2260. std::string flags;
  2261. std::string linkFlagVarBase = "CMAKE_";
  2262. linkFlagVarBase += linkType;
  2263. linkFlagVarBase += "_LINKER_FLAGS";
  2264. flags += " ";
  2265. flags += this->
  2266. Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
  2267. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  2268. flags += " ";
  2269. flags += this->
  2270. Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
  2271. const char* targetLinkFlags = this->Target->GetProperty("LINK_FLAGS");
  2272. if(targetLinkFlags)
  2273. {
  2274. flags += " ";
  2275. flags += targetLinkFlags;
  2276. }
  2277. std::string flagsProp = "LINK_FLAGS_";
  2278. flagsProp += CONFIG;
  2279. if(const char* flagsConfig = this->Target->GetProperty(flagsProp.c_str()))
  2280. {
  2281. flags += " ";
  2282. flags += flagsConfig;
  2283. }
  2284. std::string standardLibsVar = "CMAKE_";
  2285. standardLibsVar += linkLanguage;
  2286. standardLibsVar += "_STANDARD_LIBRARIES";
  2287. std::string
  2288. libs = this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  2289. // Remove trailing spaces from libs
  2290. std::string::size_type pos = libs.size()-1;
  2291. if(!libs.empty())
  2292. {
  2293. while(libs[pos] == ' ')
  2294. {
  2295. pos--;
  2296. }
  2297. }
  2298. if(pos != libs.size()-1)
  2299. {
  2300. libs = libs.substr(0, pos+1);
  2301. }
  2302. // Replace spaces in libs with ;
  2303. cmSystemTools::ReplaceString(libs, " ", ";");
  2304. std::vector<std::string> libVec;
  2305. cmSystemTools::ExpandListArgument(libs, libVec);
  2306. cmComputeLinkInformation* pcli =
  2307. this->GeneratorTarget->GetLinkInformation(config.c_str());
  2308. if(!pcli)
  2309. {
  2310. cmSystemTools::Error
  2311. ("CMake can not compute cmComputeLinkInformation for target: ",
  2312. this->Name.c_str());
  2313. return false;
  2314. }
  2315. // add the libraries for the target to libs string
  2316. cmComputeLinkInformation& cli = *pcli;
  2317. this->AddLibraries(cli, libVec);
  2318. linkOptions.AddFlag("AdditionalDependencies", libVec);
  2319. std::vector<std::string> const& ldirs = cli.GetDirectories();
  2320. std::vector<std::string> linkDirs;
  2321. for(std::vector<std::string>::const_iterator d = ldirs.begin();
  2322. d != ldirs.end(); ++d)
  2323. {
  2324. // first just full path
  2325. linkDirs.push_back(*d);
  2326. // next path with configuration type Debug, Release, etc
  2327. linkDirs.push_back(*d + "/$(Configuration)");
  2328. }
  2329. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  2330. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  2331. std::string targetName;
  2332. std::string targetNameSO;
  2333. std::string targetNameFull;
  2334. std::string targetNameImport;
  2335. std::string targetNamePDB;
  2336. if(this->GeneratorTarget->GetType() == cmTarget::EXECUTABLE)
  2337. {
  2338. this->GeneratorTarget->GetExecutableNames(targetName, targetNameFull,
  2339. targetNameImport, targetNamePDB,
  2340. config.c_str());
  2341. }
  2342. else
  2343. {
  2344. this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO,
  2345. targetNameFull,
  2346. targetNameImport, targetNamePDB,
  2347. config.c_str());
  2348. }
  2349. if(this->MSTools)
  2350. {
  2351. linkOptions.AddFlag("Version", "");
  2352. if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
  2353. {
  2354. if (this->GlobalGenerator->TargetsWindowsCE())
  2355. {
  2356. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2357. if (this->GeneratorTarget->GetType() == cmTarget::EXECUTABLE)
  2358. {
  2359. if (this->ClOptions[config]->UsingUnicode())
  2360. {
  2361. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  2362. }
  2363. else
  2364. {
  2365. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  2366. }
  2367. }
  2368. }
  2369. else
  2370. {
  2371. linkOptions.AddFlag("SubSystem", "Windows");
  2372. }
  2373. }
  2374. else
  2375. {
  2376. if (this->GlobalGenerator->TargetsWindowsCE())
  2377. {
  2378. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2379. if (this->GeneratorTarget->GetType() == cmTarget::EXECUTABLE)
  2380. {
  2381. if (this->ClOptions[config]->UsingUnicode())
  2382. {
  2383. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  2384. }
  2385. else
  2386. {
  2387. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  2388. }
  2389. }
  2390. }
  2391. else
  2392. {
  2393. linkOptions.AddFlag("SubSystem", "Console");
  2394. };
  2395. }
  2396. if(const char* stackVal =
  2397. this->Makefile->GetDefinition("CMAKE_"+linkLanguage+"_STACK_SIZE"))
  2398. {
  2399. linkOptions.AddFlag("StackReserveSize", stackVal);
  2400. }
  2401. if(linkOptions.IsDebug() || flags.find("/debug") != flags.npos)
  2402. {
  2403. linkOptions.AddFlag("GenerateDebugInformation", "true");
  2404. }
  2405. else
  2406. {
  2407. linkOptions.AddFlag("GenerateDebugInformation", "false");
  2408. }
  2409. std::string pdb = this->GeneratorTarget->GetPDBDirectory(config.c_str());
  2410. pdb += "/";
  2411. pdb += targetNamePDB;
  2412. std::string imLib =
  2413. this->GeneratorTarget->GetDirectory(config.c_str(), true);
  2414. imLib += "/";
  2415. imLib += targetNameImport;
  2416. linkOptions.AddFlag("ImportLibrary", imLib.c_str());
  2417. linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
  2418. // A Windows Runtime component uses internal .NET metadata,
  2419. // so does not have an import library.
  2420. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
  2421. this->GeneratorTarget->GetType() != cmTarget::EXECUTABLE)
  2422. {
  2423. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  2424. }
  2425. else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2426. this->GlobalGenerator->TargetsWindowsStore())
  2427. {
  2428. // WindowsPhone and WindowsStore components are in an app container
  2429. // and produce WindowsMetadata. If we are not producing a WINRT
  2430. // component, then do not generate the metadata here.
  2431. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  2432. }
  2433. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  2434. this->GlobalGenerator->GetSystemVersion() == "8.0")
  2435. {
  2436. // WindowsPhone 8.0 does not have ole32.
  2437. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  2438. }
  2439. }
  2440. else if(this->NsightTegra)
  2441. {
  2442. linkOptions.AddFlag("SoName", targetNameSO.c_str());
  2443. }
  2444. linkOptions.Parse(flags.c_str());
  2445. if(this->MSTools)
  2446. {
  2447. std::string def = this->GeneratorTarget->GetModuleDefinitionFile("");
  2448. if(!def.empty())
  2449. {
  2450. linkOptions.AddFlag("ModuleDefinitionFile", def.c_str());
  2451. }
  2452. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  2453. "%(IgnoreSpecificDefaultLibraries)");
  2454. }
  2455. if (this->GeneratorTarget->GetType() == cmTarget::SHARED_LIBRARY &&
  2456. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
  2457. {
  2458. if (this->Target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
  2459. {
  2460. linkOptions.AddFlag("ModuleDefinitionFile", "$(IntDir)exportall.def");
  2461. }
  2462. }
  2463. this->LinkOptions[config] = pOptions.release();
  2464. return true;
  2465. }
  2466. //----------------------------------------------------------------------------
  2467. void
  2468. cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
  2469. {
  2470. if(this->GeneratorTarget->GetType() == cmTarget::STATIC_LIBRARY
  2471. || this->GeneratorTarget->GetType() > cmTarget::MODULE_LIBRARY)
  2472. {
  2473. return;
  2474. }
  2475. Options& linkOptions = *(this->LinkOptions[config]);
  2476. this->WriteString("<Link>\n", 2);
  2477. linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2478. linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2479. this->WriteString("</Link>\n", 2);
  2480. if(!this->GlobalGenerator->NeedLinkLibraryDependencies(*this->Target))
  2481. {
  2482. this->WriteString("<ProjectReference>\n", 2);
  2483. this->WriteString(
  2484. "<LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 3);
  2485. this->WriteString("</ProjectReference>\n", 2);
  2486. }
  2487. }
  2488. void cmVisualStudio10TargetGenerator::AddLibraries(
  2489. cmComputeLinkInformation& cli,
  2490. std::vector<std::string>& libVec)
  2491. {
  2492. typedef cmComputeLinkInformation::ItemVector ItemVector;
  2493. ItemVector libs = cli.GetItems();
  2494. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  2495. {
  2496. if(l->IsPath)
  2497. {
  2498. std::string path = this->LocalGenerator->
  2499. Convert(l->Value.c_str(),
  2500. cmLocalGenerator::START_OUTPUT,
  2501. cmLocalGenerator::UNCHANGED);
  2502. this->ConvertToWindowsSlash(path);
  2503. libVec.push_back(path);
  2504. }
  2505. else if (!l->Target
  2506. || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  2507. {
  2508. libVec.push_back(l->Value);
  2509. }
  2510. }
  2511. }
  2512. void cmVisualStudio10TargetGenerator::
  2513. WriteMidlOptions(std::string const& /*config*/,
  2514. std::vector<std::string> const & includes)
  2515. {
  2516. if(!this->MSTools)
  2517. {
  2518. return;
  2519. }
  2520. // This processes *any* of the .idl files specified in the project's file
  2521. // list (and passed as the item metadata %(Filename) expressing the rule
  2522. // input filename) into output files at the per-config *build* dir
  2523. // ($(IntDir)) each.
  2524. //
  2525. // IOW, this MIDL section is intended to provide a fully generic syntax
  2526. // content suitable for most cases (read: if you get errors, then it's quite
  2527. // probable that the error is on your side of the .idl setup).
  2528. //
  2529. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  2530. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  2531. // project's file list, otherwise the compiler-side processing won't pick it
  2532. // up (for non-directory form, it ends up looking in project binary dir
  2533. // only). Perhaps there's something to be done to make this more automatic
  2534. // on the CMake side?
  2535. this->WriteString("<Midl>\n", 2);
  2536. this->WriteString("<AdditionalIncludeDirectories>", 3);
  2537. for(std::vector<std::string>::const_iterator i = includes.begin();
  2538. i != includes.end(); ++i)
  2539. {
  2540. *this->BuildFileStream << cmVS10EscapeXML(*i) << ";";
  2541. }
  2542. this->WriteString("%(AdditionalIncludeDirectories)"
  2543. "</AdditionalIncludeDirectories>\n", 0);
  2544. this->WriteString("<OutputDirectory>$(ProjectDir)/$(IntDir)"
  2545. "</OutputDirectory>\n", 3);
  2546. this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
  2547. this->WriteString(
  2548. "<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
  2549. this->WriteString(
  2550. "<InterfaceIdentifierFileName>"
  2551. "%(Filename)_i.c</InterfaceIdentifierFileName>\n", 3);
  2552. this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n",3);
  2553. this->WriteString("</Midl>\n", 2);
  2554. }
  2555. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
  2556. {
  2557. for(std::vector<std::string>::const_iterator
  2558. i = this->Configurations.begin();
  2559. i != this->Configurations.end(); ++i)
  2560. {
  2561. std::vector<std::string> includes;
  2562. this->LocalGenerator->GetIncludeDirectories(includes,
  2563. this->GeneratorTarget,
  2564. "C", i->c_str());
  2565. for(std::vector<std::string>::iterator ii = includes.begin();
  2566. ii != includes.end(); ++ii)
  2567. {
  2568. this->ConvertToWindowsSlash(*ii);
  2569. }
  2570. this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
  2571. *this->BuildFileStream << "\n";
  2572. // output cl compile flags <ClCompile></ClCompile>
  2573. if(this->GeneratorTarget->GetType() <= cmTarget::OBJECT_LIBRARY)
  2574. {
  2575. this->WriteClOptions(*i, includes);
  2576. // output rc compile flags <ResourceCompile></ResourceCompile>
  2577. this->WriteRCOptions(*i, includes);
  2578. this->WriteMasmOptions(*i, includes);
  2579. }
  2580. // output midl flags <Midl></Midl>
  2581. this->WriteMidlOptions(*i, includes);
  2582. // write events
  2583. this->WriteEvents(*i);
  2584. // output link flags <Link></Link>
  2585. this->WriteLinkOptions(*i);
  2586. // output lib flags <Lib></Lib>
  2587. this->WriteLibOptions(*i);
  2588. // output manifest flags <Manifest></Manifest>
  2589. this->WriteManifestOptions(*i);
  2590. if(this->NsightTegra &&
  2591. this->GeneratorTarget->GetType() == cmTarget::EXECUTABLE &&
  2592. this->Target->GetPropertyAsBool("ANDROID_GUI"))
  2593. {
  2594. this->WriteAntBuildOptions(*i);
  2595. }
  2596. this->WriteString("</ItemDefinitionGroup>\n", 1);
  2597. }
  2598. }
  2599. void
  2600. cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
  2601. {
  2602. bool addedPrelink = false;
  2603. if (this->GeneratorTarget->GetType() == cmTarget::SHARED_LIBRARY &&
  2604. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
  2605. {
  2606. if (this->Target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
  2607. {
  2608. addedPrelink = true;
  2609. std::vector<cmCustomCommand> commands =
  2610. this->Target->GetPreLinkCommands();
  2611. this->GlobalGenerator->AddSymbolExportCommand(
  2612. this->GeneratorTarget, commands, configName);
  2613. this->WriteEvent("PreLinkEvent", commands, configName);
  2614. }
  2615. }
  2616. if (!addedPrelink)
  2617. {
  2618. this->WriteEvent("PreLinkEvent",
  2619. this->Target->GetPreLinkCommands(), configName);
  2620. }
  2621. this->WriteEvent("PreBuildEvent",
  2622. this->Target->GetPreBuildCommands(), configName);
  2623. this->WriteEvent("PostBuildEvent",
  2624. this->Target->GetPostBuildCommands(), configName);
  2625. }
  2626. void cmVisualStudio10TargetGenerator::WriteEvent(
  2627. const char* name,
  2628. std::vector<cmCustomCommand> const& commands,
  2629. std::string const& configName)
  2630. {
  2631. if(commands.empty())
  2632. {
  2633. return;
  2634. }
  2635. this->WriteString("<", 2);
  2636. (*this->BuildFileStream ) << name << ">\n";
  2637. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  2638. std::string script;
  2639. const char* pre = "";
  2640. std::string comment;
  2641. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  2642. i != commands.end(); ++i)
  2643. {
  2644. cmCustomCommandGenerator ccg(*i, configName, this->LocalGenerator);
  2645. comment += pre;
  2646. comment += lg->ConstructComment(ccg);
  2647. script += pre;
  2648. pre = "\n";
  2649. script += cmVS10EscapeXML(lg->ConstructScript(ccg));
  2650. }
  2651. comment = cmVS10EscapeComment(comment);
  2652. this->WriteString("<Message>",3);
  2653. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  2654. this->WriteString("<Command>", 3);
  2655. (*this->BuildFileStream ) << script;
  2656. (*this->BuildFileStream ) << "</Command>" << "\n";
  2657. this->WriteString("</", 2);
  2658. (*this->BuildFileStream ) << name << ">\n";
  2659. }
  2660. void cmVisualStudio10TargetGenerator::WriteProjectReferences()
  2661. {
  2662. cmGlobalGenerator::TargetDependSet const& unordered
  2663. = this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  2664. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  2665. OrderedTargetDependSet;
  2666. OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  2667. this->WriteString("<ItemGroup>\n", 1);
  2668. for( OrderedTargetDependSet::const_iterator i = depends.begin();
  2669. i != depends.end(); ++i)
  2670. {
  2671. cmTarget const* dt = (*i)->Target;
  2672. if(dt->GetType() == cmTarget::INTERFACE_LIBRARY)
  2673. {
  2674. continue;
  2675. }
  2676. // skip fortran targets as they can not be processed by MSBuild
  2677. // the only reference will be in the .sln file
  2678. if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  2679. ->TargetIsFortranOnly(*dt))
  2680. {
  2681. continue;
  2682. }
  2683. this->WriteString("<ProjectReference Include=\"", 2);
  2684. cmMakefile* mf = dt->GetMakefile();
  2685. std::string name = dt->GetName();
  2686. std::string path;
  2687. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  2688. if(p)
  2689. {
  2690. path = p;
  2691. }
  2692. else
  2693. {
  2694. path = mf->GetCurrentBinaryDirectory();
  2695. path += "/";
  2696. path += dt->GetName();
  2697. path += ".vcxproj";
  2698. }
  2699. (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n";
  2700. this->WriteString("<Project>", 3);
  2701. (*this->BuildFileStream)
  2702. << this->GlobalGenerator->GetGUID(name.c_str())
  2703. << "</Project>\n";
  2704. this->WriteString("</ProjectReference>\n", 2);
  2705. }
  2706. this->WriteString("</ItemGroup>\n", 1);
  2707. }
  2708. void cmVisualStudio10TargetGenerator::WritePlatformExtensions()
  2709. {
  2710. // This only applies to Windows 10 apps
  2711. if (this->GlobalGenerator->TargetsWindowsStore() &&
  2712. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0"))
  2713. {
  2714. const char* desktopExtensionsVersion =
  2715. this->Target->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  2716. if (desktopExtensionsVersion)
  2717. {
  2718. this->WriteSinglePlatformExtension("WindowsDesktop",
  2719. desktopExtensionsVersion);
  2720. }
  2721. const char* mobileExtensionsVersion =
  2722. this->Target->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  2723. if (mobileExtensionsVersion)
  2724. {
  2725. this->WriteSinglePlatformExtension("WindowsMobile",
  2726. mobileExtensionsVersion);
  2727. }
  2728. }
  2729. }
  2730. void cmVisualStudio10TargetGenerator::WriteSinglePlatformExtension(
  2731. std::string const& extension,
  2732. std::string const& version
  2733. )
  2734. {
  2735. this->WriteString("<Import Project=", 2);
  2736. (*this->BuildFileStream)
  2737. << "\"$([Microsoft.Build.Utilities.ToolLocationHelper]"
  2738. << "::GetPlatformExtensionSDKLocation(`"
  2739. << extension <<", Version=" << version
  2740. << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  2741. << "$(ExtensionSDKDirectoryRoot), null))"
  2742. << "\\DesignTime\\CommonConfiguration\\Neutral\\"
  2743. << extension << ".props\" "
  2744. << "Condition=\"exists('$("
  2745. << "[Microsoft.Build.Utilities.ToolLocationHelper]"
  2746. << "::GetPlatformExtensionSDKLocation(`"
  2747. << extension << ", Version=" << version
  2748. << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  2749. << "$(ExtensionSDKDirectoryRoot), null))"
  2750. << "\\DesignTime\\CommonConfiguration\\Neutral\\"
  2751. << extension << ".props')\" />\n";
  2752. }
  2753. void cmVisualStudio10TargetGenerator::WriteSDKReferences()
  2754. {
  2755. // This only applies to Windows 10 apps
  2756. if (this->GlobalGenerator->TargetsWindowsStore() &&
  2757. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0"))
  2758. {
  2759. const char* desktopExtensionsVersion =
  2760. this->Target->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  2761. const char* mobileExtensionsVersion =
  2762. this->Target->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  2763. const char* iotExtensionsVersion =
  2764. this->Target->GetProperty("VS_IOT_EXTENSIONS_VERSION");
  2765. if(desktopExtensionsVersion || mobileExtensionsVersion ||
  2766. iotExtensionsVersion)
  2767. {
  2768. this->WriteString("<ItemGroup>\n", 1);
  2769. if(desktopExtensionsVersion)
  2770. {
  2771. this->WriteSingleSDKReference("WindowsDesktop",
  2772. desktopExtensionsVersion);
  2773. }
  2774. if(mobileExtensionsVersion)
  2775. {
  2776. this->WriteSingleSDKReference("WindowsMobile",
  2777. mobileExtensionsVersion);
  2778. }
  2779. if(iotExtensionsVersion)
  2780. {
  2781. this->WriteSingleSDKReference("WindowsIoT",
  2782. iotExtensionsVersion);
  2783. }
  2784. this->WriteString("</ItemGroup>\n", 1);
  2785. }
  2786. }
  2787. }
  2788. void cmVisualStudio10TargetGenerator::WriteSingleSDKReference(
  2789. std::string const& extension,
  2790. std::string const& version
  2791. )
  2792. {
  2793. this->WriteString("<SDKReference Include=\"", 2);
  2794. (*this->BuildFileStream) << extension
  2795. << ", Version=" << version << "\" />\n";
  2796. }
  2797. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
  2798. {
  2799. if((this->GlobalGenerator->TargetsWindowsStore() ||
  2800. this->GlobalGenerator->TargetsWindowsPhone())
  2801. && (cmTarget::EXECUTABLE == this->GeneratorTarget->GetType()))
  2802. {
  2803. std::string pfxFile;
  2804. std::vector<cmSourceFile const*> certificates;
  2805. this->GeneratorTarget->GetCertificates(certificates, "");
  2806. for(std::vector<cmSourceFile const*>::const_iterator si =
  2807. certificates.begin(); si != certificates.end(); ++si)
  2808. {
  2809. pfxFile = this->ConvertPath((*si)->GetFullPath(), false);
  2810. this->ConvertToWindowsSlash(pfxFile);
  2811. break;
  2812. }
  2813. if(this->IsMissingFiles &&
  2814. !(this->GlobalGenerator->TargetsWindowsPhone() &&
  2815. this->GlobalGenerator->GetSystemVersion() == "8.0"))
  2816. {
  2817. // Move the manifest to a project directory to avoid clashes
  2818. std::string artifactDir =
  2819. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2820. this->ConvertToWindowsSlash(artifactDir);
  2821. this->WriteString("<PropertyGroup>\n", 1);
  2822. this->WriteString("<AppxPackageArtifactsDir>", 2);
  2823. (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir) <<
  2824. "\\</AppxPackageArtifactsDir>\n";
  2825. this->WriteString("<ProjectPriFullPath>"
  2826. "$(TargetDir)resources.pri</ProjectPriFullPath>\n", 2);
  2827. // If we are missing files and we don't have a certificate and
  2828. // aren't targeting WP8.0, add a default certificate
  2829. if(pfxFile.empty())
  2830. {
  2831. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  2832. "/Templates/Windows";
  2833. pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  2834. cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
  2835. pfxFile, false);
  2836. this->ConvertToWindowsSlash(pfxFile);
  2837. this->AddedFiles.push_back(pfxFile);
  2838. }
  2839. this->WriteString("<", 2);
  2840. (*this->BuildFileStream) << "PackageCertificateKeyFile>"
  2841. << pfxFile << "</PackageCertificateKeyFile>\n";
  2842. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  2843. if (!thumb.empty())
  2844. {
  2845. this->WriteString("<PackageCertificateThumbprint>", 2);
  2846. (*this->BuildFileStream) << thumb
  2847. << "</PackageCertificateThumbprint>\n";
  2848. }
  2849. this->WriteString("</PropertyGroup>\n", 1);
  2850. }
  2851. else if(!pfxFile.empty())
  2852. {
  2853. this->WriteString("<PropertyGroup>\n", 1);
  2854. this->WriteString("<", 2);
  2855. (*this->BuildFileStream) << "PackageCertificateKeyFile>"
  2856. << pfxFile << "</PackageCertificateKeyFile>\n";
  2857. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  2858. if (!thumb.empty())
  2859. {
  2860. this->WriteString("<PackageCertificateThumbprint>", 2);
  2861. (*this->BuildFileStream) << thumb
  2862. << "</PackageCertificateThumbprint>\n";
  2863. }
  2864. this->WriteString("</PropertyGroup>\n", 1);
  2865. }
  2866. }
  2867. }
  2868. bool cmVisualStudio10TargetGenerator::
  2869. IsResxHeader(const std::string& headerFile)
  2870. {
  2871. std::set<std::string> expectedResxHeaders;
  2872. this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
  2873. std::set<std::string>::const_iterator it =
  2874. expectedResxHeaders.find(headerFile);
  2875. return it != expectedResxHeaders.end();
  2876. }
  2877. bool cmVisualStudio10TargetGenerator::
  2878. IsXamlHeader(const std::string& headerFile)
  2879. {
  2880. std::set<std::string> expectedXamlHeaders;
  2881. this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
  2882. std::set<std::string>::const_iterator it =
  2883. expectedXamlHeaders.find(headerFile);
  2884. return it != expectedXamlHeaders.end();
  2885. }
  2886. bool cmVisualStudio10TargetGenerator::
  2887. IsXamlSource(const std::string& sourceFile)
  2888. {
  2889. std::set<std::string> expectedXamlSources;
  2890. this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
  2891. std::set<std::string>::const_iterator it =
  2892. expectedXamlSources.find(sourceFile);
  2893. return it != expectedXamlSources.end();
  2894. }
  2895. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
  2896. {
  2897. cmGlobalVisualStudio10Generator* gg =
  2898. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2899. bool isAppContainer = false;
  2900. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  2901. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  2902. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2903. if(isWindowsPhone || isWindowsStore)
  2904. {
  2905. this->WriteString("<ApplicationType>", 2);
  2906. (*this->BuildFileStream) << (isWindowsPhone ?
  2907. "Windows Phone" : "Windows Store")
  2908. << "</ApplicationType>\n";
  2909. this->WriteString("<DefaultLanguage>en-US"
  2910. "</DefaultLanguage>\n", 2);
  2911. if (cmHasLiteralPrefix(v, "10.0"))
  2912. {
  2913. this->WriteString("<ApplicationTypeRevision>", 2);
  2914. (*this->BuildFileStream) << cmVS10EscapeXML("10.0")
  2915. << "</ApplicationTypeRevision>\n";
  2916. // Visual Studio 14.0 is necessary for building 10.0 apps
  2917. this->WriteString("<MinimumVisualStudioVersion>14.0"
  2918. "</MinimumVisualStudioVersion>\n", 2);
  2919. if(this->GeneratorTarget->GetType() < cmTarget::UTILITY)
  2920. {
  2921. isAppContainer = true;
  2922. }
  2923. }
  2924. else if(v == "8.1")
  2925. {
  2926. this->WriteString("<ApplicationTypeRevision>", 2);
  2927. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  2928. << "</ApplicationTypeRevision>\n";
  2929. // Visual Studio 12.0 is necessary for building 8.1 apps
  2930. this->WriteString("<MinimumVisualStudioVersion>12.0"
  2931. "</MinimumVisualStudioVersion>\n", 2);
  2932. if (this->GeneratorTarget->GetType() < cmTarget::UTILITY)
  2933. {
  2934. isAppContainer = true;
  2935. }
  2936. }
  2937. else if (v == "8.0")
  2938. {
  2939. this->WriteString("<ApplicationTypeRevision>", 2);
  2940. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  2941. << "</ApplicationTypeRevision>\n";
  2942. // Visual Studio 11.0 is necessary for building 8.0 apps
  2943. this->WriteString("<MinimumVisualStudioVersion>11.0"
  2944. "</MinimumVisualStudioVersion>\n", 2);
  2945. if (isWindowsStore
  2946. && this->GeneratorTarget->GetType() < cmTarget::UTILITY)
  2947. {
  2948. isAppContainer = true;
  2949. }
  2950. else if (isWindowsPhone &&
  2951. this->GeneratorTarget->GetType() == cmTarget::EXECUTABLE)
  2952. {
  2953. this->WriteString("<XapOutputs>true</XapOutputs>\n", 2);
  2954. this->WriteString("<XapFilename>", 2);
  2955. (*this->BuildFileStream) << cmVS10EscapeXML(this->Name.c_str()) <<
  2956. "_$(Configuration)_$(Platform).xap</XapFilename>\n";
  2957. }
  2958. }
  2959. }
  2960. if(isAppContainer)
  2961. {
  2962. this->WriteString("<AppContainerApplication>true"
  2963. "</AppContainerApplication>\n", 2);
  2964. }
  2965. else if (this->Platform == "ARM")
  2966. {
  2967. this->WriteString("<WindowsSDKDesktopARMSupport>true"
  2968. "</WindowsSDKDesktopARMSupport>\n", 2);
  2969. }
  2970. std::string const& targetPlatformVersion =
  2971. gg->GetWindowsTargetPlatformVersion();
  2972. if (!targetPlatformVersion.empty())
  2973. {
  2974. this->WriteString("<WindowsTargetPlatformVersion>", 2);
  2975. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion) <<
  2976. "</WindowsTargetPlatformVersion>\n";
  2977. }
  2978. const char* targetPlatformMinVersion =
  2979. this->Target->GetProperty("VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
  2980. if(targetPlatformMinVersion)
  2981. {
  2982. this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
  2983. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformMinVersion) <<
  2984. "</WindowsTargetPlatformMinVersion>\n";
  2985. }
  2986. else if (isWindowsStore && cmHasLiteralPrefix(v, "10.0"))
  2987. {
  2988. // If the min version is not set, then use the TargetPlatformVersion
  2989. if (!targetPlatformVersion.empty())
  2990. {
  2991. this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
  2992. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion) <<
  2993. "</WindowsTargetPlatformMinVersion>\n";
  2994. }
  2995. }
  2996. // Added IoT Startup Task support
  2997. if(this->Target->GetPropertyAsBool("VS_IOT_STARTUP_TASK"))
  2998. {
  2999. this->WriteString("<ContainsStartupTask>true</ContainsStartupTask>\n", 2);
  3000. }
  3001. }
  3002. void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
  3003. {
  3004. // For Windows and Windows Phone executables, we will assume that if a
  3005. // manifest is not present that we need to add all the necessary files
  3006. if (this->GeneratorTarget->GetType() == cmTarget::EXECUTABLE)
  3007. {
  3008. std::vector<cmSourceFile const*> manifestSources;
  3009. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  3010. {
  3011. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3012. if(this->GlobalGenerator->TargetsWindowsPhone())
  3013. {
  3014. if (v == "8.0")
  3015. {
  3016. // Look through the sources for WMAppManifest.xml
  3017. std::vector<cmSourceFile const*> extraSources;
  3018. this->GeneratorTarget->GetExtraSources(extraSources, "");
  3019. bool foundManifest = false;
  3020. for(std::vector<cmSourceFile const*>::const_iterator si =
  3021. extraSources.begin(); si != extraSources.end(); ++si)
  3022. {
  3023. // Need to do a lowercase comparison on the filename
  3024. if("wmappmanifest.xml" == cmSystemTools::LowerCase(
  3025. (*si)->GetLocation().GetName()))
  3026. {
  3027. foundManifest = true;
  3028. break;
  3029. }
  3030. }
  3031. if (!foundManifest)
  3032. {
  3033. this->IsMissingFiles = true;
  3034. }
  3035. }
  3036. else if (v == "8.1")
  3037. {
  3038. if(manifestSources.empty())
  3039. {
  3040. this->IsMissingFiles = true;
  3041. }
  3042. }
  3043. }
  3044. else if (this->GlobalGenerator->TargetsWindowsStore())
  3045. {
  3046. if (manifestSources.empty())
  3047. {
  3048. if (v == "8.0")
  3049. {
  3050. this->IsMissingFiles = true;
  3051. }
  3052. else if (v == "8.1" || cmHasLiteralPrefix(v, "10.0"))
  3053. {
  3054. this->IsMissingFiles = true;
  3055. }
  3056. }
  3057. }
  3058. }
  3059. }
  3060. }
  3061. void cmVisualStudio10TargetGenerator::WriteMissingFiles()
  3062. {
  3063. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3064. if(this->GlobalGenerator->TargetsWindowsPhone())
  3065. {
  3066. if (v == "8.0")
  3067. {
  3068. this->WriteMissingFilesWP80();
  3069. }
  3070. else if (v == "8.1")
  3071. {
  3072. this->WriteMissingFilesWP81();
  3073. }
  3074. }
  3075. else if (this->GlobalGenerator->TargetsWindowsStore())
  3076. {
  3077. if (v == "8.0")
  3078. {
  3079. this->WriteMissingFilesWS80();
  3080. }
  3081. else if (v == "8.1")
  3082. {
  3083. this->WriteMissingFilesWS81();
  3084. }
  3085. else if (cmHasLiteralPrefix(v, "10.0"))
  3086. {
  3087. this->WriteMissingFilesWS10_0();
  3088. }
  3089. }
  3090. }
  3091. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
  3092. {
  3093. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  3094. "/Templates/Windows";
  3095. // For WP80, the manifest needs to be in the same folder as the project
  3096. // this can cause an overwrite problem if projects aren't organized in
  3097. // folders
  3098. std::string manifestFile =
  3099. this->LocalGenerator->GetCurrentBinaryDirectory() +
  3100. std::string("/WMAppManifest.xml");
  3101. std::string artifactDir =
  3102. this->LocalGenerator->GetTargetDirectory(*this->Target);
  3103. this->ConvertToWindowsSlash(artifactDir);
  3104. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3105. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  3106. cmGeneratedFileStream fout(manifestFile.c_str());
  3107. fout.SetCopyIfDifferent(true);
  3108. fout <<
  3109. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3110. "<Deployment"
  3111. " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
  3112. " AppPlatformVersion=\"8.0\">\n"
  3113. "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
  3114. "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
  3115. " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
  3116. " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
  3117. " Description=\"Default CMake App\" Publisher=\"CMake\""
  3118. " PublisherID=\"{" << this->GUID << "}\">\n"
  3119. "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
  3120. << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
  3121. "\t\t<Capabilities/>\n"
  3122. "\t\t<Tasks>\n"
  3123. "\t\t\t<DefaultTask Name=\"_default\""
  3124. " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
  3125. "\t\t</Tasks>\n"
  3126. "\t\t<Tokens>\n"
  3127. "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
  3128. " TaskName=\"_default\">\n"
  3129. "\t\t\t\t<TemplateFlip>\n"
  3130. "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
  3131. << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
  3132. "\t\t\t\t\t<Count>0</Count>\n"
  3133. "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
  3134. << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
  3135. "\t\t\t\t</TemplateFlip>\n"
  3136. "\t\t\t</PrimaryToken>\n"
  3137. "\t\t</Tokens>\n"
  3138. "\t\t<ScreenResolutions>\n"
  3139. "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
  3140. "\t\t</ScreenResolutions>\n"
  3141. "\t</App>\n"
  3142. "</Deployment>\n";
  3143. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3144. this->ConvertToWindowsSlash(sourceFile);
  3145. this->WriteString("<Xml Include=\"", 2);
  3146. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  3147. this->WriteString("<SubType>Designer</SubType>\n", 3);
  3148. this->WriteString("</Xml>\n", 2);
  3149. this->AddedFiles.push_back(sourceFile);
  3150. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3151. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png",
  3152. smallLogo, false);
  3153. this->ConvertToWindowsSlash(smallLogo);
  3154. this->WriteString("<Image Include=\"", 2);
  3155. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  3156. this->AddedFiles.push_back(smallLogo);
  3157. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3158. cmSystemTools::CopyAFile(templateFolder + "/Logo.png",
  3159. logo, false);
  3160. this->ConvertToWindowsSlash(logo);
  3161. this->WriteString("<Image Include=\"", 2);
  3162. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  3163. this->AddedFiles.push_back(logo);
  3164. std::string applicationIcon =
  3165. this->DefaultArtifactDir + "/ApplicationIcon.png";
  3166. cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
  3167. applicationIcon, false);
  3168. this->ConvertToWindowsSlash(applicationIcon);
  3169. this->WriteString("<Image Include=\"", 2);
  3170. (*this->BuildFileStream) << cmVS10EscapeXML(applicationIcon) << "\" />\n";
  3171. this->AddedFiles.push_back(applicationIcon);
  3172. }
  3173. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
  3174. {
  3175. std::string manifestFile =
  3176. this->DefaultArtifactDir + "/package.appxManifest";
  3177. std::string artifactDir =
  3178. this->LocalGenerator->GetTargetDirectory(*this->Target);
  3179. this->ConvertToWindowsSlash(artifactDir);
  3180. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3181. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  3182. cmGeneratedFileStream fout(manifestFile.c_str());
  3183. fout.SetCopyIfDifferent(true);
  3184. fout <<
  3185. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3186. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  3187. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
  3188. " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
  3189. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3190. " Version=\"1.0.0.0\" />\n"
  3191. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
  3192. " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  3193. "\t<Properties>\n"
  3194. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3195. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3196. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3197. "\t</Properties>\n"
  3198. "\t<Prerequisites>\n"
  3199. "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
  3200. "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
  3201. "\t</Prerequisites>\n"
  3202. "\t<Resources>\n"
  3203. "\t\t<Resource Language=\"x-generate\" />\n"
  3204. "\t</Resources>\n"
  3205. "\t<Applications>\n"
  3206. "\t\t<Application Id=\"App\""
  3207. " Executable=\"" << targetNameXML << ".exe\""
  3208. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3209. "\t\t\t<m2:VisualElements\n"
  3210. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3211. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3212. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3213. "\t\t\t\tForegroundText=\"light\"\n"
  3214. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3215. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3216. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  3217. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  3218. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  3219. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  3220. "\t\t\t\t</m2:DefaultTile>\n"
  3221. "\t\t\t\t<m2:SplashScreen"
  3222. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3223. "\t\t\t</m2:VisualElements>\n"
  3224. "\t\t</Application>\n"
  3225. "\t</Applications>\n"
  3226. "</Package>\n";
  3227. this->WriteCommonMissingFiles(manifestFile);
  3228. }
  3229. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
  3230. {
  3231. std::string manifestFile =
  3232. this->DefaultArtifactDir + "/package.appxManifest";
  3233. std::string artifactDir =
  3234. this->LocalGenerator->GetTargetDirectory(*this->Target);
  3235. this->ConvertToWindowsSlash(artifactDir);
  3236. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3237. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  3238. cmGeneratedFileStream fout(manifestFile.c_str());
  3239. fout.SetCopyIfDifferent(true);
  3240. fout <<
  3241. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3242. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
  3243. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3244. " Version=\"1.0.0.0\" />\n"
  3245. "\t<Properties>\n"
  3246. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3247. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3248. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3249. "\t</Properties>\n"
  3250. "\t<Prerequisites>\n"
  3251. "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
  3252. "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
  3253. "\t</Prerequisites>\n"
  3254. "\t<Resources>\n"
  3255. "\t\t<Resource Language=\"x-generate\" />\n"
  3256. "\t</Resources>\n"
  3257. "\t<Applications>\n"
  3258. "\t\t<Application Id=\"App\""
  3259. " Executable=\"" << targetNameXML << ".exe\""
  3260. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3261. "\t\t\t<VisualElements"
  3262. " DisplayName=\"" << targetNameXML << "\""
  3263. " Description=\"" << targetNameXML << "\""
  3264. " BackgroundColor=\"#336699\" ForegroundText=\"light\""
  3265. " Logo=\"" << artifactDirXML << "\\Logo.png\""
  3266. " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3267. "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
  3268. " ShortName=\"" << targetNameXML << "\" />\n"
  3269. "\t\t\t\t<SplashScreen"
  3270. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3271. "\t\t\t</VisualElements>\n"
  3272. "\t\t</Application>\n"
  3273. "\t</Applications>\n"
  3274. "</Package>\n";
  3275. this->WriteCommonMissingFiles(manifestFile);
  3276. }
  3277. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
  3278. {
  3279. std::string manifestFile =
  3280. this->DefaultArtifactDir + "/package.appxManifest";
  3281. std::string artifactDir =
  3282. this->LocalGenerator->GetTargetDirectory(*this->Target);
  3283. this->ConvertToWindowsSlash(artifactDir);
  3284. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3285. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  3286. cmGeneratedFileStream fout(manifestFile.c_str());
  3287. fout.SetCopyIfDifferent(true);
  3288. fout <<
  3289. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3290. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  3291. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
  3292. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3293. " Version=\"1.0.0.0\" />\n"
  3294. "\t<Properties>\n"
  3295. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3296. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3297. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3298. "\t</Properties>\n"
  3299. "\t<Prerequisites>\n"
  3300. "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
  3301. "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
  3302. "\t</Prerequisites>\n"
  3303. "\t<Resources>\n"
  3304. "\t\t<Resource Language=\"x-generate\" />\n"
  3305. "\t</Resources>\n"
  3306. "\t<Applications>\n"
  3307. "\t\t<Application Id=\"App\""
  3308. " Executable=\"" << targetNameXML << ".exe\""
  3309. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3310. "\t\t\t<m2:VisualElements\n"
  3311. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3312. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3313. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3314. "\t\t\t\tForegroundText=\"light\"\n"
  3315. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3316. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3317. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  3318. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  3319. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  3320. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  3321. "\t\t\t\t</m2:DefaultTile>\n"
  3322. "\t\t\t\t<m2:SplashScreen"
  3323. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3324. "\t\t\t</m2:VisualElements>\n"
  3325. "\t\t</Application>\n"
  3326. "\t</Applications>\n"
  3327. "</Package>\n";
  3328. this->WriteCommonMissingFiles(manifestFile);
  3329. }
  3330. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0()
  3331. {
  3332. std::string manifestFile =
  3333. this->DefaultArtifactDir + "/package.appxManifest";
  3334. std::string artifactDir =
  3335. this->LocalGenerator->GetTargetDirectory(*this->Target);
  3336. this->ConvertToWindowsSlash(artifactDir);
  3337. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3338. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  3339. cmGeneratedFileStream fout(manifestFile.c_str());
  3340. fout.SetCopyIfDifferent(true);
  3341. fout <<
  3342. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3343. "<Package\n\t"
  3344. "xmlns=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10\""
  3345. "\txmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\"\n"
  3346. "\txmlns:uap=\"http://schemas.microsoft.com/appx/manifest/uap/windows10\""
  3347. "\n\tIgnorableNamespaces=\"uap mp\">\n\n"
  3348. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3349. " Version=\"1.0.0.0\" />\n"
  3350. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID <<
  3351. "\" PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  3352. "\t<Properties>\n"
  3353. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3354. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3355. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3356. "\t</Properties>\n"
  3357. "\t<Dependencies>\n"
  3358. "\t\t<TargetDeviceFamily Name=\"Windows.Universal\" "
  3359. "MinVersion=\"10.0.0.0\" MaxVersionTested=\"10.0.0.0\" />\n"
  3360. "\t</Dependencies>\n"
  3361. "\t<Resources>\n"
  3362. "\t\t<Resource Language=\"x-generate\" />\n"
  3363. "\t</Resources>\n"
  3364. "\t<Applications>\n"
  3365. "\t\t<Application Id=\"App\""
  3366. " Executable=\"" << targetNameXML << ".exe\""
  3367. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3368. "\t\t\t<uap:VisualElements\n"
  3369. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3370. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3371. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3372. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3373. "\t\t\t\tSquare44x44Logo=\"" << artifactDirXML <<
  3374. "\\SmallLogo44x44.png\">\n"
  3375. "\t\t\t\t<uap:SplashScreen"
  3376. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3377. "\t\t\t</uap:VisualElements>\n"
  3378. "\t\t</Application>\n"
  3379. "\t</Applications>\n"
  3380. "</Package>\n";
  3381. this->WriteCommonMissingFiles(manifestFile);
  3382. }
  3383. void
  3384. cmVisualStudio10TargetGenerator
  3385. ::WriteCommonMissingFiles(const std::string& manifestFile)
  3386. {
  3387. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  3388. "/Templates/Windows";
  3389. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3390. this->ConvertToWindowsSlash(sourceFile);
  3391. this->WriteString("<AppxManifest Include=\"", 2);
  3392. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  3393. this->WriteString("<SubType>Designer</SubType>\n", 3);
  3394. this->WriteString("</AppxManifest>\n", 2);
  3395. this->AddedFiles.push_back(sourceFile);
  3396. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3397. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png",
  3398. smallLogo, false);
  3399. this->ConvertToWindowsSlash(smallLogo);
  3400. this->WriteString("<Image Include=\"", 2);
  3401. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  3402. this->AddedFiles.push_back(smallLogo);
  3403. std::string smallLogo44 = this->DefaultArtifactDir + "/SmallLogo44x44.png";
  3404. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo44x44.png",
  3405. smallLogo44, false);
  3406. this->ConvertToWindowsSlash(smallLogo44);
  3407. this->WriteString("<Image Include=\"", 2);
  3408. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo44) << "\" />\n";
  3409. this->AddedFiles.push_back(smallLogo44);
  3410. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3411. cmSystemTools::CopyAFile(templateFolder + "/Logo.png",
  3412. logo, false);
  3413. this->ConvertToWindowsSlash(logo);
  3414. this->WriteString("<Image Include=\"", 2);
  3415. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  3416. this->AddedFiles.push_back(logo);
  3417. std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
  3418. cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png",
  3419. storeLogo, false);
  3420. this->ConvertToWindowsSlash(storeLogo);
  3421. this->WriteString("<Image Include=\"", 2);
  3422. (*this->BuildFileStream) << cmVS10EscapeXML(storeLogo) << "\" />\n";
  3423. this->AddedFiles.push_back(storeLogo);
  3424. std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
  3425. cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png",
  3426. splashScreen, false);
  3427. this->ConvertToWindowsSlash(splashScreen);
  3428. this->WriteString("<Image Include=\"", 2);
  3429. (*this->BuildFileStream) << cmVS10EscapeXML(splashScreen) << "\" />\n";
  3430. this->AddedFiles.push_back(splashScreen);
  3431. // This file has already been added to the build so don't copy it
  3432. std::string keyFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  3433. this->ConvertToWindowsSlash(keyFile);
  3434. this->WriteString("<None Include=\"", 2);
  3435. (*this->BuildFileStream) << cmVS10EscapeXML(keyFile) << "\" />\n";
  3436. }
  3437. bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
  3438. {
  3439. HANDLE h = CreateFileW(
  3440. cmSystemTools::ConvertToWindowsExtendedPath(source).c_str(),
  3441. FILE_WRITE_ATTRIBUTES,
  3442. FILE_SHARE_WRITE, 0, OPEN_EXISTING,
  3443. FILE_FLAG_BACKUP_SEMANTICS, 0);
  3444. if (!h)
  3445. {
  3446. return false;
  3447. }
  3448. FILETIME const ftime_20010101 = { 3365781504u, 29389701u };
  3449. if (!SetFileTime(h, &ftime_20010101, &ftime_20010101, &ftime_20010101))
  3450. {
  3451. CloseHandle(h);
  3452. return false;
  3453. }
  3454. CloseHandle(h);
  3455. return true;
  3456. }