cmVisualStudio10TargetGenerator.cxx 160 KB

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