cmVisualStudio10TargetGenerator.cxx 198 KB

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