cmVisualStudio10TargetGenerator.cxx 169 KB

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