cmGeneratorTarget.cxx 264 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGeneratorTarget.h"
  4. #include <algorithm>
  5. #include <cassert>
  6. #include <cerrno>
  7. #include <cstddef>
  8. #include <cstdio>
  9. #include <cstdlib>
  10. #include <cstring>
  11. #include <iterator>
  12. #include <queue>
  13. #include <sstream>
  14. #include <unordered_set>
  15. #include <utility>
  16. #include <cm/memory>
  17. #include <cm/string_view>
  18. #include <cmext/algorithm>
  19. #include <cmext/string_view>
  20. #include "cmsys/RegularExpression.hxx"
  21. #include "cmAlgorithms.h"
  22. #include "cmComputeLinkInformation.h"
  23. #include "cmCustomCommandGenerator.h"
  24. #include "cmFileTimes.h"
  25. #include "cmGeneratedFileStream.h"
  26. #include "cmGeneratorExpression.h"
  27. #include "cmGeneratorExpressionContext.h"
  28. #include "cmGeneratorExpressionDAGChecker.h"
  29. #include "cmGeneratorExpressionNode.h"
  30. #include "cmGlobalGenerator.h"
  31. #include "cmLocalGenerator.h"
  32. #include "cmMakefile.h"
  33. #include "cmMessageType.h"
  34. #include "cmOutputConverter.h"
  35. #include "cmPropertyMap.h"
  36. #include "cmRange.h"
  37. #include "cmSourceFile.h"
  38. #include "cmSourceFileLocation.h"
  39. #include "cmSourceFileLocationKind.h"
  40. #include "cmStandardLevelResolver.h"
  41. #include "cmState.h"
  42. #include "cmStringAlgorithms.h"
  43. #include "cmSystemTools.h"
  44. #include "cmTarget.h"
  45. #include "cmTargetLinkLibraryType.h"
  46. #include "cmTargetPropertyComputer.h"
  47. #include "cmake.h"
  48. class cmMessenger;
  49. namespace {
  50. const cmsys::RegularExpression FrameworkRegularExpression(
  51. "^(.*/)?([^/]*)\\.framework/(.*)$");
  52. }
  53. template <>
  54. cmValue cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
  55. cmGeneratorTarget const* tgt, cmMessenger* /* messenger */,
  56. cmListFileBacktrace const& /* context */)
  57. {
  58. return tgt->GetSourcesProperty();
  59. }
  60. template <>
  61. const std::string&
  62. cmTargetPropertyComputer::ComputeLocationForBuild<cmGeneratorTarget>(
  63. cmGeneratorTarget const* tgt)
  64. {
  65. return tgt->GetLocation("");
  66. }
  67. template <>
  68. const std::string&
  69. cmTargetPropertyComputer::ComputeLocation<cmGeneratorTarget>(
  70. cmGeneratorTarget const* tgt, const std::string& config)
  71. {
  72. return tgt->GetLocation(config);
  73. }
  74. class cmGeneratorTarget::TargetPropertyEntry
  75. {
  76. protected:
  77. static cmLinkImplItem NoLinkImplItem;
  78. public:
  79. TargetPropertyEntry(cmLinkImplItem const& item)
  80. : LinkImplItem(item)
  81. {
  82. }
  83. virtual ~TargetPropertyEntry() = default;
  84. virtual const std::string& Evaluate(
  85. cmLocalGenerator* lg, const std::string& config,
  86. cmGeneratorTarget const* headTarget,
  87. cmGeneratorExpressionDAGChecker* dagChecker,
  88. std::string const& language) const = 0;
  89. virtual cmListFileBacktrace GetBacktrace() const = 0;
  90. virtual std::string const& GetInput() const = 0;
  91. virtual bool GetHadContextSensitiveCondition() const { return false; }
  92. cmLinkImplItem const& LinkImplItem;
  93. };
  94. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  95. class TargetPropertyEntryGenex : public cmGeneratorTarget::TargetPropertyEntry
  96. {
  97. public:
  98. TargetPropertyEntryGenex(std::unique_ptr<cmCompiledGeneratorExpression> cge,
  99. cmLinkImplItem const& item = NoLinkImplItem)
  100. : cmGeneratorTarget::TargetPropertyEntry(item)
  101. , ge(std::move(cge))
  102. {
  103. }
  104. const std::string& Evaluate(cmLocalGenerator* lg, const std::string& config,
  105. cmGeneratorTarget const* headTarget,
  106. cmGeneratorExpressionDAGChecker* dagChecker,
  107. std::string const& language) const override
  108. {
  109. return this->ge->Evaluate(lg, config, headTarget, dagChecker, nullptr,
  110. language);
  111. }
  112. cmListFileBacktrace GetBacktrace() const override
  113. {
  114. return this->ge->GetBacktrace();
  115. }
  116. std::string const& GetInput() const override { return this->ge->GetInput(); }
  117. bool GetHadContextSensitiveCondition() const override
  118. {
  119. return this->ge->GetHadContextSensitiveCondition();
  120. }
  121. private:
  122. const std::unique_ptr<cmCompiledGeneratorExpression> ge;
  123. };
  124. class TargetPropertyEntryString : public cmGeneratorTarget::TargetPropertyEntry
  125. {
  126. public:
  127. TargetPropertyEntryString(BT<std::string> propertyValue,
  128. cmLinkImplItem const& item = NoLinkImplItem)
  129. : cmGeneratorTarget::TargetPropertyEntry(item)
  130. , PropertyValue(std::move(propertyValue))
  131. {
  132. }
  133. const std::string& Evaluate(cmLocalGenerator*, const std::string&,
  134. cmGeneratorTarget const*,
  135. cmGeneratorExpressionDAGChecker*,
  136. std::string const&) const override
  137. {
  138. return this->PropertyValue.Value;
  139. }
  140. cmListFileBacktrace GetBacktrace() const override
  141. {
  142. return this->PropertyValue.Backtrace;
  143. }
  144. std::string const& GetInput() const override
  145. {
  146. return this->PropertyValue.Value;
  147. }
  148. private:
  149. BT<std::string> PropertyValue;
  150. };
  151. std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>
  152. CreateTargetPropertyEntry(const BT<std::string>& propertyValue,
  153. bool evaluateForBuildsystem = false)
  154. {
  155. if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) {
  156. cmGeneratorExpression ge(propertyValue.Backtrace);
  157. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  158. ge.Parse(propertyValue.Value);
  159. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  160. return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
  161. cm::make_unique<TargetPropertyEntryGenex>(std::move(cge)));
  162. }
  163. return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
  164. cm::make_unique<TargetPropertyEntryString>(propertyValue));
  165. }
  166. void CreatePropertyGeneratorExpressions(
  167. cmBTStringRange entries,
  168. std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>>& items,
  169. bool evaluateForBuildsystem = false)
  170. {
  171. for (auto const& entry : entries) {
  172. items.push_back(CreateTargetPropertyEntry(entry, evaluateForBuildsystem));
  173. }
  174. }
  175. namespace {
  176. // Represent a target property entry after evaluating generator expressions
  177. // and splitting up lists.
  178. struct EvaluatedTargetPropertyEntry
  179. {
  180. EvaluatedTargetPropertyEntry(cmLinkImplItem const& item,
  181. cmListFileBacktrace bt)
  182. : LinkImplItem(item)
  183. , Backtrace(std::move(bt))
  184. {
  185. }
  186. // Move-only.
  187. EvaluatedTargetPropertyEntry(EvaluatedTargetPropertyEntry&&) = default;
  188. EvaluatedTargetPropertyEntry(EvaluatedTargetPropertyEntry const&) = delete;
  189. EvaluatedTargetPropertyEntry& operator=(EvaluatedTargetPropertyEntry&&) =
  190. delete;
  191. EvaluatedTargetPropertyEntry& operator=(
  192. EvaluatedTargetPropertyEntry const&) = delete;
  193. cmLinkImplItem const& LinkImplItem;
  194. cmListFileBacktrace Backtrace;
  195. std::vector<std::string> Values;
  196. bool ContextDependent = false;
  197. };
  198. EvaluatedTargetPropertyEntry EvaluateTargetPropertyEntry(
  199. cmGeneratorTarget const* thisTarget, std::string const& config,
  200. std::string const& lang, cmGeneratorExpressionDAGChecker* dagChecker,
  201. cmGeneratorTarget::TargetPropertyEntry& entry)
  202. {
  203. EvaluatedTargetPropertyEntry ee(entry.LinkImplItem, entry.GetBacktrace());
  204. cmExpandList(entry.Evaluate(thisTarget->GetLocalGenerator(), config,
  205. thisTarget, dagChecker, lang),
  206. ee.Values);
  207. if (entry.GetHadContextSensitiveCondition()) {
  208. ee.ContextDependent = true;
  209. }
  210. return ee;
  211. }
  212. struct EvaluatedTargetPropertyEntries
  213. {
  214. std::vector<EvaluatedTargetPropertyEntry> Entries;
  215. bool HadContextSensitiveCondition = false;
  216. };
  217. EvaluatedTargetPropertyEntries EvaluateTargetPropertyEntries(
  218. cmGeneratorTarget const* thisTarget, std::string const& config,
  219. std::string const& lang, cmGeneratorExpressionDAGChecker* dagChecker,
  220. std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>> const&
  221. in)
  222. {
  223. EvaluatedTargetPropertyEntries out;
  224. out.Entries.reserve(in.size());
  225. for (auto const& entry : in) {
  226. out.Entries.emplace_back(EvaluateTargetPropertyEntry(
  227. thisTarget, config, lang, dagChecker, *entry));
  228. }
  229. return out;
  230. }
  231. }
  232. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  233. : Target(t)
  234. , FortranModuleDirectoryCreated(false)
  235. , SourceFileFlagsConstructed(false)
  236. , PolicyWarnedCMP0022(false)
  237. , PolicyReportedCMP0069(false)
  238. , DebugIncludesDone(false)
  239. , DebugCompileOptionsDone(false)
  240. , DebugCompileFeaturesDone(false)
  241. , DebugCompileDefinitionsDone(false)
  242. , DebugLinkOptionsDone(false)
  243. , DebugLinkDirectoriesDone(false)
  244. , DebugPrecompileHeadersDone(false)
  245. , DebugSourcesDone(false)
  246. , UtilityItemsDone(false)
  247. , SourcesAreContextDependent(Tribool::Indeterminate)
  248. {
  249. this->Makefile = this->Target->GetMakefile();
  250. this->LocalGenerator = lg;
  251. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  252. this->GlobalGenerator->ComputeTargetObjectDirectory(this);
  253. CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(),
  254. this->IncludeDirectoriesEntries);
  255. CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(),
  256. this->CompileOptionsEntries);
  257. CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(),
  258. this->CompileFeaturesEntries);
  259. CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(),
  260. this->CompileDefinitionsEntries);
  261. CreatePropertyGeneratorExpressions(t->GetLinkOptionsEntries(),
  262. this->LinkOptionsEntries);
  263. CreatePropertyGeneratorExpressions(t->GetLinkDirectoriesEntries(),
  264. this->LinkDirectoriesEntries);
  265. CreatePropertyGeneratorExpressions(t->GetPrecompileHeadersEntries(),
  266. this->PrecompileHeadersEntries);
  267. CreatePropertyGeneratorExpressions(t->GetSourceEntries(),
  268. this->SourceEntries, true);
  269. this->PolicyMap = t->GetPolicyMap();
  270. // Get hard-coded linker language
  271. if (this->Target->GetProperty("HAS_CXX")) {
  272. this->LinkerLanguage = "CXX";
  273. } else {
  274. this->LinkerLanguage = this->Target->GetSafeProperty("LINKER_LANGUAGE");
  275. }
  276. }
  277. cmGeneratorTarget::~cmGeneratorTarget() = default;
  278. cmValue cmGeneratorTarget::GetSourcesProperty() const
  279. {
  280. std::vector<std::string> values;
  281. for (auto const& se : this->SourceEntries) {
  282. values.push_back(se->GetInput());
  283. }
  284. static std::string value;
  285. value.clear();
  286. value = cmJoin(values, ";");
  287. return cmValue(value);
  288. }
  289. cmGlobalGenerator* cmGeneratorTarget::GetGlobalGenerator() const
  290. {
  291. return this->GetLocalGenerator()->GetGlobalGenerator();
  292. }
  293. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  294. {
  295. return this->LocalGenerator;
  296. }
  297. cmStateEnums::TargetType cmGeneratorTarget::GetType() const
  298. {
  299. return this->Target->GetType();
  300. }
  301. const std::string& cmGeneratorTarget::GetName() const
  302. {
  303. return this->Target->GetName();
  304. }
  305. std::string cmGeneratorTarget::GetExportName() const
  306. {
  307. cmValue exportName = this->GetProperty("EXPORT_NAME");
  308. if (cmNonempty(exportName)) {
  309. if (!cmGeneratorExpression::IsValidTargetName(*exportName)) {
  310. std::ostringstream e;
  311. e << "EXPORT_NAME property \"" << *exportName << "\" for \""
  312. << this->GetName() << "\": is not valid.";
  313. cmSystemTools::Error(e.str());
  314. return "";
  315. }
  316. return *exportName;
  317. }
  318. return this->GetName();
  319. }
  320. cmValue cmGeneratorTarget::GetProperty(const std::string& prop) const
  321. {
  322. if (cmValue result = cmTargetPropertyComputer::GetProperty(
  323. this, prop, this->Makefile->GetMessenger(), this->GetBacktrace())) {
  324. return result;
  325. }
  326. if (cmSystemTools::GetFatalErrorOccured()) {
  327. return nullptr;
  328. }
  329. return this->Target->GetProperty(prop);
  330. }
  331. std::string const& cmGeneratorTarget::GetSafeProperty(
  332. std::string const& prop) const
  333. {
  334. return this->GetProperty(prop);
  335. }
  336. const char* cmGeneratorTarget::GetOutputTargetType(
  337. cmStateEnums::ArtifactType artifact) const
  338. {
  339. switch (this->GetType()) {
  340. case cmStateEnums::SHARED_LIBRARY:
  341. if (this->IsDLLPlatform()) {
  342. switch (artifact) {
  343. case cmStateEnums::RuntimeBinaryArtifact:
  344. // A DLL shared library is treated as a runtime target.
  345. return "RUNTIME";
  346. case cmStateEnums::ImportLibraryArtifact:
  347. // A DLL import library is treated as an archive target.
  348. return "ARCHIVE";
  349. }
  350. } else {
  351. // For non-DLL platforms shared libraries are treated as
  352. // library targets.
  353. return "LIBRARY";
  354. }
  355. break;
  356. case cmStateEnums::STATIC_LIBRARY:
  357. // Static libraries are always treated as archive targets.
  358. return "ARCHIVE";
  359. case cmStateEnums::MODULE_LIBRARY:
  360. switch (artifact) {
  361. case cmStateEnums::RuntimeBinaryArtifact:
  362. // Module libraries are always treated as library targets.
  363. return "LIBRARY";
  364. case cmStateEnums::ImportLibraryArtifact:
  365. // Module import libraries are treated as archive targets.
  366. return "ARCHIVE";
  367. }
  368. break;
  369. case cmStateEnums::OBJECT_LIBRARY:
  370. // Object libraries are always treated as object targets.
  371. return "OBJECT";
  372. case cmStateEnums::EXECUTABLE:
  373. switch (artifact) {
  374. case cmStateEnums::RuntimeBinaryArtifact:
  375. // Executables are always treated as runtime targets.
  376. return "RUNTIME";
  377. case cmStateEnums::ImportLibraryArtifact:
  378. // Executable import libraries are treated as archive targets.
  379. return "ARCHIVE";
  380. }
  381. break;
  382. default:
  383. break;
  384. }
  385. return "";
  386. }
  387. std::string cmGeneratorTarget::GetOutputName(
  388. const std::string& config, cmStateEnums::ArtifactType artifact) const
  389. {
  390. // Lookup/compute/cache the output name for this configuration.
  391. OutputNameKey key(config, artifact);
  392. auto i = this->OutputNameMap.find(key);
  393. if (i == this->OutputNameMap.end()) {
  394. // Add empty name in map to detect potential recursion.
  395. OutputNameMapType::value_type entry(key, "");
  396. i = this->OutputNameMap.insert(entry).first;
  397. // Compute output name.
  398. std::vector<std::string> props;
  399. std::string type = this->GetOutputTargetType(artifact);
  400. std::string configUpper = cmSystemTools::UpperCase(config);
  401. if (!type.empty() && !configUpper.empty()) {
  402. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  403. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  404. }
  405. if (!type.empty()) {
  406. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  407. props.push_back(type + "_OUTPUT_NAME");
  408. }
  409. if (!configUpper.empty()) {
  410. // OUTPUT_NAME_<CONFIG>
  411. props.push_back("OUTPUT_NAME_" + configUpper);
  412. // <CONFIG>_OUTPUT_NAME
  413. props.push_back(configUpper + "_OUTPUT_NAME");
  414. }
  415. // OUTPUT_NAME
  416. props.emplace_back("OUTPUT_NAME");
  417. std::string outName;
  418. for (std::string const& p : props) {
  419. if (cmValue outNameProp = this->GetProperty(p)) {
  420. outName = *outNameProp;
  421. break;
  422. }
  423. }
  424. if (outName.empty()) {
  425. outName = this->GetName();
  426. }
  427. // Now evaluate genex and update the previously-prepared map entry.
  428. i->second =
  429. cmGeneratorExpression::Evaluate(outName, this->LocalGenerator, config);
  430. } else if (i->second.empty()) {
  431. // An empty map entry indicates we have been called recursively
  432. // from the above block.
  433. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  434. MessageType::FATAL_ERROR,
  435. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  436. this->GetBacktrace());
  437. }
  438. return i->second;
  439. }
  440. std::string cmGeneratorTarget::GetFilePrefix(
  441. const std::string& config, cmStateEnums::ArtifactType artifact) const
  442. {
  443. if (this->IsImported()) {
  444. cmValue prefix = this->GetFilePrefixInternal(config, artifact);
  445. return prefix ? *prefix : std::string();
  446. }
  447. std::string prefix;
  448. std::string suffix;
  449. std::string base;
  450. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  451. return prefix;
  452. }
  453. std::string cmGeneratorTarget::GetFileSuffix(
  454. const std::string& config, cmStateEnums::ArtifactType artifact) const
  455. {
  456. if (this->IsImported()) {
  457. cmValue suffix = this->GetFileSuffixInternal(config, artifact);
  458. return suffix ? *suffix : std::string();
  459. }
  460. std::string prefix;
  461. std::string suffix;
  462. std::string base;
  463. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  464. return suffix;
  465. }
  466. std::string cmGeneratorTarget::GetFilePostfix(const std::string& config) const
  467. {
  468. cmValue postfix = nullptr;
  469. std::string frameworkPostfix;
  470. if (!config.empty()) {
  471. std::string configProp =
  472. cmStrCat(cmSystemTools::UpperCase(config), "_POSTFIX");
  473. postfix = this->GetProperty(configProp);
  474. // Mac application bundles and frameworks have no regular postfix like
  475. // libraries do.
  476. if (!this->IsImported() && postfix &&
  477. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple())) {
  478. postfix = nullptr;
  479. }
  480. // Frameworks created by multi config generators can have a special
  481. // framework postfix.
  482. frameworkPostfix = this->GetFrameworkMultiConfigPostfix(config);
  483. if (!frameworkPostfix.empty()) {
  484. postfix = cmValue(frameworkPostfix);
  485. }
  486. }
  487. return postfix ? *postfix : std::string();
  488. }
  489. std::string cmGeneratorTarget::GetFrameworkMultiConfigPostfix(
  490. const std::string& config) const
  491. {
  492. cmValue postfix = nullptr;
  493. if (!config.empty()) {
  494. std::string configProp = cmStrCat("FRAMEWORK_MULTI_CONFIG_POSTFIX_",
  495. cmSystemTools::UpperCase(config));
  496. postfix = this->GetProperty(configProp);
  497. if (!this->IsImported() && postfix &&
  498. (this->IsFrameworkOnApple() &&
  499. !this->GetGlobalGenerator()->IsMultiConfig())) {
  500. postfix = nullptr;
  501. }
  502. }
  503. return postfix ? *postfix : std::string();
  504. }
  505. cmValue cmGeneratorTarget::GetFilePrefixInternal(
  506. std::string const& config, cmStateEnums::ArtifactType artifact,
  507. const std::string& language) const
  508. {
  509. // no prefix for non-main target types.
  510. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  511. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  512. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  513. this->GetType() != cmStateEnums::EXECUTABLE) {
  514. return nullptr;
  515. }
  516. const bool isImportedLibraryArtifact =
  517. (artifact == cmStateEnums::ImportLibraryArtifact);
  518. // Return an empty prefix for the import library if this platform
  519. // does not support import libraries.
  520. if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
  521. return nullptr;
  522. }
  523. // The implib option is only allowed for shared libraries, module
  524. // libraries, and executables.
  525. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  526. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  527. this->GetType() != cmStateEnums::EXECUTABLE) {
  528. artifact = cmStateEnums::RuntimeBinaryArtifact;
  529. }
  530. // Compute prefix value.
  531. cmValue targetPrefix =
  532. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_PREFIX")
  533. : this->GetProperty("PREFIX"));
  534. if (!targetPrefix) {
  535. const char* prefixVar = this->Target->GetPrefixVariableInternal(artifact);
  536. if (!language.empty() && cmNonempty(prefixVar)) {
  537. std::string langPrefix = cmStrCat(prefixVar, "_", language);
  538. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  539. }
  540. // if there is no prefix on the target nor specific language
  541. // use the cmake definition.
  542. if (!targetPrefix && prefixVar) {
  543. targetPrefix = this->Makefile->GetDefinition(prefixVar);
  544. }
  545. }
  546. return targetPrefix;
  547. }
  548. cmValue cmGeneratorTarget::GetFileSuffixInternal(
  549. std::string const& config, cmStateEnums::ArtifactType artifact,
  550. const std::string& language) const
  551. {
  552. // no suffix for non-main target types.
  553. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  554. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  555. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  556. this->GetType() != cmStateEnums::EXECUTABLE) {
  557. return nullptr;
  558. }
  559. const bool isImportedLibraryArtifact =
  560. (artifact == cmStateEnums::ImportLibraryArtifact);
  561. // Return an empty suffix for the import library if this platform
  562. // does not support import libraries.
  563. if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
  564. return nullptr;
  565. }
  566. // The implib option is only allowed for shared libraries, module
  567. // libraries, and executables.
  568. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  569. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  570. this->GetType() != cmStateEnums::EXECUTABLE) {
  571. artifact = cmStateEnums::RuntimeBinaryArtifact;
  572. }
  573. // Compute suffix value.
  574. cmValue targetSuffix =
  575. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_SUFFIX")
  576. : this->GetProperty("SUFFIX"));
  577. if (!targetSuffix) {
  578. const char* suffixVar = this->Target->GetSuffixVariableInternal(artifact);
  579. if (!language.empty() && cmNonempty(suffixVar)) {
  580. std::string langSuffix = cmStrCat(suffixVar, "_", language);
  581. targetSuffix = this->Makefile->GetDefinition(langSuffix);
  582. }
  583. // if there is no suffix on the target nor specific language
  584. // use the cmake definition.
  585. if (!targetSuffix && suffixVar) {
  586. targetSuffix = this->Makefile->GetDefinition(suffixVar);
  587. }
  588. }
  589. return targetSuffix;
  590. }
  591. void cmGeneratorTarget::ClearSourcesCache()
  592. {
  593. this->AllConfigSources.clear();
  594. this->KindedSourcesMap.clear();
  595. this->SourcesAreContextDependent = Tribool::Indeterminate;
  596. this->Objects.clear();
  597. this->VisitedConfigsForObjects.clear();
  598. this->LinkImplMap.clear();
  599. }
  600. void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before)
  601. {
  602. this->SourceEntries.insert(
  603. before ? this->SourceEntries.begin() : this->SourceEntries.end(),
  604. CreateTargetPropertyEntry(
  605. BT<std::string>(src, this->Makefile->GetBacktrace()), true));
  606. this->ClearSourcesCache();
  607. }
  608. void cmGeneratorTarget::AddSource(const std::string& src, bool before)
  609. {
  610. this->Target->AddSource(src, before);
  611. this->AddSourceCommon(src, before);
  612. }
  613. void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
  614. {
  615. this->Target->AddTracedSources(srcs);
  616. if (!srcs.empty()) {
  617. this->AddSourceCommon(cmJoin(srcs, ";"));
  618. }
  619. }
  620. void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
  621. bool before)
  622. {
  623. this->Target->InsertInclude(
  624. BT<std::string>(src, this->Makefile->GetBacktrace()), before);
  625. this->IncludeDirectoriesEntries.insert(
  626. before ? this->IncludeDirectoriesEntries.begin()
  627. : this->IncludeDirectoriesEntries.end(),
  628. CreateTargetPropertyEntry(
  629. BT<std::string>(src, this->Makefile->GetBacktrace()), true));
  630. }
  631. std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
  632. cmSourceFile const* sf) const
  633. {
  634. auto i = this->SourceDepends.find(sf);
  635. if (i != this->SourceDepends.end()) {
  636. return &i->second.Depends;
  637. }
  638. return nullptr;
  639. }
  640. namespace {
  641. void handleSystemIncludesDep(cmLocalGenerator* lg,
  642. cmGeneratorTarget const* depTgt,
  643. const std::string& config,
  644. cmGeneratorTarget const* headTarget,
  645. cmGeneratorExpressionDAGChecker* dagChecker,
  646. std::vector<std::string>& result,
  647. bool excludeImported, std::string const& language)
  648. {
  649. if (cmValue dirs =
  650. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
  651. cmExpandList(cmGeneratorExpression::Evaluate(*dirs, lg, config, headTarget,
  652. dagChecker, depTgt, language),
  653. result);
  654. }
  655. if (!depTgt->IsImported() || excludeImported) {
  656. return;
  657. }
  658. if (cmValue dirs = depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES")) {
  659. cmExpandList(cmGeneratorExpression::Evaluate(*dirs, lg, config, headTarget,
  660. dagChecker, depTgt, language),
  661. result);
  662. }
  663. }
  664. }
  665. /* clang-format off */
  666. #define IMPLEMENT_VISIT(KIND) \
  667. do { \
  668. KindedSources const& kinded = this->GetKindedSources(config); \
  669. for (SourceAndKind const& s : kinded.Sources) { \
  670. if (s.Kind == KIND) { \
  671. data.push_back(s.Source.Value); \
  672. } \
  673. } \
  674. } while (false)
  675. /* clang-format on */
  676. void cmGeneratorTarget::GetObjectSources(
  677. std::vector<cmSourceFile const*>& data, const std::string& config) const
  678. {
  679. IMPLEMENT_VISIT(SourceKindObjectSource);
  680. if (this->VisitedConfigsForObjects.count(config)) {
  681. return;
  682. }
  683. for (cmSourceFile const* it : data) {
  684. this->Objects[it];
  685. }
  686. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  687. this->VisitedConfigsForObjects.insert(config);
  688. }
  689. void cmGeneratorTarget::ComputeObjectMapping()
  690. {
  691. auto const& configs =
  692. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  693. std::set<std::string> configSet(configs.begin(), configs.end());
  694. if (configSet == this->VisitedConfigsForObjects) {
  695. return;
  696. }
  697. for (std::string const& c : configs) {
  698. std::vector<cmSourceFile const*> sourceFiles;
  699. this->GetObjectSources(sourceFiles, c);
  700. }
  701. }
  702. cmValue cmGeneratorTarget::GetFeature(const std::string& feature,
  703. const std::string& config) const
  704. {
  705. if (!config.empty()) {
  706. std::string featureConfig =
  707. cmStrCat(feature, '_', cmSystemTools::UpperCase(config));
  708. if (cmValue value = this->GetProperty(featureConfig)) {
  709. return value;
  710. }
  711. }
  712. if (cmValue value = this->GetProperty(feature)) {
  713. return value;
  714. }
  715. return this->LocalGenerator->GetFeature(feature, config);
  716. }
  717. const char* cmGeneratorTarget::GetLinkPIEProperty(
  718. const std::string& config) const
  719. {
  720. static std::string PICValue;
  721. PICValue = this->GetLinkInterfaceDependentStringAsBoolProperty(
  722. "POSITION_INDEPENDENT_CODE", config);
  723. if (PICValue == "(unset)") {
  724. // POSITION_INDEPENDENT_CODE is not set
  725. return nullptr;
  726. }
  727. auto status = this->GetPolicyStatusCMP0083();
  728. return (status != cmPolicies::WARN && status != cmPolicies::OLD)
  729. ? PICValue.c_str()
  730. : nullptr;
  731. }
  732. bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang,
  733. std::string const& config) const
  734. {
  735. cmValue feature = this->GetFeature("INTERPROCEDURAL_OPTIMIZATION", config);
  736. if (!cmIsOn(feature)) {
  737. // 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies
  738. return false;
  739. }
  740. if (lang != "C" && lang != "CXX" && lang != "Fortran") {
  741. // We do not define IPO behavior for other languages.
  742. return false;
  743. }
  744. cmPolicies::PolicyStatus cmp0069 = this->GetPolicyStatusCMP0069();
  745. if (cmp0069 == cmPolicies::OLD || cmp0069 == cmPolicies::WARN) {
  746. if (this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_LEGACY_BEHAVIOR")) {
  747. return true;
  748. }
  749. if (this->PolicyReportedCMP0069) {
  750. // problem is already reported, no need to issue a message
  751. return false;
  752. }
  753. const bool in_try_compile =
  754. this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile();
  755. if (cmp0069 == cmPolicies::WARN && !in_try_compile) {
  756. std::ostringstream w;
  757. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0069) << "\n";
  758. w << "INTERPROCEDURAL_OPTIMIZATION property will be ignored for target "
  759. << "'" << this->GetName() << "'.";
  760. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  761. MessageType::AUTHOR_WARNING, w.str(), this->GetBacktrace());
  762. this->PolicyReportedCMP0069 = true;
  763. }
  764. return false;
  765. }
  766. // Note: check consistency with messages from CheckIPOSupported
  767. const char* message = nullptr;
  768. if (!this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_SUPPORTED_BY_CMAKE")) {
  769. message = "CMake doesn't support IPO for current compiler";
  770. } else if (!this->Makefile->IsOn("_CMAKE_" + lang +
  771. "_IPO_MAY_BE_SUPPORTED_BY_COMPILER")) {
  772. message = "Compiler doesn't support IPO";
  773. } else if (!this->GlobalGenerator->IsIPOSupported()) {
  774. message = "CMake doesn't support IPO for current generator";
  775. }
  776. if (!message) {
  777. // No error/warning messages
  778. return true;
  779. }
  780. if (this->PolicyReportedCMP0069) {
  781. // problem is already reported, no need to issue a message
  782. return false;
  783. }
  784. this->PolicyReportedCMP0069 = true;
  785. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  786. MessageType::FATAL_ERROR, message, this->GetBacktrace());
  787. return false;
  788. }
  789. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  790. {
  791. this->ComputeObjectMapping();
  792. return this->Objects[file];
  793. }
  794. const char* cmGeneratorTarget::GetCustomObjectExtension() const
  795. {
  796. static std::string extension;
  797. const bool has_ptx_extension =
  798. this->GetPropertyAsBool("CUDA_PTX_COMPILATION");
  799. if (has_ptx_extension) {
  800. extension = ".ptx";
  801. return extension.c_str();
  802. }
  803. return nullptr;
  804. }
  805. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  806. {
  807. this->ExplicitObjectName.insert(sf);
  808. }
  809. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  810. {
  811. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  812. auto it = this->ExplicitObjectName.find(file);
  813. return it != this->ExplicitObjectName.end();
  814. }
  815. BTs<std::string> const* cmGeneratorTarget::GetLanguageStandardProperty(
  816. std::string const& lang, std::string const& config) const
  817. {
  818. std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang);
  819. auto langStandardIter = this->LanguageStandardMap.find(key);
  820. if (langStandardIter != this->LanguageStandardMap.end()) {
  821. return &langStandardIter->second;
  822. }
  823. return this->Target->GetLanguageStandardProperty(
  824. cmStrCat(lang, "_STANDARD"));
  825. }
  826. cmValue cmGeneratorTarget::GetLanguageStandard(std::string const& lang,
  827. std::string const& config) const
  828. {
  829. BTs<std::string> const* languageStandard =
  830. this->GetLanguageStandardProperty(lang, config);
  831. if (languageStandard) {
  832. return cmValue(languageStandard->Value);
  833. }
  834. return nullptr;
  835. }
  836. cmValue cmGeneratorTarget::GetPropertyWithPairedLanguageSupport(
  837. std::string const& lang, const char* suffix) const
  838. {
  839. cmValue propertyValue = this->Target->GetProperty(cmStrCat(lang, suffix));
  840. if (!propertyValue) {
  841. // Check if we should use the value set by another language.
  842. if (lang == "OBJC") {
  843. propertyValue = this->GetPropertyWithPairedLanguageSupport("C", suffix);
  844. } else if (lang == "OBJCXX" || lang == "CUDA" || lang == "HIP") {
  845. propertyValue =
  846. this->GetPropertyWithPairedLanguageSupport("CXX", suffix);
  847. }
  848. }
  849. return propertyValue;
  850. }
  851. cmValue cmGeneratorTarget::GetLanguageExtensions(std::string const& lang) const
  852. {
  853. return this->GetPropertyWithPairedLanguageSupport(lang, "_EXTENSIONS");
  854. }
  855. bool cmGeneratorTarget::GetLanguageStandardRequired(
  856. std::string const& lang) const
  857. {
  858. return cmIsOn(
  859. this->GetPropertyWithPairedLanguageSupport(lang, "_STANDARD_REQUIRED"));
  860. }
  861. void cmGeneratorTarget::GetModuleDefinitionSources(
  862. std::vector<cmSourceFile const*>& data, const std::string& config) const
  863. {
  864. IMPLEMENT_VISIT(SourceKindModuleDefinition);
  865. }
  866. void cmGeneratorTarget::GetHeaderSources(
  867. std::vector<cmSourceFile const*>& data, const std::string& config) const
  868. {
  869. IMPLEMENT_VISIT(SourceKindHeader);
  870. }
  871. void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile const*>& data,
  872. const std::string& config) const
  873. {
  874. IMPLEMENT_VISIT(SourceKindExtra);
  875. }
  876. void cmGeneratorTarget::GetCustomCommands(
  877. std::vector<cmSourceFile const*>& data, const std::string& config) const
  878. {
  879. IMPLEMENT_VISIT(SourceKindCustomCommand);
  880. }
  881. void cmGeneratorTarget::GetExternalObjects(
  882. std::vector<cmSourceFile const*>& data, const std::string& config) const
  883. {
  884. IMPLEMENT_VISIT(SourceKindExternalObject);
  885. }
  886. void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data,
  887. const std::string& config) const
  888. {
  889. IMPLEMENT_VISIT(SourceKindManifest);
  890. }
  891. std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
  892. {
  893. if (!this->UtilityItemsDone) {
  894. this->UtilityItemsDone = true;
  895. std::set<BT<std::pair<std::string, bool>>> const& utilities =
  896. this->GetUtilities();
  897. for (BT<std::pair<std::string, bool>> const& i : utilities) {
  898. if (cmGeneratorTarget* gt =
  899. this->LocalGenerator->FindGeneratorTargetToUse(i.Value.first)) {
  900. this->UtilityItems.insert(cmLinkItem(gt, i.Value.second, i.Backtrace));
  901. } else {
  902. this->UtilityItems.insert(
  903. cmLinkItem(i.Value.first, i.Value.second, i.Backtrace));
  904. }
  905. }
  906. }
  907. return this->UtilityItems;
  908. }
  909. const std::string& cmGeneratorTarget::GetLocation(
  910. const std::string& config) const
  911. {
  912. static std::string location;
  913. if (this->IsImported()) {
  914. location = this->Target->ImportedGetFullPath(
  915. config, cmStateEnums::RuntimeBinaryArtifact);
  916. } else {
  917. location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  918. }
  919. return location;
  920. }
  921. cm::optional<std::string> cmGeneratorTarget::MaybeGetLocation(
  922. std::string const& config) const
  923. {
  924. cm::optional<std::string> location;
  925. if (cmGeneratorTarget::ImportInfo const* imp = this->GetImportInfo(config)) {
  926. if (!imp->Location.empty()) {
  927. location = imp->Location;
  928. }
  929. } else {
  930. location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  931. }
  932. return location;
  933. }
  934. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreBuildCommands()
  935. const
  936. {
  937. return this->Target->GetPreBuildCommands();
  938. }
  939. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreLinkCommands()
  940. const
  941. {
  942. return this->Target->GetPreLinkCommands();
  943. }
  944. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPostBuildCommands()
  945. const
  946. {
  947. return this->Target->GetPostBuildCommands();
  948. }
  949. void cmGeneratorTarget::AppendCustomCommandSideEffects(
  950. std::set<cmGeneratorTarget const*>& sideEffects) const
  951. {
  952. if (!this->GetPreBuildCommands().empty() ||
  953. !this->GetPreLinkCommands().empty() ||
  954. !this->GetPostBuildCommands().empty()) {
  955. sideEffects.insert(this);
  956. } else {
  957. for (auto const& source : this->GetAllConfigSources()) {
  958. if (source.Source->GetCustomCommand() != nullptr) {
  959. sideEffects.insert(this);
  960. break;
  961. }
  962. }
  963. }
  964. }
  965. void cmGeneratorTarget::AppendLanguageSideEffects(
  966. std::map<std::string, std::set<cmGeneratorTarget const*>>& sideEffects) const
  967. {
  968. static const std::set<cm::string_view> LANGS_WITH_NO_SIDE_EFFECTS = {
  969. "C"_s, "CXX"_s, "OBJC"_s, "OBJCXX"_s, "ASM"_s, "CUDA"_s, "HIP"_s
  970. };
  971. for (auto const& lang : this->GetAllConfigCompileLanguages()) {
  972. if (!LANGS_WITH_NO_SIDE_EFFECTS.count(lang)) {
  973. sideEffects[lang].insert(this);
  974. }
  975. }
  976. }
  977. bool cmGeneratorTarget::IsInBuildSystem() const
  978. {
  979. if (this->IsImported()) {
  980. return false;
  981. }
  982. switch (this->Target->GetType()) {
  983. case cmStateEnums::EXECUTABLE:
  984. case cmStateEnums::STATIC_LIBRARY:
  985. case cmStateEnums::SHARED_LIBRARY:
  986. case cmStateEnums::MODULE_LIBRARY:
  987. case cmStateEnums::OBJECT_LIBRARY:
  988. case cmStateEnums::UTILITY:
  989. case cmStateEnums::GLOBAL_TARGET:
  990. return true;
  991. case cmStateEnums::INTERFACE_LIBRARY:
  992. // An INTERFACE library is in the build system if it has SOURCES.
  993. if (!this->SourceEntries.empty()) {
  994. return true;
  995. }
  996. case cmStateEnums::UNKNOWN_LIBRARY:
  997. break;
  998. }
  999. return false;
  1000. }
  1001. bool cmGeneratorTarget::IsImported() const
  1002. {
  1003. return this->Target->IsImported();
  1004. }
  1005. bool cmGeneratorTarget::IsImportedGloballyVisible() const
  1006. {
  1007. return this->Target->IsImportedGloballyVisible();
  1008. }
  1009. bool cmGeneratorTarget::CanCompileSources() const
  1010. {
  1011. return this->Target->CanCompileSources();
  1012. }
  1013. const std::string& cmGeneratorTarget::GetLocationForBuild() const
  1014. {
  1015. static std::string location;
  1016. if (this->IsImported()) {
  1017. location = this->Target->ImportedGetFullPath(
  1018. "", cmStateEnums::RuntimeBinaryArtifact);
  1019. return location;
  1020. }
  1021. // Now handle the deprecated build-time configuration location.
  1022. std::string const noConfig;
  1023. location = this->GetDirectory(noConfig);
  1024. cmValue cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  1025. if (cfgid && (*cfgid != ".")) {
  1026. location += "/";
  1027. location += *cfgid;
  1028. }
  1029. if (this->IsAppBundleOnApple()) {
  1030. std::string macdir = this->BuildBundleDirectory("", "", FullLevel);
  1031. if (!macdir.empty()) {
  1032. location += "/";
  1033. location += macdir;
  1034. }
  1035. }
  1036. location += "/";
  1037. location += this->GetFullName("", cmStateEnums::RuntimeBinaryArtifact);
  1038. return location;
  1039. }
  1040. bool cmGeneratorTarget::IsSystemIncludeDirectory(
  1041. const std::string& dir, const std::string& config,
  1042. const std::string& language) const
  1043. {
  1044. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  1045. std::string config_upper;
  1046. if (!config.empty()) {
  1047. config_upper = cmSystemTools::UpperCase(config);
  1048. }
  1049. std::string key = cmStrCat(config_upper, "/", language);
  1050. auto iter = this->SystemIncludesCache.find(key);
  1051. if (iter == this->SystemIncludesCache.end()) {
  1052. cmGeneratorExpressionDAGChecker dagChecker(
  1053. this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr);
  1054. bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  1055. std::vector<std::string> result;
  1056. for (std::string const& it : this->Target->GetSystemIncludeDirectories()) {
  1057. cmExpandList(cmGeneratorExpression::Evaluate(it, this->LocalGenerator,
  1058. config, this, &dagChecker,
  1059. nullptr, language),
  1060. result);
  1061. }
  1062. std::vector<cmGeneratorTarget const*> const& deps =
  1063. this->GetLinkImplementationClosure(config);
  1064. for (cmGeneratorTarget const* dep : deps) {
  1065. handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
  1066. &dagChecker, result, excludeImported, language);
  1067. }
  1068. cmLinkImplementation const* impl = this->GetLinkImplementation(config);
  1069. if (impl != nullptr) {
  1070. auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language);
  1071. if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) {
  1072. for (auto const& lib : runtimeEntries->second) {
  1073. if (lib.Target) {
  1074. handleSystemIncludesDep(this->LocalGenerator, lib.Target, config,
  1075. this, &dagChecker, result, excludeImported,
  1076. language);
  1077. }
  1078. }
  1079. }
  1080. }
  1081. std::for_each(result.begin(), result.end(),
  1082. cmSystemTools::ConvertToUnixSlashes);
  1083. std::sort(result.begin(), result.end());
  1084. result.erase(std::unique(result.begin(), result.end()), result.end());
  1085. iter = this->SystemIncludesCache.emplace(key, result).first;
  1086. }
  1087. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  1088. }
  1089. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  1090. {
  1091. return this->Target->GetPropertyAsBool(prop);
  1092. }
  1093. bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
  1094. std::string const& prop, cmGeneratorExpressionContext* context,
  1095. bool usage_requirements_only) const
  1096. {
  1097. std::string const key = prop + '@' + context->Config;
  1098. auto i = this->MaybeInterfacePropertyExists.find(key);
  1099. if (i == this->MaybeInterfacePropertyExists.end()) {
  1100. // Insert an entry now in case there is a cycle.
  1101. i = this->MaybeInterfacePropertyExists.emplace(key, false).first;
  1102. bool& maybeInterfaceProp = i->second;
  1103. // If this target itself has a non-empty property value, we are done.
  1104. maybeInterfaceProp = cmNonempty(this->GetProperty(prop));
  1105. // Otherwise, recurse to interface dependencies.
  1106. if (!maybeInterfaceProp) {
  1107. cmGeneratorTarget const* headTarget =
  1108. context->HeadTarget ? context->HeadTarget : this;
  1109. if (cmLinkInterfaceLibraries const* iface =
  1110. this->GetLinkInterfaceLibraries(context->Config, headTarget,
  1111. usage_requirements_only)) {
  1112. if (iface->HadHeadSensitiveCondition) {
  1113. // With a different head target we may get to a library with
  1114. // this interface property.
  1115. maybeInterfaceProp = true;
  1116. } else {
  1117. // The transitive interface libraries do not depend on the
  1118. // head target, so we can follow them.
  1119. for (cmLinkItem const& lib : iface->Libraries) {
  1120. if (lib.Target &&
  1121. lib.Target->MaybeHaveInterfaceProperty(
  1122. prop, context, usage_requirements_only)) {
  1123. maybeInterfaceProp = true;
  1124. break;
  1125. }
  1126. }
  1127. }
  1128. }
  1129. }
  1130. }
  1131. return i->second;
  1132. }
  1133. std::string cmGeneratorTarget::EvaluateInterfaceProperty(
  1134. std::string const& prop, cmGeneratorExpressionContext* context,
  1135. cmGeneratorExpressionDAGChecker* dagCheckerParent,
  1136. bool usage_requirements_only) const
  1137. {
  1138. std::string result;
  1139. // If the property does not appear transitively at all, we are done.
  1140. if (!this->MaybeHaveInterfaceProperty(prop, context,
  1141. usage_requirements_only)) {
  1142. return result;
  1143. }
  1144. // Evaluate $<TARGET_PROPERTY:this,prop> as if it were compiled. This is
  1145. // a subset of TargetPropertyNode::Evaluate without stringify/parse steps
  1146. // but sufficient for transitive interface properties.
  1147. cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace, this, prop,
  1148. nullptr, dagCheckerParent);
  1149. switch (dagChecker.Check()) {
  1150. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  1151. dagChecker.ReportError(
  1152. context, "$<TARGET_PROPERTY:" + this->GetName() + "," + prop + ">");
  1153. return result;
  1154. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  1155. // No error. We just skip cyclic references.
  1156. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  1157. // No error. We have already seen this transitive property.
  1158. return result;
  1159. case cmGeneratorExpressionDAGChecker::DAG:
  1160. break;
  1161. }
  1162. cmGeneratorTarget const* headTarget =
  1163. context->HeadTarget ? context->HeadTarget : this;
  1164. if (cmValue p = this->GetProperty(prop)) {
  1165. result = cmGeneratorExpressionNode::EvaluateDependentExpression(
  1166. *p, context->LG, context, headTarget, &dagChecker, this);
  1167. }
  1168. if (cmLinkInterfaceLibraries const* iface = this->GetLinkInterfaceLibraries(
  1169. context->Config, headTarget, usage_requirements_only)) {
  1170. context->HadContextSensitiveCondition =
  1171. context->HadContextSensitiveCondition ||
  1172. iface->HadContextSensitiveCondition;
  1173. for (cmLinkItem const& lib : iface->Libraries) {
  1174. // Broken code can have a target in its own link interface.
  1175. // Don't follow such link interface entries so as not to create a
  1176. // self-referencing loop.
  1177. if (lib.Target && lib.Target != this) {
  1178. // Pretend $<TARGET_PROPERTY:lib.Target,prop> appeared in the
  1179. // above property and hand-evaluate it as if it were compiled.
  1180. // Create a context as cmCompiledGeneratorExpression::Evaluate does.
  1181. cmGeneratorExpressionContext libContext(
  1182. context->LG, context->Config, context->Quiet, headTarget, this,
  1183. context->EvaluateForBuildsystem, context->Backtrace,
  1184. context->Language);
  1185. std::string libResult = cmGeneratorExpression::StripEmptyListElements(
  1186. lib.Target->EvaluateInterfaceProperty(prop, &libContext, &dagChecker,
  1187. usage_requirements_only));
  1188. if (!libResult.empty()) {
  1189. if (result.empty()) {
  1190. result = std::move(libResult);
  1191. } else {
  1192. result.reserve(result.size() + 1 + libResult.size());
  1193. result += ";";
  1194. result += libResult;
  1195. }
  1196. }
  1197. context->HadContextSensitiveCondition =
  1198. context->HadContextSensitiveCondition ||
  1199. libContext.HadContextSensitiveCondition;
  1200. context->HadHeadSensitiveCondition =
  1201. context->HadHeadSensitiveCondition ||
  1202. libContext.HadHeadSensitiveCondition;
  1203. }
  1204. }
  1205. }
  1206. return result;
  1207. }
  1208. namespace {
  1209. enum class IncludeDirectoryFallBack
  1210. {
  1211. BINARY,
  1212. OBJECT
  1213. };
  1214. std::string AddLangSpecificInterfaceIncludeDirectories(
  1215. const cmGeneratorTarget* root, const cmGeneratorTarget* target,
  1216. const std::string& lang, const std::string& config,
  1217. const std::string& propertyName, IncludeDirectoryFallBack mode,
  1218. cmGeneratorExpressionDAGChecker* context)
  1219. {
  1220. cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
  1221. propertyName, nullptr, context };
  1222. switch (dag.Check()) {
  1223. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  1224. dag.ReportError(
  1225. nullptr, "$<TARGET_PROPERTY:" + target->GetName() + ",propertyName");
  1226. CM_FALLTHROUGH;
  1227. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  1228. // No error. We just skip cyclic references.
  1229. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  1230. // No error. We have already seen this transitive property.
  1231. return "";
  1232. case cmGeneratorExpressionDAGChecker::DAG:
  1233. break;
  1234. }
  1235. std::string directories;
  1236. if (const auto* interface =
  1237. target->GetLinkInterfaceLibraries(config, root, true)) {
  1238. for (const cmLinkItem& library : interface->Libraries) {
  1239. if (const cmGeneratorTarget* dependency = library.Target) {
  1240. if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
  1241. auto* lg = dependency->GetLocalGenerator();
  1242. std::string value = dependency->GetSafeProperty(propertyName);
  1243. if (value.empty()) {
  1244. if (mode == IncludeDirectoryFallBack::BINARY) {
  1245. value = lg->GetCurrentBinaryDirectory();
  1246. } else if (mode == IncludeDirectoryFallBack::OBJECT) {
  1247. value = cmStrCat(lg->GetCurrentBinaryDirectory(), '/',
  1248. lg->GetTargetDirectory(dependency));
  1249. }
  1250. }
  1251. if (!directories.empty()) {
  1252. directories += ";";
  1253. }
  1254. directories += value;
  1255. }
  1256. }
  1257. }
  1258. }
  1259. return directories;
  1260. }
  1261. void AddLangSpecificImplicitIncludeDirectories(
  1262. const cmGeneratorTarget* target, const std::string& lang,
  1263. const std::string& config, const std::string& propertyName,
  1264. IncludeDirectoryFallBack mode, EvaluatedTargetPropertyEntries& entries)
  1265. {
  1266. if (const auto* libraries = target->GetLinkImplementationLibraries(config)) {
  1267. cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
  1268. propertyName, nullptr, nullptr };
  1269. for (const cmLinkImplItem& library : libraries->Libraries) {
  1270. if (const cmGeneratorTarget* dependency = library.Target) {
  1271. if (!dependency->IsInBuildSystem()) {
  1272. continue;
  1273. }
  1274. if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
  1275. auto* lg = dependency->GetLocalGenerator();
  1276. EvaluatedTargetPropertyEntry entry{ library, library.Backtrace };
  1277. if (cmValue val = dependency->GetProperty(propertyName)) {
  1278. entry.Values.emplace_back(*val);
  1279. } else {
  1280. if (mode == IncludeDirectoryFallBack::BINARY) {
  1281. entry.Values.emplace_back(lg->GetCurrentBinaryDirectory());
  1282. } else if (mode == IncludeDirectoryFallBack::OBJECT) {
  1283. entry.Values.emplace_back(
  1284. dependency->GetObjectDirectory(config));
  1285. }
  1286. }
  1287. cmExpandList(
  1288. AddLangSpecificInterfaceIncludeDirectories(
  1289. target, dependency, lang, config, propertyName, mode, &dag),
  1290. entry.Values);
  1291. entries.Entries.emplace_back(std::move(entry));
  1292. }
  1293. }
  1294. }
  1295. }
  1296. }
  1297. void addInterfaceEntry(cmGeneratorTarget const* headTarget,
  1298. std::string const& config, std::string const& prop,
  1299. std::string const& lang,
  1300. cmGeneratorExpressionDAGChecker* dagChecker,
  1301. EvaluatedTargetPropertyEntries& entries,
  1302. bool usage_requirements_only,
  1303. std::vector<cmLinkImplItem> const& libraries)
  1304. {
  1305. for (cmLinkImplItem const& lib : libraries) {
  1306. if (lib.Target) {
  1307. EvaluatedTargetPropertyEntry ee(lib, lib.Backtrace);
  1308. // Pretend $<TARGET_PROPERTY:lib.Target,prop> appeared in our
  1309. // caller's property and hand-evaluate it as if it were compiled.
  1310. // Create a context as cmCompiledGeneratorExpression::Evaluate does.
  1311. cmGeneratorExpressionContext context(
  1312. headTarget->GetLocalGenerator(), config, false, headTarget, headTarget,
  1313. true, lib.Backtrace, lang);
  1314. cmExpandList(lib.Target->EvaluateInterfaceProperty(
  1315. prop, &context, dagChecker, usage_requirements_only),
  1316. ee.Values);
  1317. ee.ContextDependent = context.HadContextSensitiveCondition;
  1318. entries.Entries.emplace_back(std::move(ee));
  1319. }
  1320. }
  1321. }
  1322. // IncludeRuntimeInterface is used to break the cycle in computing
  1323. // the necessary transitive dependencies of targets that can occur
  1324. // now that we have implicit language runtime targets.
  1325. //
  1326. // To determine the set of languages that a target has we need to iterate
  1327. // all the sources which includes transitive INTERFACE sources.
  1328. // Therefore we can't determine what language runtimes are needed
  1329. // for a target until after all sources are computed.
  1330. //
  1331. // Therefore while computing the applicable INTERFACE_SOURCES we
  1332. // must ignore anything in LanguageRuntimeLibraries or we would
  1333. // create a cycle ( INTERFACE_SOURCES requires LanguageRuntimeLibraries,
  1334. // LanguageRuntimeLibraries requires INTERFACE_SOURCES).
  1335. //
  1336. enum class IncludeRuntimeInterface
  1337. {
  1338. Yes,
  1339. No
  1340. };
  1341. void AddInterfaceEntries(cmGeneratorTarget const* headTarget,
  1342. std::string const& config, std::string const& prop,
  1343. std::string const& lang,
  1344. cmGeneratorExpressionDAGChecker* dagChecker,
  1345. EvaluatedTargetPropertyEntries& entries,
  1346. IncludeRuntimeInterface searchRuntime,
  1347. bool usage_requirements_only = true)
  1348. {
  1349. if (searchRuntime == IncludeRuntimeInterface::Yes) {
  1350. if (cmLinkImplementation const* impl =
  1351. headTarget->GetLinkImplementation(config)) {
  1352. entries.HadContextSensitiveCondition =
  1353. impl->HadContextSensitiveCondition;
  1354. auto runtimeLibIt = impl->LanguageRuntimeLibraries.find(lang);
  1355. if (runtimeLibIt != impl->LanguageRuntimeLibraries.end()) {
  1356. addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries,
  1357. usage_requirements_only, runtimeLibIt->second);
  1358. }
  1359. addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries,
  1360. usage_requirements_only, impl->Libraries);
  1361. }
  1362. } else {
  1363. if (cmLinkImplementationLibraries const* impl =
  1364. headTarget->GetLinkImplementationLibraries(config)) {
  1365. entries.HadContextSensitiveCondition =
  1366. impl->HadContextSensitiveCondition;
  1367. addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries,
  1368. usage_requirements_only, impl->Libraries);
  1369. }
  1370. }
  1371. }
  1372. void AddObjectEntries(cmGeneratorTarget const* headTarget,
  1373. std::string const& config,
  1374. cmGeneratorExpressionDAGChecker* dagChecker,
  1375. EvaluatedTargetPropertyEntries& entries)
  1376. {
  1377. if (cmLinkImplementationLibraries const* impl =
  1378. headTarget->GetLinkImplementationLibraries(config)) {
  1379. entries.HadContextSensitiveCondition = impl->HadContextSensitiveCondition;
  1380. for (cmLinkImplItem const& lib : impl->Libraries) {
  1381. if (lib.Target &&
  1382. lib.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1383. std::string uniqueName =
  1384. headTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
  1385. lib.Target);
  1386. std::string genex = "$<TARGET_OBJECTS:" + std::move(uniqueName) + ">";
  1387. cmGeneratorExpression ge(lib.Backtrace);
  1388. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  1389. cge->SetEvaluateForBuildsystem(true);
  1390. EvaluatedTargetPropertyEntry ee(lib, lib.Backtrace);
  1391. cmExpandList(cge->Evaluate(headTarget->GetLocalGenerator(), config,
  1392. headTarget, dagChecker),
  1393. ee.Values);
  1394. if (cge->GetHadContextSensitiveCondition()) {
  1395. ee.ContextDependent = true;
  1396. }
  1397. entries.Entries.emplace_back(std::move(ee));
  1398. }
  1399. }
  1400. }
  1401. }
  1402. bool processSources(cmGeneratorTarget const* tgt,
  1403. EvaluatedTargetPropertyEntries& entries,
  1404. std::vector<BT<std::string>>& srcs,
  1405. std::unordered_set<std::string>& uniqueSrcs,
  1406. bool debugSources)
  1407. {
  1408. cmMakefile* mf = tgt->Target->GetMakefile();
  1409. bool contextDependent = entries.HadContextSensitiveCondition;
  1410. for (EvaluatedTargetPropertyEntry& entry : entries.Entries) {
  1411. if (entry.ContextDependent) {
  1412. contextDependent = true;
  1413. }
  1414. cmLinkImplItem const& item = entry.LinkImplItem;
  1415. std::string const& targetName = item.AsStr();
  1416. for (std::string& src : entry.Values) {
  1417. cmSourceFile* sf = mf->GetOrCreateSource(src);
  1418. std::string e;
  1419. std::string w;
  1420. std::string fullPath = sf->ResolveFullPath(&e, &w);
  1421. cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
  1422. if (!w.empty()) {
  1423. cm->IssueMessage(MessageType::AUTHOR_WARNING, w, tgt->GetBacktrace());
  1424. }
  1425. if (fullPath.empty()) {
  1426. if (!e.empty()) {
  1427. cm->IssueMessage(MessageType::FATAL_ERROR, e, tgt->GetBacktrace());
  1428. }
  1429. return contextDependent;
  1430. }
  1431. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src)) {
  1432. std::ostringstream err;
  1433. if (!targetName.empty()) {
  1434. err << "Target \"" << targetName
  1435. << "\" contains relative path in its INTERFACE_SOURCES:\n \""
  1436. << src << "\"";
  1437. } else {
  1438. err << "Found relative path while evaluating sources of \""
  1439. << tgt->GetName() << "\":\n \"" << src << "\"\n";
  1440. }
  1441. tgt->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
  1442. err.str());
  1443. return contextDependent;
  1444. }
  1445. src = fullPath;
  1446. }
  1447. std::string usedSources;
  1448. for (std::string const& src : entry.Values) {
  1449. if (uniqueSrcs.insert(src).second) {
  1450. srcs.emplace_back(src, entry.Backtrace);
  1451. if (debugSources) {
  1452. usedSources += " * " + src + "\n";
  1453. }
  1454. }
  1455. }
  1456. if (!usedSources.empty()) {
  1457. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1458. MessageType::LOG,
  1459. std::string("Used sources for target ") + tgt->GetName() + ":\n" +
  1460. usedSources,
  1461. entry.Backtrace);
  1462. }
  1463. }
  1464. return contextDependent;
  1465. }
  1466. }
  1467. std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
  1468. std::string const& config) const
  1469. {
  1470. std::vector<BT<std::string>> files;
  1471. if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  1472. // At configure-time, this method can be called as part of getting the
  1473. // LOCATION property or to export() a file to be include()d. However
  1474. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  1475. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  1476. // behavior of CMP0024 and CMP0026 only.
  1477. cmBTStringRange sourceEntries = this->Target->GetSourceEntries();
  1478. for (auto const& entry : sourceEntries) {
  1479. std::vector<std::string> items = cmExpandedList(entry.Value);
  1480. for (std::string const& item : items) {
  1481. if (cmHasLiteralPrefix(item, "$<TARGET_OBJECTS:") &&
  1482. item.back() == '>') {
  1483. continue;
  1484. }
  1485. files.emplace_back(item);
  1486. }
  1487. }
  1488. return files;
  1489. }
  1490. std::vector<std::string> debugProperties;
  1491. this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
  1492. debugProperties);
  1493. bool debugSources =
  1494. !this->DebugSourcesDone && cm::contains(debugProperties, "SOURCES");
  1495. if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  1496. this->DebugSourcesDone = true;
  1497. }
  1498. cmGeneratorExpressionDAGChecker dagChecker(this, "SOURCES", nullptr,
  1499. nullptr);
  1500. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  1501. this, config, std::string(), &dagChecker, this->SourceEntries);
  1502. std::unordered_set<std::string> uniqueSrcs;
  1503. bool contextDependentDirectSources =
  1504. processSources(this, entries, files, uniqueSrcs, debugSources);
  1505. // Collect INTERFACE_SOURCES of all direct link-dependencies.
  1506. EvaluatedTargetPropertyEntries linkInterfaceSourcesEntries;
  1507. AddInterfaceEntries(this, config, "INTERFACE_SOURCES", std::string(),
  1508. &dagChecker, linkInterfaceSourcesEntries,
  1509. IncludeRuntimeInterface::No, true);
  1510. std::vector<std::string>::size_type numFilesBefore = files.size();
  1511. bool contextDependentInterfaceSources = processSources(
  1512. this, linkInterfaceSourcesEntries, files, uniqueSrcs, debugSources);
  1513. // Collect TARGET_OBJECTS of direct object link-dependencies.
  1514. bool contextDependentObjects = false;
  1515. std::vector<std::string>::size_type numFilesBefore2 = files.size();
  1516. if (this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  1517. EvaluatedTargetPropertyEntries linkObjectsEntries;
  1518. AddObjectEntries(this, config, &dagChecker, linkObjectsEntries);
  1519. contextDependentObjects = processSources(this, linkObjectsEntries, files,
  1520. uniqueSrcs, debugSources);
  1521. }
  1522. // Determine if sources are context-dependent or not.
  1523. if (!contextDependentDirectSources &&
  1524. !(contextDependentInterfaceSources && numFilesBefore < files.size()) &&
  1525. !(contextDependentObjects && numFilesBefore2 < files.size())) {
  1526. this->SourcesAreContextDependent = Tribool::False;
  1527. } else {
  1528. this->SourcesAreContextDependent = Tribool::True;
  1529. }
  1530. return files;
  1531. }
  1532. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*>& files,
  1533. const std::string& config) const
  1534. {
  1535. std::vector<BT<cmSourceFile*>> tmp = this->GetSourceFiles(config);
  1536. files.reserve(tmp.size());
  1537. for (BT<cmSourceFile*>& v : tmp) {
  1538. files.push_back(v.Value);
  1539. }
  1540. }
  1541. std::vector<BT<cmSourceFile*>> cmGeneratorTarget::GetSourceFiles(
  1542. std::string const& config) const
  1543. {
  1544. std::vector<BT<cmSourceFile*>> files;
  1545. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  1546. // Since we are still configuring not all sources may exist yet,
  1547. // so we need to avoid full source classification because that
  1548. // requires the absolute paths to all sources to be determined.
  1549. // Since this is only for compatibility with old policies that
  1550. // projects should not depend on anymore, just compute the files
  1551. // without memoizing them.
  1552. std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
  1553. std::set<cmSourceFile*> emitted;
  1554. for (BT<std::string> const& s : srcs) {
  1555. cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
  1556. if (emitted.insert(sf).second) {
  1557. files.emplace_back(sf, s.Backtrace);
  1558. }
  1559. }
  1560. return files;
  1561. }
  1562. KindedSources const& kinded = this->GetKindedSources(config);
  1563. files.reserve(kinded.Sources.size());
  1564. for (SourceAndKind const& si : kinded.Sources) {
  1565. files.push_back(si.Source);
  1566. }
  1567. return files;
  1568. }
  1569. void cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  1570. std::vector<cmSourceFile*>& files, const std::string& config) const
  1571. {
  1572. std::vector<BT<cmSourceFile*>> tmp =
  1573. this->GetSourceFilesWithoutObjectLibraries(config);
  1574. files.reserve(tmp.size());
  1575. for (BT<cmSourceFile*>& v : tmp) {
  1576. files.push_back(v.Value);
  1577. }
  1578. }
  1579. std::vector<BT<cmSourceFile*>>
  1580. cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  1581. std::string const& config) const
  1582. {
  1583. std::vector<BT<cmSourceFile*>> files;
  1584. KindedSources const& kinded = this->GetKindedSources(config);
  1585. files.reserve(kinded.Sources.size());
  1586. for (SourceAndKind const& si : kinded.Sources) {
  1587. if (si.Source.Value->GetObjectLibrary().empty()) {
  1588. files.push_back(si.Source);
  1589. }
  1590. }
  1591. return files;
  1592. }
  1593. cmGeneratorTarget::KindedSources const& cmGeneratorTarget::GetKindedSources(
  1594. std::string const& config) const
  1595. {
  1596. // If we already processed one configuration and found no dependency
  1597. // on configuration then always use the one result.
  1598. if (this->SourcesAreContextDependent == Tribool::False) {
  1599. return this->KindedSourcesMap.begin()->second;
  1600. }
  1601. // Lookup any existing link implementation for this configuration.
  1602. std::string const key = cmSystemTools::UpperCase(config);
  1603. auto it = this->KindedSourcesMap.find(key);
  1604. if (it != this->KindedSourcesMap.end()) {
  1605. if (!it->second.Initialized) {
  1606. std::ostringstream e;
  1607. e << "The SOURCES of \"" << this->GetName()
  1608. << "\" use a generator expression that depends on the "
  1609. "SOURCES themselves.";
  1610. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  1611. MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
  1612. static KindedSources empty;
  1613. return empty;
  1614. }
  1615. return it->second;
  1616. }
  1617. // Add an entry to the map for this configuration.
  1618. KindedSources& files = this->KindedSourcesMap[key];
  1619. this->ComputeKindedSources(files, config);
  1620. files.Initialized = true;
  1621. return files;
  1622. }
  1623. void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
  1624. std::string const& config) const
  1625. {
  1626. // Get the source file paths by string.
  1627. std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
  1628. cmsys::RegularExpression header_regex(CM_HEADER_REGEX);
  1629. std::vector<cmSourceFile*> badObjLib;
  1630. std::set<cmSourceFile*> emitted;
  1631. for (BT<std::string> const& s : srcs) {
  1632. // Create each source at most once.
  1633. cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
  1634. if (!emitted.insert(sf).second) {
  1635. continue;
  1636. }
  1637. // Compute the kind (classification) of this source file.
  1638. SourceKind kind;
  1639. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1640. if (sf->GetCustomCommand()) {
  1641. kind = SourceKindCustomCommand;
  1642. } else if (this->Target->GetType() == cmStateEnums::UTILITY ||
  1643. this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY
  1644. // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
  1645. // NOLINTNEXTLINE(bugprone-branch-clone)
  1646. ) {
  1647. kind = SourceKindExtra;
  1648. } else if (this->IsSourceFilePartOfUnityBatch(sf->ResolveFullPath())) {
  1649. kind = SourceKindUnityBatched;
  1650. // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
  1651. // NOLINTNEXTLINE(bugprone-branch-clone)
  1652. } else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) {
  1653. kind = SourceKindHeader;
  1654. } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  1655. kind = SourceKindExternalObject;
  1656. } else if (!sf->GetOrDetermineLanguage().empty()) {
  1657. kind = SourceKindObjectSource;
  1658. } else if (ext == "def") {
  1659. kind = SourceKindModuleDefinition;
  1660. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1661. badObjLib.push_back(sf);
  1662. }
  1663. } else if (ext == "idl") {
  1664. kind = SourceKindIDL;
  1665. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1666. badObjLib.push_back(sf);
  1667. }
  1668. } else if (ext == "resx") {
  1669. kind = SourceKindResx;
  1670. } else if (ext == "appxmanifest") {
  1671. kind = SourceKindAppManifest;
  1672. } else if (ext == "manifest") {
  1673. kind = SourceKindManifest;
  1674. } else if (ext == "pfx") {
  1675. kind = SourceKindCertificate;
  1676. } else if (ext == "xaml") {
  1677. kind = SourceKindXaml;
  1678. } else if (header_regex.find(sf->ResolveFullPath())) {
  1679. kind = SourceKindHeader;
  1680. } else {
  1681. kind = SourceKindExtra;
  1682. }
  1683. // Save this classified source file in the result vector.
  1684. files.Sources.push_back({ BT<cmSourceFile*>(sf, s.Backtrace), kind });
  1685. }
  1686. if (!badObjLib.empty()) {
  1687. std::ostringstream e;
  1688. e << "OBJECT library \"" << this->GetName() << "\" contains:\n";
  1689. for (cmSourceFile* i : badObjLib) {
  1690. e << " " << i->GetLocation().GetName() << "\n";
  1691. }
  1692. e << "but may contain only sources that compile, header files, and "
  1693. "other files that would not affect linking of a normal library.";
  1694. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  1695. MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
  1696. }
  1697. }
  1698. std::vector<cmGeneratorTarget::AllConfigSource> const&
  1699. cmGeneratorTarget::GetAllConfigSources() const
  1700. {
  1701. if (this->AllConfigSources.empty()) {
  1702. this->ComputeAllConfigSources();
  1703. }
  1704. return this->AllConfigSources;
  1705. }
  1706. void cmGeneratorTarget::ComputeAllConfigSources() const
  1707. {
  1708. std::vector<std::string> configs =
  1709. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  1710. std::map<cmSourceFile const*, size_t> index;
  1711. for (size_t ci = 0; ci < configs.size(); ++ci) {
  1712. KindedSources const& sources = this->GetKindedSources(configs[ci]);
  1713. for (SourceAndKind const& src : sources.Sources) {
  1714. auto mi = index.find(src.Source.Value);
  1715. if (mi == index.end()) {
  1716. AllConfigSource acs;
  1717. acs.Source = src.Source.Value;
  1718. acs.Kind = src.Kind;
  1719. this->AllConfigSources.push_back(std::move(acs));
  1720. std::map<cmSourceFile const*, size_t>::value_type entry(
  1721. src.Source.Value, this->AllConfigSources.size() - 1);
  1722. mi = index.insert(entry).first;
  1723. }
  1724. this->AllConfigSources[mi->second].Configs.push_back(ci);
  1725. }
  1726. }
  1727. }
  1728. std::vector<cmGeneratorTarget::AllConfigSource>
  1729. cmGeneratorTarget::GetAllConfigSources(SourceKind kind) const
  1730. {
  1731. std::vector<AllConfigSource> result;
  1732. for (AllConfigSource const& source : this->GetAllConfigSources()) {
  1733. if (source.Kind == kind) {
  1734. result.push_back(source);
  1735. }
  1736. }
  1737. return result;
  1738. }
  1739. std::set<std::string> cmGeneratorTarget::GetAllConfigCompileLanguages() const
  1740. {
  1741. std::set<std::string> languages;
  1742. std::vector<AllConfigSource> const& sources = this->GetAllConfigSources();
  1743. for (AllConfigSource const& si : sources) {
  1744. std::string const& lang = si.Source->GetOrDetermineLanguage();
  1745. if (!lang.empty()) {
  1746. languages.emplace(lang);
  1747. }
  1748. }
  1749. return languages;
  1750. }
  1751. std::string cmGeneratorTarget::GetCompilePDBName(
  1752. const std::string& config) const
  1753. {
  1754. std::string prefix;
  1755. std::string base;
  1756. std::string suffix;
  1757. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  1758. prefix, base, suffix);
  1759. // Check for a per-configuration output directory target property.
  1760. std::string configUpper = cmSystemTools::UpperCase(config);
  1761. std::string configProp = cmStrCat("COMPILE_PDB_NAME_", configUpper);
  1762. cmValue config_name = this->GetProperty(configProp);
  1763. if (cmNonempty(config_name)) {
  1764. return prefix + *config_name + ".pdb";
  1765. }
  1766. cmValue name = this->GetProperty("COMPILE_PDB_NAME");
  1767. if (cmNonempty(name)) {
  1768. return prefix + *name + ".pdb";
  1769. }
  1770. return "";
  1771. }
  1772. std::string cmGeneratorTarget::GetCompilePDBPath(
  1773. const std::string& config) const
  1774. {
  1775. std::string dir = this->GetCompilePDBDirectory(config);
  1776. std::string name = this->GetCompilePDBName(config);
  1777. if (dir.empty() && !name.empty() && this->HaveWellDefinedOutputFiles()) {
  1778. dir = this->GetPDBDirectory(config);
  1779. }
  1780. if (!dir.empty()) {
  1781. dir += "/";
  1782. }
  1783. return dir + name;
  1784. }
  1785. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  1786. {
  1787. // soname is supported only for shared libraries and modules,
  1788. // and then only when the platform supports an soname flag.
  1789. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY) &&
  1790. !this->GetPropertyAsBool("NO_SONAME") &&
  1791. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  1792. }
  1793. bool cmGeneratorTarget::NeedRelinkBeforeInstall(
  1794. const std::string& config) const
  1795. {
  1796. // Only executables and shared libraries can have an rpath and may
  1797. // need relinking.
  1798. if (this->GetType() != cmStateEnums::EXECUTABLE &&
  1799. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1800. this->GetType() != cmStateEnums::MODULE_LIBRARY) {
  1801. return false;
  1802. }
  1803. // If there is no install location this target will not be installed
  1804. // and therefore does not need relinking.
  1805. if (!this->Target->GetHaveInstallRule()) {
  1806. return false;
  1807. }
  1808. // If skipping all rpaths completely then no relinking is needed.
  1809. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1810. return false;
  1811. }
  1812. // If building with the install-tree rpath no relinking is needed.
  1813. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1814. return false;
  1815. }
  1816. // If chrpath is going to be used no relinking is needed.
  1817. if (this->IsChrpathUsed(config)) {
  1818. return false;
  1819. }
  1820. // Check for rpath support on this platform.
  1821. std::string ll = this->GetLinkerLanguage(config);
  1822. if (!ll.empty()) {
  1823. std::string flagVar =
  1824. cmStrCat("CMAKE_SHARED_LIBRARY_RUNTIME_", ll, "_FLAG");
  1825. if (!this->Makefile->IsSet(flagVar)) {
  1826. // There is no rpath support on this platform so nothing needs
  1827. // relinking.
  1828. return false;
  1829. }
  1830. } else {
  1831. // No linker language is known. This error will be reported by
  1832. // other code.
  1833. return false;
  1834. }
  1835. // If either a build or install tree rpath is set then the rpath
  1836. // will likely change between the build tree and install tree and
  1837. // this target must be relinked.
  1838. bool have_rpath =
  1839. this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH(config);
  1840. bool is_ninja = this->LocalGenerator->GetGlobalGenerator()->IsNinja();
  1841. if (have_rpath && is_ninja) {
  1842. std::ostringstream w;
  1843. /* clang-format off */
  1844. w <<
  1845. "The install of the " << this->GetName() << " target requires changing "
  1846. "an RPATH from the build tree, but this is not supported with the Ninja "
  1847. "generator unless on an ELF-based or XCOFF-based platform. "
  1848. "The CMAKE_BUILD_WITH_INSTALL_RPATH variable may be set to avoid this "
  1849. "relinking step."
  1850. ;
  1851. /* clang-format on */
  1852. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1853. cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
  1854. }
  1855. return have_rpath;
  1856. }
  1857. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  1858. {
  1859. // Only certain target types have an rpath.
  1860. if (!(this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1861. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1862. this->GetType() == cmStateEnums::EXECUTABLE)) {
  1863. return false;
  1864. }
  1865. // If the target will not be installed we do not need to change its
  1866. // rpath.
  1867. if (!this->Target->GetHaveInstallRule()) {
  1868. return false;
  1869. }
  1870. // Skip chrpath if skipping rpath altogether.
  1871. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1872. return false;
  1873. }
  1874. // Skip chrpath if it does not need to be changed at install time.
  1875. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1876. return false;
  1877. }
  1878. // Allow the user to disable builtin chrpath explicitly.
  1879. if (this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH")) {
  1880. return false;
  1881. }
  1882. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1883. return true;
  1884. }
  1885. // Enable if the rpath flag uses a separator and the target uses
  1886. // binaries we know how to edit.
  1887. std::string ll = this->GetLinkerLanguage(config);
  1888. if (!ll.empty()) {
  1889. std::string sepVar =
  1890. cmStrCat("CMAKE_SHARED_LIBRARY_RUNTIME_", ll, "_FLAG_SEP");
  1891. cmValue sep = this->Makefile->GetDefinition(sepVar);
  1892. if (cmNonempty(sep)) {
  1893. // TODO: Add binary format check to ABI detection and get rid of
  1894. // CMAKE_EXECUTABLE_FORMAT.
  1895. if (cmValue fmt =
  1896. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT")) {
  1897. if (*fmt == "ELF") {
  1898. return true;
  1899. }
  1900. #if defined(CMake_USE_XCOFF_PARSER)
  1901. if (*fmt == "XCOFF") {
  1902. return true;
  1903. }
  1904. #endif
  1905. }
  1906. }
  1907. }
  1908. return false;
  1909. }
  1910. bool cmGeneratorTarget::IsImportedSharedLibWithoutSOName(
  1911. const std::string& config) const
  1912. {
  1913. if (this->IsImported() && this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  1914. if (cmGeneratorTarget::ImportInfo const* info =
  1915. this->GetImportInfo(config)) {
  1916. return info->NoSOName;
  1917. }
  1918. }
  1919. return false;
  1920. }
  1921. bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
  1922. const std::string& config) const
  1923. {
  1924. TargetPtrToBoolMap& cache = this->MacOSXRpathInstallNameDirCache[config];
  1925. const auto lookup = cache.find(this->Target);
  1926. if (lookup != cache.cend()) {
  1927. return lookup->second;
  1928. }
  1929. const bool result = this->DetermineHasMacOSXRpathInstallNameDir(config);
  1930. cache[this->Target] = result;
  1931. return result;
  1932. }
  1933. bool cmGeneratorTarget::DetermineHasMacOSXRpathInstallNameDir(
  1934. const std::string& config) const
  1935. {
  1936. bool install_name_is_rpath = false;
  1937. bool macosx_rpath = false;
  1938. if (!this->IsImported()) {
  1939. if (this->GetType() != cmStateEnums::SHARED_LIBRARY) {
  1940. return false;
  1941. }
  1942. cmValue install_name = this->GetProperty("INSTALL_NAME_DIR");
  1943. bool use_install_name = this->MacOSXUseInstallNameDir();
  1944. if (install_name && use_install_name && *install_name == "@rpath") {
  1945. install_name_is_rpath = true;
  1946. } else if (install_name && use_install_name) {
  1947. return false;
  1948. }
  1949. if (!install_name_is_rpath) {
  1950. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  1951. }
  1952. } else {
  1953. // Lookup the imported soname.
  1954. if (cmGeneratorTarget::ImportInfo const* info =
  1955. this->GetImportInfo(config)) {
  1956. if (!info->NoSOName && !info->SOName.empty()) {
  1957. if (cmHasLiteralPrefix(info->SOName, "@rpath/")) {
  1958. install_name_is_rpath = true;
  1959. }
  1960. } else {
  1961. std::string install_name;
  1962. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  1963. if (install_name.find("@rpath") != std::string::npos) {
  1964. install_name_is_rpath = true;
  1965. }
  1966. }
  1967. }
  1968. }
  1969. if (!install_name_is_rpath && !macosx_rpath) {
  1970. return false;
  1971. }
  1972. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  1973. std::ostringstream w;
  1974. w << "Attempting to use ";
  1975. if (macosx_rpath) {
  1976. w << "MACOSX_RPATH";
  1977. } else {
  1978. w << "@rpath";
  1979. }
  1980. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  1981. w << " This could be because you are using a Mac OS X version";
  1982. w << " less than 10.5 or because CMake's platform configuration is";
  1983. w << " corrupt.";
  1984. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1985. cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
  1986. }
  1987. return true;
  1988. }
  1989. bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const
  1990. {
  1991. // we can't do rpaths when unsupported
  1992. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  1993. return false;
  1994. }
  1995. cmValue macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  1996. if (macosx_rpath_str) {
  1997. return this->GetPropertyAsBool("MACOSX_RPATH");
  1998. }
  1999. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  2000. if (cmp0042 == cmPolicies::WARN) {
  2001. this->LocalGenerator->GetGlobalGenerator()->AddCMP0042WarnTarget(
  2002. this->GetName());
  2003. }
  2004. return cmp0042 == cmPolicies::NEW;
  2005. }
  2006. bool cmGeneratorTarget::MacOSXUseInstallNameDir() const
  2007. {
  2008. cmValue build_with_install_name =
  2009. this->GetProperty("BUILD_WITH_INSTALL_NAME_DIR");
  2010. if (build_with_install_name) {
  2011. return cmIsOn(*build_with_install_name);
  2012. }
  2013. cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068();
  2014. if (cmp0068 == cmPolicies::NEW) {
  2015. return false;
  2016. }
  2017. bool use_install_name = this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  2018. if (use_install_name && cmp0068 == cmPolicies::WARN) {
  2019. this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget(
  2020. this->GetName());
  2021. }
  2022. return use_install_name;
  2023. }
  2024. bool cmGeneratorTarget::CanGenerateInstallNameDir(
  2025. InstallNameType name_type) const
  2026. {
  2027. cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068();
  2028. if (cmp0068 == cmPolicies::NEW) {
  2029. return true;
  2030. }
  2031. bool skip = this->Makefile->IsOn("CMAKE_SKIP_RPATH");
  2032. if (name_type == INSTALL_NAME_FOR_INSTALL) {
  2033. skip |= this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  2034. } else {
  2035. skip |= this->GetPropertyAsBool("SKIP_BUILD_RPATH");
  2036. }
  2037. if (skip && cmp0068 == cmPolicies::WARN) {
  2038. this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget(
  2039. this->GetName());
  2040. }
  2041. return !skip;
  2042. }
  2043. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  2044. {
  2045. if (this->IsImported()) {
  2046. // Lookup the imported soname.
  2047. if (cmGeneratorTarget::ImportInfo const* info =
  2048. this->GetImportInfo(config)) {
  2049. if (info->NoSOName) {
  2050. // The imported library has no builtin soname so the name
  2051. // searched at runtime will be just the filename.
  2052. return cmSystemTools::GetFilenameName(info->Location);
  2053. }
  2054. // Use the soname given if any.
  2055. if (this->IsFrameworkOnApple()) {
  2056. cmsys::RegularExpressionMatch match;
  2057. if (FrameworkRegularExpression.find(info->SOName.c_str(), match)) {
  2058. auto frameworkName = match.match(2);
  2059. auto fileName = match.match(3);
  2060. return cmStrCat(frameworkName, ".framework/", fileName);
  2061. }
  2062. }
  2063. if (cmHasLiteralPrefix(info->SOName, "@rpath/")) {
  2064. return info->SOName.substr(cmStrLen("@rpath/"));
  2065. }
  2066. return info->SOName;
  2067. }
  2068. return "";
  2069. }
  2070. // Compute the soname that will be built.
  2071. return this->GetLibraryNames(config).SharedObject;
  2072. }
  2073. namespace {
  2074. bool shouldAddFullLevel(cmGeneratorTarget::BundleDirectoryLevel level)
  2075. {
  2076. return level == cmGeneratorTarget::FullLevel;
  2077. }
  2078. bool shouldAddContentLevel(cmGeneratorTarget::BundleDirectoryLevel level)
  2079. {
  2080. return level == cmGeneratorTarget::ContentLevel || shouldAddFullLevel(level);
  2081. }
  2082. }
  2083. std::string cmGeneratorTarget::GetAppBundleDirectory(
  2084. const std::string& config, BundleDirectoryLevel level) const
  2085. {
  2086. std::string fpath = cmStrCat(
  2087. this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact), '.');
  2088. cmValue ext = this->GetProperty("BUNDLE_EXTENSION");
  2089. fpath += (ext ? *ext : "app");
  2090. if (shouldAddContentLevel(level) &&
  2091. !this->Makefile->PlatformIsAppleEmbedded()) {
  2092. fpath += "/Contents";
  2093. if (shouldAddFullLevel(level)) {
  2094. fpath += "/MacOS";
  2095. }
  2096. }
  2097. return fpath;
  2098. }
  2099. bool cmGeneratorTarget::IsBundleOnApple() const
  2100. {
  2101. return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
  2102. this->IsCFBundleOnApple();
  2103. }
  2104. bool cmGeneratorTarget::IsWin32Executable(const std::string& config) const
  2105. {
  2106. return cmIsOn(cmGeneratorExpression::Evaluate(
  2107. this->GetSafeProperty("WIN32_EXECUTABLE"), this->LocalGenerator, config));
  2108. }
  2109. std::string cmGeneratorTarget::GetCFBundleDirectory(
  2110. const std::string& config, BundleDirectoryLevel level) const
  2111. {
  2112. std::string fpath = cmStrCat(
  2113. this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact), '.');
  2114. std::string ext;
  2115. if (cmValue p = this->GetProperty("BUNDLE_EXTENSION")) {
  2116. ext = *p;
  2117. } else {
  2118. if (this->IsXCTestOnApple()) {
  2119. ext = "xctest";
  2120. } else {
  2121. ext = "bundle";
  2122. }
  2123. }
  2124. fpath += ext;
  2125. if (shouldAddContentLevel(level) &&
  2126. !this->Makefile->PlatformIsAppleEmbedded()) {
  2127. fpath += "/Contents";
  2128. if (shouldAddFullLevel(level)) {
  2129. fpath += "/MacOS";
  2130. }
  2131. }
  2132. return fpath;
  2133. }
  2134. std::string cmGeneratorTarget::GetFrameworkDirectory(
  2135. const std::string& config, BundleDirectoryLevel level) const
  2136. {
  2137. std::string fpath = cmStrCat(
  2138. this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact), '.');
  2139. cmValue ext = this->GetProperty("BUNDLE_EXTENSION");
  2140. fpath += (ext ? *ext : "framework");
  2141. if (shouldAddFullLevel(level) &&
  2142. !this->Makefile->PlatformIsAppleEmbedded()) {
  2143. fpath += "/Versions/";
  2144. fpath += this->GetFrameworkVersion();
  2145. }
  2146. return fpath;
  2147. }
  2148. std::string cmGeneratorTarget::GetFullName(
  2149. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2150. {
  2151. if (this->IsImported()) {
  2152. return this->GetFullNameImported(config, artifact);
  2153. }
  2154. return this->GetFullNameInternal(config, artifact);
  2155. }
  2156. std::string cmGeneratorTarget::GetInstallNameDirForBuildTree(
  2157. const std::string& config) const
  2158. {
  2159. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  2160. // If building directly for installation then the build tree install_name
  2161. // is the same as the install tree.
  2162. if (this->MacOSXUseInstallNameDir()) {
  2163. std::string installPrefix =
  2164. this->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
  2165. return this->GetInstallNameDirForInstallTree(config, installPrefix);
  2166. }
  2167. // Use the build tree directory for the target.
  2168. if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_BUILD)) {
  2169. std::string dir;
  2170. if (this->MacOSXRpathInstallNameDirDefault()) {
  2171. dir = "@rpath";
  2172. } else {
  2173. dir = this->GetDirectory(config);
  2174. }
  2175. dir += "/";
  2176. return dir;
  2177. }
  2178. }
  2179. return "";
  2180. }
  2181. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree(
  2182. const std::string& config, const std::string& installPrefix) const
  2183. {
  2184. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  2185. std::string dir;
  2186. cmValue install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  2187. if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_INSTALL)) {
  2188. if (cmNonempty(install_name_dir)) {
  2189. dir = *install_name_dir;
  2190. cmGeneratorExpression::ReplaceInstallPrefix(dir, installPrefix);
  2191. dir =
  2192. cmGeneratorExpression::Evaluate(dir, this->LocalGenerator, config);
  2193. if (!dir.empty()) {
  2194. dir = cmStrCat(dir, '/');
  2195. }
  2196. }
  2197. }
  2198. if (!install_name_dir) {
  2199. if (this->MacOSXRpathInstallNameDirDefault()) {
  2200. dir = "@rpath/";
  2201. }
  2202. }
  2203. return dir;
  2204. }
  2205. return "";
  2206. }
  2207. cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const
  2208. {
  2209. return this->Target->GetBacktrace();
  2210. }
  2211. const std::set<BT<std::pair<std::string, bool>>>&
  2212. cmGeneratorTarget::GetUtilities() const
  2213. {
  2214. return this->Target->GetUtilities();
  2215. }
  2216. bool cmGeneratorTarget::HaveWellDefinedOutputFiles() const
  2217. {
  2218. return this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  2219. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2220. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  2221. this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  2222. this->GetType() == cmStateEnums::EXECUTABLE;
  2223. }
  2224. const std::string* cmGeneratorTarget::GetExportMacro() const
  2225. {
  2226. // Define the symbol for targets that export symbols.
  2227. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2228. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  2229. this->IsExecutableWithExports()) {
  2230. if (cmValue custom_export_name = this->GetProperty("DEFINE_SYMBOL")) {
  2231. this->ExportMacro = *custom_export_name;
  2232. } else {
  2233. std::string in = cmStrCat(this->GetName(), "_EXPORTS");
  2234. this->ExportMacro = cmSystemTools::MakeCidentifier(in);
  2235. }
  2236. return &this->ExportMacro;
  2237. }
  2238. return nullptr;
  2239. }
  2240. class cmTargetCollectLinkLanguages
  2241. {
  2242. public:
  2243. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  2244. std::string config,
  2245. std::unordered_set<std::string>& languages,
  2246. cmGeneratorTarget const* head, bool secondPass)
  2247. : Config(std::move(config))
  2248. , Languages(languages)
  2249. , HeadTarget(head)
  2250. , Target(target)
  2251. , SecondPass(secondPass)
  2252. {
  2253. this->Visited.insert(target);
  2254. }
  2255. void Visit(cmLinkItem const& item)
  2256. {
  2257. if (!item.Target) {
  2258. if (item.AsStr().find("::") != std::string::npos) {
  2259. bool noMessage = false;
  2260. MessageType messageType = MessageType::FATAL_ERROR;
  2261. std::ostringstream e;
  2262. switch (this->Target->GetLocalGenerator()->GetPolicyStatus(
  2263. cmPolicies::CMP0028)) {
  2264. case cmPolicies::WARN: {
  2265. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  2266. messageType = MessageType::AUTHOR_WARNING;
  2267. } break;
  2268. case cmPolicies::OLD:
  2269. noMessage = true;
  2270. case cmPolicies::REQUIRED_IF_USED:
  2271. case cmPolicies::REQUIRED_ALWAYS:
  2272. case cmPolicies::NEW:
  2273. // Issue the fatal message.
  2274. break;
  2275. }
  2276. if (!noMessage) {
  2277. e << "Target \"" << this->Target->GetName()
  2278. << "\" links to target \"" << item.AsStr()
  2279. << "\" but the target was not found. Perhaps a find_package() "
  2280. "call is missing for an IMPORTED target, or an ALIAS target is "
  2281. "missing?";
  2282. this->Target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2283. messageType, e.str(), this->Target->GetBacktrace());
  2284. }
  2285. }
  2286. return;
  2287. }
  2288. if (!this->Visited.insert(item.Target).second) {
  2289. return;
  2290. }
  2291. cmLinkInterface const* iface = item.Target->GetLinkInterface(
  2292. this->Config, this->HeadTarget, this->SecondPass);
  2293. if (!iface) {
  2294. return;
  2295. }
  2296. if (iface->HadLinkLanguageSensitiveCondition) {
  2297. this->HadLinkLanguageSensitiveCondition = true;
  2298. }
  2299. for (std::string const& language : iface->Languages) {
  2300. this->Languages.insert(language);
  2301. }
  2302. for (cmLinkItem const& lib : iface->Libraries) {
  2303. this->Visit(lib);
  2304. }
  2305. }
  2306. bool GetHadLinkLanguageSensitiveCondition() const
  2307. {
  2308. return this->HadLinkLanguageSensitiveCondition;
  2309. }
  2310. private:
  2311. std::string Config;
  2312. std::unordered_set<std::string>& Languages;
  2313. cmGeneratorTarget const* HeadTarget;
  2314. const cmGeneratorTarget* Target;
  2315. std::set<cmGeneratorTarget const*> Visited;
  2316. bool SecondPass;
  2317. bool HadLinkLanguageSensitiveCondition = false;
  2318. };
  2319. cmGeneratorTarget::LinkClosure const* cmGeneratorTarget::GetLinkClosure(
  2320. const std::string& config) const
  2321. {
  2322. // There is no link implementation for targets that cannot compile sources.
  2323. if (!this->CanCompileSources()) {
  2324. static LinkClosure const empty = { {}, {} };
  2325. return &empty;
  2326. }
  2327. std::string key(cmSystemTools::UpperCase(config));
  2328. auto i = this->LinkClosureMap.find(key);
  2329. if (i == this->LinkClosureMap.end()) {
  2330. LinkClosure lc;
  2331. this->ComputeLinkClosure(config, lc);
  2332. LinkClosureMapType::value_type entry(key, lc);
  2333. i = this->LinkClosureMap.insert(entry).first;
  2334. }
  2335. return &i->second;
  2336. }
  2337. class cmTargetSelectLinker
  2338. {
  2339. int Preference;
  2340. cmGeneratorTarget const* Target;
  2341. cmGlobalGenerator* GG;
  2342. std::set<std::string> Preferred;
  2343. public:
  2344. cmTargetSelectLinker(cmGeneratorTarget const* target)
  2345. : Preference(0)
  2346. , Target(target)
  2347. {
  2348. this->GG = this->Target->GetLocalGenerator()->GetGlobalGenerator();
  2349. }
  2350. void Consider(const std::string& lang)
  2351. {
  2352. int preference = this->GG->GetLinkerPreference(lang);
  2353. if (preference > this->Preference) {
  2354. this->Preference = preference;
  2355. this->Preferred.clear();
  2356. }
  2357. if (preference == this->Preference) {
  2358. this->Preferred.insert(lang);
  2359. }
  2360. }
  2361. std::string Choose()
  2362. {
  2363. if (this->Preferred.empty()) {
  2364. return "";
  2365. }
  2366. if (this->Preferred.size() > 1) {
  2367. std::ostringstream e;
  2368. e << "Target " << this->Target->GetName()
  2369. << " contains multiple languages with the highest linker preference"
  2370. << " (" << this->Preference << "):\n";
  2371. for (std::string const& li : this->Preferred) {
  2372. e << " " << li << "\n";
  2373. }
  2374. e << "Set the LINKER_LANGUAGE property for this target.";
  2375. cmake* cm = this->Target->GetLocalGenerator()->GetCMakeInstance();
  2376. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  2377. this->Target->GetBacktrace());
  2378. }
  2379. return *this->Preferred.begin();
  2380. }
  2381. };
  2382. bool cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  2383. LinkClosure& lc,
  2384. bool secondPass) const
  2385. {
  2386. // Get languages built in this target.
  2387. std::unordered_set<std::string> languages;
  2388. cmLinkImplementation const* impl =
  2389. this->GetLinkImplementation(config, secondPass);
  2390. assert(impl);
  2391. languages.insert(impl->Languages.cbegin(), impl->Languages.cend());
  2392. // Add interface languages from linked targets.
  2393. // cmTargetCollectLinkLanguages cll(this, config, languages, this,
  2394. // secondPass);
  2395. cmTargetCollectLinkLanguages cll(this, config, languages, this, secondPass);
  2396. for (cmLinkImplItem const& lib : impl->Libraries) {
  2397. cll.Visit(lib);
  2398. }
  2399. // Store the transitive closure of languages.
  2400. cm::append(lc.Languages, languages);
  2401. // Choose the language whose linker should be used.
  2402. if (secondPass || lc.LinkerLanguage.empty()) {
  2403. // Find the language with the highest preference value.
  2404. cmTargetSelectLinker tsl(this);
  2405. // First select from the languages compiled directly in this target.
  2406. for (std::string const& l : impl->Languages) {
  2407. tsl.Consider(l);
  2408. }
  2409. // Now consider languages that propagate from linked targets.
  2410. for (std::string const& lang : languages) {
  2411. std::string propagates =
  2412. "CMAKE_" + lang + "_LINKER_PREFERENCE_PROPAGATES";
  2413. if (this->Makefile->IsOn(propagates)) {
  2414. tsl.Consider(lang);
  2415. }
  2416. }
  2417. lc.LinkerLanguage = tsl.Choose();
  2418. }
  2419. return impl->HadLinkLanguageSensitiveCondition ||
  2420. cll.GetHadLinkLanguageSensitiveCondition();
  2421. }
  2422. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  2423. LinkClosure& lc) const
  2424. {
  2425. bool secondPass = false;
  2426. {
  2427. LinkClosure linkClosure;
  2428. linkClosure.LinkerLanguage = this->LinkerLanguage;
  2429. bool hasHardCodedLinkerLanguage = this->Target->GetProperty("HAS_CXX") ||
  2430. !this->Target->GetSafeProperty("LINKER_LANGUAGE").empty();
  2431. // Get languages built in this target.
  2432. secondPass = this->ComputeLinkClosure(config, linkClosure, false) &&
  2433. !hasHardCodedLinkerLanguage;
  2434. this->LinkerLanguage = linkClosure.LinkerLanguage;
  2435. if (!secondPass) {
  2436. lc = std::move(linkClosure);
  2437. }
  2438. }
  2439. if (secondPass) {
  2440. LinkClosure linkClosure;
  2441. this->ComputeLinkClosure(config, linkClosure, secondPass);
  2442. lc = std::move(linkClosure);
  2443. // linker language must not be changed between the two passes
  2444. if (this->LinkerLanguage != lc.LinkerLanguage) {
  2445. std::ostringstream e;
  2446. e << "Evaluation of $<LINK_LANGUAGE:...> or $<LINK_LAND_AND_ID:...> "
  2447. "changes\nthe linker language for target \""
  2448. << this->GetName() << "\" (from '" << this->LinkerLanguage << "' to '"
  2449. << lc.LinkerLanguage << "') which is invalid.";
  2450. cmSystemTools::Error(e.str());
  2451. }
  2452. }
  2453. }
  2454. void cmGeneratorTarget::GetFullNameComponents(
  2455. std::string& prefix, std::string& base, std::string& suffix,
  2456. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2457. {
  2458. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  2459. }
  2460. std::string cmGeneratorTarget::BuildBundleDirectory(
  2461. const std::string& base, const std::string& config,
  2462. BundleDirectoryLevel level) const
  2463. {
  2464. std::string fpath = base;
  2465. if (this->IsAppBundleOnApple()) {
  2466. fpath += this->GetAppBundleDirectory(config, level);
  2467. }
  2468. if (this->IsFrameworkOnApple()) {
  2469. fpath += this->GetFrameworkDirectory(config, level);
  2470. }
  2471. if (this->IsCFBundleOnApple()) {
  2472. fpath += this->GetCFBundleDirectory(config, level);
  2473. }
  2474. return fpath;
  2475. }
  2476. std::string cmGeneratorTarget::GetMacContentDirectory(
  2477. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2478. {
  2479. // Start with the output directory for the target.
  2480. std::string fpath = cmStrCat(this->GetDirectory(config, artifact), '/');
  2481. BundleDirectoryLevel level = ContentLevel;
  2482. if (this->IsFrameworkOnApple()) {
  2483. // additional files with a framework go into the version specific
  2484. // directory
  2485. level = FullLevel;
  2486. }
  2487. fpath = this->BuildBundleDirectory(fpath, config, level);
  2488. return fpath;
  2489. }
  2490. std::string cmGeneratorTarget::GetEffectiveFolderName() const
  2491. {
  2492. std::string effectiveFolder;
  2493. if (!this->GlobalGenerator->UseFolderProperty()) {
  2494. return effectiveFolder;
  2495. }
  2496. cmValue targetFolder = this->GetProperty("FOLDER");
  2497. if (targetFolder) {
  2498. effectiveFolder += *targetFolder;
  2499. }
  2500. return effectiveFolder;
  2501. }
  2502. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  2503. const std::string& config) const
  2504. {
  2505. // There is no compile information for imported targets.
  2506. if (this->IsImported()) {
  2507. return nullptr;
  2508. }
  2509. if (this->GetType() > cmStateEnums::OBJECT_LIBRARY) {
  2510. std::string msg = cmStrCat("cmTarget::GetCompileInfo called for ",
  2511. this->GetName(), " which has type ",
  2512. cmState::GetTargetTypeName(this->GetType()));
  2513. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  2514. return nullptr;
  2515. }
  2516. // Lookup/compute/cache the compile information for this configuration.
  2517. std::string config_upper;
  2518. if (!config.empty()) {
  2519. config_upper = cmSystemTools::UpperCase(config);
  2520. }
  2521. auto i = this->CompileInfoMap.find(config_upper);
  2522. if (i == this->CompileInfoMap.end()) {
  2523. CompileInfo info;
  2524. this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  2525. CompileInfoMapType::value_type entry(config_upper, info);
  2526. i = this->CompileInfoMap.insert(entry).first;
  2527. }
  2528. return &i->second;
  2529. }
  2530. cmGeneratorTarget::ModuleDefinitionInfo const*
  2531. cmGeneratorTarget::GetModuleDefinitionInfo(std::string const& config) const
  2532. {
  2533. // A module definition file only makes sense on certain target types.
  2534. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  2535. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  2536. !this->IsExecutableWithExports()) {
  2537. return nullptr;
  2538. }
  2539. // Lookup/compute/cache the compile information for this configuration.
  2540. std::string config_upper;
  2541. if (!config.empty()) {
  2542. config_upper = cmSystemTools::UpperCase(config);
  2543. }
  2544. auto i = this->ModuleDefinitionInfoMap.find(config_upper);
  2545. if (i == this->ModuleDefinitionInfoMap.end()) {
  2546. ModuleDefinitionInfo info;
  2547. this->ComputeModuleDefinitionInfo(config, info);
  2548. ModuleDefinitionInfoMapType::value_type entry(config_upper, info);
  2549. i = this->ModuleDefinitionInfoMap.insert(entry).first;
  2550. }
  2551. return &i->second;
  2552. }
  2553. void cmGeneratorTarget::ComputeModuleDefinitionInfo(
  2554. std::string const& config, ModuleDefinitionInfo& info) const
  2555. {
  2556. this->GetModuleDefinitionSources(info.Sources, config);
  2557. info.WindowsExportAllSymbols =
  2558. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") &&
  2559. this->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS");
  2560. #if !defined(CMAKE_BOOTSTRAP)
  2561. info.DefFileGenerated =
  2562. info.WindowsExportAllSymbols || info.Sources.size() > 1;
  2563. #else
  2564. // Our __create_def helper is not available during CMake bootstrap.
  2565. info.DefFileGenerated = false;
  2566. #endif
  2567. if (info.DefFileGenerated) {
  2568. info.DefFile =
  2569. this->GetObjectDirectory(config) /* has slash */ + "exports.def";
  2570. } else if (!info.Sources.empty()) {
  2571. info.DefFile = info.Sources.front()->GetFullPath();
  2572. }
  2573. }
  2574. bool cmGeneratorTarget::IsDLLPlatform() const
  2575. {
  2576. return this->Target->IsDLLPlatform();
  2577. }
  2578. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result,
  2579. const std::string& config) const
  2580. {
  2581. const char* prop =
  2582. this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS", config);
  2583. if (!prop) {
  2584. return;
  2585. }
  2586. cmGeneratorExpressionDAGChecker dagChecker(this, "AUTOUIC_OPTIONS", nullptr,
  2587. nullptr);
  2588. cmExpandList(cmGeneratorExpression::Evaluate(prop, this->LocalGenerator,
  2589. config, this, &dagChecker),
  2590. result);
  2591. }
  2592. void processILibs(const std::string& config,
  2593. cmGeneratorTarget const* headTarget, cmLinkItem const& item,
  2594. cmGlobalGenerator* gg,
  2595. std::vector<cmGeneratorTarget const*>& tgts,
  2596. std::set<cmGeneratorTarget const*>& emitted)
  2597. {
  2598. if (item.Target && emitted.insert(item.Target).second) {
  2599. tgts.push_back(item.Target);
  2600. if (cmLinkInterfaceLibraries const* iface =
  2601. item.Target->GetLinkInterfaceLibraries(config, headTarget, true)) {
  2602. for (cmLinkItem const& lib : iface->Libraries) {
  2603. processILibs(config, headTarget, lib, gg, tgts, emitted);
  2604. }
  2605. }
  2606. }
  2607. }
  2608. const std::vector<const cmGeneratorTarget*>&
  2609. cmGeneratorTarget::GetLinkImplementationClosure(
  2610. const std::string& config) const
  2611. {
  2612. // There is no link implementation for targets that cannot compile sources.
  2613. if (!this->CanCompileSources()) {
  2614. static std::vector<const cmGeneratorTarget*> const empty;
  2615. return empty;
  2616. }
  2617. LinkImplClosure& tgts = this->LinkImplClosureMap[config];
  2618. if (!tgts.Done) {
  2619. tgts.Done = true;
  2620. std::set<cmGeneratorTarget const*> emitted;
  2621. cmLinkImplementationLibraries const* impl =
  2622. this->GetLinkImplementationLibraries(config);
  2623. assert(impl);
  2624. for (cmLinkImplItem const& lib : impl->Libraries) {
  2625. processILibs(config, this, lib,
  2626. this->LocalGenerator->GetGlobalGenerator(), tgts, emitted);
  2627. }
  2628. }
  2629. return tgts;
  2630. }
  2631. class cmTargetTraceDependencies
  2632. {
  2633. public:
  2634. cmTargetTraceDependencies(cmGeneratorTarget* target);
  2635. void Trace();
  2636. private:
  2637. cmGeneratorTarget* GeneratorTarget;
  2638. cmMakefile* Makefile;
  2639. cmLocalGenerator* LocalGenerator;
  2640. cmGlobalGenerator const* GlobalGenerator;
  2641. using SourceEntry = cmGeneratorTarget::SourceEntry;
  2642. SourceEntry* CurrentEntry;
  2643. std::queue<cmSourceFile*> SourceQueue;
  2644. std::set<cmSourceFile*> SourcesQueued;
  2645. using NameMapType = std::map<std::string, cmSourcesWithOutput>;
  2646. NameMapType NameMap;
  2647. std::vector<std::string> NewSources;
  2648. void QueueSource(cmSourceFile* sf);
  2649. void FollowName(std::string const& name);
  2650. void FollowNames(std::vector<std::string> const& names);
  2651. bool IsUtility(std::string const& dep);
  2652. void CheckCustomCommand(cmCustomCommand const& cc);
  2653. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  2654. };
  2655. cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target)
  2656. : GeneratorTarget(target)
  2657. {
  2658. // Convenience.
  2659. this->Makefile = target->Target->GetMakefile();
  2660. this->LocalGenerator = target->GetLocalGenerator();
  2661. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  2662. this->CurrentEntry = nullptr;
  2663. // Queue all the source files already specified for the target.
  2664. std::set<cmSourceFile*> emitted;
  2665. std::vector<std::string> const& configs =
  2666. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  2667. for (std::string const& c : configs) {
  2668. std::vector<cmSourceFile*> sources;
  2669. this->GeneratorTarget->GetSourceFiles(sources, c);
  2670. for (cmSourceFile* sf : sources) {
  2671. const std::set<cmGeneratorTarget const*> tgts =
  2672. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  2673. if (cm::contains(tgts, this->GeneratorTarget)) {
  2674. std::ostringstream e;
  2675. e << "Evaluation output file\n \"" << sf->ResolveFullPath()
  2676. << "\"\ndepends on the sources of a target it is used in. This "
  2677. "is a dependency loop and is not allowed.";
  2678. this->GeneratorTarget->LocalGenerator->IssueMessage(
  2679. MessageType::FATAL_ERROR, e.str());
  2680. return;
  2681. }
  2682. if (emitted.insert(sf).second && this->SourcesQueued.insert(sf).second) {
  2683. this->SourceQueue.push(sf);
  2684. }
  2685. }
  2686. }
  2687. // Queue pre-build, pre-link, and post-build rule dependencies.
  2688. this->CheckCustomCommands(this->GeneratorTarget->GetPreBuildCommands());
  2689. this->CheckCustomCommands(this->GeneratorTarget->GetPreLinkCommands());
  2690. this->CheckCustomCommands(this->GeneratorTarget->GetPostBuildCommands());
  2691. }
  2692. void cmTargetTraceDependencies::Trace()
  2693. {
  2694. // Process one dependency at a time until the queue is empty.
  2695. while (!this->SourceQueue.empty()) {
  2696. // Get the next source from the queue.
  2697. cmSourceFile* sf = this->SourceQueue.front();
  2698. this->SourceQueue.pop();
  2699. this->CurrentEntry = &this->GeneratorTarget->SourceDepends[sf];
  2700. // Queue dependencies added explicitly by the user.
  2701. if (cmValue additionalDeps = sf->GetProperty("OBJECT_DEPENDS")) {
  2702. std::vector<std::string> objDeps = cmExpandedList(*additionalDeps);
  2703. for (std::string& objDep : objDeps) {
  2704. if (cmSystemTools::FileIsFullPath(objDep)) {
  2705. objDep = cmSystemTools::CollapseFullPath(objDep);
  2706. }
  2707. }
  2708. this->FollowNames(objDeps);
  2709. }
  2710. // Queue the source needed to generate this file, if any.
  2711. this->FollowName(sf->ResolveFullPath());
  2712. // Queue dependencies added programmatically by commands.
  2713. this->FollowNames(sf->GetDepends());
  2714. // Queue custom command dependencies.
  2715. if (cmCustomCommand const* cc = sf->GetCustomCommand()) {
  2716. this->CheckCustomCommand(*cc);
  2717. }
  2718. }
  2719. this->CurrentEntry = nullptr;
  2720. this->GeneratorTarget->AddTracedSources(this->NewSources);
  2721. }
  2722. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  2723. {
  2724. if (this->SourcesQueued.insert(sf).second) {
  2725. this->SourceQueue.push(sf);
  2726. // Make sure this file is in the target at the end.
  2727. this->NewSources.push_back(sf->ResolveFullPath());
  2728. }
  2729. }
  2730. void cmTargetTraceDependencies::FollowName(std::string const& name)
  2731. {
  2732. // Use lower bound with key comparison to not repeat the search for the
  2733. // insert position if the name could not be found (which is the common case).
  2734. auto i = this->NameMap.lower_bound(name);
  2735. if (i == this->NameMap.end() || i->first != name) {
  2736. // Check if we know how to generate this file.
  2737. cmSourcesWithOutput sources =
  2738. this->LocalGenerator->GetSourcesWithOutput(name);
  2739. // If we failed to find a target or source and we have a relative path, it
  2740. // might be a valid source if made relative to the current binary
  2741. // directory.
  2742. if (!sources.Target && !sources.Source &&
  2743. !cmSystemTools::FileIsFullPath(name)) {
  2744. auto fullname =
  2745. cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/', name);
  2746. fullname = cmSystemTools::CollapseFullPath(
  2747. fullname, this->Makefile->GetHomeOutputDirectory());
  2748. sources = this->LocalGenerator->GetSourcesWithOutput(fullname);
  2749. }
  2750. i = this->NameMap.emplace_hint(i, name, sources);
  2751. }
  2752. if (cmTarget* t = i->second.Target) {
  2753. // The name is a byproduct of a utility target or a PRE_BUILD, PRE_LINK, or
  2754. // POST_BUILD command.
  2755. this->GeneratorTarget->Target->AddUtility(t->GetName(), false);
  2756. }
  2757. if (cmSourceFile* sf = i->second.Source) {
  2758. // For now only follow the dependency if the source file is not a
  2759. // byproduct. Semantics of byproducts in a non-Ninja context will have to
  2760. // be defined first.
  2761. if (!i->second.SourceIsByproduct) {
  2762. // Record the dependency we just followed.
  2763. if (this->CurrentEntry) {
  2764. this->CurrentEntry->Depends.push_back(sf);
  2765. }
  2766. this->QueueSource(sf);
  2767. }
  2768. }
  2769. }
  2770. void cmTargetTraceDependencies::FollowNames(
  2771. std::vector<std::string> const& names)
  2772. {
  2773. for (std::string const& name : names) {
  2774. this->FollowName(name);
  2775. }
  2776. }
  2777. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  2778. {
  2779. // Dependencies on targets (utilities) are supposed to be named by
  2780. // just the target name. However for compatibility we support
  2781. // naming the output file generated by the target (assuming there is
  2782. // no output-name property which old code would not have set). In
  2783. // that case the target name will be the file basename of the
  2784. // dependency.
  2785. std::string util = cmSystemTools::GetFilenameName(dep);
  2786. if (cmSystemTools::GetFilenameLastExtension(util) == ".exe") {
  2787. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  2788. }
  2789. // Check for a target with this name.
  2790. if (cmGeneratorTarget* t =
  2791. this->GeneratorTarget->GetLocalGenerator()->FindGeneratorTargetToUse(
  2792. util)) {
  2793. // If we find the target and the dep was given as a full path,
  2794. // then make sure it was not a full path to something else, and
  2795. // the fact that the name matched a target was just a coincidence.
  2796. if (cmSystemTools::FileIsFullPath(dep)) {
  2797. if (t->GetType() >= cmStateEnums::EXECUTABLE &&
  2798. t->GetType() <= cmStateEnums::MODULE_LIBRARY) {
  2799. // This is really only for compatibility so we do not need to
  2800. // worry about configuration names and output names.
  2801. std::string tLocation = t->GetLocationForBuild();
  2802. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  2803. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  2804. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  2805. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  2806. if (depLocation == tLocation) {
  2807. this->GeneratorTarget->Target->AddUtility(util, false);
  2808. return true;
  2809. }
  2810. }
  2811. } else {
  2812. // The original name of the dependency was not a full path. It
  2813. // must name a target, so add the target-level dependency.
  2814. this->GeneratorTarget->Target->AddUtility(util, true);
  2815. return true;
  2816. }
  2817. }
  2818. // The dependency does not name a target built in this project.
  2819. return false;
  2820. }
  2821. void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
  2822. {
  2823. // Collect dependencies referenced by all configurations.
  2824. std::set<std::string> depends;
  2825. for (std::string const& config :
  2826. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig)) {
  2827. for (cmCustomCommandGenerator const& ccg :
  2828. this->LocalGenerator->MakeCustomCommandGenerators(cc, config)) {
  2829. // Collect target-level dependencies referenced in command lines.
  2830. for (auto const& util : ccg.GetUtilities()) {
  2831. this->GeneratorTarget->Target->AddUtility(util);
  2832. }
  2833. // Collect file-level dependencies referenced in DEPENDS.
  2834. depends.insert(ccg.GetDepends().begin(), ccg.GetDepends().end());
  2835. }
  2836. }
  2837. // Queue file-level dependencies.
  2838. for (std::string const& dep : depends) {
  2839. if (!this->IsUtility(dep)) {
  2840. // The dependency does not name a target and may be a file we
  2841. // know how to generate. Queue it.
  2842. this->FollowName(dep);
  2843. }
  2844. }
  2845. }
  2846. void cmTargetTraceDependencies::CheckCustomCommands(
  2847. const std::vector<cmCustomCommand>& commands)
  2848. {
  2849. for (cmCustomCommand const& command : commands) {
  2850. this->CheckCustomCommand(command);
  2851. }
  2852. }
  2853. void cmGeneratorTarget::TraceDependencies()
  2854. {
  2855. // CMake-generated targets have no dependencies to trace. Normally tracing
  2856. // would find nothing anyway, but when building CMake itself the "install"
  2857. // target command ends up referencing the "cmake" target but we do not
  2858. // really want the dependency because "install" depend on "all" anyway.
  2859. if (this->GetType() == cmStateEnums::GLOBAL_TARGET) {
  2860. return;
  2861. }
  2862. // Use a helper object to trace the dependencies.
  2863. cmTargetTraceDependencies tracer(this);
  2864. tracer.Trace();
  2865. }
  2866. std::string cmGeneratorTarget::GetCompilePDBDirectory(
  2867. const std::string& config) const
  2868. {
  2869. if (CompileInfo const* info = this->GetCompileInfo(config)) {
  2870. return info->CompilePdbDir;
  2871. }
  2872. return "";
  2873. }
  2874. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  2875. std::vector<std::string>& archVec) const
  2876. {
  2877. if (!this->Makefile->IsOn("APPLE")) {
  2878. return;
  2879. }
  2880. cmValue archs = nullptr;
  2881. if (!config.empty()) {
  2882. std::string defVarName =
  2883. cmStrCat("OSX_ARCHITECTURES_", cmSystemTools::UpperCase(config));
  2884. archs = this->GetProperty(defVarName);
  2885. }
  2886. if (!archs) {
  2887. archs = this->GetProperty("OSX_ARCHITECTURES");
  2888. }
  2889. if (archs) {
  2890. cmExpandList(*archs, archVec);
  2891. }
  2892. if (archVec.empty()) {
  2893. this->Makefile->GetDefExpandList("_CMAKE_APPLE_ARCHS_DEFAULT", archVec);
  2894. }
  2895. }
  2896. void cmGeneratorTarget::AddExplicitLanguageFlags(std::string& flags,
  2897. cmSourceFile const& sf) const
  2898. {
  2899. cmValue lang = sf.GetProperty("LANGUAGE");
  2900. if (!lang) {
  2901. return;
  2902. }
  2903. switch (this->GetPolicyStatusCMP0119()) {
  2904. case cmPolicies::WARN:
  2905. case cmPolicies::OLD:
  2906. // The OLD behavior is to not add explicit language flags.
  2907. return;
  2908. case cmPolicies::REQUIRED_ALWAYS:
  2909. case cmPolicies::REQUIRED_IF_USED:
  2910. case cmPolicies::NEW:
  2911. // The NEW behavior is to add explicit language flags.
  2912. break;
  2913. }
  2914. this->LocalGenerator->AppendFeatureOptions(flags, *lang,
  2915. "EXPLICIT_LANGUAGE");
  2916. }
  2917. void cmGeneratorTarget::AddCUDAArchitectureFlags(std::string& flags) const
  2918. {
  2919. const std::string& property = this->GetSafeProperty("CUDA_ARCHITECTURES");
  2920. if (property.empty()) {
  2921. switch (this->GetPolicyStatusCMP0104()) {
  2922. case cmPolicies::WARN:
  2923. if (!this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile()) {
  2924. this->Makefile->IssueMessage(
  2925. MessageType::AUTHOR_WARNING,
  2926. cmPolicies::GetPolicyWarning(cmPolicies::CMP0104) +
  2927. "\nCUDA_ARCHITECTURES is empty for target \"" + this->GetName() +
  2928. "\".");
  2929. }
  2930. CM_FALLTHROUGH;
  2931. case cmPolicies::OLD:
  2932. break;
  2933. default:
  2934. this->Makefile->IssueMessage(
  2935. MessageType::FATAL_ERROR,
  2936. "CUDA_ARCHITECTURES is empty for target \"" + this->GetName() +
  2937. "\".");
  2938. }
  2939. }
  2940. // If CUDA_ARCHITECTURES is false we don't add any architectures.
  2941. if (cmIsOff(property)) {
  2942. return;
  2943. }
  2944. struct CudaArchitecture
  2945. {
  2946. std::string name;
  2947. bool real{ true };
  2948. bool virtual_{ true };
  2949. };
  2950. std::vector<CudaArchitecture> architectures;
  2951. {
  2952. std::vector<std::string> options;
  2953. cmExpandList(property, options);
  2954. for (std::string& option : options) {
  2955. CudaArchitecture architecture;
  2956. // Architecture name is up to the first specifier.
  2957. std::size_t pos = option.find_first_of('-');
  2958. architecture.name = option.substr(0, pos);
  2959. if (pos != std::string::npos) {
  2960. cm::string_view specifier{ option.c_str() + pos + 1,
  2961. option.length() - pos - 1 };
  2962. if (specifier == "real") {
  2963. architecture.real = true;
  2964. architecture.virtual_ = false;
  2965. } else if (specifier == "virtual") {
  2966. architecture.real = false;
  2967. architecture.virtual_ = true;
  2968. } else {
  2969. this->Makefile->IssueMessage(
  2970. MessageType::FATAL_ERROR,
  2971. "Unknown CUDA architecture specifier \"" + std::string(specifier) +
  2972. "\".");
  2973. }
  2974. }
  2975. architectures.emplace_back(architecture);
  2976. }
  2977. }
  2978. std::string const& compiler =
  2979. this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
  2980. if (compiler == "NVIDIA") {
  2981. for (CudaArchitecture& architecture : architectures) {
  2982. flags +=
  2983. " --generate-code=arch=compute_" + architecture.name + ",code=[";
  2984. if (architecture.virtual_) {
  2985. flags += "compute_" + architecture.name;
  2986. if (architecture.real) {
  2987. flags += ",";
  2988. }
  2989. }
  2990. if (architecture.real) {
  2991. flags += "sm_" + architecture.name;
  2992. }
  2993. flags += "]";
  2994. }
  2995. } else if (compiler == "Clang") {
  2996. for (CudaArchitecture& architecture : architectures) {
  2997. flags += " --cuda-gpu-arch=sm_" + architecture.name;
  2998. if (!architecture.real) {
  2999. this->Makefile->IssueMessage(
  3000. MessageType::WARNING,
  3001. "Clang doesn't support disabling CUDA real code generation.");
  3002. }
  3003. if (!architecture.virtual_) {
  3004. flags += " --no-cuda-include-ptx=sm_" + architecture.name;
  3005. }
  3006. }
  3007. }
  3008. }
  3009. void cmGeneratorTarget::AddISPCTargetFlags(std::string& flags) const
  3010. {
  3011. const std::string& property = this->GetSafeProperty("ISPC_INSTRUCTION_SETS");
  3012. // If ISPC_TARGET is false we don't add any architectures.
  3013. if (cmIsOff(property)) {
  3014. return;
  3015. }
  3016. std::string const& compiler =
  3017. this->Makefile->GetSafeDefinition("CMAKE_ISPC_COMPILER_ID");
  3018. if (compiler == "Intel") {
  3019. std::vector<std::string> targets;
  3020. cmExpandList(property, targets);
  3021. if (!targets.empty()) {
  3022. flags += cmStrCat(" --target=", cmWrap("", targets, "", ","));
  3023. }
  3024. }
  3025. }
  3026. void cmGeneratorTarget::AddHIPArchitectureFlags(std::string& flags) const
  3027. {
  3028. const std::string& property = this->GetSafeProperty("HIP_ARCHITECTURES");
  3029. if (property.empty()) {
  3030. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  3031. "HIP_ARCHITECTURES is empty for target \"" +
  3032. this->GetName() + "\".");
  3033. }
  3034. // If HIP_ARCHITECTURES is false we don't add any architectures.
  3035. if (cmIsOff(property)) {
  3036. return;
  3037. }
  3038. std::vector<std::string> options;
  3039. cmExpandList(property, options);
  3040. for (std::string& option : options) {
  3041. flags += " --offload-arch=" + option;
  3042. }
  3043. }
  3044. void cmGeneratorTarget::AddCUDAToolkitFlags(std::string& flags) const
  3045. {
  3046. std::string const& compiler =
  3047. this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
  3048. if (compiler == "Clang") {
  3049. // Pass CUDA toolkit explicitly to Clang.
  3050. // Clang's searching for the system CUDA toolkit isn't very good and it's
  3051. // expected the user will explicitly pass the toolkit path.
  3052. // This also avoids Clang having to search for the toolkit on every
  3053. // invocation.
  3054. std::string toolkitRoot =
  3055. this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_LIBRARY_ROOT");
  3056. if (!toolkitRoot.empty()) {
  3057. flags += " --cuda-path=" +
  3058. this->LocalGenerator->ConvertToOutputFormat(toolkitRoot,
  3059. cmOutputConverter::SHELL);
  3060. }
  3061. }
  3062. }
  3063. //----------------------------------------------------------------------------
  3064. std::string cmGeneratorTarget::GetFeatureSpecificLinkRuleVariable(
  3065. std::string const& var, std::string const& lang,
  3066. std::string const& config) const
  3067. {
  3068. if (this->IsIPOEnabled(lang, config)) {
  3069. std::string varIPO = var + "_IPO";
  3070. if (this->Makefile->IsDefinitionSet(varIPO)) {
  3071. return varIPO;
  3072. }
  3073. }
  3074. return var;
  3075. }
  3076. //----------------------------------------------------------------------------
  3077. std::string cmGeneratorTarget::GetCreateRuleVariable(
  3078. std::string const& lang, std::string const& config) const
  3079. {
  3080. switch (this->GetType()) {
  3081. case cmStateEnums::STATIC_LIBRARY: {
  3082. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  3083. return this->GetFeatureSpecificLinkRuleVariable(var, lang, config);
  3084. }
  3085. case cmStateEnums::SHARED_LIBRARY:
  3086. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  3087. case cmStateEnums::MODULE_LIBRARY:
  3088. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  3089. case cmStateEnums::EXECUTABLE:
  3090. if (this->IsExecutableWithExports()) {
  3091. std::string linkExeWithExports =
  3092. "CMAKE_" + lang + "_LINK_EXECUTABLE_WITH_EXPORTS";
  3093. if (this->Makefile->IsDefinitionSet(linkExeWithExports)) {
  3094. return linkExeWithExports;
  3095. }
  3096. }
  3097. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  3098. default:
  3099. break;
  3100. }
  3101. return "";
  3102. }
  3103. namespace {
  3104. void processIncludeDirectories(cmGeneratorTarget const* tgt,
  3105. EvaluatedTargetPropertyEntries& entries,
  3106. std::vector<BT<std::string>>& includes,
  3107. std::unordered_set<std::string>& uniqueIncludes,
  3108. bool debugIncludes)
  3109. {
  3110. for (EvaluatedTargetPropertyEntry& entry : entries.Entries) {
  3111. cmLinkImplItem const& item = entry.LinkImplItem;
  3112. std::string const& targetName = item.AsStr();
  3113. bool const fromImported = item.Target && item.Target->IsImported();
  3114. bool const checkCMP0027 = item.FromGenex;
  3115. std::string usedIncludes;
  3116. for (std::string& entryInclude : entry.Values) {
  3117. if (fromImported && !cmSystemTools::FileExists(entryInclude)) {
  3118. std::ostringstream e;
  3119. MessageType messageType = MessageType::FATAL_ERROR;
  3120. if (checkCMP0027) {
  3121. switch (tgt->GetPolicyStatusCMP0027()) {
  3122. case cmPolicies::WARN:
  3123. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  3124. CM_FALLTHROUGH;
  3125. case cmPolicies::OLD:
  3126. messageType = MessageType::AUTHOR_WARNING;
  3127. break;
  3128. case cmPolicies::REQUIRED_ALWAYS:
  3129. case cmPolicies::REQUIRED_IF_USED:
  3130. case cmPolicies::NEW:
  3131. break;
  3132. }
  3133. }
  3134. /* clang-format off */
  3135. e << "Imported target \"" << targetName << "\" includes "
  3136. "non-existent path\n \"" << entryInclude << "\"\nin its "
  3137. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  3138. "* The path was deleted, renamed, or moved to another "
  3139. "location.\n"
  3140. "* An install or uninstall procedure did not complete "
  3141. "successfully.\n"
  3142. "* The installation package was faulty and references files it "
  3143. "does not provide.\n";
  3144. /* clang-format on */
  3145. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  3146. return;
  3147. }
  3148. if (!cmSystemTools::FileIsFullPath(entryInclude)) {
  3149. std::ostringstream e;
  3150. bool noMessage = false;
  3151. MessageType messageType = MessageType::FATAL_ERROR;
  3152. if (!targetName.empty()) {
  3153. /* clang-format off */
  3154. e << "Target \"" << targetName << "\" contains relative "
  3155. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  3156. " \"" << entryInclude << "\"";
  3157. /* clang-format on */
  3158. } else {
  3159. switch (tgt->GetPolicyStatusCMP0021()) {
  3160. case cmPolicies::WARN: {
  3161. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  3162. messageType = MessageType::AUTHOR_WARNING;
  3163. } break;
  3164. case cmPolicies::OLD:
  3165. noMessage = true;
  3166. case cmPolicies::REQUIRED_IF_USED:
  3167. case cmPolicies::REQUIRED_ALWAYS:
  3168. case cmPolicies::NEW:
  3169. // Issue the fatal message.
  3170. break;
  3171. }
  3172. e << "Found relative path while evaluating include directories of "
  3173. "\""
  3174. << tgt->GetName() << "\":\n \"" << entryInclude << "\"\n";
  3175. }
  3176. if (!noMessage) {
  3177. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  3178. if (messageType == MessageType::FATAL_ERROR) {
  3179. return;
  3180. }
  3181. }
  3182. }
  3183. if (!cmIsOff(entryInclude)) {
  3184. cmSystemTools::ConvertToUnixSlashes(entryInclude);
  3185. }
  3186. if (uniqueIncludes.insert(entryInclude).second) {
  3187. includes.emplace_back(entryInclude, entry.Backtrace);
  3188. if (debugIncludes) {
  3189. usedIncludes += " * " + entryInclude + "\n";
  3190. }
  3191. }
  3192. }
  3193. if (!usedIncludes.empty()) {
  3194. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  3195. MessageType::LOG,
  3196. std::string("Used includes for target ") + tgt->GetName() + ":\n" +
  3197. usedIncludes,
  3198. entry.Backtrace);
  3199. }
  3200. }
  3201. }
  3202. }
  3203. std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
  3204. const std::string& config, const std::string& lang) const
  3205. {
  3206. std::vector<BT<std::string>> includes;
  3207. std::unordered_set<std::string> uniqueIncludes;
  3208. cmGeneratorExpressionDAGChecker dagChecker(this, "INCLUDE_DIRECTORIES",
  3209. nullptr, nullptr);
  3210. std::vector<std::string> debugProperties;
  3211. this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
  3212. debugProperties);
  3213. bool debugIncludes = !this->DebugIncludesDone &&
  3214. cm::contains(debugProperties, "INCLUDE_DIRECTORIES");
  3215. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3216. this->DebugIncludesDone = true;
  3217. }
  3218. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3219. this, config, lang, &dagChecker, this->IncludeDirectoriesEntries);
  3220. if (lang == "Swift") {
  3221. AddLangSpecificImplicitIncludeDirectories(
  3222. this, lang, config, "Swift_MODULE_DIRECTORY",
  3223. IncludeDirectoryFallBack::BINARY, entries);
  3224. }
  3225. if (this->CanCompileSources() && (lang != "Swift" && lang != "Fortran")) {
  3226. const std::string propertyName = "ISPC_HEADER_DIRECTORY";
  3227. // If this target has ISPC sources make sure to add the header
  3228. // directory to other compilation units
  3229. if (cm::contains(this->GetAllConfigCompileLanguages(), "ISPC")) {
  3230. if (cmValue val = this->GetProperty(propertyName)) {
  3231. includes.emplace_back(*val);
  3232. } else {
  3233. includes.emplace_back(this->GetObjectDirectory(config));
  3234. }
  3235. }
  3236. AddLangSpecificImplicitIncludeDirectories(
  3237. this, "ISPC", config, propertyName, IncludeDirectoryFallBack::OBJECT,
  3238. entries);
  3239. }
  3240. AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES", lang,
  3241. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  3242. if (this->Makefile->IsOn("APPLE")) {
  3243. if (cmLinkImplementationLibraries const* impl =
  3244. this->GetLinkImplementationLibraries(config)) {
  3245. for (cmLinkImplItem const& lib : impl->Libraries) {
  3246. std::string libDir = cmSystemTools::CollapseFullPath(
  3247. lib.AsStr(), this->Makefile->GetHomeOutputDirectory());
  3248. static cmsys::RegularExpression frameworkCheck(
  3249. "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  3250. if (!frameworkCheck.find(libDir)) {
  3251. continue;
  3252. }
  3253. libDir = frameworkCheck.match(1);
  3254. EvaluatedTargetPropertyEntry ee(lib, cmListFileBacktrace());
  3255. ee.Values.emplace_back(std::move(libDir));
  3256. entries.Entries.emplace_back(std::move(ee));
  3257. }
  3258. }
  3259. }
  3260. processIncludeDirectories(this, entries, includes, uniqueIncludes,
  3261. debugIncludes);
  3262. return includes;
  3263. }
  3264. enum class OptionsParse
  3265. {
  3266. None,
  3267. Shell
  3268. };
  3269. namespace {
  3270. const auto DL_BEGIN = "<DEVICE_LINK>"_s;
  3271. const auto DL_END = "</DEVICE_LINK>"_s;
  3272. void processOptions(cmGeneratorTarget const* tgt,
  3273. EvaluatedTargetPropertyEntries const& entries,
  3274. std::vector<BT<std::string>>& options,
  3275. std::unordered_set<std::string>& uniqueOptions,
  3276. bool debugOptions, const char* logName, OptionsParse parse,
  3277. bool processDeviceOptions = false)
  3278. {
  3279. bool splitOption = !processDeviceOptions;
  3280. for (EvaluatedTargetPropertyEntry const& entry : entries.Entries) {
  3281. std::string usedOptions;
  3282. for (std::string const& opt : entry.Values) {
  3283. if (processDeviceOptions && (opt == DL_BEGIN || opt == DL_END)) {
  3284. options.emplace_back(opt, entry.Backtrace);
  3285. splitOption = opt == DL_BEGIN;
  3286. continue;
  3287. }
  3288. if (uniqueOptions.insert(opt).second) {
  3289. if (parse == OptionsParse::Shell &&
  3290. cmHasLiteralPrefix(opt, "SHELL:")) {
  3291. if (splitOption) {
  3292. std::vector<std::string> tmp;
  3293. cmSystemTools::ParseUnixCommandLine(opt.c_str() + 6, tmp);
  3294. for (std::string& o : tmp) {
  3295. options.emplace_back(std::move(o), entry.Backtrace);
  3296. }
  3297. } else {
  3298. options.emplace_back(std::string(opt.c_str() + 6),
  3299. entry.Backtrace);
  3300. }
  3301. } else {
  3302. options.emplace_back(opt, entry.Backtrace);
  3303. }
  3304. if (debugOptions) {
  3305. usedOptions += " * " + opt + "\n";
  3306. }
  3307. }
  3308. }
  3309. if (!usedOptions.empty()) {
  3310. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  3311. MessageType::LOG,
  3312. std::string("Used ") + logName + std::string(" for target ") +
  3313. tgt->GetName() + ":\n" + usedOptions,
  3314. entry.Backtrace);
  3315. }
  3316. }
  3317. }
  3318. std::vector<BT<std::string>> wrapOptions(
  3319. std::vector<std::string>& options, const cmListFileBacktrace& bt,
  3320. const std::vector<std::string>& wrapperFlag, const std::string& wrapperSep,
  3321. bool concatFlagAndArgs)
  3322. {
  3323. std::vector<BT<std::string>> result;
  3324. if (options.empty()) {
  3325. return result;
  3326. }
  3327. if (wrapperFlag.empty()) {
  3328. // nothing specified, insert elements as is
  3329. result.reserve(options.size());
  3330. for (std::string& o : options) {
  3331. result.emplace_back(std::move(o), bt);
  3332. }
  3333. return result;
  3334. }
  3335. for (std::vector<std::string>::size_type index = 0; index < options.size();
  3336. index++) {
  3337. if (cmHasLiteralPrefix(options[index], "LINKER:")) {
  3338. // LINKER wrapper specified, insert elements as is
  3339. result.emplace_back(std::move(options[index]), bt);
  3340. continue;
  3341. }
  3342. if (cmHasLiteralPrefix(options[index], "-Wl,")) {
  3343. // replace option by LINKER wrapper
  3344. result.emplace_back(options[index].replace(0, 4, "LINKER:"), bt);
  3345. continue;
  3346. }
  3347. if (cmHasLiteralPrefix(options[index], "-Xlinker=")) {
  3348. // replace option by LINKER wrapper
  3349. result.emplace_back(options[index].replace(0, 9, "LINKER:"), bt);
  3350. continue;
  3351. }
  3352. if (options[index] == "-Xlinker") {
  3353. // replace option by LINKER wrapper
  3354. if (index + 1 < options.size()) {
  3355. result.emplace_back("LINKER:" + options[++index], bt);
  3356. } else {
  3357. result.emplace_back(std::move(options[index]), bt);
  3358. }
  3359. continue;
  3360. }
  3361. // collect all options which must be transformed
  3362. std::vector<std::string> opts;
  3363. while (index < options.size()) {
  3364. if (!cmHasLiteralPrefix(options[index], "LINKER:") &&
  3365. !cmHasLiteralPrefix(options[index], "-Wl,") &&
  3366. !cmHasLiteralPrefix(options[index], "-Xlinker")) {
  3367. opts.emplace_back(std::move(options[index++]));
  3368. } else {
  3369. --index;
  3370. break;
  3371. }
  3372. }
  3373. if (opts.empty()) {
  3374. continue;
  3375. }
  3376. if (!wrapperSep.empty()) {
  3377. if (concatFlagAndArgs) {
  3378. // insert flag elements except last one
  3379. for (auto i = wrapperFlag.begin(); i != wrapperFlag.end() - 1; ++i) {
  3380. result.emplace_back(*i, bt);
  3381. }
  3382. // concatenate last flag element and all list values
  3383. // in one option
  3384. result.emplace_back(wrapperFlag.back() + cmJoin(opts, wrapperSep), bt);
  3385. } else {
  3386. for (std::string const& i : wrapperFlag) {
  3387. result.emplace_back(i, bt);
  3388. }
  3389. // concatenate all list values in one option
  3390. result.emplace_back(cmJoin(opts, wrapperSep), bt);
  3391. }
  3392. } else {
  3393. // prefix each element of list with wrapper
  3394. if (concatFlagAndArgs) {
  3395. std::transform(opts.begin(), opts.end(), opts.begin(),
  3396. [&wrapperFlag](std::string const& o) -> std::string {
  3397. return wrapperFlag.back() + o;
  3398. });
  3399. }
  3400. for (std::string& o : opts) {
  3401. for (auto i = wrapperFlag.begin(),
  3402. e = concatFlagAndArgs ? wrapperFlag.end() - 1
  3403. : wrapperFlag.end();
  3404. i != e; ++i) {
  3405. result.emplace_back(*i, bt);
  3406. }
  3407. result.emplace_back(std::move(o), bt);
  3408. }
  3409. }
  3410. }
  3411. return result;
  3412. }
  3413. }
  3414. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
  3415. const std::string& config,
  3416. const std::string& language) const
  3417. {
  3418. std::vector<BT<std::string>> tmp = this->GetCompileOptions(config, language);
  3419. result.reserve(tmp.size());
  3420. for (BT<std::string>& v : tmp) {
  3421. result.emplace_back(std::move(v.Value));
  3422. }
  3423. }
  3424. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
  3425. std::string const& config, std::string const& language) const
  3426. {
  3427. std::vector<BT<std::string>> result;
  3428. std::unordered_set<std::string> uniqueOptions;
  3429. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_OPTIONS", nullptr,
  3430. nullptr);
  3431. std::vector<std::string> debugProperties;
  3432. this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
  3433. debugProperties);
  3434. bool debugOptions = !this->DebugCompileOptionsDone &&
  3435. cm::contains(debugProperties, "COMPILE_OPTIONS");
  3436. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3437. this->DebugCompileOptionsDone = true;
  3438. }
  3439. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3440. this, config, language, &dagChecker, this->CompileOptionsEntries);
  3441. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_OPTIONS", language,
  3442. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  3443. processOptions(this, entries, result, uniqueOptions, debugOptions,
  3444. "compile options", OptionsParse::Shell);
  3445. return result;
  3446. }
  3447. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
  3448. const std::string& config) const
  3449. {
  3450. std::vector<BT<std::string>> tmp = this->GetCompileFeatures(config);
  3451. result.reserve(tmp.size());
  3452. for (BT<std::string>& v : tmp) {
  3453. result.emplace_back(std::move(v.Value));
  3454. }
  3455. }
  3456. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
  3457. std::string const& config) const
  3458. {
  3459. std::vector<BT<std::string>> result;
  3460. std::unordered_set<std::string> uniqueFeatures;
  3461. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_FEATURES", nullptr,
  3462. nullptr);
  3463. std::vector<std::string> debugProperties;
  3464. this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
  3465. debugProperties);
  3466. bool debugFeatures = !this->DebugCompileFeaturesDone &&
  3467. cm::contains(debugProperties, "COMPILE_FEATURES");
  3468. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3469. this->DebugCompileFeaturesDone = true;
  3470. }
  3471. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3472. this, config, std::string(), &dagChecker, this->CompileFeaturesEntries);
  3473. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_FEATURES",
  3474. std::string(), &dagChecker, entries,
  3475. IncludeRuntimeInterface::Yes);
  3476. processOptions(this, entries, result, uniqueFeatures, debugFeatures,
  3477. "compile features", OptionsParse::None);
  3478. return result;
  3479. }
  3480. void cmGeneratorTarget::GetCompileDefinitions(
  3481. std::vector<std::string>& result, const std::string& config,
  3482. const std::string& language) const
  3483. {
  3484. std::vector<BT<std::string>> tmp =
  3485. this->GetCompileDefinitions(config, language);
  3486. result.reserve(tmp.size());
  3487. for (BT<std::string>& v : tmp) {
  3488. result.emplace_back(std::move(v.Value));
  3489. }
  3490. }
  3491. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
  3492. std::string const& config, std::string const& language) const
  3493. {
  3494. std::vector<BT<std::string>> list;
  3495. std::unordered_set<std::string> uniqueOptions;
  3496. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_DEFINITIONS",
  3497. nullptr, nullptr);
  3498. std::vector<std::string> debugProperties;
  3499. this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
  3500. debugProperties);
  3501. bool debugDefines = !this->DebugCompileDefinitionsDone &&
  3502. cm::contains(debugProperties, "COMPILE_DEFINITIONS");
  3503. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3504. this->DebugCompileDefinitionsDone = true;
  3505. }
  3506. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3507. this, config, language, &dagChecker, this->CompileDefinitionsEntries);
  3508. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS", language,
  3509. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  3510. if (!config.empty()) {
  3511. std::string configPropName =
  3512. "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
  3513. cmValue configProp = this->GetProperty(configPropName);
  3514. if (configProp) {
  3515. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) {
  3516. case cmPolicies::WARN: {
  3517. this->LocalGenerator->IssueMessage(
  3518. MessageType::AUTHOR_WARNING,
  3519. cmPolicies::GetPolicyWarning(cmPolicies::CMP0043));
  3520. CM_FALLTHROUGH;
  3521. }
  3522. case cmPolicies::OLD: {
  3523. std::unique_ptr<TargetPropertyEntry> entry =
  3524. CreateTargetPropertyEntry(*configProp);
  3525. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  3526. this, config, language, &dagChecker, *entry));
  3527. } break;
  3528. case cmPolicies::NEW:
  3529. case cmPolicies::REQUIRED_ALWAYS:
  3530. case cmPolicies::REQUIRED_IF_USED:
  3531. break;
  3532. }
  3533. }
  3534. }
  3535. processOptions(this, entries, list, uniqueOptions, debugDefines,
  3536. "compile definitions", OptionsParse::None);
  3537. return list;
  3538. }
  3539. std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders(
  3540. const std::string& config, const std::string& language) const
  3541. {
  3542. std::unordered_set<std::string> uniqueOptions;
  3543. cmGeneratorExpressionDAGChecker dagChecker(this, "PRECOMPILE_HEADERS",
  3544. nullptr, nullptr);
  3545. std::vector<std::string> debugProperties;
  3546. this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
  3547. debugProperties);
  3548. bool debugDefines = !this->DebugPrecompileHeadersDone &&
  3549. std::find(debugProperties.begin(), debugProperties.end(),
  3550. "PRECOMPILE_HEADERS") != debugProperties.end();
  3551. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3552. this->DebugPrecompileHeadersDone = true;
  3553. }
  3554. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3555. this, config, language, &dagChecker, this->PrecompileHeadersEntries);
  3556. AddInterfaceEntries(this, config, "INTERFACE_PRECOMPILE_HEADERS", language,
  3557. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  3558. std::vector<BT<std::string>> list;
  3559. processOptions(this, entries, list, uniqueOptions, debugDefines,
  3560. "precompile headers", OptionsParse::None);
  3561. return list;
  3562. }
  3563. std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
  3564. const std::string& language,
  3565. const std::string& arch) const
  3566. {
  3567. if (language != "C" && language != "CXX" && language != "OBJC" &&
  3568. language != "OBJCXX") {
  3569. return std::string();
  3570. }
  3571. if (this->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) {
  3572. return std::string();
  3573. }
  3574. const cmGeneratorTarget* generatorTarget = this;
  3575. cmValue pchReuseFrom =
  3576. generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
  3577. const auto inserted =
  3578. this->PchHeaders.insert(std::make_pair(language + config + arch, ""));
  3579. if (inserted.second) {
  3580. const std::vector<BT<std::string>> headers =
  3581. this->GetPrecompileHeaders(config, language);
  3582. if (headers.empty() && !pchReuseFrom) {
  3583. return std::string();
  3584. }
  3585. std::string& filename = inserted.first->second;
  3586. if (pchReuseFrom) {
  3587. generatorTarget =
  3588. this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
  3589. }
  3590. filename = cmStrCat(
  3591. generatorTarget->LocalGenerator->GetCurrentBinaryDirectory(), "/");
  3592. const std::map<std::string, std::string> languageToExtension = {
  3593. { "C", ".h" },
  3594. { "CXX", ".hxx" },
  3595. { "OBJC", ".objc.h" },
  3596. { "OBJCXX", ".objcxx.hxx" }
  3597. };
  3598. filename =
  3599. cmStrCat(filename, "CMakeFiles/", generatorTarget->GetName(), ".dir");
  3600. if (this->GetGlobalGenerator()->IsMultiConfig()) {
  3601. filename = cmStrCat(filename, "/", config);
  3602. }
  3603. filename =
  3604. cmStrCat(filename, "/cmake_pch", arch.empty() ? "" : cmStrCat("_", arch),
  3605. languageToExtension.at(language));
  3606. const std::string filename_tmp = cmStrCat(filename, ".tmp");
  3607. if (!pchReuseFrom) {
  3608. cmValue pchPrologue =
  3609. this->Makefile->GetDefinition("CMAKE_PCH_PROLOGUE");
  3610. cmValue pchEpilogue =
  3611. this->Makefile->GetDefinition("CMAKE_PCH_EPILOGUE");
  3612. std::string firstHeaderOnDisk;
  3613. {
  3614. cmGeneratedFileStream file(
  3615. filename_tmp, false,
  3616. this->GetGlobalGenerator()->GetMakefileEncoding());
  3617. file << "/* generated by CMake */\n\n";
  3618. if (pchPrologue) {
  3619. file << *pchPrologue << "\n";
  3620. }
  3621. if (this->GetGlobalGenerator()->IsXcode()) {
  3622. file << "#ifndef CMAKE_SKIP_PRECOMPILE_HEADERS\n";
  3623. }
  3624. if (language == "CXX" && !this->GetGlobalGenerator()->IsXcode()) {
  3625. file << "#ifdef __cplusplus\n";
  3626. }
  3627. for (auto const& header_bt : headers) {
  3628. if (header_bt.Value.empty()) {
  3629. continue;
  3630. }
  3631. if (header_bt.Value[0] == '<' || header_bt.Value[0] == '\"') {
  3632. file << "#include " << header_bt.Value << "\n";
  3633. } else {
  3634. file << "#include \"" << header_bt.Value << "\"\n";
  3635. }
  3636. if (cmSystemTools::FileExists(header_bt.Value) &&
  3637. firstHeaderOnDisk.empty()) {
  3638. firstHeaderOnDisk = header_bt.Value;
  3639. }
  3640. }
  3641. if (language == "CXX" && !this->GetGlobalGenerator()->IsXcode()) {
  3642. file << "#endif // __cplusplus\n";
  3643. }
  3644. if (this->GetGlobalGenerator()->IsXcode()) {
  3645. file << "#endif // CMAKE_SKIP_PRECOMPILE_HEADERS\n";
  3646. }
  3647. if (pchEpilogue) {
  3648. file << *pchEpilogue << "\n";
  3649. }
  3650. }
  3651. if (!firstHeaderOnDisk.empty()) {
  3652. cmFileTimes::Copy(firstHeaderOnDisk, filename_tmp);
  3653. }
  3654. cmSystemTools::MoveFileIfDifferent(filename_tmp, filename);
  3655. }
  3656. }
  3657. return inserted.first->second;
  3658. }
  3659. std::string cmGeneratorTarget::GetPchSource(const std::string& config,
  3660. const std::string& language,
  3661. const std::string& arch) const
  3662. {
  3663. if (language != "C" && language != "CXX" && language != "OBJC" &&
  3664. language != "OBJCXX") {
  3665. return std::string();
  3666. }
  3667. const auto inserted =
  3668. this->PchSources.insert(std::make_pair(language + config + arch, ""));
  3669. if (inserted.second) {
  3670. const std::string pchHeader = this->GetPchHeader(config, language, arch);
  3671. if (pchHeader.empty()) {
  3672. return std::string();
  3673. }
  3674. std::string& filename = inserted.first->second;
  3675. const cmGeneratorTarget* generatorTarget = this;
  3676. cmValue pchReuseFrom =
  3677. generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
  3678. if (pchReuseFrom) {
  3679. generatorTarget =
  3680. this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
  3681. }
  3682. filename =
  3683. cmStrCat(generatorTarget->LocalGenerator->GetCurrentBinaryDirectory(),
  3684. "/CMakeFiles/", generatorTarget->GetName(), ".dir/cmake_pch");
  3685. // For GCC the source extension will be transformed into .h[xx].gch
  3686. if (!this->Makefile->IsOn("CMAKE_LINK_PCH")) {
  3687. const std::map<std::string, std::string> languageToExtension = {
  3688. { "C", ".h.c" },
  3689. { "CXX", ".hxx.cxx" },
  3690. { "OBJC", ".objc.h.m" },
  3691. { "OBJCXX", ".objcxx.hxx.mm" }
  3692. };
  3693. filename = cmStrCat(filename, arch.empty() ? "" : cmStrCat("_", arch),
  3694. languageToExtension.at(language));
  3695. } else {
  3696. const std::map<std::string, std::string> languageToExtension = {
  3697. { "C", ".c" }, { "CXX", ".cxx" }, { "OBJC", ".m" }, { "OBJCXX", ".mm" }
  3698. };
  3699. filename = cmStrCat(filename, arch.empty() ? "" : cmStrCat("_", arch),
  3700. languageToExtension.at(language));
  3701. }
  3702. const std::string filename_tmp = cmStrCat(filename, ".tmp");
  3703. if (!pchReuseFrom) {
  3704. {
  3705. cmGeneratedFileStream file(filename_tmp);
  3706. file << "/* generated by CMake */\n";
  3707. }
  3708. cmFileTimes::Copy(pchHeader, filename_tmp);
  3709. cmSystemTools::MoveFileIfDifferent(filename_tmp, filename);
  3710. }
  3711. }
  3712. return inserted.first->second;
  3713. }
  3714. std::string cmGeneratorTarget::GetPchFileObject(const std::string& config,
  3715. const std::string& language,
  3716. const std::string& arch)
  3717. {
  3718. if (language != "C" && language != "CXX" && language != "OBJC" &&
  3719. language != "OBJCXX") {
  3720. return std::string();
  3721. }
  3722. const auto inserted =
  3723. this->PchObjectFiles.insert(std::make_pair(language + config + arch, ""));
  3724. if (inserted.second) {
  3725. const std::string pchSource = this->GetPchSource(config, language, arch);
  3726. if (pchSource.empty()) {
  3727. return std::string();
  3728. }
  3729. std::string& filename = inserted.first->second;
  3730. auto* pchSf = this->Makefile->GetOrCreateSource(
  3731. pchSource, false, cmSourceFileLocationKind::Known);
  3732. filename = cmStrCat(this->ObjectDirectory, this->GetObjectName(pchSf));
  3733. if (this->GetGlobalGenerator()->IsMultiConfig()) {
  3734. cmSystemTools::ReplaceString(
  3735. filename, this->GetGlobalGenerator()->GetCMakeCFGIntDir(), config);
  3736. }
  3737. }
  3738. return inserted.first->second;
  3739. }
  3740. std::string cmGeneratorTarget::GetPchFile(const std::string& config,
  3741. const std::string& language,
  3742. const std::string& arch)
  3743. {
  3744. const auto inserted =
  3745. this->PchFiles.insert(std::make_pair(language + config + arch, ""));
  3746. if (inserted.second) {
  3747. std::string& pchFile = inserted.first->second;
  3748. const std::string pchExtension =
  3749. this->Makefile->GetSafeDefinition("CMAKE_PCH_EXTENSION");
  3750. if (this->Makefile->IsOn("CMAKE_LINK_PCH")) {
  3751. auto replaceExtension = [](const std::string& str,
  3752. const std::string& ext) -> std::string {
  3753. auto dot_pos = str.rfind('.');
  3754. std::string result;
  3755. if (dot_pos != std::string::npos) {
  3756. result = str.substr(0, dot_pos);
  3757. }
  3758. result += ext;
  3759. return result;
  3760. };
  3761. cmGeneratorTarget* generatorTarget = this;
  3762. cmValue pchReuseFrom =
  3763. generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
  3764. if (pchReuseFrom) {
  3765. generatorTarget =
  3766. this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
  3767. }
  3768. const std::string pchFileObject =
  3769. generatorTarget->GetPchFileObject(config, language, arch);
  3770. if (!pchExtension.empty()) {
  3771. pchFile = replaceExtension(pchFileObject, pchExtension);
  3772. }
  3773. } else {
  3774. pchFile = this->GetPchHeader(config, language, arch);
  3775. pchFile += pchExtension;
  3776. }
  3777. }
  3778. return inserted.first->second;
  3779. }
  3780. std::string cmGeneratorTarget::GetPchCreateCompileOptions(
  3781. const std::string& config, const std::string& language,
  3782. const std::string& arch)
  3783. {
  3784. const auto inserted = this->PchCreateCompileOptions.insert(
  3785. std::make_pair(language + config + arch, ""));
  3786. if (inserted.second) {
  3787. std::string& createOptionList = inserted.first->second;
  3788. if (this->GetPropertyAsBool("PCH_WARN_INVALID")) {
  3789. createOptionList = this->Makefile->GetSafeDefinition(
  3790. cmStrCat("CMAKE_", language, "_COMPILE_OPTIONS_INVALID_PCH"));
  3791. }
  3792. if (this->GetPropertyAsBool("PCH_INSTANTIATE_TEMPLATES")) {
  3793. std::string varName = cmStrCat(
  3794. "CMAKE_", language, "_COMPILE_OPTIONS_INSTANTIATE_TEMPLATES_PCH");
  3795. std::string instantiateOption =
  3796. this->Makefile->GetSafeDefinition(varName);
  3797. if (!instantiateOption.empty()) {
  3798. createOptionList = cmStrCat(createOptionList, ";", instantiateOption);
  3799. }
  3800. }
  3801. const std::string createOptVar =
  3802. cmStrCat("CMAKE_", language, "_COMPILE_OPTIONS_CREATE_PCH");
  3803. createOptionList = cmStrCat(
  3804. createOptionList, ";", this->Makefile->GetSafeDefinition(createOptVar));
  3805. const std::string pchHeader = this->GetPchHeader(config, language, arch);
  3806. const std::string pchFile = this->GetPchFile(config, language, arch);
  3807. cmSystemTools::ReplaceString(createOptionList, "<PCH_HEADER>", pchHeader);
  3808. cmSystemTools::ReplaceString(createOptionList, "<PCH_FILE>", pchFile);
  3809. }
  3810. return inserted.first->second;
  3811. }
  3812. std::string cmGeneratorTarget::GetPchUseCompileOptions(
  3813. const std::string& config, const std::string& language,
  3814. const std::string& arch)
  3815. {
  3816. const auto inserted = this->PchUseCompileOptions.insert(
  3817. std::make_pair(language + config + arch, ""));
  3818. if (inserted.second) {
  3819. std::string& useOptionList = inserted.first->second;
  3820. if (this->GetPropertyAsBool("PCH_WARN_INVALID")) {
  3821. useOptionList = this->Makefile->GetSafeDefinition(
  3822. cmStrCat("CMAKE_", language, "_COMPILE_OPTIONS_INVALID_PCH"));
  3823. }
  3824. const std::string useOptVar =
  3825. cmStrCat(language, "_COMPILE_OPTIONS_USE_PCH");
  3826. std::string const& useOptionListProperty =
  3827. this->GetSafeProperty(useOptVar);
  3828. useOptionList = cmStrCat(
  3829. useOptionList, ";",
  3830. useOptionListProperty.empty()
  3831. ? this->Makefile->GetSafeDefinition(cmStrCat("CMAKE_", useOptVar))
  3832. : useOptionListProperty);
  3833. const std::string pchHeader = this->GetPchHeader(config, language, arch);
  3834. const std::string pchFile = this->GetPchFile(config, language, arch);
  3835. cmSystemTools::ReplaceString(useOptionList, "<PCH_HEADER>", pchHeader);
  3836. cmSystemTools::ReplaceString(useOptionList, "<PCH_FILE>", pchFile);
  3837. }
  3838. return inserted.first->second;
  3839. }
  3840. void cmGeneratorTarget::AddSourceFileToUnityBatch(
  3841. const std::string& sourceFilename)
  3842. {
  3843. this->UnityBatchedSourceFiles.insert(sourceFilename);
  3844. }
  3845. bool cmGeneratorTarget::IsSourceFilePartOfUnityBatch(
  3846. const std::string& sourceFilename) const
  3847. {
  3848. if (!this->GetPropertyAsBool("UNITY_BUILD")) {
  3849. return false;
  3850. }
  3851. return this->UnityBatchedSourceFiles.find(sourceFilename) !=
  3852. this->UnityBatchedSourceFiles.end();
  3853. }
  3854. void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
  3855. const std::string& config,
  3856. const std::string& language) const
  3857. {
  3858. if (this->IsDeviceLink() &&
  3859. this->GetPolicyStatusCMP0105() != cmPolicies::NEW) {
  3860. // link options are not propagated to the device link step
  3861. return;
  3862. }
  3863. std::vector<BT<std::string>> tmp = this->GetLinkOptions(config, language);
  3864. result.reserve(tmp.size());
  3865. for (BT<std::string>& v : tmp) {
  3866. result.emplace_back(std::move(v.Value));
  3867. }
  3868. }
  3869. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
  3870. std::string const& config, std::string const& language) const
  3871. {
  3872. std::vector<BT<std::string>> result;
  3873. std::unordered_set<std::string> uniqueOptions;
  3874. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_OPTIONS", nullptr,
  3875. nullptr);
  3876. std::vector<std::string> debugProperties;
  3877. this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
  3878. debugProperties);
  3879. bool debugOptions = !this->DebugLinkOptionsDone &&
  3880. cm::contains(debugProperties, "LINK_OPTIONS");
  3881. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3882. this->DebugLinkOptionsDone = true;
  3883. }
  3884. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3885. this, config, language, &dagChecker, this->LinkOptionsEntries);
  3886. AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS", language,
  3887. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  3888. this->GetPolicyStatusCMP0099() != cmPolicies::NEW);
  3889. processOptions(this, entries, result, uniqueOptions, debugOptions,
  3890. "link options", OptionsParse::Shell, this->IsDeviceLink());
  3891. if (this->IsDeviceLink()) {
  3892. // wrap host link options
  3893. const std::string wrapper(this->Makefile->GetSafeDefinition(
  3894. "CMAKE_" + language + "_DEVICE_COMPILER_WRAPPER_FLAG"));
  3895. std::vector<std::string> wrapperFlag = cmExpandedList(wrapper);
  3896. const std::string wrapperSep(this->Makefile->GetSafeDefinition(
  3897. "CMAKE_" + language + "_DEVICE_COMPILER_WRAPPER_FLAG_SEP"));
  3898. bool concatFlagAndArgs = true;
  3899. if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
  3900. concatFlagAndArgs = false;
  3901. wrapperFlag.pop_back();
  3902. }
  3903. auto it = result.begin();
  3904. while (it != result.end()) {
  3905. if (it->Value == DL_BEGIN) {
  3906. // device link options, no treatment
  3907. it = result.erase(it);
  3908. it = std::find_if(it, result.end(), [](const BT<std::string>& item) {
  3909. return item.Value == DL_END;
  3910. });
  3911. if (it != result.end()) {
  3912. it = result.erase(it);
  3913. }
  3914. } else {
  3915. // host link options must be wrapped
  3916. std::vector<std::string> options;
  3917. cmSystemTools::ParseUnixCommandLine(it->Value.c_str(), options);
  3918. auto hostOptions = wrapOptions(options, it->Backtrace, wrapperFlag,
  3919. wrapperSep, concatFlagAndArgs);
  3920. it = result.erase(it);
  3921. // some compilers (like gcc 4.8 or Intel 19.0 or XLC 16) do not respect
  3922. // C++11 standard: 'std::vector::insert()' do not returns an iterator,
  3923. // so need to recompute the iterator after insertion.
  3924. if (it == result.end()) {
  3925. cm::append(result, hostOptions);
  3926. it = result.end();
  3927. } else {
  3928. auto index = it - result.begin();
  3929. result.insert(it, hostOptions.begin(), hostOptions.end());
  3930. it = result.begin() + index + hostOptions.size();
  3931. }
  3932. }
  3933. }
  3934. }
  3935. // Last step: replace "LINKER:" prefixed elements by
  3936. // actual linker wrapper
  3937. return this->ResolveLinkerWrapper(result, language);
  3938. }
  3939. std::vector<BT<std::string>>& cmGeneratorTarget::ResolveLinkerWrapper(
  3940. std::vector<BT<std::string>>& result, const std::string& language) const
  3941. {
  3942. // replace "LINKER:" prefixed elements by actual linker wrapper
  3943. const std::string wrapper(this->Makefile->GetSafeDefinition(
  3944. "CMAKE_" + language +
  3945. (this->IsDeviceLink() ? "_DEVICE_LINKER_WRAPPER_FLAG"
  3946. : "_LINKER_WRAPPER_FLAG")));
  3947. std::vector<std::string> wrapperFlag = cmExpandedList(wrapper);
  3948. const std::string wrapperSep(this->Makefile->GetSafeDefinition(
  3949. "CMAKE_" + language +
  3950. (this->IsDeviceLink() ? "_DEVICE_LINKER_WRAPPER_FLAG_SEP"
  3951. : "_LINKER_WRAPPER_FLAG_SEP")));
  3952. bool concatFlagAndArgs = true;
  3953. if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
  3954. concatFlagAndArgs = false;
  3955. wrapperFlag.pop_back();
  3956. }
  3957. const std::string LINKER{ "LINKER:" };
  3958. const std::string SHELL{ "SHELL:" };
  3959. const std::string LINKER_SHELL = LINKER + SHELL;
  3960. std::vector<BT<std::string>>::iterator entry;
  3961. while ((entry = std::find_if(result.begin(), result.end(),
  3962. [&LINKER](BT<std::string> const& item) -> bool {
  3963. return item.Value.compare(0, LINKER.length(),
  3964. LINKER) == 0;
  3965. })) != result.end()) {
  3966. std::string value = std::move(entry->Value);
  3967. cmListFileBacktrace bt = std::move(entry->Backtrace);
  3968. entry = result.erase(entry);
  3969. std::vector<std::string> linkerOptions;
  3970. if (value.compare(0, LINKER_SHELL.length(), LINKER_SHELL) == 0) {
  3971. cmSystemTools::ParseUnixCommandLine(
  3972. value.c_str() + LINKER_SHELL.length(), linkerOptions);
  3973. } else {
  3974. linkerOptions = cmTokenize(value.substr(LINKER.length()), ",");
  3975. }
  3976. if (linkerOptions.empty() ||
  3977. (linkerOptions.size() == 1 && linkerOptions.front().empty())) {
  3978. continue;
  3979. }
  3980. // for now, raise an error if prefix SHELL: is part of arguments
  3981. if (std::find_if(linkerOptions.begin(), linkerOptions.end(),
  3982. [&SHELL](const std::string& item) -> bool {
  3983. return item.find(SHELL) != std::string::npos;
  3984. }) != linkerOptions.end()) {
  3985. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  3986. MessageType::FATAL_ERROR,
  3987. "'SHELL:' prefix is not supported as part of 'LINKER:' arguments.",
  3988. this->GetBacktrace());
  3989. return result;
  3990. }
  3991. std::vector<BT<std::string>> options = wrapOptions(
  3992. linkerOptions, bt, wrapperFlag, wrapperSep, concatFlagAndArgs);
  3993. result.insert(entry, options.begin(), options.end());
  3994. }
  3995. return result;
  3996. }
  3997. void cmGeneratorTarget::GetStaticLibraryLinkOptions(
  3998. std::vector<std::string>& result, const std::string& config,
  3999. const std::string& language) const
  4000. {
  4001. std::vector<BT<std::string>> tmp =
  4002. this->GetStaticLibraryLinkOptions(config, language);
  4003. result.reserve(tmp.size());
  4004. for (BT<std::string>& v : tmp) {
  4005. result.emplace_back(std::move(v.Value));
  4006. }
  4007. }
  4008. std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
  4009. std::string const& config, std::string const& language) const
  4010. {
  4011. std::vector<BT<std::string>> result;
  4012. std::unordered_set<std::string> uniqueOptions;
  4013. cmGeneratorExpressionDAGChecker dagChecker(this, "STATIC_LIBRARY_OPTIONS",
  4014. nullptr, nullptr);
  4015. EvaluatedTargetPropertyEntries entries;
  4016. if (cmValue linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
  4017. std::vector<std::string> options = cmExpandedList(*linkOptions);
  4018. for (const auto& option : options) {
  4019. std::unique_ptr<TargetPropertyEntry> entry =
  4020. CreateTargetPropertyEntry(option);
  4021. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  4022. this, config, language, &dagChecker, *entry));
  4023. }
  4024. }
  4025. processOptions(this, entries, result, uniqueOptions, false,
  4026. "static library link options", OptionsParse::Shell);
  4027. return result;
  4028. }
  4029. namespace {
  4030. void processLinkDirectories(cmGeneratorTarget const* tgt,
  4031. EvaluatedTargetPropertyEntries& entries,
  4032. std::vector<BT<std::string>>& directories,
  4033. std::unordered_set<std::string>& uniqueDirectories,
  4034. bool debugDirectories)
  4035. {
  4036. for (EvaluatedTargetPropertyEntry& entry : entries.Entries) {
  4037. cmLinkImplItem const& item = entry.LinkImplItem;
  4038. std::string const& targetName = item.AsStr();
  4039. std::string usedDirectories;
  4040. for (std::string& entryDirectory : entry.Values) {
  4041. if (!cmSystemTools::FileIsFullPath(entryDirectory)) {
  4042. std::ostringstream e;
  4043. bool noMessage = false;
  4044. MessageType messageType = MessageType::FATAL_ERROR;
  4045. if (!targetName.empty()) {
  4046. /* clang-format off */
  4047. e << "Target \"" << targetName << "\" contains relative "
  4048. "path in its INTERFACE_LINK_DIRECTORIES:\n"
  4049. " \"" << entryDirectory << "\"";
  4050. /* clang-format on */
  4051. } else {
  4052. switch (tgt->GetPolicyStatusCMP0081()) {
  4053. case cmPolicies::WARN: {
  4054. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0081) << "\n";
  4055. messageType = MessageType::AUTHOR_WARNING;
  4056. } break;
  4057. case cmPolicies::OLD:
  4058. noMessage = true;
  4059. break;
  4060. case cmPolicies::REQUIRED_IF_USED:
  4061. case cmPolicies::REQUIRED_ALWAYS:
  4062. case cmPolicies::NEW:
  4063. // Issue the fatal message.
  4064. break;
  4065. }
  4066. e << "Found relative path while evaluating link directories of "
  4067. "\""
  4068. << tgt->GetName() << "\":\n \"" << entryDirectory << "\"\n";
  4069. }
  4070. if (!noMessage) {
  4071. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  4072. if (messageType == MessageType::FATAL_ERROR) {
  4073. return;
  4074. }
  4075. }
  4076. }
  4077. // Sanitize the path the same way the link_directories command does
  4078. // in case projects set the LINK_DIRECTORIES property directly.
  4079. cmSystemTools::ConvertToUnixSlashes(entryDirectory);
  4080. if (uniqueDirectories.insert(entryDirectory).second) {
  4081. directories.emplace_back(entryDirectory, entry.Backtrace);
  4082. if (debugDirectories) {
  4083. usedDirectories += " * " + entryDirectory + "\n";
  4084. }
  4085. }
  4086. }
  4087. if (!usedDirectories.empty()) {
  4088. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  4089. MessageType::LOG,
  4090. std::string("Used link directories for target ") + tgt->GetName() +
  4091. ":\n" + usedDirectories,
  4092. entry.Backtrace);
  4093. }
  4094. }
  4095. }
  4096. }
  4097. void cmGeneratorTarget::GetLinkDirectories(std::vector<std::string>& result,
  4098. const std::string& config,
  4099. const std::string& language) const
  4100. {
  4101. std::vector<BT<std::string>> tmp =
  4102. this->GetLinkDirectories(config, language);
  4103. result.reserve(tmp.size());
  4104. for (BT<std::string>& v : tmp) {
  4105. result.emplace_back(std::move(v.Value));
  4106. }
  4107. }
  4108. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
  4109. std::string const& config, std::string const& language) const
  4110. {
  4111. std::vector<BT<std::string>> result;
  4112. std::unordered_set<std::string> uniqueDirectories;
  4113. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DIRECTORIES", nullptr,
  4114. nullptr);
  4115. std::vector<std::string> debugProperties;
  4116. this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
  4117. debugProperties);
  4118. bool debugDirectories = !this->DebugLinkDirectoriesDone &&
  4119. cm::contains(debugProperties, "LINK_DIRECTORIES");
  4120. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  4121. this->DebugLinkDirectoriesDone = true;
  4122. }
  4123. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  4124. this, config, language, &dagChecker, this->LinkDirectoriesEntries);
  4125. AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES", language,
  4126. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  4127. this->GetPolicyStatusCMP0099() != cmPolicies::NEW);
  4128. processLinkDirectories(this, entries, result, uniqueDirectories,
  4129. debugDirectories);
  4130. return result;
  4131. }
  4132. void cmGeneratorTarget::GetLinkDepends(std::vector<std::string>& result,
  4133. const std::string& config,
  4134. const std::string& language) const
  4135. {
  4136. std::vector<BT<std::string>> tmp = this->GetLinkDepends(config, language);
  4137. result.reserve(tmp.size());
  4138. for (BT<std::string>& v : tmp) {
  4139. result.emplace_back(std::move(v.Value));
  4140. }
  4141. }
  4142. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
  4143. std::string const& config, std::string const& language) const
  4144. {
  4145. std::vector<BT<std::string>> result;
  4146. std::unordered_set<std::string> uniqueOptions;
  4147. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DEPENDS", nullptr,
  4148. nullptr);
  4149. EvaluatedTargetPropertyEntries entries;
  4150. if (cmValue linkDepends = this->GetProperty("LINK_DEPENDS")) {
  4151. std::vector<std::string> depends = cmExpandedList(*linkDepends);
  4152. for (const auto& depend : depends) {
  4153. std::unique_ptr<TargetPropertyEntry> entry =
  4154. CreateTargetPropertyEntry(depend);
  4155. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  4156. this, config, language, &dagChecker, *entry));
  4157. }
  4158. }
  4159. AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language,
  4160. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  4161. this->GetPolicyStatusCMP0099() != cmPolicies::NEW);
  4162. processOptions(this, entries, result, uniqueOptions, false, "link depends",
  4163. OptionsParse::None);
  4164. return result;
  4165. }
  4166. void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
  4167. {
  4168. if (this->IsImported()) {
  4169. return;
  4170. }
  4171. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  4172. // Get the names.
  4173. cmGeneratorTarget::Names targetNames;
  4174. if (this->GetType() == cmStateEnums::EXECUTABLE) {
  4175. targetNames = this->GetExecutableNames(config);
  4176. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  4177. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4178. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  4179. targetNames = this->GetLibraryNames(config);
  4180. } else {
  4181. return;
  4182. }
  4183. // Get the directory.
  4184. std::string dir =
  4185. this->GetDirectory(config, cmStateEnums::RuntimeBinaryArtifact);
  4186. // Add each name.
  4187. std::string f;
  4188. if (!targetNames.Output.empty()) {
  4189. f = cmStrCat(dir, '/', targetNames.Output);
  4190. gg->AddToManifest(f);
  4191. }
  4192. if (!targetNames.SharedObject.empty()) {
  4193. f = cmStrCat(dir, '/', targetNames.SharedObject);
  4194. gg->AddToManifest(f);
  4195. }
  4196. if (!targetNames.Real.empty()) {
  4197. f = cmStrCat(dir, '/', targetNames.Real);
  4198. gg->AddToManifest(f);
  4199. }
  4200. if (!targetNames.PDB.empty()) {
  4201. f = cmStrCat(dir, '/', targetNames.PDB);
  4202. gg->AddToManifest(f);
  4203. }
  4204. if (!targetNames.ImportLibrary.empty()) {
  4205. f =
  4206. cmStrCat(this->GetDirectory(config, cmStateEnums::ImportLibraryArtifact),
  4207. '/', targetNames.ImportLibrary);
  4208. gg->AddToManifest(f);
  4209. }
  4210. }
  4211. bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config) const
  4212. {
  4213. // Compute the language standard based on the compile features.
  4214. cmStandardLevelResolver standardResolver(this->Makefile);
  4215. std::vector<BT<std::string>> features = this->GetCompileFeatures(config);
  4216. for (BT<std::string> const& f : features) {
  4217. std::string lang;
  4218. if (!standardResolver.CompileFeatureKnown(this->Target->GetName(), f.Value,
  4219. lang, nullptr)) {
  4220. return false;
  4221. }
  4222. std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang);
  4223. cmValue currentLanguageStandard = this->GetLanguageStandard(lang, config);
  4224. std::string newRequiredStandard;
  4225. if (!standardResolver.GetNewRequiredStandard(
  4226. this->Target->GetName(), f.Value, currentLanguageStandard,
  4227. newRequiredStandard)) {
  4228. return false;
  4229. }
  4230. if (!newRequiredStandard.empty()) {
  4231. BTs<std::string>& languageStandardProperty =
  4232. this->LanguageStandardMap[key];
  4233. if (languageStandardProperty.Value != newRequiredStandard) {
  4234. languageStandardProperty.Value = newRequiredStandard;
  4235. languageStandardProperty.Backtraces.clear();
  4236. }
  4237. languageStandardProperty.Backtraces.emplace_back(f.Backtrace);
  4238. }
  4239. }
  4240. return true;
  4241. }
  4242. bool cmGeneratorTarget::ComputeCompileFeatures(
  4243. std::string const& config, std::set<LanguagePair> const& languagePairs) const
  4244. {
  4245. for (const auto& language : languagePairs) {
  4246. BTs<std::string> const* generatorTargetLanguageStandard =
  4247. this->GetLanguageStandardProperty(language.first, config);
  4248. if (!generatorTargetLanguageStandard) {
  4249. // If the standard isn't explicitly set we copy it over from the
  4250. // specified paired language.
  4251. std::string key =
  4252. cmStrCat(cmSystemTools::UpperCase(config), '-', language.first);
  4253. BTs<std::string> const* standardToCopy =
  4254. this->GetLanguageStandardProperty(language.second, config);
  4255. if (standardToCopy) {
  4256. this->LanguageStandardMap[key] = *standardToCopy;
  4257. generatorTargetLanguageStandard = &this->LanguageStandardMap[key];
  4258. } else {
  4259. cmValue defaultStandard = this->Makefile->GetDefinition(
  4260. cmStrCat("CMAKE_", language.second, "_STANDARD_DEFAULT"));
  4261. if (defaultStandard) {
  4262. this->LanguageStandardMap[key] = BTs<std::string>(*defaultStandard);
  4263. generatorTargetLanguageStandard = &this->LanguageStandardMap[key];
  4264. }
  4265. }
  4266. // Custom updates for the CUDA standard.
  4267. if (generatorTargetLanguageStandard != nullptr &&
  4268. (language.first == "CUDA")) {
  4269. if (generatorTargetLanguageStandard->Value == "98") {
  4270. this->LanguageStandardMap[key].Value = "03";
  4271. }
  4272. }
  4273. }
  4274. }
  4275. return true;
  4276. }
  4277. std::string cmGeneratorTarget::GetImportedLibName(
  4278. std::string const& config) const
  4279. {
  4280. if (cmGeneratorTarget::ImportInfo const* info =
  4281. this->GetImportInfo(config)) {
  4282. return info->LibName;
  4283. }
  4284. return std::string();
  4285. }
  4286. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  4287. cmStateEnums::ArtifactType artifact,
  4288. bool realname) const
  4289. {
  4290. if (this->IsImported()) {
  4291. return this->Target->ImportedGetFullPath(config, artifact);
  4292. }
  4293. return this->NormalGetFullPath(config, artifact, realname);
  4294. }
  4295. std::string cmGeneratorTarget::NormalGetFullPath(
  4296. const std::string& config, cmStateEnums::ArtifactType artifact,
  4297. bool realname) const
  4298. {
  4299. std::string fpath = cmStrCat(this->GetDirectory(config, artifact), '/');
  4300. if (this->IsAppBundleOnApple()) {
  4301. fpath =
  4302. cmStrCat(this->BuildBundleDirectory(fpath, config, FullLevel), '/');
  4303. }
  4304. // Add the full name of the target.
  4305. switch (artifact) {
  4306. case cmStateEnums::RuntimeBinaryArtifact:
  4307. if (realname) {
  4308. fpath += this->NormalGetRealName(config);
  4309. } else {
  4310. fpath +=
  4311. this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact);
  4312. }
  4313. break;
  4314. case cmStateEnums::ImportLibraryArtifact:
  4315. fpath += this->GetFullName(config, cmStateEnums::ImportLibraryArtifact);
  4316. break;
  4317. }
  4318. return fpath;
  4319. }
  4320. std::string cmGeneratorTarget::NormalGetRealName(
  4321. const std::string& config) const
  4322. {
  4323. // This should not be called for imported targets.
  4324. // TODO: Split cmTarget into a class hierarchy to get compile-time
  4325. // enforcement of the limited imported target API.
  4326. if (this->IsImported()) {
  4327. std::string msg = cmStrCat("NormalGetRealName called on imported target: ",
  4328. this->GetName());
  4329. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  4330. }
  4331. if (this->GetType() == cmStateEnums::EXECUTABLE) {
  4332. // Compute the real name that will be built.
  4333. return this->GetExecutableNames(config).Real;
  4334. }
  4335. // Compute the real name that will be built.
  4336. return this->GetLibraryNames(config).Real;
  4337. }
  4338. cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames(
  4339. const std::string& config) const
  4340. {
  4341. cmGeneratorTarget::Names targetNames;
  4342. // This should not be called for imported targets.
  4343. // TODO: Split cmTarget into a class hierarchy to get compile-time
  4344. // enforcement of the limited imported target API.
  4345. if (this->IsImported()) {
  4346. std::string msg =
  4347. cmStrCat("GetLibraryNames called on imported target: ", this->GetName());
  4348. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  4349. }
  4350. // Check for library version properties.
  4351. cmValue version = this->GetProperty("VERSION");
  4352. cmValue soversion = this->GetProperty("SOVERSION");
  4353. if (!this->HasSOName(config) ||
  4354. this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
  4355. this->IsFrameworkOnApple()) {
  4356. // Versioning is supported only for shared libraries and modules,
  4357. // and then only when the platform supports an soname flag.
  4358. version = nullptr;
  4359. soversion = nullptr;
  4360. }
  4361. if (version && !soversion) {
  4362. // The soversion must be set if the library version is set. Use
  4363. // the library version as the soversion.
  4364. soversion = version;
  4365. }
  4366. if (!version && soversion) {
  4367. // Use the soversion as the library version.
  4368. version = soversion;
  4369. }
  4370. // Get the components of the library name.
  4371. std::string prefix;
  4372. std::string suffix;
  4373. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  4374. prefix, targetNames.Base, suffix);
  4375. // The library name.
  4376. targetNames.Output = prefix + targetNames.Base + suffix;
  4377. if (this->IsFrameworkOnApple()) {
  4378. targetNames.Real = prefix;
  4379. if (!this->Makefile->PlatformIsAppleEmbedded()) {
  4380. targetNames.Real += "Versions/";
  4381. targetNames.Real += this->GetFrameworkVersion();
  4382. targetNames.Real += "/";
  4383. }
  4384. targetNames.Real += targetNames.Base + suffix;
  4385. targetNames.SharedObject = targetNames.Real + suffix;
  4386. } else {
  4387. // The library's soname.
  4388. this->ComputeVersionedName(targetNames.SharedObject, prefix,
  4389. targetNames.Base, suffix, targetNames.Output,
  4390. soversion);
  4391. // The library's real name on disk.
  4392. this->ComputeVersionedName(targetNames.Real, prefix, targetNames.Base,
  4393. suffix, targetNames.Output, version);
  4394. }
  4395. // The import library name.
  4396. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4397. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  4398. targetNames.ImportLibrary =
  4399. this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
  4400. }
  4401. // The program database file name.
  4402. targetNames.PDB = this->GetPDBName(config);
  4403. return targetNames;
  4404. }
  4405. cmGeneratorTarget::Names cmGeneratorTarget::GetExecutableNames(
  4406. const std::string& config) const
  4407. {
  4408. cmGeneratorTarget::Names targetNames;
  4409. // This should not be called for imported targets.
  4410. // TODO: Split cmTarget into a class hierarchy to get compile-time
  4411. // enforcement of the limited imported target API.
  4412. if (this->IsImported()) {
  4413. std::string msg = cmStrCat(
  4414. "GetExecutableNames called on imported target: ", this->GetName());
  4415. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  4416. }
  4417. // This versioning is supported only for executables and then only
  4418. // when the platform supports symbolic links.
  4419. #if defined(_WIN32) && !defined(__CYGWIN__)
  4420. cmValue version;
  4421. #else
  4422. // Check for executable version properties.
  4423. cmValue version = this->GetProperty("VERSION");
  4424. if (this->GetType() != cmStateEnums::EXECUTABLE ||
  4425. this->Makefile->IsOn("XCODE")) {
  4426. version = nullptr;
  4427. }
  4428. #endif
  4429. // Get the components of the executable name.
  4430. std::string prefix;
  4431. std::string suffix;
  4432. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  4433. prefix, targetNames.Base, suffix);
  4434. // The executable name.
  4435. targetNames.Output = prefix + targetNames.Base + suffix;
  4436. // The executable's real name on disk.
  4437. #if defined(__CYGWIN__)
  4438. targetNames.Real = prefix + targetNames.Base;
  4439. #else
  4440. targetNames.Real = targetNames.Output;
  4441. #endif
  4442. if (version) {
  4443. targetNames.Real += "-";
  4444. targetNames.Real += *version;
  4445. }
  4446. #if defined(__CYGWIN__)
  4447. targetNames.Real += suffix;
  4448. #endif
  4449. // The import library name.
  4450. targetNames.ImportLibrary =
  4451. this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
  4452. // The program database file name.
  4453. targetNames.PDB = this->GetPDBName(config);
  4454. return targetNames;
  4455. }
  4456. std::string cmGeneratorTarget::GetFullNameInternal(
  4457. const std::string& config, cmStateEnums::ArtifactType artifact) const
  4458. {
  4459. std::string prefix;
  4460. std::string base;
  4461. std::string suffix;
  4462. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  4463. return prefix + base + suffix;
  4464. }
  4465. std::string cmGeneratorTarget::ImportedGetLocation(
  4466. const std::string& config) const
  4467. {
  4468. assert(this->IsImported());
  4469. return this->Target->ImportedGetFullPath(
  4470. config, cmStateEnums::RuntimeBinaryArtifact);
  4471. }
  4472. std::string cmGeneratorTarget::GetFullNameImported(
  4473. const std::string& config, cmStateEnums::ArtifactType artifact) const
  4474. {
  4475. return cmSystemTools::GetFilenameName(
  4476. this->Target->ImportedGetFullPath(config, artifact));
  4477. }
  4478. void cmGeneratorTarget::GetFullNameInternal(
  4479. const std::string& config, cmStateEnums::ArtifactType artifact,
  4480. std::string& outPrefix, std::string& outBase, std::string& outSuffix) const
  4481. {
  4482. // Use just the target name for non-main target types.
  4483. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  4484. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  4485. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  4486. this->GetType() != cmStateEnums::EXECUTABLE) {
  4487. outPrefix.clear();
  4488. outBase = this->GetName();
  4489. outSuffix.clear();
  4490. return;
  4491. }
  4492. const bool isImportedLibraryArtifact =
  4493. (artifact == cmStateEnums::ImportLibraryArtifact);
  4494. // Return an empty name for the import library if this platform
  4495. // does not support import libraries.
  4496. if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
  4497. outPrefix.clear();
  4498. outBase.clear();
  4499. outSuffix.clear();
  4500. return;
  4501. }
  4502. // retrieve prefix and suffix
  4503. std::string ll = this->GetLinkerLanguage(config);
  4504. cmValue targetPrefix = this->GetFilePrefixInternal(config, artifact, ll);
  4505. cmValue targetSuffix = this->GetFileSuffixInternal(config, artifact, ll);
  4506. // The implib option is only allowed for shared libraries, module
  4507. // libraries, and executables.
  4508. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  4509. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  4510. this->GetType() != cmStateEnums::EXECUTABLE) {
  4511. artifact = cmStateEnums::RuntimeBinaryArtifact;
  4512. }
  4513. // Compute the full name for main target types.
  4514. const std::string configPostfix = this->GetFilePostfix(config);
  4515. // frameworks have directory prefix but no suffix
  4516. std::string fw_prefix;
  4517. if (this->IsFrameworkOnApple()) {
  4518. fw_prefix =
  4519. cmStrCat(this->GetFrameworkDirectory(config, ContentLevel), '/');
  4520. targetPrefix = cmValue(fw_prefix);
  4521. targetSuffix = nullptr;
  4522. }
  4523. if (this->IsCFBundleOnApple()) {
  4524. fw_prefix = cmStrCat(this->GetCFBundleDirectory(config, FullLevel), '/');
  4525. targetPrefix = cmValue(fw_prefix);
  4526. targetSuffix = nullptr;
  4527. }
  4528. // Begin the final name with the prefix.
  4529. outPrefix = targetPrefix ? *targetPrefix : "";
  4530. // Append the target name or property-specified name.
  4531. outBase += this->GetOutputName(config, artifact);
  4532. // Append the per-configuration postfix.
  4533. // When using Xcode, the postfix should be part of the suffix rather than
  4534. // the base, because the suffix ends up being used in Xcode's
  4535. // EXECUTABLE_SUFFIX attribute.
  4536. if (this->IsFrameworkOnApple() &&
  4537. this->GetGlobalGenerator()->GetName() == "Xcode") {
  4538. targetSuffix = cmValue(configPostfix);
  4539. } else {
  4540. outBase += configPostfix;
  4541. }
  4542. // Name shared libraries with their version number on some platforms.
  4543. if (cmValue soversion = this->GetProperty("SOVERSION")) {
  4544. if (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
  4545. !isImportedLibraryArtifact &&
  4546. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION")) {
  4547. outBase += "-";
  4548. outBase += *soversion;
  4549. }
  4550. }
  4551. // Append the suffix.
  4552. outSuffix = targetSuffix ? *targetSuffix : "";
  4553. }
  4554. std::string cmGeneratorTarget::GetLinkerLanguage(
  4555. const std::string& config) const
  4556. {
  4557. return this->GetLinkClosure(config)->LinkerLanguage;
  4558. }
  4559. std::string cmGeneratorTarget::GetPDBOutputName(
  4560. const std::string& config) const
  4561. {
  4562. std::string base =
  4563. this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact);
  4564. std::vector<std::string> props;
  4565. std::string configUpper = cmSystemTools::UpperCase(config);
  4566. if (!configUpper.empty()) {
  4567. // PDB_NAME_<CONFIG>
  4568. props.push_back("PDB_NAME_" + configUpper);
  4569. }
  4570. // PDB_NAME
  4571. props.emplace_back("PDB_NAME");
  4572. for (std::string const& p : props) {
  4573. if (cmValue outName = this->GetProperty(p)) {
  4574. base = *outName;
  4575. break;
  4576. }
  4577. }
  4578. return base;
  4579. }
  4580. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  4581. {
  4582. std::string prefix;
  4583. std::string base;
  4584. std::string suffix;
  4585. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  4586. prefix, base, suffix);
  4587. std::vector<std::string> props;
  4588. std::string configUpper = cmSystemTools::UpperCase(config);
  4589. if (!configUpper.empty()) {
  4590. // PDB_NAME_<CONFIG>
  4591. props.push_back("PDB_NAME_" + configUpper);
  4592. }
  4593. // PDB_NAME
  4594. props.emplace_back("PDB_NAME");
  4595. for (std::string const& p : props) {
  4596. if (cmValue outName = this->GetProperty(p)) {
  4597. base = *outName;
  4598. break;
  4599. }
  4600. }
  4601. return prefix + base + ".pdb";
  4602. }
  4603. std::string cmGeneratorTarget::GetObjectDirectory(
  4604. std::string const& config) const
  4605. {
  4606. std::string obj_dir =
  4607. this->GlobalGenerator->ExpandCFGIntDir(this->ObjectDirectory, config);
  4608. #if defined(__APPLE__)
  4609. // find and replace $(PROJECT_NAME) xcode placeholder
  4610. const std::string projectName = this->LocalGenerator->GetProjectName();
  4611. cmSystemTools::ReplaceString(obj_dir, "$(PROJECT_NAME)", projectName);
  4612. // Replace Xcode's placeholder for the object file directory since
  4613. // installation and export scripts need to know the real directory.
  4614. // Xcode has build-time settings (e.g. for sanitizers) that affect this,
  4615. // but we use the default here. Users that want to enable sanitizers
  4616. // will do so at the cost of object library installation and export.
  4617. cmSystemTools::ReplaceString(obj_dir, "$(OBJECT_FILE_DIR_normal:base)",
  4618. "Objects-normal");
  4619. #endif
  4620. return obj_dir;
  4621. }
  4622. void cmGeneratorTarget::GetTargetObjectNames(
  4623. std::string const& config, std::vector<std::string>& objects) const
  4624. {
  4625. std::vector<cmSourceFile const*> objectSources;
  4626. this->GetObjectSources(objectSources, config);
  4627. std::map<cmSourceFile const*, std::string> mapping;
  4628. for (cmSourceFile const* sf : objectSources) {
  4629. mapping[sf];
  4630. }
  4631. this->LocalGenerator->ComputeObjectFilenames(mapping, this);
  4632. for (cmSourceFile const* src : objectSources) {
  4633. // Find the object file name corresponding to this source file.
  4634. auto map_it = mapping.find(src);
  4635. // It must exist because we populated the mapping just above.
  4636. assert(!map_it->second.empty());
  4637. objects.push_back(map_it->second);
  4638. }
  4639. // We need to compute the relative path from the root of
  4640. // of the object directory to handle subdirectory paths
  4641. std::string rootObjectDir = this->GetObjectDirectory(config);
  4642. rootObjectDir = cmSystemTools::CollapseFullPath(rootObjectDir);
  4643. auto ispcObjects = this->GetGeneratedISPCObjects(config);
  4644. for (std::string const& output : ispcObjects) {
  4645. auto relativePathFromObjectDir = output.substr(rootObjectDir.size());
  4646. objects.push_back(relativePathFromObjectDir);
  4647. }
  4648. }
  4649. bool cmGeneratorTarget::StrictTargetComparison::operator()(
  4650. cmGeneratorTarget const* t1, cmGeneratorTarget const* t2) const
  4651. {
  4652. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  4653. if (nameResult == 0) {
  4654. return strcmp(
  4655. t1->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str(),
  4656. t2->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str()) < 0;
  4657. }
  4658. return nameResult < 0;
  4659. }
  4660. struct cmGeneratorTarget::SourceFileFlags
  4661. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  4662. {
  4663. struct SourceFileFlags flags;
  4664. this->ConstructSourceFileFlags();
  4665. auto si = this->SourceFlagsMap.find(sf);
  4666. if (si != this->SourceFlagsMap.end()) {
  4667. flags = si->second;
  4668. } else {
  4669. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  4670. // were not listed in one of the other lists.
  4671. if (cmValue location = sf->GetProperty("MACOSX_PACKAGE_LOCATION")) {
  4672. flags.MacFolder = location->c_str();
  4673. const bool stripResources =
  4674. this->GlobalGenerator->ShouldStripResourcePath(this->Makefile);
  4675. if (*location == "Resources") {
  4676. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  4677. if (stripResources) {
  4678. flags.MacFolder = "";
  4679. }
  4680. } else if (cmHasLiteralPrefix(*location, "Resources/")) {
  4681. flags.Type = cmGeneratorTarget::SourceFileTypeDeepResource;
  4682. if (stripResources) {
  4683. flags.MacFolder += strlen("Resources/");
  4684. }
  4685. } else {
  4686. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  4687. }
  4688. }
  4689. }
  4690. return flags;
  4691. }
  4692. void cmGeneratorTarget::ConstructSourceFileFlags() const
  4693. {
  4694. if (this->SourceFileFlagsConstructed) {
  4695. return;
  4696. }
  4697. this->SourceFileFlagsConstructed = true;
  4698. // Process public headers to mark the source files.
  4699. if (cmValue files = this->GetProperty("PUBLIC_HEADER")) {
  4700. std::vector<std::string> relFiles = cmExpandedList(*files);
  4701. for (std::string const& relFile : relFiles) {
  4702. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  4703. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  4704. flags.MacFolder = "Headers";
  4705. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  4706. }
  4707. }
  4708. }
  4709. // Process private headers after public headers so that they take
  4710. // precedence if a file is listed in both.
  4711. if (cmValue files = this->GetProperty("PRIVATE_HEADER")) {
  4712. std::vector<std::string> relFiles = cmExpandedList(*files);
  4713. for (std::string const& relFile : relFiles) {
  4714. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  4715. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  4716. flags.MacFolder = "PrivateHeaders";
  4717. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  4718. }
  4719. }
  4720. }
  4721. // Mark sources listed as resources.
  4722. if (cmValue files = this->GetProperty("RESOURCE")) {
  4723. std::vector<std::string> relFiles = cmExpandedList(*files);
  4724. for (std::string const& relFile : relFiles) {
  4725. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  4726. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  4727. flags.MacFolder = "";
  4728. if (!this->GlobalGenerator->ShouldStripResourcePath(this->Makefile)) {
  4729. flags.MacFolder = "Resources";
  4730. }
  4731. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  4732. }
  4733. }
  4734. }
  4735. }
  4736. const cmGeneratorTarget::CompatibleInterfacesBase&
  4737. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  4738. {
  4739. cmGeneratorTarget::CompatibleInterfaces& compat =
  4740. this->CompatibleInterfacesMap[config];
  4741. if (!compat.Done) {
  4742. compat.Done = true;
  4743. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  4744. compat.PropsString.insert("AUTOUIC_OPTIONS");
  4745. std::vector<cmGeneratorTarget const*> const& deps =
  4746. this->GetLinkImplementationClosure(config);
  4747. for (cmGeneratorTarget const* li : deps) {
  4748. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  4749. if (cmValue prop = li->GetProperty("COMPATIBLE_INTERFACE_" #X)) { \
  4750. std::vector<std::string> props; \
  4751. cmExpandList(*prop, props); \
  4752. compat.Props##x.insert(props.begin(), props.end()); \
  4753. }
  4754. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  4755. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  4756. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  4757. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  4758. #undef CM_READ_COMPATIBLE_INTERFACE
  4759. }
  4760. }
  4761. return compat;
  4762. }
  4763. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  4764. const std::string& p, const std::string& config) const
  4765. {
  4766. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  4767. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4768. return false;
  4769. }
  4770. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  4771. }
  4772. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  4773. const std::string& p, const std::string& config) const
  4774. {
  4775. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  4776. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4777. return false;
  4778. }
  4779. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  4780. }
  4781. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  4782. const std::string& p, const std::string& config) const
  4783. {
  4784. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  4785. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4786. return false;
  4787. }
  4788. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  4789. }
  4790. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  4791. const std::string& p, const std::string& config) const
  4792. {
  4793. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  4794. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4795. return false;
  4796. }
  4797. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  4798. }
  4799. enum CompatibleType
  4800. {
  4801. BoolType,
  4802. StringType,
  4803. NumberMinType,
  4804. NumberMaxType
  4805. };
  4806. template <typename PropertyType>
  4807. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  4808. const std::string& prop,
  4809. const std::string& config,
  4810. CompatibleType, PropertyType*);
  4811. template <>
  4812. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  4813. const std::string& prop,
  4814. const std::string& config,
  4815. CompatibleType /*unused*/,
  4816. bool* /*unused*/)
  4817. {
  4818. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  4819. }
  4820. template <>
  4821. const char* getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  4822. const std::string& prop,
  4823. const std::string& config,
  4824. CompatibleType t,
  4825. const char** /*unused*/)
  4826. {
  4827. switch (t) {
  4828. case BoolType:
  4829. assert(false &&
  4830. "String compatibility check function called for boolean");
  4831. return nullptr;
  4832. case StringType:
  4833. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  4834. case NumberMinType:
  4835. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  4836. case NumberMaxType:
  4837. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  4838. }
  4839. assert(false && "Unreachable!");
  4840. return nullptr;
  4841. }
  4842. template <typename PropertyType>
  4843. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  4844. cmGeneratorTarget const* dependee,
  4845. const std::string& propName,
  4846. std::set<std::string>& emitted,
  4847. const std::string& config, CompatibleType t,
  4848. PropertyType* /*unused*/)
  4849. {
  4850. cmValue prop = dependee->GetProperty(propName);
  4851. if (!prop) {
  4852. return;
  4853. }
  4854. std::vector<std::string> props = cmExpandedList(*prop);
  4855. std::string pdir =
  4856. cmStrCat(cmSystemTools::GetCMakeRoot(), "/Help/prop_tgt/");
  4857. for (std::string const& p : props) {
  4858. std::string pname = cmSystemTools::HelpFileName(p);
  4859. std::string pfile = pdir + pname + ".rst";
  4860. if (cmSystemTools::FileExists(pfile, true)) {
  4861. std::ostringstream e;
  4862. e << "Target \"" << dependee->GetName() << "\" has property \"" << p
  4863. << "\" listed in its " << propName
  4864. << " property. "
  4865. "This is not allowed. Only user-defined properties may appear "
  4866. "listed in the "
  4867. << propName << " property.";
  4868. depender->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
  4869. e.str());
  4870. return;
  4871. }
  4872. if (emitted.insert(p).second) {
  4873. getLinkInterfaceDependentProperty<PropertyType>(depender, p, config, t,
  4874. nullptr);
  4875. if (cmSystemTools::GetErrorOccuredFlag()) {
  4876. return;
  4877. }
  4878. }
  4879. }
  4880. }
  4881. namespace {
  4882. std::string intersect(const std::set<std::string>& s1,
  4883. const std::set<std::string>& s2)
  4884. {
  4885. std::set<std::string> intersect;
  4886. std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(),
  4887. std::inserter(intersect, intersect.begin()));
  4888. if (!intersect.empty()) {
  4889. return *intersect.begin();
  4890. }
  4891. return "";
  4892. }
  4893. std::string intersect(const std::set<std::string>& s1,
  4894. const std::set<std::string>& s2,
  4895. const std::set<std::string>& s3)
  4896. {
  4897. std::string result;
  4898. result = intersect(s1, s2);
  4899. if (!result.empty()) {
  4900. return result;
  4901. }
  4902. result = intersect(s1, s3);
  4903. if (!result.empty()) {
  4904. return result;
  4905. }
  4906. return intersect(s2, s3);
  4907. }
  4908. std::string intersect(const std::set<std::string>& s1,
  4909. const std::set<std::string>& s2,
  4910. const std::set<std::string>& s3,
  4911. const std::set<std::string>& s4)
  4912. {
  4913. std::string result;
  4914. result = intersect(s1, s2);
  4915. if (!result.empty()) {
  4916. return result;
  4917. }
  4918. result = intersect(s1, s3);
  4919. if (!result.empty()) {
  4920. return result;
  4921. }
  4922. result = intersect(s1, s4);
  4923. if (!result.empty()) {
  4924. return result;
  4925. }
  4926. return intersect(s2, s3, s4);
  4927. }
  4928. }
  4929. void cmGeneratorTarget::CheckPropertyCompatibility(
  4930. cmComputeLinkInformation& info, const std::string& config) const
  4931. {
  4932. const cmComputeLinkInformation::ItemVector& deps = info.GetItems();
  4933. std::set<std::string> emittedBools;
  4934. static const std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  4935. std::set<std::string> emittedStrings;
  4936. static const std::string strString = "COMPATIBLE_INTERFACE_STRING";
  4937. std::set<std::string> emittedMinNumbers;
  4938. static const std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  4939. std::set<std::string> emittedMaxNumbers;
  4940. static const std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  4941. for (auto const& dep : deps) {
  4942. if (!dep.Target) {
  4943. continue;
  4944. }
  4945. checkPropertyConsistency<bool>(this, dep.Target, strBool, emittedBools,
  4946. config, BoolType, nullptr);
  4947. if (cmSystemTools::GetErrorOccuredFlag()) {
  4948. return;
  4949. }
  4950. checkPropertyConsistency<const char*>(this, dep.Target, strString,
  4951. emittedStrings, config, StringType,
  4952. nullptr);
  4953. if (cmSystemTools::GetErrorOccuredFlag()) {
  4954. return;
  4955. }
  4956. checkPropertyConsistency<const char*>(this, dep.Target, strNumMin,
  4957. emittedMinNumbers, config,
  4958. NumberMinType, nullptr);
  4959. if (cmSystemTools::GetErrorOccuredFlag()) {
  4960. return;
  4961. }
  4962. checkPropertyConsistency<const char*>(this, dep.Target, strNumMax,
  4963. emittedMaxNumbers, config,
  4964. NumberMaxType, nullptr);
  4965. if (cmSystemTools::GetErrorOccuredFlag()) {
  4966. return;
  4967. }
  4968. }
  4969. std::string prop = intersect(emittedBools, emittedStrings, emittedMinNumbers,
  4970. emittedMaxNumbers);
  4971. if (!prop.empty()) {
  4972. // Use a sorted std::vector to keep the error message sorted.
  4973. std::vector<std::string> props;
  4974. auto i = emittedBools.find(prop);
  4975. if (i != emittedBools.end()) {
  4976. props.push_back(strBool);
  4977. }
  4978. i = emittedStrings.find(prop);
  4979. if (i != emittedStrings.end()) {
  4980. props.push_back(strString);
  4981. }
  4982. i = emittedMinNumbers.find(prop);
  4983. if (i != emittedMinNumbers.end()) {
  4984. props.push_back(strNumMin);
  4985. }
  4986. i = emittedMaxNumbers.find(prop);
  4987. if (i != emittedMaxNumbers.end()) {
  4988. props.push_back(strNumMax);
  4989. }
  4990. std::sort(props.begin(), props.end());
  4991. std::string propsString = cmStrCat(
  4992. cmJoin(cmMakeRange(props).retreat(1), ", "), " and the ", props.back());
  4993. std::ostringstream e;
  4994. e << "Property \"" << prop << "\" appears in both the " << propsString
  4995. << " property in the dependencies of target \"" << this->GetName()
  4996. << "\". This is not allowed. A property may only require "
  4997. "compatibility "
  4998. "in a boolean interpretation, a numeric minimum, a numeric maximum "
  4999. "or a "
  5000. "string interpretation, but not a mixture.";
  5001. this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
  5002. }
  5003. }
  5004. template <typename PropertyType>
  5005. std::string valueAsString(PropertyType);
  5006. template <>
  5007. std::string valueAsString<bool>(bool value)
  5008. {
  5009. return value ? "TRUE" : "FALSE";
  5010. }
  5011. template <>
  5012. std::string valueAsString<const char*>(const char* value)
  5013. {
  5014. return value ? value : "(unset)";
  5015. }
  5016. template <>
  5017. std::string valueAsString<std::string>(std::string value)
  5018. {
  5019. return value;
  5020. }
  5021. template <>
  5022. std::string valueAsString<cmValue>(cmValue value)
  5023. {
  5024. return value ? value : std::string("(unset)");
  5025. }
  5026. template <>
  5027. std::string valueAsString<std::nullptr_t>(std::nullptr_t /*unused*/)
  5028. {
  5029. return "(unset)";
  5030. }
  5031. std::string compatibilityType(CompatibleType t)
  5032. {
  5033. switch (t) {
  5034. case BoolType:
  5035. return "Boolean compatibility";
  5036. case StringType:
  5037. return "String compatibility";
  5038. case NumberMaxType:
  5039. return "Numeric maximum compatibility";
  5040. case NumberMinType:
  5041. return "Numeric minimum compatibility";
  5042. }
  5043. assert(false && "Unreachable!");
  5044. return "";
  5045. }
  5046. std::string compatibilityAgree(CompatibleType t, bool dominant)
  5047. {
  5048. switch (t) {
  5049. case BoolType:
  5050. case StringType:
  5051. return dominant ? "(Disagree)\n" : "(Agree)\n";
  5052. case NumberMaxType:
  5053. case NumberMinType:
  5054. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  5055. }
  5056. assert(false && "Unreachable!");
  5057. return "";
  5058. }
  5059. template <typename PropertyType>
  5060. PropertyType getTypedProperty(
  5061. cmGeneratorTarget const* tgt, const std::string& prop,
  5062. cmGeneratorExpressionInterpreter* genexInterpreter = nullptr);
  5063. template <>
  5064. bool getTypedProperty<bool>(cmGeneratorTarget const* tgt,
  5065. const std::string& prop,
  5066. cmGeneratorExpressionInterpreter* genexInterpreter)
  5067. {
  5068. if (genexInterpreter == nullptr) {
  5069. return tgt->GetPropertyAsBool(prop);
  5070. }
  5071. cmValue value = tgt->GetProperty(prop);
  5072. return cmIsOn(genexInterpreter->Evaluate(value ? *value : "", prop));
  5073. }
  5074. template <>
  5075. const char* getTypedProperty<const char*>(
  5076. cmGeneratorTarget const* tgt, const std::string& prop,
  5077. cmGeneratorExpressionInterpreter* genexInterpreter)
  5078. {
  5079. cmValue value = tgt->GetProperty(prop);
  5080. if (genexInterpreter == nullptr) {
  5081. return value.GetCStr();
  5082. }
  5083. return genexInterpreter->Evaluate(value ? *value : "", prop).c_str();
  5084. }
  5085. template <>
  5086. std::string getTypedProperty<std::string>(
  5087. cmGeneratorTarget const* tgt, const std::string& prop,
  5088. cmGeneratorExpressionInterpreter* genexInterpreter)
  5089. {
  5090. cmValue value = tgt->GetProperty(prop);
  5091. if (genexInterpreter == nullptr) {
  5092. return valueAsString(value);
  5093. }
  5094. return genexInterpreter->Evaluate(value ? *value : "", prop);
  5095. }
  5096. template <typename PropertyType>
  5097. PropertyType impliedValue(PropertyType);
  5098. template <>
  5099. bool impliedValue<bool>(bool /*unused*/)
  5100. {
  5101. return false;
  5102. }
  5103. template <>
  5104. const char* impliedValue<const char*>(const char* /*unused*/)
  5105. {
  5106. return "";
  5107. }
  5108. template <>
  5109. std::string impliedValue<std::string>(std::string /*unused*/) // NOLINT(*)
  5110. {
  5111. return std::string();
  5112. }
  5113. template <typename PropertyType>
  5114. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  5115. PropertyType rhs,
  5116. CompatibleType t);
  5117. template <>
  5118. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  5119. CompatibleType /*unused*/)
  5120. {
  5121. return { lhs == rhs, lhs };
  5122. }
  5123. std::pair<bool, const char*> consistentStringProperty(const char* lhs,
  5124. const char* rhs)
  5125. {
  5126. const bool b = strcmp(lhs, rhs) == 0;
  5127. return { b, b ? lhs : nullptr };
  5128. }
  5129. std::pair<bool, std::string> consistentStringProperty(const std::string& lhs,
  5130. const std::string& rhs)
  5131. {
  5132. const bool b = lhs == rhs;
  5133. return { b, b ? lhs : valueAsString(nullptr) };
  5134. }
  5135. std::pair<bool, const char*> consistentNumberProperty(const char* lhs,
  5136. const char* rhs,
  5137. CompatibleType t)
  5138. {
  5139. char* pEnd;
  5140. long lnum = strtol(lhs, &pEnd, 0);
  5141. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) {
  5142. return { false, nullptr };
  5143. }
  5144. long rnum = strtol(rhs, &pEnd, 0);
  5145. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) {
  5146. return { false, nullptr };
  5147. }
  5148. if (t == NumberMaxType) {
  5149. return { true, std::max(lnum, rnum) == lnum ? lhs : rhs };
  5150. }
  5151. return { true, std::min(lnum, rnum) == lnum ? lhs : rhs };
  5152. }
  5153. template <>
  5154. std::pair<bool, const char*> consistentProperty(const char* lhs,
  5155. const char* rhs,
  5156. CompatibleType t)
  5157. {
  5158. if (!lhs && !rhs) {
  5159. return { true, lhs };
  5160. }
  5161. if (!lhs) {
  5162. return { true, rhs };
  5163. }
  5164. if (!rhs) {
  5165. return { true, lhs };
  5166. }
  5167. switch (t) {
  5168. case BoolType: {
  5169. bool same = cmIsOn(lhs) == cmIsOn(rhs);
  5170. return { same, same ? lhs : nullptr };
  5171. }
  5172. case StringType:
  5173. return consistentStringProperty(lhs, rhs);
  5174. case NumberMinType:
  5175. case NumberMaxType:
  5176. return consistentNumberProperty(lhs, rhs, t);
  5177. }
  5178. assert(false && "Unreachable!");
  5179. return { false, nullptr };
  5180. }
  5181. std::pair<bool, std::string> consistentProperty(const std::string& lhs,
  5182. const std::string& rhs,
  5183. CompatibleType t)
  5184. {
  5185. const std::string null_ptr = valueAsString(nullptr);
  5186. if (lhs == null_ptr && rhs == null_ptr) {
  5187. return { true, lhs };
  5188. }
  5189. if (lhs == null_ptr) {
  5190. return { true, rhs };
  5191. }
  5192. if (rhs == null_ptr) {
  5193. return { true, lhs };
  5194. }
  5195. switch (t) {
  5196. case BoolType: {
  5197. bool same = cmIsOn(lhs) == cmIsOn(rhs);
  5198. return { same, same ? lhs : null_ptr };
  5199. }
  5200. case StringType:
  5201. return consistentStringProperty(lhs, rhs);
  5202. case NumberMinType:
  5203. case NumberMaxType: {
  5204. auto value = consistentNumberProperty(lhs.c_str(), rhs.c_str(), t);
  5205. return { value.first,
  5206. value.first ? std::string(value.second) : null_ptr };
  5207. }
  5208. }
  5209. assert(false && "Unreachable!");
  5210. return { false, null_ptr };
  5211. }
  5212. template <typename PropertyType>
  5213. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  5214. const std::string& p,
  5215. const std::string& config,
  5216. const char* defaultValue,
  5217. CompatibleType t,
  5218. PropertyType* /*unused*/)
  5219. {
  5220. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
  5221. std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
  5222. const bool explicitlySet = cm::contains(headPropKeys, p);
  5223. const bool impliedByUse = tgt->IsNullImpliedByLinkLibraries(p);
  5224. assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet));
  5225. std::vector<cmGeneratorTarget const*> const& deps =
  5226. tgt->GetLinkImplementationClosure(config);
  5227. if (deps.empty()) {
  5228. return propContent;
  5229. }
  5230. bool propInitialized = explicitlySet;
  5231. std::string report = cmStrCat(" * Target \"", tgt->GetName());
  5232. if (explicitlySet) {
  5233. report += "\" has property content \"";
  5234. report += valueAsString<PropertyType>(propContent);
  5235. report += "\"\n";
  5236. } else if (impliedByUse) {
  5237. report += "\" property is implied by use.\n";
  5238. } else {
  5239. report += "\" property not set.\n";
  5240. }
  5241. std::string interfaceProperty = "INTERFACE_" + p;
  5242. std::unique_ptr<cmGeneratorExpressionInterpreter> genexInterpreter;
  5243. if (p == "POSITION_INDEPENDENT_CODE") {
  5244. genexInterpreter = cm::make_unique<cmGeneratorExpressionInterpreter>(
  5245. tgt->GetLocalGenerator(), config, tgt);
  5246. }
  5247. for (cmGeneratorTarget const* theTarget : deps) {
  5248. // An error should be reported if one dependency
  5249. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  5250. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  5251. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  5252. // with a dependency.
  5253. std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
  5254. const bool ifaceIsSet = cm::contains(propKeys, interfaceProperty);
  5255. PropertyType ifacePropContent = getTypedProperty<PropertyType>(
  5256. theTarget, interfaceProperty, genexInterpreter.get());
  5257. std::string reportEntry;
  5258. if (ifaceIsSet) {
  5259. reportEntry += " * Target \"";
  5260. reportEntry += theTarget->GetName();
  5261. reportEntry += "\" property value \"";
  5262. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  5263. reportEntry += "\" ";
  5264. }
  5265. if (explicitlySet) {
  5266. if (ifaceIsSet) {
  5267. std::pair<bool, PropertyType> consistent =
  5268. consistentProperty(propContent, ifacePropContent, t);
  5269. report += reportEntry;
  5270. report += compatibilityAgree(t, propContent != consistent.second);
  5271. if (!consistent.first) {
  5272. std::ostringstream e;
  5273. e << "Property " << p << " on target \"" << tgt->GetName()
  5274. << "\" does\nnot match the "
  5275. "INTERFACE_"
  5276. << p
  5277. << " property requirement\nof "
  5278. "dependency \""
  5279. << theTarget->GetName() << "\".\n";
  5280. cmSystemTools::Error(e.str());
  5281. break;
  5282. }
  5283. propContent = consistent.second;
  5284. continue;
  5285. }
  5286. // Explicitly set on target and not set in iface. Can't disagree.
  5287. continue;
  5288. }
  5289. if (impliedByUse) {
  5290. propContent = impliedValue<PropertyType>(propContent);
  5291. if (ifaceIsSet) {
  5292. std::pair<bool, PropertyType> consistent =
  5293. consistentProperty(propContent, ifacePropContent, t);
  5294. report += reportEntry;
  5295. report += compatibilityAgree(t, propContent != consistent.second);
  5296. if (!consistent.first) {
  5297. std::ostringstream e;
  5298. e << "Property " << p << " on target \"" << tgt->GetName()
  5299. << "\" is\nimplied to be " << defaultValue
  5300. << " because it was used to determine the link libraries\n"
  5301. "already. The INTERFACE_"
  5302. << p << " property on\ndependency \"" << theTarget->GetName()
  5303. << "\" is in conflict.\n";
  5304. cmSystemTools::Error(e.str());
  5305. break;
  5306. }
  5307. propContent = consistent.second;
  5308. continue;
  5309. }
  5310. // Implicitly set on target and not set in iface. Can't disagree.
  5311. continue;
  5312. }
  5313. if (ifaceIsSet) {
  5314. if (propInitialized) {
  5315. std::pair<bool, PropertyType> consistent =
  5316. consistentProperty(propContent, ifacePropContent, t);
  5317. report += reportEntry;
  5318. report += compatibilityAgree(t, propContent != consistent.second);
  5319. if (!consistent.first) {
  5320. std::ostringstream e;
  5321. e << "The INTERFACE_" << p << " property of \""
  5322. << theTarget->GetName() << "\" does\nnot agree with the value of "
  5323. << p << " already determined\nfor \"" << tgt->GetName() << "\".\n";
  5324. cmSystemTools::Error(e.str());
  5325. break;
  5326. }
  5327. propContent = consistent.second;
  5328. continue;
  5329. }
  5330. report += reportEntry + "(Interface set)\n";
  5331. propContent = ifacePropContent;
  5332. propInitialized = true;
  5333. } else {
  5334. // Not set. Nothing to agree on.
  5335. continue;
  5336. }
  5337. }
  5338. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  5339. report, compatibilityType(t));
  5340. return propContent;
  5341. }
  5342. bool cmGeneratorTarget::SetDeviceLink(bool deviceLink)
  5343. {
  5344. bool previous = this->DeviceLink;
  5345. this->DeviceLink = deviceLink;
  5346. return previous;
  5347. }
  5348. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  5349. const std::string& p, const std::string& config) const
  5350. {
  5351. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  5352. BoolType, nullptr);
  5353. }
  5354. std::string cmGeneratorTarget::GetLinkInterfaceDependentStringAsBoolProperty(
  5355. const std::string& p, const std::string& config) const
  5356. {
  5357. return checkInterfacePropertyCompatibility<std::string>(
  5358. this, p, config, "FALSE", BoolType, nullptr);
  5359. }
  5360. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  5361. const std::string& p, const std::string& config) const
  5362. {
  5363. return checkInterfacePropertyCompatibility<const char*>(
  5364. this, p, config, "empty", StringType, nullptr);
  5365. }
  5366. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  5367. const std::string& p, const std::string& config) const
  5368. {
  5369. return checkInterfacePropertyCompatibility<const char*>(
  5370. this, p, config, "empty", NumberMinType, nullptr);
  5371. }
  5372. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  5373. const std::string& p, const std::string& config) const
  5374. {
  5375. return checkInterfacePropertyCompatibility<const char*>(
  5376. this, p, config, "empty", NumberMaxType, nullptr);
  5377. }
  5378. cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
  5379. const std::string& config) const
  5380. {
  5381. // Lookup any existing information for this configuration.
  5382. std::string key(cmSystemTools::UpperCase(config));
  5383. auto i = this->LinkInformation.find(key);
  5384. if (i == this->LinkInformation.end()) {
  5385. // Compute information for this configuration.
  5386. auto info = cm::make_unique<cmComputeLinkInformation>(this, config);
  5387. if (info && !info->Compute()) {
  5388. info.reset();
  5389. }
  5390. // Store the information for this configuration.
  5391. i = this->LinkInformation.emplace(key, std::move(info)).first;
  5392. if (i->second) {
  5393. this->CheckPropertyCompatibility(*i->second, config);
  5394. }
  5395. }
  5396. return i->second.get();
  5397. }
  5398. void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
  5399. {
  5400. int patch;
  5401. this->GetTargetVersion("VERSION", major, minor, patch);
  5402. }
  5403. void cmGeneratorTarget::GetTargetVersionFallback(
  5404. const std::string& property, const std::string& fallback_property,
  5405. int& major, int& minor, int& patch) const
  5406. {
  5407. if (this->GetProperty(property)) {
  5408. this->GetTargetVersion(property, major, minor, patch);
  5409. } else {
  5410. this->GetTargetVersion(fallback_property, major, minor, patch);
  5411. }
  5412. }
  5413. void cmGeneratorTarget::GetTargetVersion(const std::string& property,
  5414. int& major, int& minor,
  5415. int& patch) const
  5416. {
  5417. // Set the default values.
  5418. major = 0;
  5419. minor = 0;
  5420. patch = 0;
  5421. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  5422. if (cmValue version = this->GetProperty(property)) {
  5423. // Try to parse the version number and store the results that were
  5424. // successfully parsed.
  5425. int parsed_major;
  5426. int parsed_minor;
  5427. int parsed_patch;
  5428. switch (sscanf(version->c_str(), "%d.%d.%d", &parsed_major, &parsed_minor,
  5429. &parsed_patch)) {
  5430. case 3:
  5431. patch = parsed_patch;
  5432. CM_FALLTHROUGH;
  5433. case 2:
  5434. minor = parsed_minor;
  5435. CM_FALLTHROUGH;
  5436. case 1:
  5437. major = parsed_major;
  5438. CM_FALLTHROUGH;
  5439. default:
  5440. break;
  5441. }
  5442. }
  5443. }
  5444. std::string cmGeneratorTarget::GetRuntimeLinkLibrary(
  5445. std::string const& lang, std::string const& config) const
  5446. {
  5447. // This is activated by the presence of a default selection whether or
  5448. // not it is overridden by a property.
  5449. cmValue runtimeLibraryDefault = this->Makefile->GetDefinition(
  5450. cmStrCat("CMAKE_", lang, "_RUNTIME_LIBRARY_DEFAULT"));
  5451. if (!cmNonempty(runtimeLibraryDefault)) {
  5452. return std::string();
  5453. }
  5454. cmValue runtimeLibraryValue =
  5455. this->Target->GetProperty(cmStrCat(lang, "_RUNTIME_LIBRARY"));
  5456. if (!runtimeLibraryValue) {
  5457. runtimeLibraryValue = runtimeLibraryDefault;
  5458. }
  5459. return cmSystemTools::UpperCase(cmGeneratorExpression::Evaluate(
  5460. *runtimeLibraryValue, this->LocalGenerator, config, this));
  5461. }
  5462. std::string cmGeneratorTarget::GetFortranModuleDirectory(
  5463. std::string const& working_dir) const
  5464. {
  5465. if (!this->FortranModuleDirectoryCreated) {
  5466. this->FortranModuleDirectory =
  5467. this->CreateFortranModuleDirectory(working_dir);
  5468. this->FortranModuleDirectoryCreated = true;
  5469. }
  5470. return this->FortranModuleDirectory;
  5471. }
  5472. bool cmGeneratorTarget::IsFortranBuildingInstrinsicModules() const
  5473. {
  5474. if (cmValue prop =
  5475. this->GetProperty("Fortran_BUILDING_INSTRINSIC_MODULES")) {
  5476. return cmIsOn(*prop);
  5477. }
  5478. return false;
  5479. }
  5480. std::string cmGeneratorTarget::CreateFortranModuleDirectory(
  5481. std::string const& working_dir) const
  5482. {
  5483. std::string mod_dir;
  5484. std::string target_mod_dir;
  5485. if (cmValue prop = this->GetProperty("Fortran_MODULE_DIRECTORY")) {
  5486. target_mod_dir = *prop;
  5487. } else {
  5488. std::string const& default_mod_dir =
  5489. this->LocalGenerator->GetCurrentBinaryDirectory();
  5490. if (default_mod_dir != working_dir) {
  5491. target_mod_dir = default_mod_dir;
  5492. }
  5493. }
  5494. cmValue moddir_flag =
  5495. this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
  5496. if (!target_mod_dir.empty() && moddir_flag) {
  5497. // Compute the full path to the module directory.
  5498. if (cmSystemTools::FileIsFullPath(target_mod_dir)) {
  5499. // Already a full path.
  5500. mod_dir = target_mod_dir;
  5501. } else {
  5502. // Interpret relative to the current output directory.
  5503. mod_dir = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(),
  5504. '/', target_mod_dir);
  5505. }
  5506. // Make sure the module output directory exists.
  5507. cmSystemTools::MakeDirectory(mod_dir);
  5508. }
  5509. return mod_dir;
  5510. }
  5511. void cmGeneratorTarget::AddISPCGeneratedHeader(std::string const& header,
  5512. std::string const& config)
  5513. {
  5514. std::string config_upper;
  5515. if (!config.empty()) {
  5516. config_upper = cmSystemTools::UpperCase(config);
  5517. }
  5518. auto iter = this->ISPCGeneratedHeaders.find(config_upper);
  5519. if (iter == this->ISPCGeneratedHeaders.end()) {
  5520. std::vector<std::string> headers;
  5521. headers.emplace_back(header);
  5522. this->ISPCGeneratedHeaders.insert({ config_upper, headers });
  5523. } else {
  5524. iter->second.emplace_back(header);
  5525. }
  5526. }
  5527. std::vector<std::string> cmGeneratorTarget::GetGeneratedISPCHeaders(
  5528. std::string const& config) const
  5529. {
  5530. std::string config_upper;
  5531. if (!config.empty()) {
  5532. config_upper = cmSystemTools::UpperCase(config);
  5533. }
  5534. auto iter = this->ISPCGeneratedHeaders.find(config_upper);
  5535. if (iter == this->ISPCGeneratedHeaders.end()) {
  5536. return std::vector<std::string>{};
  5537. }
  5538. return iter->second;
  5539. }
  5540. void cmGeneratorTarget::AddISPCGeneratedObject(std::vector<std::string>&& objs,
  5541. std::string const& config)
  5542. {
  5543. std::string config_upper;
  5544. if (!config.empty()) {
  5545. config_upper = cmSystemTools::UpperCase(config);
  5546. }
  5547. auto iter = this->ISPCGeneratedObjects.find(config_upper);
  5548. if (iter == this->ISPCGeneratedObjects.end()) {
  5549. this->ISPCGeneratedObjects.insert({ config_upper, objs });
  5550. } else {
  5551. iter->second.insert(iter->second.end(), objs.begin(), objs.end());
  5552. }
  5553. }
  5554. std::vector<std::string> cmGeneratorTarget::GetGeneratedISPCObjects(
  5555. std::string const& config) const
  5556. {
  5557. std::string config_upper;
  5558. if (!config.empty()) {
  5559. config_upper = cmSystemTools::UpperCase(config);
  5560. }
  5561. auto iter = this->ISPCGeneratedObjects.find(config_upper);
  5562. if (iter == this->ISPCGeneratedObjects.end()) {
  5563. return std::vector<std::string>{};
  5564. }
  5565. return iter->second;
  5566. }
  5567. std::string cmGeneratorTarget::GetFrameworkVersion() const
  5568. {
  5569. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  5570. if (cmValue fversion = this->GetProperty("FRAMEWORK_VERSION")) {
  5571. return *fversion;
  5572. }
  5573. if (cmValue tversion = this->GetProperty("VERSION")) {
  5574. return *tversion;
  5575. }
  5576. return "A";
  5577. }
  5578. void cmGeneratorTarget::ComputeVersionedName(
  5579. std::string& vName, std::string const& prefix, std::string const& base,
  5580. std::string const& suffix, std::string const& name, cmValue version) const
  5581. {
  5582. vName = this->Makefile->IsOn("APPLE") ? (prefix + base) : name;
  5583. if (version) {
  5584. vName += ".";
  5585. vName += *version;
  5586. }
  5587. vName += this->Makefile->IsOn("APPLE") ? suffix : std::string();
  5588. }
  5589. std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const
  5590. {
  5591. return this->Target->GetProperties().GetKeys();
  5592. }
  5593. void cmGeneratorTarget::ReportPropertyOrigin(
  5594. const std::string& p, const std::string& result, const std::string& report,
  5595. const std::string& compatibilityType) const
  5596. {
  5597. std::vector<std::string> debugProperties;
  5598. this->Target->GetMakefile()->GetDefExpandList(
  5599. "CMAKE_DEBUG_TARGET_PROPERTIES", debugProperties);
  5600. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] &&
  5601. cm::contains(debugProperties, p);
  5602. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  5603. this->DebugCompatiblePropertiesDone[p] = true;
  5604. }
  5605. if (!debugOrigin) {
  5606. return;
  5607. }
  5608. std::string areport =
  5609. cmStrCat(compatibilityType, " of property \"", p, "\" for target \"",
  5610. this->GetName(), "\" (result: \"", result, "\"):\n", report);
  5611. this->LocalGenerator->GetCMakeInstance()->IssueMessage(MessageType::LOG,
  5612. areport);
  5613. }
  5614. bool cmGeneratorTarget::IsLinkLookupScope(std::string const& n,
  5615. cmLocalGenerator const*& lg) const
  5616. {
  5617. if (cmHasLiteralPrefix(n, CMAKE_DIRECTORY_ID_SEP)) {
  5618. cmDirectoryId const dirId = n.substr(sizeof(CMAKE_DIRECTORY_ID_SEP) - 1);
  5619. if (dirId.String.empty()) {
  5620. lg = this->LocalGenerator;
  5621. return true;
  5622. }
  5623. if (cmLocalGenerator const* otherLG =
  5624. this->GlobalGenerator->FindLocalGenerator(dirId)) {
  5625. lg = otherLG;
  5626. return true;
  5627. }
  5628. }
  5629. return false;
  5630. }
  5631. cm::optional<cmLinkItem> cmGeneratorTarget::LookupLinkItem(
  5632. std::string const& n, cmListFileBacktrace const& bt,
  5633. LookupLinkItemScope* scope) const
  5634. {
  5635. cm::optional<cmLinkItem> maybeItem;
  5636. if (this->IsLinkLookupScope(n, scope->LG)) {
  5637. return maybeItem;
  5638. }
  5639. std::string name = this->CheckCMP0004(n);
  5640. if (name == this->GetName() || name.empty()) {
  5641. return maybeItem;
  5642. }
  5643. maybeItem = this->ResolveLinkItem(BT<std::string>(name, bt), scope->LG);
  5644. return maybeItem;
  5645. }
  5646. void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
  5647. std::string const& value,
  5648. std::string const& config,
  5649. cmGeneratorTarget const* headTarget,
  5650. bool usage_requirements_only,
  5651. cmLinkInterface& iface) const
  5652. {
  5653. // Keep this logic in sync with ComputeLinkImplementationLibraries.
  5654. cmGeneratorExpression ge;
  5655. cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr);
  5656. // The $<LINK_ONLY> expression may be in a link interface to specify
  5657. // private link dependencies that are otherwise excluded from usage
  5658. // requirements.
  5659. if (usage_requirements_only) {
  5660. dagChecker.SetTransitivePropertiesOnly();
  5661. }
  5662. std::vector<std::string> libs;
  5663. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  5664. cge->SetEvaluateForBuildsystem(true);
  5665. cmExpandList(cge->Evaluate(this->LocalGenerator, config, headTarget,
  5666. &dagChecker, this, headTarget->LinkerLanguage),
  5667. libs);
  5668. cmMakefile const* mf = this->LocalGenerator->GetMakefile();
  5669. LookupLinkItemScope scope{ this->LocalGenerator };
  5670. for (std::string const& lib : libs) {
  5671. if (cm::optional<cmLinkItem> maybeItem =
  5672. this->LookupLinkItem(lib, cge->GetBacktrace(), &scope)) {
  5673. cmLinkItem item = std::move(*maybeItem);
  5674. if (!item.Target) {
  5675. // Report explicitly linked object files separately.
  5676. std::string const& maybeObj = item.AsStr();
  5677. if (cmSystemTools::FileIsFullPath(maybeObj)) {
  5678. cmSourceFile const* sf =
  5679. mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
  5680. if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  5681. iface.Objects.emplace_back(std::move(item));
  5682. continue;
  5683. }
  5684. }
  5685. }
  5686. iface.Libraries.emplace_back(std::move(item));
  5687. }
  5688. }
  5689. iface.HadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  5690. iface.HadContextSensitiveCondition = cge->GetHadContextSensitiveCondition();
  5691. iface.HadLinkLanguageSensitiveCondition =
  5692. cge->GetHadLinkLanguageSensitiveCondition();
  5693. }
  5694. cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
  5695. const std::string& config, cmGeneratorTarget const* head) const
  5696. {
  5697. return this->GetLinkInterface(config, head, false);
  5698. }
  5699. cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
  5700. const std::string& config, cmGeneratorTarget const* head,
  5701. bool secondPass) const
  5702. {
  5703. // Imported targets have their own link interface.
  5704. if (this->IsImported()) {
  5705. return this->GetImportLinkInterface(config, head, false, secondPass);
  5706. }
  5707. // Link interfaces are not supported for executables that do not
  5708. // export symbols.
  5709. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  5710. !this->IsExecutableWithExports()) {
  5711. return nullptr;
  5712. }
  5713. // Lookup any existing link interface for this configuration.
  5714. cmHeadToLinkInterfaceMap& hm = this->GetHeadToLinkInterfaceMap(config);
  5715. if (secondPass) {
  5716. hm.erase(head);
  5717. }
  5718. // If the link interface does not depend on the head target
  5719. // then return the one we computed first.
  5720. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  5721. return &hm.begin()->second;
  5722. }
  5723. cmOptionalLinkInterface& iface = hm[head];
  5724. if (!iface.LibrariesDone) {
  5725. iface.LibrariesDone = true;
  5726. this->ComputeLinkInterfaceLibraries(config, iface, head, false);
  5727. }
  5728. if (!iface.AllDone) {
  5729. iface.AllDone = true;
  5730. if (iface.Exists) {
  5731. this->ComputeLinkInterface(config, iface, head, secondPass);
  5732. this->ComputeLinkInterfaceRuntimeLibraries(config, iface);
  5733. }
  5734. }
  5735. return iface.Exists ? &iface : nullptr;
  5736. }
  5737. void cmGeneratorTarget::ComputeLinkInterface(
  5738. const std::string& config, cmOptionalLinkInterface& iface,
  5739. cmGeneratorTarget const* headTarget) const
  5740. {
  5741. this->ComputeLinkInterface(config, iface, headTarget, false);
  5742. }
  5743. void cmGeneratorTarget::ComputeLinkInterface(
  5744. const std::string& config, cmOptionalLinkInterface& iface,
  5745. cmGeneratorTarget const* headTarget, bool secondPass) const
  5746. {
  5747. if (iface.Explicit) {
  5748. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5749. this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  5750. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  5751. // Shared libraries may have runtime implementation dependencies
  5752. // on other shared libraries that are not in the interface.
  5753. std::set<cmLinkItem> emitted;
  5754. for (cmLinkItem const& lib : iface.Libraries) {
  5755. emitted.insert(lib);
  5756. }
  5757. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  5758. cmLinkImplementation const* impl =
  5759. this->GetLinkImplementation(config, secondPass);
  5760. for (cmLinkImplItem const& lib : impl->Libraries) {
  5761. if (emitted.insert(lib).second) {
  5762. if (lib.Target) {
  5763. // This is a runtime dependency on another shared library.
  5764. if (lib.Target->GetType() == cmStateEnums::SHARED_LIBRARY) {
  5765. iface.SharedDeps.push_back(lib);
  5766. }
  5767. } else {
  5768. // TODO: Recognize shared library file names. Perhaps this
  5769. // should be moved to cmComputeLinkInformation, but that
  5770. // creates a chicken-and-egg problem since this list is needed
  5771. // for its construction.
  5772. }
  5773. }
  5774. }
  5775. }
  5776. }
  5777. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  5778. this->GetPolicyStatusCMP0022() == cmPolicies::OLD) {
  5779. // The link implementation is the default link interface.
  5780. cmLinkImplementationLibraries const* impl =
  5781. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  5782. iface.ImplementationIsInterface = true;
  5783. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  5784. }
  5785. if (this->LinkLanguagePropagatesToDependents()) {
  5786. // Targets using this archive need its language runtime libraries.
  5787. if (cmLinkImplementation const* impl =
  5788. this->GetLinkImplementation(config, secondPass)) {
  5789. iface.Languages = impl->Languages;
  5790. }
  5791. }
  5792. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  5793. // Construct the property name suffix for this configuration.
  5794. std::string suffix = "_";
  5795. if (!config.empty()) {
  5796. suffix += cmSystemTools::UpperCase(config);
  5797. } else {
  5798. suffix += "NOCONFIG";
  5799. }
  5800. // How many repetitions are needed if this library has cyclic
  5801. // dependencies?
  5802. std::string propName = cmStrCat("LINK_INTERFACE_MULTIPLICITY", suffix);
  5803. if (cmValue config_reps = this->GetProperty(propName)) {
  5804. sscanf(config_reps->c_str(), "%u", &iface.Multiplicity);
  5805. } else if (cmValue reps =
  5806. this->GetProperty("LINK_INTERFACE_MULTIPLICITY")) {
  5807. sscanf(reps->c_str(), "%u", &iface.Multiplicity);
  5808. }
  5809. }
  5810. }
  5811. const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
  5812. const std::string& config, cmGeneratorTarget const* head,
  5813. bool usage_requirements_only) const
  5814. {
  5815. // Imported targets have their own link interface.
  5816. if (this->IsImported()) {
  5817. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  5818. }
  5819. // Link interfaces are not supported for executables that do not
  5820. // export symbols.
  5821. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  5822. !this->IsExecutableWithExports()) {
  5823. return nullptr;
  5824. }
  5825. // Lookup any existing link interface for this configuration.
  5826. cmHeadToLinkInterfaceMap& hm =
  5827. (usage_requirements_only
  5828. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  5829. : this->GetHeadToLinkInterfaceMap(config));
  5830. // If the link interface does not depend on the head target
  5831. // then return the one we computed first.
  5832. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  5833. return &hm.begin()->second;
  5834. }
  5835. cmOptionalLinkInterface& iface = hm[head];
  5836. if (!iface.LibrariesDone) {
  5837. iface.LibrariesDone = true;
  5838. this->ComputeLinkInterfaceLibraries(config, iface, head,
  5839. usage_requirements_only);
  5840. }
  5841. return iface.Exists ? &iface : nullptr;
  5842. }
  5843. std::string cmGeneratorTarget::GetDirectory(
  5844. const std::string& config, cmStateEnums::ArtifactType artifact) const
  5845. {
  5846. if (this->IsImported()) {
  5847. auto fullPath = this->Target->ImportedGetFullPath(config, artifact);
  5848. if (this->IsFrameworkOnApple()) {
  5849. cmsys::RegularExpressionMatch match;
  5850. if (FrameworkRegularExpression.find(fullPath.c_str(), match)) {
  5851. auto path = match.match(1);
  5852. if (!path.empty()) {
  5853. path.erase(path.length() - 1);
  5854. }
  5855. return path;
  5856. }
  5857. }
  5858. // Return the directory from which the target is imported.
  5859. return cmSystemTools::GetFilenamePath(fullPath);
  5860. }
  5861. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  5862. // Return the directory in which the target will be built.
  5863. switch (artifact) {
  5864. case cmStateEnums::RuntimeBinaryArtifact:
  5865. return info->OutDir;
  5866. case cmStateEnums::ImportLibraryArtifact:
  5867. return info->ImpDir;
  5868. }
  5869. }
  5870. return "";
  5871. }
  5872. bool cmGeneratorTarget::UsesDefaultOutputDir(
  5873. const std::string& config, cmStateEnums::ArtifactType artifact) const
  5874. {
  5875. std::string dir;
  5876. return this->ComputeOutputDir(config, artifact, dir);
  5877. }
  5878. cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
  5879. const std::string& config) const
  5880. {
  5881. // There is no output information for imported targets.
  5882. if (this->IsImported()) {
  5883. return nullptr;
  5884. }
  5885. // Only libraries and executables have well-defined output files.
  5886. if (!this->HaveWellDefinedOutputFiles()) {
  5887. std::string msg = cmStrCat("cmGeneratorTarget::GetOutputInfo called for ",
  5888. this->GetName(), " which has type ",
  5889. cmState::GetTargetTypeName(this->GetType()));
  5890. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  5891. return nullptr;
  5892. }
  5893. // Lookup/compute/cache the output information for this configuration.
  5894. std::string config_upper;
  5895. if (!config.empty()) {
  5896. config_upper = cmSystemTools::UpperCase(config);
  5897. }
  5898. auto i = this->OutputInfoMap.find(config_upper);
  5899. if (i == this->OutputInfoMap.end()) {
  5900. // Add empty info in map to detect potential recursion.
  5901. OutputInfo info;
  5902. OutputInfoMapType::value_type entry(config_upper, info);
  5903. i = this->OutputInfoMap.insert(entry).first;
  5904. // Compute output directories.
  5905. this->ComputeOutputDir(config, cmStateEnums::RuntimeBinaryArtifact,
  5906. info.OutDir);
  5907. this->ComputeOutputDir(config, cmStateEnums::ImportLibraryArtifact,
  5908. info.ImpDir);
  5909. if (!this->ComputePDBOutputDir("PDB", config, info.PdbDir)) {
  5910. info.PdbDir = info.OutDir;
  5911. }
  5912. // Now update the previously-prepared map entry.
  5913. i->second = info;
  5914. } else if (i->second.empty()) {
  5915. // An empty map entry indicates we have been called recursively
  5916. // from the above block.
  5917. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  5918. MessageType::FATAL_ERROR,
  5919. "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
  5920. this->GetBacktrace());
  5921. return nullptr;
  5922. }
  5923. return &i->second;
  5924. }
  5925. bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
  5926. cmStateEnums::ArtifactType artifact,
  5927. std::string& out) const
  5928. {
  5929. bool usesDefaultOutputDir = false;
  5930. std::string conf = config;
  5931. // Look for a target property defining the target output directory
  5932. // based on the target type.
  5933. std::string targetTypeName = this->GetOutputTargetType(artifact);
  5934. std::string propertyName;
  5935. if (!targetTypeName.empty()) {
  5936. propertyName = cmStrCat(targetTypeName, "_OUTPUT_DIRECTORY");
  5937. }
  5938. // Check for a per-configuration output directory target property.
  5939. std::string configUpper = cmSystemTools::UpperCase(conf);
  5940. std::string configProp;
  5941. if (!targetTypeName.empty()) {
  5942. configProp = cmStrCat(targetTypeName, "_OUTPUT_DIRECTORY_", configUpper);
  5943. }
  5944. // Select an output directory.
  5945. if (cmValue config_outdir = this->GetProperty(configProp)) {
  5946. // Use the user-specified per-configuration output directory.
  5947. out = cmGeneratorExpression::Evaluate(*config_outdir, this->LocalGenerator,
  5948. config, this);
  5949. // Skip per-configuration subdirectory.
  5950. conf.clear();
  5951. } else if (cmValue outdir = this->GetProperty(propertyName)) {
  5952. // Use the user-specified output directory.
  5953. out = cmGeneratorExpression::Evaluate(*outdir, this->LocalGenerator,
  5954. config, this);
  5955. // Skip per-configuration subdirectory if the value contained a
  5956. // generator expression.
  5957. if (out != *outdir) {
  5958. conf.clear();
  5959. }
  5960. } else if (this->GetType() == cmStateEnums::EXECUTABLE) {
  5961. // Lookup the output path for executables.
  5962. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  5963. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  5964. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5965. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  5966. // Lookup the output path for libraries.
  5967. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  5968. }
  5969. if (out.empty()) {
  5970. // Default to the current output directory.
  5971. usesDefaultOutputDir = true;
  5972. out = ".";
  5973. }
  5974. // Convert the output path to a full path in case it is
  5975. // specified as a relative path. Treat a relative path as
  5976. // relative to the current output directory for this makefile.
  5977. out = (cmSystemTools::CollapseFullPath(
  5978. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  5979. // The generator may add the configuration's subdirectory.
  5980. if (!conf.empty()) {
  5981. bool useEPN =
  5982. this->GlobalGenerator->UseEffectivePlatformName(this->Makefile);
  5983. std::string suffix =
  5984. usesDefaultOutputDir && useEPN ? "${EFFECTIVE_PLATFORM_NAME}" : "";
  5985. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  5986. "/", conf, suffix, out);
  5987. }
  5988. return usesDefaultOutputDir;
  5989. }
  5990. bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
  5991. const std::string& config,
  5992. std::string& out) const
  5993. {
  5994. // Look for a target property defining the target output directory
  5995. // based on the target type.
  5996. std::string propertyName;
  5997. if (!kind.empty()) {
  5998. propertyName = cmStrCat(kind, "_OUTPUT_DIRECTORY");
  5999. }
  6000. std::string conf = config;
  6001. // Check for a per-configuration output directory target property.
  6002. std::string configUpper = cmSystemTools::UpperCase(conf);
  6003. std::string configProp;
  6004. if (!kind.empty()) {
  6005. configProp = cmStrCat(kind, "_OUTPUT_DIRECTORY_", configUpper);
  6006. }
  6007. // Select an output directory.
  6008. if (cmValue config_outdir = this->GetProperty(configProp)) {
  6009. // Use the user-specified per-configuration output directory.
  6010. out = cmGeneratorExpression::Evaluate(*config_outdir, this->LocalGenerator,
  6011. config);
  6012. // Skip per-configuration subdirectory.
  6013. conf.clear();
  6014. } else if (cmValue outdir = this->GetProperty(propertyName)) {
  6015. // Use the user-specified output directory.
  6016. out =
  6017. cmGeneratorExpression::Evaluate(*outdir, this->LocalGenerator, config);
  6018. // Skip per-configuration subdirectory if the value contained a
  6019. // generator expression.
  6020. if (out != *outdir) {
  6021. conf.clear();
  6022. }
  6023. }
  6024. if (out.empty()) {
  6025. return false;
  6026. }
  6027. // Convert the output path to a full path in case it is
  6028. // specified as a relative path. Treat a relative path as
  6029. // relative to the current output directory for this makefile.
  6030. out = (cmSystemTools::CollapseFullPath(
  6031. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  6032. // The generator may add the configuration's subdirectory.
  6033. if (!conf.empty()) {
  6034. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  6035. "/", conf, "", out);
  6036. }
  6037. return true;
  6038. }
  6039. bool cmGeneratorTarget::HaveInstallTreeRPATH(const std::string& config) const
  6040. {
  6041. std::string install_rpath;
  6042. this->GetInstallRPATH(config, install_rpath);
  6043. return !install_rpath.empty() &&
  6044. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  6045. }
  6046. bool cmGeneratorTarget::GetBuildRPATH(const std::string& config,
  6047. std::string& rpath) const
  6048. {
  6049. return this->GetRPATH(config, "BUILD_RPATH", rpath);
  6050. }
  6051. bool cmGeneratorTarget::GetInstallRPATH(const std::string& config,
  6052. std::string& rpath) const
  6053. {
  6054. return this->GetRPATH(config, "INSTALL_RPATH", rpath);
  6055. }
  6056. bool cmGeneratorTarget::GetRPATH(const std::string& config,
  6057. const std::string& prop,
  6058. std::string& rpath) const
  6059. {
  6060. cmValue value = this->GetProperty(prop);
  6061. if (!value) {
  6062. return false;
  6063. }
  6064. rpath =
  6065. cmGeneratorExpression::Evaluate(*value, this->LocalGenerator, config);
  6066. return true;
  6067. }
  6068. void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  6069. const std::string& config, cmOptionalLinkInterface& iface,
  6070. cmGeneratorTarget const* headTarget, bool usage_requirements_only) const
  6071. {
  6072. // Construct the property name suffix for this configuration.
  6073. std::string suffix = "_";
  6074. if (!config.empty()) {
  6075. suffix += cmSystemTools::UpperCase(config);
  6076. } else {
  6077. suffix += "NOCONFIG";
  6078. }
  6079. // An explicit list of interface libraries may be set for shared
  6080. // libraries and executables that export symbols.
  6081. cmValue explicitLibraries = nullptr;
  6082. std::string linkIfaceProp;
  6083. bool const cmp0022NEW = (this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  6084. this->GetPolicyStatusCMP0022() != cmPolicies::WARN);
  6085. if (cmp0022NEW) {
  6086. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  6087. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  6088. explicitLibraries = this->GetProperty(linkIfaceProp);
  6089. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6090. this->IsExecutableWithExports()) {
  6091. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  6092. // shared lib or executable.
  6093. // Lookup the per-configuration property.
  6094. linkIfaceProp = cmStrCat("LINK_INTERFACE_LIBRARIES", suffix);
  6095. explicitLibraries = this->GetProperty(linkIfaceProp);
  6096. // If not set, try the generic property.
  6097. if (!explicitLibraries) {
  6098. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  6099. explicitLibraries = this->GetProperty(linkIfaceProp);
  6100. }
  6101. }
  6102. if (explicitLibraries &&
  6103. this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  6104. !this->PolicyWarnedCMP0022) {
  6105. // Compare the explicitly set old link interface properties to the
  6106. // preferred new link interface property one and warn if different.
  6107. cmValue newExplicitLibraries =
  6108. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  6109. if (newExplicitLibraries &&
  6110. (*newExplicitLibraries != *explicitLibraries)) {
  6111. std::ostringstream w;
  6112. /* clang-format off */
  6113. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  6114. "Target \"" << this->GetName() << "\" has an "
  6115. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  6116. linkIfaceProp << " properties."
  6117. "\n"
  6118. "INTERFACE_LINK_LIBRARIES:\n"
  6119. " " << *newExplicitLibraries << "\n" <<
  6120. linkIfaceProp << ":\n"
  6121. " " << *explicitLibraries << "\n";
  6122. /* clang-format on */
  6123. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
  6124. this->PolicyWarnedCMP0022 = true;
  6125. }
  6126. }
  6127. // There is no implicit link interface for executables or modules
  6128. // so if none was explicitly set then there is no link interface.
  6129. if (!explicitLibraries &&
  6130. (this->GetType() == cmStateEnums::EXECUTABLE ||
  6131. (this->GetType() == cmStateEnums::MODULE_LIBRARY))) {
  6132. return;
  6133. }
  6134. iface.Exists = true;
  6135. // If CMP0022 is NEW then the plain tll signature sets the
  6136. // INTERFACE_LINK_LIBRARIES property. Even if the project
  6137. // clears it, the link interface is still explicit.
  6138. iface.Explicit = cmp0022NEW || explicitLibraries;
  6139. if (explicitLibraries) {
  6140. // The interface libraries have been explicitly set.
  6141. this->ExpandLinkItems(linkIfaceProp, *explicitLibraries, config,
  6142. headTarget, usage_requirements_only, iface);
  6143. }
  6144. // If the link interface is explicit, do not fall back to the link impl.
  6145. if (iface.Explicit) {
  6146. return;
  6147. }
  6148. // The link implementation is the default link interface.
  6149. if (cmLinkImplementationLibraries const* impl =
  6150. this->GetLinkImplementationLibrariesInternal(config, headTarget)) {
  6151. iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(),
  6152. impl->Libraries.end());
  6153. if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  6154. !this->PolicyWarnedCMP0022 && !usage_requirements_only) {
  6155. // Compare the link implementation fallback link interface to the
  6156. // preferred new link interface property and warn if different.
  6157. cmLinkInterface ifaceNew;
  6158. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  6159. if (cmValue newExplicitLibraries = this->GetProperty(newProp)) {
  6160. this->ExpandLinkItems(newProp, *newExplicitLibraries, config,
  6161. headTarget, usage_requirements_only, ifaceNew);
  6162. }
  6163. if (ifaceNew.Libraries != iface.Libraries) {
  6164. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  6165. std::string newLibraries = cmJoin(ifaceNew.Libraries, ";");
  6166. if (oldLibraries.empty()) {
  6167. oldLibraries = "(empty)";
  6168. }
  6169. if (newLibraries.empty()) {
  6170. newLibraries = "(empty)";
  6171. }
  6172. std::ostringstream w;
  6173. /* clang-format off */
  6174. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  6175. "Target \"" << this->GetName() << "\" has an "
  6176. "INTERFACE_LINK_LIBRARIES property. "
  6177. "This should be preferred as the source of the link interface "
  6178. "for this library but because CMP0022 is not set CMake is "
  6179. "ignoring the property and using the link implementation "
  6180. "as the link interface instead."
  6181. "\n"
  6182. "INTERFACE_LINK_LIBRARIES:\n"
  6183. " " << newLibraries << "\n"
  6184. "Link implementation:\n"
  6185. " " << oldLibraries << "\n";
  6186. /* clang-format on */
  6187. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING,
  6188. w.str());
  6189. this->PolicyWarnedCMP0022 = true;
  6190. }
  6191. }
  6192. }
  6193. }
  6194. namespace {
  6195. template <typename ReturnType>
  6196. ReturnType constructItem(cmGeneratorTarget* target,
  6197. cmListFileBacktrace const& bt);
  6198. template <>
  6199. inline cmLinkImplItem constructItem(cmGeneratorTarget* target,
  6200. cmListFileBacktrace const& bt)
  6201. {
  6202. return cmLinkImplItem(cmLinkItem(target, false, bt), false);
  6203. }
  6204. template <>
  6205. inline cmLinkItem constructItem(cmGeneratorTarget* target,
  6206. cmListFileBacktrace const& bt)
  6207. {
  6208. return cmLinkItem(target, false, bt);
  6209. }
  6210. template <typename ValueType>
  6211. std::vector<ValueType> computeImplicitLanguageTargets(
  6212. std::string const& lang, std::string const& config,
  6213. cmGeneratorTarget const* currentTarget)
  6214. {
  6215. cmListFileBacktrace bt;
  6216. std::vector<ValueType> result;
  6217. cmLocalGenerator* lg = currentTarget->GetLocalGenerator();
  6218. std::string const& runtimeLibrary =
  6219. currentTarget->GetRuntimeLinkLibrary(lang, config);
  6220. if (cmValue runtimeLinkOptions = currentTarget->Makefile->GetDefinition(
  6221. "CMAKE_" + lang + "_RUNTIME_LIBRARIES_" + runtimeLibrary)) {
  6222. std::vector<std::string> libsVec = cmExpandedList(*runtimeLinkOptions);
  6223. result.reserve(libsVec.size());
  6224. for (std::string const& i : libsVec) {
  6225. cmGeneratorTarget::TargetOrString resolved =
  6226. currentTarget->ResolveTargetReference(i, lg);
  6227. if (resolved.Target) {
  6228. result.emplace_back(constructItem<ValueType>(resolved.Target, bt));
  6229. }
  6230. }
  6231. }
  6232. return result;
  6233. }
  6234. }
  6235. void cmGeneratorTarget::ComputeLinkInterfaceRuntimeLibraries(
  6236. const std::string& config, cmOptionalLinkInterface& iface) const
  6237. {
  6238. for (std::string const& lang : iface.Languages) {
  6239. if ((lang == "CUDA" || lang == "HIP") &&
  6240. iface.LanguageRuntimeLibraries.find(lang) ==
  6241. iface.LanguageRuntimeLibraries.end()) {
  6242. auto implicitTargets =
  6243. computeImplicitLanguageTargets<cmLinkItem>(lang, config, this);
  6244. iface.LanguageRuntimeLibraries[lang] = std::move(implicitTargets);
  6245. }
  6246. }
  6247. }
  6248. void cmGeneratorTarget::ComputeLinkImplementationRuntimeLibraries(
  6249. const std::string& config, cmOptionalLinkImplementation& impl) const
  6250. {
  6251. for (std::string const& lang : impl.Languages) {
  6252. if ((lang == "CUDA" || lang == "HIP") &&
  6253. impl.LanguageRuntimeLibraries.find(lang) ==
  6254. impl.LanguageRuntimeLibraries.end()) {
  6255. auto implicitTargets =
  6256. computeImplicitLanguageTargets<cmLinkImplItem>(lang, config, this);
  6257. impl.LanguageRuntimeLibraries[lang] = std::move(implicitTargets);
  6258. }
  6259. }
  6260. }
  6261. const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
  6262. const std::string& config, cmGeneratorTarget const* headTarget,
  6263. bool usage_requirements_only, bool secondPass) const
  6264. {
  6265. cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
  6266. if (!info) {
  6267. return nullptr;
  6268. }
  6269. cmHeadToLinkInterfaceMap& hm =
  6270. (usage_requirements_only
  6271. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  6272. : this->GetHeadToLinkInterfaceMap(config));
  6273. if (secondPass) {
  6274. hm.erase(headTarget);
  6275. }
  6276. // If the link interface does not depend on the head target
  6277. // then return the one we computed first.
  6278. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  6279. return &hm.begin()->second;
  6280. }
  6281. cmOptionalLinkInterface& iface = hm[headTarget];
  6282. if (!iface.AllDone) {
  6283. iface.AllDone = true;
  6284. iface.Multiplicity = info->Multiplicity;
  6285. cmExpandList(info->Languages, iface.Languages);
  6286. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  6287. headTarget, usage_requirements_only, iface);
  6288. std::vector<std::string> deps = cmExpandedList(info->SharedDeps);
  6289. LookupLinkItemScope scope{ this->LocalGenerator };
  6290. for (std::string const& dep : deps) {
  6291. if (cm::optional<cmLinkItem> maybeItem =
  6292. this->LookupLinkItem(dep, cmListFileBacktrace(), &scope)) {
  6293. iface.SharedDeps.emplace_back(std::move(*maybeItem));
  6294. }
  6295. }
  6296. }
  6297. return &iface;
  6298. }
  6299. cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo(
  6300. const std::string& config) const
  6301. {
  6302. // There is no imported information for non-imported targets.
  6303. if (!this->IsImported()) {
  6304. return nullptr;
  6305. }
  6306. // Lookup/compute/cache the import information for this
  6307. // configuration.
  6308. std::string config_upper;
  6309. if (!config.empty()) {
  6310. config_upper = cmSystemTools::UpperCase(config);
  6311. } else {
  6312. config_upper = "NOCONFIG";
  6313. }
  6314. auto i = this->ImportInfoMap.find(config_upper);
  6315. if (i == this->ImportInfoMap.end()) {
  6316. ImportInfo info;
  6317. this->ComputeImportInfo(config_upper, info);
  6318. ImportInfoMapType::value_type entry(config_upper, info);
  6319. i = this->ImportInfoMap.insert(entry).first;
  6320. }
  6321. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  6322. return &i->second;
  6323. }
  6324. // If the location is empty then the target is not available for
  6325. // this configuration.
  6326. if (i->second.Location.empty() && i->second.ImportLibrary.empty()) {
  6327. return nullptr;
  6328. }
  6329. // Return the import information.
  6330. return &i->second;
  6331. }
  6332. void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
  6333. ImportInfo& info) const
  6334. {
  6335. // This method finds information about an imported target from its
  6336. // properties. The "IMPORTED_" namespace is reserved for properties
  6337. // defined by the project exporting the target.
  6338. // Initialize members.
  6339. info.NoSOName = false;
  6340. cmValue loc = nullptr;
  6341. cmValue imp = nullptr;
  6342. std::string suffix;
  6343. if (!this->Target->GetMappedConfig(desired_config, loc, imp, suffix)) {
  6344. return;
  6345. }
  6346. // Get the link interface.
  6347. {
  6348. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  6349. cmValue propertyLibs = this->GetProperty(linkProp);
  6350. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  6351. if (!propertyLibs) {
  6352. linkProp = cmStrCat("IMPORTED_LINK_INTERFACE_LIBRARIES", suffix);
  6353. propertyLibs = this->GetProperty(linkProp);
  6354. }
  6355. if (!propertyLibs) {
  6356. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  6357. propertyLibs = this->GetProperty(linkProp);
  6358. }
  6359. }
  6360. if (propertyLibs) {
  6361. info.LibrariesProp = linkProp;
  6362. info.Libraries = *propertyLibs;
  6363. }
  6364. }
  6365. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  6366. if (loc) {
  6367. info.LibName = *loc;
  6368. }
  6369. return;
  6370. }
  6371. // A provided configuration has been chosen. Load the
  6372. // configuration's properties.
  6373. // Get the location.
  6374. if (loc) {
  6375. info.Location = *loc;
  6376. } else {
  6377. std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix);
  6378. if (cmValue config_location = this->GetProperty(impProp)) {
  6379. info.Location = *config_location;
  6380. } else if (cmValue location = this->GetProperty("IMPORTED_LOCATION")) {
  6381. info.Location = *location;
  6382. }
  6383. }
  6384. // Get the soname.
  6385. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  6386. std::string soProp = cmStrCat("IMPORTED_SONAME", suffix);
  6387. if (cmValue config_soname = this->GetProperty(soProp)) {
  6388. info.SOName = *config_soname;
  6389. } else if (cmValue soname = this->GetProperty("IMPORTED_SONAME")) {
  6390. info.SOName = *soname;
  6391. }
  6392. }
  6393. // Get the "no-soname" mark.
  6394. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  6395. std::string soProp = cmStrCat("IMPORTED_NO_SONAME", suffix);
  6396. if (cmValue config_no_soname = this->GetProperty(soProp)) {
  6397. info.NoSOName = cmIsOn(*config_no_soname);
  6398. } else if (cmValue no_soname = this->GetProperty("IMPORTED_NO_SONAME")) {
  6399. info.NoSOName = cmIsOn(*no_soname);
  6400. }
  6401. }
  6402. // Get the import library.
  6403. if (imp) {
  6404. info.ImportLibrary = *imp;
  6405. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6406. this->IsExecutableWithExports()) {
  6407. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  6408. if (cmValue config_implib = this->GetProperty(impProp)) {
  6409. info.ImportLibrary = *config_implib;
  6410. } else if (cmValue implib = this->GetProperty("IMPORTED_IMPLIB")) {
  6411. info.ImportLibrary = *implib;
  6412. }
  6413. }
  6414. // Get the link dependencies.
  6415. {
  6416. std::string linkProp =
  6417. cmStrCat("IMPORTED_LINK_DEPENDENT_LIBRARIES", suffix);
  6418. if (cmValue config_libs = this->GetProperty(linkProp)) {
  6419. info.SharedDeps = *config_libs;
  6420. } else if (cmValue libs =
  6421. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES")) {
  6422. info.SharedDeps = *libs;
  6423. }
  6424. }
  6425. // Get the link languages.
  6426. if (this->LinkLanguagePropagatesToDependents()) {
  6427. std::string linkProp =
  6428. cmStrCat("IMPORTED_LINK_INTERFACE_LANGUAGES", suffix);
  6429. if (cmValue config_libs = this->GetProperty(linkProp)) {
  6430. info.Languages = *config_libs;
  6431. } else if (cmValue libs =
  6432. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES")) {
  6433. info.Languages = *libs;
  6434. }
  6435. }
  6436. // Get information if target is managed assembly.
  6437. {
  6438. std::string linkProp = "IMPORTED_COMMON_LANGUAGE_RUNTIME";
  6439. if (cmValue pc = this->GetProperty(linkProp + suffix)) {
  6440. info.Managed = this->CheckManagedType(*pc);
  6441. } else if (cmValue p = this->GetProperty(linkProp)) {
  6442. info.Managed = this->CheckManagedType(*p);
  6443. }
  6444. }
  6445. // Get the cyclic repetition count.
  6446. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  6447. std::string linkProp =
  6448. cmStrCat("IMPORTED_LINK_INTERFACE_MULTIPLICITY", suffix);
  6449. if (cmValue config_reps = this->GetProperty(linkProp)) {
  6450. sscanf(config_reps->c_str(), "%u", &info.Multiplicity);
  6451. } else if (cmValue reps =
  6452. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY")) {
  6453. sscanf(reps->c_str(), "%u", &info.Multiplicity);
  6454. }
  6455. }
  6456. }
  6457. cmHeadToLinkInterfaceMap& cmGeneratorTarget::GetHeadToLinkInterfaceMap(
  6458. const std::string& config) const
  6459. {
  6460. return this->LinkInterfaceMap[cmSystemTools::UpperCase(config)];
  6461. }
  6462. cmHeadToLinkInterfaceMap&
  6463. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  6464. const std::string& config) const
  6465. {
  6466. return this
  6467. ->LinkInterfaceUsageRequirementsOnlyMap[cmSystemTools::UpperCase(config)];
  6468. }
  6469. const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
  6470. const std::string& config) const
  6471. {
  6472. return this->GetLinkImplementation(config, false);
  6473. }
  6474. const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
  6475. const std::string& config, bool secondPass) const
  6476. {
  6477. // There is no link implementation for targets that cannot compile sources.
  6478. if (!this->CanCompileSources()) {
  6479. return nullptr;
  6480. }
  6481. cmOptionalLinkImplementation& impl =
  6482. this->LinkImplMap[cmSystemTools::UpperCase(config)][this];
  6483. if (secondPass) {
  6484. impl = cmOptionalLinkImplementation();
  6485. }
  6486. if (!impl.LibrariesDone) {
  6487. impl.LibrariesDone = true;
  6488. this->ComputeLinkImplementationLibraries(config, impl, this);
  6489. }
  6490. if (!impl.LanguagesDone) {
  6491. impl.LanguagesDone = true;
  6492. this->ComputeLinkImplementationLanguages(config, impl);
  6493. this->ComputeLinkImplementationRuntimeLibraries(config, impl);
  6494. }
  6495. return &impl;
  6496. }
  6497. bool cmGeneratorTarget::GetConfigCommonSourceFilesForXcode(
  6498. std::vector<cmSourceFile*>& files) const
  6499. {
  6500. std::vector<std::string> const& configs =
  6501. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  6502. auto it = configs.begin();
  6503. const std::string& firstConfig = *it;
  6504. this->GetSourceFilesWithoutObjectLibraries(files, firstConfig);
  6505. for (; it != configs.end(); ++it) {
  6506. std::vector<cmSourceFile*> configFiles;
  6507. this->GetSourceFilesWithoutObjectLibraries(configFiles, *it);
  6508. if (configFiles != files) {
  6509. std::string firstConfigFiles;
  6510. const char* sep = "";
  6511. for (cmSourceFile* f : files) {
  6512. firstConfigFiles += sep;
  6513. firstConfigFiles += f->ResolveFullPath();
  6514. sep = "\n ";
  6515. }
  6516. std::string thisConfigFiles;
  6517. sep = "";
  6518. for (cmSourceFile* f : configFiles) {
  6519. thisConfigFiles += sep;
  6520. thisConfigFiles += f->ResolveFullPath();
  6521. sep = "\n ";
  6522. }
  6523. std::ostringstream e;
  6524. /* clang-format off */
  6525. e << "Target \"" << this->GetName()
  6526. << "\" has source files which vary by "
  6527. "configuration. This is not supported by the \""
  6528. << this->GlobalGenerator->GetName()
  6529. << "\" generator.\n"
  6530. "Config \"" << firstConfig << "\":\n"
  6531. " " << firstConfigFiles << "\n"
  6532. "Config \"" << *it << "\":\n"
  6533. " " << thisConfigFiles << "\n";
  6534. /* clang-format on */
  6535. this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
  6536. return false;
  6537. }
  6538. }
  6539. return true;
  6540. }
  6541. void cmGeneratorTarget::GetObjectLibrariesCMP0026(
  6542. std::vector<cmGeneratorTarget*>& objlibs) const
  6543. {
  6544. // At configure-time, this method can be called as part of getting the
  6545. // LOCATION property or to export() a file to be include()d. However
  6546. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  6547. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  6548. // behavior of CMP0024 and CMP0026 only.
  6549. cmBTStringRange rng = this->Target->GetSourceEntries();
  6550. for (auto const& entry : rng) {
  6551. std::vector<std::string> files = cmExpandedList(entry.Value);
  6552. for (std::string const& li : files) {
  6553. if (cmHasLiteralPrefix(li, "$<TARGET_OBJECTS:") && li.back() == '>') {
  6554. std::string objLibName = li.substr(17, li.size() - 18);
  6555. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  6556. continue;
  6557. }
  6558. cmGeneratorTarget* objLib =
  6559. this->LocalGenerator->FindGeneratorTargetToUse(objLibName);
  6560. if (objLib) {
  6561. objlibs.push_back(objLib);
  6562. }
  6563. }
  6564. }
  6565. }
  6566. }
  6567. std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
  6568. {
  6569. // Strip whitespace off the library names because we used to do this
  6570. // in case variables were expanded at generate time. We no longer
  6571. // do the expansion but users link to libraries like " ${VAR} ".
  6572. std::string lib = item;
  6573. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  6574. if (pos != std::string::npos) {
  6575. lib = lib.substr(pos);
  6576. }
  6577. pos = lib.find_last_not_of(" \t\r\n");
  6578. if (pos != std::string::npos) {
  6579. lib = lib.substr(0, pos + 1);
  6580. }
  6581. if (lib != item) {
  6582. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  6583. switch (this->GetPolicyStatusCMP0004()) {
  6584. case cmPolicies::WARN: {
  6585. std::ostringstream w;
  6586. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  6587. << "Target \"" << this->GetName() << "\" links to item \"" << item
  6588. << "\" which has leading or trailing whitespace.";
  6589. cm->IssueMessage(MessageType::AUTHOR_WARNING, w.str(),
  6590. this->GetBacktrace());
  6591. }
  6592. case cmPolicies::OLD:
  6593. break;
  6594. case cmPolicies::NEW: {
  6595. std::ostringstream e;
  6596. e << "Target \"" << this->GetName() << "\" links to item \"" << item
  6597. << "\" which has leading or trailing whitespace. "
  6598. << "This is now an error according to policy CMP0004.";
  6599. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  6600. this->GetBacktrace());
  6601. } break;
  6602. case cmPolicies::REQUIRED_IF_USED:
  6603. case cmPolicies::REQUIRED_ALWAYS: {
  6604. std::ostringstream e;
  6605. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  6606. << "Target \"" << this->GetName() << "\" links to item \"" << item
  6607. << "\" which has leading or trailing whitespace.";
  6608. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  6609. this->GetBacktrace());
  6610. } break;
  6611. }
  6612. }
  6613. return lib;
  6614. }
  6615. bool cmGeneratorTarget::IsDeprecated() const
  6616. {
  6617. cmValue deprecation = this->GetProperty("DEPRECATION");
  6618. return cmNonempty(deprecation);
  6619. }
  6620. std::string cmGeneratorTarget::GetDeprecation() const
  6621. {
  6622. // find DEPRECATION property
  6623. if (cmValue deprecation = this->GetProperty("DEPRECATION")) {
  6624. return *deprecation;
  6625. }
  6626. return std::string();
  6627. }
  6628. void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
  6629. const std::string& config) const
  6630. {
  6631. // Targets that do not compile anything have no languages.
  6632. if (!this->CanCompileSources()) {
  6633. return;
  6634. }
  6635. std::vector<cmSourceFile*> sourceFiles;
  6636. this->GetSourceFiles(sourceFiles, config);
  6637. for (cmSourceFile* src : sourceFiles) {
  6638. const std::string& lang = src->GetOrDetermineLanguage();
  6639. if (!lang.empty()) {
  6640. languages.insert(lang);
  6641. }
  6642. }
  6643. std::vector<cmGeneratorTarget*> objectLibraries;
  6644. std::vector<cmSourceFile const*> externalObjects;
  6645. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  6646. std::vector<cmGeneratorTarget*> objectTargets;
  6647. this->GetObjectLibrariesCMP0026(objectTargets);
  6648. objectLibraries.reserve(objectTargets.size());
  6649. for (cmGeneratorTarget* gt : objectTargets) {
  6650. objectLibraries.push_back(gt);
  6651. }
  6652. } else {
  6653. this->GetExternalObjects(externalObjects, config);
  6654. for (cmSourceFile const* extObj : externalObjects) {
  6655. std::string objLib = extObj->GetObjectLibrary();
  6656. if (cmGeneratorTarget* tgt =
  6657. this->LocalGenerator->FindGeneratorTargetToUse(objLib)) {
  6658. auto const objLibIt =
  6659. std::find_if(objectLibraries.cbegin(), objectLibraries.cend(),
  6660. [tgt](cmGeneratorTarget* t) { return t == tgt; });
  6661. if (objectLibraries.cend() == objLibIt) {
  6662. objectLibraries.push_back(tgt);
  6663. }
  6664. }
  6665. }
  6666. }
  6667. for (cmGeneratorTarget* objLib : objectLibraries) {
  6668. objLib->GetLanguages(languages, config);
  6669. }
  6670. }
  6671. bool cmGeneratorTarget::IsLanguageUsed(std::string const& language,
  6672. std::string const& config) const
  6673. {
  6674. std::set<std::string> languages;
  6675. this->GetLanguages(languages, config);
  6676. return languages.count(language);
  6677. }
  6678. bool cmGeneratorTarget::IsCSharpOnly() const
  6679. {
  6680. // Only certain target types may compile CSharp.
  6681. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  6682. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  6683. this->GetType() != cmStateEnums::EXECUTABLE) {
  6684. return false;
  6685. }
  6686. std::set<std::string> languages = this->GetAllConfigCompileLanguages();
  6687. // Consider an explicit linker language property, but *not* the
  6688. // computed linker language that may depend on linked targets.
  6689. cmValue linkLang = this->GetProperty("LINKER_LANGUAGE");
  6690. if (cmNonempty(linkLang)) {
  6691. languages.insert(*linkLang);
  6692. }
  6693. return languages.size() == 1 && languages.count("CSharp") > 0;
  6694. }
  6695. void cmGeneratorTarget::ComputeLinkImplementationLanguages(
  6696. const std::string& config, cmOptionalLinkImplementation& impl) const
  6697. {
  6698. // This target needs runtime libraries for its source languages.
  6699. std::set<std::string> languages;
  6700. // Get languages used in our source files.
  6701. this->GetLanguages(languages, config);
  6702. // Copy the set of languages to the link implementation.
  6703. impl.Languages.insert(impl.Languages.begin(), languages.begin(),
  6704. languages.end());
  6705. }
  6706. bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
  6707. {
  6708. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH")) {
  6709. return false;
  6710. }
  6711. std::string build_rpath;
  6712. if (this->GetBuildRPATH(config, build_rpath)) {
  6713. return true;
  6714. }
  6715. if (cmLinkImplementationLibraries const* impl =
  6716. this->GetLinkImplementationLibraries(config)) {
  6717. return !impl->Libraries.empty();
  6718. }
  6719. return false;
  6720. }
  6721. cmLinkImplementationLibraries const*
  6722. cmGeneratorTarget::GetLinkImplementationLibraries(
  6723. const std::string& config) const
  6724. {
  6725. return this->GetLinkImplementationLibrariesInternal(config, this);
  6726. }
  6727. cmLinkImplementationLibraries const*
  6728. cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
  6729. const std::string& config, cmGeneratorTarget const* head) const
  6730. {
  6731. // There is no link implementation for targets that cannot compile sources.
  6732. if (!this->CanCompileSources()) {
  6733. return nullptr;
  6734. }
  6735. // Populate the link implementation libraries for this configuration.
  6736. HeadToLinkImplementationMap& hm =
  6737. this->LinkImplMap[cmSystemTools::UpperCase(config)];
  6738. // If the link implementation does not depend on the head target
  6739. // then return the one we computed first.
  6740. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  6741. return &hm.begin()->second;
  6742. }
  6743. cmOptionalLinkImplementation& impl = hm[head];
  6744. if (!impl.LibrariesDone) {
  6745. impl.LibrariesDone = true;
  6746. this->ComputeLinkImplementationLibraries(config, impl, head);
  6747. }
  6748. return &impl;
  6749. }
  6750. bool cmGeneratorTarget::IsNullImpliedByLinkLibraries(
  6751. const std::string& p) const
  6752. {
  6753. return cm::contains(this->LinkImplicitNullProperties, p);
  6754. }
  6755. void cmGeneratorTarget::ComputeLinkImplementationLibraries(
  6756. const std::string& config, cmOptionalLinkImplementation& impl,
  6757. cmGeneratorTarget const* head) const
  6758. {
  6759. cmLocalGenerator const* lg = this->LocalGenerator;
  6760. cmMakefile const* mf = lg->GetMakefile();
  6761. cmBTStringRange entryRange = this->Target->GetLinkImplementationEntries();
  6762. // Collect libraries directly linked in this configuration.
  6763. for (auto const& entry : entryRange) {
  6764. std::vector<std::string> llibs;
  6765. // Keep this logic in sync with ExpandLinkItems.
  6766. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr,
  6767. nullptr);
  6768. cmGeneratorExpression ge(entry.Backtrace);
  6769. std::unique_ptr<cmCompiledGeneratorExpression> const cge =
  6770. ge.Parse(entry.Value);
  6771. cge->SetEvaluateForBuildsystem(true);
  6772. std::string const& evaluated =
  6773. cge->Evaluate(this->LocalGenerator, config, head, &dagChecker, nullptr,
  6774. this->LinkerLanguage);
  6775. bool const fromGenex = evaluated != entry.Value;
  6776. cmExpandList(evaluated, llibs);
  6777. if (cge->GetHadHeadSensitiveCondition()) {
  6778. impl.HadHeadSensitiveCondition = true;
  6779. }
  6780. if (cge->GetHadContextSensitiveCondition()) {
  6781. impl.HadContextSensitiveCondition = true;
  6782. }
  6783. if (cge->GetHadLinkLanguageSensitiveCondition()) {
  6784. impl.HadLinkLanguageSensitiveCondition = true;
  6785. }
  6786. for (std::string const& lib : llibs) {
  6787. if (this->IsLinkLookupScope(lib, lg)) {
  6788. continue;
  6789. }
  6790. // Skip entries that resolve to the target itself or are empty.
  6791. std::string name = this->CheckCMP0004(lib);
  6792. if (this->GetPolicyStatusCMP0108() == cmPolicies::NEW) {
  6793. // resolve alias name
  6794. auto* target = this->Makefile->FindTargetToUse(name);
  6795. if (target) {
  6796. name = target->GetName();
  6797. }
  6798. }
  6799. if (name == this->GetName() || name.empty()) {
  6800. if (name == this->GetName()) {
  6801. bool noMessage = false;
  6802. MessageType messageType = MessageType::FATAL_ERROR;
  6803. std::ostringstream e;
  6804. switch (this->GetPolicyStatusCMP0038()) {
  6805. case cmPolicies::WARN: {
  6806. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  6807. messageType = MessageType::AUTHOR_WARNING;
  6808. } break;
  6809. case cmPolicies::OLD:
  6810. noMessage = true;
  6811. case cmPolicies::REQUIRED_IF_USED:
  6812. case cmPolicies::REQUIRED_ALWAYS:
  6813. case cmPolicies::NEW:
  6814. // Issue the fatal message.
  6815. break;
  6816. }
  6817. if (!noMessage) {
  6818. e << "Target \"" << this->GetName() << "\" links to itself.";
  6819. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  6820. messageType, e.str(), this->GetBacktrace());
  6821. if (messageType == MessageType::FATAL_ERROR) {
  6822. return;
  6823. }
  6824. }
  6825. }
  6826. continue;
  6827. }
  6828. // The entry is meant for this configuration.
  6829. cmLinkItem item =
  6830. this->ResolveLinkItem(BT<std::string>(name, entry.Backtrace), lg);
  6831. if (!item.Target) {
  6832. // Report explicitly linked object files separately.
  6833. std::string const& maybeObj = item.AsStr();
  6834. if (cmSystemTools::FileIsFullPath(maybeObj)) {
  6835. cmSourceFile const* sf =
  6836. mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
  6837. if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  6838. impl.Objects.emplace_back(std::move(item));
  6839. continue;
  6840. }
  6841. }
  6842. }
  6843. impl.Libraries.emplace_back(std::move(item), fromGenex);
  6844. }
  6845. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  6846. for (std::string const& sp : seenProps) {
  6847. if (!this->GetProperty(sp)) {
  6848. this->LinkImplicitNullProperties.insert(sp);
  6849. }
  6850. }
  6851. cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards);
  6852. }
  6853. // Get the list of configurations considered to be DEBUG.
  6854. std::vector<std::string> debugConfigs =
  6855. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  6856. cmTargetLinkLibraryType linkType =
  6857. CMP0003_ComputeLinkType(config, debugConfigs);
  6858. cmTarget::LinkLibraryVectorType const& oldllibs =
  6859. this->Target->GetOriginalLinkLibraries();
  6860. for (cmTarget::LibraryID const& oldllib : oldllibs) {
  6861. if (oldllib.second != GENERAL_LibraryType && oldllib.second != linkType) {
  6862. std::string name = this->CheckCMP0004(oldllib.first);
  6863. if (name == this->GetName() || name.empty()) {
  6864. continue;
  6865. }
  6866. // Support OLD behavior for CMP0003.
  6867. impl.WrongConfigLibraries.push_back(
  6868. this->ResolveLinkItem(BT<std::string>(name)));
  6869. }
  6870. }
  6871. }
  6872. cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
  6873. std::string const& name) const
  6874. {
  6875. return this->ResolveTargetReference(name, this->LocalGenerator);
  6876. }
  6877. cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
  6878. std::string const& name, cmLocalGenerator const* lg) const
  6879. {
  6880. TargetOrString resolved;
  6881. if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(name)) {
  6882. resolved.Target = tgt;
  6883. } else {
  6884. resolved.String = name;
  6885. }
  6886. return resolved;
  6887. }
  6888. cmLinkItem cmGeneratorTarget::ResolveLinkItem(
  6889. BT<std::string> const& name) const
  6890. {
  6891. return this->ResolveLinkItem(name, this->LocalGenerator);
  6892. }
  6893. cmLinkItem cmGeneratorTarget::ResolveLinkItem(BT<std::string> const& name,
  6894. cmLocalGenerator const* lg) const
  6895. {
  6896. auto bt = name.Backtrace;
  6897. TargetOrString resolved = this->ResolveTargetReference(name.Value, lg);
  6898. if (!resolved.Target) {
  6899. return cmLinkItem(resolved.String, false, bt);
  6900. }
  6901. // Check deprecation, issue message with `bt` backtrace.
  6902. if (resolved.Target->IsDeprecated()) {
  6903. std::ostringstream w;
  6904. /* clang-format off */
  6905. w <<
  6906. "The library that is being linked to, " << resolved.Target->GetName() <<
  6907. ", is marked as being deprecated by the owner. The message provided by "
  6908. "the developer is: \n" << resolved.Target->GetDeprecation() << "\n";
  6909. /* clang-format on */
  6910. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  6911. MessageType::AUTHOR_WARNING, w.str(), bt);
  6912. }
  6913. // Skip targets that will not really be linked. This is probably a
  6914. // name conflict between an external library and an executable
  6915. // within the project.
  6916. if (resolved.Target->GetType() == cmStateEnums::EXECUTABLE &&
  6917. !resolved.Target->IsExecutableWithExports()) {
  6918. return cmLinkItem(resolved.Target->GetName(), false, bt);
  6919. }
  6920. return cmLinkItem(resolved.Target, false, bt);
  6921. }
  6922. std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
  6923. {
  6924. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  6925. // Return the directory in which the target will be built.
  6926. return info->PdbDir;
  6927. }
  6928. return "";
  6929. }
  6930. bool cmGeneratorTarget::HasImplibGNUtoMS(std::string const& config) const
  6931. {
  6932. return this->HasImportLibrary(config) && this->GetPropertyAsBool("GNUtoMS");
  6933. }
  6934. bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& config,
  6935. std::string const& gnuName,
  6936. std::string& out,
  6937. const char* newExt) const
  6938. {
  6939. if (this->HasImplibGNUtoMS(config) && gnuName.size() > 6 &&
  6940. gnuName.substr(gnuName.size() - 6) == ".dll.a") {
  6941. out = cmStrCat(cm::string_view(gnuName).substr(0, gnuName.size() - 6),
  6942. newExt ? newExt : ".lib");
  6943. return true;
  6944. }
  6945. return false;
  6946. }
  6947. bool cmGeneratorTarget::HasContextDependentSources() const
  6948. {
  6949. return this->SourcesAreContextDependent == Tribool::True;
  6950. }
  6951. bool cmGeneratorTarget::IsExecutableWithExports() const
  6952. {
  6953. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  6954. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  6955. }
  6956. bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const
  6957. {
  6958. return (this->IsDLLPlatform() &&
  6959. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6960. this->IsExecutableWithExports()) &&
  6961. // Assemblies which have only managed code do not have
  6962. // import libraries.
  6963. this->GetManagedType(config) != ManagedType::Managed) ||
  6964. (this->Target->IsAIX() && this->IsExecutableWithExports());
  6965. }
  6966. bool cmGeneratorTarget::NeedImportLibraryName(std::string const& config) const
  6967. {
  6968. return this->HasImportLibrary(config) ||
  6969. // On DLL platforms we always generate the import library name
  6970. // just in case the sources have export markup.
  6971. (this->IsDLLPlatform() &&
  6972. (this->GetType() == cmStateEnums::EXECUTABLE ||
  6973. this->GetType() == cmStateEnums::MODULE_LIBRARY));
  6974. }
  6975. std::string cmGeneratorTarget::GetSupportDirectory() const
  6976. {
  6977. std::string dir = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(),
  6978. "/CMakeFiles/", this->GetName());
  6979. #if defined(__VMS)
  6980. dir += "_dir";
  6981. #else
  6982. dir += ".dir";
  6983. #endif
  6984. return dir;
  6985. }
  6986. bool cmGeneratorTarget::IsLinkable() const
  6987. {
  6988. return (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  6989. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6990. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  6991. this->GetType() == cmStateEnums::UNKNOWN_LIBRARY ||
  6992. this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  6993. this->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
  6994. this->IsExecutableWithExports());
  6995. }
  6996. bool cmGeneratorTarget::IsFrameworkOnApple() const
  6997. {
  6998. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6999. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  7000. this->Makefile->IsOn("APPLE") &&
  7001. this->GetPropertyAsBool("FRAMEWORK"));
  7002. }
  7003. bool cmGeneratorTarget::IsAppBundleOnApple() const
  7004. {
  7005. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  7006. this->Makefile->IsOn("APPLE") &&
  7007. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  7008. }
  7009. bool cmGeneratorTarget::IsXCTestOnApple() const
  7010. {
  7011. return (this->IsCFBundleOnApple() && this->GetPropertyAsBool("XCTEST"));
  7012. }
  7013. bool cmGeneratorTarget::IsCFBundleOnApple() const
  7014. {
  7015. return (this->GetType() == cmStateEnums::MODULE_LIBRARY &&
  7016. this->Makefile->IsOn("APPLE") && this->GetPropertyAsBool("BUNDLE"));
  7017. }
  7018. cmGeneratorTarget::ManagedType cmGeneratorTarget::CheckManagedType(
  7019. std::string const& propval) const
  7020. {
  7021. // The type of the managed assembly (mixed unmanaged C++ and C++/CLI,
  7022. // or only C++/CLI) does only depend on whether the property is an empty
  7023. // string or contains any value at all. In Visual Studio generators
  7024. // this propval is prepended with /clr[:] which results in:
  7025. //
  7026. // 1. propval does not exist: no /clr flag, unmanaged target, has import
  7027. // lib
  7028. // 2. empty propval: add /clr as flag, mixed unmanaged/managed
  7029. // target, has import lib
  7030. // 3. any value (safe,pure): add /clr:[propval] as flag, target with
  7031. // managed code only, no import lib
  7032. return propval.empty() ? ManagedType::Mixed : ManagedType::Managed;
  7033. }
  7034. cmGeneratorTarget::ManagedType cmGeneratorTarget::GetManagedType(
  7035. const std::string& config) const
  7036. {
  7037. // Only libraries and executables can be managed targets.
  7038. if (this->GetType() > cmStateEnums::SHARED_LIBRARY) {
  7039. return ManagedType::Undefined;
  7040. }
  7041. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  7042. return ManagedType::Native;
  7043. }
  7044. // Check imported target.
  7045. if (this->IsImported()) {
  7046. if (cmGeneratorTarget::ImportInfo const* info =
  7047. this->GetImportInfo(config)) {
  7048. return info->Managed;
  7049. }
  7050. return ManagedType::Undefined;
  7051. }
  7052. // Check for explicitly set clr target property.
  7053. if (cmValue clr = this->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  7054. return this->CheckManagedType(*clr);
  7055. }
  7056. // C# targets are always managed. This language specific check
  7057. // is added to avoid that the COMMON_LANGUAGE_RUNTIME target property
  7058. // has to be set manually for C# targets.
  7059. return this->IsCSharpOnly() ? ManagedType::Managed : ManagedType::Native;
  7060. }