cmVisualStudio10TargetGenerator.cxx 166 KB

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