cmVisualStudio10TargetGenerator.cxx 167 KB

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