cmGeneratorTarget.cxx 264 KB

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