cmGeneratorTarget.cxx 264 KB

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