cmVisualStudio10TargetGenerator.cxx 183 KB

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