cmGeneratorTarget.cxx 264 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGeneratorTarget.h"
  4. #include <algorithm>
  5. #include <cassert>
  6. #include <cerrno>
  7. #include <cstddef>
  8. #include <cstdio>
  9. #include <cstdlib>
  10. #include <cstring>
  11. #include <iterator>
  12. #include <queue>
  13. #include <sstream>
  14. #include <unordered_set>
  15. #include <utility>
  16. #include <cm/memory>
  17. #include <cm/string_view>
  18. #include <cmext/algorithm>
  19. #include <cmext/string_view>
  20. #include "cmsys/RegularExpression.hxx"
  21. #include "cmAlgorithms.h"
  22. #include "cmComputeLinkInformation.h"
  23. #include "cmCustomCommandGenerator.h"
  24. #include "cmFileTimes.h"
  25. #include "cmGeneratedFileStream.h"
  26. #include "cmGeneratorExpression.h"
  27. #include "cmGeneratorExpressionContext.h"
  28. #include "cmGeneratorExpressionDAGChecker.h"
  29. #include "cmGeneratorExpressionNode.h"
  30. #include "cmGlobalGenerator.h"
  31. #include "cmLocalGenerator.h"
  32. #include "cmMakefile.h"
  33. #include "cmMessageType.h"
  34. #include "cmOutputConverter.h"
  35. #include "cmPropertyMap.h"
  36. #include "cmRange.h"
  37. #include "cmSourceFile.h"
  38. #include "cmSourceFileLocation.h"
  39. #include "cmSourceFileLocationKind.h"
  40. #include "cmStandardLevelResolver.h"
  41. #include "cmState.h"
  42. #include "cmStringAlgorithms.h"
  43. #include "cmSystemTools.h"
  44. #include "cmTarget.h"
  45. #include "cmTargetLinkLibraryType.h"
  46. #include "cmTargetPropertyComputer.h"
  47. #include "cmake.h"
  48. class cmMessenger;
  49. namespace {
  50. const cmsys::RegularExpression FrameworkRegularExpression(
  51. "^(.*/)?([^/]*)\\.framework/(.*)$");
  52. }
  53. template <>
  54. cmProp cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
  55. cmGeneratorTarget const* tgt, cmMessenger* /* messenger */,
  56. cmListFileBacktrace const& /* context */)
  57. {
  58. return &tgt->GetSourcesProperty();
  59. }
  60. template <>
  61. const std::string&
  62. cmTargetPropertyComputer::ComputeLocationForBuild<cmGeneratorTarget>(
  63. cmGeneratorTarget const* tgt)
  64. {
  65. return tgt->GetLocation("");
  66. }
  67. template <>
  68. const std::string&
  69. cmTargetPropertyComputer::ComputeLocation<cmGeneratorTarget>(
  70. cmGeneratorTarget const* tgt, const std::string& config)
  71. {
  72. return tgt->GetLocation(config);
  73. }
  74. class cmGeneratorTarget::TargetPropertyEntry
  75. {
  76. protected:
  77. static cmLinkImplItem NoLinkImplItem;
  78. public:
  79. TargetPropertyEntry(cmLinkImplItem const& item)
  80. : LinkImplItem(item)
  81. {
  82. }
  83. virtual ~TargetPropertyEntry() = default;
  84. virtual const std::string& Evaluate(
  85. cmLocalGenerator* lg, const std::string& config,
  86. cmGeneratorTarget const* headTarget,
  87. cmGeneratorExpressionDAGChecker* dagChecker,
  88. std::string const& language) const = 0;
  89. virtual cmListFileBacktrace GetBacktrace() const = 0;
  90. virtual std::string const& GetInput() const = 0;
  91. virtual bool GetHadContextSensitiveCondition() const { return false; }
  92. cmLinkImplItem const& LinkImplItem;
  93. };
  94. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  95. class TargetPropertyEntryGenex : public cmGeneratorTarget::TargetPropertyEntry
  96. {
  97. public:
  98. TargetPropertyEntryGenex(std::unique_ptr<cmCompiledGeneratorExpression> cge,
  99. cmLinkImplItem const& item = NoLinkImplItem)
  100. : cmGeneratorTarget::TargetPropertyEntry(item)
  101. , ge(std::move(cge))
  102. {
  103. }
  104. const std::string& Evaluate(cmLocalGenerator* lg, const std::string& config,
  105. cmGeneratorTarget const* headTarget,
  106. cmGeneratorExpressionDAGChecker* dagChecker,
  107. std::string const& language) const override
  108. {
  109. return this->ge->Evaluate(lg, config, headTarget, dagChecker, nullptr,
  110. language);
  111. }
  112. cmListFileBacktrace GetBacktrace() const override
  113. {
  114. return this->ge->GetBacktrace();
  115. }
  116. std::string const& GetInput() const override { return this->ge->GetInput(); }
  117. bool GetHadContextSensitiveCondition() const override
  118. {
  119. return this->ge->GetHadContextSensitiveCondition();
  120. }
  121. private:
  122. const std::unique_ptr<cmCompiledGeneratorExpression> ge;
  123. };
  124. class TargetPropertyEntryString : public cmGeneratorTarget::TargetPropertyEntry
  125. {
  126. public:
  127. TargetPropertyEntryString(std::string propertyValue,
  128. cmListFileBacktrace backtrace,
  129. cmLinkImplItem const& item = NoLinkImplItem)
  130. : cmGeneratorTarget::TargetPropertyEntry(item)
  131. , PropertyValue(std::move(propertyValue))
  132. , Backtrace(std::move(backtrace))
  133. {
  134. }
  135. const std::string& Evaluate(cmLocalGenerator*, const std::string&,
  136. cmGeneratorTarget const*,
  137. cmGeneratorExpressionDAGChecker*,
  138. std::string const&) const override
  139. {
  140. return this->PropertyValue;
  141. }
  142. cmListFileBacktrace GetBacktrace() const override { return this->Backtrace; }
  143. std::string const& GetInput() const override { return this->PropertyValue; }
  144. private:
  145. std::string PropertyValue;
  146. cmListFileBacktrace Backtrace;
  147. };
  148. std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>
  149. CreateTargetPropertyEntry(
  150. const std::string& propertyValue,
  151. cmListFileBacktrace backtrace = cmListFileBacktrace(),
  152. bool evaluateForBuildsystem = false)
  153. {
  154. if (cmGeneratorExpression::Find(propertyValue) != std::string::npos) {
  155. cmGeneratorExpression ge(std::move(backtrace));
  156. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  157. ge.Parse(propertyValue);
  158. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  159. return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
  160. cm::make_unique<TargetPropertyEntryGenex>(std::move(cge)));
  161. }
  162. return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
  163. cm::make_unique<TargetPropertyEntryString>(propertyValue,
  164. std::move(backtrace)));
  165. }
  166. void CreatePropertyGeneratorExpressions(
  167. cmStringRange entries, cmBacktraceRange backtraces,
  168. std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>>& items,
  169. bool evaluateForBuildsystem = false)
  170. {
  171. auto btIt = backtraces.begin();
  172. for (auto it = entries.begin(); it != entries.end(); ++it, ++btIt) {
  173. items.push_back(
  174. CreateTargetPropertyEntry(*it, *btIt, evaluateForBuildsystem));
  175. }
  176. }
  177. namespace {
  178. // Represent a target property entry after evaluating generator expressions
  179. // and splitting up lists.
  180. struct EvaluatedTargetPropertyEntry
  181. {
  182. EvaluatedTargetPropertyEntry(cmLinkImplItem const& item,
  183. cmListFileBacktrace bt)
  184. : LinkImplItem(item)
  185. , Backtrace(std::move(bt))
  186. {
  187. }
  188. // Move-only.
  189. EvaluatedTargetPropertyEntry(EvaluatedTargetPropertyEntry&&) = default;
  190. EvaluatedTargetPropertyEntry(EvaluatedTargetPropertyEntry const&) = delete;
  191. EvaluatedTargetPropertyEntry& operator=(EvaluatedTargetPropertyEntry&&) =
  192. delete;
  193. EvaluatedTargetPropertyEntry& operator=(
  194. EvaluatedTargetPropertyEntry const&) = delete;
  195. cmLinkImplItem const& LinkImplItem;
  196. cmListFileBacktrace Backtrace;
  197. std::vector<std::string> Values;
  198. bool ContextDependent = false;
  199. };
  200. EvaluatedTargetPropertyEntry EvaluateTargetPropertyEntry(
  201. cmGeneratorTarget const* thisTarget, std::string const& config,
  202. std::string const& lang, cmGeneratorExpressionDAGChecker* dagChecker,
  203. cmGeneratorTarget::TargetPropertyEntry& entry)
  204. {
  205. EvaluatedTargetPropertyEntry ee(entry.LinkImplItem, entry.GetBacktrace());
  206. cmExpandList(entry.Evaluate(thisTarget->GetLocalGenerator(), config,
  207. thisTarget, dagChecker, lang),
  208. ee.Values);
  209. if (entry.GetHadContextSensitiveCondition()) {
  210. ee.ContextDependent = true;
  211. }
  212. return ee;
  213. }
  214. struct EvaluatedTargetPropertyEntries
  215. {
  216. std::vector<EvaluatedTargetPropertyEntry> Entries;
  217. bool HadContextSensitiveCondition = false;
  218. };
  219. EvaluatedTargetPropertyEntries EvaluateTargetPropertyEntries(
  220. cmGeneratorTarget const* thisTarget, std::string const& config,
  221. std::string const& lang, cmGeneratorExpressionDAGChecker* dagChecker,
  222. std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>> const&
  223. in)
  224. {
  225. EvaluatedTargetPropertyEntries out;
  226. out.Entries.reserve(in.size());
  227. for (auto const& entry : in) {
  228. out.Entries.emplace_back(EvaluateTargetPropertyEntry(
  229. thisTarget, config, lang, dagChecker, *entry));
  230. }
  231. return out;
  232. }
  233. }
  234. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  235. : Target(t)
  236. , FortranModuleDirectoryCreated(false)
  237. , SourceFileFlagsConstructed(false)
  238. , PolicyWarnedCMP0022(false)
  239. , PolicyReportedCMP0069(false)
  240. , DebugIncludesDone(false)
  241. , DebugCompileOptionsDone(false)
  242. , DebugCompileFeaturesDone(false)
  243. , DebugCompileDefinitionsDone(false)
  244. , DebugLinkOptionsDone(false)
  245. , DebugLinkDirectoriesDone(false)
  246. , DebugPrecompileHeadersDone(false)
  247. , DebugSourcesDone(false)
  248. , UtilityItemsDone(false)
  249. , SourcesAreContextDependent(Tribool::Indeterminate)
  250. {
  251. this->Makefile = this->Target->GetMakefile();
  252. this->LocalGenerator = lg;
  253. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  254. this->GlobalGenerator->ComputeTargetObjectDirectory(this);
  255. CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(),
  256. t->GetIncludeDirectoriesBacktraces(),
  257. this->IncludeDirectoriesEntries);
  258. CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(),
  259. t->GetCompileOptionsBacktraces(),
  260. this->CompileOptionsEntries);
  261. CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(),
  262. t->GetCompileFeaturesBacktraces(),
  263. this->CompileFeaturesEntries);
  264. CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(),
  265. t->GetCompileDefinitionsBacktraces(),
  266. this->CompileDefinitionsEntries);
  267. CreatePropertyGeneratorExpressions(t->GetLinkOptionsEntries(),
  268. t->GetLinkOptionsBacktraces(),
  269. this->LinkOptionsEntries);
  270. CreatePropertyGeneratorExpressions(t->GetLinkDirectoriesEntries(),
  271. t->GetLinkDirectoriesBacktraces(),
  272. this->LinkDirectoriesEntries);
  273. CreatePropertyGeneratorExpressions(t->GetPrecompileHeadersEntries(),
  274. t->GetPrecompileHeadersBacktraces(),
  275. this->PrecompileHeadersEntries);
  276. CreatePropertyGeneratorExpressions(t->GetSourceEntries(),
  277. t->GetSourceBacktraces(),
  278. this->SourceEntries, true);
  279. this->PolicyMap = t->GetPolicyMap();
  280. // Get hard-coded linker language
  281. if (this->Target->GetProperty("HAS_CXX")) {
  282. this->LinkerLanguage = "CXX";
  283. } else {
  284. this->LinkerLanguage = this->Target->GetSafeProperty("LINKER_LANGUAGE");
  285. }
  286. }
  287. cmGeneratorTarget::~cmGeneratorTarget() = default;
  288. const std::string& cmGeneratorTarget::GetSourcesProperty() const
  289. {
  290. std::vector<std::string> values;
  291. for (auto const& se : this->SourceEntries) {
  292. values.push_back(se->GetInput());
  293. }
  294. static std::string value;
  295. value.clear();
  296. value = cmJoin(values, ";");
  297. return value;
  298. }
  299. cmGlobalGenerator* cmGeneratorTarget::GetGlobalGenerator() const
  300. {
  301. return this->GetLocalGenerator()->GetGlobalGenerator();
  302. }
  303. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  304. {
  305. return this->LocalGenerator;
  306. }
  307. cmStateEnums::TargetType cmGeneratorTarget::GetType() const
  308. {
  309. return this->Target->GetType();
  310. }
  311. const std::string& cmGeneratorTarget::GetName() const
  312. {
  313. return this->Target->GetName();
  314. }
  315. std::string cmGeneratorTarget::GetExportName() const
  316. {
  317. cmProp exportName = this->GetProperty("EXPORT_NAME");
  318. if (cmNonempty(exportName)) {
  319. if (!cmGeneratorExpression::IsValidTargetName(*exportName)) {
  320. std::ostringstream e;
  321. e << "EXPORT_NAME property \"" << *exportName << "\" for \""
  322. << this->GetName() << "\": is not valid.";
  323. cmSystemTools::Error(e.str());
  324. return "";
  325. }
  326. return *exportName;
  327. }
  328. return this->GetName();
  329. }
  330. cmProp cmGeneratorTarget::GetProperty(const std::string& prop) const
  331. {
  332. if (cmProp result = cmTargetPropertyComputer::GetProperty(
  333. this, prop, this->Makefile->GetMessenger(), this->GetBacktrace())) {
  334. return result;
  335. }
  336. if (cmSystemTools::GetFatalErrorOccured()) {
  337. return nullptr;
  338. }
  339. return this->Target->GetProperty(prop);
  340. }
  341. std::string const& cmGeneratorTarget::GetSafeProperty(
  342. std::string const& prop) const
  343. {
  344. cmProp ret = this->GetProperty(prop);
  345. if (ret) {
  346. return *ret;
  347. }
  348. static std::string const s_empty;
  349. return s_empty;
  350. }
  351. const char* cmGeneratorTarget::GetOutputTargetType(
  352. cmStateEnums::ArtifactType artifact) const
  353. {
  354. switch (this->GetType()) {
  355. case cmStateEnums::SHARED_LIBRARY:
  356. if (this->IsDLLPlatform()) {
  357. switch (artifact) {
  358. case cmStateEnums::RuntimeBinaryArtifact:
  359. // A DLL shared library is treated as a runtime target.
  360. return "RUNTIME";
  361. case cmStateEnums::ImportLibraryArtifact:
  362. // A DLL import library is treated as an archive target.
  363. return "ARCHIVE";
  364. }
  365. } else {
  366. // For non-DLL platforms shared libraries are treated as
  367. // library targets.
  368. return "LIBRARY";
  369. }
  370. break;
  371. case cmStateEnums::STATIC_LIBRARY:
  372. // Static libraries are always treated as archive targets.
  373. return "ARCHIVE";
  374. case cmStateEnums::MODULE_LIBRARY:
  375. switch (artifact) {
  376. case cmStateEnums::RuntimeBinaryArtifact:
  377. // Module libraries are always treated as library targets.
  378. return "LIBRARY";
  379. case cmStateEnums::ImportLibraryArtifact:
  380. // Module import libraries are treated as archive targets.
  381. return "ARCHIVE";
  382. }
  383. break;
  384. case cmStateEnums::OBJECT_LIBRARY:
  385. // Object libraries are always treated as object targets.
  386. return "OBJECT";
  387. case cmStateEnums::EXECUTABLE:
  388. switch (artifact) {
  389. case cmStateEnums::RuntimeBinaryArtifact:
  390. // Executables are always treated as runtime targets.
  391. return "RUNTIME";
  392. case cmStateEnums::ImportLibraryArtifact:
  393. // Executable import libraries are treated as archive targets.
  394. return "ARCHIVE";
  395. }
  396. break;
  397. default:
  398. break;
  399. }
  400. return "";
  401. }
  402. std::string cmGeneratorTarget::GetOutputName(
  403. const std::string& config, cmStateEnums::ArtifactType artifact) const
  404. {
  405. // Lookup/compute/cache the output name for this configuration.
  406. OutputNameKey key(config, artifact);
  407. auto i = this->OutputNameMap.find(key);
  408. if (i == this->OutputNameMap.end()) {
  409. // Add empty name in map to detect potential recursion.
  410. OutputNameMapType::value_type entry(key, "");
  411. i = this->OutputNameMap.insert(entry).first;
  412. // Compute output name.
  413. std::vector<std::string> props;
  414. std::string type = this->GetOutputTargetType(artifact);
  415. std::string configUpper = cmSystemTools::UpperCase(config);
  416. if (!type.empty() && !configUpper.empty()) {
  417. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  418. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  419. }
  420. if (!type.empty()) {
  421. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  422. props.push_back(type + "_OUTPUT_NAME");
  423. }
  424. if (!configUpper.empty()) {
  425. // OUTPUT_NAME_<CONFIG>
  426. props.push_back("OUTPUT_NAME_" + configUpper);
  427. // <CONFIG>_OUTPUT_NAME
  428. props.push_back(configUpper + "_OUTPUT_NAME");
  429. }
  430. // OUTPUT_NAME
  431. props.emplace_back("OUTPUT_NAME");
  432. std::string outName;
  433. for (std::string const& p : props) {
  434. if (cmProp outNameProp = this->GetProperty(p)) {
  435. outName = *outNameProp;
  436. break;
  437. }
  438. }
  439. if (outName.empty()) {
  440. outName = this->GetName();
  441. }
  442. // Now evaluate genex and update the previously-prepared map entry.
  443. i->second =
  444. cmGeneratorExpression::Evaluate(outName, this->LocalGenerator, config);
  445. } else if (i->second.empty()) {
  446. // An empty map entry indicates we have been called recursively
  447. // from the above block.
  448. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  449. MessageType::FATAL_ERROR,
  450. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  451. this->GetBacktrace());
  452. }
  453. return i->second;
  454. }
  455. std::string cmGeneratorTarget::GetFilePrefix(
  456. const std::string& config, cmStateEnums::ArtifactType artifact) const
  457. {
  458. if (this->IsImported()) {
  459. cmProp prefix = this->GetFilePrefixInternal(config, artifact);
  460. return prefix ? *prefix : std::string();
  461. }
  462. std::string prefix;
  463. std::string suffix;
  464. std::string base;
  465. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  466. return prefix;
  467. }
  468. std::string cmGeneratorTarget::GetFileSuffix(
  469. const std::string& config, cmStateEnums::ArtifactType artifact) const
  470. {
  471. if (this->IsImported()) {
  472. cmProp suffix = this->GetFileSuffixInternal(config, artifact);
  473. return suffix ? *suffix : std::string();
  474. }
  475. std::string prefix;
  476. std::string suffix;
  477. std::string base;
  478. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  479. return suffix;
  480. }
  481. std::string cmGeneratorTarget::GetFilePostfix(const std::string& config) const
  482. {
  483. cmProp postfix = nullptr;
  484. std::string frameworkPostfix;
  485. if (!config.empty()) {
  486. std::string configProp =
  487. cmStrCat(cmSystemTools::UpperCase(config), "_POSTFIX");
  488. postfix = this->GetProperty(configProp);
  489. // Mac application bundles and frameworks have no regular postfix like
  490. // libraries do.
  491. if (!this->IsImported() && postfix &&
  492. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple())) {
  493. postfix = nullptr;
  494. }
  495. // Frameworks created by multi config generators can have a special
  496. // framework postfix.
  497. frameworkPostfix = this->GetFrameworkMultiConfigPostfix(config);
  498. if (!frameworkPostfix.empty()) {
  499. postfix = &frameworkPostfix;
  500. }
  501. }
  502. return postfix ? *postfix : std::string();
  503. }
  504. std::string cmGeneratorTarget::GetFrameworkMultiConfigPostfix(
  505. const std::string& config) const
  506. {
  507. cmProp postfix = nullptr;
  508. if (!config.empty()) {
  509. std::string configProp = cmStrCat("FRAMEWORK_MULTI_CONFIG_POSTFIX_",
  510. cmSystemTools::UpperCase(config));
  511. postfix = this->GetProperty(configProp);
  512. if (!this->IsImported() && postfix &&
  513. (this->IsFrameworkOnApple() &&
  514. !this->GetGlobalGenerator()->IsMultiConfig())) {
  515. postfix = nullptr;
  516. }
  517. }
  518. return postfix ? *postfix : std::string();
  519. }
  520. cmProp cmGeneratorTarget::GetFilePrefixInternal(
  521. std::string const& config, cmStateEnums::ArtifactType artifact,
  522. const std::string& language) const
  523. {
  524. // no prefix for non-main target types.
  525. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  526. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  527. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  528. this->GetType() != cmStateEnums::EXECUTABLE) {
  529. return nullptr;
  530. }
  531. const bool isImportedLibraryArtifact =
  532. (artifact == cmStateEnums::ImportLibraryArtifact);
  533. // Return an empty prefix for the import library if this platform
  534. // does not support import libraries.
  535. if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
  536. return nullptr;
  537. }
  538. // The implib option is only allowed for shared libraries, module
  539. // libraries, and executables.
  540. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  541. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  542. this->GetType() != cmStateEnums::EXECUTABLE) {
  543. artifact = cmStateEnums::RuntimeBinaryArtifact;
  544. }
  545. // Compute prefix value.
  546. cmProp targetPrefix =
  547. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_PREFIX")
  548. : this->GetProperty("PREFIX"));
  549. if (!targetPrefix) {
  550. const char* prefixVar = this->Target->GetPrefixVariableInternal(artifact);
  551. if (!language.empty() && cmNonempty(prefixVar)) {
  552. std::string langPrefix = cmStrCat(prefixVar, "_", language);
  553. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  554. }
  555. // if there is no prefix on the target nor specific language
  556. // use the cmake definition.
  557. if (!targetPrefix && prefixVar) {
  558. targetPrefix = this->Makefile->GetDefinition(prefixVar);
  559. }
  560. }
  561. return targetPrefix;
  562. }
  563. cmProp cmGeneratorTarget::GetFileSuffixInternal(
  564. std::string const& config, cmStateEnums::ArtifactType artifact,
  565. const std::string& language) const
  566. {
  567. // no suffix for non-main target types.
  568. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  569. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  570. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  571. this->GetType() != cmStateEnums::EXECUTABLE) {
  572. return nullptr;
  573. }
  574. const bool isImportedLibraryArtifact =
  575. (artifact == cmStateEnums::ImportLibraryArtifact);
  576. // Return an empty suffix for the import library if this platform
  577. // does not support import libraries.
  578. if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
  579. return nullptr;
  580. }
  581. // The implib option is only allowed for shared libraries, module
  582. // libraries, and executables.
  583. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  584. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  585. this->GetType() != cmStateEnums::EXECUTABLE) {
  586. artifact = cmStateEnums::RuntimeBinaryArtifact;
  587. }
  588. // Compute suffix value.
  589. cmProp targetSuffix =
  590. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_SUFFIX")
  591. : this->GetProperty("SUFFIX"));
  592. if (!targetSuffix) {
  593. const char* suffixVar = this->Target->GetSuffixVariableInternal(artifact);
  594. if (!language.empty() && cmNonempty(suffixVar)) {
  595. std::string langSuffix = cmStrCat(suffixVar, "_", language);
  596. targetSuffix = this->Makefile->GetDefinition(langSuffix);
  597. }
  598. // if there is no suffix on the target nor specific language
  599. // use the cmake definition.
  600. if (!targetSuffix && suffixVar) {
  601. targetSuffix = this->Makefile->GetDefinition(suffixVar);
  602. }
  603. }
  604. return targetSuffix;
  605. }
  606. void cmGeneratorTarget::ClearSourcesCache()
  607. {
  608. this->AllConfigSources.clear();
  609. this->KindedSourcesMap.clear();
  610. this->SourcesAreContextDependent = Tribool::Indeterminate;
  611. this->Objects.clear();
  612. this->VisitedConfigsForObjects.clear();
  613. this->LinkImplMap.clear();
  614. }
  615. void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before)
  616. {
  617. this->SourceEntries.insert(
  618. before ? this->SourceEntries.begin() : this->SourceEntries.end(),
  619. CreateTargetPropertyEntry(src, this->Makefile->GetBacktrace(), true));
  620. this->ClearSourcesCache();
  621. }
  622. void cmGeneratorTarget::AddSource(const std::string& src, bool before)
  623. {
  624. this->Target->AddSource(src, before);
  625. this->AddSourceCommon(src, before);
  626. }
  627. void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
  628. {
  629. this->Target->AddTracedSources(srcs);
  630. if (!srcs.empty()) {
  631. this->AddSourceCommon(cmJoin(srcs, ";"));
  632. }
  633. }
  634. void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
  635. bool before)
  636. {
  637. this->Target->InsertInclude(src, this->Makefile->GetBacktrace(), before);
  638. this->IncludeDirectoriesEntries.insert(
  639. before ? this->IncludeDirectoriesEntries.begin()
  640. : this->IncludeDirectoriesEntries.end(),
  641. CreateTargetPropertyEntry(src, this->Makefile->GetBacktrace(), true));
  642. }
  643. std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
  644. cmSourceFile const* sf) const
  645. {
  646. auto i = this->SourceDepends.find(sf);
  647. if (i != this->SourceDepends.end()) {
  648. return &i->second.Depends;
  649. }
  650. return nullptr;
  651. }
  652. namespace {
  653. void handleSystemIncludesDep(cmLocalGenerator* lg,
  654. cmGeneratorTarget const* depTgt,
  655. const std::string& config,
  656. cmGeneratorTarget const* headTarget,
  657. cmGeneratorExpressionDAGChecker* dagChecker,
  658. std::vector<std::string>& result,
  659. bool excludeImported, std::string const& language)
  660. {
  661. if (cmProp dirs =
  662. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
  663. cmExpandList(cmGeneratorExpression::Evaluate(*dirs, lg, config, headTarget,
  664. dagChecker, depTgt, language),
  665. result);
  666. }
  667. if (!depTgt->IsImported() || excludeImported) {
  668. return;
  669. }
  670. if (cmProp dirs = depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES")) {
  671. cmExpandList(cmGeneratorExpression::Evaluate(*dirs, lg, config, headTarget,
  672. dagChecker, depTgt, language),
  673. result);
  674. }
  675. }
  676. }
  677. /* clang-format off */
  678. #define IMPLEMENT_VISIT(KIND) \
  679. do { \
  680. KindedSources const& kinded = this->GetKindedSources(config); \
  681. for (SourceAndKind const& s : kinded.Sources) { \
  682. if (s.Kind == KIND) { \
  683. data.push_back(s.Source.Value); \
  684. } \
  685. } \
  686. } while (false)
  687. /* clang-format on */
  688. void cmGeneratorTarget::GetObjectSources(
  689. std::vector<cmSourceFile const*>& data, const std::string& config) const
  690. {
  691. IMPLEMENT_VISIT(SourceKindObjectSource);
  692. if (this->VisitedConfigsForObjects.count(config)) {
  693. return;
  694. }
  695. for (cmSourceFile const* it : data) {
  696. this->Objects[it];
  697. }
  698. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  699. this->VisitedConfigsForObjects.insert(config);
  700. }
  701. void cmGeneratorTarget::ComputeObjectMapping()
  702. {
  703. auto const& configs =
  704. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  705. std::set<std::string> configSet(configs.begin(), configs.end());
  706. if (configSet == this->VisitedConfigsForObjects) {
  707. return;
  708. }
  709. for (std::string const& c : configs) {
  710. std::vector<cmSourceFile const*> sourceFiles;
  711. this->GetObjectSources(sourceFiles, c);
  712. }
  713. }
  714. cmProp cmGeneratorTarget::GetFeature(const std::string& feature,
  715. const std::string& config) const
  716. {
  717. if (!config.empty()) {
  718. std::string featureConfig =
  719. cmStrCat(feature, '_', cmSystemTools::UpperCase(config));
  720. if (cmProp value = this->GetProperty(featureConfig)) {
  721. return value;
  722. }
  723. }
  724. if (cmProp value = this->GetProperty(feature)) {
  725. return value;
  726. }
  727. return this->LocalGenerator->GetFeature(feature, config);
  728. }
  729. const char* cmGeneratorTarget::GetLinkPIEProperty(
  730. const std::string& config) const
  731. {
  732. static std::string PICValue;
  733. PICValue = this->GetLinkInterfaceDependentStringAsBoolProperty(
  734. "POSITION_INDEPENDENT_CODE", config);
  735. if (PICValue == "(unset)") {
  736. // POSITION_INDEPENDENT_CODE is not set
  737. return nullptr;
  738. }
  739. auto status = this->GetPolicyStatusCMP0083();
  740. return (status != cmPolicies::WARN && status != cmPolicies::OLD)
  741. ? PICValue.c_str()
  742. : nullptr;
  743. }
  744. bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang,
  745. std::string const& config) const
  746. {
  747. cmProp feature = this->GetFeature("INTERPROCEDURAL_OPTIMIZATION", config);
  748. if (!cmIsOn(feature)) {
  749. // 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies
  750. return false;
  751. }
  752. if (lang != "C" && lang != "CXX" && lang != "Fortran") {
  753. // We do not define IPO behavior for other languages.
  754. return false;
  755. }
  756. cmPolicies::PolicyStatus cmp0069 = this->GetPolicyStatusCMP0069();
  757. if (cmp0069 == cmPolicies::OLD || cmp0069 == cmPolicies::WARN) {
  758. if (this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_LEGACY_BEHAVIOR")) {
  759. return true;
  760. }
  761. if (this->PolicyReportedCMP0069) {
  762. // problem is already reported, no need to issue a message
  763. return false;
  764. }
  765. const bool in_try_compile =
  766. this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile();
  767. if (cmp0069 == cmPolicies::WARN && !in_try_compile) {
  768. std::ostringstream w;
  769. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0069) << "\n";
  770. w << "INTERPROCEDURAL_OPTIMIZATION property will be ignored for target "
  771. << "'" << this->GetName() << "'.";
  772. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  773. MessageType::AUTHOR_WARNING, w.str(), this->GetBacktrace());
  774. this->PolicyReportedCMP0069 = true;
  775. }
  776. return false;
  777. }
  778. // Note: check consistency with messages from CheckIPOSupported
  779. const char* message = nullptr;
  780. if (!this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_SUPPORTED_BY_CMAKE")) {
  781. message = "CMake doesn't support IPO for current compiler";
  782. } else if (!this->Makefile->IsOn("_CMAKE_" + lang +
  783. "_IPO_MAY_BE_SUPPORTED_BY_COMPILER")) {
  784. message = "Compiler doesn't support IPO";
  785. } else if (!this->GlobalGenerator->IsIPOSupported()) {
  786. message = "CMake doesn't support IPO for current generator";
  787. }
  788. if (!message) {
  789. // No error/warning messages
  790. return true;
  791. }
  792. if (this->PolicyReportedCMP0069) {
  793. // problem is already reported, no need to issue a message
  794. return false;
  795. }
  796. this->PolicyReportedCMP0069 = true;
  797. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  798. MessageType::FATAL_ERROR, message, this->GetBacktrace());
  799. return false;
  800. }
  801. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  802. {
  803. this->ComputeObjectMapping();
  804. return this->Objects[file];
  805. }
  806. const char* cmGeneratorTarget::GetCustomObjectExtension() const
  807. {
  808. static std::string extension;
  809. const bool has_ptx_extension =
  810. this->GetPropertyAsBool("CUDA_PTX_COMPILATION");
  811. if (has_ptx_extension) {
  812. extension = ".ptx";
  813. return extension.c_str();
  814. }
  815. return nullptr;
  816. }
  817. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  818. {
  819. this->ExplicitObjectName.insert(sf);
  820. }
  821. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  822. {
  823. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  824. auto it = this->ExplicitObjectName.find(file);
  825. return it != this->ExplicitObjectName.end();
  826. }
  827. BTs<std::string> const* cmGeneratorTarget::GetLanguageStandardProperty(
  828. std::string const& lang, std::string const& config) const
  829. {
  830. std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang);
  831. auto langStandardIter = this->LanguageStandardMap.find(key);
  832. if (langStandardIter != this->LanguageStandardMap.end()) {
  833. return &langStandardIter->second;
  834. }
  835. return this->Target->GetLanguageStandardProperty(
  836. cmStrCat(lang, "_STANDARD"));
  837. }
  838. cmProp cmGeneratorTarget::GetLanguageStandard(std::string const& lang,
  839. std::string const& config) const
  840. {
  841. BTs<std::string> const* languageStandard =
  842. this->GetLanguageStandardProperty(lang, config);
  843. if (languageStandard) {
  844. return &(languageStandard->Value);
  845. }
  846. return nullptr;
  847. }
  848. cmProp cmGeneratorTarget::GetPropertyWithPairedLanguageSupport(
  849. std::string const& lang, const char* suffix) const
  850. {
  851. cmProp propertyValue = this->Target->GetProperty(cmStrCat(lang, suffix));
  852. if (!propertyValue) {
  853. // Check if we should use the value set by another language.
  854. if (lang == "OBJC") {
  855. propertyValue = this->GetPropertyWithPairedLanguageSupport("C", suffix);
  856. } else if (lang == "OBJCXX" || lang == "CUDA" || lang == "HIP") {
  857. propertyValue =
  858. this->GetPropertyWithPairedLanguageSupport("CXX", suffix);
  859. }
  860. }
  861. return propertyValue;
  862. }
  863. cmProp cmGeneratorTarget::GetLanguageExtensions(std::string const& lang) const
  864. {
  865. return this->GetPropertyWithPairedLanguageSupport(lang, "_EXTENSIONS");
  866. }
  867. bool cmGeneratorTarget::GetLanguageStandardRequired(
  868. std::string const& lang) const
  869. {
  870. return cmIsOn(
  871. this->GetPropertyWithPairedLanguageSupport(lang, "_STANDARD_REQUIRED"));
  872. }
  873. void cmGeneratorTarget::GetModuleDefinitionSources(
  874. std::vector<cmSourceFile const*>& data, const std::string& config) const
  875. {
  876. IMPLEMENT_VISIT(SourceKindModuleDefinition);
  877. }
  878. void cmGeneratorTarget::GetHeaderSources(
  879. std::vector<cmSourceFile const*>& data, const std::string& config) const
  880. {
  881. IMPLEMENT_VISIT(SourceKindHeader);
  882. }
  883. void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile const*>& data,
  884. const std::string& config) const
  885. {
  886. IMPLEMENT_VISIT(SourceKindExtra);
  887. }
  888. void cmGeneratorTarget::GetCustomCommands(
  889. std::vector<cmSourceFile const*>& data, const std::string& config) const
  890. {
  891. IMPLEMENT_VISIT(SourceKindCustomCommand);
  892. }
  893. void cmGeneratorTarget::GetExternalObjects(
  894. std::vector<cmSourceFile const*>& data, const std::string& config) const
  895. {
  896. IMPLEMENT_VISIT(SourceKindExternalObject);
  897. }
  898. void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data,
  899. const std::string& config) const
  900. {
  901. IMPLEMENT_VISIT(SourceKindManifest);
  902. }
  903. std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
  904. {
  905. if (!this->UtilityItemsDone) {
  906. this->UtilityItemsDone = true;
  907. std::set<BT<std::pair<std::string, bool>>> const& utilities =
  908. this->GetUtilities();
  909. for (BT<std::pair<std::string, bool>> const& i : utilities) {
  910. if (cmGeneratorTarget* gt =
  911. this->LocalGenerator->FindGeneratorTargetToUse(i.Value.first)) {
  912. this->UtilityItems.insert(cmLinkItem(gt, i.Value.second, i.Backtrace));
  913. } else {
  914. this->UtilityItems.insert(
  915. cmLinkItem(i.Value.first, i.Value.second, i.Backtrace));
  916. }
  917. }
  918. }
  919. return this->UtilityItems;
  920. }
  921. const std::string& cmGeneratorTarget::GetLocation(
  922. const std::string& config) const
  923. {
  924. static std::string location;
  925. if (this->IsImported()) {
  926. location = this->Target->ImportedGetFullPath(
  927. config, cmStateEnums::RuntimeBinaryArtifact);
  928. } else {
  929. location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  930. }
  931. return location;
  932. }
  933. cm::optional<std::string> cmGeneratorTarget::MaybeGetLocation(
  934. std::string const& config) const
  935. {
  936. cm::optional<std::string> location;
  937. if (cmGeneratorTarget::ImportInfo const* imp = this->GetImportInfo(config)) {
  938. if (!imp->Location.empty()) {
  939. location = imp->Location;
  940. }
  941. } else {
  942. location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  943. }
  944. return location;
  945. }
  946. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreBuildCommands()
  947. const
  948. {
  949. return this->Target->GetPreBuildCommands();
  950. }
  951. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreLinkCommands()
  952. const
  953. {
  954. return this->Target->GetPreLinkCommands();
  955. }
  956. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPostBuildCommands()
  957. const
  958. {
  959. return this->Target->GetPostBuildCommands();
  960. }
  961. void cmGeneratorTarget::AppendCustomCommandSideEffects(
  962. std::set<cmGeneratorTarget const*>& sideEffects) const
  963. {
  964. if (!this->GetPreBuildCommands().empty() ||
  965. !this->GetPreLinkCommands().empty() ||
  966. !this->GetPostBuildCommands().empty()) {
  967. sideEffects.insert(this);
  968. } else {
  969. for (auto const& source : this->GetAllConfigSources()) {
  970. if (source.Source->GetCustomCommand() != nullptr) {
  971. sideEffects.insert(this);
  972. break;
  973. }
  974. }
  975. }
  976. }
  977. void cmGeneratorTarget::AppendLanguageSideEffects(
  978. std::map<std::string, std::set<cmGeneratorTarget const*>>& sideEffects) const
  979. {
  980. static const std::set<cm::string_view> LANGS_WITH_NO_SIDE_EFFECTS = {
  981. "C"_s, "CXX"_s, "OBJC"_s, "OBJCXX"_s, "ASM"_s, "CUDA"_s, "HIP"_s
  982. };
  983. for (auto const& lang : this->GetAllConfigCompileLanguages()) {
  984. if (!LANGS_WITH_NO_SIDE_EFFECTS.count(lang)) {
  985. sideEffects[lang].insert(this);
  986. }
  987. }
  988. }
  989. bool cmGeneratorTarget::IsInBuildSystem() const
  990. {
  991. if (this->IsImported()) {
  992. return false;
  993. }
  994. switch (this->Target->GetType()) {
  995. case cmStateEnums::EXECUTABLE:
  996. case cmStateEnums::STATIC_LIBRARY:
  997. case cmStateEnums::SHARED_LIBRARY:
  998. case cmStateEnums::MODULE_LIBRARY:
  999. case cmStateEnums::OBJECT_LIBRARY:
  1000. case cmStateEnums::UTILITY:
  1001. case cmStateEnums::GLOBAL_TARGET:
  1002. return true;
  1003. case cmStateEnums::INTERFACE_LIBRARY:
  1004. // An INTERFACE library is in the build system if it has SOURCES.
  1005. if (!this->SourceEntries.empty()) {
  1006. return true;
  1007. }
  1008. case cmStateEnums::UNKNOWN_LIBRARY:
  1009. break;
  1010. }
  1011. return false;
  1012. }
  1013. bool cmGeneratorTarget::IsImported() const
  1014. {
  1015. return this->Target->IsImported();
  1016. }
  1017. bool cmGeneratorTarget::IsImportedGloballyVisible() const
  1018. {
  1019. return this->Target->IsImportedGloballyVisible();
  1020. }
  1021. bool cmGeneratorTarget::CanCompileSources() const
  1022. {
  1023. return this->Target->CanCompileSources();
  1024. }
  1025. const std::string& cmGeneratorTarget::GetLocationForBuild() const
  1026. {
  1027. static std::string location;
  1028. if (this->IsImported()) {
  1029. location = this->Target->ImportedGetFullPath(
  1030. "", cmStateEnums::RuntimeBinaryArtifact);
  1031. return location;
  1032. }
  1033. // Now handle the deprecated build-time configuration location.
  1034. std::string const noConfig;
  1035. location = this->GetDirectory(noConfig);
  1036. cmProp cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  1037. if (cfgid && (*cfgid != ".")) {
  1038. location += "/";
  1039. location += *cfgid;
  1040. }
  1041. if (this->IsAppBundleOnApple()) {
  1042. std::string macdir = this->BuildBundleDirectory("", "", FullLevel);
  1043. if (!macdir.empty()) {
  1044. location += "/";
  1045. location += macdir;
  1046. }
  1047. }
  1048. location += "/";
  1049. location += this->GetFullName("", cmStateEnums::RuntimeBinaryArtifact);
  1050. return location;
  1051. }
  1052. bool cmGeneratorTarget::IsSystemIncludeDirectory(
  1053. const std::string& dir, const std::string& config,
  1054. const std::string& language) const
  1055. {
  1056. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  1057. std::string config_upper;
  1058. if (!config.empty()) {
  1059. config_upper = cmSystemTools::UpperCase(config);
  1060. }
  1061. std::string key = cmStrCat(config_upper, "/", language);
  1062. auto iter = this->SystemIncludesCache.find(key);
  1063. if (iter == this->SystemIncludesCache.end()) {
  1064. cmGeneratorExpressionDAGChecker dagChecker(
  1065. this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr);
  1066. bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  1067. std::vector<std::string> result;
  1068. for (std::string const& it : this->Target->GetSystemIncludeDirectories()) {
  1069. cmExpandList(cmGeneratorExpression::Evaluate(it, this->LocalGenerator,
  1070. config, this, &dagChecker,
  1071. nullptr, language),
  1072. result);
  1073. }
  1074. std::vector<cmGeneratorTarget const*> const& deps =
  1075. this->GetLinkImplementationClosure(config);
  1076. for (cmGeneratorTarget const* dep : deps) {
  1077. handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
  1078. &dagChecker, result, excludeImported, language);
  1079. }
  1080. cmLinkImplementation const* impl = this->GetLinkImplementation(config);
  1081. if (impl != nullptr) {
  1082. auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language);
  1083. if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) {
  1084. for (auto const& lib : runtimeEntries->second) {
  1085. if (lib.Target) {
  1086. handleSystemIncludesDep(this->LocalGenerator, lib.Target, config,
  1087. this, &dagChecker, result, excludeImported,
  1088. language);
  1089. }
  1090. }
  1091. }
  1092. }
  1093. std::for_each(result.begin(), result.end(),
  1094. cmSystemTools::ConvertToUnixSlashes);
  1095. std::sort(result.begin(), result.end());
  1096. result.erase(std::unique(result.begin(), result.end()), result.end());
  1097. iter = this->SystemIncludesCache.emplace(key, result).first;
  1098. }
  1099. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  1100. }
  1101. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  1102. {
  1103. return this->Target->GetPropertyAsBool(prop);
  1104. }
  1105. bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
  1106. std::string const& prop, cmGeneratorExpressionContext* context,
  1107. bool usage_requirements_only) const
  1108. {
  1109. std::string const key = prop + '@' + context->Config;
  1110. auto i = this->MaybeInterfacePropertyExists.find(key);
  1111. if (i == this->MaybeInterfacePropertyExists.end()) {
  1112. // Insert an entry now in case there is a cycle.
  1113. i = this->MaybeInterfacePropertyExists.emplace(key, false).first;
  1114. bool& maybeInterfaceProp = i->second;
  1115. // If this target itself has a non-empty property value, we are done.
  1116. maybeInterfaceProp = cmNonempty(this->GetProperty(prop));
  1117. // Otherwise, recurse to interface dependencies.
  1118. if (!maybeInterfaceProp) {
  1119. cmGeneratorTarget const* headTarget =
  1120. context->HeadTarget ? context->HeadTarget : this;
  1121. if (cmLinkInterfaceLibraries const* iface =
  1122. this->GetLinkInterfaceLibraries(context->Config, headTarget,
  1123. usage_requirements_only)) {
  1124. if (iface->HadHeadSensitiveCondition) {
  1125. // With a different head target we may get to a library with
  1126. // this interface property.
  1127. maybeInterfaceProp = true;
  1128. } else {
  1129. // The transitive interface libraries do not depend on the
  1130. // head target, so we can follow them.
  1131. for (cmLinkItem const& lib : iface->Libraries) {
  1132. if (lib.Target &&
  1133. lib.Target->MaybeHaveInterfaceProperty(
  1134. prop, context, usage_requirements_only)) {
  1135. maybeInterfaceProp = true;
  1136. break;
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. }
  1143. return i->second;
  1144. }
  1145. std::string cmGeneratorTarget::EvaluateInterfaceProperty(
  1146. std::string const& prop, cmGeneratorExpressionContext* context,
  1147. cmGeneratorExpressionDAGChecker* dagCheckerParent,
  1148. bool usage_requirements_only) const
  1149. {
  1150. std::string result;
  1151. // If the property does not appear transitively at all, we are done.
  1152. if (!this->MaybeHaveInterfaceProperty(prop, context,
  1153. usage_requirements_only)) {
  1154. return result;
  1155. }
  1156. // Evaluate $<TARGET_PROPERTY:this,prop> as if it were compiled. This is
  1157. // a subset of TargetPropertyNode::Evaluate without stringify/parse steps
  1158. // but sufficient for transitive interface properties.
  1159. cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace, this, prop,
  1160. nullptr, dagCheckerParent);
  1161. switch (dagChecker.Check()) {
  1162. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  1163. dagChecker.ReportError(
  1164. context, "$<TARGET_PROPERTY:" + this->GetName() + "," + prop + ">");
  1165. return result;
  1166. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  1167. // No error. We just skip cyclic references.
  1168. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  1169. // No error. We have already seen this transitive property.
  1170. return result;
  1171. case cmGeneratorExpressionDAGChecker::DAG:
  1172. break;
  1173. }
  1174. cmGeneratorTarget const* headTarget =
  1175. context->HeadTarget ? context->HeadTarget : this;
  1176. if (cmProp p = this->GetProperty(prop)) {
  1177. result = cmGeneratorExpressionNode::EvaluateDependentExpression(
  1178. *p, context->LG, context, headTarget, &dagChecker, this);
  1179. }
  1180. if (cmLinkInterfaceLibraries const* iface = this->GetLinkInterfaceLibraries(
  1181. context->Config, headTarget, usage_requirements_only)) {
  1182. context->HadContextSensitiveCondition =
  1183. context->HadContextSensitiveCondition ||
  1184. iface->HadContextSensitiveCondition;
  1185. for (cmLinkItem const& lib : iface->Libraries) {
  1186. // Broken code can have a target in its own link interface.
  1187. // Don't follow such link interface entries so as not to create a
  1188. // self-referencing loop.
  1189. if (lib.Target && lib.Target != this) {
  1190. // Pretend $<TARGET_PROPERTY:lib.Target,prop> appeared in the
  1191. // above property and hand-evaluate it as if it were compiled.
  1192. // Create a context as cmCompiledGeneratorExpression::Evaluate does.
  1193. cmGeneratorExpressionContext libContext(
  1194. context->LG, context->Config, context->Quiet, headTarget, this,
  1195. context->EvaluateForBuildsystem, context->Backtrace,
  1196. context->Language);
  1197. std::string libResult = cmGeneratorExpression::StripEmptyListElements(
  1198. lib.Target->EvaluateInterfaceProperty(prop, &libContext, &dagChecker,
  1199. usage_requirements_only));
  1200. if (!libResult.empty()) {
  1201. if (result.empty()) {
  1202. result = std::move(libResult);
  1203. } else {
  1204. result.reserve(result.size() + 1 + libResult.size());
  1205. result += ";";
  1206. result += libResult;
  1207. }
  1208. }
  1209. context->HadContextSensitiveCondition =
  1210. context->HadContextSensitiveCondition ||
  1211. libContext.HadContextSensitiveCondition;
  1212. context->HadHeadSensitiveCondition =
  1213. context->HadHeadSensitiveCondition ||
  1214. libContext.HadHeadSensitiveCondition;
  1215. }
  1216. }
  1217. }
  1218. return result;
  1219. }
  1220. namespace {
  1221. enum class IncludeDirectoryFallBack
  1222. {
  1223. BINARY,
  1224. OBJECT
  1225. };
  1226. std::string AddLangSpecificInterfaceIncludeDirectories(
  1227. const cmGeneratorTarget* root, const cmGeneratorTarget* target,
  1228. const std::string& lang, const std::string& config,
  1229. const std::string& propertyName, IncludeDirectoryFallBack mode,
  1230. cmGeneratorExpressionDAGChecker* context)
  1231. {
  1232. cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
  1233. propertyName, nullptr, context };
  1234. switch (dag.Check()) {
  1235. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  1236. dag.ReportError(
  1237. nullptr, "$<TARGET_PROPERTY:" + target->GetName() + ",propertyName");
  1238. CM_FALLTHROUGH;
  1239. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  1240. // No error. We just skip cyclic references.
  1241. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  1242. // No error. We have already seen this transitive property.
  1243. return "";
  1244. case cmGeneratorExpressionDAGChecker::DAG:
  1245. break;
  1246. }
  1247. std::string directories;
  1248. if (const auto* interface =
  1249. target->GetLinkInterfaceLibraries(config, root, true)) {
  1250. for (const cmLinkItem& library : interface->Libraries) {
  1251. if (const cmGeneratorTarget* dependency = library.Target) {
  1252. if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
  1253. auto* lg = dependency->GetLocalGenerator();
  1254. std::string value = dependency->GetSafeProperty(propertyName);
  1255. if (value.empty()) {
  1256. if (mode == IncludeDirectoryFallBack::BINARY) {
  1257. value = lg->GetCurrentBinaryDirectory();
  1258. } else if (mode == IncludeDirectoryFallBack::OBJECT) {
  1259. value = cmStrCat(lg->GetCurrentBinaryDirectory(), '/',
  1260. lg->GetTargetDirectory(dependency));
  1261. }
  1262. }
  1263. if (!directories.empty()) {
  1264. directories += ";";
  1265. }
  1266. directories += value;
  1267. }
  1268. }
  1269. }
  1270. }
  1271. return directories;
  1272. }
  1273. void AddLangSpecificImplicitIncludeDirectories(
  1274. const cmGeneratorTarget* target, const std::string& lang,
  1275. const std::string& config, const std::string& propertyName,
  1276. IncludeDirectoryFallBack mode, EvaluatedTargetPropertyEntries& entries)
  1277. {
  1278. if (const auto* libraries = target->GetLinkImplementationLibraries(config)) {
  1279. cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
  1280. propertyName, nullptr, nullptr };
  1281. for (const cmLinkImplItem& library : libraries->Libraries) {
  1282. if (const cmGeneratorTarget* dependency = library.Target) {
  1283. if (!dependency->IsInBuildSystem()) {
  1284. continue;
  1285. }
  1286. if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
  1287. auto* lg = dependency->GetLocalGenerator();
  1288. EvaluatedTargetPropertyEntry entry{ library, library.Backtrace };
  1289. if (cmProp val = dependency->GetProperty(propertyName)) {
  1290. entry.Values.emplace_back(*val);
  1291. } else {
  1292. if (mode == IncludeDirectoryFallBack::BINARY) {
  1293. entry.Values.emplace_back(lg->GetCurrentBinaryDirectory());
  1294. } else if (mode == IncludeDirectoryFallBack::OBJECT) {
  1295. entry.Values.emplace_back(
  1296. dependency->GetObjectDirectory(config));
  1297. }
  1298. }
  1299. cmExpandList(
  1300. AddLangSpecificInterfaceIncludeDirectories(
  1301. target, dependency, lang, config, propertyName, mode, &dag),
  1302. entry.Values);
  1303. entries.Entries.emplace_back(std::move(entry));
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. void addInterfaceEntry(cmGeneratorTarget const* headTarget,
  1310. std::string const& config, std::string const& prop,
  1311. std::string const& lang,
  1312. cmGeneratorExpressionDAGChecker* dagChecker,
  1313. EvaluatedTargetPropertyEntries& entries,
  1314. bool usage_requirements_only,
  1315. std::vector<cmLinkImplItem> const& libraries)
  1316. {
  1317. for (cmLinkImplItem const& lib : libraries) {
  1318. if (lib.Target) {
  1319. EvaluatedTargetPropertyEntry ee(lib, lib.Backtrace);
  1320. // Pretend $<TARGET_PROPERTY:lib.Target,prop> appeared in our
  1321. // caller's property and hand-evaluate it as if it were compiled.
  1322. // Create a context as cmCompiledGeneratorExpression::Evaluate does.
  1323. cmGeneratorExpressionContext context(
  1324. headTarget->GetLocalGenerator(), config, false, headTarget, headTarget,
  1325. true, lib.Backtrace, lang);
  1326. cmExpandList(lib.Target->EvaluateInterfaceProperty(
  1327. prop, &context, dagChecker, usage_requirements_only),
  1328. ee.Values);
  1329. ee.ContextDependent = context.HadContextSensitiveCondition;
  1330. entries.Entries.emplace_back(std::move(ee));
  1331. }
  1332. }
  1333. }
  1334. // IncludeRuntimeInterface is used to break the cycle in computing
  1335. // the necessary transitive dependencies of targets that can occur
  1336. // now that we have implicit language runtime targets.
  1337. //
  1338. // To determine the set of languages that a target has we need to iterate
  1339. // all the sources which includes transitive INTERFACE sources.
  1340. // Therefore we can't determine what language runtimes are needed
  1341. // for a target until after all sources are computed.
  1342. //
  1343. // Therefore while computing the applicable INTERFACE_SOURCES we
  1344. // must ignore anything in LanguageRuntimeLibraries or we would
  1345. // create a cycle ( INTERFACE_SOURCES requires LanguageRuntimeLibraries,
  1346. // LanguageRuntimeLibraries requires INTERFACE_SOURCES).
  1347. //
  1348. enum class IncludeRuntimeInterface
  1349. {
  1350. Yes,
  1351. No
  1352. };
  1353. void AddInterfaceEntries(cmGeneratorTarget const* headTarget,
  1354. std::string const& config, std::string const& prop,
  1355. std::string const& lang,
  1356. cmGeneratorExpressionDAGChecker* dagChecker,
  1357. EvaluatedTargetPropertyEntries& entries,
  1358. IncludeRuntimeInterface searchRuntime,
  1359. bool usage_requirements_only = true)
  1360. {
  1361. if (searchRuntime == IncludeRuntimeInterface::Yes) {
  1362. if (cmLinkImplementation const* impl =
  1363. headTarget->GetLinkImplementation(config)) {
  1364. entries.HadContextSensitiveCondition =
  1365. impl->HadContextSensitiveCondition;
  1366. auto runtimeLibIt = impl->LanguageRuntimeLibraries.find(lang);
  1367. if (runtimeLibIt != impl->LanguageRuntimeLibraries.end()) {
  1368. addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries,
  1369. usage_requirements_only, runtimeLibIt->second);
  1370. }
  1371. addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries,
  1372. usage_requirements_only, impl->Libraries);
  1373. }
  1374. } else {
  1375. if (cmLinkImplementationLibraries const* impl =
  1376. headTarget->GetLinkImplementationLibraries(config)) {
  1377. entries.HadContextSensitiveCondition =
  1378. impl->HadContextSensitiveCondition;
  1379. addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries,
  1380. usage_requirements_only, impl->Libraries);
  1381. }
  1382. }
  1383. }
  1384. void AddObjectEntries(cmGeneratorTarget const* headTarget,
  1385. std::string const& config,
  1386. cmGeneratorExpressionDAGChecker* dagChecker,
  1387. EvaluatedTargetPropertyEntries& entries)
  1388. {
  1389. if (cmLinkImplementationLibraries const* impl =
  1390. headTarget->GetLinkImplementationLibraries(config)) {
  1391. entries.HadContextSensitiveCondition = impl->HadContextSensitiveCondition;
  1392. for (cmLinkImplItem const& lib : impl->Libraries) {
  1393. if (lib.Target &&
  1394. lib.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1395. std::string uniqueName =
  1396. headTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
  1397. lib.Target);
  1398. std::string genex = "$<TARGET_OBJECTS:" + std::move(uniqueName) + ">";
  1399. cmGeneratorExpression ge(lib.Backtrace);
  1400. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  1401. cge->SetEvaluateForBuildsystem(true);
  1402. EvaluatedTargetPropertyEntry ee(lib, lib.Backtrace);
  1403. cmExpandList(cge->Evaluate(headTarget->GetLocalGenerator(), config,
  1404. headTarget, dagChecker),
  1405. ee.Values);
  1406. if (cge->GetHadContextSensitiveCondition()) {
  1407. ee.ContextDependent = true;
  1408. }
  1409. entries.Entries.emplace_back(std::move(ee));
  1410. }
  1411. }
  1412. }
  1413. }
  1414. bool processSources(cmGeneratorTarget const* tgt,
  1415. EvaluatedTargetPropertyEntries& entries,
  1416. std::vector<BT<std::string>>& srcs,
  1417. std::unordered_set<std::string>& uniqueSrcs,
  1418. bool debugSources)
  1419. {
  1420. cmMakefile* mf = tgt->Target->GetMakefile();
  1421. bool contextDependent = entries.HadContextSensitiveCondition;
  1422. for (EvaluatedTargetPropertyEntry& entry : entries.Entries) {
  1423. if (entry.ContextDependent) {
  1424. contextDependent = true;
  1425. }
  1426. cmLinkImplItem const& item = entry.LinkImplItem;
  1427. std::string const& targetName = item.AsStr();
  1428. for (std::string& src : entry.Values) {
  1429. cmSourceFile* sf = mf->GetOrCreateSource(src);
  1430. std::string e;
  1431. std::string w;
  1432. std::string fullPath = sf->ResolveFullPath(&e, &w);
  1433. cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
  1434. if (!w.empty()) {
  1435. cm->IssueMessage(MessageType::AUTHOR_WARNING, w, tgt->GetBacktrace());
  1436. }
  1437. if (fullPath.empty()) {
  1438. if (!e.empty()) {
  1439. cm->IssueMessage(MessageType::FATAL_ERROR, e, tgt->GetBacktrace());
  1440. }
  1441. return contextDependent;
  1442. }
  1443. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src)) {
  1444. std::ostringstream err;
  1445. if (!targetName.empty()) {
  1446. err << "Target \"" << targetName
  1447. << "\" contains relative path in its INTERFACE_SOURCES:\n \""
  1448. << src << "\"";
  1449. } else {
  1450. err << "Found relative path while evaluating sources of \""
  1451. << tgt->GetName() << "\":\n \"" << src << "\"\n";
  1452. }
  1453. tgt->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
  1454. err.str());
  1455. return contextDependent;
  1456. }
  1457. src = fullPath;
  1458. }
  1459. std::string usedSources;
  1460. for (std::string const& src : entry.Values) {
  1461. if (uniqueSrcs.insert(src).second) {
  1462. srcs.emplace_back(src, entry.Backtrace);
  1463. if (debugSources) {
  1464. usedSources += " * " + src + "\n";
  1465. }
  1466. }
  1467. }
  1468. if (!usedSources.empty()) {
  1469. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1470. MessageType::LOG,
  1471. std::string("Used sources for target ") + tgt->GetName() + ":\n" +
  1472. usedSources,
  1473. entry.Backtrace);
  1474. }
  1475. }
  1476. return contextDependent;
  1477. }
  1478. }
  1479. std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
  1480. std::string const& config) const
  1481. {
  1482. std::vector<BT<std::string>> files;
  1483. if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  1484. // At configure-time, this method can be called as part of getting the
  1485. // LOCATION property or to export() a file to be include()d. However
  1486. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  1487. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  1488. // behavior of CMP0024 and CMP0026 only.
  1489. cmStringRange sourceEntries = this->Target->GetSourceEntries();
  1490. for (std::string const& entry : sourceEntries) {
  1491. std::vector<std::string> items = cmExpandedList(entry);
  1492. for (std::string const& item : items) {
  1493. if (cmHasLiteralPrefix(item, "$<TARGET_OBJECTS:") &&
  1494. item.back() == '>') {
  1495. continue;
  1496. }
  1497. files.emplace_back(item);
  1498. }
  1499. }
  1500. return files;
  1501. }
  1502. std::vector<std::string> debugProperties;
  1503. this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
  1504. debugProperties);
  1505. bool debugSources =
  1506. !this->DebugSourcesDone && cm::contains(debugProperties, "SOURCES");
  1507. if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  1508. this->DebugSourcesDone = true;
  1509. }
  1510. cmGeneratorExpressionDAGChecker dagChecker(this, "SOURCES", nullptr,
  1511. nullptr);
  1512. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  1513. this, config, std::string(), &dagChecker, this->SourceEntries);
  1514. std::unordered_set<std::string> uniqueSrcs;
  1515. bool contextDependentDirectSources =
  1516. processSources(this, entries, files, uniqueSrcs, debugSources);
  1517. // Collect INTERFACE_SOURCES of all direct link-dependencies.
  1518. EvaluatedTargetPropertyEntries linkInterfaceSourcesEntries;
  1519. AddInterfaceEntries(this, config, "INTERFACE_SOURCES", std::string(),
  1520. &dagChecker, linkInterfaceSourcesEntries,
  1521. IncludeRuntimeInterface::No, true);
  1522. std::vector<std::string>::size_type numFilesBefore = files.size();
  1523. bool contextDependentInterfaceSources = processSources(
  1524. this, linkInterfaceSourcesEntries, files, uniqueSrcs, debugSources);
  1525. // Collect TARGET_OBJECTS of direct object link-dependencies.
  1526. bool contextDependentObjects = false;
  1527. std::vector<std::string>::size_type numFilesBefore2 = files.size();
  1528. if (this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  1529. EvaluatedTargetPropertyEntries linkObjectsEntries;
  1530. AddObjectEntries(this, config, &dagChecker, linkObjectsEntries);
  1531. contextDependentObjects = processSources(this, linkObjectsEntries, files,
  1532. uniqueSrcs, debugSources);
  1533. }
  1534. // Determine if sources are context-dependent or not.
  1535. if (!contextDependentDirectSources &&
  1536. !(contextDependentInterfaceSources && numFilesBefore < files.size()) &&
  1537. !(contextDependentObjects && numFilesBefore2 < files.size())) {
  1538. this->SourcesAreContextDependent = Tribool::False;
  1539. } else {
  1540. this->SourcesAreContextDependent = Tribool::True;
  1541. }
  1542. return files;
  1543. }
  1544. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*>& files,
  1545. const std::string& config) const
  1546. {
  1547. std::vector<BT<cmSourceFile*>> tmp = this->GetSourceFiles(config);
  1548. files.reserve(tmp.size());
  1549. for (BT<cmSourceFile*>& v : tmp) {
  1550. files.push_back(v.Value);
  1551. }
  1552. }
  1553. std::vector<BT<cmSourceFile*>> cmGeneratorTarget::GetSourceFiles(
  1554. std::string const& config) const
  1555. {
  1556. std::vector<BT<cmSourceFile*>> files;
  1557. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  1558. // Since we are still configuring not all sources may exist yet,
  1559. // so we need to avoid full source classification because that
  1560. // requires the absolute paths to all sources to be determined.
  1561. // Since this is only for compatibility with old policies that
  1562. // projects should not depend on anymore, just compute the files
  1563. // without memoizing them.
  1564. std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
  1565. std::set<cmSourceFile*> emitted;
  1566. for (BT<std::string> const& s : srcs) {
  1567. cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
  1568. if (emitted.insert(sf).second) {
  1569. files.emplace_back(sf, s.Backtrace);
  1570. }
  1571. }
  1572. return files;
  1573. }
  1574. KindedSources const& kinded = this->GetKindedSources(config);
  1575. files.reserve(kinded.Sources.size());
  1576. for (SourceAndKind const& si : kinded.Sources) {
  1577. files.push_back(si.Source);
  1578. }
  1579. return files;
  1580. }
  1581. void cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  1582. std::vector<cmSourceFile*>& files, const std::string& config) const
  1583. {
  1584. std::vector<BT<cmSourceFile*>> tmp =
  1585. this->GetSourceFilesWithoutObjectLibraries(config);
  1586. files.reserve(tmp.size());
  1587. for (BT<cmSourceFile*>& v : tmp) {
  1588. files.push_back(v.Value);
  1589. }
  1590. }
  1591. std::vector<BT<cmSourceFile*>>
  1592. cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  1593. std::string const& config) const
  1594. {
  1595. std::vector<BT<cmSourceFile*>> files;
  1596. KindedSources const& kinded = this->GetKindedSources(config);
  1597. files.reserve(kinded.Sources.size());
  1598. for (SourceAndKind const& si : kinded.Sources) {
  1599. if (si.Source.Value->GetObjectLibrary().empty()) {
  1600. files.push_back(si.Source);
  1601. }
  1602. }
  1603. return files;
  1604. }
  1605. cmGeneratorTarget::KindedSources const& cmGeneratorTarget::GetKindedSources(
  1606. std::string const& config) const
  1607. {
  1608. // If we already processed one configuration and found no dependency
  1609. // on configuration then always use the one result.
  1610. if (this->SourcesAreContextDependent == Tribool::False) {
  1611. return this->KindedSourcesMap.begin()->second;
  1612. }
  1613. // Lookup any existing link implementation for this configuration.
  1614. std::string const key = cmSystemTools::UpperCase(config);
  1615. auto it = this->KindedSourcesMap.find(key);
  1616. if (it != this->KindedSourcesMap.end()) {
  1617. if (!it->second.Initialized) {
  1618. std::ostringstream e;
  1619. e << "The SOURCES of \"" << this->GetName()
  1620. << "\" use a generator expression that depends on the "
  1621. "SOURCES themselves.";
  1622. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  1623. MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
  1624. static KindedSources empty;
  1625. return empty;
  1626. }
  1627. return it->second;
  1628. }
  1629. // Add an entry to the map for this configuration.
  1630. KindedSources& files = this->KindedSourcesMap[key];
  1631. this->ComputeKindedSources(files, config);
  1632. files.Initialized = true;
  1633. return files;
  1634. }
  1635. void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
  1636. std::string const& config) const
  1637. {
  1638. // Get the source file paths by string.
  1639. std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
  1640. cmsys::RegularExpression header_regex(CM_HEADER_REGEX);
  1641. std::vector<cmSourceFile*> badObjLib;
  1642. std::set<cmSourceFile*> emitted;
  1643. for (BT<std::string> const& s : srcs) {
  1644. // Create each source at most once.
  1645. cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
  1646. if (!emitted.insert(sf).second) {
  1647. continue;
  1648. }
  1649. // Compute the kind (classification) of this source file.
  1650. SourceKind kind;
  1651. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1652. if (sf->GetCustomCommand()) {
  1653. kind = SourceKindCustomCommand;
  1654. } else if (this->Target->GetType() == cmStateEnums::UTILITY ||
  1655. this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY
  1656. // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
  1657. // NOLINTNEXTLINE(bugprone-branch-clone)
  1658. ) {
  1659. kind = SourceKindExtra;
  1660. } else if (this->IsSourceFilePartOfUnityBatch(sf->ResolveFullPath())) {
  1661. kind = SourceKindUnityBatched;
  1662. // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
  1663. // NOLINTNEXTLINE(bugprone-branch-clone)
  1664. } else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) {
  1665. kind = SourceKindHeader;
  1666. } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  1667. kind = SourceKindExternalObject;
  1668. } else if (!sf->GetOrDetermineLanguage().empty()) {
  1669. kind = SourceKindObjectSource;
  1670. } else if (ext == "def") {
  1671. kind = SourceKindModuleDefinition;
  1672. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1673. badObjLib.push_back(sf);
  1674. }
  1675. } else if (ext == "idl") {
  1676. kind = SourceKindIDL;
  1677. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1678. badObjLib.push_back(sf);
  1679. }
  1680. } else if (ext == "resx") {
  1681. kind = SourceKindResx;
  1682. } else if (ext == "appxmanifest") {
  1683. kind = SourceKindAppManifest;
  1684. } else if (ext == "manifest") {
  1685. kind = SourceKindManifest;
  1686. } else if (ext == "pfx") {
  1687. kind = SourceKindCertificate;
  1688. } else if (ext == "xaml") {
  1689. kind = SourceKindXaml;
  1690. } else if (header_regex.find(sf->ResolveFullPath())) {
  1691. kind = SourceKindHeader;
  1692. } else {
  1693. kind = SourceKindExtra;
  1694. }
  1695. // Save this classified source file in the result vector.
  1696. files.Sources.push_back({ BT<cmSourceFile*>(sf, s.Backtrace), kind });
  1697. }
  1698. if (!badObjLib.empty()) {
  1699. std::ostringstream e;
  1700. e << "OBJECT library \"" << this->GetName() << "\" contains:\n";
  1701. for (cmSourceFile* i : badObjLib) {
  1702. e << " " << i->GetLocation().GetName() << "\n";
  1703. }
  1704. e << "but may contain only sources that compile, header files, and "
  1705. "other files that would not affect linking of a normal library.";
  1706. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  1707. MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
  1708. }
  1709. }
  1710. std::vector<cmGeneratorTarget::AllConfigSource> const&
  1711. cmGeneratorTarget::GetAllConfigSources() const
  1712. {
  1713. if (this->AllConfigSources.empty()) {
  1714. this->ComputeAllConfigSources();
  1715. }
  1716. return this->AllConfigSources;
  1717. }
  1718. void cmGeneratorTarget::ComputeAllConfigSources() const
  1719. {
  1720. std::vector<std::string> configs =
  1721. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  1722. std::map<cmSourceFile const*, size_t> index;
  1723. for (size_t ci = 0; ci < configs.size(); ++ci) {
  1724. KindedSources const& sources = this->GetKindedSources(configs[ci]);
  1725. for (SourceAndKind const& src : sources.Sources) {
  1726. auto mi = index.find(src.Source.Value);
  1727. if (mi == index.end()) {
  1728. AllConfigSource acs;
  1729. acs.Source = src.Source.Value;
  1730. acs.Kind = src.Kind;
  1731. this->AllConfigSources.push_back(std::move(acs));
  1732. std::map<cmSourceFile const*, size_t>::value_type entry(
  1733. src.Source.Value, this->AllConfigSources.size() - 1);
  1734. mi = index.insert(entry).first;
  1735. }
  1736. this->AllConfigSources[mi->second].Configs.push_back(ci);
  1737. }
  1738. }
  1739. }
  1740. std::vector<cmGeneratorTarget::AllConfigSource>
  1741. cmGeneratorTarget::GetAllConfigSources(SourceKind kind) const
  1742. {
  1743. std::vector<AllConfigSource> result;
  1744. for (AllConfigSource const& source : this->GetAllConfigSources()) {
  1745. if (source.Kind == kind) {
  1746. result.push_back(source);
  1747. }
  1748. }
  1749. return result;
  1750. }
  1751. std::set<std::string> cmGeneratorTarget::GetAllConfigCompileLanguages() const
  1752. {
  1753. std::set<std::string> languages;
  1754. std::vector<AllConfigSource> const& sources = this->GetAllConfigSources();
  1755. for (AllConfigSource const& si : sources) {
  1756. std::string const& lang = si.Source->GetOrDetermineLanguage();
  1757. if (!lang.empty()) {
  1758. languages.emplace(lang);
  1759. }
  1760. }
  1761. return languages;
  1762. }
  1763. std::string cmGeneratorTarget::GetCompilePDBName(
  1764. const std::string& config) const
  1765. {
  1766. std::string prefix;
  1767. std::string base;
  1768. std::string suffix;
  1769. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  1770. prefix, base, suffix);
  1771. // Check for a per-configuration output directory target property.
  1772. std::string configUpper = cmSystemTools::UpperCase(config);
  1773. std::string configProp = cmStrCat("COMPILE_PDB_NAME_", configUpper);
  1774. cmProp config_name = this->GetProperty(configProp);
  1775. if (cmNonempty(config_name)) {
  1776. return prefix + *config_name + ".pdb";
  1777. }
  1778. cmProp name = this->GetProperty("COMPILE_PDB_NAME");
  1779. if (cmNonempty(name)) {
  1780. return prefix + *name + ".pdb";
  1781. }
  1782. return "";
  1783. }
  1784. std::string cmGeneratorTarget::GetCompilePDBPath(
  1785. const std::string& config) const
  1786. {
  1787. std::string dir = this->GetCompilePDBDirectory(config);
  1788. std::string name = this->GetCompilePDBName(config);
  1789. if (dir.empty() && !name.empty() && this->HaveWellDefinedOutputFiles()) {
  1790. dir = this->GetPDBDirectory(config);
  1791. }
  1792. if (!dir.empty()) {
  1793. dir += "/";
  1794. }
  1795. return dir + name;
  1796. }
  1797. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  1798. {
  1799. // soname is supported only for shared libraries and modules,
  1800. // and then only when the platform supports an soname flag.
  1801. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY) &&
  1802. !this->GetPropertyAsBool("NO_SONAME") &&
  1803. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  1804. }
  1805. bool cmGeneratorTarget::NeedRelinkBeforeInstall(
  1806. const std::string& config) const
  1807. {
  1808. // Only executables and shared libraries can have an rpath and may
  1809. // need relinking.
  1810. if (this->GetType() != cmStateEnums::EXECUTABLE &&
  1811. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1812. this->GetType() != cmStateEnums::MODULE_LIBRARY) {
  1813. return false;
  1814. }
  1815. // If there is no install location this target will not be installed
  1816. // and therefore does not need relinking.
  1817. if (!this->Target->GetHaveInstallRule()) {
  1818. return false;
  1819. }
  1820. // If skipping all rpaths completely then no relinking is needed.
  1821. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1822. return false;
  1823. }
  1824. // If building with the install-tree rpath no relinking is needed.
  1825. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1826. return false;
  1827. }
  1828. // If chrpath is going to be used no relinking is needed.
  1829. if (this->IsChrpathUsed(config)) {
  1830. return false;
  1831. }
  1832. // Check for rpath support on this platform.
  1833. std::string ll = this->GetLinkerLanguage(config);
  1834. if (!ll.empty()) {
  1835. std::string flagVar =
  1836. cmStrCat("CMAKE_SHARED_LIBRARY_RUNTIME_", ll, "_FLAG");
  1837. if (!this->Makefile->IsSet(flagVar)) {
  1838. // There is no rpath support on this platform so nothing needs
  1839. // relinking.
  1840. return false;
  1841. }
  1842. } else {
  1843. // No linker language is known. This error will be reported by
  1844. // other code.
  1845. return false;
  1846. }
  1847. // If either a build or install tree rpath is set then the rpath
  1848. // will likely change between the build tree and install tree and
  1849. // this target must be relinked.
  1850. bool have_rpath =
  1851. this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH(config);
  1852. bool is_ninja = this->LocalGenerator->GetGlobalGenerator()->IsNinja();
  1853. if (have_rpath && is_ninja) {
  1854. std::ostringstream w;
  1855. /* clang-format off */
  1856. w <<
  1857. "The install of the " << this->GetName() << " target requires changing "
  1858. "an RPATH from the build tree, but this is not supported with the Ninja "
  1859. "generator unless on an ELF-based or XCOFF-based platform. "
  1860. "The CMAKE_BUILD_WITH_INSTALL_RPATH variable may be set to avoid this "
  1861. "relinking step."
  1862. ;
  1863. /* clang-format on */
  1864. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1865. cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
  1866. }
  1867. return have_rpath;
  1868. }
  1869. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  1870. {
  1871. // Only certain target types have an rpath.
  1872. if (!(this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1873. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1874. this->GetType() == cmStateEnums::EXECUTABLE)) {
  1875. return false;
  1876. }
  1877. // If the target will not be installed we do not need to change its
  1878. // rpath.
  1879. if (!this->Target->GetHaveInstallRule()) {
  1880. return false;
  1881. }
  1882. // Skip chrpath if skipping rpath altogether.
  1883. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1884. return false;
  1885. }
  1886. // Skip chrpath if it does not need to be changed at install time.
  1887. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1888. return false;
  1889. }
  1890. // Allow the user to disable builtin chrpath explicitly.
  1891. if (this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH")) {
  1892. return false;
  1893. }
  1894. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1895. return true;
  1896. }
  1897. // Enable if the rpath flag uses a separator and the target uses
  1898. // binaries we know how to edit.
  1899. std::string ll = this->GetLinkerLanguage(config);
  1900. if (!ll.empty()) {
  1901. std::string sepVar =
  1902. cmStrCat("CMAKE_SHARED_LIBRARY_RUNTIME_", ll, "_FLAG_SEP");
  1903. cmProp sep = this->Makefile->GetDefinition(sepVar);
  1904. if (cmNonempty(sep)) {
  1905. // TODO: Add binary format check to ABI detection and get rid of
  1906. // CMAKE_EXECUTABLE_FORMAT.
  1907. if (cmProp fmt =
  1908. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT")) {
  1909. if (*fmt == "ELF") {
  1910. return true;
  1911. }
  1912. #if defined(CMake_USE_XCOFF_PARSER)
  1913. if (*fmt == "XCOFF") {
  1914. return true;
  1915. }
  1916. #endif
  1917. }
  1918. }
  1919. }
  1920. return false;
  1921. }
  1922. bool cmGeneratorTarget::IsImportedSharedLibWithoutSOName(
  1923. const std::string& config) const
  1924. {
  1925. if (this->IsImported() && this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  1926. if (cmGeneratorTarget::ImportInfo const* info =
  1927. this->GetImportInfo(config)) {
  1928. return info->NoSOName;
  1929. }
  1930. }
  1931. return false;
  1932. }
  1933. bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
  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") {
  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") {
  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. cmToCStr(soversion));
  4389. // The library's real name on disk.
  4390. this->ComputeVersionedName(targetNames.Real, prefix, targetNames.Base,
  4391. suffix, targetNames.Output, cmToCStr(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. const char* version = nullptr;
  4419. #else
  4420. // Check for executable version properties.
  4421. const char* version = cmToCStr(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 = &fw_prefix;
  4519. targetSuffix = nullptr;
  4520. }
  4521. if (this->IsCFBundleOnApple()) {
  4522. fw_prefix = cmStrCat(this->GetCFBundleDirectory(config, FullLevel), '/');
  4523. targetPrefix = &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 = &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<std::nullptr_t>(std::nullptr_t /*unused*/)
  5021. {
  5022. return "(unset)";
  5023. }
  5024. std::string compatibilityType(CompatibleType t)
  5025. {
  5026. switch (t) {
  5027. case BoolType:
  5028. return "Boolean compatibility";
  5029. case StringType:
  5030. return "String compatibility";
  5031. case NumberMaxType:
  5032. return "Numeric maximum compatibility";
  5033. case NumberMinType:
  5034. return "Numeric minimum compatibility";
  5035. }
  5036. assert(false && "Unreachable!");
  5037. return "";
  5038. }
  5039. std::string compatibilityAgree(CompatibleType t, bool dominant)
  5040. {
  5041. switch (t) {
  5042. case BoolType:
  5043. case StringType:
  5044. return dominant ? "(Disagree)\n" : "(Agree)\n";
  5045. case NumberMaxType:
  5046. case NumberMinType:
  5047. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  5048. }
  5049. assert(false && "Unreachable!");
  5050. return "";
  5051. }
  5052. template <typename PropertyType>
  5053. PropertyType getTypedProperty(
  5054. cmGeneratorTarget const* tgt, const std::string& prop,
  5055. cmGeneratorExpressionInterpreter* genexInterpreter = nullptr);
  5056. template <>
  5057. bool getTypedProperty<bool>(cmGeneratorTarget const* tgt,
  5058. const std::string& prop,
  5059. cmGeneratorExpressionInterpreter* genexInterpreter)
  5060. {
  5061. if (genexInterpreter == nullptr) {
  5062. return tgt->GetPropertyAsBool(prop);
  5063. }
  5064. cmProp value = tgt->GetProperty(prop);
  5065. return cmIsOn(genexInterpreter->Evaluate(value ? *value : "", prop));
  5066. }
  5067. template <>
  5068. const char* getTypedProperty<const char*>(
  5069. cmGeneratorTarget const* tgt, const std::string& prop,
  5070. cmGeneratorExpressionInterpreter* genexInterpreter)
  5071. {
  5072. cmProp value = tgt->GetProperty(prop);
  5073. if (genexInterpreter == nullptr) {
  5074. return cmToCStr(value);
  5075. }
  5076. return genexInterpreter->Evaluate(value ? *value : "", prop).c_str();
  5077. }
  5078. template <>
  5079. std::string getTypedProperty<std::string>(
  5080. cmGeneratorTarget const* tgt, const std::string& prop,
  5081. cmGeneratorExpressionInterpreter* genexInterpreter)
  5082. {
  5083. cmProp value = tgt->GetProperty(prop);
  5084. if (genexInterpreter == nullptr) {
  5085. return valueAsString(cmToCStr(value));
  5086. }
  5087. return genexInterpreter->Evaluate(value ? *value : "", prop);
  5088. }
  5089. template <typename PropertyType>
  5090. PropertyType impliedValue(PropertyType);
  5091. template <>
  5092. bool impliedValue<bool>(bool /*unused*/)
  5093. {
  5094. return false;
  5095. }
  5096. template <>
  5097. const char* impliedValue<const char*>(const char* /*unused*/)
  5098. {
  5099. return "";
  5100. }
  5101. template <>
  5102. std::string impliedValue<std::string>(std::string /*unused*/) // NOLINT(*)
  5103. {
  5104. return std::string();
  5105. }
  5106. template <typename PropertyType>
  5107. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  5108. PropertyType rhs,
  5109. CompatibleType t);
  5110. template <>
  5111. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  5112. CompatibleType /*unused*/)
  5113. {
  5114. return { lhs == rhs, lhs };
  5115. }
  5116. std::pair<bool, const char*> consistentStringProperty(const char* lhs,
  5117. const char* rhs)
  5118. {
  5119. const bool b = strcmp(lhs, rhs) == 0;
  5120. return { b, b ? lhs : nullptr };
  5121. }
  5122. std::pair<bool, std::string> consistentStringProperty(const std::string& lhs,
  5123. const std::string& rhs)
  5124. {
  5125. const bool b = lhs == rhs;
  5126. return { b, b ? lhs : valueAsString(nullptr) };
  5127. }
  5128. std::pair<bool, const char*> consistentNumberProperty(const char* lhs,
  5129. const char* rhs,
  5130. CompatibleType t)
  5131. {
  5132. char* pEnd;
  5133. long lnum = strtol(lhs, &pEnd, 0);
  5134. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) {
  5135. return { false, nullptr };
  5136. }
  5137. long rnum = strtol(rhs, &pEnd, 0);
  5138. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) {
  5139. return { false, nullptr };
  5140. }
  5141. if (t == NumberMaxType) {
  5142. return { true, std::max(lnum, rnum) == lnum ? lhs : rhs };
  5143. }
  5144. return { true, std::min(lnum, rnum) == lnum ? lhs : rhs };
  5145. }
  5146. template <>
  5147. std::pair<bool, const char*> consistentProperty(const char* lhs,
  5148. const char* rhs,
  5149. CompatibleType t)
  5150. {
  5151. if (!lhs && !rhs) {
  5152. return { true, lhs };
  5153. }
  5154. if (!lhs) {
  5155. return { true, rhs };
  5156. }
  5157. if (!rhs) {
  5158. return { true, lhs };
  5159. }
  5160. switch (t) {
  5161. case BoolType: {
  5162. bool same = cmIsOn(lhs) == cmIsOn(rhs);
  5163. return { same, same ? lhs : nullptr };
  5164. }
  5165. case StringType:
  5166. return consistentStringProperty(lhs, rhs);
  5167. case NumberMinType:
  5168. case NumberMaxType:
  5169. return consistentNumberProperty(lhs, rhs, t);
  5170. }
  5171. assert(false && "Unreachable!");
  5172. return { false, nullptr };
  5173. }
  5174. std::pair<bool, std::string> consistentProperty(const std::string& lhs,
  5175. const std::string& rhs,
  5176. CompatibleType t)
  5177. {
  5178. const std::string null_ptr = valueAsString(nullptr);
  5179. if (lhs == null_ptr && rhs == null_ptr) {
  5180. return { true, lhs };
  5181. }
  5182. if (lhs == null_ptr) {
  5183. return { true, rhs };
  5184. }
  5185. if (rhs == null_ptr) {
  5186. return { true, lhs };
  5187. }
  5188. switch (t) {
  5189. case BoolType: {
  5190. bool same = cmIsOn(lhs) == cmIsOn(rhs);
  5191. return { same, same ? lhs : null_ptr };
  5192. }
  5193. case StringType:
  5194. return consistentStringProperty(lhs, rhs);
  5195. case NumberMinType:
  5196. case NumberMaxType: {
  5197. auto value = consistentNumberProperty(lhs.c_str(), rhs.c_str(), t);
  5198. return { value.first,
  5199. value.first ? std::string(value.second) : null_ptr };
  5200. }
  5201. }
  5202. assert(false && "Unreachable!");
  5203. return { false, null_ptr };
  5204. }
  5205. template <typename PropertyType>
  5206. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  5207. const std::string& p,
  5208. const std::string& config,
  5209. const char* defaultValue,
  5210. CompatibleType t,
  5211. PropertyType* /*unused*/)
  5212. {
  5213. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
  5214. std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
  5215. const bool explicitlySet = cm::contains(headPropKeys, p);
  5216. const bool impliedByUse = tgt->IsNullImpliedByLinkLibraries(p);
  5217. assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet));
  5218. std::vector<cmGeneratorTarget const*> const& deps =
  5219. tgt->GetLinkImplementationClosure(config);
  5220. if (deps.empty()) {
  5221. return propContent;
  5222. }
  5223. bool propInitialized = explicitlySet;
  5224. std::string report = cmStrCat(" * Target \"", tgt->GetName());
  5225. if (explicitlySet) {
  5226. report += "\" has property content \"";
  5227. report += valueAsString<PropertyType>(propContent);
  5228. report += "\"\n";
  5229. } else if (impliedByUse) {
  5230. report += "\" property is implied by use.\n";
  5231. } else {
  5232. report += "\" property not set.\n";
  5233. }
  5234. std::string interfaceProperty = "INTERFACE_" + p;
  5235. std::unique_ptr<cmGeneratorExpressionInterpreter> genexInterpreter;
  5236. if (p == "POSITION_INDEPENDENT_CODE") {
  5237. genexInterpreter = cm::make_unique<cmGeneratorExpressionInterpreter>(
  5238. tgt->GetLocalGenerator(), config, tgt);
  5239. }
  5240. for (cmGeneratorTarget const* theTarget : deps) {
  5241. // An error should be reported if one dependency
  5242. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  5243. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  5244. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  5245. // with a dependency.
  5246. std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
  5247. const bool ifaceIsSet = cm::contains(propKeys, interfaceProperty);
  5248. PropertyType ifacePropContent = getTypedProperty<PropertyType>(
  5249. theTarget, interfaceProperty, genexInterpreter.get());
  5250. std::string reportEntry;
  5251. if (ifaceIsSet) {
  5252. reportEntry += " * Target \"";
  5253. reportEntry += theTarget->GetName();
  5254. reportEntry += "\" property value \"";
  5255. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  5256. reportEntry += "\" ";
  5257. }
  5258. if (explicitlySet) {
  5259. if (ifaceIsSet) {
  5260. std::pair<bool, PropertyType> consistent =
  5261. consistentProperty(propContent, ifacePropContent, t);
  5262. report += reportEntry;
  5263. report += compatibilityAgree(t, propContent != consistent.second);
  5264. if (!consistent.first) {
  5265. std::ostringstream e;
  5266. e << "Property " << p << " on target \"" << tgt->GetName()
  5267. << "\" does\nnot match the "
  5268. "INTERFACE_"
  5269. << p
  5270. << " property requirement\nof "
  5271. "dependency \""
  5272. << theTarget->GetName() << "\".\n";
  5273. cmSystemTools::Error(e.str());
  5274. break;
  5275. }
  5276. propContent = consistent.second;
  5277. continue;
  5278. }
  5279. // Explicitly set on target and not set in iface. Can't disagree.
  5280. continue;
  5281. }
  5282. if (impliedByUse) {
  5283. propContent = impliedValue<PropertyType>(propContent);
  5284. if (ifaceIsSet) {
  5285. std::pair<bool, PropertyType> consistent =
  5286. consistentProperty(propContent, ifacePropContent, t);
  5287. report += reportEntry;
  5288. report += compatibilityAgree(t, propContent != consistent.second);
  5289. if (!consistent.first) {
  5290. std::ostringstream e;
  5291. e << "Property " << p << " on target \"" << tgt->GetName()
  5292. << "\" is\nimplied to be " << defaultValue
  5293. << " because it was used to determine the link libraries\n"
  5294. "already. The INTERFACE_"
  5295. << p << " property on\ndependency \"" << theTarget->GetName()
  5296. << "\" is in conflict.\n";
  5297. cmSystemTools::Error(e.str());
  5298. break;
  5299. }
  5300. propContent = consistent.second;
  5301. continue;
  5302. }
  5303. // Implicitly set on target and not set in iface. Can't disagree.
  5304. continue;
  5305. }
  5306. if (ifaceIsSet) {
  5307. if (propInitialized) {
  5308. std::pair<bool, PropertyType> consistent =
  5309. consistentProperty(propContent, ifacePropContent, t);
  5310. report += reportEntry;
  5311. report += compatibilityAgree(t, propContent != consistent.second);
  5312. if (!consistent.first) {
  5313. std::ostringstream e;
  5314. e << "The INTERFACE_" << p << " property of \""
  5315. << theTarget->GetName() << "\" does\nnot agree with the value of "
  5316. << p << " already determined\nfor \"" << tgt->GetName() << "\".\n";
  5317. cmSystemTools::Error(e.str());
  5318. break;
  5319. }
  5320. propContent = consistent.second;
  5321. continue;
  5322. }
  5323. report += reportEntry + "(Interface set)\n";
  5324. propContent = ifacePropContent;
  5325. propInitialized = true;
  5326. } else {
  5327. // Not set. Nothing to agree on.
  5328. continue;
  5329. }
  5330. }
  5331. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  5332. report, compatibilityType(t));
  5333. return propContent;
  5334. }
  5335. bool cmGeneratorTarget::SetDeviceLink(bool deviceLink)
  5336. {
  5337. bool previous = this->DeviceLink;
  5338. this->DeviceLink = deviceLink;
  5339. return previous;
  5340. }
  5341. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  5342. const std::string& p, const std::string& config) const
  5343. {
  5344. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  5345. BoolType, nullptr);
  5346. }
  5347. std::string cmGeneratorTarget::GetLinkInterfaceDependentStringAsBoolProperty(
  5348. const std::string& p, const std::string& config) const
  5349. {
  5350. return checkInterfacePropertyCompatibility<std::string>(
  5351. this, p, config, "FALSE", BoolType, nullptr);
  5352. }
  5353. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  5354. const std::string& p, const std::string& config) const
  5355. {
  5356. return checkInterfacePropertyCompatibility<const char*>(
  5357. this, p, config, "empty", StringType, nullptr);
  5358. }
  5359. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  5360. const std::string& p, const std::string& config) const
  5361. {
  5362. return checkInterfacePropertyCompatibility<const char*>(
  5363. this, p, config, "empty", NumberMinType, nullptr);
  5364. }
  5365. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  5366. const std::string& p, const std::string& config) const
  5367. {
  5368. return checkInterfacePropertyCompatibility<const char*>(
  5369. this, p, config, "empty", NumberMaxType, nullptr);
  5370. }
  5371. cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
  5372. const std::string& config) const
  5373. {
  5374. // Lookup any existing information for this configuration.
  5375. std::string key(cmSystemTools::UpperCase(config));
  5376. auto i = this->LinkInformation.find(key);
  5377. if (i == this->LinkInformation.end()) {
  5378. // Compute information for this configuration.
  5379. auto info = cm::make_unique<cmComputeLinkInformation>(this, config);
  5380. if (info && !info->Compute()) {
  5381. info.reset();
  5382. }
  5383. // Store the information for this configuration.
  5384. i = this->LinkInformation.emplace(key, std::move(info)).first;
  5385. if (i->second) {
  5386. this->CheckPropertyCompatibility(*i->second, config);
  5387. }
  5388. }
  5389. return i->second.get();
  5390. }
  5391. void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
  5392. {
  5393. int patch;
  5394. this->GetTargetVersion("VERSION", major, minor, patch);
  5395. }
  5396. void cmGeneratorTarget::GetTargetVersionFallback(
  5397. const std::string& property, const std::string& fallback_property,
  5398. int& major, int& minor, int& patch) const
  5399. {
  5400. if (this->GetProperty(property)) {
  5401. this->GetTargetVersion(property, major, minor, patch);
  5402. } else {
  5403. this->GetTargetVersion(fallback_property, major, minor, patch);
  5404. }
  5405. }
  5406. void cmGeneratorTarget::GetTargetVersion(const std::string& property,
  5407. int& major, int& minor,
  5408. int& patch) const
  5409. {
  5410. // Set the default values.
  5411. major = 0;
  5412. minor = 0;
  5413. patch = 0;
  5414. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  5415. if (cmProp version = this->GetProperty(property)) {
  5416. // Try to parse the version number and store the results that were
  5417. // successfully parsed.
  5418. int parsed_major;
  5419. int parsed_minor;
  5420. int parsed_patch;
  5421. switch (sscanf(version->c_str(), "%d.%d.%d", &parsed_major, &parsed_minor,
  5422. &parsed_patch)) {
  5423. case 3:
  5424. patch = parsed_patch;
  5425. CM_FALLTHROUGH;
  5426. case 2:
  5427. minor = parsed_minor;
  5428. CM_FALLTHROUGH;
  5429. case 1:
  5430. major = parsed_major;
  5431. CM_FALLTHROUGH;
  5432. default:
  5433. break;
  5434. }
  5435. }
  5436. }
  5437. std::string cmGeneratorTarget::GetRuntimeLinkLibrary(
  5438. std::string const& lang, std::string const& config) const
  5439. {
  5440. // This is activated by the presence of a default selection whether or
  5441. // not it is overridden by a property.
  5442. cmProp runtimeLibraryDefault = this->Makefile->GetDefinition(
  5443. cmStrCat("CMAKE_", lang, "_RUNTIME_LIBRARY_DEFAULT"));
  5444. if (!cmNonempty(runtimeLibraryDefault)) {
  5445. return std::string();
  5446. }
  5447. cmProp runtimeLibraryValue =
  5448. this->Target->GetProperty(cmStrCat(lang, "_RUNTIME_LIBRARY"));
  5449. if (!runtimeLibraryValue) {
  5450. runtimeLibraryValue = runtimeLibraryDefault;
  5451. }
  5452. return cmSystemTools::UpperCase(cmGeneratorExpression::Evaluate(
  5453. *runtimeLibraryValue, this->LocalGenerator, config, this));
  5454. }
  5455. std::string cmGeneratorTarget::GetFortranModuleDirectory(
  5456. std::string const& working_dir) const
  5457. {
  5458. if (!this->FortranModuleDirectoryCreated) {
  5459. this->FortranModuleDirectory =
  5460. this->CreateFortranModuleDirectory(working_dir);
  5461. this->FortranModuleDirectoryCreated = true;
  5462. }
  5463. return this->FortranModuleDirectory;
  5464. }
  5465. bool cmGeneratorTarget::IsFortranBuildingInstrinsicModules() const
  5466. {
  5467. if (cmProp prop = this->GetProperty("Fortran_BUILDING_INSTRINSIC_MODULES")) {
  5468. return cmIsOn(*prop);
  5469. }
  5470. return false;
  5471. }
  5472. std::string cmGeneratorTarget::CreateFortranModuleDirectory(
  5473. std::string const& working_dir) const
  5474. {
  5475. std::string mod_dir;
  5476. std::string target_mod_dir;
  5477. if (cmProp prop = this->GetProperty("Fortran_MODULE_DIRECTORY")) {
  5478. target_mod_dir = *prop;
  5479. } else {
  5480. std::string const& default_mod_dir =
  5481. this->LocalGenerator->GetCurrentBinaryDirectory();
  5482. if (default_mod_dir != working_dir) {
  5483. target_mod_dir = default_mod_dir;
  5484. }
  5485. }
  5486. cmProp moddir_flag =
  5487. this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
  5488. if (!target_mod_dir.empty() && moddir_flag) {
  5489. // Compute the full path to the module directory.
  5490. if (cmSystemTools::FileIsFullPath(target_mod_dir)) {
  5491. // Already a full path.
  5492. mod_dir = target_mod_dir;
  5493. } else {
  5494. // Interpret relative to the current output directory.
  5495. mod_dir = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(),
  5496. '/', target_mod_dir);
  5497. }
  5498. // Make sure the module output directory exists.
  5499. cmSystemTools::MakeDirectory(mod_dir);
  5500. }
  5501. return mod_dir;
  5502. }
  5503. void cmGeneratorTarget::AddISPCGeneratedHeader(std::string const& header,
  5504. std::string const& config)
  5505. {
  5506. std::string config_upper;
  5507. if (!config.empty()) {
  5508. config_upper = cmSystemTools::UpperCase(config);
  5509. }
  5510. auto iter = this->ISPCGeneratedHeaders.find(config_upper);
  5511. if (iter == this->ISPCGeneratedHeaders.end()) {
  5512. std::vector<std::string> headers;
  5513. headers.emplace_back(header);
  5514. this->ISPCGeneratedHeaders.insert({ config_upper, headers });
  5515. } else {
  5516. iter->second.emplace_back(header);
  5517. }
  5518. }
  5519. std::vector<std::string> cmGeneratorTarget::GetGeneratedISPCHeaders(
  5520. std::string const& config) const
  5521. {
  5522. std::string config_upper;
  5523. if (!config.empty()) {
  5524. config_upper = cmSystemTools::UpperCase(config);
  5525. }
  5526. auto iter = this->ISPCGeneratedHeaders.find(config_upper);
  5527. if (iter == this->ISPCGeneratedHeaders.end()) {
  5528. return std::vector<std::string>{};
  5529. }
  5530. return iter->second;
  5531. }
  5532. void cmGeneratorTarget::AddISPCGeneratedObject(std::vector<std::string>&& objs,
  5533. std::string const& config)
  5534. {
  5535. std::string config_upper;
  5536. if (!config.empty()) {
  5537. config_upper = cmSystemTools::UpperCase(config);
  5538. }
  5539. auto iter = this->ISPCGeneratedObjects.find(config_upper);
  5540. if (iter == this->ISPCGeneratedObjects.end()) {
  5541. this->ISPCGeneratedObjects.insert({ config_upper, objs });
  5542. } else {
  5543. iter->second.insert(iter->second.end(), objs.begin(), objs.end());
  5544. }
  5545. }
  5546. std::vector<std::string> cmGeneratorTarget::GetGeneratedISPCObjects(
  5547. std::string const& config) const
  5548. {
  5549. std::string config_upper;
  5550. if (!config.empty()) {
  5551. config_upper = cmSystemTools::UpperCase(config);
  5552. }
  5553. auto iter = this->ISPCGeneratedObjects.find(config_upper);
  5554. if (iter == this->ISPCGeneratedObjects.end()) {
  5555. return std::vector<std::string>{};
  5556. }
  5557. return iter->second;
  5558. }
  5559. std::string cmGeneratorTarget::GetFrameworkVersion() const
  5560. {
  5561. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  5562. if (cmProp fversion = this->GetProperty("FRAMEWORK_VERSION")) {
  5563. return *fversion;
  5564. }
  5565. if (cmProp tversion = this->GetProperty("VERSION")) {
  5566. return *tversion;
  5567. }
  5568. return "A";
  5569. }
  5570. void cmGeneratorTarget::ComputeVersionedName(std::string& vName,
  5571. std::string const& prefix,
  5572. std::string const& base,
  5573. std::string const& suffix,
  5574. std::string const& name,
  5575. const char* version) const
  5576. {
  5577. vName = this->Makefile->IsOn("APPLE") ? (prefix + base) : name;
  5578. if (version) {
  5579. vName += ".";
  5580. vName += version;
  5581. }
  5582. vName += this->Makefile->IsOn("APPLE") ? suffix : std::string();
  5583. }
  5584. std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const
  5585. {
  5586. return this->Target->GetProperties().GetKeys();
  5587. }
  5588. void cmGeneratorTarget::ReportPropertyOrigin(
  5589. const std::string& p, const std::string& result, const std::string& report,
  5590. const std::string& compatibilityType) const
  5591. {
  5592. std::vector<std::string> debugProperties;
  5593. this->Target->GetMakefile()->GetDefExpandList(
  5594. "CMAKE_DEBUG_TARGET_PROPERTIES", debugProperties);
  5595. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] &&
  5596. cm::contains(debugProperties, p);
  5597. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  5598. this->DebugCompatiblePropertiesDone[p] = true;
  5599. }
  5600. if (!debugOrigin) {
  5601. return;
  5602. }
  5603. std::string areport =
  5604. cmStrCat(compatibilityType, " of property \"", p, "\" for target \"",
  5605. this->GetName(), "\" (result: \"", result, "\"):\n", report);
  5606. this->LocalGenerator->GetCMakeInstance()->IssueMessage(MessageType::LOG,
  5607. areport);
  5608. }
  5609. bool cmGeneratorTarget::IsLinkLookupScope(std::string const& n,
  5610. cmLocalGenerator const*& lg) const
  5611. {
  5612. if (cmHasLiteralPrefix(n, CMAKE_DIRECTORY_ID_SEP)) {
  5613. cmDirectoryId const dirId = n.substr(sizeof(CMAKE_DIRECTORY_ID_SEP) - 1);
  5614. if (dirId.String.empty()) {
  5615. lg = this->LocalGenerator;
  5616. return true;
  5617. }
  5618. if (cmLocalGenerator const* otherLG =
  5619. this->GlobalGenerator->FindLocalGenerator(dirId)) {
  5620. lg = otherLG;
  5621. return true;
  5622. }
  5623. }
  5624. return false;
  5625. }
  5626. cm::optional<cmLinkItem> cmGeneratorTarget::LookupLinkItem(
  5627. std::string const& n, cmListFileBacktrace const& bt,
  5628. LookupLinkItemScope* scope) const
  5629. {
  5630. cm::optional<cmLinkItem> maybeItem;
  5631. if (this->IsLinkLookupScope(n, scope->LG)) {
  5632. return maybeItem;
  5633. }
  5634. std::string name = this->CheckCMP0004(n);
  5635. if (name == this->GetName() || name.empty()) {
  5636. return maybeItem;
  5637. }
  5638. maybeItem = this->ResolveLinkItem(name, bt, scope->LG);
  5639. return maybeItem;
  5640. }
  5641. void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
  5642. std::string const& value,
  5643. std::string const& config,
  5644. cmGeneratorTarget const* headTarget,
  5645. bool usage_requirements_only,
  5646. cmLinkInterface& iface) const
  5647. {
  5648. // Keep this logic in sync with ComputeLinkImplementationLibraries.
  5649. cmGeneratorExpression ge;
  5650. cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr);
  5651. // The $<LINK_ONLY> expression may be in a link interface to specify
  5652. // private link dependencies that are otherwise excluded from usage
  5653. // requirements.
  5654. if (usage_requirements_only) {
  5655. dagChecker.SetTransitivePropertiesOnly();
  5656. }
  5657. std::vector<std::string> libs;
  5658. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  5659. cge->SetEvaluateForBuildsystem(true);
  5660. cmExpandList(cge->Evaluate(this->LocalGenerator, config, headTarget,
  5661. &dagChecker, this, headTarget->LinkerLanguage),
  5662. libs);
  5663. cmMakefile const* mf = this->LocalGenerator->GetMakefile();
  5664. LookupLinkItemScope scope{ this->LocalGenerator };
  5665. for (std::string const& lib : libs) {
  5666. if (cm::optional<cmLinkItem> maybeItem =
  5667. this->LookupLinkItem(lib, cge->GetBacktrace(), &scope)) {
  5668. if (!maybeItem->Target) {
  5669. // Report explicitly linked object files separately.
  5670. std::string const& maybeObj = maybeItem->AsStr();
  5671. if (cmSystemTools::FileIsFullPath(maybeObj)) {
  5672. cmSourceFile const* sf =
  5673. mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
  5674. if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  5675. iface.Objects.emplace_back(std::move(*maybeItem));
  5676. continue;
  5677. }
  5678. }
  5679. }
  5680. iface.Libraries.emplace_back(std::move(*maybeItem));
  5681. }
  5682. }
  5683. iface.HadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  5684. iface.HadContextSensitiveCondition = cge->GetHadContextSensitiveCondition();
  5685. iface.HadLinkLanguageSensitiveCondition =
  5686. cge->GetHadLinkLanguageSensitiveCondition();
  5687. }
  5688. cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
  5689. const std::string& config, cmGeneratorTarget const* head) const
  5690. {
  5691. return this->GetLinkInterface(config, head, false);
  5692. }
  5693. cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
  5694. const std::string& config, cmGeneratorTarget const* head,
  5695. bool secondPass) const
  5696. {
  5697. // Imported targets have their own link interface.
  5698. if (this->IsImported()) {
  5699. return this->GetImportLinkInterface(config, head, false, secondPass);
  5700. }
  5701. // Link interfaces are not supported for executables that do not
  5702. // export symbols.
  5703. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  5704. !this->IsExecutableWithExports()) {
  5705. return nullptr;
  5706. }
  5707. // Lookup any existing link interface for this configuration.
  5708. cmHeadToLinkInterfaceMap& hm = this->GetHeadToLinkInterfaceMap(config);
  5709. if (secondPass) {
  5710. hm.erase(head);
  5711. }
  5712. // If the link interface does not depend on the head target
  5713. // then return the one we computed first.
  5714. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  5715. return &hm.begin()->second;
  5716. }
  5717. cmOptionalLinkInterface& iface = hm[head];
  5718. if (!iface.LibrariesDone) {
  5719. iface.LibrariesDone = true;
  5720. this->ComputeLinkInterfaceLibraries(config, iface, head, false);
  5721. }
  5722. if (!iface.AllDone) {
  5723. iface.AllDone = true;
  5724. if (iface.Exists) {
  5725. this->ComputeLinkInterface(config, iface, head, secondPass);
  5726. this->ComputeLinkInterfaceRuntimeLibraries(config, iface);
  5727. }
  5728. }
  5729. return iface.Exists ? &iface : nullptr;
  5730. }
  5731. void cmGeneratorTarget::ComputeLinkInterface(
  5732. const std::string& config, cmOptionalLinkInterface& iface,
  5733. cmGeneratorTarget const* headTarget) const
  5734. {
  5735. this->ComputeLinkInterface(config, iface, headTarget, false);
  5736. }
  5737. void cmGeneratorTarget::ComputeLinkInterface(
  5738. const std::string& config, cmOptionalLinkInterface& iface,
  5739. cmGeneratorTarget const* headTarget, bool secondPass) const
  5740. {
  5741. if (iface.Explicit) {
  5742. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5743. this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  5744. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  5745. // Shared libraries may have runtime implementation dependencies
  5746. // on other shared libraries that are not in the interface.
  5747. std::set<cmLinkItem> emitted;
  5748. for (cmLinkItem const& lib : iface.Libraries) {
  5749. emitted.insert(lib);
  5750. }
  5751. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  5752. cmLinkImplementation const* impl =
  5753. this->GetLinkImplementation(config, secondPass);
  5754. for (cmLinkImplItem const& lib : impl->Libraries) {
  5755. if (emitted.insert(lib).second) {
  5756. if (lib.Target) {
  5757. // This is a runtime dependency on another shared library.
  5758. if (lib.Target->GetType() == cmStateEnums::SHARED_LIBRARY) {
  5759. iface.SharedDeps.push_back(lib);
  5760. }
  5761. } else {
  5762. // TODO: Recognize shared library file names. Perhaps this
  5763. // should be moved to cmComputeLinkInformation, but that
  5764. // creates a chicken-and-egg problem since this list is needed
  5765. // for its construction.
  5766. }
  5767. }
  5768. }
  5769. }
  5770. }
  5771. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  5772. this->GetPolicyStatusCMP0022() == cmPolicies::OLD) {
  5773. // The link implementation is the default link interface.
  5774. cmLinkImplementationLibraries const* impl =
  5775. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  5776. iface.ImplementationIsInterface = true;
  5777. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  5778. }
  5779. if (this->LinkLanguagePropagatesToDependents()) {
  5780. // Targets using this archive need its language runtime libraries.
  5781. if (cmLinkImplementation const* impl =
  5782. this->GetLinkImplementation(config, secondPass)) {
  5783. iface.Languages = impl->Languages;
  5784. }
  5785. }
  5786. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  5787. // Construct the property name suffix for this configuration.
  5788. std::string suffix = "_";
  5789. if (!config.empty()) {
  5790. suffix += cmSystemTools::UpperCase(config);
  5791. } else {
  5792. suffix += "NOCONFIG";
  5793. }
  5794. // How many repetitions are needed if this library has cyclic
  5795. // dependencies?
  5796. std::string propName = cmStrCat("LINK_INTERFACE_MULTIPLICITY", suffix);
  5797. if (cmProp config_reps = this->GetProperty(propName)) {
  5798. sscanf(config_reps->c_str(), "%u", &iface.Multiplicity);
  5799. } else if (cmProp reps =
  5800. this->GetProperty("LINK_INTERFACE_MULTIPLICITY")) {
  5801. sscanf(reps->c_str(), "%u", &iface.Multiplicity);
  5802. }
  5803. }
  5804. }
  5805. const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
  5806. const std::string& config, cmGeneratorTarget const* head,
  5807. bool usage_requirements_only) const
  5808. {
  5809. // Imported targets have their own link interface.
  5810. if (this->IsImported()) {
  5811. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  5812. }
  5813. // Link interfaces are not supported for executables that do not
  5814. // export symbols.
  5815. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  5816. !this->IsExecutableWithExports()) {
  5817. return nullptr;
  5818. }
  5819. // Lookup any existing link interface for this configuration.
  5820. cmHeadToLinkInterfaceMap& hm =
  5821. (usage_requirements_only
  5822. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  5823. : this->GetHeadToLinkInterfaceMap(config));
  5824. // If the link interface does not depend on the head target
  5825. // then return the one we computed first.
  5826. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  5827. return &hm.begin()->second;
  5828. }
  5829. cmOptionalLinkInterface& iface = hm[head];
  5830. if (!iface.LibrariesDone) {
  5831. iface.LibrariesDone = true;
  5832. this->ComputeLinkInterfaceLibraries(config, iface, head,
  5833. usage_requirements_only);
  5834. }
  5835. return iface.Exists ? &iface : nullptr;
  5836. }
  5837. std::string cmGeneratorTarget::GetDirectory(
  5838. const std::string& config, cmStateEnums::ArtifactType artifact) const
  5839. {
  5840. if (this->IsImported()) {
  5841. auto fullPath = this->Target->ImportedGetFullPath(config, artifact);
  5842. if (this->IsFrameworkOnApple()) {
  5843. cmsys::RegularExpressionMatch match;
  5844. if (FrameworkRegularExpression.find(fullPath.c_str(), match)) {
  5845. auto path = match.match(1);
  5846. if (!path.empty()) {
  5847. path.erase(path.length() - 1);
  5848. }
  5849. return path;
  5850. }
  5851. }
  5852. // Return the directory from which the target is imported.
  5853. return cmSystemTools::GetFilenamePath(fullPath);
  5854. }
  5855. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  5856. // Return the directory in which the target will be built.
  5857. switch (artifact) {
  5858. case cmStateEnums::RuntimeBinaryArtifact:
  5859. return info->OutDir;
  5860. case cmStateEnums::ImportLibraryArtifact:
  5861. return info->ImpDir;
  5862. }
  5863. }
  5864. return "";
  5865. }
  5866. bool cmGeneratorTarget::UsesDefaultOutputDir(
  5867. const std::string& config, cmStateEnums::ArtifactType artifact) const
  5868. {
  5869. std::string dir;
  5870. return this->ComputeOutputDir(config, artifact, dir);
  5871. }
  5872. cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
  5873. const std::string& config) const
  5874. {
  5875. // There is no output information for imported targets.
  5876. if (this->IsImported()) {
  5877. return nullptr;
  5878. }
  5879. // Only libraries and executables have well-defined output files.
  5880. if (!this->HaveWellDefinedOutputFiles()) {
  5881. std::string msg = cmStrCat("cmGeneratorTarget::GetOutputInfo called for ",
  5882. this->GetName(), " which has type ",
  5883. cmState::GetTargetTypeName(this->GetType()));
  5884. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  5885. return nullptr;
  5886. }
  5887. // Lookup/compute/cache the output information for this configuration.
  5888. std::string config_upper;
  5889. if (!config.empty()) {
  5890. config_upper = cmSystemTools::UpperCase(config);
  5891. }
  5892. auto i = this->OutputInfoMap.find(config_upper);
  5893. if (i == this->OutputInfoMap.end()) {
  5894. // Add empty info in map to detect potential recursion.
  5895. OutputInfo info;
  5896. OutputInfoMapType::value_type entry(config_upper, info);
  5897. i = this->OutputInfoMap.insert(entry).first;
  5898. // Compute output directories.
  5899. this->ComputeOutputDir(config, cmStateEnums::RuntimeBinaryArtifact,
  5900. info.OutDir);
  5901. this->ComputeOutputDir(config, cmStateEnums::ImportLibraryArtifact,
  5902. info.ImpDir);
  5903. if (!this->ComputePDBOutputDir("PDB", config, info.PdbDir)) {
  5904. info.PdbDir = info.OutDir;
  5905. }
  5906. // Now update the previously-prepared map entry.
  5907. i->second = info;
  5908. } else if (i->second.empty()) {
  5909. // An empty map entry indicates we have been called recursively
  5910. // from the above block.
  5911. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  5912. MessageType::FATAL_ERROR,
  5913. "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
  5914. this->GetBacktrace());
  5915. return nullptr;
  5916. }
  5917. return &i->second;
  5918. }
  5919. bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
  5920. cmStateEnums::ArtifactType artifact,
  5921. std::string& out) const
  5922. {
  5923. bool usesDefaultOutputDir = false;
  5924. std::string conf = config;
  5925. // Look for a target property defining the target output directory
  5926. // based on the target type.
  5927. std::string targetTypeName = this->GetOutputTargetType(artifact);
  5928. std::string propertyName;
  5929. if (!targetTypeName.empty()) {
  5930. propertyName = cmStrCat(targetTypeName, "_OUTPUT_DIRECTORY");
  5931. }
  5932. // Check for a per-configuration output directory target property.
  5933. std::string configUpper = cmSystemTools::UpperCase(conf);
  5934. std::string configProp;
  5935. if (!targetTypeName.empty()) {
  5936. configProp = cmStrCat(targetTypeName, "_OUTPUT_DIRECTORY_", configUpper);
  5937. }
  5938. // Select an output directory.
  5939. if (cmProp config_outdir = this->GetProperty(configProp)) {
  5940. // Use the user-specified per-configuration output directory.
  5941. out = cmGeneratorExpression::Evaluate(*config_outdir, this->LocalGenerator,
  5942. config, this);
  5943. // Skip per-configuration subdirectory.
  5944. conf.clear();
  5945. } else if (cmProp outdir = this->GetProperty(propertyName)) {
  5946. // Use the user-specified output directory.
  5947. out = cmGeneratorExpression::Evaluate(*outdir, this->LocalGenerator,
  5948. config, this);
  5949. // Skip per-configuration subdirectory if the value contained a
  5950. // generator expression.
  5951. if (out != *outdir) {
  5952. conf.clear();
  5953. }
  5954. } else if (this->GetType() == cmStateEnums::EXECUTABLE) {
  5955. // Lookup the output path for executables.
  5956. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  5957. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  5958. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5959. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  5960. // Lookup the output path for libraries.
  5961. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  5962. }
  5963. if (out.empty()) {
  5964. // Default to the current output directory.
  5965. usesDefaultOutputDir = true;
  5966. out = ".";
  5967. }
  5968. // Convert the output path to a full path in case it is
  5969. // specified as a relative path. Treat a relative path as
  5970. // relative to the current output directory for this makefile.
  5971. out = (cmSystemTools::CollapseFullPath(
  5972. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  5973. // The generator may add the configuration's subdirectory.
  5974. if (!conf.empty()) {
  5975. bool useEPN =
  5976. this->GlobalGenerator->UseEffectivePlatformName(this->Makefile);
  5977. std::string suffix =
  5978. usesDefaultOutputDir && useEPN ? "${EFFECTIVE_PLATFORM_NAME}" : "";
  5979. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  5980. "/", conf, suffix, out);
  5981. }
  5982. return usesDefaultOutputDir;
  5983. }
  5984. bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
  5985. const std::string& config,
  5986. std::string& out) const
  5987. {
  5988. // Look for a target property defining the target output directory
  5989. // based on the target type.
  5990. std::string propertyName;
  5991. if (!kind.empty()) {
  5992. propertyName = cmStrCat(kind, "_OUTPUT_DIRECTORY");
  5993. }
  5994. std::string conf = config;
  5995. // Check for a per-configuration output directory target property.
  5996. std::string configUpper = cmSystemTools::UpperCase(conf);
  5997. std::string configProp;
  5998. if (!kind.empty()) {
  5999. configProp = cmStrCat(kind, "_OUTPUT_DIRECTORY_", configUpper);
  6000. }
  6001. // Select an output directory.
  6002. if (cmProp config_outdir = this->GetProperty(configProp)) {
  6003. // Use the user-specified per-configuration output directory.
  6004. out = cmGeneratorExpression::Evaluate(*config_outdir, this->LocalGenerator,
  6005. config);
  6006. // Skip per-configuration subdirectory.
  6007. conf.clear();
  6008. } else if (cmProp outdir = this->GetProperty(propertyName)) {
  6009. // Use the user-specified output directory.
  6010. out =
  6011. cmGeneratorExpression::Evaluate(*outdir, this->LocalGenerator, config);
  6012. // Skip per-configuration subdirectory if the value contained a
  6013. // generator expression.
  6014. if (out != *outdir) {
  6015. conf.clear();
  6016. }
  6017. }
  6018. if (out.empty()) {
  6019. return false;
  6020. }
  6021. // Convert the output path to a full path in case it is
  6022. // specified as a relative path. Treat a relative path as
  6023. // relative to the current output directory for this makefile.
  6024. out = (cmSystemTools::CollapseFullPath(
  6025. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  6026. // The generator may add the configuration's subdirectory.
  6027. if (!conf.empty()) {
  6028. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  6029. "/", conf, "", out);
  6030. }
  6031. return true;
  6032. }
  6033. bool cmGeneratorTarget::HaveInstallTreeRPATH(const std::string& config) const
  6034. {
  6035. std::string install_rpath;
  6036. this->GetInstallRPATH(config, install_rpath);
  6037. return !install_rpath.empty() &&
  6038. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  6039. }
  6040. bool cmGeneratorTarget::GetBuildRPATH(const std::string& config,
  6041. std::string& rpath) const
  6042. {
  6043. return this->GetRPATH(config, "BUILD_RPATH", rpath);
  6044. }
  6045. bool cmGeneratorTarget::GetInstallRPATH(const std::string& config,
  6046. std::string& rpath) const
  6047. {
  6048. return this->GetRPATH(config, "INSTALL_RPATH", rpath);
  6049. }
  6050. bool cmGeneratorTarget::GetRPATH(const std::string& config,
  6051. const std::string& prop,
  6052. std::string& rpath) const
  6053. {
  6054. cmProp value = this->GetProperty(prop);
  6055. if (!value) {
  6056. return false;
  6057. }
  6058. rpath =
  6059. cmGeneratorExpression::Evaluate(*value, this->LocalGenerator, config);
  6060. return true;
  6061. }
  6062. void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  6063. const std::string& config, cmOptionalLinkInterface& iface,
  6064. cmGeneratorTarget const* headTarget, bool usage_requirements_only) const
  6065. {
  6066. // Construct the property name suffix for this configuration.
  6067. std::string suffix = "_";
  6068. if (!config.empty()) {
  6069. suffix += cmSystemTools::UpperCase(config);
  6070. } else {
  6071. suffix += "NOCONFIG";
  6072. }
  6073. // An explicit list of interface libraries may be set for shared
  6074. // libraries and executables that export symbols.
  6075. cmProp explicitLibraries = nullptr;
  6076. std::string linkIfaceProp;
  6077. bool const cmp0022NEW = (this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  6078. this->GetPolicyStatusCMP0022() != cmPolicies::WARN);
  6079. if (cmp0022NEW) {
  6080. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  6081. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  6082. explicitLibraries = this->GetProperty(linkIfaceProp);
  6083. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6084. this->IsExecutableWithExports()) {
  6085. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  6086. // shared lib or executable.
  6087. // Lookup the per-configuration property.
  6088. linkIfaceProp = cmStrCat("LINK_INTERFACE_LIBRARIES", suffix);
  6089. explicitLibraries = this->GetProperty(linkIfaceProp);
  6090. // If not set, try the generic property.
  6091. if (!explicitLibraries) {
  6092. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  6093. explicitLibraries = this->GetProperty(linkIfaceProp);
  6094. }
  6095. }
  6096. if (explicitLibraries &&
  6097. this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  6098. !this->PolicyWarnedCMP0022) {
  6099. // Compare the explicitly set old link interface properties to the
  6100. // preferred new link interface property one and warn if different.
  6101. cmProp newExplicitLibraries =
  6102. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  6103. if (newExplicitLibraries &&
  6104. (*newExplicitLibraries != *explicitLibraries)) {
  6105. std::ostringstream w;
  6106. /* clang-format off */
  6107. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  6108. "Target \"" << this->GetName() << "\" has an "
  6109. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  6110. linkIfaceProp << " properties."
  6111. "\n"
  6112. "INTERFACE_LINK_LIBRARIES:\n"
  6113. " " << *newExplicitLibraries << "\n" <<
  6114. linkIfaceProp << ":\n"
  6115. " " << *explicitLibraries << "\n";
  6116. /* clang-format on */
  6117. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
  6118. this->PolicyWarnedCMP0022 = true;
  6119. }
  6120. }
  6121. // There is no implicit link interface for executables or modules
  6122. // so if none was explicitly set then there is no link interface.
  6123. if (!explicitLibraries &&
  6124. (this->GetType() == cmStateEnums::EXECUTABLE ||
  6125. (this->GetType() == cmStateEnums::MODULE_LIBRARY))) {
  6126. return;
  6127. }
  6128. iface.Exists = true;
  6129. iface.Explicit = cmp0022NEW || explicitLibraries;
  6130. if (explicitLibraries) {
  6131. // The interface libraries have been explicitly set.
  6132. this->ExpandLinkItems(linkIfaceProp, *explicitLibraries, config,
  6133. headTarget, usage_requirements_only, iface);
  6134. return;
  6135. }
  6136. // If CMP0022 is NEW then the plain tll signature sets the
  6137. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  6138. // cleared the property explicitly and we should not fall back
  6139. // to the link implementation.
  6140. if (cmp0022NEW) {
  6141. return;
  6142. }
  6143. // The link implementation is the default link interface.
  6144. if (cmLinkImplementationLibraries const* impl =
  6145. this->GetLinkImplementationLibrariesInternal(config, headTarget)) {
  6146. iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(),
  6147. impl->Libraries.end());
  6148. if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  6149. !this->PolicyWarnedCMP0022 && !usage_requirements_only) {
  6150. // Compare the link implementation fallback link interface to the
  6151. // preferred new link interface property and warn if different.
  6152. cmLinkInterface ifaceNew;
  6153. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  6154. if (cmProp newExplicitLibraries = this->GetProperty(newProp)) {
  6155. this->ExpandLinkItems(newProp, *newExplicitLibraries, config,
  6156. headTarget, usage_requirements_only, ifaceNew);
  6157. }
  6158. if (ifaceNew.Libraries != iface.Libraries) {
  6159. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  6160. std::string newLibraries = cmJoin(ifaceNew.Libraries, ";");
  6161. if (oldLibraries.empty()) {
  6162. oldLibraries = "(empty)";
  6163. }
  6164. if (newLibraries.empty()) {
  6165. newLibraries = "(empty)";
  6166. }
  6167. std::ostringstream w;
  6168. /* clang-format off */
  6169. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  6170. "Target \"" << this->GetName() << "\" has an "
  6171. "INTERFACE_LINK_LIBRARIES property. "
  6172. "This should be preferred as the source of the link interface "
  6173. "for this library but because CMP0022 is not set CMake is "
  6174. "ignoring the property and using the link implementation "
  6175. "as the link interface instead."
  6176. "\n"
  6177. "INTERFACE_LINK_LIBRARIES:\n"
  6178. " " << newLibraries << "\n"
  6179. "Link implementation:\n"
  6180. " " << oldLibraries << "\n";
  6181. /* clang-format on */
  6182. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING,
  6183. w.str());
  6184. this->PolicyWarnedCMP0022 = true;
  6185. }
  6186. }
  6187. }
  6188. }
  6189. namespace {
  6190. template <typename ReturnType>
  6191. ReturnType constructItem(cmGeneratorTarget* target,
  6192. cmListFileBacktrace const& bt);
  6193. template <>
  6194. inline cmLinkImplItem constructItem(cmGeneratorTarget* target,
  6195. cmListFileBacktrace const& bt)
  6196. {
  6197. return cmLinkImplItem(cmLinkItem(target, false, bt), false);
  6198. }
  6199. template <>
  6200. inline cmLinkItem constructItem(cmGeneratorTarget* target,
  6201. cmListFileBacktrace const& bt)
  6202. {
  6203. return cmLinkItem(target, false, bt);
  6204. }
  6205. template <typename ValueType>
  6206. std::vector<ValueType> computeImplicitLanguageTargets(
  6207. std::string const& lang, std::string const& config,
  6208. cmGeneratorTarget const* currentTarget)
  6209. {
  6210. cmListFileBacktrace bt;
  6211. std::vector<ValueType> result;
  6212. cmLocalGenerator* lg = currentTarget->GetLocalGenerator();
  6213. std::string const& runtimeLibrary =
  6214. currentTarget->GetRuntimeLinkLibrary(lang, config);
  6215. if (cmProp runtimeLinkOptions = currentTarget->Makefile->GetDefinition(
  6216. "CMAKE_" + lang + "_RUNTIME_LIBRARIES_" + runtimeLibrary)) {
  6217. std::vector<std::string> libsVec = cmExpandedList(*runtimeLinkOptions);
  6218. result.reserve(libsVec.size());
  6219. for (std::string const& i : libsVec) {
  6220. cmGeneratorTarget::TargetOrString resolved =
  6221. currentTarget->ResolveTargetReference(i, lg);
  6222. if (resolved.Target) {
  6223. result.emplace_back(constructItem<ValueType>(resolved.Target, bt));
  6224. }
  6225. }
  6226. }
  6227. return result;
  6228. }
  6229. }
  6230. void cmGeneratorTarget::ComputeLinkInterfaceRuntimeLibraries(
  6231. const std::string& config, cmOptionalLinkInterface& iface) const
  6232. {
  6233. for (std::string const& lang : iface.Languages) {
  6234. if ((lang == "CUDA" || lang == "HIP") &&
  6235. iface.LanguageRuntimeLibraries.find(lang) ==
  6236. iface.LanguageRuntimeLibraries.end()) {
  6237. auto implicitTargets =
  6238. computeImplicitLanguageTargets<cmLinkItem>(lang, config, this);
  6239. iface.LanguageRuntimeLibraries[lang] = std::move(implicitTargets);
  6240. }
  6241. }
  6242. }
  6243. void cmGeneratorTarget::ComputeLinkImplementationRuntimeLibraries(
  6244. const std::string& config, cmOptionalLinkImplementation& impl) const
  6245. {
  6246. for (std::string const& lang : impl.Languages) {
  6247. if ((lang == "CUDA" || lang == "HIP") &&
  6248. impl.LanguageRuntimeLibraries.find(lang) ==
  6249. impl.LanguageRuntimeLibraries.end()) {
  6250. auto implicitTargets =
  6251. computeImplicitLanguageTargets<cmLinkImplItem>(lang, config, this);
  6252. impl.LanguageRuntimeLibraries[lang] = std::move(implicitTargets);
  6253. }
  6254. }
  6255. }
  6256. const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
  6257. const std::string& config, cmGeneratorTarget const* headTarget,
  6258. bool usage_requirements_only, bool secondPass) const
  6259. {
  6260. cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
  6261. if (!info) {
  6262. return nullptr;
  6263. }
  6264. cmHeadToLinkInterfaceMap& hm =
  6265. (usage_requirements_only
  6266. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  6267. : this->GetHeadToLinkInterfaceMap(config));
  6268. if (secondPass) {
  6269. hm.erase(headTarget);
  6270. }
  6271. // If the link interface does not depend on the head target
  6272. // then return the one we computed first.
  6273. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  6274. return &hm.begin()->second;
  6275. }
  6276. cmOptionalLinkInterface& iface = hm[headTarget];
  6277. if (!iface.AllDone) {
  6278. iface.AllDone = true;
  6279. iface.Multiplicity = info->Multiplicity;
  6280. cmExpandList(info->Languages, iface.Languages);
  6281. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  6282. headTarget, usage_requirements_only, iface);
  6283. std::vector<std::string> deps = cmExpandedList(info->SharedDeps);
  6284. LookupLinkItemScope scope{ this->LocalGenerator };
  6285. for (std::string const& dep : deps) {
  6286. if (cm::optional<cmLinkItem> maybeItem =
  6287. this->LookupLinkItem(dep, cmListFileBacktrace(), &scope)) {
  6288. iface.SharedDeps.emplace_back(std::move(*maybeItem));
  6289. }
  6290. }
  6291. }
  6292. return &iface;
  6293. }
  6294. cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo(
  6295. const std::string& config) const
  6296. {
  6297. // There is no imported information for non-imported targets.
  6298. if (!this->IsImported()) {
  6299. return nullptr;
  6300. }
  6301. // Lookup/compute/cache the import information for this
  6302. // configuration.
  6303. std::string config_upper;
  6304. if (!config.empty()) {
  6305. config_upper = cmSystemTools::UpperCase(config);
  6306. } else {
  6307. config_upper = "NOCONFIG";
  6308. }
  6309. auto i = this->ImportInfoMap.find(config_upper);
  6310. if (i == this->ImportInfoMap.end()) {
  6311. ImportInfo info;
  6312. this->ComputeImportInfo(config_upper, info);
  6313. ImportInfoMapType::value_type entry(config_upper, info);
  6314. i = this->ImportInfoMap.insert(entry).first;
  6315. }
  6316. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  6317. return &i->second;
  6318. }
  6319. // If the location is empty then the target is not available for
  6320. // this configuration.
  6321. if (i->second.Location.empty() && i->second.ImportLibrary.empty()) {
  6322. return nullptr;
  6323. }
  6324. // Return the import information.
  6325. return &i->second;
  6326. }
  6327. void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
  6328. ImportInfo& info) const
  6329. {
  6330. // This method finds information about an imported target from its
  6331. // properties. The "IMPORTED_" namespace is reserved for properties
  6332. // defined by the project exporting the target.
  6333. // Initialize members.
  6334. info.NoSOName = false;
  6335. cmProp loc = nullptr;
  6336. cmProp imp = nullptr;
  6337. std::string suffix;
  6338. if (!this->Target->GetMappedConfig(desired_config, loc, imp, suffix)) {
  6339. return;
  6340. }
  6341. // Get the link interface.
  6342. {
  6343. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  6344. cmProp propertyLibs = this->GetProperty(linkProp);
  6345. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  6346. if (!propertyLibs) {
  6347. linkProp = cmStrCat("IMPORTED_LINK_INTERFACE_LIBRARIES", suffix);
  6348. propertyLibs = this->GetProperty(linkProp);
  6349. }
  6350. if (!propertyLibs) {
  6351. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  6352. propertyLibs = this->GetProperty(linkProp);
  6353. }
  6354. }
  6355. if (propertyLibs) {
  6356. info.LibrariesProp = linkProp;
  6357. info.Libraries = *propertyLibs;
  6358. }
  6359. }
  6360. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  6361. if (loc) {
  6362. info.LibName = *loc;
  6363. }
  6364. return;
  6365. }
  6366. // A provided configuration has been chosen. Load the
  6367. // configuration's properties.
  6368. // Get the location.
  6369. if (loc) {
  6370. info.Location = *loc;
  6371. } else {
  6372. std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix);
  6373. if (cmProp config_location = this->GetProperty(impProp)) {
  6374. info.Location = *config_location;
  6375. } else if (cmProp location = this->GetProperty("IMPORTED_LOCATION")) {
  6376. info.Location = *location;
  6377. }
  6378. }
  6379. // Get the soname.
  6380. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  6381. std::string soProp = cmStrCat("IMPORTED_SONAME", suffix);
  6382. if (cmProp config_soname = this->GetProperty(soProp)) {
  6383. info.SOName = *config_soname;
  6384. } else if (cmProp soname = this->GetProperty("IMPORTED_SONAME")) {
  6385. info.SOName = *soname;
  6386. }
  6387. }
  6388. // Get the "no-soname" mark.
  6389. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  6390. std::string soProp = cmStrCat("IMPORTED_NO_SONAME", suffix);
  6391. if (cmProp config_no_soname = this->GetProperty(soProp)) {
  6392. info.NoSOName = cmIsOn(*config_no_soname);
  6393. } else if (cmProp no_soname = this->GetProperty("IMPORTED_NO_SONAME")) {
  6394. info.NoSOName = cmIsOn(*no_soname);
  6395. }
  6396. }
  6397. // Get the import library.
  6398. if (imp) {
  6399. info.ImportLibrary = *imp;
  6400. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6401. this->IsExecutableWithExports()) {
  6402. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  6403. if (cmProp config_implib = this->GetProperty(impProp)) {
  6404. info.ImportLibrary = *config_implib;
  6405. } else if (cmProp implib = this->GetProperty("IMPORTED_IMPLIB")) {
  6406. info.ImportLibrary = *implib;
  6407. }
  6408. }
  6409. // Get the link dependencies.
  6410. {
  6411. std::string linkProp =
  6412. cmStrCat("IMPORTED_LINK_DEPENDENT_LIBRARIES", suffix);
  6413. if (cmProp config_libs = this->GetProperty(linkProp)) {
  6414. info.SharedDeps = *config_libs;
  6415. } else if (cmProp libs =
  6416. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES")) {
  6417. info.SharedDeps = *libs;
  6418. }
  6419. }
  6420. // Get the link languages.
  6421. if (this->LinkLanguagePropagatesToDependents()) {
  6422. std::string linkProp =
  6423. cmStrCat("IMPORTED_LINK_INTERFACE_LANGUAGES", suffix);
  6424. if (cmProp config_libs = this->GetProperty(linkProp)) {
  6425. info.Languages = *config_libs;
  6426. } else if (cmProp libs =
  6427. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES")) {
  6428. info.Languages = *libs;
  6429. }
  6430. }
  6431. // Get information if target is managed assembly.
  6432. {
  6433. std::string linkProp = "IMPORTED_COMMON_LANGUAGE_RUNTIME";
  6434. if (cmProp pc = this->GetProperty(linkProp + suffix)) {
  6435. info.Managed = this->CheckManagedType(*pc);
  6436. } else if (cmProp p = this->GetProperty(linkProp)) {
  6437. info.Managed = this->CheckManagedType(*p);
  6438. }
  6439. }
  6440. // Get the cyclic repetition count.
  6441. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  6442. std::string linkProp =
  6443. cmStrCat("IMPORTED_LINK_INTERFACE_MULTIPLICITY", suffix);
  6444. if (cmProp config_reps = this->GetProperty(linkProp)) {
  6445. sscanf(config_reps->c_str(), "%u", &info.Multiplicity);
  6446. } else if (cmProp reps =
  6447. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY")) {
  6448. sscanf(reps->c_str(), "%u", &info.Multiplicity);
  6449. }
  6450. }
  6451. }
  6452. cmHeadToLinkInterfaceMap& cmGeneratorTarget::GetHeadToLinkInterfaceMap(
  6453. const std::string& config) const
  6454. {
  6455. return this->LinkInterfaceMap[cmSystemTools::UpperCase(config)];
  6456. }
  6457. cmHeadToLinkInterfaceMap&
  6458. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  6459. const std::string& config) const
  6460. {
  6461. return this
  6462. ->LinkInterfaceUsageRequirementsOnlyMap[cmSystemTools::UpperCase(config)];
  6463. }
  6464. const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
  6465. const std::string& config) const
  6466. {
  6467. return this->GetLinkImplementation(config, false);
  6468. }
  6469. const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
  6470. const std::string& config, bool secondPass) const
  6471. {
  6472. // There is no link implementation for targets that cannot compile sources.
  6473. if (!this->CanCompileSources()) {
  6474. return nullptr;
  6475. }
  6476. cmOptionalLinkImplementation& impl =
  6477. this->LinkImplMap[cmSystemTools::UpperCase(config)][this];
  6478. if (secondPass) {
  6479. impl = cmOptionalLinkImplementation();
  6480. }
  6481. if (!impl.LibrariesDone) {
  6482. impl.LibrariesDone = true;
  6483. this->ComputeLinkImplementationLibraries(config, impl, this);
  6484. }
  6485. if (!impl.LanguagesDone) {
  6486. impl.LanguagesDone = true;
  6487. this->ComputeLinkImplementationLanguages(config, impl);
  6488. this->ComputeLinkImplementationRuntimeLibraries(config, impl);
  6489. }
  6490. return &impl;
  6491. }
  6492. bool cmGeneratorTarget::GetConfigCommonSourceFilesForXcode(
  6493. std::vector<cmSourceFile*>& files) const
  6494. {
  6495. std::vector<std::string> const& configs =
  6496. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  6497. auto it = configs.begin();
  6498. const std::string& firstConfig = *it;
  6499. this->GetSourceFilesWithoutObjectLibraries(files, firstConfig);
  6500. for (; it != configs.end(); ++it) {
  6501. std::vector<cmSourceFile*> configFiles;
  6502. this->GetSourceFilesWithoutObjectLibraries(configFiles, *it);
  6503. if (configFiles != files) {
  6504. std::string firstConfigFiles;
  6505. const char* sep = "";
  6506. for (cmSourceFile* f : files) {
  6507. firstConfigFiles += sep;
  6508. firstConfigFiles += f->ResolveFullPath();
  6509. sep = "\n ";
  6510. }
  6511. std::string thisConfigFiles;
  6512. sep = "";
  6513. for (cmSourceFile* f : configFiles) {
  6514. thisConfigFiles += sep;
  6515. thisConfigFiles += f->ResolveFullPath();
  6516. sep = "\n ";
  6517. }
  6518. std::ostringstream e;
  6519. /* clang-format off */
  6520. e << "Target \"" << this->GetName()
  6521. << "\" has source files which vary by "
  6522. "configuration. This is not supported by the \""
  6523. << this->GlobalGenerator->GetName()
  6524. << "\" generator.\n"
  6525. "Config \"" << firstConfig << "\":\n"
  6526. " " << firstConfigFiles << "\n"
  6527. "Config \"" << *it << "\":\n"
  6528. " " << thisConfigFiles << "\n";
  6529. /* clang-format on */
  6530. this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
  6531. return false;
  6532. }
  6533. }
  6534. return true;
  6535. }
  6536. void cmGeneratorTarget::GetObjectLibrariesCMP0026(
  6537. std::vector<cmGeneratorTarget*>& objlibs) const
  6538. {
  6539. // At configure-time, this method can be called as part of getting the
  6540. // LOCATION property or to export() a file to be include()d. However
  6541. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  6542. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  6543. // behavior of CMP0024 and CMP0026 only.
  6544. cmStringRange rng = this->Target->GetSourceEntries();
  6545. for (std::string const& entry : rng) {
  6546. std::vector<std::string> files = cmExpandedList(entry);
  6547. for (std::string const& li : files) {
  6548. if (cmHasLiteralPrefix(li, "$<TARGET_OBJECTS:") && li.back() == '>') {
  6549. std::string objLibName = li.substr(17, li.size() - 18);
  6550. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  6551. continue;
  6552. }
  6553. cmGeneratorTarget* objLib =
  6554. this->LocalGenerator->FindGeneratorTargetToUse(objLibName);
  6555. if (objLib) {
  6556. objlibs.push_back(objLib);
  6557. }
  6558. }
  6559. }
  6560. }
  6561. }
  6562. std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
  6563. {
  6564. // Strip whitespace off the library names because we used to do this
  6565. // in case variables were expanded at generate time. We no longer
  6566. // do the expansion but users link to libraries like " ${VAR} ".
  6567. std::string lib = item;
  6568. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  6569. if (pos != std::string::npos) {
  6570. lib = lib.substr(pos);
  6571. }
  6572. pos = lib.find_last_not_of(" \t\r\n");
  6573. if (pos != std::string::npos) {
  6574. lib = lib.substr(0, pos + 1);
  6575. }
  6576. if (lib != item) {
  6577. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  6578. switch (this->GetPolicyStatusCMP0004()) {
  6579. case cmPolicies::WARN: {
  6580. std::ostringstream w;
  6581. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  6582. << "Target \"" << this->GetName() << "\" links to item \"" << item
  6583. << "\" which has leading or trailing whitespace.";
  6584. cm->IssueMessage(MessageType::AUTHOR_WARNING, w.str(),
  6585. this->GetBacktrace());
  6586. }
  6587. case cmPolicies::OLD:
  6588. break;
  6589. case cmPolicies::NEW: {
  6590. std::ostringstream e;
  6591. e << "Target \"" << this->GetName() << "\" links to item \"" << item
  6592. << "\" which has leading or trailing whitespace. "
  6593. << "This is now an error according to policy CMP0004.";
  6594. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  6595. this->GetBacktrace());
  6596. } break;
  6597. case cmPolicies::REQUIRED_IF_USED:
  6598. case cmPolicies::REQUIRED_ALWAYS: {
  6599. std::ostringstream e;
  6600. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  6601. << "Target \"" << this->GetName() << "\" links to item \"" << item
  6602. << "\" which has leading or trailing whitespace.";
  6603. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  6604. this->GetBacktrace());
  6605. } break;
  6606. }
  6607. }
  6608. return lib;
  6609. }
  6610. bool cmGeneratorTarget::IsDeprecated() const
  6611. {
  6612. cmProp deprecation = this->GetProperty("DEPRECATION");
  6613. return cmNonempty(deprecation);
  6614. }
  6615. std::string cmGeneratorTarget::GetDeprecation() const
  6616. {
  6617. // find DEPRECATION property
  6618. if (cmProp deprecation = this->GetProperty("DEPRECATION")) {
  6619. return *deprecation;
  6620. }
  6621. return std::string();
  6622. }
  6623. void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
  6624. const std::string& config) const
  6625. {
  6626. // Targets that do not compile anything have no languages.
  6627. if (!this->CanCompileSources()) {
  6628. return;
  6629. }
  6630. std::vector<cmSourceFile*> sourceFiles;
  6631. this->GetSourceFiles(sourceFiles, config);
  6632. for (cmSourceFile* src : sourceFiles) {
  6633. const std::string& lang = src->GetOrDetermineLanguage();
  6634. if (!lang.empty()) {
  6635. languages.insert(lang);
  6636. }
  6637. }
  6638. std::vector<cmGeneratorTarget*> objectLibraries;
  6639. std::vector<cmSourceFile const*> externalObjects;
  6640. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  6641. std::vector<cmGeneratorTarget*> objectTargets;
  6642. this->GetObjectLibrariesCMP0026(objectTargets);
  6643. objectLibraries.reserve(objectTargets.size());
  6644. for (cmGeneratorTarget* gt : objectTargets) {
  6645. objectLibraries.push_back(gt);
  6646. }
  6647. } else {
  6648. this->GetExternalObjects(externalObjects, config);
  6649. for (cmSourceFile const* extObj : externalObjects) {
  6650. std::string objLib = extObj->GetObjectLibrary();
  6651. if (cmGeneratorTarget* tgt =
  6652. this->LocalGenerator->FindGeneratorTargetToUse(objLib)) {
  6653. auto const objLibIt =
  6654. std::find_if(objectLibraries.cbegin(), objectLibraries.cend(),
  6655. [tgt](cmGeneratorTarget* t) { return t == tgt; });
  6656. if (objectLibraries.cend() == objLibIt) {
  6657. objectLibraries.push_back(tgt);
  6658. }
  6659. }
  6660. }
  6661. }
  6662. for (cmGeneratorTarget* objLib : objectLibraries) {
  6663. objLib->GetLanguages(languages, config);
  6664. }
  6665. }
  6666. bool cmGeneratorTarget::IsLanguageUsed(std::string const& language,
  6667. std::string const& config) const
  6668. {
  6669. std::set<std::string> languages;
  6670. this->GetLanguages(languages, config);
  6671. return languages.count(language);
  6672. }
  6673. bool cmGeneratorTarget::IsCSharpOnly() const
  6674. {
  6675. // Only certain target types may compile CSharp.
  6676. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  6677. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  6678. this->GetType() != cmStateEnums::EXECUTABLE) {
  6679. return false;
  6680. }
  6681. std::set<std::string> languages = this->GetAllConfigCompileLanguages();
  6682. // Consider an explicit linker language property, but *not* the
  6683. // computed linker language that may depend on linked targets.
  6684. cmProp linkLang = this->GetProperty("LINKER_LANGUAGE");
  6685. if (cmNonempty(linkLang)) {
  6686. languages.insert(*linkLang);
  6687. }
  6688. return languages.size() == 1 && languages.count("CSharp") > 0;
  6689. }
  6690. void cmGeneratorTarget::ComputeLinkImplementationLanguages(
  6691. const std::string& config, cmOptionalLinkImplementation& impl) const
  6692. {
  6693. // This target needs runtime libraries for its source languages.
  6694. std::set<std::string> languages;
  6695. // Get languages used in our source files.
  6696. this->GetLanguages(languages, config);
  6697. // Copy the set of languages to the link implementation.
  6698. impl.Languages.insert(impl.Languages.begin(), languages.begin(),
  6699. languages.end());
  6700. }
  6701. bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
  6702. {
  6703. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH")) {
  6704. return false;
  6705. }
  6706. std::string build_rpath;
  6707. if (this->GetBuildRPATH(config, build_rpath)) {
  6708. return true;
  6709. }
  6710. if (cmLinkImplementationLibraries const* impl =
  6711. this->GetLinkImplementationLibraries(config)) {
  6712. return !impl->Libraries.empty();
  6713. }
  6714. return false;
  6715. }
  6716. cmLinkImplementationLibraries const*
  6717. cmGeneratorTarget::GetLinkImplementationLibraries(
  6718. const std::string& config) const
  6719. {
  6720. return this->GetLinkImplementationLibrariesInternal(config, this);
  6721. }
  6722. cmLinkImplementationLibraries const*
  6723. cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
  6724. const std::string& config, cmGeneratorTarget const* head) const
  6725. {
  6726. // There is no link implementation for targets that cannot compile sources.
  6727. if (!this->CanCompileSources()) {
  6728. return nullptr;
  6729. }
  6730. // Populate the link implementation libraries for this configuration.
  6731. HeadToLinkImplementationMap& hm =
  6732. this->LinkImplMap[cmSystemTools::UpperCase(config)];
  6733. // If the link implementation does not depend on the head target
  6734. // then return the one we computed first.
  6735. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  6736. return &hm.begin()->second;
  6737. }
  6738. cmOptionalLinkImplementation& impl = hm[head];
  6739. if (!impl.LibrariesDone) {
  6740. impl.LibrariesDone = true;
  6741. this->ComputeLinkImplementationLibraries(config, impl, head);
  6742. }
  6743. return &impl;
  6744. }
  6745. bool cmGeneratorTarget::IsNullImpliedByLinkLibraries(
  6746. const std::string& p) const
  6747. {
  6748. return cm::contains(this->LinkImplicitNullProperties, p);
  6749. }
  6750. void cmGeneratorTarget::ComputeLinkImplementationLibraries(
  6751. const std::string& config, cmOptionalLinkImplementation& impl,
  6752. cmGeneratorTarget const* head) const
  6753. {
  6754. cmLocalGenerator const* lg = this->LocalGenerator;
  6755. cmMakefile const* mf = lg->GetMakefile();
  6756. cmStringRange entryRange = this->Target->GetLinkImplementationEntries();
  6757. cmBacktraceRange btRange = this->Target->GetLinkImplementationBacktraces();
  6758. cmBacktraceRange::const_iterator btIt = btRange.begin();
  6759. // Collect libraries directly linked in this configuration.
  6760. for (cmStringRange::const_iterator le = entryRange.begin(),
  6761. end = entryRange.end();
  6762. le != end; ++le, ++btIt) {
  6763. std::vector<std::string> llibs;
  6764. // Keep this logic in sync with ExpandLinkItems.
  6765. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr,
  6766. nullptr);
  6767. cmGeneratorExpression ge(*btIt);
  6768. std::unique_ptr<cmCompiledGeneratorExpression> const cge = ge.Parse(*le);
  6769. cge->SetEvaluateForBuildsystem(true);
  6770. std::string const& evaluated =
  6771. cge->Evaluate(this->LocalGenerator, config, head, &dagChecker, nullptr,
  6772. this->LinkerLanguage);
  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 = this->ResolveLinkItem(name, *btIt, lg);
  6827. if (!item.Target) {
  6828. // Report explicitly linked object files separately.
  6829. std::string const& maybeObj = item.AsStr();
  6830. if (cmSystemTools::FileIsFullPath(maybeObj)) {
  6831. cmSourceFile const* sf =
  6832. mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
  6833. if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  6834. impl.Objects.emplace_back(std::move(item));
  6835. continue;
  6836. }
  6837. }
  6838. }
  6839. impl.Libraries.emplace_back(std::move(item), evaluated != *le);
  6840. }
  6841. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  6842. for (std::string const& sp : seenProps) {
  6843. if (!this->GetProperty(sp)) {
  6844. this->LinkImplicitNullProperties.insert(sp);
  6845. }
  6846. }
  6847. cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards);
  6848. }
  6849. // Get the list of configurations considered to be DEBUG.
  6850. std::vector<std::string> debugConfigs =
  6851. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  6852. cmTargetLinkLibraryType linkType =
  6853. CMP0003_ComputeLinkType(config, debugConfigs);
  6854. cmTarget::LinkLibraryVectorType const& oldllibs =
  6855. this->Target->GetOriginalLinkLibraries();
  6856. for (cmTarget::LibraryID const& oldllib : oldllibs) {
  6857. if (oldllib.second != GENERAL_LibraryType && oldllib.second != linkType) {
  6858. std::string name = this->CheckCMP0004(oldllib.first);
  6859. if (name == this->GetName() || name.empty()) {
  6860. continue;
  6861. }
  6862. // Support OLD behavior for CMP0003.
  6863. impl.WrongConfigLibraries.push_back(
  6864. this->ResolveLinkItem(name, cmListFileBacktrace()));
  6865. }
  6866. }
  6867. }
  6868. cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
  6869. std::string const& name) const
  6870. {
  6871. return this->ResolveTargetReference(name, this->LocalGenerator);
  6872. }
  6873. cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
  6874. std::string const& name, cmLocalGenerator const* lg) const
  6875. {
  6876. TargetOrString resolved;
  6877. if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(name)) {
  6878. resolved.Target = tgt;
  6879. } else {
  6880. resolved.String = name;
  6881. }
  6882. return resolved;
  6883. }
  6884. cmLinkItem cmGeneratorTarget::ResolveLinkItem(
  6885. std::string const& name, cmListFileBacktrace const& bt) const
  6886. {
  6887. return this->ResolveLinkItem(name, bt, this->LocalGenerator);
  6888. }
  6889. cmLinkItem cmGeneratorTarget::ResolveLinkItem(std::string const& name,
  6890. cmListFileBacktrace const& bt,
  6891. cmLocalGenerator const* lg) const
  6892. {
  6893. TargetOrString resolved = this->ResolveTargetReference(name, lg);
  6894. if (!resolved.Target) {
  6895. return cmLinkItem(resolved.String, false, bt);
  6896. }
  6897. // Check deprecation, issue message with `bt` backtrace.
  6898. if (resolved.Target->IsDeprecated()) {
  6899. std::ostringstream w;
  6900. /* clang-format off */
  6901. w <<
  6902. "The library that is being linked to, " << resolved.Target->GetName() <<
  6903. ", is marked as being deprecated by the owner. The message provided by "
  6904. "the developer is: \n" << resolved.Target->GetDeprecation() << "\n";
  6905. /* clang-format on */
  6906. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  6907. MessageType::AUTHOR_WARNING, w.str(), bt);
  6908. }
  6909. // Skip targets that will not really be linked. This is probably a
  6910. // name conflict between an external library and an executable
  6911. // within the project.
  6912. if (resolved.Target->GetType() == cmStateEnums::EXECUTABLE &&
  6913. !resolved.Target->IsExecutableWithExports()) {
  6914. return cmLinkItem(resolved.Target->GetName(), false, bt);
  6915. }
  6916. return cmLinkItem(resolved.Target, false, bt);
  6917. }
  6918. std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
  6919. {
  6920. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  6921. // Return the directory in which the target will be built.
  6922. return info->PdbDir;
  6923. }
  6924. return "";
  6925. }
  6926. bool cmGeneratorTarget::HasImplibGNUtoMS(std::string const& config) const
  6927. {
  6928. return this->HasImportLibrary(config) && this->GetPropertyAsBool("GNUtoMS");
  6929. }
  6930. bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& config,
  6931. std::string const& gnuName,
  6932. std::string& out,
  6933. const char* newExt) const
  6934. {
  6935. if (this->HasImplibGNUtoMS(config) && gnuName.size() > 6 &&
  6936. gnuName.substr(gnuName.size() - 6) == ".dll.a") {
  6937. out = cmStrCat(cm::string_view(gnuName).substr(0, gnuName.size() - 6),
  6938. newExt ? newExt : ".lib");
  6939. return true;
  6940. }
  6941. return false;
  6942. }
  6943. bool cmGeneratorTarget::HasContextDependentSources() const
  6944. {
  6945. return this->SourcesAreContextDependent == Tribool::True;
  6946. }
  6947. bool cmGeneratorTarget::IsExecutableWithExports() const
  6948. {
  6949. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  6950. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  6951. }
  6952. bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const
  6953. {
  6954. return (this->IsDLLPlatform() &&
  6955. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6956. this->IsExecutableWithExports()) &&
  6957. // Assemblies which have only managed code do not have
  6958. // import libraries.
  6959. this->GetManagedType(config) != ManagedType::Managed) ||
  6960. (this->Target->IsAIX() && this->IsExecutableWithExports());
  6961. }
  6962. bool cmGeneratorTarget::NeedImportLibraryName(std::string const& config) const
  6963. {
  6964. return this->HasImportLibrary(config) ||
  6965. // On DLL platforms we always generate the import library name
  6966. // just in case the sources have export markup.
  6967. (this->IsDLLPlatform() &&
  6968. (this->GetType() == cmStateEnums::EXECUTABLE ||
  6969. this->GetType() == cmStateEnums::MODULE_LIBRARY));
  6970. }
  6971. std::string cmGeneratorTarget::GetSupportDirectory() const
  6972. {
  6973. std::string dir = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(),
  6974. "/CMakeFiles/", this->GetName());
  6975. #if defined(__VMS)
  6976. dir += "_dir";
  6977. #else
  6978. dir += ".dir";
  6979. #endif
  6980. return dir;
  6981. }
  6982. bool cmGeneratorTarget::IsLinkable() const
  6983. {
  6984. return (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  6985. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6986. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  6987. this->GetType() == cmStateEnums::UNKNOWN_LIBRARY ||
  6988. this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  6989. this->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
  6990. this->IsExecutableWithExports());
  6991. }
  6992. bool cmGeneratorTarget::IsFrameworkOnApple() const
  6993. {
  6994. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6995. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  6996. this->Makefile->IsOn("APPLE") &&
  6997. this->GetPropertyAsBool("FRAMEWORK"));
  6998. }
  6999. bool cmGeneratorTarget::IsAppBundleOnApple() const
  7000. {
  7001. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  7002. this->Makefile->IsOn("APPLE") &&
  7003. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  7004. }
  7005. bool cmGeneratorTarget::IsXCTestOnApple() const
  7006. {
  7007. return (this->IsCFBundleOnApple() && this->GetPropertyAsBool("XCTEST"));
  7008. }
  7009. bool cmGeneratorTarget::IsCFBundleOnApple() const
  7010. {
  7011. return (this->GetType() == cmStateEnums::MODULE_LIBRARY &&
  7012. this->Makefile->IsOn("APPLE") && this->GetPropertyAsBool("BUNDLE"));
  7013. }
  7014. cmGeneratorTarget::ManagedType cmGeneratorTarget::CheckManagedType(
  7015. std::string const& propval) const
  7016. {
  7017. // The type of the managed assembly (mixed unmanaged C++ and C++/CLI,
  7018. // or only C++/CLI) does only depend on whether the property is an empty
  7019. // string or contains any value at all. In Visual Studio generators
  7020. // this propval is prepended with /clr[:] which results in:
  7021. //
  7022. // 1. propval does not exist: no /clr flag, unmanaged target, has import
  7023. // lib
  7024. // 2. empty propval: add /clr as flag, mixed unmanaged/managed
  7025. // target, has import lib
  7026. // 3. any value (safe,pure): add /clr:[propval] as flag, target with
  7027. // managed code only, no import lib
  7028. return propval.empty() ? ManagedType::Mixed : ManagedType::Managed;
  7029. }
  7030. cmGeneratorTarget::ManagedType cmGeneratorTarget::GetManagedType(
  7031. const std::string& config) const
  7032. {
  7033. // Only libraries and executables can be managed targets.
  7034. if (this->GetType() > cmStateEnums::SHARED_LIBRARY) {
  7035. return ManagedType::Undefined;
  7036. }
  7037. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  7038. return ManagedType::Native;
  7039. }
  7040. // Check imported target.
  7041. if (this->IsImported()) {
  7042. if (cmGeneratorTarget::ImportInfo const* info =
  7043. this->GetImportInfo(config)) {
  7044. return info->Managed;
  7045. }
  7046. return ManagedType::Undefined;
  7047. }
  7048. // Check for explicitly set clr target property.
  7049. if (cmProp clr = this->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  7050. return this->CheckManagedType(*clr);
  7051. }
  7052. // C# targets are always managed. This language specific check
  7053. // is added to avoid that the COMMON_LANGUAGE_RUNTIME target property
  7054. // has to be set manually for C# targets.
  7055. return this->IsCSharpOnly() ? ManagedType::Managed : ManagedType::Native;
  7056. }