cmVisualStudio10TargetGenerator.cxx 216 KB

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