cmVisualStudio10TargetGenerator.cxx 166 KB

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