cmVisualStudio10TargetGenerator.cxx 179 KB

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