cmVisualStudio10TargetGenerator.cxx 167 KB

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