cmVisualStudio10TargetGenerator.cxx 162 KB

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