cmVisualStudio10TargetGenerator.cxx 159 KB

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