cmVisualStudio10TargetGenerator.cxx 183 KB

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