cmVisualStudio10TargetGenerator.cxx 160 KB

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