cmVisualStudio10TargetGenerator.cxx 160 KB

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