cmVisualStudio10TargetGenerator.cxx 184 KB

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