cmVisualStudio10TargetGenerator.cxx 163 KB

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