cmVisualStudio10TargetGenerator.cxx 166 KB

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