cmVisualStudio10TargetGenerator.cxx 166 KB

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