1
0

cmVisualStudio10TargetGenerator.cxx 165 KB

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