cmVisualStudio10TargetGenerator.cxx 162 KB

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