cmVisualStudio10TargetGenerator.cxx 180 KB

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