cmVisualStudio10TargetGenerator.cxx 162 KB

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