cmVisualStudio10TargetGenerator.cxx 180 KB

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