cmVisualStudio10TargetGenerator.cxx 166 KB

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