cmGeneratorTarget.cxx 208 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238
  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 "cmsys/RegularExpression.hxx"
  5. #include <algorithm>
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <iterator>
  9. #include <memory> // IWYU pragma: keep
  10. #include <queue>
  11. #include <sstream>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <unordered_set>
  16. #include "cmAlgorithms.h"
  17. #include "cmComputeLinkInformation.h"
  18. #include "cmCustomCommand.h"
  19. #include "cmCustomCommandGenerator.h"
  20. #include "cmCustomCommandLines.h"
  21. #include "cmGeneratorExpression.h"
  22. #include "cmGeneratorExpressionDAGChecker.h"
  23. #include "cmGlobalGenerator.h"
  24. #include "cmLocalGenerator.h"
  25. #include "cmMakefile.h"
  26. #include "cmMessageType.h"
  27. #include "cmPropertyMap.h"
  28. #include "cmSourceFile.h"
  29. #include "cmSourceFileLocation.h"
  30. #include "cmState.h"
  31. #include "cmSystemTools.h"
  32. #include "cmTarget.h"
  33. #include "cmTargetLinkLibraryType.h"
  34. #include "cmTargetPropertyComputer.h"
  35. #include "cmake.h"
  36. class cmMessenger;
  37. template <>
  38. const char* cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
  39. cmGeneratorTarget const* tgt, cmMessenger* /* messenger */,
  40. cmListFileBacktrace const& /* context */)
  41. {
  42. return tgt->GetSourcesProperty();
  43. }
  44. template <>
  45. const char*
  46. cmTargetPropertyComputer::ComputeLocationForBuild<cmGeneratorTarget>(
  47. cmGeneratorTarget const* tgt)
  48. {
  49. return tgt->GetLocation("");
  50. }
  51. template <>
  52. const char* cmTargetPropertyComputer::ComputeLocation<cmGeneratorTarget>(
  53. cmGeneratorTarget const* tgt, const std::string& config)
  54. {
  55. return tgt->GetLocation(config);
  56. }
  57. class cmGeneratorTarget::TargetPropertyEntry
  58. {
  59. static cmLinkImplItem NoLinkImplItem;
  60. public:
  61. TargetPropertyEntry(std::unique_ptr<cmCompiledGeneratorExpression> cge,
  62. cmLinkImplItem const& item = NoLinkImplItem)
  63. : ge(std::move(cge))
  64. , LinkImplItem(item)
  65. {
  66. }
  67. const std::unique_ptr<cmCompiledGeneratorExpression> ge;
  68. cmLinkImplItem const& LinkImplItem;
  69. };
  70. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  71. void CreatePropertyGeneratorExpressions(
  72. cmStringRange entries, cmBacktraceRange backtraces,
  73. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
  74. bool evaluateForBuildsystem = false)
  75. {
  76. std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
  77. for (std::vector<std::string>::const_iterator it = entries.begin();
  78. it != entries.end(); ++it, ++btIt) {
  79. cmGeneratorExpression ge(*btIt);
  80. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
  81. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  82. items.push_back(
  83. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge)));
  84. }
  85. }
  86. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  87. : Target(t)
  88. , FortranModuleDirectoryCreated(false)
  89. , SourceFileFlagsConstructed(false)
  90. , PolicyWarnedCMP0022(false)
  91. , PolicyReportedCMP0069(false)
  92. , DebugIncludesDone(false)
  93. , DebugCompileOptionsDone(false)
  94. , DebugCompileFeaturesDone(false)
  95. , DebugCompileDefinitionsDone(false)
  96. , DebugLinkOptionsDone(false)
  97. , DebugLinkDirectoriesDone(false)
  98. , DebugSourcesDone(false)
  99. , LinkImplementationLanguageIsContextDependent(true)
  100. , UtilityItemsDone(false)
  101. {
  102. this->Makefile = this->Target->GetMakefile();
  103. this->LocalGenerator = lg;
  104. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  105. this->GlobalGenerator->ComputeTargetObjectDirectory(this);
  106. CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(),
  107. t->GetIncludeDirectoriesBacktraces(),
  108. this->IncludeDirectoriesEntries);
  109. CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(),
  110. t->GetCompileOptionsBacktraces(),
  111. this->CompileOptionsEntries);
  112. CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(),
  113. t->GetCompileFeaturesBacktraces(),
  114. this->CompileFeaturesEntries);
  115. CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(),
  116. t->GetCompileDefinitionsBacktraces(),
  117. this->CompileDefinitionsEntries);
  118. CreatePropertyGeneratorExpressions(t->GetLinkOptionsEntries(),
  119. t->GetLinkOptionsBacktraces(),
  120. this->LinkOptionsEntries);
  121. CreatePropertyGeneratorExpressions(t->GetLinkDirectoriesEntries(),
  122. t->GetLinkDirectoriesBacktraces(),
  123. this->LinkDirectoriesEntries);
  124. CreatePropertyGeneratorExpressions(t->GetSourceEntries(),
  125. t->GetSourceBacktraces(),
  126. this->SourceEntries, true);
  127. this->DLLPlatform =
  128. !this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty();
  129. this->PolicyMap = t->PolicyMap;
  130. }
  131. cmGeneratorTarget::~cmGeneratorTarget()
  132. {
  133. cmDeleteAll(this->IncludeDirectoriesEntries);
  134. cmDeleteAll(this->CompileOptionsEntries);
  135. cmDeleteAll(this->CompileFeaturesEntries);
  136. cmDeleteAll(this->CompileDefinitionsEntries);
  137. cmDeleteAll(this->LinkOptionsEntries);
  138. cmDeleteAll(this->LinkDirectoriesEntries);
  139. cmDeleteAll(this->SourceEntries);
  140. cmDeleteAll(this->LinkInformation);
  141. }
  142. const char* cmGeneratorTarget::GetSourcesProperty() const
  143. {
  144. std::vector<std::string> values;
  145. for (TargetPropertyEntry* se : this->SourceEntries) {
  146. values.push_back(se->ge->GetInput());
  147. }
  148. static std::string value;
  149. value.clear();
  150. value = cmJoin(values, ";");
  151. return value.c_str();
  152. }
  153. cmGlobalGenerator* cmGeneratorTarget::GetGlobalGenerator() const
  154. {
  155. return this->GetLocalGenerator()->GetGlobalGenerator();
  156. }
  157. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  158. {
  159. return this->LocalGenerator;
  160. }
  161. cmStateEnums::TargetType cmGeneratorTarget::GetType() const
  162. {
  163. return this->Target->GetType();
  164. }
  165. const std::string& cmGeneratorTarget::GetName() const
  166. {
  167. return this->Target->GetName();
  168. }
  169. std::string cmGeneratorTarget::GetExportName() const
  170. {
  171. const char* exportName = this->GetProperty("EXPORT_NAME");
  172. if (exportName && *exportName) {
  173. if (!cmGeneratorExpression::IsValidTargetName(exportName)) {
  174. std::ostringstream e;
  175. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  176. << this->GetName() << "\": is not valid.";
  177. cmSystemTools::Error(e.str().c_str());
  178. return "";
  179. }
  180. return exportName;
  181. }
  182. return this->GetName();
  183. }
  184. const char* cmGeneratorTarget::GetProperty(const std::string& prop) const
  185. {
  186. if (!cmTargetPropertyComputer::PassesWhitelist(
  187. this->GetType(), prop, this->Makefile->GetMessenger(),
  188. this->GetBacktrace())) {
  189. return nullptr;
  190. }
  191. if (const char* result = cmTargetPropertyComputer::GetProperty(
  192. this, prop, this->Makefile->GetMessenger(), this->GetBacktrace())) {
  193. return result;
  194. }
  195. if (cmSystemTools::GetFatalErrorOccured()) {
  196. return nullptr;
  197. }
  198. return this->Target->GetProperty(prop);
  199. }
  200. const char* cmGeneratorTarget::GetSafeProperty(const std::string& prop) const
  201. {
  202. const char* ret = this->GetProperty(prop);
  203. if (!ret) {
  204. return "";
  205. }
  206. return ret;
  207. }
  208. const char* cmGeneratorTarget::GetOutputTargetType(
  209. cmStateEnums::ArtifactType artifact) const
  210. {
  211. switch (this->GetType()) {
  212. case cmStateEnums::SHARED_LIBRARY:
  213. if (this->IsDLLPlatform()) {
  214. switch (artifact) {
  215. case cmStateEnums::RuntimeBinaryArtifact:
  216. // A DLL shared library is treated as a runtime target.
  217. return "RUNTIME";
  218. case cmStateEnums::ImportLibraryArtifact:
  219. // A DLL import library is treated as an archive target.
  220. return "ARCHIVE";
  221. }
  222. } else {
  223. // For non-DLL platforms shared libraries are treated as
  224. // library targets.
  225. return "LIBRARY";
  226. }
  227. break;
  228. case cmStateEnums::STATIC_LIBRARY:
  229. // Static libraries are always treated as archive targets.
  230. return "ARCHIVE";
  231. case cmStateEnums::MODULE_LIBRARY:
  232. switch (artifact) {
  233. case cmStateEnums::RuntimeBinaryArtifact:
  234. // Module libraries are always treated as library targets.
  235. return "LIBRARY";
  236. case cmStateEnums::ImportLibraryArtifact:
  237. // Module import libraries are treated as archive targets.
  238. return "ARCHIVE";
  239. }
  240. break;
  241. case cmStateEnums::OBJECT_LIBRARY:
  242. // Object libraries are always treated as object targets.
  243. return "OBJECT";
  244. case cmStateEnums::EXECUTABLE:
  245. switch (artifact) {
  246. case cmStateEnums::RuntimeBinaryArtifact:
  247. // Executables are always treated as runtime targets.
  248. return "RUNTIME";
  249. case cmStateEnums::ImportLibraryArtifact:
  250. // Executable import libraries are treated as archive targets.
  251. return "ARCHIVE";
  252. }
  253. break;
  254. default:
  255. break;
  256. }
  257. return "";
  258. }
  259. std::string cmGeneratorTarget::GetOutputName(
  260. const std::string& config, cmStateEnums::ArtifactType artifact) const
  261. {
  262. // Lookup/compute/cache the output name for this configuration.
  263. OutputNameKey key(config, artifact);
  264. cmGeneratorTarget::OutputNameMapType::iterator i =
  265. this->OutputNameMap.find(key);
  266. if (i == this->OutputNameMap.end()) {
  267. // Add empty name in map to detect potential recursion.
  268. OutputNameMapType::value_type entry(key, "");
  269. i = this->OutputNameMap.insert(entry).first;
  270. // Compute output name.
  271. std::vector<std::string> props;
  272. std::string type = this->GetOutputTargetType(artifact);
  273. std::string configUpper = cmSystemTools::UpperCase(config);
  274. if (!type.empty() && !configUpper.empty()) {
  275. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  276. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  277. }
  278. if (!type.empty()) {
  279. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  280. props.push_back(type + "_OUTPUT_NAME");
  281. }
  282. if (!configUpper.empty()) {
  283. // OUTPUT_NAME_<CONFIG>
  284. props.push_back("OUTPUT_NAME_" + configUpper);
  285. // <CONFIG>_OUTPUT_NAME
  286. props.push_back(configUpper + "_OUTPUT_NAME");
  287. }
  288. // OUTPUT_NAME
  289. props.push_back("OUTPUT_NAME");
  290. std::string outName;
  291. for (std::string const& p : props) {
  292. if (const char* outNameProp = this->GetProperty(p)) {
  293. outName = outNameProp;
  294. break;
  295. }
  296. }
  297. if (outName.empty()) {
  298. outName = this->GetName();
  299. }
  300. // Now evaluate genex and update the previously-prepared map entry.
  301. cmGeneratorExpression ge;
  302. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  303. i->second = cge->Evaluate(this->LocalGenerator, config);
  304. } else if (i->second.empty()) {
  305. // An empty map entry indicates we have been called recursively
  306. // from the above block.
  307. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  308. MessageType::FATAL_ERROR,
  309. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  310. this->GetBacktrace());
  311. }
  312. return i->second;
  313. }
  314. void cmGeneratorTarget::ClearSourcesCache()
  315. {
  316. this->KindedSourcesMap.clear();
  317. this->LinkImplementationLanguageIsContextDependent = true;
  318. this->Objects.clear();
  319. }
  320. void cmGeneratorTarget::AddSourceCommon(const std::string& src)
  321. {
  322. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  323. cmGeneratorExpression ge(lfbt);
  324. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  325. cge->SetEvaluateForBuildsystem(true);
  326. this->SourceEntries.push_back(new TargetPropertyEntry(std::move(cge)));
  327. this->ClearSourcesCache();
  328. }
  329. void cmGeneratorTarget::AddSource(const std::string& src)
  330. {
  331. this->Target->AddSource(src);
  332. this->AddSourceCommon(src);
  333. }
  334. void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
  335. {
  336. this->Target->AddTracedSources(srcs);
  337. if (!srcs.empty()) {
  338. this->AddSourceCommon(cmJoin(srcs, ";"));
  339. }
  340. }
  341. void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
  342. bool before)
  343. {
  344. this->Target->InsertInclude(src, this->Makefile->GetBacktrace(), before);
  345. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  346. cmGeneratorExpression ge(lfbt);
  347. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  348. cge->SetEvaluateForBuildsystem(true);
  349. // Insert before begin/end
  350. std::vector<TargetPropertyEntry*>::iterator pos = before
  351. ? this->IncludeDirectoriesEntries.begin()
  352. : this->IncludeDirectoriesEntries.end();
  353. this->IncludeDirectoriesEntries.insert(
  354. pos, new TargetPropertyEntry(std::move(cge)));
  355. }
  356. std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
  357. cmSourceFile const* sf) const
  358. {
  359. SourceEntriesType::const_iterator i = this->SourceDepends.find(sf);
  360. if (i != this->SourceDepends.end()) {
  361. return &i->second.Depends;
  362. }
  363. return nullptr;
  364. }
  365. static void handleSystemIncludesDep(
  366. cmLocalGenerator* lg, cmGeneratorTarget const* depTgt,
  367. const std::string& config, cmGeneratorTarget const* headTarget,
  368. cmGeneratorExpressionDAGChecker* dagChecker,
  369. std::vector<std::string>& result, bool excludeImported,
  370. std::string const& language)
  371. {
  372. if (const char* dirs =
  373. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
  374. cmGeneratorExpression ge;
  375. cmSystemTools::ExpandListArgument(
  376. ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
  377. dagChecker, language),
  378. result);
  379. }
  380. if (!depTgt->IsImported() || excludeImported) {
  381. return;
  382. }
  383. if (const char* dirs =
  384. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES")) {
  385. cmGeneratorExpression ge;
  386. cmSystemTools::ExpandListArgument(
  387. ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
  388. dagChecker, language),
  389. result);
  390. }
  391. }
  392. /* clang-format off */
  393. #define IMPLEMENT_VISIT(KIND) \
  394. { \
  395. KindedSources const& kinded = this->GetKindedSources(config); \
  396. for (SourceAndKind const& s : kinded.Sources) { \
  397. if (s.Kind == KIND) { \
  398. data.push_back(s.Source.Value); \
  399. } \
  400. } \
  401. }
  402. /* clang-format on */
  403. void cmGeneratorTarget::GetObjectSources(
  404. std::vector<cmSourceFile const*>& data, const std::string& config) const
  405. {
  406. IMPLEMENT_VISIT(SourceKindObjectSource);
  407. if (!this->Objects.empty()) {
  408. return;
  409. }
  410. for (cmSourceFile const* it : data) {
  411. this->Objects[it];
  412. }
  413. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  414. }
  415. void cmGeneratorTarget::ComputeObjectMapping()
  416. {
  417. if (!this->Objects.empty()) {
  418. return;
  419. }
  420. std::vector<std::string> configs;
  421. this->Makefile->GetConfigurations(configs);
  422. if (configs.empty()) {
  423. configs.emplace_back();
  424. }
  425. for (std::string const& c : configs) {
  426. std::vector<cmSourceFile const*> sourceFiles;
  427. this->GetObjectSources(sourceFiles, c);
  428. }
  429. }
  430. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  431. const std::string& config) const
  432. {
  433. if (!config.empty()) {
  434. std::string featureConfig = feature;
  435. featureConfig += "_";
  436. featureConfig += cmSystemTools::UpperCase(config);
  437. if (const char* value = this->GetProperty(featureConfig)) {
  438. return value;
  439. }
  440. }
  441. if (const char* value = this->GetProperty(feature)) {
  442. return value;
  443. }
  444. return this->LocalGenerator->GetFeature(feature, config);
  445. }
  446. const char* cmGeneratorTarget::GetLinkPIEProperty(
  447. const std::string& config) const
  448. {
  449. static std::string PICValue;
  450. PICValue = this->GetLinkInterfaceDependentStringAsBoolProperty(
  451. "POSITION_INDEPENDENT_CODE", config);
  452. if (PICValue == "(unset)") {
  453. // POSITION_INDEPENDENT_CODE is not set
  454. return nullptr;
  455. }
  456. switch (this->GetPolicyStatusCMP0083()) {
  457. case cmPolicies::WARN: {
  458. std::ostringstream e;
  459. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0083);
  460. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
  461. CM_FALLTHROUGH;
  462. }
  463. case cmPolicies::OLD:
  464. return nullptr;
  465. default:
  466. // nothing to do
  467. break;
  468. }
  469. return PICValue.c_str();
  470. }
  471. bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang,
  472. std::string const& config) const
  473. {
  474. const char* feature = "INTERPROCEDURAL_OPTIMIZATION";
  475. const bool result = cmSystemTools::IsOn(this->GetFeature(feature, config));
  476. if (!result) {
  477. // 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies
  478. return false;
  479. }
  480. if (lang != "C" && lang != "CXX" && lang != "Fortran") {
  481. // We do not define IPO behavior for other languages.
  482. return false;
  483. }
  484. cmPolicies::PolicyStatus cmp0069 = this->GetPolicyStatusCMP0069();
  485. if (cmp0069 == cmPolicies::OLD || cmp0069 == cmPolicies::WARN) {
  486. if (this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_LEGACY_BEHAVIOR")) {
  487. return true;
  488. }
  489. if (this->PolicyReportedCMP0069) {
  490. // problem is already reported, no need to issue a message
  491. return false;
  492. }
  493. const bool in_try_compile =
  494. this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile();
  495. if (cmp0069 == cmPolicies::WARN && !in_try_compile) {
  496. std::ostringstream w;
  497. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0069) << "\n";
  498. w << "INTERPROCEDURAL_OPTIMIZATION property will be ignored for target "
  499. << "'" << this->GetName() << "'.";
  500. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  501. MessageType::AUTHOR_WARNING, w.str(), this->GetBacktrace());
  502. this->PolicyReportedCMP0069 = true;
  503. }
  504. return false;
  505. }
  506. // Note: check consistency with messages from CheckIPOSupported
  507. const char* message = nullptr;
  508. if (!this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_SUPPORTED_BY_CMAKE")) {
  509. message = "CMake doesn't support IPO for current compiler";
  510. } else if (!this->Makefile->IsOn("_CMAKE_" + lang +
  511. "_IPO_MAY_BE_SUPPORTED_BY_COMPILER")) {
  512. message = "Compiler doesn't support IPO";
  513. } else if (!this->GlobalGenerator->IsIPOSupported()) {
  514. message = "CMake doesn't support IPO for current generator";
  515. }
  516. if (!message) {
  517. // No error/warning messages
  518. return true;
  519. }
  520. if (this->PolicyReportedCMP0069) {
  521. // problem is already reported, no need to issue a message
  522. return false;
  523. }
  524. this->PolicyReportedCMP0069 = true;
  525. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  526. MessageType::FATAL_ERROR, message, this->GetBacktrace());
  527. return false;
  528. }
  529. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  530. {
  531. this->ComputeObjectMapping();
  532. return this->Objects[file];
  533. }
  534. const char* cmGeneratorTarget::GetCustomObjectExtension() const
  535. {
  536. static std::string extension;
  537. const bool has_ptx_extension =
  538. this->GetPropertyAsBool("CUDA_PTX_COMPILATION");
  539. if (has_ptx_extension) {
  540. extension = ".ptx";
  541. return extension.c_str();
  542. }
  543. return nullptr;
  544. }
  545. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  546. {
  547. this->ExplicitObjectName.insert(sf);
  548. }
  549. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  550. {
  551. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  552. std::set<cmSourceFile const*>::const_iterator it =
  553. this->ExplicitObjectName.find(file);
  554. return it != this->ExplicitObjectName.end();
  555. }
  556. void cmGeneratorTarget::GetModuleDefinitionSources(
  557. std::vector<cmSourceFile const*>& data, const std::string& config) const
  558. {
  559. IMPLEMENT_VISIT(SourceKindModuleDefinition);
  560. }
  561. void cmGeneratorTarget::GetHeaderSources(
  562. std::vector<cmSourceFile const*>& data, const std::string& config) const
  563. {
  564. IMPLEMENT_VISIT(SourceKindHeader);
  565. }
  566. void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile const*>& data,
  567. const std::string& config) const
  568. {
  569. IMPLEMENT_VISIT(SourceKindExtra);
  570. }
  571. void cmGeneratorTarget::GetCustomCommands(
  572. std::vector<cmSourceFile const*>& data, const std::string& config) const
  573. {
  574. IMPLEMENT_VISIT(SourceKindCustomCommand);
  575. }
  576. void cmGeneratorTarget::GetExternalObjects(
  577. std::vector<cmSourceFile const*>& data, const std::string& config) const
  578. {
  579. IMPLEMENT_VISIT(SourceKindExternalObject);
  580. }
  581. void cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& headers,
  582. const std::string& config) const
  583. {
  584. KindedSources const& kinded = this->GetKindedSources(config);
  585. headers = kinded.ExpectedResxHeaders;
  586. }
  587. void cmGeneratorTarget::GetResxSources(std::vector<cmSourceFile const*>& data,
  588. const std::string& config) const
  589. {
  590. IMPLEMENT_VISIT(SourceKindResx);
  591. }
  592. void cmGeneratorTarget::GetAppManifest(std::vector<cmSourceFile const*>& data,
  593. const std::string& config) const
  594. {
  595. IMPLEMENT_VISIT(SourceKindAppManifest);
  596. }
  597. void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data,
  598. const std::string& config) const
  599. {
  600. IMPLEMENT_VISIT(SourceKindManifest);
  601. }
  602. void cmGeneratorTarget::GetCertificates(std::vector<cmSourceFile const*>& data,
  603. const std::string& config) const
  604. {
  605. IMPLEMENT_VISIT(SourceKindCertificate);
  606. }
  607. void cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  608. const std::string& config) const
  609. {
  610. KindedSources const& kinded = this->GetKindedSources(config);
  611. headers = kinded.ExpectedXamlHeaders;
  612. }
  613. void cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  614. const std::string& config) const
  615. {
  616. KindedSources const& kinded = this->GetKindedSources(config);
  617. srcs = kinded.ExpectedXamlSources;
  618. }
  619. std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
  620. {
  621. if (!this->UtilityItemsDone) {
  622. this->UtilityItemsDone = true;
  623. std::set<BT<std::string>> const& utilities = this->GetUtilities();
  624. for (BT<std::string> const& i : utilities) {
  625. if (cmGeneratorTarget* gt =
  626. this->LocalGenerator->FindGeneratorTargetToUse(i.Value)) {
  627. this->UtilityItems.insert(cmLinkItem(gt, i.Backtrace));
  628. } else {
  629. this->UtilityItems.insert(cmLinkItem(i.Value, i.Backtrace));
  630. }
  631. }
  632. }
  633. return this->UtilityItems;
  634. }
  635. void cmGeneratorTarget::GetXamlSources(std::vector<cmSourceFile const*>& data,
  636. const std::string& config) const
  637. {
  638. IMPLEMENT_VISIT(SourceKindXaml);
  639. }
  640. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  641. {
  642. static std::string location;
  643. if (this->IsImported()) {
  644. location = this->Target->ImportedGetFullPath(
  645. config, cmStateEnums::RuntimeBinaryArtifact);
  646. } else {
  647. location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  648. }
  649. return location.c_str();
  650. }
  651. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreBuildCommands()
  652. const
  653. {
  654. return this->Target->GetPreBuildCommands();
  655. }
  656. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreLinkCommands()
  657. const
  658. {
  659. return this->Target->GetPreLinkCommands();
  660. }
  661. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPostBuildCommands()
  662. const
  663. {
  664. return this->Target->GetPostBuildCommands();
  665. }
  666. bool cmGeneratorTarget::IsImported() const
  667. {
  668. return this->Target->IsImported();
  669. }
  670. bool cmGeneratorTarget::IsImportedGloballyVisible() const
  671. {
  672. return this->Target->IsImportedGloballyVisible();
  673. }
  674. const char* cmGeneratorTarget::GetLocationForBuild() const
  675. {
  676. static std::string location;
  677. if (this->IsImported()) {
  678. location = this->Target->ImportedGetFullPath(
  679. "", cmStateEnums::RuntimeBinaryArtifact);
  680. return location.c_str();
  681. }
  682. // Now handle the deprecated build-time configuration location.
  683. location = this->GetDirectory();
  684. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  685. if (cfgid && strcmp(cfgid, ".") != 0) {
  686. location += "/";
  687. location += cfgid;
  688. }
  689. if (this->IsAppBundleOnApple()) {
  690. std::string macdir = this->BuildBundleDirectory("", "", FullLevel);
  691. if (!macdir.empty()) {
  692. location += "/";
  693. location += macdir;
  694. }
  695. }
  696. location += "/";
  697. location += this->GetFullName("", cmStateEnums::RuntimeBinaryArtifact);
  698. return location.c_str();
  699. }
  700. bool cmGeneratorTarget::IsSystemIncludeDirectory(
  701. const std::string& dir, const std::string& config,
  702. const std::string& language) const
  703. {
  704. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  705. std::string config_upper;
  706. if (!config.empty()) {
  707. config_upper = cmSystemTools::UpperCase(config);
  708. }
  709. typedef std::map<std::string, std::vector<std::string>> IncludeCacheType;
  710. IncludeCacheType::const_iterator iter =
  711. this->SystemIncludesCache.find(config_upper);
  712. if (iter == this->SystemIncludesCache.end()) {
  713. cmGeneratorExpressionDAGChecker dagChecker(
  714. this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr);
  715. bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  716. std::vector<std::string> result;
  717. for (std::string const& it : this->Target->GetSystemIncludeDirectories()) {
  718. cmGeneratorExpression ge;
  719. cmSystemTools::ExpandListArgument(
  720. ge.Parse(it)->Evaluate(this->LocalGenerator, config, false, this,
  721. &dagChecker, language),
  722. result);
  723. }
  724. std::vector<cmGeneratorTarget const*> const& deps =
  725. this->GetLinkImplementationClosure(config);
  726. for (cmGeneratorTarget const* dep : deps) {
  727. handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
  728. &dagChecker, result, excludeImported, language);
  729. }
  730. std::for_each(result.begin(), result.end(),
  731. cmSystemTools::ConvertToUnixSlashes);
  732. std::sort(result.begin(), result.end());
  733. result.erase(std::unique(result.begin(), result.end()), result.end());
  734. IncludeCacheType::value_type entry(config_upper, result);
  735. iter = this->SystemIncludesCache.insert(entry).first;
  736. }
  737. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  738. }
  739. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  740. {
  741. return this->Target->GetPropertyAsBool(prop);
  742. }
  743. static void AddInterfaceEntries(
  744. cmGeneratorTarget const* thisTarget, std::string const& config,
  745. std::string const& prop,
  746. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
  747. {
  748. if (cmLinkImplementationLibraries const* impl =
  749. thisTarget->GetLinkImplementationLibraries(config)) {
  750. for (cmLinkImplItem const& lib : impl->Libraries) {
  751. if (lib.Target) {
  752. std::string uniqueName =
  753. thisTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
  754. lib.Target);
  755. std::string genex =
  756. "$<TARGET_PROPERTY:" + std::move(uniqueName) + "," + prop + ">";
  757. cmGeneratorExpression ge(lib.Backtrace);
  758. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  759. cge->SetEvaluateForBuildsystem(true);
  760. entries.push_back(
  761. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge), lib));
  762. }
  763. }
  764. }
  765. }
  766. static void AddObjectEntries(
  767. cmGeneratorTarget const* thisTarget, std::string const& config,
  768. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
  769. {
  770. if (cmLinkImplementationLibraries const* impl =
  771. thisTarget->GetLinkImplementationLibraries(config)) {
  772. for (cmLinkImplItem const& lib : impl->Libraries) {
  773. if (lib.Target &&
  774. lib.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  775. std::string uniqueName =
  776. thisTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
  777. lib.Target);
  778. std::string genex = "$<TARGET_OBJECTS:" + std::move(uniqueName) + ">";
  779. cmGeneratorExpression ge(lib.Backtrace);
  780. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  781. cge->SetEvaluateForBuildsystem(true);
  782. entries.push_back(
  783. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge), lib));
  784. }
  785. }
  786. }
  787. }
  788. static bool processSources(
  789. cmGeneratorTarget const* tgt,
  790. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  791. std::vector<BT<std::string>>& srcs,
  792. std::unordered_set<std::string>& uniqueSrcs,
  793. cmGeneratorExpressionDAGChecker* dagChecker, std::string const& config,
  794. bool debugSources)
  795. {
  796. cmMakefile* mf = tgt->Target->GetMakefile();
  797. bool contextDependent = false;
  798. for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
  799. cmLinkImplItem const& item = entry->LinkImplItem;
  800. std::string const& targetName = item.AsStr();
  801. std::vector<std::string> entrySources;
  802. cmSystemTools::ExpandListArgument(
  803. entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, tgt,
  804. dagChecker),
  805. entrySources);
  806. if (entry->ge->GetHadContextSensitiveCondition()) {
  807. contextDependent = true;
  808. }
  809. for (std::string& src : entrySources) {
  810. cmSourceFile* sf = mf->GetOrCreateSource(src);
  811. std::string e;
  812. std::string fullPath = sf->GetFullPath(&e);
  813. if (fullPath.empty()) {
  814. if (!e.empty()) {
  815. cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
  816. cm->IssueMessage(MessageType::FATAL_ERROR, e, tgt->GetBacktrace());
  817. }
  818. return contextDependent;
  819. }
  820. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src)) {
  821. std::ostringstream err;
  822. if (!targetName.empty()) {
  823. err << "Target \"" << targetName
  824. << "\" contains relative path in its INTERFACE_SOURCES:\n \""
  825. << src << "\"";
  826. } else {
  827. err << "Found relative path while evaluating sources of \""
  828. << tgt->GetName() << "\":\n \"" << src << "\"\n";
  829. }
  830. tgt->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
  831. err.str());
  832. return contextDependent;
  833. }
  834. src = fullPath;
  835. }
  836. std::string usedSources;
  837. for (std::string const& src : entrySources) {
  838. if (uniqueSrcs.insert(src).second) {
  839. srcs.emplace_back(src, entry->ge->GetBacktrace());
  840. if (debugSources) {
  841. usedSources += " * " + src + "\n";
  842. }
  843. }
  844. }
  845. if (!usedSources.empty()) {
  846. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  847. MessageType::LOG,
  848. std::string("Used sources for target ") + tgt->GetName() + ":\n" +
  849. usedSources,
  850. entry->ge->GetBacktrace());
  851. }
  852. }
  853. return contextDependent;
  854. }
  855. std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
  856. std::string const& config) const
  857. {
  858. std::vector<BT<std::string>> files;
  859. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  860. if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  861. // At configure-time, this method can be called as part of getting the
  862. // LOCATION property or to export() a file to be include()d. However
  863. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  864. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  865. // behavior of CMP0024 and CMP0026 only.
  866. cmStringRange sourceEntries = this->Target->GetSourceEntries();
  867. for (std::string const& entry : sourceEntries) {
  868. std::vector<std::string> items;
  869. cmSystemTools::ExpandListArgument(entry, items);
  870. for (std::string const& item : items) {
  871. if (cmHasLiteralPrefix(item, "$<TARGET_OBJECTS:") &&
  872. item.back() == '>') {
  873. continue;
  874. }
  875. files.push_back(item);
  876. }
  877. }
  878. return files;
  879. }
  880. std::vector<std::string> debugProperties;
  881. const char* debugProp =
  882. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  883. if (debugProp) {
  884. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  885. }
  886. bool debugSources = !this->DebugSourcesDone &&
  887. std::find(debugProperties.begin(), debugProperties.end(), "SOURCES") !=
  888. debugProperties.end();
  889. if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  890. this->DebugSourcesDone = true;
  891. }
  892. cmGeneratorExpressionDAGChecker dagChecker(this, "SOURCES", nullptr,
  893. nullptr);
  894. std::unordered_set<std::string> uniqueSrcs;
  895. bool contextDependentDirectSources =
  896. processSources(this, this->SourceEntries, files, uniqueSrcs, &dagChecker,
  897. config, debugSources);
  898. // Collect INTERFACE_SOURCES of all direct link-dependencies.
  899. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  900. linkInterfaceSourcesEntries;
  901. AddInterfaceEntries(this, config, "INTERFACE_SOURCES",
  902. linkInterfaceSourcesEntries);
  903. std::vector<std::string>::size_type numFilesBefore = files.size();
  904. bool contextDependentInterfaceSources =
  905. processSources(this, linkInterfaceSourcesEntries, files, uniqueSrcs,
  906. &dagChecker, config, debugSources);
  907. // Collect TARGET_OBJECTS of direct object link-dependencies.
  908. std::vector<cmGeneratorTarget::TargetPropertyEntry*> linkObjectsEntries;
  909. AddObjectEntries(this, config, linkObjectsEntries);
  910. std::vector<std::string>::size_type numFilesBefore2 = files.size();
  911. bool contextDependentObjects =
  912. processSources(this, linkObjectsEntries, files, uniqueSrcs, &dagChecker,
  913. config, debugSources);
  914. if (!contextDependentDirectSources &&
  915. !(contextDependentInterfaceSources && numFilesBefore < files.size()) &&
  916. !(contextDependentObjects && numFilesBefore2 < files.size())) {
  917. this->LinkImplementationLanguageIsContextDependent = false;
  918. }
  919. cmDeleteAll(linkInterfaceSourcesEntries);
  920. cmDeleteAll(linkObjectsEntries);
  921. return files;
  922. }
  923. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*>& files,
  924. const std::string& config) const
  925. {
  926. std::vector<BT<cmSourceFile*>> tmp = this->GetSourceFiles(config);
  927. files.reserve(tmp.size());
  928. for (BT<cmSourceFile*>& v : tmp) {
  929. files.push_back(v.Value);
  930. }
  931. }
  932. std::vector<BT<cmSourceFile*>> cmGeneratorTarget::GetSourceFiles(
  933. std::string const& config) const
  934. {
  935. std::vector<BT<cmSourceFile*>> files;
  936. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  937. // Since we are still configuring not all sources may exist yet,
  938. // so we need to avoid full source classification because that
  939. // requires the absolute paths to all sources to be determined.
  940. // Since this is only for compatibility with old policies that
  941. // projects should not depend on anymore, just compute the files
  942. // without memoizing them.
  943. std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
  944. std::set<cmSourceFile*> emitted;
  945. for (BT<std::string> const& s : srcs) {
  946. cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
  947. if (emitted.insert(sf).second) {
  948. files.emplace_back(sf, s.Backtrace);
  949. }
  950. }
  951. return files;
  952. }
  953. KindedSources const& kinded = this->GetKindedSources(config);
  954. files.reserve(kinded.Sources.size());
  955. for (SourceAndKind const& si : kinded.Sources) {
  956. files.push_back(si.Source);
  957. }
  958. return files;
  959. }
  960. void cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  961. std::vector<cmSourceFile*>& files, const std::string& config) const
  962. {
  963. std::vector<BT<cmSourceFile*>> tmp =
  964. this->GetSourceFilesWithoutObjectLibraries(config);
  965. files.reserve(tmp.size());
  966. for (BT<cmSourceFile*>& v : tmp) {
  967. files.push_back(v.Value);
  968. }
  969. }
  970. std::vector<BT<cmSourceFile*>>
  971. cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  972. std::string const& config) const
  973. {
  974. std::vector<BT<cmSourceFile*>> files;
  975. KindedSources const& kinded = this->GetKindedSources(config);
  976. files.reserve(kinded.Sources.size());
  977. for (SourceAndKind const& si : kinded.Sources) {
  978. if (si.Source.Value->GetObjectLibrary().empty()) {
  979. files.push_back(si.Source);
  980. }
  981. }
  982. return files;
  983. }
  984. cmGeneratorTarget::KindedSources const& cmGeneratorTarget::GetKindedSources(
  985. std::string const& config) const
  986. {
  987. // If we already processed one configuration and found no dependenc
  988. // on configuration then always use the one result.
  989. if (!this->LinkImplementationLanguageIsContextDependent) {
  990. return this->KindedSourcesMap.begin()->second;
  991. }
  992. // Lookup any existing link implementation for this configuration.
  993. std::string const key = cmSystemTools::UpperCase(config);
  994. KindedSourcesMapType::iterator it = this->KindedSourcesMap.find(key);
  995. if (it != this->KindedSourcesMap.end()) {
  996. if (!it->second.Initialized) {
  997. std::ostringstream e;
  998. e << "The SOURCES of \"" << this->GetName()
  999. << "\" use a generator expression that depends on the "
  1000. "SOURCES themselves.";
  1001. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  1002. MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
  1003. static KindedSources empty;
  1004. return empty;
  1005. }
  1006. return it->second;
  1007. }
  1008. // Add an entry to the map for this configuration.
  1009. KindedSources& files = this->KindedSourcesMap[key];
  1010. this->ComputeKindedSources(files, config);
  1011. files.Initialized = true;
  1012. return files;
  1013. }
  1014. void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
  1015. std::string const& config) const
  1016. {
  1017. // Get the source file paths by string.
  1018. std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
  1019. cmsys::RegularExpression header_regex(CM_HEADER_REGEX);
  1020. std::vector<cmSourceFile*> badObjLib;
  1021. std::set<cmSourceFile*> emitted;
  1022. for (BT<std::string> const& s : srcs) {
  1023. // Create each source at most once.
  1024. cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
  1025. if (!emitted.insert(sf).second) {
  1026. continue;
  1027. }
  1028. // Compute the kind (classification) of this source file.
  1029. SourceKind kind;
  1030. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1031. if (sf->GetCustomCommand()) {
  1032. kind = SourceKindCustomCommand;
  1033. } else if (this->Target->GetType() == cmStateEnums::UTILITY) {
  1034. kind = SourceKindExtra;
  1035. } else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) {
  1036. kind = SourceKindHeader;
  1037. } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  1038. kind = SourceKindExternalObject;
  1039. } else if (!sf->GetLanguage().empty()) {
  1040. kind = SourceKindObjectSource;
  1041. } else if (ext == "def") {
  1042. kind = SourceKindModuleDefinition;
  1043. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1044. badObjLib.push_back(sf);
  1045. }
  1046. } else if (ext == "idl") {
  1047. kind = SourceKindIDL;
  1048. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1049. badObjLib.push_back(sf);
  1050. }
  1051. } else if (ext == "resx") {
  1052. kind = SourceKindResx;
  1053. // Build and save the name of the corresponding .h file
  1054. // This relationship will be used later when building the project files.
  1055. // Both names would have been auto generated from Visual Studio
  1056. // where the user supplied the file name and Visual Studio
  1057. // appended the suffix.
  1058. std::string resx = sf->GetFullPath();
  1059. std::string hFileName = resx.substr(0, resx.find_last_of('.')) + ".h";
  1060. files.ExpectedResxHeaders.insert(hFileName);
  1061. } else if (ext == "appxmanifest") {
  1062. kind = SourceKindAppManifest;
  1063. } else if (ext == "manifest") {
  1064. kind = SourceKindManifest;
  1065. } else if (ext == "pfx") {
  1066. kind = SourceKindCertificate;
  1067. } else if (ext == "xaml") {
  1068. kind = SourceKindXaml;
  1069. // Build and save the name of the corresponding .h and .cpp file
  1070. // This relationship will be used later when building the project files.
  1071. // Both names would have been auto generated from Visual Studio
  1072. // where the user supplied the file name and Visual Studio
  1073. // appended the suffix.
  1074. std::string xaml = sf->GetFullPath();
  1075. std::string hFileName = xaml + ".h";
  1076. std::string cppFileName = xaml + ".cpp";
  1077. files.ExpectedXamlHeaders.insert(hFileName);
  1078. files.ExpectedXamlSources.insert(cppFileName);
  1079. } else if (header_regex.find(sf->GetFullPath())) {
  1080. kind = SourceKindHeader;
  1081. } else {
  1082. kind = SourceKindExtra;
  1083. }
  1084. // Save this classified source file in the result vector.
  1085. files.Sources.push_back({ BT<cmSourceFile*>(sf, s.Backtrace), kind });
  1086. }
  1087. if (!badObjLib.empty()) {
  1088. std::ostringstream e;
  1089. e << "OBJECT library \"" << this->GetName() << "\" contains:\n";
  1090. for (cmSourceFile* i : badObjLib) {
  1091. e << " " << i->GetLocation().GetName() << "\n";
  1092. }
  1093. e << "but may contain only sources that compile, header files, and "
  1094. "other files that would not affect linking of a normal library.";
  1095. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  1096. MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
  1097. }
  1098. }
  1099. std::vector<cmGeneratorTarget::AllConfigSource> const&
  1100. cmGeneratorTarget::GetAllConfigSources() const
  1101. {
  1102. if (this->AllConfigSources.empty()) {
  1103. this->ComputeAllConfigSources();
  1104. }
  1105. return this->AllConfigSources;
  1106. }
  1107. void cmGeneratorTarget::ComputeAllConfigSources() const
  1108. {
  1109. std::vector<std::string> configs;
  1110. this->Makefile->GetConfigurations(configs);
  1111. std::map<cmSourceFile const*, size_t> index;
  1112. for (size_t ci = 0; ci < configs.size(); ++ci) {
  1113. KindedSources const& sources = this->GetKindedSources(configs[ci]);
  1114. for (SourceAndKind const& src : sources.Sources) {
  1115. std::map<cmSourceFile const*, size_t>::iterator mi =
  1116. index.find(src.Source.Value);
  1117. if (mi == index.end()) {
  1118. AllConfigSource acs;
  1119. acs.Source = src.Source.Value;
  1120. acs.Kind = src.Kind;
  1121. this->AllConfigSources.push_back(std::move(acs));
  1122. std::map<cmSourceFile const*, size_t>::value_type entry(
  1123. src.Source.Value, this->AllConfigSources.size() - 1);
  1124. mi = index.insert(entry).first;
  1125. }
  1126. this->AllConfigSources[mi->second].Configs.push_back(ci);
  1127. }
  1128. }
  1129. }
  1130. std::string cmGeneratorTarget::GetCompilePDBName(
  1131. const std::string& config) const
  1132. {
  1133. std::string prefix;
  1134. std::string base;
  1135. std::string suffix;
  1136. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  1137. prefix, base, suffix);
  1138. // Check for a per-configuration output directory target property.
  1139. std::string configUpper = cmSystemTools::UpperCase(config);
  1140. std::string configProp = "COMPILE_PDB_NAME_";
  1141. configProp += configUpper;
  1142. const char* config_name = this->GetProperty(configProp);
  1143. if (config_name && *config_name) {
  1144. return prefix + config_name + ".pdb";
  1145. }
  1146. const char* name = this->GetProperty("COMPILE_PDB_NAME");
  1147. if (name && *name) {
  1148. return prefix + name + ".pdb";
  1149. }
  1150. return "";
  1151. }
  1152. std::string cmGeneratorTarget::GetCompilePDBPath(
  1153. const std::string& config) const
  1154. {
  1155. std::string dir = this->GetCompilePDBDirectory(config);
  1156. std::string name = this->GetCompilePDBName(config);
  1157. if (dir.empty() && !name.empty() && this->HaveWellDefinedOutputFiles()) {
  1158. dir = this->GetPDBDirectory(config);
  1159. }
  1160. if (!dir.empty()) {
  1161. dir += "/";
  1162. }
  1163. return dir + name;
  1164. }
  1165. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  1166. {
  1167. // soname is supported only for shared libraries and modules,
  1168. // and then only when the platform supports an soname flag.
  1169. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY) &&
  1170. !this->GetPropertyAsBool("NO_SONAME") &&
  1171. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  1172. }
  1173. bool cmGeneratorTarget::NeedRelinkBeforeInstall(
  1174. const std::string& config) const
  1175. {
  1176. // Only executables and shared libraries can have an rpath and may
  1177. // need relinking.
  1178. if (this->GetType() != cmStateEnums::EXECUTABLE &&
  1179. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1180. this->GetType() != cmStateEnums::MODULE_LIBRARY) {
  1181. return false;
  1182. }
  1183. // If there is no install location this target will not be installed
  1184. // and therefore does not need relinking.
  1185. if (!this->Target->GetHaveInstallRule()) {
  1186. return false;
  1187. }
  1188. // If skipping all rpaths completely then no relinking is needed.
  1189. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1190. return false;
  1191. }
  1192. // If building with the install-tree rpath no relinking is needed.
  1193. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1194. return false;
  1195. }
  1196. // If chrpath is going to be used no relinking is needed.
  1197. if (this->IsChrpathUsed(config)) {
  1198. return false;
  1199. }
  1200. // Check for rpath support on this platform.
  1201. std::string ll = this->GetLinkerLanguage(config);
  1202. if (!ll.empty()) {
  1203. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1204. flagVar += ll;
  1205. flagVar += "_FLAG";
  1206. if (!this->Makefile->IsSet(flagVar)) {
  1207. // There is no rpath support on this platform so nothing needs
  1208. // relinking.
  1209. return false;
  1210. }
  1211. } else {
  1212. // No linker language is known. This error will be reported by
  1213. // other code.
  1214. return false;
  1215. }
  1216. // If either a build or install tree rpath is set then the rpath
  1217. // will likely change between the build tree and install tree and
  1218. // this target must be relinked.
  1219. bool have_rpath =
  1220. this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
  1221. bool is_ninja =
  1222. this->LocalGenerator->GetGlobalGenerator()->GetName() == "Ninja";
  1223. if (have_rpath && is_ninja) {
  1224. std::ostringstream w;
  1225. /* clang-format off */
  1226. w <<
  1227. "The install of the " << this->GetName() << " target requires "
  1228. "changing an RPATH from the build tree, but this is not supported "
  1229. "with the Ninja generator unless on an ELF-based platform. The "
  1230. "CMAKE_BUILD_WITH_INSTALL_RPATH variable may be set to avoid this "
  1231. "relinking step."
  1232. ;
  1233. /* clang-format on */
  1234. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1235. cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
  1236. }
  1237. return have_rpath;
  1238. }
  1239. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  1240. {
  1241. // Only certain target types have an rpath.
  1242. if (!(this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1243. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1244. this->GetType() == cmStateEnums::EXECUTABLE)) {
  1245. return false;
  1246. }
  1247. // If the target will not be installed we do not need to change its
  1248. // rpath.
  1249. if (!this->Target->GetHaveInstallRule()) {
  1250. return false;
  1251. }
  1252. // Skip chrpath if skipping rpath altogether.
  1253. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1254. return false;
  1255. }
  1256. // Skip chrpath if it does not need to be changed at install time.
  1257. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1258. return false;
  1259. }
  1260. // Allow the user to disable builtin chrpath explicitly.
  1261. if (this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH")) {
  1262. return false;
  1263. }
  1264. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1265. return true;
  1266. }
  1267. #if defined(CMAKE_USE_ELF_PARSER)
  1268. // Enable if the rpath flag uses a separator and the target uses ELF
  1269. // binaries.
  1270. std::string ll = this->GetLinkerLanguage(config);
  1271. if (!ll.empty()) {
  1272. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1273. sepVar += ll;
  1274. sepVar += "_FLAG_SEP";
  1275. const char* sep = this->Makefile->GetDefinition(sepVar);
  1276. if (sep && *sep) {
  1277. // TODO: Add ELF check to ABI detection and get rid of
  1278. // CMAKE_EXECUTABLE_FORMAT.
  1279. if (const char* fmt =
  1280. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT")) {
  1281. return strcmp(fmt, "ELF") == 0;
  1282. }
  1283. }
  1284. }
  1285. #endif
  1286. static_cast<void>(config);
  1287. return false;
  1288. }
  1289. bool cmGeneratorTarget::IsImportedSharedLibWithoutSOName(
  1290. const std::string& config) const
  1291. {
  1292. if (this->IsImported() && this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  1293. if (cmGeneratorTarget::ImportInfo const* info =
  1294. this->GetImportInfo(config)) {
  1295. return info->NoSOName;
  1296. }
  1297. }
  1298. return false;
  1299. }
  1300. bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
  1301. const std::string& config) const
  1302. {
  1303. bool install_name_is_rpath = false;
  1304. bool macosx_rpath = false;
  1305. if (!this->IsImported()) {
  1306. if (this->GetType() != cmStateEnums::SHARED_LIBRARY) {
  1307. return false;
  1308. }
  1309. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  1310. bool use_install_name = this->MacOSXUseInstallNameDir();
  1311. if (install_name && use_install_name &&
  1312. std::string(install_name) == "@rpath") {
  1313. install_name_is_rpath = true;
  1314. } else if (install_name && use_install_name) {
  1315. return false;
  1316. }
  1317. if (!install_name_is_rpath) {
  1318. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  1319. }
  1320. } else {
  1321. // Lookup the imported soname.
  1322. if (cmGeneratorTarget::ImportInfo const* info =
  1323. this->GetImportInfo(config)) {
  1324. if (!info->NoSOName && !info->SOName.empty()) {
  1325. if (info->SOName.find("@rpath/") == 0) {
  1326. install_name_is_rpath = true;
  1327. }
  1328. } else {
  1329. std::string install_name;
  1330. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  1331. if (install_name.find("@rpath") != std::string::npos) {
  1332. install_name_is_rpath = true;
  1333. }
  1334. }
  1335. }
  1336. }
  1337. if (!install_name_is_rpath && !macosx_rpath) {
  1338. return false;
  1339. }
  1340. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  1341. std::ostringstream w;
  1342. w << "Attempting to use ";
  1343. if (macosx_rpath) {
  1344. w << "MACOSX_RPATH";
  1345. } else {
  1346. w << "@rpath";
  1347. }
  1348. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  1349. w << " This could be because you are using a Mac OS X version";
  1350. w << " less than 10.5 or because CMake's platform configuration is";
  1351. w << " corrupt.";
  1352. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1353. cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
  1354. }
  1355. return true;
  1356. }
  1357. bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const
  1358. {
  1359. // we can't do rpaths when unsupported
  1360. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  1361. return false;
  1362. }
  1363. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  1364. if (macosx_rpath_str) {
  1365. return this->GetPropertyAsBool("MACOSX_RPATH");
  1366. }
  1367. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  1368. if (cmp0042 == cmPolicies::WARN) {
  1369. this->LocalGenerator->GetGlobalGenerator()->AddCMP0042WarnTarget(
  1370. this->GetName());
  1371. }
  1372. return cmp0042 == cmPolicies::NEW;
  1373. }
  1374. bool cmGeneratorTarget::MacOSXUseInstallNameDir() const
  1375. {
  1376. const char* build_with_install_name =
  1377. this->GetProperty("BUILD_WITH_INSTALL_NAME_DIR");
  1378. if (build_with_install_name) {
  1379. return cmSystemTools::IsOn(build_with_install_name);
  1380. }
  1381. cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068();
  1382. if (cmp0068 == cmPolicies::NEW) {
  1383. return false;
  1384. }
  1385. bool use_install_name = this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  1386. if (use_install_name && cmp0068 == cmPolicies::WARN) {
  1387. this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget(
  1388. this->GetName());
  1389. }
  1390. return use_install_name;
  1391. }
  1392. bool cmGeneratorTarget::CanGenerateInstallNameDir(
  1393. InstallNameType name_type) const
  1394. {
  1395. cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068();
  1396. if (cmp0068 == cmPolicies::NEW) {
  1397. return true;
  1398. }
  1399. bool skip = this->Makefile->IsOn("CMAKE_SKIP_RPATH");
  1400. if (name_type == INSTALL_NAME_FOR_INSTALL) {
  1401. skip |= this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  1402. } else {
  1403. skip |= this->GetPropertyAsBool("SKIP_BUILD_RPATH");
  1404. }
  1405. if (skip && cmp0068 == cmPolicies::WARN) {
  1406. this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget(
  1407. this->GetName());
  1408. }
  1409. return !skip;
  1410. }
  1411. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  1412. {
  1413. if (this->IsImported()) {
  1414. // Lookup the imported soname.
  1415. if (cmGeneratorTarget::ImportInfo const* info =
  1416. this->GetImportInfo(config)) {
  1417. if (info->NoSOName) {
  1418. // The imported library has no builtin soname so the name
  1419. // searched at runtime will be just the filename.
  1420. return cmSystemTools::GetFilenameName(info->Location);
  1421. }
  1422. // Use the soname given if any.
  1423. if (info->SOName.find("@rpath/") == 0) {
  1424. return info->SOName.substr(6);
  1425. }
  1426. return info->SOName;
  1427. }
  1428. return "";
  1429. }
  1430. // Compute the soname that will be built.
  1431. std::string name;
  1432. std::string soName;
  1433. std::string realName;
  1434. std::string impName;
  1435. std::string pdbName;
  1436. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  1437. return soName;
  1438. }
  1439. static bool shouldAddFullLevel(cmGeneratorTarget::BundleDirectoryLevel level)
  1440. {
  1441. return level == cmGeneratorTarget::FullLevel;
  1442. }
  1443. static bool shouldAddContentLevel(
  1444. cmGeneratorTarget::BundleDirectoryLevel level)
  1445. {
  1446. return level == cmGeneratorTarget::ContentLevel || shouldAddFullLevel(level);
  1447. }
  1448. std::string cmGeneratorTarget::GetAppBundleDirectory(
  1449. const std::string& config, BundleDirectoryLevel level) const
  1450. {
  1451. std::string fpath =
  1452. this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact);
  1453. fpath += ".";
  1454. const char* ext = this->GetProperty("BUNDLE_EXTENSION");
  1455. if (!ext) {
  1456. ext = "app";
  1457. }
  1458. fpath += ext;
  1459. if (shouldAddContentLevel(level) &&
  1460. !this->Makefile->PlatformIsAppleEmbedded()) {
  1461. fpath += "/Contents";
  1462. if (shouldAddFullLevel(level)) {
  1463. fpath += "/MacOS";
  1464. }
  1465. }
  1466. return fpath;
  1467. }
  1468. bool cmGeneratorTarget::IsBundleOnApple() const
  1469. {
  1470. return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
  1471. this->IsCFBundleOnApple();
  1472. }
  1473. std::string cmGeneratorTarget::GetCFBundleDirectory(
  1474. const std::string& config, BundleDirectoryLevel level) const
  1475. {
  1476. std::string fpath;
  1477. fpath += this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact);
  1478. fpath += ".";
  1479. const char* ext = this->GetProperty("BUNDLE_EXTENSION");
  1480. if (!ext) {
  1481. if (this->IsXCTestOnApple()) {
  1482. ext = "xctest";
  1483. } else {
  1484. ext = "bundle";
  1485. }
  1486. }
  1487. fpath += ext;
  1488. if (shouldAddContentLevel(level) &&
  1489. !this->Makefile->PlatformIsAppleEmbedded()) {
  1490. fpath += "/Contents";
  1491. if (shouldAddFullLevel(level)) {
  1492. fpath += "/MacOS";
  1493. }
  1494. }
  1495. return fpath;
  1496. }
  1497. std::string cmGeneratorTarget::GetFrameworkDirectory(
  1498. const std::string& config, BundleDirectoryLevel level) const
  1499. {
  1500. std::string fpath;
  1501. fpath += this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact);
  1502. fpath += ".";
  1503. const char* ext = this->GetProperty("BUNDLE_EXTENSION");
  1504. if (!ext) {
  1505. ext = "framework";
  1506. }
  1507. fpath += ext;
  1508. if (shouldAddFullLevel(level) &&
  1509. !this->Makefile->PlatformIsAppleEmbedded()) {
  1510. fpath += "/Versions/";
  1511. fpath += this->GetFrameworkVersion();
  1512. }
  1513. return fpath;
  1514. }
  1515. std::string cmGeneratorTarget::GetFullName(
  1516. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1517. {
  1518. if (this->IsImported()) {
  1519. return this->GetFullNameImported(config, artifact);
  1520. }
  1521. return this->GetFullNameInternal(config, artifact);
  1522. }
  1523. std::string cmGeneratorTarget::GetInstallNameDirForBuildTree(
  1524. const std::string& config) const
  1525. {
  1526. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1527. // If building directly for installation then the build tree install_name
  1528. // is the same as the install tree.
  1529. if (this->MacOSXUseInstallNameDir()) {
  1530. return this->GetInstallNameDirForInstallTree();
  1531. }
  1532. // Use the build tree directory for the target.
  1533. if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_BUILD)) {
  1534. std::string dir;
  1535. if (this->MacOSXRpathInstallNameDirDefault()) {
  1536. dir = "@rpath";
  1537. } else {
  1538. dir = this->GetDirectory(config);
  1539. }
  1540. dir += "/";
  1541. return dir;
  1542. }
  1543. }
  1544. return "";
  1545. }
  1546. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
  1547. {
  1548. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1549. std::string dir;
  1550. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  1551. if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_INSTALL)) {
  1552. if (install_name_dir && *install_name_dir) {
  1553. dir = install_name_dir;
  1554. dir += "/";
  1555. }
  1556. }
  1557. if (!install_name_dir) {
  1558. if (this->MacOSXRpathInstallNameDirDefault()) {
  1559. dir = "@rpath/";
  1560. }
  1561. }
  1562. return dir;
  1563. }
  1564. return "";
  1565. }
  1566. cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const
  1567. {
  1568. return this->Target->GetBacktrace();
  1569. }
  1570. const std::set<BT<std::string>>& cmGeneratorTarget::GetUtilities() const
  1571. {
  1572. return this->Target->GetUtilities();
  1573. }
  1574. bool cmGeneratorTarget::HaveWellDefinedOutputFiles() const
  1575. {
  1576. return this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  1577. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1578. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1579. this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  1580. this->GetType() == cmStateEnums::EXECUTABLE;
  1581. }
  1582. const std::string* cmGeneratorTarget::GetExportMacro() const
  1583. {
  1584. // Define the symbol for targets that export symbols.
  1585. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1586. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1587. this->IsExecutableWithExports()) {
  1588. if (const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL")) {
  1589. this->ExportMacro = custom_export_name;
  1590. } else {
  1591. std::string in = this->GetName();
  1592. in += "_EXPORTS";
  1593. this->ExportMacro = cmSystemTools::MakeCidentifier(in);
  1594. }
  1595. return &this->ExportMacro;
  1596. }
  1597. return nullptr;
  1598. }
  1599. class cmTargetCollectLinkLanguages
  1600. {
  1601. public:
  1602. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  1603. const std::string& config,
  1604. std::unordered_set<std::string>& languages,
  1605. cmGeneratorTarget const* head)
  1606. : Config(config)
  1607. , Languages(languages)
  1608. , HeadTarget(head)
  1609. , Target(target)
  1610. {
  1611. this->Visited.insert(target);
  1612. }
  1613. void Visit(cmLinkItem const& item)
  1614. {
  1615. if (!item.Target) {
  1616. if (item.AsStr().find("::") != std::string::npos) {
  1617. bool noMessage = false;
  1618. MessageType messageType = MessageType::FATAL_ERROR;
  1619. std::ostringstream e;
  1620. switch (this->Target->GetLocalGenerator()->GetPolicyStatus(
  1621. cmPolicies::CMP0028)) {
  1622. case cmPolicies::WARN: {
  1623. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  1624. messageType = MessageType::AUTHOR_WARNING;
  1625. } break;
  1626. case cmPolicies::OLD:
  1627. noMessage = true;
  1628. case cmPolicies::REQUIRED_IF_USED:
  1629. case cmPolicies::REQUIRED_ALWAYS:
  1630. case cmPolicies::NEW:
  1631. // Issue the fatal message.
  1632. break;
  1633. }
  1634. if (!noMessage) {
  1635. e << "Target \"" << this->Target->GetName()
  1636. << "\" links to target \"" << item.AsStr()
  1637. << "\" but the target was not found. Perhaps a find_package() "
  1638. "call is missing for an IMPORTED target, or an ALIAS target is "
  1639. "missing?";
  1640. this->Target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1641. messageType, e.str(), this->Target->GetBacktrace());
  1642. }
  1643. }
  1644. return;
  1645. }
  1646. if (!this->Visited.insert(item.Target).second) {
  1647. return;
  1648. }
  1649. cmLinkInterface const* iface =
  1650. item.Target->GetLinkInterface(this->Config, this->HeadTarget);
  1651. if (!iface) {
  1652. return;
  1653. }
  1654. for (std::string const& language : iface->Languages) {
  1655. this->Languages.insert(language);
  1656. }
  1657. for (cmLinkItem const& lib : iface->Libraries) {
  1658. this->Visit(lib);
  1659. }
  1660. }
  1661. private:
  1662. std::string Config;
  1663. std::unordered_set<std::string>& Languages;
  1664. cmGeneratorTarget const* HeadTarget;
  1665. const cmGeneratorTarget* Target;
  1666. std::set<cmGeneratorTarget const*> Visited;
  1667. };
  1668. cmGeneratorTarget::LinkClosure const* cmGeneratorTarget::GetLinkClosure(
  1669. const std::string& config) const
  1670. {
  1671. std::string key(cmSystemTools::UpperCase(config));
  1672. LinkClosureMapType::iterator i = this->LinkClosureMap.find(key);
  1673. if (i == this->LinkClosureMap.end()) {
  1674. LinkClosure lc;
  1675. this->ComputeLinkClosure(config, lc);
  1676. LinkClosureMapType::value_type entry(key, lc);
  1677. i = this->LinkClosureMap.insert(entry).first;
  1678. }
  1679. return &i->second;
  1680. }
  1681. class cmTargetSelectLinker
  1682. {
  1683. int Preference;
  1684. cmGeneratorTarget const* Target;
  1685. cmGlobalGenerator* GG;
  1686. std::set<std::string> Preferred;
  1687. public:
  1688. cmTargetSelectLinker(cmGeneratorTarget const* target)
  1689. : Preference(0)
  1690. , Target(target)
  1691. {
  1692. this->GG = this->Target->GetLocalGenerator()->GetGlobalGenerator();
  1693. }
  1694. void Consider(const char* lang)
  1695. {
  1696. int preference = this->GG->GetLinkerPreference(lang);
  1697. if (preference > this->Preference) {
  1698. this->Preference = preference;
  1699. this->Preferred.clear();
  1700. }
  1701. if (preference == this->Preference) {
  1702. this->Preferred.insert(lang);
  1703. }
  1704. }
  1705. std::string Choose()
  1706. {
  1707. if (this->Preferred.empty()) {
  1708. return "";
  1709. }
  1710. if (this->Preferred.size() > 1) {
  1711. std::ostringstream e;
  1712. e << "Target " << this->Target->GetName()
  1713. << " contains multiple languages with the highest linker preference"
  1714. << " (" << this->Preference << "):\n";
  1715. for (std::string const& li : this->Preferred) {
  1716. e << " " << li << "\n";
  1717. }
  1718. e << "Set the LINKER_LANGUAGE property for this target.";
  1719. cmake* cm = this->Target->GetLocalGenerator()->GetCMakeInstance();
  1720. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  1721. this->Target->GetBacktrace());
  1722. }
  1723. return *this->Preferred.begin();
  1724. }
  1725. };
  1726. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  1727. LinkClosure& lc) const
  1728. {
  1729. // Get languages built in this target.
  1730. std::unordered_set<std::string> languages;
  1731. cmLinkImplementation const* impl = this->GetLinkImplementation(config);
  1732. assert(impl);
  1733. for (std::string const& li : impl->Languages) {
  1734. languages.insert(li);
  1735. }
  1736. // Add interface languages from linked targets.
  1737. cmTargetCollectLinkLanguages cll(this, config, languages, this);
  1738. for (cmLinkImplItem const& lib : impl->Libraries) {
  1739. cll.Visit(lib);
  1740. }
  1741. // Store the transitive closure of languages.
  1742. for (std::string const& lang : languages) {
  1743. lc.Languages.push_back(lang);
  1744. }
  1745. // Choose the language whose linker should be used.
  1746. if (this->GetProperty("HAS_CXX")) {
  1747. lc.LinkerLanguage = "CXX";
  1748. } else if (const char* linkerLang = this->GetProperty("LINKER_LANGUAGE")) {
  1749. lc.LinkerLanguage = linkerLang;
  1750. } else {
  1751. // Find the language with the highest preference value.
  1752. cmTargetSelectLinker tsl(this);
  1753. // First select from the languages compiled directly in this target.
  1754. for (std::string const& l : impl->Languages) {
  1755. tsl.Consider(l.c_str());
  1756. }
  1757. // Now consider languages that propagate from linked targets.
  1758. for (std::string const& lang : languages) {
  1759. std::string propagates =
  1760. "CMAKE_" + lang + "_LINKER_PREFERENCE_PROPAGATES";
  1761. if (this->Makefile->IsOn(propagates)) {
  1762. tsl.Consider(lang.c_str());
  1763. }
  1764. }
  1765. lc.LinkerLanguage = tsl.Choose();
  1766. }
  1767. }
  1768. void cmGeneratorTarget::GetFullNameComponents(
  1769. std::string& prefix, std::string& base, std::string& suffix,
  1770. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1771. {
  1772. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  1773. }
  1774. std::string cmGeneratorTarget::BuildBundleDirectory(
  1775. const std::string& base, const std::string& config,
  1776. BundleDirectoryLevel level) const
  1777. {
  1778. std::string fpath = base;
  1779. if (this->IsAppBundleOnApple()) {
  1780. fpath += this->GetAppBundleDirectory(config, level);
  1781. }
  1782. if (this->IsFrameworkOnApple()) {
  1783. fpath += this->GetFrameworkDirectory(config, level);
  1784. }
  1785. if (this->IsCFBundleOnApple()) {
  1786. fpath += this->GetCFBundleDirectory(config, level);
  1787. }
  1788. return fpath;
  1789. }
  1790. std::string cmGeneratorTarget::GetMacContentDirectory(
  1791. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1792. {
  1793. // Start with the output directory for the target.
  1794. std::string fpath = this->GetDirectory(config, artifact);
  1795. fpath += "/";
  1796. BundleDirectoryLevel level = ContentLevel;
  1797. if (this->IsFrameworkOnApple()) {
  1798. // additional files with a framework go into the version specific
  1799. // directory
  1800. level = FullLevel;
  1801. }
  1802. fpath = this->BuildBundleDirectory(fpath, config, level);
  1803. return fpath;
  1804. }
  1805. std::string cmGeneratorTarget::GetEffectiveFolderName() const
  1806. {
  1807. std::string effectiveFolder;
  1808. if (!this->GlobalGenerator->UseFolderProperty()) {
  1809. return effectiveFolder;
  1810. }
  1811. const char* targetFolder = this->GetProperty("FOLDER");
  1812. if (targetFolder) {
  1813. effectiveFolder += targetFolder;
  1814. }
  1815. return effectiveFolder;
  1816. }
  1817. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  1818. const std::string& config) const
  1819. {
  1820. // There is no compile information for imported targets.
  1821. if (this->IsImported()) {
  1822. return nullptr;
  1823. }
  1824. if (this->GetType() > cmStateEnums::OBJECT_LIBRARY) {
  1825. std::string msg = "cmTarget::GetCompileInfo called for ";
  1826. msg += this->GetName();
  1827. msg += " which has type ";
  1828. msg += cmState::GetTargetTypeName(this->GetType());
  1829. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  1830. return nullptr;
  1831. }
  1832. // Lookup/compute/cache the compile information for this configuration.
  1833. std::string config_upper;
  1834. if (!config.empty()) {
  1835. config_upper = cmSystemTools::UpperCase(config);
  1836. }
  1837. CompileInfoMapType::const_iterator i =
  1838. this->CompileInfoMap.find(config_upper);
  1839. if (i == this->CompileInfoMap.end()) {
  1840. CompileInfo info;
  1841. this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  1842. CompileInfoMapType::value_type entry(config_upper, info);
  1843. i = this->CompileInfoMap.insert(entry).first;
  1844. }
  1845. return &i->second;
  1846. }
  1847. cmGeneratorTarget::ModuleDefinitionInfo const*
  1848. cmGeneratorTarget::GetModuleDefinitionInfo(std::string const& config) const
  1849. {
  1850. // A module definition file only makes sense on certain target types.
  1851. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1852. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  1853. !this->IsExecutableWithExports()) {
  1854. return nullptr;
  1855. }
  1856. // Lookup/compute/cache the compile information for this configuration.
  1857. std::string config_upper;
  1858. if (!config.empty()) {
  1859. config_upper = cmSystemTools::UpperCase(config);
  1860. }
  1861. ModuleDefinitionInfoMapType::const_iterator i =
  1862. this->ModuleDefinitionInfoMap.find(config_upper);
  1863. if (i == this->ModuleDefinitionInfoMap.end()) {
  1864. ModuleDefinitionInfo info;
  1865. this->ComputeModuleDefinitionInfo(config, info);
  1866. ModuleDefinitionInfoMapType::value_type entry(config_upper, info);
  1867. i = this->ModuleDefinitionInfoMap.insert(entry).first;
  1868. }
  1869. return &i->second;
  1870. }
  1871. void cmGeneratorTarget::ComputeModuleDefinitionInfo(
  1872. std::string const& config, ModuleDefinitionInfo& info) const
  1873. {
  1874. this->GetModuleDefinitionSources(info.Sources, config);
  1875. info.WindowsExportAllSymbols =
  1876. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") &&
  1877. this->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS");
  1878. #if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
  1879. info.DefFileGenerated =
  1880. info.WindowsExportAllSymbols || info.Sources.size() > 1;
  1881. #else
  1882. // Our __create_def helper is only available on Windows.
  1883. info.DefFileGenerated = false;
  1884. #endif
  1885. if (info.DefFileGenerated) {
  1886. info.DefFile = this->ObjectDirectory /* has slash */ + "exports.def";
  1887. } else if (!info.Sources.empty()) {
  1888. info.DefFile = info.Sources.front()->GetFullPath();
  1889. }
  1890. }
  1891. bool cmGeneratorTarget::IsDLLPlatform() const
  1892. {
  1893. return this->DLLPlatform;
  1894. }
  1895. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result,
  1896. const std::string& config) const
  1897. {
  1898. const char* prop =
  1899. this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS", config);
  1900. if (!prop) {
  1901. return;
  1902. }
  1903. cmGeneratorExpression ge;
  1904. cmGeneratorExpressionDAGChecker dagChecker(this, "AUTOUIC_OPTIONS", nullptr,
  1905. nullptr);
  1906. cmSystemTools::ExpandListArgument(
  1907. ge.Parse(prop)->Evaluate(this->LocalGenerator, config, false, this,
  1908. &dagChecker),
  1909. result);
  1910. }
  1911. void processILibs(const std::string& config,
  1912. cmGeneratorTarget const* headTarget, cmLinkItem const& item,
  1913. cmGlobalGenerator* gg,
  1914. std::vector<cmGeneratorTarget const*>& tgts,
  1915. std::set<cmGeneratorTarget const*>& emitted)
  1916. {
  1917. if (item.Target && emitted.insert(item.Target).second) {
  1918. tgts.push_back(item.Target);
  1919. if (cmLinkInterfaceLibraries const* iface =
  1920. item.Target->GetLinkInterfaceLibraries(config, headTarget, true)) {
  1921. for (cmLinkItem const& lib : iface->Libraries) {
  1922. processILibs(config, headTarget, lib, gg, tgts, emitted);
  1923. }
  1924. }
  1925. }
  1926. }
  1927. const std::vector<const cmGeneratorTarget*>&
  1928. cmGeneratorTarget::GetLinkImplementationClosure(
  1929. const std::string& config) const
  1930. {
  1931. LinkImplClosure& tgts = this->LinkImplClosureMap[config];
  1932. if (!tgts.Done) {
  1933. tgts.Done = true;
  1934. std::set<cmGeneratorTarget const*> emitted;
  1935. cmLinkImplementationLibraries const* impl =
  1936. this->GetLinkImplementationLibraries(config);
  1937. for (cmLinkImplItem const& lib : impl->Libraries) {
  1938. processILibs(config, this, lib,
  1939. this->LocalGenerator->GetGlobalGenerator(), tgts, emitted);
  1940. }
  1941. }
  1942. return tgts;
  1943. }
  1944. class cmTargetTraceDependencies
  1945. {
  1946. public:
  1947. cmTargetTraceDependencies(cmGeneratorTarget* target);
  1948. void Trace();
  1949. private:
  1950. cmGeneratorTarget* GeneratorTarget;
  1951. cmMakefile* Makefile;
  1952. cmLocalGenerator* LocalGenerator;
  1953. cmGlobalGenerator const* GlobalGenerator;
  1954. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  1955. SourceEntry* CurrentEntry;
  1956. std::queue<cmSourceFile*> SourceQueue;
  1957. std::set<cmSourceFile*> SourcesQueued;
  1958. typedef std::map<std::string, cmSourceFile*> NameMapType;
  1959. NameMapType NameMap;
  1960. std::vector<std::string> NewSources;
  1961. void QueueSource(cmSourceFile* sf);
  1962. void FollowName(std::string const& name);
  1963. void FollowNames(std::vector<std::string> const& names);
  1964. bool IsUtility(std::string const& dep);
  1965. void CheckCustomCommand(cmCustomCommand const& cc);
  1966. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1967. void FollowCommandDepends(cmCustomCommand const& cc,
  1968. const std::string& config,
  1969. std::set<std::string>& emitted);
  1970. };
  1971. cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target)
  1972. : GeneratorTarget(target)
  1973. {
  1974. // Convenience.
  1975. this->Makefile = target->Target->GetMakefile();
  1976. this->LocalGenerator = target->GetLocalGenerator();
  1977. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  1978. this->CurrentEntry = nullptr;
  1979. // Queue all the source files already specified for the target.
  1980. if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1981. std::vector<std::string> configs;
  1982. this->Makefile->GetConfigurations(configs);
  1983. if (configs.empty()) {
  1984. configs.emplace_back();
  1985. }
  1986. std::set<cmSourceFile*> emitted;
  1987. for (std::string const& c : configs) {
  1988. std::vector<cmSourceFile*> sources;
  1989. this->GeneratorTarget->GetSourceFiles(sources, c);
  1990. for (cmSourceFile* sf : sources) {
  1991. const std::set<cmGeneratorTarget const*> tgts =
  1992. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  1993. if (tgts.find(this->GeneratorTarget) != tgts.end()) {
  1994. std::ostringstream e;
  1995. e << "Evaluation output file\n \"" << sf->GetFullPath()
  1996. << "\"\ndepends on the sources of a target it is used in. This "
  1997. "is a dependency loop and is not allowed.";
  1998. this->GeneratorTarget->LocalGenerator->IssueMessage(
  1999. MessageType::FATAL_ERROR, e.str());
  2000. return;
  2001. }
  2002. if (emitted.insert(sf).second &&
  2003. this->SourcesQueued.insert(sf).second) {
  2004. this->SourceQueue.push(sf);
  2005. }
  2006. }
  2007. }
  2008. }
  2009. // Queue pre-build, pre-link, and post-build rule dependencies.
  2010. this->CheckCustomCommands(this->GeneratorTarget->GetPreBuildCommands());
  2011. this->CheckCustomCommands(this->GeneratorTarget->GetPreLinkCommands());
  2012. this->CheckCustomCommands(this->GeneratorTarget->GetPostBuildCommands());
  2013. }
  2014. void cmTargetTraceDependencies::Trace()
  2015. {
  2016. // Process one dependency at a time until the queue is empty.
  2017. while (!this->SourceQueue.empty()) {
  2018. // Get the next source from the queue.
  2019. cmSourceFile* sf = this->SourceQueue.front();
  2020. this->SourceQueue.pop();
  2021. this->CurrentEntry = &this->GeneratorTarget->SourceDepends[sf];
  2022. // Queue dependencies added explicitly by the user.
  2023. if (const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS")) {
  2024. std::vector<std::string> objDeps;
  2025. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  2026. for (std::string& objDep : objDeps) {
  2027. if (cmSystemTools::FileIsFullPath(objDep)) {
  2028. objDep = cmSystemTools::CollapseFullPath(objDep);
  2029. }
  2030. }
  2031. this->FollowNames(objDeps);
  2032. }
  2033. // Queue the source needed to generate this file, if any.
  2034. this->FollowName(sf->GetFullPath());
  2035. // Queue dependencies added programmatically by commands.
  2036. this->FollowNames(sf->GetDepends());
  2037. // Queue custom command dependencies.
  2038. if (cmCustomCommand const* cc = sf->GetCustomCommand()) {
  2039. this->CheckCustomCommand(*cc);
  2040. }
  2041. }
  2042. this->CurrentEntry = nullptr;
  2043. this->GeneratorTarget->AddTracedSources(this->NewSources);
  2044. }
  2045. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  2046. {
  2047. if (this->SourcesQueued.insert(sf).second) {
  2048. this->SourceQueue.push(sf);
  2049. // Make sure this file is in the target at the end.
  2050. this->NewSources.push_back(sf->GetFullPath());
  2051. }
  2052. }
  2053. void cmTargetTraceDependencies::FollowName(std::string const& name)
  2054. {
  2055. NameMapType::iterator i = this->NameMap.find(name);
  2056. if (i == this->NameMap.end()) {
  2057. // Check if we know how to generate this file.
  2058. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  2059. NameMapType::value_type entry(name, sf);
  2060. i = this->NameMap.insert(entry).first;
  2061. }
  2062. if (cmSourceFile* sf = i->second) {
  2063. // Record the dependency we just followed.
  2064. if (this->CurrentEntry) {
  2065. this->CurrentEntry->Depends.push_back(sf);
  2066. }
  2067. this->QueueSource(sf);
  2068. }
  2069. }
  2070. void cmTargetTraceDependencies::FollowNames(
  2071. std::vector<std::string> const& names)
  2072. {
  2073. for (std::string const& name : names) {
  2074. this->FollowName(name);
  2075. }
  2076. }
  2077. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  2078. {
  2079. // Dependencies on targets (utilities) are supposed to be named by
  2080. // just the target name. However for compatibility we support
  2081. // naming the output file generated by the target (assuming there is
  2082. // no output-name property which old code would not have set). In
  2083. // that case the target name will be the file basename of the
  2084. // dependency.
  2085. std::string util = cmSystemTools::GetFilenameName(dep);
  2086. if (cmSystemTools::GetFilenameLastExtension(util) == ".exe") {
  2087. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  2088. }
  2089. // Check for a target with this name.
  2090. if (cmGeneratorTarget* t =
  2091. this->GeneratorTarget->GetLocalGenerator()->FindGeneratorTargetToUse(
  2092. util)) {
  2093. // If we find the target and the dep was given as a full path,
  2094. // then make sure it was not a full path to something else, and
  2095. // the fact that the name matched a target was just a coincidence.
  2096. if (cmSystemTools::FileIsFullPath(dep)) {
  2097. if (t->GetType() >= cmStateEnums::EXECUTABLE &&
  2098. t->GetType() <= cmStateEnums::MODULE_LIBRARY) {
  2099. // This is really only for compatibility so we do not need to
  2100. // worry about configuration names and output names.
  2101. std::string tLocation = t->GetLocationForBuild();
  2102. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  2103. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  2104. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  2105. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  2106. if (depLocation == tLocation) {
  2107. this->GeneratorTarget->Target->AddUtility(util);
  2108. return true;
  2109. }
  2110. }
  2111. } else {
  2112. // The original name of the dependency was not a full path. It
  2113. // must name a target, so add the target-level dependency.
  2114. this->GeneratorTarget->Target->AddUtility(util);
  2115. return true;
  2116. }
  2117. }
  2118. // The dependency does not name a target built in this project.
  2119. return false;
  2120. }
  2121. void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
  2122. {
  2123. // Transform command names that reference targets built in this
  2124. // project to corresponding target-level dependencies.
  2125. cmGeneratorExpression ge(cc.GetBacktrace());
  2126. // Add target-level dependencies referenced by generator expressions.
  2127. std::set<cmGeneratorTarget*> targets;
  2128. for (cmCustomCommandLine const& cCmdLine : cc.GetCommandLines()) {
  2129. std::string const& command = *cCmdLine.begin();
  2130. // Check for a target with this name.
  2131. if (cmGeneratorTarget* t =
  2132. this->LocalGenerator->FindGeneratorTargetToUse(command)) {
  2133. if (t->GetType() == cmStateEnums::EXECUTABLE) {
  2134. // The command refers to an executable target built in
  2135. // this project. Add the target-level dependency to make
  2136. // sure the executable is up to date before this custom
  2137. // command possibly runs.
  2138. this->GeneratorTarget->Target->AddUtility(command);
  2139. }
  2140. }
  2141. // Check for target references in generator expressions.
  2142. for (std::string const& cl : cCmdLine) {
  2143. const std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(cl);
  2144. cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), "", true);
  2145. std::set<cmGeneratorTarget*> geTargets = cge->GetTargets();
  2146. targets.insert(geTargets.begin(), geTargets.end());
  2147. }
  2148. }
  2149. for (cmGeneratorTarget* target : targets) {
  2150. this->GeneratorTarget->Target->AddUtility(target->GetName());
  2151. }
  2152. // Queue the custom command dependencies.
  2153. std::vector<std::string> configs;
  2154. std::set<std::string> emitted;
  2155. this->Makefile->GetConfigurations(configs);
  2156. if (configs.empty()) {
  2157. configs.emplace_back();
  2158. }
  2159. for (std::string const& conf : configs) {
  2160. this->FollowCommandDepends(cc, conf, emitted);
  2161. }
  2162. }
  2163. void cmTargetTraceDependencies::FollowCommandDepends(
  2164. cmCustomCommand const& cc, const std::string& config,
  2165. std::set<std::string>& emitted)
  2166. {
  2167. cmCustomCommandGenerator ccg(cc, config,
  2168. this->GeneratorTarget->LocalGenerator);
  2169. const std::vector<std::string>& depends = ccg.GetDepends();
  2170. for (std::string const& dep : depends) {
  2171. if (emitted.insert(dep).second) {
  2172. if (!this->IsUtility(dep)) {
  2173. // The dependency does not name a target and may be a file we
  2174. // know how to generate. Queue it.
  2175. this->FollowName(dep);
  2176. }
  2177. }
  2178. }
  2179. }
  2180. void cmTargetTraceDependencies::CheckCustomCommands(
  2181. const std::vector<cmCustomCommand>& commands)
  2182. {
  2183. for (cmCustomCommand const& command : commands) {
  2184. this->CheckCustomCommand(command);
  2185. }
  2186. }
  2187. void cmGeneratorTarget::TraceDependencies()
  2188. {
  2189. // CMake-generated targets have no dependencies to trace. Normally tracing
  2190. // would find nothing anyway, but when building CMake itself the "install"
  2191. // target command ends up referencing the "cmake" target but we do not
  2192. // really want the dependency because "install" depend on "all" anyway.
  2193. if (this->GetType() == cmStateEnums::GLOBAL_TARGET) {
  2194. return;
  2195. }
  2196. // Use a helper object to trace the dependencies.
  2197. cmTargetTraceDependencies tracer(this);
  2198. tracer.Trace();
  2199. }
  2200. std::string cmGeneratorTarget::GetCompilePDBDirectory(
  2201. const std::string& config) const
  2202. {
  2203. if (CompileInfo const* info = this->GetCompileInfo(config)) {
  2204. return info->CompilePdbDir;
  2205. }
  2206. return "";
  2207. }
  2208. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  2209. std::vector<std::string>& archVec) const
  2210. {
  2211. const char* archs = nullptr;
  2212. if (!config.empty()) {
  2213. std::string defVarName = "OSX_ARCHITECTURES_";
  2214. defVarName += cmSystemTools::UpperCase(config);
  2215. archs = this->GetProperty(defVarName);
  2216. }
  2217. if (!archs) {
  2218. archs = this->GetProperty("OSX_ARCHITECTURES");
  2219. }
  2220. if (archs) {
  2221. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  2222. }
  2223. }
  2224. //----------------------------------------------------------------------------
  2225. std::string cmGeneratorTarget::GetFeatureSpecificLinkRuleVariable(
  2226. std::string const& var, std::string const& lang,
  2227. std::string const& config) const
  2228. {
  2229. if (this->IsIPOEnabled(lang, config)) {
  2230. std::string varIPO = var + "_IPO";
  2231. if (this->Makefile->IsDefinitionSet(varIPO)) {
  2232. return varIPO;
  2233. }
  2234. }
  2235. return var;
  2236. }
  2237. //----------------------------------------------------------------------------
  2238. std::string cmGeneratorTarget::GetCreateRuleVariable(
  2239. std::string const& lang, std::string const& config) const
  2240. {
  2241. switch (this->GetType()) {
  2242. case cmStateEnums::STATIC_LIBRARY: {
  2243. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  2244. return this->GetFeatureSpecificLinkRuleVariable(var, lang, config);
  2245. }
  2246. case cmStateEnums::SHARED_LIBRARY:
  2247. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  2248. case cmStateEnums::MODULE_LIBRARY:
  2249. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  2250. case cmStateEnums::EXECUTABLE:
  2251. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  2252. default:
  2253. break;
  2254. }
  2255. return "";
  2256. }
  2257. static void processIncludeDirectories(
  2258. cmGeneratorTarget const* tgt,
  2259. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2260. std::vector<BT<std::string>>& includes,
  2261. std::unordered_set<std::string>& uniqueIncludes,
  2262. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2263. bool debugIncludes, const std::string& language)
  2264. {
  2265. for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
  2266. cmLinkImplItem const& item = entry->LinkImplItem;
  2267. std::string const& targetName = item.AsStr();
  2268. bool const fromImported = item.Target && item.Target->IsImported();
  2269. bool const checkCMP0027 = item.FromGenex;
  2270. std::vector<std::string> entryIncludes;
  2271. cmSystemTools::ExpandListArgument(
  2272. entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
  2273. dagChecker, language),
  2274. entryIncludes);
  2275. std::string usedIncludes;
  2276. for (std::string& entryInclude : entryIncludes) {
  2277. if (fromImported && !cmSystemTools::FileExists(entryInclude)) {
  2278. std::ostringstream e;
  2279. MessageType messageType = MessageType::FATAL_ERROR;
  2280. if (checkCMP0027) {
  2281. switch (tgt->GetPolicyStatusCMP0027()) {
  2282. case cmPolicies::WARN:
  2283. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  2284. CM_FALLTHROUGH;
  2285. case cmPolicies::OLD:
  2286. messageType = MessageType::AUTHOR_WARNING;
  2287. break;
  2288. case cmPolicies::REQUIRED_ALWAYS:
  2289. case cmPolicies::REQUIRED_IF_USED:
  2290. case cmPolicies::NEW:
  2291. break;
  2292. }
  2293. }
  2294. /* clang-format off */
  2295. e << "Imported target \"" << targetName << "\" includes "
  2296. "non-existent path\n \"" << entryInclude << "\"\nin its "
  2297. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  2298. "* The path was deleted, renamed, or moved to another "
  2299. "location.\n"
  2300. "* An install or uninstall procedure did not complete "
  2301. "successfully.\n"
  2302. "* The installation package was faulty and references files it "
  2303. "does not provide.\n";
  2304. /* clang-format on */
  2305. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2306. return;
  2307. }
  2308. if (!cmSystemTools::FileIsFullPath(entryInclude)) {
  2309. std::ostringstream e;
  2310. bool noMessage = false;
  2311. MessageType messageType = MessageType::FATAL_ERROR;
  2312. if (!targetName.empty()) {
  2313. /* clang-format off */
  2314. e << "Target \"" << targetName << "\" contains relative "
  2315. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  2316. " \"" << entryInclude << "\"";
  2317. /* clang-format on */
  2318. } else {
  2319. switch (tgt->GetPolicyStatusCMP0021()) {
  2320. case cmPolicies::WARN: {
  2321. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  2322. messageType = MessageType::AUTHOR_WARNING;
  2323. } break;
  2324. case cmPolicies::OLD:
  2325. noMessage = true;
  2326. case cmPolicies::REQUIRED_IF_USED:
  2327. case cmPolicies::REQUIRED_ALWAYS:
  2328. case cmPolicies::NEW:
  2329. // Issue the fatal message.
  2330. break;
  2331. }
  2332. e << "Found relative path while evaluating include directories of "
  2333. "\""
  2334. << tgt->GetName() << "\":\n \"" << entryInclude << "\"\n";
  2335. }
  2336. if (!noMessage) {
  2337. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2338. if (messageType == MessageType::FATAL_ERROR) {
  2339. return;
  2340. }
  2341. }
  2342. }
  2343. if (!cmSystemTools::IsOff(entryInclude)) {
  2344. cmSystemTools::ConvertToUnixSlashes(entryInclude);
  2345. }
  2346. std::string inc = entryInclude;
  2347. if (uniqueIncludes.insert(inc).second) {
  2348. includes.emplace_back(inc, entry->ge->GetBacktrace());
  2349. if (debugIncludes) {
  2350. usedIncludes += " * " + inc + "\n";
  2351. }
  2352. }
  2353. }
  2354. if (!usedIncludes.empty()) {
  2355. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2356. MessageType::LOG,
  2357. std::string("Used includes for target ") + tgt->GetName() + ":\n" +
  2358. usedIncludes,
  2359. entry->ge->GetBacktrace());
  2360. }
  2361. }
  2362. }
  2363. std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
  2364. const std::string& config, const std::string& lang) const
  2365. {
  2366. std::vector<BT<std::string>> includes;
  2367. std::unordered_set<std::string> uniqueIncludes;
  2368. cmGeneratorExpressionDAGChecker dagChecker(this, "INCLUDE_DIRECTORIES",
  2369. nullptr, nullptr);
  2370. std::vector<std::string> debugProperties;
  2371. const char* debugProp =
  2372. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2373. if (debugProp) {
  2374. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2375. }
  2376. bool debugIncludes = !this->DebugIncludesDone &&
  2377. std::find(debugProperties.begin(), debugProperties.end(),
  2378. "INCLUDE_DIRECTORIES") != debugProperties.end();
  2379. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2380. this->DebugIncludesDone = true;
  2381. }
  2382. processIncludeDirectories(this, this->IncludeDirectoriesEntries, includes,
  2383. uniqueIncludes, &dagChecker, config, debugIncludes,
  2384. lang);
  2385. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2386. linkInterfaceIncludeDirectoriesEntries;
  2387. AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  2388. linkInterfaceIncludeDirectoriesEntries);
  2389. if (this->Makefile->IsOn("APPLE")) {
  2390. cmLinkImplementationLibraries const* impl =
  2391. this->GetLinkImplementationLibraries(config);
  2392. for (cmLinkImplItem const& lib : impl->Libraries) {
  2393. std::string libDir = cmSystemTools::CollapseFullPath(lib.AsStr());
  2394. static cmsys::RegularExpression frameworkCheck(
  2395. "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  2396. if (!frameworkCheck.find(libDir)) {
  2397. continue;
  2398. }
  2399. libDir = frameworkCheck.match(1);
  2400. cmGeneratorExpression ge;
  2401. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2402. ge.Parse(libDir.c_str());
  2403. linkInterfaceIncludeDirectoriesEntries.push_back(
  2404. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge)));
  2405. }
  2406. }
  2407. processIncludeDirectories(this, linkInterfaceIncludeDirectoriesEntries,
  2408. includes, uniqueIncludes, &dagChecker, config,
  2409. debugIncludes, lang);
  2410. cmDeleteAll(linkInterfaceIncludeDirectoriesEntries);
  2411. return includes;
  2412. }
  2413. enum class OptionsParse
  2414. {
  2415. None,
  2416. Shell
  2417. };
  2418. static void processOptionsInternal(
  2419. cmGeneratorTarget const* tgt,
  2420. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2421. std::vector<BT<std::string>>& options,
  2422. std::unordered_set<std::string>& uniqueOptions,
  2423. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2424. bool debugOptions, const char* logName, std::string const& language,
  2425. OptionsParse parse)
  2426. {
  2427. for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
  2428. std::vector<std::string> entryOptions;
  2429. cmSystemTools::ExpandListArgument(
  2430. entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
  2431. dagChecker, language),
  2432. entryOptions);
  2433. std::string usedOptions;
  2434. for (std::string const& opt : entryOptions) {
  2435. if (uniqueOptions.insert(opt).second) {
  2436. if (parse == OptionsParse::Shell &&
  2437. cmHasLiteralPrefix(opt, "SHELL:")) {
  2438. std::vector<std::string> tmp;
  2439. cmSystemTools::ParseUnixCommandLine(opt.c_str() + 6, tmp);
  2440. for (std::string& o : tmp) {
  2441. options.emplace_back(std::move(o), entry->ge->GetBacktrace());
  2442. }
  2443. } else {
  2444. options.emplace_back(opt, entry->ge->GetBacktrace());
  2445. }
  2446. if (debugOptions) {
  2447. usedOptions += " * " + opt + "\n";
  2448. }
  2449. }
  2450. }
  2451. if (!usedOptions.empty()) {
  2452. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2453. MessageType::LOG,
  2454. std::string("Used ") + logName + std::string(" for target ") +
  2455. tgt->GetName() + ":\n" + usedOptions,
  2456. entry->ge->GetBacktrace());
  2457. }
  2458. }
  2459. }
  2460. static void processCompileOptions(
  2461. cmGeneratorTarget const* tgt,
  2462. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2463. std::vector<BT<std::string>>& options,
  2464. std::unordered_set<std::string>& uniqueOptions,
  2465. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2466. bool debugOptions, std::string const& language)
  2467. {
  2468. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2469. config, debugOptions, "compile options", language,
  2470. OptionsParse::Shell);
  2471. }
  2472. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
  2473. const std::string& config,
  2474. const std::string& language) const
  2475. {
  2476. std::vector<BT<std::string>> tmp = this->GetCompileOptions(config, language);
  2477. result.reserve(tmp.size());
  2478. for (BT<std::string>& v : tmp) {
  2479. result.emplace_back(std::move(v.Value));
  2480. }
  2481. }
  2482. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
  2483. std::string const& config, std::string const& language) const
  2484. {
  2485. std::vector<BT<std::string>> result;
  2486. std::unordered_set<std::string> uniqueOptions;
  2487. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_OPTIONS", nullptr,
  2488. nullptr);
  2489. std::vector<std::string> debugProperties;
  2490. const char* debugProp =
  2491. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2492. if (debugProp) {
  2493. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2494. }
  2495. bool debugOptions = !this->DebugCompileOptionsDone &&
  2496. std::find(debugProperties.begin(), debugProperties.end(),
  2497. "COMPILE_OPTIONS") != debugProperties.end();
  2498. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2499. this->DebugCompileOptionsDone = true;
  2500. }
  2501. processCompileOptions(this, this->CompileOptionsEntries, result,
  2502. uniqueOptions, &dagChecker, config, debugOptions,
  2503. language);
  2504. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2505. linkInterfaceCompileOptionsEntries;
  2506. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_OPTIONS",
  2507. linkInterfaceCompileOptionsEntries);
  2508. processCompileOptions(this, linkInterfaceCompileOptionsEntries, result,
  2509. uniqueOptions, &dagChecker, config, debugOptions,
  2510. language);
  2511. cmDeleteAll(linkInterfaceCompileOptionsEntries);
  2512. return result;
  2513. }
  2514. static void processCompileFeatures(
  2515. cmGeneratorTarget const* tgt,
  2516. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2517. std::vector<BT<std::string>>& options,
  2518. std::unordered_set<std::string>& uniqueOptions,
  2519. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2520. bool debugOptions)
  2521. {
  2522. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2523. config, debugOptions, "compile features",
  2524. std::string(), OptionsParse::None);
  2525. }
  2526. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
  2527. const std::string& config) const
  2528. {
  2529. std::vector<BT<std::string>> tmp = this->GetCompileFeatures(config);
  2530. result.reserve(tmp.size());
  2531. for (BT<std::string>& v : tmp) {
  2532. result.emplace_back(std::move(v.Value));
  2533. }
  2534. }
  2535. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
  2536. std::string const& config) const
  2537. {
  2538. std::vector<BT<std::string>> result;
  2539. std::unordered_set<std::string> uniqueFeatures;
  2540. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_FEATURES", nullptr,
  2541. nullptr);
  2542. std::vector<std::string> debugProperties;
  2543. const char* debugProp =
  2544. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2545. if (debugProp) {
  2546. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2547. }
  2548. bool debugFeatures = !this->DebugCompileFeaturesDone &&
  2549. std::find(debugProperties.begin(), debugProperties.end(),
  2550. "COMPILE_FEATURES") != debugProperties.end();
  2551. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2552. this->DebugCompileFeaturesDone = true;
  2553. }
  2554. processCompileFeatures(this, this->CompileFeaturesEntries, result,
  2555. uniqueFeatures, &dagChecker, config, debugFeatures);
  2556. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2557. linkInterfaceCompileFeaturesEntries;
  2558. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_FEATURES",
  2559. linkInterfaceCompileFeaturesEntries);
  2560. processCompileFeatures(this, linkInterfaceCompileFeaturesEntries, result,
  2561. uniqueFeatures, &dagChecker, config, debugFeatures);
  2562. cmDeleteAll(linkInterfaceCompileFeaturesEntries);
  2563. return result;
  2564. }
  2565. static void processCompileDefinitions(
  2566. cmGeneratorTarget const* tgt,
  2567. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2568. std::vector<BT<std::string>>& options,
  2569. std::unordered_set<std::string>& uniqueOptions,
  2570. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2571. bool debugOptions, std::string const& language)
  2572. {
  2573. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2574. config, debugOptions, "compile definitions", language,
  2575. OptionsParse::None);
  2576. }
  2577. void cmGeneratorTarget::GetCompileDefinitions(
  2578. std::vector<std::string>& result, const std::string& config,
  2579. const std::string& language) const
  2580. {
  2581. std::vector<BT<std::string>> tmp =
  2582. this->GetCompileDefinitions(config, language);
  2583. result.reserve(tmp.size());
  2584. for (BT<std::string>& v : tmp) {
  2585. result.emplace_back(std::move(v.Value));
  2586. }
  2587. }
  2588. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
  2589. std::string const& config, std::string const& language) const
  2590. {
  2591. std::vector<BT<std::string>> list;
  2592. std::unordered_set<std::string> uniqueOptions;
  2593. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_DEFINITIONS",
  2594. nullptr, nullptr);
  2595. std::vector<std::string> debugProperties;
  2596. const char* debugProp =
  2597. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2598. if (debugProp) {
  2599. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2600. }
  2601. bool debugDefines = !this->DebugCompileDefinitionsDone &&
  2602. std::find(debugProperties.begin(), debugProperties.end(),
  2603. "COMPILE_DEFINITIONS") != debugProperties.end();
  2604. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2605. this->DebugCompileDefinitionsDone = true;
  2606. }
  2607. processCompileDefinitions(this, this->CompileDefinitionsEntries, list,
  2608. uniqueOptions, &dagChecker, config, debugDefines,
  2609. language);
  2610. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2611. linkInterfaceCompileDefinitionsEntries;
  2612. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2613. linkInterfaceCompileDefinitionsEntries);
  2614. if (!config.empty()) {
  2615. std::string configPropName =
  2616. "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
  2617. const char* configProp = this->GetProperty(configPropName);
  2618. if (configProp) {
  2619. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) {
  2620. case cmPolicies::WARN: {
  2621. std::ostringstream e;
  2622. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  2623. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING,
  2624. e.str());
  2625. CM_FALLTHROUGH;
  2626. }
  2627. case cmPolicies::OLD: {
  2628. cmGeneratorExpression ge;
  2629. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2630. ge.Parse(configProp);
  2631. linkInterfaceCompileDefinitionsEntries.push_back(
  2632. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge)));
  2633. } break;
  2634. case cmPolicies::NEW:
  2635. case cmPolicies::REQUIRED_ALWAYS:
  2636. case cmPolicies::REQUIRED_IF_USED:
  2637. break;
  2638. }
  2639. }
  2640. }
  2641. processCompileDefinitions(this, linkInterfaceCompileDefinitionsEntries, list,
  2642. uniqueOptions, &dagChecker, config, debugDefines,
  2643. language);
  2644. cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
  2645. return list;
  2646. }
  2647. namespace {
  2648. void processLinkOptions(
  2649. cmGeneratorTarget const* tgt,
  2650. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2651. std::vector<BT<std::string>>& options,
  2652. std::unordered_set<std::string>& uniqueOptions,
  2653. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2654. bool debugOptions, std::string const& language)
  2655. {
  2656. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2657. config, debugOptions, "link options", language,
  2658. OptionsParse::Shell);
  2659. }
  2660. }
  2661. void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
  2662. const std::string& config,
  2663. const std::string& language) const
  2664. {
  2665. std::vector<BT<std::string>> tmp = this->GetLinkOptions(config, language);
  2666. result.reserve(tmp.size());
  2667. for (BT<std::string>& v : tmp) {
  2668. result.emplace_back(std::move(v.Value));
  2669. }
  2670. }
  2671. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
  2672. std::string const& config, std::string const& language) const
  2673. {
  2674. std::vector<BT<std::string>> result;
  2675. std::unordered_set<std::string> uniqueOptions;
  2676. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_OPTIONS", nullptr,
  2677. nullptr);
  2678. std::vector<std::string> debugProperties;
  2679. const char* debugProp =
  2680. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2681. if (debugProp) {
  2682. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2683. }
  2684. bool debugOptions = !this->DebugLinkOptionsDone &&
  2685. std::find(debugProperties.begin(), debugProperties.end(),
  2686. "LINK_OPTIONS") != debugProperties.end();
  2687. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2688. this->DebugLinkOptionsDone = true;
  2689. }
  2690. processLinkOptions(this, this->LinkOptionsEntries, result, uniqueOptions,
  2691. &dagChecker, config, debugOptions, language);
  2692. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2693. linkInterfaceLinkOptionsEntries;
  2694. AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS",
  2695. linkInterfaceLinkOptionsEntries);
  2696. processLinkOptions(this, linkInterfaceLinkOptionsEntries, result,
  2697. uniqueOptions, &dagChecker, config, debugOptions,
  2698. language);
  2699. cmDeleteAll(linkInterfaceLinkOptionsEntries);
  2700. // Last step: replace "LINKER:" prefixed elements by
  2701. // actual linker wrapper
  2702. const std::string wrapper(this->Makefile->GetSafeDefinition(
  2703. "CMAKE_" + language + "_LINKER_WRAPPER_FLAG"));
  2704. std::vector<std::string> wrapperFlag;
  2705. cmSystemTools::ExpandListArgument(wrapper, wrapperFlag);
  2706. const std::string wrapperSep(this->Makefile->GetSafeDefinition(
  2707. "CMAKE_" + language + "_LINKER_WRAPPER_FLAG_SEP"));
  2708. bool concatFlagAndArgs = true;
  2709. if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
  2710. concatFlagAndArgs = false;
  2711. wrapperFlag.pop_back();
  2712. }
  2713. const std::string LINKER{ "LINKER:" };
  2714. const std::string SHELL{ "SHELL:" };
  2715. const std::string LINKER_SHELL = LINKER + SHELL;
  2716. std::vector<BT<std::string>>::iterator entry;
  2717. while ((entry = std::find_if(result.begin(), result.end(),
  2718. [&LINKER](BT<std::string> const& item) -> bool {
  2719. return item.Value.compare(0, LINKER.length(),
  2720. LINKER) == 0;
  2721. })) != result.end()) {
  2722. std::string value = std::move(entry->Value);
  2723. cmListFileBacktrace bt = std::move(entry->Backtrace);
  2724. entry = result.erase(entry);
  2725. std::vector<std::string> linkerOptions;
  2726. if (value.compare(0, LINKER_SHELL.length(), LINKER_SHELL) == 0) {
  2727. cmSystemTools::ParseUnixCommandLine(
  2728. value.c_str() + LINKER_SHELL.length(), linkerOptions);
  2729. } else {
  2730. linkerOptions =
  2731. cmSystemTools::tokenize(value.substr(LINKER.length()), ",");
  2732. }
  2733. if (linkerOptions.empty() ||
  2734. (linkerOptions.size() == 1 && linkerOptions.front().empty())) {
  2735. continue;
  2736. }
  2737. // for now, raise an error if prefix SHELL: is part of arguments
  2738. if (std::find_if(linkerOptions.begin(), linkerOptions.end(),
  2739. [&SHELL](const std::string& item) -> bool {
  2740. return item.find(SHELL) != std::string::npos;
  2741. }) != linkerOptions.end()) {
  2742. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  2743. MessageType::FATAL_ERROR,
  2744. "'SHELL:' prefix is not supported as part of 'LINKER:' arguments.",
  2745. this->GetBacktrace());
  2746. return result;
  2747. }
  2748. std::vector<BT<std::string>> options;
  2749. if (wrapperFlag.empty()) {
  2750. // nothing specified, insert elements as is
  2751. options.reserve(linkerOptions.size());
  2752. for (std::string& o : linkerOptions) {
  2753. options.emplace_back(std::move(o), bt);
  2754. }
  2755. } else {
  2756. if (!wrapperSep.empty()) {
  2757. if (concatFlagAndArgs) {
  2758. // insert flag elements except last one
  2759. for (auto i = wrapperFlag.begin(); i != wrapperFlag.end() - 1; ++i) {
  2760. options.emplace_back(*i, bt);
  2761. }
  2762. // concatenate last flag element and all LINKER list values
  2763. // in one option
  2764. options.emplace_back(
  2765. wrapperFlag.back() + cmJoin(linkerOptions, wrapperSep), bt);
  2766. } else {
  2767. for (std::string const& i : wrapperFlag) {
  2768. options.emplace_back(i, bt);
  2769. }
  2770. // concatenate all LINKER list values in one option
  2771. options.emplace_back(cmJoin(linkerOptions, wrapperSep), bt);
  2772. }
  2773. } else {
  2774. // prefix each element of LINKER list with wrapper
  2775. if (concatFlagAndArgs) {
  2776. std::transform(linkerOptions.begin(), linkerOptions.end(),
  2777. linkerOptions.begin(),
  2778. [&wrapperFlag](std::string const& o) -> std::string {
  2779. return wrapperFlag.back() + o;
  2780. });
  2781. }
  2782. for (std::string& o : linkerOptions) {
  2783. for (auto i = wrapperFlag.begin(),
  2784. e = concatFlagAndArgs ? wrapperFlag.end() - 1
  2785. : wrapperFlag.end();
  2786. i != e; ++i) {
  2787. options.emplace_back(*i, bt);
  2788. }
  2789. options.emplace_back(std::move(o), bt);
  2790. }
  2791. }
  2792. }
  2793. result.insert(entry, options.begin(), options.end());
  2794. }
  2795. return result;
  2796. }
  2797. namespace {
  2798. void processStaticLibraryLinkOptions(
  2799. cmGeneratorTarget const* tgt,
  2800. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2801. std::vector<BT<std::string>>& options,
  2802. std::unordered_set<std::string>& uniqueOptions,
  2803. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2804. std::string const& language)
  2805. {
  2806. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2807. config, false, "static library link options",
  2808. language, OptionsParse::Shell);
  2809. }
  2810. }
  2811. void cmGeneratorTarget::GetStaticLibraryLinkOptions(
  2812. std::vector<std::string>& result, const std::string& config,
  2813. const std::string& language) const
  2814. {
  2815. std::vector<BT<std::string>> tmp =
  2816. this->GetStaticLibraryLinkOptions(config, language);
  2817. result.reserve(tmp.size());
  2818. for (BT<std::string>& v : tmp) {
  2819. result.emplace_back(std::move(v.Value));
  2820. }
  2821. }
  2822. std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
  2823. std::string const& config, std::string const& language) const
  2824. {
  2825. std::vector<BT<std::string>> result;
  2826. std::vector<cmGeneratorTarget::TargetPropertyEntry*> entries;
  2827. std::unordered_set<std::string> uniqueOptions;
  2828. cmGeneratorExpressionDAGChecker dagChecker(this, "STATIC_LIBRARY_OPTIONS",
  2829. nullptr, nullptr);
  2830. if (const char* linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
  2831. std::vector<std::string> options;
  2832. cmGeneratorExpression ge;
  2833. cmSystemTools::ExpandListArgument(linkOptions, options);
  2834. for (const auto& option : options) {
  2835. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(option);
  2836. entries.push_back(
  2837. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge)));
  2838. }
  2839. }
  2840. processStaticLibraryLinkOptions(this, entries, result, uniqueOptions,
  2841. &dagChecker, config, language);
  2842. cmDeleteAll(entries);
  2843. return result;
  2844. }
  2845. namespace {
  2846. void processLinkDirectories(
  2847. cmGeneratorTarget const* tgt,
  2848. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2849. std::vector<BT<std::string>>& directories,
  2850. std::unordered_set<std::string>& uniqueDirectories,
  2851. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2852. bool debugDirectories, std::string const& language)
  2853. {
  2854. for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
  2855. cmLinkImplItem const& item = entry->LinkImplItem;
  2856. std::string const& targetName = item.AsStr();
  2857. std::vector<std::string> entryDirectories;
  2858. cmSystemTools::ExpandListArgument(
  2859. entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
  2860. dagChecker, language),
  2861. entryDirectories);
  2862. std::string usedDirectories;
  2863. for (std::string& entryDirectory : entryDirectories) {
  2864. if (!cmSystemTools::FileIsFullPath(entryDirectory)) {
  2865. std::ostringstream e;
  2866. bool noMessage = false;
  2867. MessageType messageType = MessageType::FATAL_ERROR;
  2868. if (!targetName.empty()) {
  2869. /* clang-format off */
  2870. e << "Target \"" << targetName << "\" contains relative "
  2871. "path in its INTERFACE_LINK_DIRECTORIES:\n"
  2872. " \"" << entryDirectory << "\"";
  2873. /* clang-format on */
  2874. } else {
  2875. switch (tgt->GetPolicyStatusCMP0081()) {
  2876. case cmPolicies::WARN: {
  2877. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0081) << "\n";
  2878. messageType = MessageType::AUTHOR_WARNING;
  2879. } break;
  2880. case cmPolicies::OLD:
  2881. noMessage = true;
  2882. break;
  2883. case cmPolicies::REQUIRED_IF_USED:
  2884. case cmPolicies::REQUIRED_ALWAYS:
  2885. case cmPolicies::NEW:
  2886. // Issue the fatal message.
  2887. break;
  2888. }
  2889. e << "Found relative path while evaluating link directories of "
  2890. "\""
  2891. << tgt->GetName() << "\":\n \"" << entryDirectory << "\"\n";
  2892. }
  2893. if (!noMessage) {
  2894. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2895. if (messageType == MessageType::FATAL_ERROR) {
  2896. return;
  2897. }
  2898. }
  2899. }
  2900. // Sanitize the path the same way the link_directories command does
  2901. // in case projects set the LINK_DIRECTORIES property directly.
  2902. cmSystemTools::ConvertToUnixSlashes(entryDirectory);
  2903. if (uniqueDirectories.insert(entryDirectory).second) {
  2904. directories.push_back(entryDirectory);
  2905. if (debugDirectories) {
  2906. usedDirectories += " * " + entryDirectory + "\n";
  2907. }
  2908. }
  2909. }
  2910. if (!usedDirectories.empty()) {
  2911. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2912. MessageType::LOG,
  2913. std::string("Used link directories for target ") + tgt->GetName() +
  2914. ":\n" + usedDirectories,
  2915. entry->ge->GetBacktrace());
  2916. }
  2917. }
  2918. }
  2919. }
  2920. void cmGeneratorTarget::GetLinkDirectories(std::vector<std::string>& result,
  2921. const std::string& config,
  2922. const std::string& language) const
  2923. {
  2924. std::vector<BT<std::string>> tmp =
  2925. this->GetLinkDirectories(config, language);
  2926. result.reserve(tmp.size());
  2927. for (BT<std::string>& v : tmp) {
  2928. result.emplace_back(std::move(v.Value));
  2929. }
  2930. }
  2931. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
  2932. std::string const& config, std::string const& language) const
  2933. {
  2934. std::vector<BT<std::string>> result;
  2935. std::unordered_set<std::string> uniqueDirectories;
  2936. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DIRECTORIES", nullptr,
  2937. nullptr);
  2938. std::vector<std::string> debugProperties;
  2939. const char* debugProp =
  2940. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2941. if (debugProp) {
  2942. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2943. }
  2944. bool debugDirectories = !this->DebugLinkDirectoriesDone &&
  2945. std::find(debugProperties.begin(), debugProperties.end(),
  2946. "LINK_DIRECTORIES") != debugProperties.end();
  2947. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2948. this->DebugLinkDirectoriesDone = true;
  2949. }
  2950. processLinkDirectories(this, this->LinkDirectoriesEntries, result,
  2951. uniqueDirectories, &dagChecker, config,
  2952. debugDirectories, language);
  2953. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2954. linkInterfaceLinkDirectoriesEntries;
  2955. AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES",
  2956. linkInterfaceLinkDirectoriesEntries);
  2957. processLinkDirectories(this, linkInterfaceLinkDirectoriesEntries, result,
  2958. uniqueDirectories, &dagChecker, config,
  2959. debugDirectories, language);
  2960. cmDeleteAll(linkInterfaceLinkDirectoriesEntries);
  2961. return result;
  2962. }
  2963. namespace {
  2964. void processLinkDepends(
  2965. cmGeneratorTarget const* tgt,
  2966. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2967. std::vector<BT<std::string>>& options,
  2968. std::unordered_set<std::string>& uniqueOptions,
  2969. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2970. std::string const& language)
  2971. {
  2972. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2973. config, false, "link depends", language,
  2974. OptionsParse::None);
  2975. }
  2976. }
  2977. void cmGeneratorTarget::GetLinkDepends(std::vector<std::string>& result,
  2978. const std::string& config,
  2979. const std::string& language) const
  2980. {
  2981. std::vector<BT<std::string>> tmp = this->GetLinkDepends(config, language);
  2982. result.reserve(tmp.size());
  2983. for (BT<std::string>& v : tmp) {
  2984. result.emplace_back(std::move(v.Value));
  2985. }
  2986. }
  2987. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
  2988. std::string const& config, std::string const& language) const
  2989. {
  2990. std::vector<BT<std::string>> result;
  2991. std::vector<cmGeneratorTarget::TargetPropertyEntry*> linkDependsEntries;
  2992. std::unordered_set<std::string> uniqueOptions;
  2993. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DEPENDS", nullptr,
  2994. nullptr);
  2995. if (const char* linkDepends = this->GetProperty("LINK_DEPENDS")) {
  2996. std::vector<std::string> depends;
  2997. cmGeneratorExpression ge;
  2998. cmSystemTools::ExpandListArgument(linkDepends, depends);
  2999. for (const auto& depend : depends) {
  3000. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(depend);
  3001. linkDependsEntries.push_back(
  3002. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge)));
  3003. }
  3004. }
  3005. AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS",
  3006. linkDependsEntries);
  3007. processLinkDepends(this, linkDependsEntries, result, uniqueOptions,
  3008. &dagChecker, config, language);
  3009. cmDeleteAll(linkDependsEntries);
  3010. return result;
  3011. }
  3012. void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
  3013. {
  3014. if (this->IsImported()) {
  3015. return;
  3016. }
  3017. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  3018. // Get the names.
  3019. std::string name;
  3020. std::string soName;
  3021. std::string realName;
  3022. std::string impName;
  3023. std::string pdbName;
  3024. if (this->GetType() == cmStateEnums::EXECUTABLE) {
  3025. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3026. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  3027. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3028. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3029. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3030. } else {
  3031. return;
  3032. }
  3033. // Get the directory.
  3034. std::string dir =
  3035. this->GetDirectory(config, cmStateEnums::RuntimeBinaryArtifact);
  3036. // Add each name.
  3037. std::string f;
  3038. if (!name.empty()) {
  3039. f = dir;
  3040. f += "/";
  3041. f += name;
  3042. gg->AddToManifest(f);
  3043. }
  3044. if (!soName.empty()) {
  3045. f = dir;
  3046. f += "/";
  3047. f += soName;
  3048. gg->AddToManifest(f);
  3049. }
  3050. if (!realName.empty()) {
  3051. f = dir;
  3052. f += "/";
  3053. f += realName;
  3054. gg->AddToManifest(f);
  3055. }
  3056. if (!pdbName.empty()) {
  3057. f = dir;
  3058. f += "/";
  3059. f += pdbName;
  3060. gg->AddToManifest(f);
  3061. }
  3062. if (!impName.empty()) {
  3063. f = this->GetDirectory(config, cmStateEnums::ImportLibraryArtifact);
  3064. f += "/";
  3065. f += impName;
  3066. gg->AddToManifest(f);
  3067. }
  3068. }
  3069. bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config) const
  3070. {
  3071. std::vector<BT<std::string>> features = this->GetCompileFeatures(config);
  3072. for (BT<std::string> const& f : features) {
  3073. if (!this->Makefile->AddRequiredTargetFeature(this->Target, f.Value)) {
  3074. return false;
  3075. }
  3076. }
  3077. return true;
  3078. }
  3079. std::string cmGeneratorTarget::GetImportedLibName(
  3080. std::string const& config) const
  3081. {
  3082. if (cmGeneratorTarget::ImportInfo const* info =
  3083. this->GetImportInfo(config)) {
  3084. return info->LibName;
  3085. }
  3086. return std::string();
  3087. }
  3088. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  3089. cmStateEnums::ArtifactType artifact,
  3090. bool realname) const
  3091. {
  3092. if (this->IsImported()) {
  3093. return this->Target->ImportedGetFullPath(config, artifact);
  3094. }
  3095. return this->NormalGetFullPath(config, artifact, realname);
  3096. }
  3097. std::string cmGeneratorTarget::NormalGetFullPath(
  3098. const std::string& config, cmStateEnums::ArtifactType artifact,
  3099. bool realname) const
  3100. {
  3101. std::string fpath = this->GetDirectory(config, artifact);
  3102. fpath += "/";
  3103. if (this->IsAppBundleOnApple()) {
  3104. fpath = this->BuildBundleDirectory(fpath, config, FullLevel);
  3105. fpath += "/";
  3106. }
  3107. // Add the full name of the target.
  3108. switch (artifact) {
  3109. case cmStateEnums::RuntimeBinaryArtifact:
  3110. if (realname) {
  3111. fpath += this->NormalGetRealName(config);
  3112. } else {
  3113. fpath +=
  3114. this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact);
  3115. }
  3116. break;
  3117. case cmStateEnums::ImportLibraryArtifact:
  3118. fpath += this->GetFullName(config, cmStateEnums::ImportLibraryArtifact);
  3119. break;
  3120. }
  3121. return fpath;
  3122. }
  3123. std::string cmGeneratorTarget::NormalGetRealName(
  3124. const std::string& config) const
  3125. {
  3126. // This should not be called for imported targets.
  3127. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3128. // enforcement of the limited imported target API.
  3129. if (this->IsImported()) {
  3130. std::string msg = "NormalGetRealName called on imported target: ";
  3131. msg += this->GetName();
  3132. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  3133. }
  3134. if (this->GetType() == cmStateEnums::EXECUTABLE) {
  3135. // Compute the real name that will be built.
  3136. std::string name;
  3137. std::string realName;
  3138. std::string impName;
  3139. std::string pdbName;
  3140. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3141. return realName;
  3142. }
  3143. // Compute the real name that will be built.
  3144. std::string name;
  3145. std::string soName;
  3146. std::string realName;
  3147. std::string impName;
  3148. std::string pdbName;
  3149. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3150. return realName;
  3151. }
  3152. void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName,
  3153. std::string& realName,
  3154. std::string& impName,
  3155. std::string& pdbName,
  3156. const std::string& config) const
  3157. {
  3158. // This should not be called for imported targets.
  3159. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3160. // enforcement of the limited imported target API.
  3161. if (this->IsImported()) {
  3162. std::string msg = "GetLibraryNames called on imported target: ";
  3163. msg += this->GetName();
  3164. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  3165. return;
  3166. }
  3167. // Check for library version properties.
  3168. const char* version = this->GetProperty("VERSION");
  3169. const char* soversion = this->GetProperty("SOVERSION");
  3170. if (!this->HasSOName(config) ||
  3171. this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
  3172. this->IsFrameworkOnApple()) {
  3173. // Versioning is supported only for shared libraries and modules,
  3174. // and then only when the platform supports an soname flag.
  3175. version = nullptr;
  3176. soversion = nullptr;
  3177. }
  3178. if (version && !soversion) {
  3179. // The soversion must be set if the library version is set. Use
  3180. // the library version as the soversion.
  3181. soversion = version;
  3182. }
  3183. if (!version && soversion) {
  3184. // Use the soversion as the library version.
  3185. version = soversion;
  3186. }
  3187. // Get the components of the library name.
  3188. std::string prefix;
  3189. std::string base;
  3190. std::string suffix;
  3191. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  3192. prefix, base, suffix);
  3193. // The library name.
  3194. name = prefix + base + suffix;
  3195. if (this->IsFrameworkOnApple()) {
  3196. realName = prefix;
  3197. if (!this->Makefile->PlatformIsAppleEmbedded()) {
  3198. realName += "Versions/";
  3199. realName += this->GetFrameworkVersion();
  3200. realName += "/";
  3201. }
  3202. realName += base;
  3203. soName = realName;
  3204. } else {
  3205. // The library's soname.
  3206. this->ComputeVersionedName(soName, prefix, base, suffix, name, soversion);
  3207. // The library's real name on disk.
  3208. this->ComputeVersionedName(realName, prefix, base, suffix, name, version);
  3209. }
  3210. // The import library name.
  3211. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3212. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3213. impName =
  3214. this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
  3215. } else {
  3216. impName.clear();
  3217. }
  3218. // The program database file name.
  3219. pdbName = this->GetPDBName(config);
  3220. }
  3221. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  3222. std::string& realName,
  3223. std::string& impName,
  3224. std::string& pdbName,
  3225. const std::string& config) const
  3226. {
  3227. // This should not be called for imported targets.
  3228. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3229. // enforcement of the limited imported target API.
  3230. if (this->IsImported()) {
  3231. std::string msg = "GetExecutableNames called on imported target: ";
  3232. msg += this->GetName();
  3233. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  3234. }
  3235. // This versioning is supported only for executables and then only
  3236. // when the platform supports symbolic links.
  3237. #if defined(_WIN32) && !defined(__CYGWIN__)
  3238. const char* version = 0;
  3239. #else
  3240. // Check for executable version properties.
  3241. const char* version = this->GetProperty("VERSION");
  3242. if (this->GetType() != cmStateEnums::EXECUTABLE ||
  3243. this->Makefile->IsOn("XCODE")) {
  3244. version = nullptr;
  3245. }
  3246. #endif
  3247. // Get the components of the executable name.
  3248. std::string prefix;
  3249. std::string base;
  3250. std::string suffix;
  3251. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  3252. prefix, base, suffix);
  3253. // The executable name.
  3254. name = prefix + base + suffix;
  3255. // The executable's real name on disk.
  3256. #if defined(__CYGWIN__)
  3257. realName = prefix + base;
  3258. #else
  3259. realName = name;
  3260. #endif
  3261. if (version) {
  3262. realName += "-";
  3263. realName += version;
  3264. }
  3265. #if defined(__CYGWIN__)
  3266. realName += suffix;
  3267. #endif
  3268. // The import library name.
  3269. impName =
  3270. this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
  3271. // The program database file name.
  3272. pdbName = this->GetPDBName(config);
  3273. }
  3274. std::string cmGeneratorTarget::GetFullNameInternal(
  3275. const std::string& config, cmStateEnums::ArtifactType artifact) const
  3276. {
  3277. std::string prefix;
  3278. std::string base;
  3279. std::string suffix;
  3280. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  3281. return prefix + base + suffix;
  3282. }
  3283. std::string cmGeneratorTarget::ImportedGetLocation(
  3284. const std::string& config) const
  3285. {
  3286. assert(this->IsImported());
  3287. return this->Target->ImportedGetFullPath(
  3288. config, cmStateEnums::RuntimeBinaryArtifact);
  3289. }
  3290. std::string cmGeneratorTarget::GetFullNameImported(
  3291. const std::string& config, cmStateEnums::ArtifactType artifact) const
  3292. {
  3293. return cmSystemTools::GetFilenameName(
  3294. this->Target->ImportedGetFullPath(config, artifact));
  3295. }
  3296. void cmGeneratorTarget::GetFullNameInternal(
  3297. const std::string& config, cmStateEnums::ArtifactType artifact,
  3298. std::string& outPrefix, std::string& outBase, std::string& outSuffix) const
  3299. {
  3300. // Use just the target name for non-main target types.
  3301. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  3302. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  3303. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  3304. this->GetType() != cmStateEnums::EXECUTABLE) {
  3305. outPrefix.clear();
  3306. outBase = this->GetName();
  3307. outSuffix.clear();
  3308. return;
  3309. }
  3310. const bool isImportedLibraryArtifact =
  3311. (artifact == cmStateEnums::ImportLibraryArtifact);
  3312. // Return an empty name for the import library if this platform
  3313. // does not support import libraries.
  3314. if (isImportedLibraryArtifact &&
  3315. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
  3316. outPrefix.clear();
  3317. outBase.clear();
  3318. outSuffix.clear();
  3319. return;
  3320. }
  3321. // The implib option is only allowed for shared libraries, module
  3322. // libraries, and executables.
  3323. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  3324. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  3325. this->GetType() != cmStateEnums::EXECUTABLE) {
  3326. artifact = cmStateEnums::RuntimeBinaryArtifact;
  3327. }
  3328. // Compute the full name for main target types.
  3329. const char* targetPrefix =
  3330. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_PREFIX")
  3331. : this->GetProperty("PREFIX"));
  3332. const char* targetSuffix =
  3333. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_SUFFIX")
  3334. : this->GetProperty("SUFFIX"));
  3335. const char* configPostfix = nullptr;
  3336. if (!config.empty()) {
  3337. std::string configProp = cmSystemTools::UpperCase(config);
  3338. configProp += "_POSTFIX";
  3339. configPostfix = this->GetProperty(configProp);
  3340. // Mac application bundles and frameworks have no postfix.
  3341. if (configPostfix &&
  3342. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple())) {
  3343. configPostfix = nullptr;
  3344. }
  3345. }
  3346. const char* prefixVar = this->Target->GetPrefixVariableInternal(artifact);
  3347. const char* suffixVar = this->Target->GetSuffixVariableInternal(artifact);
  3348. // Check for language-specific default prefix and suffix.
  3349. std::string ll = this->GetLinkerLanguage(config);
  3350. if (!ll.empty()) {
  3351. if (!targetSuffix && suffixVar && *suffixVar) {
  3352. std::string langSuff = suffixVar + std::string("_") + ll;
  3353. targetSuffix = this->Makefile->GetDefinition(langSuff);
  3354. }
  3355. if (!targetPrefix && prefixVar && *prefixVar) {
  3356. std::string langPrefix = prefixVar + std::string("_") + ll;
  3357. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  3358. }
  3359. }
  3360. // if there is no prefix on the target use the cmake definition
  3361. if (!targetPrefix && prefixVar) {
  3362. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar).c_str();
  3363. }
  3364. // if there is no suffix on the target use the cmake definition
  3365. if (!targetSuffix && suffixVar) {
  3366. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar).c_str();
  3367. }
  3368. // frameworks have directory prefix but no suffix
  3369. std::string fw_prefix;
  3370. if (this->IsFrameworkOnApple()) {
  3371. fw_prefix = this->GetFrameworkDirectory(config, ContentLevel);
  3372. fw_prefix += "/";
  3373. targetPrefix = fw_prefix.c_str();
  3374. targetSuffix = nullptr;
  3375. }
  3376. if (this->IsCFBundleOnApple()) {
  3377. fw_prefix = this->GetCFBundleDirectory(config, FullLevel);
  3378. fw_prefix += "/";
  3379. targetPrefix = fw_prefix.c_str();
  3380. targetSuffix = nullptr;
  3381. }
  3382. // Begin the final name with the prefix.
  3383. outPrefix = targetPrefix ? targetPrefix : "";
  3384. // Append the target name or property-specified name.
  3385. outBase += this->GetOutputName(config, artifact);
  3386. // Append the per-configuration postfix.
  3387. outBase += configPostfix ? configPostfix : "";
  3388. // Name shared libraries with their version number on some platforms.
  3389. if (const char* soversion = this->GetProperty("SOVERSION")) {
  3390. if (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
  3391. !isImportedLibraryArtifact &&
  3392. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION")) {
  3393. outBase += "-";
  3394. outBase += soversion;
  3395. }
  3396. }
  3397. // Append the suffix.
  3398. outSuffix = targetSuffix ? targetSuffix : "";
  3399. }
  3400. std::string cmGeneratorTarget::GetLinkerLanguage(
  3401. const std::string& config) const
  3402. {
  3403. return this->GetLinkClosure(config)->LinkerLanguage;
  3404. }
  3405. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  3406. {
  3407. std::string prefix;
  3408. std::string base;
  3409. std::string suffix;
  3410. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  3411. prefix, base, suffix);
  3412. std::vector<std::string> props;
  3413. std::string configUpper = cmSystemTools::UpperCase(config);
  3414. if (!configUpper.empty()) {
  3415. // PDB_NAME_<CONFIG>
  3416. props.push_back("PDB_NAME_" + configUpper);
  3417. }
  3418. // PDB_NAME
  3419. props.push_back("PDB_NAME");
  3420. for (std::string const& p : props) {
  3421. if (const char* outName = this->GetProperty(p)) {
  3422. base = outName;
  3423. break;
  3424. }
  3425. }
  3426. return prefix + base + ".pdb";
  3427. }
  3428. std::string cmGeneratorTarget::GetObjectDirectory(
  3429. std::string const& config) const
  3430. {
  3431. std::string obj_dir =
  3432. this->GlobalGenerator->ExpandCFGIntDir(this->ObjectDirectory, config);
  3433. #if defined(__APPLE__)
  3434. // find and replace $(PROJECT_NAME) xcode placeholder
  3435. const std::string projectName = this->LocalGenerator->GetProjectName();
  3436. cmSystemTools::ReplaceString(obj_dir, "$(PROJECT_NAME)", projectName);
  3437. #endif
  3438. return obj_dir;
  3439. }
  3440. void cmGeneratorTarget::GetTargetObjectNames(
  3441. std::string const& config, std::vector<std::string>& objects) const
  3442. {
  3443. std::vector<cmSourceFile const*> objectSources;
  3444. this->GetObjectSources(objectSources, config);
  3445. std::map<cmSourceFile const*, std::string> mapping;
  3446. for (cmSourceFile const* sf : objectSources) {
  3447. mapping[sf];
  3448. }
  3449. this->LocalGenerator->ComputeObjectFilenames(mapping, this);
  3450. for (cmSourceFile const* src : objectSources) {
  3451. // Find the object file name corresponding to this source file.
  3452. std::map<cmSourceFile const*, std::string>::const_iterator map_it =
  3453. mapping.find(src);
  3454. // It must exist because we populated the mapping just above.
  3455. assert(!map_it->second.empty());
  3456. objects.push_back(map_it->second);
  3457. }
  3458. }
  3459. bool cmGeneratorTarget::StrictTargetComparison::operator()(
  3460. cmGeneratorTarget const* t1, cmGeneratorTarget const* t2) const
  3461. {
  3462. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  3463. if (nameResult == 0) {
  3464. return strcmp(
  3465. t1->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str(),
  3466. t2->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str()) < 0;
  3467. }
  3468. return nameResult < 0;
  3469. }
  3470. struct cmGeneratorTarget::SourceFileFlags
  3471. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  3472. {
  3473. struct SourceFileFlags flags;
  3474. this->ConstructSourceFileFlags();
  3475. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  3476. this->SourceFlagsMap.find(sf);
  3477. if (si != this->SourceFlagsMap.end()) {
  3478. flags = si->second;
  3479. } else {
  3480. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  3481. // were not listed in one of the other lists.
  3482. if (const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION")) {
  3483. flags.MacFolder = location;
  3484. const bool stripResources =
  3485. this->GlobalGenerator->ShouldStripResourcePath(this->Makefile);
  3486. if (strcmp(location, "Resources") == 0) {
  3487. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  3488. if (stripResources) {
  3489. flags.MacFolder = "";
  3490. }
  3491. } else if (cmSystemTools::StringStartsWith(location, "Resources/")) {
  3492. flags.Type = cmGeneratorTarget::SourceFileTypeDeepResource;
  3493. if (stripResources) {
  3494. flags.MacFolder += strlen("Resources/");
  3495. }
  3496. } else {
  3497. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  3498. }
  3499. }
  3500. }
  3501. return flags;
  3502. }
  3503. void cmGeneratorTarget::ConstructSourceFileFlags() const
  3504. {
  3505. if (this->SourceFileFlagsConstructed) {
  3506. return;
  3507. }
  3508. this->SourceFileFlagsConstructed = true;
  3509. // Process public headers to mark the source files.
  3510. if (const char* files = this->GetProperty("PUBLIC_HEADER")) {
  3511. std::vector<std::string> relFiles;
  3512. cmSystemTools::ExpandListArgument(files, relFiles);
  3513. for (std::string const& relFile : relFiles) {
  3514. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  3515. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3516. flags.MacFolder = "Headers";
  3517. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  3518. }
  3519. }
  3520. }
  3521. // Process private headers after public headers so that they take
  3522. // precedence if a file is listed in both.
  3523. if (const char* files = this->GetProperty("PRIVATE_HEADER")) {
  3524. std::vector<std::string> relFiles;
  3525. cmSystemTools::ExpandListArgument(files, relFiles);
  3526. for (std::string const& relFile : relFiles) {
  3527. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  3528. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3529. flags.MacFolder = "PrivateHeaders";
  3530. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  3531. }
  3532. }
  3533. }
  3534. // Mark sources listed as resources.
  3535. if (const char* files = this->GetProperty("RESOURCE")) {
  3536. std::vector<std::string> relFiles;
  3537. cmSystemTools::ExpandListArgument(files, relFiles);
  3538. for (std::string const& relFile : relFiles) {
  3539. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  3540. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3541. flags.MacFolder = "";
  3542. if (!this->GlobalGenerator->ShouldStripResourcePath(this->Makefile)) {
  3543. flags.MacFolder = "Resources";
  3544. }
  3545. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  3546. }
  3547. }
  3548. }
  3549. }
  3550. const cmGeneratorTarget::CompatibleInterfacesBase&
  3551. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  3552. {
  3553. cmGeneratorTarget::CompatibleInterfaces& compat =
  3554. this->CompatibleInterfacesMap[config];
  3555. if (!compat.Done) {
  3556. compat.Done = true;
  3557. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  3558. compat.PropsString.insert("AUTOUIC_OPTIONS");
  3559. std::vector<cmGeneratorTarget const*> const& deps =
  3560. this->GetLinkImplementationClosure(config);
  3561. for (cmGeneratorTarget const* li : deps) {
  3562. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  3563. if (const char* prop = li->GetProperty("COMPATIBLE_INTERFACE_" #X)) { \
  3564. std::vector<std::string> props; \
  3565. cmSystemTools::ExpandListArgument(prop, props); \
  3566. compat.Props##x.insert(props.begin(), props.end()); \
  3567. }
  3568. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  3569. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  3570. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  3571. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  3572. #undef CM_READ_COMPATIBLE_INTERFACE
  3573. }
  3574. }
  3575. return compat;
  3576. }
  3577. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  3578. const std::string& p, const std::string& config) const
  3579. {
  3580. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3581. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3582. return false;
  3583. }
  3584. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  3585. }
  3586. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  3587. const std::string& p, const std::string& config) const
  3588. {
  3589. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3590. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3591. return false;
  3592. }
  3593. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  3594. }
  3595. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  3596. const std::string& p, const std::string& config) const
  3597. {
  3598. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3599. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3600. return false;
  3601. }
  3602. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  3603. }
  3604. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  3605. const std::string& p, const std::string& config) const
  3606. {
  3607. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3608. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3609. return false;
  3610. }
  3611. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  3612. }
  3613. enum CompatibleType
  3614. {
  3615. BoolType,
  3616. StringType,
  3617. NumberMinType,
  3618. NumberMaxType
  3619. };
  3620. template <typename PropertyType>
  3621. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3622. const std::string& prop,
  3623. const std::string& config,
  3624. CompatibleType, PropertyType*);
  3625. template <>
  3626. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3627. const std::string& prop,
  3628. const std::string& config,
  3629. CompatibleType /*unused*/,
  3630. bool* /*unused*/)
  3631. {
  3632. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  3633. }
  3634. template <>
  3635. const char* getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3636. const std::string& prop,
  3637. const std::string& config,
  3638. CompatibleType t,
  3639. const char** /*unused*/)
  3640. {
  3641. switch (t) {
  3642. case BoolType:
  3643. assert(false &&
  3644. "String compatibility check function called for boolean");
  3645. return nullptr;
  3646. case StringType:
  3647. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  3648. case NumberMinType:
  3649. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  3650. case NumberMaxType:
  3651. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  3652. }
  3653. assert(false && "Unreachable!");
  3654. return nullptr;
  3655. }
  3656. template <typename PropertyType>
  3657. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  3658. cmGeneratorTarget const* dependee,
  3659. const std::string& propName,
  3660. std::set<std::string>& emitted,
  3661. const std::string& config, CompatibleType t,
  3662. PropertyType* /*unused*/)
  3663. {
  3664. const char* prop = dependee->GetProperty(propName);
  3665. if (!prop) {
  3666. return;
  3667. }
  3668. std::vector<std::string> props;
  3669. cmSystemTools::ExpandListArgument(prop, props);
  3670. std::string pdir = cmSystemTools::GetCMakeRoot();
  3671. pdir += "/Help/prop_tgt/";
  3672. for (std::string const& p : props) {
  3673. std::string pname = cmSystemTools::HelpFileName(p);
  3674. std::string pfile = pdir + pname + ".rst";
  3675. if (cmSystemTools::FileExists(pfile, true)) {
  3676. std::ostringstream e;
  3677. e << "Target \"" << dependee->GetName() << "\" has property \"" << p
  3678. << "\" listed in its " << propName
  3679. << " property. "
  3680. "This is not allowed. Only user-defined properties may appear "
  3681. "listed in the "
  3682. << propName << " property.";
  3683. depender->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
  3684. e.str());
  3685. return;
  3686. }
  3687. if (emitted.insert(p).second) {
  3688. getLinkInterfaceDependentProperty<PropertyType>(depender, p, config, t,
  3689. nullptr);
  3690. if (cmSystemTools::GetErrorOccuredFlag()) {
  3691. return;
  3692. }
  3693. }
  3694. }
  3695. }
  3696. static std::string intersect(const std::set<std::string>& s1,
  3697. const std::set<std::string>& s2)
  3698. {
  3699. std::set<std::string> intersect;
  3700. std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(),
  3701. std::inserter(intersect, intersect.begin()));
  3702. if (!intersect.empty()) {
  3703. return *intersect.begin();
  3704. }
  3705. return "";
  3706. }
  3707. static std::string intersect(const std::set<std::string>& s1,
  3708. const std::set<std::string>& s2,
  3709. const std::set<std::string>& s3)
  3710. {
  3711. std::string result;
  3712. result = intersect(s1, s2);
  3713. if (!result.empty()) {
  3714. return result;
  3715. }
  3716. result = intersect(s1, s3);
  3717. if (!result.empty()) {
  3718. return result;
  3719. }
  3720. return intersect(s2, s3);
  3721. }
  3722. static std::string intersect(const std::set<std::string>& s1,
  3723. const std::set<std::string>& s2,
  3724. const std::set<std::string>& s3,
  3725. const std::set<std::string>& s4)
  3726. {
  3727. std::string result;
  3728. result = intersect(s1, s2);
  3729. if (!result.empty()) {
  3730. return result;
  3731. }
  3732. result = intersect(s1, s3);
  3733. if (!result.empty()) {
  3734. return result;
  3735. }
  3736. result = intersect(s1, s4);
  3737. if (!result.empty()) {
  3738. return result;
  3739. }
  3740. return intersect(s2, s3, s4);
  3741. }
  3742. void cmGeneratorTarget::CheckPropertyCompatibility(
  3743. cmComputeLinkInformation* info, const std::string& config) const
  3744. {
  3745. const cmComputeLinkInformation::ItemVector& deps = info->GetItems();
  3746. std::set<std::string> emittedBools;
  3747. static const std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  3748. std::set<std::string> emittedStrings;
  3749. static const std::string strString = "COMPATIBLE_INTERFACE_STRING";
  3750. std::set<std::string> emittedMinNumbers;
  3751. static const std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  3752. std::set<std::string> emittedMaxNumbers;
  3753. static const std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  3754. for (auto const& dep : deps) {
  3755. if (!dep.Target) {
  3756. continue;
  3757. }
  3758. checkPropertyConsistency<bool>(this, dep.Target, strBool, emittedBools,
  3759. config, BoolType, nullptr);
  3760. if (cmSystemTools::GetErrorOccuredFlag()) {
  3761. return;
  3762. }
  3763. checkPropertyConsistency<const char*>(this, dep.Target, strString,
  3764. emittedStrings, config, StringType,
  3765. nullptr);
  3766. if (cmSystemTools::GetErrorOccuredFlag()) {
  3767. return;
  3768. }
  3769. checkPropertyConsistency<const char*>(this, dep.Target, strNumMin,
  3770. emittedMinNumbers, config,
  3771. NumberMinType, nullptr);
  3772. if (cmSystemTools::GetErrorOccuredFlag()) {
  3773. return;
  3774. }
  3775. checkPropertyConsistency<const char*>(this, dep.Target, strNumMax,
  3776. emittedMaxNumbers, config,
  3777. NumberMaxType, nullptr);
  3778. if (cmSystemTools::GetErrorOccuredFlag()) {
  3779. return;
  3780. }
  3781. }
  3782. std::string prop = intersect(emittedBools, emittedStrings, emittedMinNumbers,
  3783. emittedMaxNumbers);
  3784. if (!prop.empty()) {
  3785. // Use a sorted std::vector to keep the error message sorted.
  3786. std::vector<std::string> props;
  3787. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  3788. if (i != emittedBools.end()) {
  3789. props.push_back(strBool);
  3790. }
  3791. i = emittedStrings.find(prop);
  3792. if (i != emittedStrings.end()) {
  3793. props.push_back(strString);
  3794. }
  3795. i = emittedMinNumbers.find(prop);
  3796. if (i != emittedMinNumbers.end()) {
  3797. props.push_back(strNumMin);
  3798. }
  3799. i = emittedMaxNumbers.find(prop);
  3800. if (i != emittedMaxNumbers.end()) {
  3801. props.push_back(strNumMax);
  3802. }
  3803. std::sort(props.begin(), props.end());
  3804. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  3805. propsString += " and the " + props.back();
  3806. std::ostringstream e;
  3807. e << "Property \"" << prop << "\" appears in both the " << propsString
  3808. << " property in the dependencies of target \"" << this->GetName()
  3809. << "\". This is not allowed. A property may only require compatibility "
  3810. "in a boolean interpretation, a numeric minimum, a numeric maximum "
  3811. "or a "
  3812. "string interpretation, but not a mixture.";
  3813. this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
  3814. }
  3815. }
  3816. template <typename PropertyType>
  3817. std::string valueAsString(PropertyType);
  3818. template <>
  3819. std::string valueAsString<bool>(bool value)
  3820. {
  3821. return value ? "TRUE" : "FALSE";
  3822. }
  3823. template <>
  3824. std::string valueAsString<const char*>(const char* value)
  3825. {
  3826. return value ? value : "(unset)";
  3827. }
  3828. template <>
  3829. std::string valueAsString<std::string>(std::string value)
  3830. {
  3831. return value;
  3832. }
  3833. template <>
  3834. std::string valueAsString<std::nullptr_t>(std::nullptr_t /*unused*/)
  3835. {
  3836. return "(unset)";
  3837. }
  3838. std::string compatibilityType(CompatibleType t)
  3839. {
  3840. switch (t) {
  3841. case BoolType:
  3842. return "Boolean compatibility";
  3843. case StringType:
  3844. return "String compatibility";
  3845. case NumberMaxType:
  3846. return "Numeric maximum compatibility";
  3847. case NumberMinType:
  3848. return "Numeric minimum compatibility";
  3849. }
  3850. assert(false && "Unreachable!");
  3851. return "";
  3852. }
  3853. std::string compatibilityAgree(CompatibleType t, bool dominant)
  3854. {
  3855. switch (t) {
  3856. case BoolType:
  3857. case StringType:
  3858. return dominant ? "(Disagree)\n" : "(Agree)\n";
  3859. case NumberMaxType:
  3860. case NumberMinType:
  3861. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  3862. }
  3863. assert(false && "Unreachable!");
  3864. return "";
  3865. }
  3866. template <typename PropertyType>
  3867. PropertyType getTypedProperty(
  3868. cmGeneratorTarget const* tgt, const std::string& prop,
  3869. cmGeneratorExpressionInterpreter* genexInterpreter = nullptr);
  3870. template <>
  3871. bool getTypedProperty<bool>(cmGeneratorTarget const* tgt,
  3872. const std::string& prop,
  3873. cmGeneratorExpressionInterpreter* genexInterpreter)
  3874. {
  3875. if (genexInterpreter == nullptr) {
  3876. return tgt->GetPropertyAsBool(prop);
  3877. }
  3878. const char* value = tgt->GetProperty(prop);
  3879. return cmSystemTools::IsOn(genexInterpreter->Evaluate(value, prop));
  3880. }
  3881. template <>
  3882. const char* getTypedProperty<const char*>(
  3883. cmGeneratorTarget const* tgt, const std::string& prop,
  3884. cmGeneratorExpressionInterpreter* genexInterpreter)
  3885. {
  3886. const char* value = tgt->GetProperty(prop);
  3887. if (genexInterpreter == nullptr) {
  3888. return value;
  3889. }
  3890. return genexInterpreter->Evaluate(value, prop).c_str();
  3891. }
  3892. template <>
  3893. std::string getTypedProperty<std::string>(
  3894. cmGeneratorTarget const* tgt, const std::string& prop,
  3895. cmGeneratorExpressionInterpreter* genexInterpreter)
  3896. {
  3897. const char* value = tgt->GetProperty(prop);
  3898. if (genexInterpreter == nullptr) {
  3899. return valueAsString(value);
  3900. }
  3901. return genexInterpreter->Evaluate(value, prop);
  3902. }
  3903. template <typename PropertyType>
  3904. PropertyType impliedValue(PropertyType);
  3905. template <>
  3906. bool impliedValue<bool>(bool /*unused*/)
  3907. {
  3908. return false;
  3909. }
  3910. template <>
  3911. const char* impliedValue<const char*>(const char* /*unused*/)
  3912. {
  3913. return "";
  3914. }
  3915. template <>
  3916. std::string impliedValue<std::string>(std::string /*unused*/) // NOLINT(*)
  3917. {
  3918. return std::string();
  3919. }
  3920. template <typename PropertyType>
  3921. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  3922. PropertyType rhs,
  3923. CompatibleType t);
  3924. template <>
  3925. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  3926. CompatibleType /*unused*/)
  3927. {
  3928. return std::make_pair(lhs == rhs, lhs);
  3929. }
  3930. std::pair<bool, const char*> consistentStringProperty(const char* lhs,
  3931. const char* rhs)
  3932. {
  3933. const bool b = strcmp(lhs, rhs) == 0;
  3934. return std::make_pair(b, b ? lhs : nullptr);
  3935. }
  3936. std::pair<bool, std::string> consistentStringProperty(const std::string& lhs,
  3937. const std::string& rhs)
  3938. {
  3939. const bool b = lhs == rhs;
  3940. return std::make_pair(b, b ? lhs : valueAsString(nullptr));
  3941. }
  3942. std::pair<bool, const char*> consistentNumberProperty(const char* lhs,
  3943. const char* rhs,
  3944. CompatibleType t)
  3945. {
  3946. char* pEnd;
  3947. const char* const null_ptr = nullptr;
  3948. long lnum = strtol(lhs, &pEnd, 0);
  3949. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) {
  3950. return std::pair<bool, const char*>(false, null_ptr);
  3951. }
  3952. long rnum = strtol(rhs, &pEnd, 0);
  3953. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) {
  3954. return std::pair<bool, const char*>(false, null_ptr);
  3955. }
  3956. if (t == NumberMaxType) {
  3957. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  3958. }
  3959. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  3960. }
  3961. template <>
  3962. std::pair<bool, const char*> consistentProperty(const char* lhs,
  3963. const char* rhs,
  3964. CompatibleType t)
  3965. {
  3966. if (!lhs && !rhs) {
  3967. return std::make_pair(true, lhs);
  3968. }
  3969. if (!lhs) {
  3970. return std::make_pair(true, rhs);
  3971. }
  3972. if (!rhs) {
  3973. return std::make_pair(true, lhs);
  3974. }
  3975. const char* const null_ptr = nullptr;
  3976. switch (t) {
  3977. case BoolType: {
  3978. bool same = cmSystemTools::IsOn(lhs) == cmSystemTools::IsOn(rhs);
  3979. return std::make_pair(same, same ? lhs : nullptr);
  3980. }
  3981. case StringType:
  3982. return consistentStringProperty(lhs, rhs);
  3983. case NumberMinType:
  3984. case NumberMaxType:
  3985. return consistentNumberProperty(lhs, rhs, t);
  3986. }
  3987. assert(false && "Unreachable!");
  3988. return std::pair<bool, const char*>(false, null_ptr);
  3989. }
  3990. std::pair<bool, std::string> consistentProperty(const std::string& lhs,
  3991. const std::string& rhs,
  3992. CompatibleType t)
  3993. {
  3994. const std::string null_ptr = valueAsString(nullptr);
  3995. if (lhs == null_ptr && rhs == null_ptr) {
  3996. return std::make_pair(true, lhs);
  3997. }
  3998. if (lhs == null_ptr) {
  3999. return std::make_pair(true, rhs);
  4000. }
  4001. if (rhs == null_ptr) {
  4002. return std::make_pair(true, lhs);
  4003. }
  4004. switch (t) {
  4005. case BoolType: {
  4006. bool same = cmSystemTools::IsOn(lhs) == cmSystemTools::IsOn(rhs);
  4007. return std::make_pair(same, same ? lhs : null_ptr);
  4008. }
  4009. case StringType:
  4010. return consistentStringProperty(lhs, rhs);
  4011. case NumberMinType:
  4012. case NumberMaxType: {
  4013. auto value = consistentNumberProperty(lhs.c_str(), rhs.c_str(), t);
  4014. return std::make_pair(
  4015. value.first, value.first ? std::string(value.second) : null_ptr);
  4016. }
  4017. }
  4018. assert(false && "Unreachable!");
  4019. return std::pair<bool, std::string>(false, null_ptr);
  4020. }
  4021. template <typename PropertyType>
  4022. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  4023. const std::string& p,
  4024. const std::string& config,
  4025. const char* defaultValue,
  4026. CompatibleType t,
  4027. PropertyType* /*unused*/)
  4028. {
  4029. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
  4030. std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
  4031. const bool explicitlySet =
  4032. std::find(headPropKeys.begin(), headPropKeys.end(), p) !=
  4033. headPropKeys.end();
  4034. const bool impliedByUse = tgt->IsNullImpliedByLinkLibraries(p);
  4035. assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet));
  4036. std::vector<cmGeneratorTarget const*> const& deps =
  4037. tgt->GetLinkImplementationClosure(config);
  4038. if (deps.empty()) {
  4039. return propContent;
  4040. }
  4041. bool propInitialized = explicitlySet;
  4042. std::string report = " * Target \"";
  4043. report += tgt->GetName();
  4044. if (explicitlySet) {
  4045. report += "\" has property content \"";
  4046. report += valueAsString<PropertyType>(propContent);
  4047. report += "\"\n";
  4048. } else if (impliedByUse) {
  4049. report += "\" property is implied by use.\n";
  4050. } else {
  4051. report += "\" property not set.\n";
  4052. }
  4053. std::string interfaceProperty = "INTERFACE_" + p;
  4054. std::unique_ptr<cmGeneratorExpressionInterpreter> genexInterpreter(
  4055. p == "POSITION_INDEPENDENT_CODE" ? new cmGeneratorExpressionInterpreter(
  4056. tgt->GetLocalGenerator(), config, tgt)
  4057. : nullptr);
  4058. for (cmGeneratorTarget const* theTarget : deps) {
  4059. // An error should be reported if one dependency
  4060. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  4061. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  4062. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  4063. // with a dependency.
  4064. std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
  4065. const bool ifaceIsSet = std::find(propKeys.begin(), propKeys.end(),
  4066. interfaceProperty) != propKeys.end();
  4067. PropertyType ifacePropContent = getTypedProperty<PropertyType>(
  4068. theTarget, interfaceProperty, genexInterpreter.get());
  4069. std::string reportEntry;
  4070. if (ifaceIsSet) {
  4071. reportEntry += " * Target \"";
  4072. reportEntry += theTarget->GetName();
  4073. reportEntry += "\" property value \"";
  4074. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  4075. reportEntry += "\" ";
  4076. }
  4077. if (explicitlySet) {
  4078. if (ifaceIsSet) {
  4079. std::pair<bool, PropertyType> consistent =
  4080. consistentProperty(propContent, ifacePropContent, t);
  4081. report += reportEntry;
  4082. report += compatibilityAgree(t, propContent != consistent.second);
  4083. if (!consistent.first) {
  4084. std::ostringstream e;
  4085. e << "Property " << p << " on target \"" << tgt->GetName()
  4086. << "\" does\nnot match the "
  4087. "INTERFACE_"
  4088. << p
  4089. << " property requirement\nof "
  4090. "dependency \""
  4091. << theTarget->GetName() << "\".\n";
  4092. cmSystemTools::Error(e.str().c_str());
  4093. break;
  4094. }
  4095. propContent = consistent.second;
  4096. continue;
  4097. }
  4098. // Explicitly set on target and not set in iface. Can't disagree.
  4099. continue;
  4100. }
  4101. if (impliedByUse) {
  4102. propContent = impliedValue<PropertyType>(propContent);
  4103. if (ifaceIsSet) {
  4104. std::pair<bool, PropertyType> consistent =
  4105. consistentProperty(propContent, ifacePropContent, t);
  4106. report += reportEntry;
  4107. report += compatibilityAgree(t, propContent != consistent.second);
  4108. if (!consistent.first) {
  4109. std::ostringstream e;
  4110. e << "Property " << p << " on target \"" << tgt->GetName()
  4111. << "\" is\nimplied to be " << defaultValue
  4112. << " because it was used to determine the link libraries\n"
  4113. "already. The INTERFACE_"
  4114. << p << " property on\ndependency \"" << theTarget->GetName()
  4115. << "\" is in conflict.\n";
  4116. cmSystemTools::Error(e.str().c_str());
  4117. break;
  4118. }
  4119. propContent = consistent.second;
  4120. continue;
  4121. }
  4122. // Implicitly set on target and not set in iface. Can't disagree.
  4123. continue;
  4124. }
  4125. if (ifaceIsSet) {
  4126. if (propInitialized) {
  4127. std::pair<bool, PropertyType> consistent =
  4128. consistentProperty(propContent, ifacePropContent, t);
  4129. report += reportEntry;
  4130. report += compatibilityAgree(t, propContent != consistent.second);
  4131. if (!consistent.first) {
  4132. std::ostringstream e;
  4133. e << "The INTERFACE_" << p << " property of \""
  4134. << theTarget->GetName() << "\" does\nnot agree with the value of "
  4135. << p << " already determined\nfor \"" << tgt->GetName() << "\".\n";
  4136. cmSystemTools::Error(e.str().c_str());
  4137. break;
  4138. }
  4139. propContent = consistent.second;
  4140. continue;
  4141. }
  4142. report += reportEntry + "(Interface set)\n";
  4143. propContent = ifacePropContent;
  4144. propInitialized = true;
  4145. } else {
  4146. // Not set. Nothing to agree on.
  4147. continue;
  4148. }
  4149. }
  4150. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  4151. report, compatibilityType(t));
  4152. return propContent;
  4153. }
  4154. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  4155. const std::string& p, const std::string& config) const
  4156. {
  4157. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  4158. BoolType, nullptr);
  4159. }
  4160. std::string cmGeneratorTarget::GetLinkInterfaceDependentStringAsBoolProperty(
  4161. const std::string& p, const std::string& config) const
  4162. {
  4163. return checkInterfacePropertyCompatibility<std::string>(
  4164. this, p, config, "FALSE", BoolType, nullptr);
  4165. }
  4166. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  4167. const std::string& p, const std::string& config) const
  4168. {
  4169. return checkInterfacePropertyCompatibility<const char*>(
  4170. this, p, config, "empty", StringType, nullptr);
  4171. }
  4172. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  4173. const std::string& p, const std::string& config) const
  4174. {
  4175. return checkInterfacePropertyCompatibility<const char*>(
  4176. this, p, config, "empty", NumberMinType, nullptr);
  4177. }
  4178. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  4179. const std::string& p, const std::string& config) const
  4180. {
  4181. return checkInterfacePropertyCompatibility<const char*>(
  4182. this, p, config, "empty", NumberMaxType, nullptr);
  4183. }
  4184. cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
  4185. const std::string& config) const
  4186. {
  4187. // Lookup any existing information for this configuration.
  4188. std::string key(cmSystemTools::UpperCase(config));
  4189. cmTargetLinkInformationMap::iterator i = this->LinkInformation.find(key);
  4190. if (i == this->LinkInformation.end()) {
  4191. // Compute information for this configuration.
  4192. cmComputeLinkInformation* info =
  4193. new cmComputeLinkInformation(this, config);
  4194. if (!info || !info->Compute()) {
  4195. delete info;
  4196. info = nullptr;
  4197. }
  4198. // Store the information for this configuration.
  4199. cmTargetLinkInformationMap::value_type entry(key, info);
  4200. i = this->LinkInformation.insert(entry).first;
  4201. if (info) {
  4202. this->CheckPropertyCompatibility(info, config);
  4203. }
  4204. }
  4205. return i->second;
  4206. }
  4207. void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
  4208. {
  4209. int patch;
  4210. this->GetTargetVersion(false, major, minor, patch);
  4211. }
  4212. void cmGeneratorTarget::GetTargetVersion(bool soversion, int& major,
  4213. int& minor, int& patch) const
  4214. {
  4215. // Set the default values.
  4216. major = 0;
  4217. minor = 0;
  4218. patch = 0;
  4219. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  4220. // Look for a VERSION or SOVERSION property.
  4221. const char* prop = soversion ? "SOVERSION" : "VERSION";
  4222. if (const char* version = this->GetProperty(prop)) {
  4223. // Try to parse the version number and store the results that were
  4224. // successfully parsed.
  4225. int parsed_major;
  4226. int parsed_minor;
  4227. int parsed_patch;
  4228. switch (sscanf(version, "%d.%d.%d", &parsed_major, &parsed_minor,
  4229. &parsed_patch)) {
  4230. case 3:
  4231. patch = parsed_patch;
  4232. CM_FALLTHROUGH;
  4233. case 2:
  4234. minor = parsed_minor;
  4235. CM_FALLTHROUGH;
  4236. case 1:
  4237. major = parsed_major;
  4238. CM_FALLTHROUGH;
  4239. default:
  4240. break;
  4241. }
  4242. }
  4243. }
  4244. std::string cmGeneratorTarget::GetFortranModuleDirectory(
  4245. std::string const& working_dir) const
  4246. {
  4247. if (!this->FortranModuleDirectoryCreated) {
  4248. this->FortranModuleDirectory =
  4249. this->CreateFortranModuleDirectory(working_dir);
  4250. this->FortranModuleDirectoryCreated = true;
  4251. }
  4252. return this->FortranModuleDirectory;
  4253. }
  4254. std::string cmGeneratorTarget::CreateFortranModuleDirectory(
  4255. std::string const& working_dir) const
  4256. {
  4257. std::string mod_dir;
  4258. std::string target_mod_dir;
  4259. if (const char* prop = this->GetProperty("Fortran_MODULE_DIRECTORY")) {
  4260. target_mod_dir = prop;
  4261. } else {
  4262. std::string const& default_mod_dir =
  4263. this->LocalGenerator->GetCurrentBinaryDirectory();
  4264. if (default_mod_dir != working_dir) {
  4265. target_mod_dir = default_mod_dir;
  4266. }
  4267. }
  4268. const char* moddir_flag =
  4269. this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
  4270. if (!target_mod_dir.empty() && moddir_flag) {
  4271. // Compute the full path to the module directory.
  4272. if (cmSystemTools::FileIsFullPath(target_mod_dir)) {
  4273. // Already a full path.
  4274. mod_dir = target_mod_dir;
  4275. } else {
  4276. // Interpret relative to the current output directory.
  4277. mod_dir = this->LocalGenerator->GetCurrentBinaryDirectory();
  4278. mod_dir += "/";
  4279. mod_dir += target_mod_dir;
  4280. }
  4281. // Make sure the module output directory exists.
  4282. cmSystemTools::MakeDirectory(mod_dir);
  4283. }
  4284. return mod_dir;
  4285. }
  4286. std::string cmGeneratorTarget::GetFrameworkVersion() const
  4287. {
  4288. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  4289. if (const char* fversion = this->GetProperty("FRAMEWORK_VERSION")) {
  4290. return fversion;
  4291. }
  4292. if (const char* tversion = this->GetProperty("VERSION")) {
  4293. return tversion;
  4294. }
  4295. return "A";
  4296. }
  4297. void cmGeneratorTarget::ComputeVersionedName(std::string& vName,
  4298. std::string const& prefix,
  4299. std::string const& base,
  4300. std::string const& suffix,
  4301. std::string const& name,
  4302. const char* version) const
  4303. {
  4304. vName = this->Makefile->IsOn("APPLE") ? (prefix + base) : name;
  4305. if (version) {
  4306. vName += ".";
  4307. vName += version;
  4308. }
  4309. vName += this->Makefile->IsOn("APPLE") ? suffix : std::string();
  4310. }
  4311. std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const
  4312. {
  4313. cmPropertyMap const& propsObject = this->Target->GetProperties();
  4314. std::vector<std::string> props;
  4315. props.reserve(propsObject.size());
  4316. for (auto const& it : propsObject) {
  4317. props.push_back(it.first);
  4318. }
  4319. return props;
  4320. }
  4321. void cmGeneratorTarget::ReportPropertyOrigin(
  4322. const std::string& p, const std::string& result, const std::string& report,
  4323. const std::string& compatibilityType) const
  4324. {
  4325. std::vector<std::string> debugProperties;
  4326. const char* debugProp = this->Target->GetMakefile()->GetDefinition(
  4327. "CMAKE_DEBUG_TARGET_PROPERTIES");
  4328. if (debugProp) {
  4329. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  4330. }
  4331. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] &&
  4332. std::find(debugProperties.begin(), debugProperties.end(), p) !=
  4333. debugProperties.end();
  4334. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  4335. this->DebugCompatiblePropertiesDone[p] = true;
  4336. }
  4337. if (!debugOrigin) {
  4338. return;
  4339. }
  4340. std::string areport = compatibilityType;
  4341. areport += std::string(" of property \"") + p + "\" for target \"";
  4342. areport += std::string(this->GetName());
  4343. areport += "\" (result: \"";
  4344. areport += result;
  4345. areport += "\"):\n" + report;
  4346. this->LocalGenerator->GetCMakeInstance()->IssueMessage(MessageType::LOG,
  4347. areport);
  4348. }
  4349. void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
  4350. cmListFileBacktrace const& bt,
  4351. std::vector<cmLinkItem>& items) const
  4352. {
  4353. for (std::string const& n : names) {
  4354. std::string name = this->CheckCMP0004(n);
  4355. if (name == this->GetName() || name.empty()) {
  4356. continue;
  4357. }
  4358. items.push_back(this->ResolveLinkItem(name, bt));
  4359. }
  4360. }
  4361. void cmGeneratorTarget::ExpandLinkItems(
  4362. std::string const& prop, std::string const& value, std::string const& config,
  4363. cmGeneratorTarget const* headTarget, bool usage_requirements_only,
  4364. std::vector<cmLinkItem>& items, bool& hadHeadSensitiveCondition) const
  4365. {
  4366. cmGeneratorExpression ge;
  4367. cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr);
  4368. // The $<LINK_ONLY> expression may be in a link interface to specify private
  4369. // link dependencies that are otherwise excluded from usage requirements.
  4370. if (usage_requirements_only) {
  4371. dagChecker.SetTransitivePropertiesOnly();
  4372. }
  4373. std::vector<std::string> libs;
  4374. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  4375. cmSystemTools::ExpandListArgument(cge->Evaluate(this->LocalGenerator, config,
  4376. false, headTarget, this,
  4377. &dagChecker),
  4378. libs);
  4379. this->LookupLinkItems(libs, cge->GetBacktrace(), items);
  4380. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  4381. }
  4382. cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
  4383. const std::string& config, cmGeneratorTarget const* head) const
  4384. {
  4385. // Imported targets have their own link interface.
  4386. if (this->IsImported()) {
  4387. return this->GetImportLinkInterface(config, head, false);
  4388. }
  4389. // Link interfaces are not supported for executables that do not
  4390. // export symbols.
  4391. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  4392. !this->IsExecutableWithExports()) {
  4393. return nullptr;
  4394. }
  4395. // Lookup any existing link interface for this configuration.
  4396. cmHeadToLinkInterfaceMap& hm = this->GetHeadToLinkInterfaceMap(config);
  4397. // If the link interface does not depend on the head target
  4398. // then return the one we computed first.
  4399. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  4400. return &hm.begin()->second;
  4401. }
  4402. cmOptionalLinkInterface& iface = hm[head];
  4403. if (!iface.LibrariesDone) {
  4404. iface.LibrariesDone = true;
  4405. this->ComputeLinkInterfaceLibraries(config, iface, head, false);
  4406. }
  4407. if (!iface.AllDone) {
  4408. iface.AllDone = true;
  4409. if (iface.Exists) {
  4410. this->ComputeLinkInterface(config, iface, head);
  4411. }
  4412. }
  4413. return iface.Exists ? &iface : nullptr;
  4414. }
  4415. void cmGeneratorTarget::ComputeLinkInterface(
  4416. const std::string& config, cmOptionalLinkInterface& iface,
  4417. cmGeneratorTarget const* headTarget) const
  4418. {
  4419. if (iface.ExplicitLibraries) {
  4420. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4421. this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  4422. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4423. // Shared libraries may have runtime implementation dependencies
  4424. // on other shared libraries that are not in the interface.
  4425. std::set<cmLinkItem> emitted;
  4426. for (cmLinkItem const& lib : iface.Libraries) {
  4427. emitted.insert(lib);
  4428. }
  4429. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  4430. cmLinkImplementation const* impl = this->GetLinkImplementation(config);
  4431. for (cmLinkImplItem const& lib : impl->Libraries) {
  4432. if (emitted.insert(lib).second) {
  4433. if (lib.Target) {
  4434. // This is a runtime dependency on another shared library.
  4435. if (lib.Target->GetType() == cmStateEnums::SHARED_LIBRARY) {
  4436. iface.SharedDeps.push_back(lib);
  4437. }
  4438. } else {
  4439. // TODO: Recognize shared library file names. Perhaps this
  4440. // should be moved to cmComputeLinkInformation, but that creates
  4441. // a chicken-and-egg problem since this list is needed for its
  4442. // construction.
  4443. }
  4444. }
  4445. }
  4446. }
  4447. }
  4448. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  4449. this->GetPolicyStatusCMP0022() == cmPolicies::OLD) {
  4450. // The link implementation is the default link interface.
  4451. cmLinkImplementationLibraries const* impl =
  4452. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  4453. iface.ImplementationIsInterface = true;
  4454. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  4455. }
  4456. if (this->LinkLanguagePropagatesToDependents()) {
  4457. // Targets using this archive need its language runtime libraries.
  4458. if (cmLinkImplementation const* impl =
  4459. this->GetLinkImplementation(config)) {
  4460. iface.Languages = impl->Languages;
  4461. }
  4462. }
  4463. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  4464. // Construct the property name suffix for this configuration.
  4465. std::string suffix = "_";
  4466. if (!config.empty()) {
  4467. suffix += cmSystemTools::UpperCase(config);
  4468. } else {
  4469. suffix += "NOCONFIG";
  4470. }
  4471. // How many repetitions are needed if this library has cyclic
  4472. // dependencies?
  4473. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4474. propName += suffix;
  4475. if (const char* config_reps = this->GetProperty(propName)) {
  4476. sscanf(config_reps, "%u", &iface.Multiplicity);
  4477. } else if (const char* reps =
  4478. this->GetProperty("LINK_INTERFACE_MULTIPLICITY")) {
  4479. sscanf(reps, "%u", &iface.Multiplicity);
  4480. }
  4481. }
  4482. }
  4483. const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
  4484. const std::string& config, cmGeneratorTarget const* head,
  4485. bool usage_requirements_only) const
  4486. {
  4487. // Imported targets have their own link interface.
  4488. if (this->IsImported()) {
  4489. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  4490. }
  4491. // Link interfaces are not supported for executables that do not
  4492. // export symbols.
  4493. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  4494. !this->IsExecutableWithExports()) {
  4495. return nullptr;
  4496. }
  4497. // Lookup any existing link interface for this configuration.
  4498. std::string CONFIG = cmSystemTools::UpperCase(config);
  4499. cmHeadToLinkInterfaceMap& hm =
  4500. (usage_requirements_only
  4501. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  4502. : this->GetHeadToLinkInterfaceMap(config));
  4503. // If the link interface does not depend on the head target
  4504. // then return the one we computed first.
  4505. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  4506. return &hm.begin()->second;
  4507. }
  4508. cmOptionalLinkInterface& iface = hm[head];
  4509. if (!iface.LibrariesDone) {
  4510. iface.LibrariesDone = true;
  4511. this->ComputeLinkInterfaceLibraries(config, iface, head,
  4512. usage_requirements_only);
  4513. }
  4514. return iface.Exists ? &iface : nullptr;
  4515. }
  4516. std::string cmGeneratorTarget::GetDirectory(
  4517. const std::string& config, cmStateEnums::ArtifactType artifact) const
  4518. {
  4519. if (this->IsImported()) {
  4520. // Return the directory from which the target is imported.
  4521. return cmSystemTools::GetFilenamePath(
  4522. this->Target->ImportedGetFullPath(config, artifact));
  4523. }
  4524. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  4525. // Return the directory in which the target will be built.
  4526. switch (artifact) {
  4527. case cmStateEnums::RuntimeBinaryArtifact:
  4528. return info->OutDir;
  4529. case cmStateEnums::ImportLibraryArtifact:
  4530. return info->ImpDir;
  4531. }
  4532. }
  4533. return "";
  4534. }
  4535. bool cmGeneratorTarget::UsesDefaultOutputDir(
  4536. const std::string& config, cmStateEnums::ArtifactType artifact) const
  4537. {
  4538. std::string dir;
  4539. return this->ComputeOutputDir(config, artifact, dir);
  4540. }
  4541. cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
  4542. const std::string& config) const
  4543. {
  4544. // There is no output information for imported targets.
  4545. if (this->IsImported()) {
  4546. return nullptr;
  4547. }
  4548. // Only libraries and executables have well-defined output files.
  4549. if (!this->HaveWellDefinedOutputFiles()) {
  4550. std::string msg = "cmGeneratorTarget::GetOutputInfo called for ";
  4551. msg += this->GetName();
  4552. msg += " which has type ";
  4553. msg += cmState::GetTargetTypeName(this->GetType());
  4554. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  4555. return nullptr;
  4556. }
  4557. // Lookup/compute/cache the output information for this configuration.
  4558. std::string config_upper;
  4559. if (!config.empty()) {
  4560. config_upper = cmSystemTools::UpperCase(config);
  4561. }
  4562. OutputInfoMapType::iterator i = this->OutputInfoMap.find(config_upper);
  4563. if (i == this->OutputInfoMap.end()) {
  4564. // Add empty info in map to detect potential recursion.
  4565. OutputInfo info;
  4566. OutputInfoMapType::value_type entry(config_upper, info);
  4567. i = this->OutputInfoMap.insert(entry).first;
  4568. // Compute output directories.
  4569. this->ComputeOutputDir(config, cmStateEnums::RuntimeBinaryArtifact,
  4570. info.OutDir);
  4571. this->ComputeOutputDir(config, cmStateEnums::ImportLibraryArtifact,
  4572. info.ImpDir);
  4573. if (!this->ComputePDBOutputDir("PDB", config, info.PdbDir)) {
  4574. info.PdbDir = info.OutDir;
  4575. }
  4576. // Now update the previously-prepared map entry.
  4577. i->second = info;
  4578. } else if (i->second.empty()) {
  4579. // An empty map entry indicates we have been called recursively
  4580. // from the above block.
  4581. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  4582. MessageType::FATAL_ERROR,
  4583. "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
  4584. this->GetBacktrace());
  4585. return nullptr;
  4586. }
  4587. return &i->second;
  4588. }
  4589. bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
  4590. cmStateEnums::ArtifactType artifact,
  4591. std::string& out) const
  4592. {
  4593. bool usesDefaultOutputDir = false;
  4594. std::string conf = config;
  4595. // Look for a target property defining the target output directory
  4596. // based on the target type.
  4597. std::string targetTypeName = this->GetOutputTargetType(artifact);
  4598. const char* propertyName = nullptr;
  4599. std::string propertyNameStr = targetTypeName;
  4600. if (!propertyNameStr.empty()) {
  4601. propertyNameStr += "_OUTPUT_DIRECTORY";
  4602. propertyName = propertyNameStr.c_str();
  4603. }
  4604. // Check for a per-configuration output directory target property.
  4605. std::string configUpper = cmSystemTools::UpperCase(conf);
  4606. const char* configProp = nullptr;
  4607. std::string configPropStr = targetTypeName;
  4608. if (!configPropStr.empty()) {
  4609. configPropStr += "_OUTPUT_DIRECTORY_";
  4610. configPropStr += configUpper;
  4611. configProp = configPropStr.c_str();
  4612. }
  4613. // Select an output directory.
  4614. if (const char* config_outdir = this->GetProperty(configProp)) {
  4615. // Use the user-specified per-configuration output directory.
  4616. cmGeneratorExpression ge;
  4617. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  4618. ge.Parse(config_outdir);
  4619. out = cge->Evaluate(this->LocalGenerator, config);
  4620. // Skip per-configuration subdirectory.
  4621. conf.clear();
  4622. } else if (const char* outdir = this->GetProperty(propertyName)) {
  4623. // Use the user-specified output directory.
  4624. cmGeneratorExpression ge;
  4625. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outdir);
  4626. out = cge->Evaluate(this->LocalGenerator, config);
  4627. // Skip per-configuration subdirectory if the value contained a
  4628. // generator expression.
  4629. if (out != outdir) {
  4630. conf.clear();
  4631. }
  4632. } else if (this->GetType() == cmStateEnums::EXECUTABLE) {
  4633. // Lookup the output path for executables.
  4634. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  4635. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  4636. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4637. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  4638. // Lookup the output path for libraries.
  4639. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  4640. }
  4641. if (out.empty()) {
  4642. // Default to the current output directory.
  4643. usesDefaultOutputDir = true;
  4644. out = ".";
  4645. }
  4646. // Convert the output path to a full path in case it is
  4647. // specified as a relative path. Treat a relative path as
  4648. // relative to the current output directory for this makefile.
  4649. out = (cmSystemTools::CollapseFullPath(
  4650. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  4651. // The generator may add the configuration's subdirectory.
  4652. if (!conf.empty()) {
  4653. bool useEPN =
  4654. this->GlobalGenerator->UseEffectivePlatformName(this->Makefile);
  4655. std::string suffix =
  4656. usesDefaultOutputDir && useEPN ? "${EFFECTIVE_PLATFORM_NAME}" : "";
  4657. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  4658. "/", conf, suffix, out);
  4659. }
  4660. return usesDefaultOutputDir;
  4661. }
  4662. bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
  4663. const std::string& config,
  4664. std::string& out) const
  4665. {
  4666. // Look for a target property defining the target output directory
  4667. // based on the target type.
  4668. const char* propertyName = nullptr;
  4669. std::string propertyNameStr = kind;
  4670. if (!propertyNameStr.empty()) {
  4671. propertyNameStr += "_OUTPUT_DIRECTORY";
  4672. propertyName = propertyNameStr.c_str();
  4673. }
  4674. std::string conf = config;
  4675. // Check for a per-configuration output directory target property.
  4676. std::string configUpper = cmSystemTools::UpperCase(conf);
  4677. const char* configProp = nullptr;
  4678. std::string configPropStr = kind;
  4679. if (!configPropStr.empty()) {
  4680. configPropStr += "_OUTPUT_DIRECTORY_";
  4681. configPropStr += configUpper;
  4682. configProp = configPropStr.c_str();
  4683. }
  4684. // Select an output directory.
  4685. if (const char* config_outdir = this->GetProperty(configProp)) {
  4686. // Use the user-specified per-configuration output directory.
  4687. cmGeneratorExpression ge;
  4688. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  4689. ge.Parse(config_outdir);
  4690. out = cge->Evaluate(this->LocalGenerator, config);
  4691. // Skip per-configuration subdirectory.
  4692. conf.clear();
  4693. } else if (const char* outdir = this->GetProperty(propertyName)) {
  4694. // Use the user-specified output directory.
  4695. cmGeneratorExpression ge;
  4696. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outdir);
  4697. out = cge->Evaluate(this->LocalGenerator, config);
  4698. // Skip per-configuration subdirectory if the value contained a
  4699. // generator expression.
  4700. if (out != outdir) {
  4701. conf.clear();
  4702. }
  4703. }
  4704. if (out.empty()) {
  4705. return false;
  4706. }
  4707. // Convert the output path to a full path in case it is
  4708. // specified as a relative path. Treat a relative path as
  4709. // relative to the current output directory for this makefile.
  4710. out = (cmSystemTools::CollapseFullPath(
  4711. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  4712. // The generator may add the configuration's subdirectory.
  4713. if (!conf.empty()) {
  4714. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  4715. "/", conf, "", out);
  4716. }
  4717. return true;
  4718. }
  4719. bool cmGeneratorTarget::HaveInstallTreeRPATH() const
  4720. {
  4721. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  4722. return (install_rpath && *install_rpath) &&
  4723. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  4724. }
  4725. void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  4726. const std::string& config, cmOptionalLinkInterface& iface,
  4727. cmGeneratorTarget const* headTarget, bool usage_requirements_only) const
  4728. {
  4729. // Construct the property name suffix for this configuration.
  4730. std::string suffix = "_";
  4731. if (!config.empty()) {
  4732. suffix += cmSystemTools::UpperCase(config);
  4733. } else {
  4734. suffix += "NOCONFIG";
  4735. }
  4736. // An explicit list of interface libraries may be set for shared
  4737. // libraries and executables that export symbols.
  4738. const char* explicitLibraries = nullptr;
  4739. std::string linkIfaceProp;
  4740. if (this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  4741. this->GetPolicyStatusCMP0022() != cmPolicies::WARN) {
  4742. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  4743. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  4744. explicitLibraries = this->GetProperty(linkIfaceProp);
  4745. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4746. this->IsExecutableWithExports()) {
  4747. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  4748. // shared lib or executable.
  4749. // Lookup the per-configuration property.
  4750. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4751. linkIfaceProp += suffix;
  4752. explicitLibraries = this->GetProperty(linkIfaceProp);
  4753. // If not set, try the generic property.
  4754. if (!explicitLibraries) {
  4755. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4756. explicitLibraries = this->GetProperty(linkIfaceProp);
  4757. }
  4758. }
  4759. if (explicitLibraries &&
  4760. this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4761. !this->PolicyWarnedCMP0022) {
  4762. // Compare the explicitly set old link interface properties to the
  4763. // preferred new link interface property one and warn if different.
  4764. const char* newExplicitLibraries =
  4765. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  4766. if (newExplicitLibraries &&
  4767. strcmp(newExplicitLibraries, explicitLibraries) != 0) {
  4768. std::ostringstream w;
  4769. /* clang-format off */
  4770. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4771. "Target \"" << this->GetName() << "\" has an "
  4772. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  4773. linkIfaceProp << " properties."
  4774. "\n"
  4775. "INTERFACE_LINK_LIBRARIES:\n"
  4776. " " << newExplicitLibraries << "\n" <<
  4777. linkIfaceProp << ":\n"
  4778. " " << explicitLibraries << "\n";
  4779. /* clang-format on */
  4780. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
  4781. this->PolicyWarnedCMP0022 = true;
  4782. }
  4783. }
  4784. // There is no implicit link interface for executables or modules
  4785. // so if none was explicitly set then there is no link interface.
  4786. if (!explicitLibraries &&
  4787. (this->GetType() == cmStateEnums::EXECUTABLE ||
  4788. (this->GetType() == cmStateEnums::MODULE_LIBRARY))) {
  4789. return;
  4790. }
  4791. iface.Exists = true;
  4792. iface.ExplicitLibraries = explicitLibraries;
  4793. if (explicitLibraries) {
  4794. // The interface libraries have been explicitly set.
  4795. this->ExpandLinkItems(linkIfaceProp, explicitLibraries, config, headTarget,
  4796. usage_requirements_only, iface.Libraries,
  4797. iface.HadHeadSensitiveCondition);
  4798. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  4799. this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  4800. // If CMP0022 is NEW then the plain tll signature sets the
  4801. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  4802. // cleared the property explicitly and we should not fall back
  4803. // to the link implementation.
  4804. {
  4805. // The link implementation is the default link interface.
  4806. cmLinkImplementationLibraries const* impl =
  4807. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  4808. iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(),
  4809. impl->Libraries.end());
  4810. if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4811. !this->PolicyWarnedCMP0022 && !usage_requirements_only) {
  4812. // Compare the link implementation fallback link interface to the
  4813. // preferred new link interface property and warn if different.
  4814. std::vector<cmLinkItem> ifaceLibs;
  4815. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  4816. if (const char* newExplicitLibraries = this->GetProperty(newProp)) {
  4817. bool hadHeadSensitiveConditionDummy = false;
  4818. this->ExpandLinkItems(newProp, newExplicitLibraries, config,
  4819. headTarget, usage_requirements_only, ifaceLibs,
  4820. hadHeadSensitiveConditionDummy);
  4821. }
  4822. if (ifaceLibs != iface.Libraries) {
  4823. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  4824. std::string newLibraries = cmJoin(ifaceLibs, ";");
  4825. if (oldLibraries.empty()) {
  4826. oldLibraries = "(empty)";
  4827. }
  4828. if (newLibraries.empty()) {
  4829. newLibraries = "(empty)";
  4830. }
  4831. std::ostringstream w;
  4832. /* clang-format off */
  4833. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4834. "Target \"" << this->GetName() << "\" has an "
  4835. "INTERFACE_LINK_LIBRARIES property. "
  4836. "This should be preferred as the source of the link interface "
  4837. "for this library but because CMP0022 is not set CMake is "
  4838. "ignoring the property and using the link implementation "
  4839. "as the link interface instead."
  4840. "\n"
  4841. "INTERFACE_LINK_LIBRARIES:\n"
  4842. " " << newLibraries << "\n"
  4843. "Link implementation:\n"
  4844. " " << oldLibraries << "\n";
  4845. /* clang-format on */
  4846. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING,
  4847. w.str());
  4848. this->PolicyWarnedCMP0022 = true;
  4849. }
  4850. }
  4851. }
  4852. }
  4853. const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
  4854. const std::string& config, cmGeneratorTarget const* headTarget,
  4855. bool usage_requirements_only) const
  4856. {
  4857. cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
  4858. if (!info) {
  4859. return nullptr;
  4860. }
  4861. std::string CONFIG = cmSystemTools::UpperCase(config);
  4862. cmHeadToLinkInterfaceMap& hm =
  4863. (usage_requirements_only
  4864. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  4865. : this->GetHeadToLinkInterfaceMap(config));
  4866. // If the link interface does not depend on the head target
  4867. // then return the one we computed first.
  4868. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  4869. return &hm.begin()->second;
  4870. }
  4871. cmOptionalLinkInterface& iface = hm[headTarget];
  4872. if (!iface.AllDone) {
  4873. iface.AllDone = true;
  4874. iface.Multiplicity = info->Multiplicity;
  4875. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  4876. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  4877. headTarget, usage_requirements_only, iface.Libraries,
  4878. iface.HadHeadSensitiveCondition);
  4879. std::vector<std::string> deps;
  4880. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  4881. this->LookupLinkItems(deps, cmListFileBacktrace(), iface.SharedDeps);
  4882. }
  4883. return &iface;
  4884. }
  4885. cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo(
  4886. const std::string& config) const
  4887. {
  4888. // There is no imported information for non-imported targets.
  4889. if (!this->IsImported()) {
  4890. return nullptr;
  4891. }
  4892. // Lookup/compute/cache the import information for this
  4893. // configuration.
  4894. std::string config_upper;
  4895. if (!config.empty()) {
  4896. config_upper = cmSystemTools::UpperCase(config);
  4897. } else {
  4898. config_upper = "NOCONFIG";
  4899. }
  4900. ImportInfoMapType::const_iterator i = this->ImportInfoMap.find(config_upper);
  4901. if (i == this->ImportInfoMap.end()) {
  4902. ImportInfo info;
  4903. this->ComputeImportInfo(config_upper, info);
  4904. ImportInfoMapType::value_type entry(config_upper, info);
  4905. i = this->ImportInfoMap.insert(entry).first;
  4906. }
  4907. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4908. return &i->second;
  4909. }
  4910. // If the location is empty then the target is not available for
  4911. // this configuration.
  4912. if (i->second.Location.empty() && i->second.ImportLibrary.empty()) {
  4913. return nullptr;
  4914. }
  4915. // Return the import information.
  4916. return &i->second;
  4917. }
  4918. void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
  4919. ImportInfo& info) const
  4920. {
  4921. // This method finds information about an imported target from its
  4922. // properties. The "IMPORTED_" namespace is reserved for properties
  4923. // defined by the project exporting the target.
  4924. // Initialize members.
  4925. info.NoSOName = false;
  4926. const char* loc = nullptr;
  4927. const char* imp = nullptr;
  4928. std::string suffix;
  4929. if (!this->Target->GetMappedConfig(desired_config, &loc, &imp, suffix)) {
  4930. return;
  4931. }
  4932. // Get the link interface.
  4933. {
  4934. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  4935. const char* propertyLibs = this->GetProperty(linkProp);
  4936. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  4937. if (!propertyLibs) {
  4938. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4939. linkProp += suffix;
  4940. propertyLibs = this->GetProperty(linkProp);
  4941. }
  4942. if (!propertyLibs) {
  4943. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4944. propertyLibs = this->GetProperty(linkProp);
  4945. }
  4946. }
  4947. if (propertyLibs) {
  4948. info.LibrariesProp = linkProp;
  4949. info.Libraries = propertyLibs;
  4950. }
  4951. }
  4952. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4953. if (loc) {
  4954. info.LibName = loc;
  4955. }
  4956. return;
  4957. }
  4958. // A provided configuration has been chosen. Load the
  4959. // configuration's properties.
  4960. // Get the location.
  4961. if (loc) {
  4962. info.Location = loc;
  4963. } else {
  4964. std::string impProp = "IMPORTED_LOCATION";
  4965. impProp += suffix;
  4966. if (const char* config_location = this->GetProperty(impProp)) {
  4967. info.Location = config_location;
  4968. } else if (const char* location = this->GetProperty("IMPORTED_LOCATION")) {
  4969. info.Location = location;
  4970. }
  4971. }
  4972. // Get the soname.
  4973. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  4974. std::string soProp = "IMPORTED_SONAME";
  4975. soProp += suffix;
  4976. if (const char* config_soname = this->GetProperty(soProp)) {
  4977. info.SOName = config_soname;
  4978. } else if (const char* soname = this->GetProperty("IMPORTED_SONAME")) {
  4979. info.SOName = soname;
  4980. }
  4981. }
  4982. // Get the "no-soname" mark.
  4983. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  4984. std::string soProp = "IMPORTED_NO_SONAME";
  4985. soProp += suffix;
  4986. if (const char* config_no_soname = this->GetProperty(soProp)) {
  4987. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  4988. } else if (const char* no_soname =
  4989. this->GetProperty("IMPORTED_NO_SONAME")) {
  4990. info.NoSOName = cmSystemTools::IsOn(no_soname);
  4991. }
  4992. }
  4993. // Get the import library.
  4994. if (imp) {
  4995. info.ImportLibrary = imp;
  4996. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4997. this->IsExecutableWithExports()) {
  4998. std::string impProp = "IMPORTED_IMPLIB";
  4999. impProp += suffix;
  5000. if (const char* config_implib = this->GetProperty(impProp)) {
  5001. info.ImportLibrary = config_implib;
  5002. } else if (const char* implib = this->GetProperty("IMPORTED_IMPLIB")) {
  5003. info.ImportLibrary = implib;
  5004. }
  5005. }
  5006. // Get the link dependencies.
  5007. {
  5008. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  5009. linkProp += suffix;
  5010. if (const char* config_libs = this->GetProperty(linkProp)) {
  5011. info.SharedDeps = config_libs;
  5012. } else if (const char* libs =
  5013. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES")) {
  5014. info.SharedDeps = libs;
  5015. }
  5016. }
  5017. // Get the link languages.
  5018. if (this->LinkLanguagePropagatesToDependents()) {
  5019. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  5020. linkProp += suffix;
  5021. if (const char* config_libs = this->GetProperty(linkProp)) {
  5022. info.Languages = config_libs;
  5023. } else if (const char* libs =
  5024. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES")) {
  5025. info.Languages = libs;
  5026. }
  5027. }
  5028. // Get information if target is managed assembly.
  5029. {
  5030. std::string linkProp = "IMPORTED_COMMON_LANGUAGE_RUNTIME";
  5031. if (auto pc = this->GetProperty(linkProp + suffix)) {
  5032. info.Managed = this->CheckManagedType(pc);
  5033. } else if (auto p = this->GetProperty(linkProp)) {
  5034. info.Managed = this->CheckManagedType(p);
  5035. }
  5036. }
  5037. // Get the cyclic repetition count.
  5038. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  5039. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  5040. linkProp += suffix;
  5041. if (const char* config_reps = this->GetProperty(linkProp)) {
  5042. sscanf(config_reps, "%u", &info.Multiplicity);
  5043. } else if (const char* reps =
  5044. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY")) {
  5045. sscanf(reps, "%u", &info.Multiplicity);
  5046. }
  5047. }
  5048. }
  5049. cmHeadToLinkInterfaceMap& cmGeneratorTarget::GetHeadToLinkInterfaceMap(
  5050. const std::string& config) const
  5051. {
  5052. std::string CONFIG = cmSystemTools::UpperCase(config);
  5053. return this->LinkInterfaceMap[CONFIG];
  5054. }
  5055. cmHeadToLinkInterfaceMap&
  5056. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  5057. const std::string& config) const
  5058. {
  5059. std::string CONFIG = cmSystemTools::UpperCase(config);
  5060. return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG];
  5061. }
  5062. const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
  5063. const std::string& config) const
  5064. {
  5065. // There is no link implementation for imported targets.
  5066. if (this->IsImported()) {
  5067. return nullptr;
  5068. }
  5069. std::string CONFIG = cmSystemTools::UpperCase(config);
  5070. cmOptionalLinkImplementation& impl = this->LinkImplMap[CONFIG][this];
  5071. if (!impl.LibrariesDone) {
  5072. impl.LibrariesDone = true;
  5073. this->ComputeLinkImplementationLibraries(config, impl, this);
  5074. }
  5075. if (!impl.LanguagesDone) {
  5076. impl.LanguagesDone = true;
  5077. this->ComputeLinkImplementationLanguages(config, impl);
  5078. }
  5079. return &impl;
  5080. }
  5081. bool cmGeneratorTarget::GetConfigCommonSourceFiles(
  5082. std::vector<cmSourceFile*>& files) const
  5083. {
  5084. std::vector<std::string> configs;
  5085. this->Makefile->GetConfigurations(configs);
  5086. if (configs.empty()) {
  5087. configs.emplace_back();
  5088. }
  5089. std::vector<std::string>::const_iterator it = configs.begin();
  5090. const std::string& firstConfig = *it;
  5091. this->GetSourceFilesWithoutObjectLibraries(files, firstConfig);
  5092. for (; it != configs.end(); ++it) {
  5093. std::vector<cmSourceFile*> configFiles;
  5094. this->GetSourceFilesWithoutObjectLibraries(configFiles, *it);
  5095. if (configFiles != files) {
  5096. std::string firstConfigFiles;
  5097. const char* sep = "";
  5098. for (cmSourceFile* f : files) {
  5099. firstConfigFiles += sep;
  5100. firstConfigFiles += f->GetFullPath();
  5101. sep = "\n ";
  5102. }
  5103. std::string thisConfigFiles;
  5104. sep = "";
  5105. for (cmSourceFile* f : configFiles) {
  5106. thisConfigFiles += sep;
  5107. thisConfigFiles += f->GetFullPath();
  5108. sep = "\n ";
  5109. }
  5110. std::ostringstream e;
  5111. /* clang-format off */
  5112. e << "Target \"" << this->GetName()
  5113. << "\" has source files which vary by "
  5114. "configuration. This is not supported by the \""
  5115. << this->GlobalGenerator->GetName()
  5116. << "\" generator.\n"
  5117. "Config \"" << firstConfig << "\":\n"
  5118. " " << firstConfigFiles << "\n"
  5119. "Config \"" << *it << "\":\n"
  5120. " " << thisConfigFiles << "\n";
  5121. /* clang-format on */
  5122. this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
  5123. return false;
  5124. }
  5125. }
  5126. return true;
  5127. }
  5128. void cmGeneratorTarget::GetObjectLibrariesCMP0026(
  5129. std::vector<cmGeneratorTarget*>& objlibs) const
  5130. {
  5131. // At configure-time, this method can be called as part of getting the
  5132. // LOCATION property or to export() a file to be include()d. However
  5133. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  5134. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  5135. // behavior of CMP0024 and CMP0026 only.
  5136. cmStringRange rng = this->Target->GetSourceEntries();
  5137. for (std::string const& entry : rng) {
  5138. std::vector<std::string> files;
  5139. cmSystemTools::ExpandListArgument(entry, files);
  5140. for (std::string const& li : files) {
  5141. if (cmHasLiteralPrefix(li, "$<TARGET_OBJECTS:") && li.back() == '>') {
  5142. std::string objLibName = li.substr(17, li.size() - 18);
  5143. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  5144. continue;
  5145. }
  5146. cmGeneratorTarget* objLib =
  5147. this->LocalGenerator->FindGeneratorTargetToUse(objLibName);
  5148. if (objLib) {
  5149. objlibs.push_back(objLib);
  5150. }
  5151. }
  5152. }
  5153. }
  5154. }
  5155. std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
  5156. {
  5157. // Strip whitespace off the library names because we used to do this
  5158. // in case variables were expanded at generate time. We no longer
  5159. // do the expansion but users link to libraries like " ${VAR} ".
  5160. std::string lib = item;
  5161. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  5162. if (pos != std::string::npos) {
  5163. lib = lib.substr(pos);
  5164. }
  5165. pos = lib.find_last_not_of(" \t\r\n");
  5166. if (pos != std::string::npos) {
  5167. lib = lib.substr(0, pos + 1);
  5168. }
  5169. if (lib != item) {
  5170. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  5171. switch (this->GetPolicyStatusCMP0004()) {
  5172. case cmPolicies::WARN: {
  5173. std::ostringstream w;
  5174. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  5175. << "Target \"" << this->GetName() << "\" links to item \"" << item
  5176. << "\" which has leading or trailing whitespace.";
  5177. cm->IssueMessage(MessageType::AUTHOR_WARNING, w.str(),
  5178. this->GetBacktrace());
  5179. }
  5180. case cmPolicies::OLD:
  5181. break;
  5182. case cmPolicies::NEW: {
  5183. std::ostringstream e;
  5184. e << "Target \"" << this->GetName() << "\" links to item \"" << item
  5185. << "\" which has leading or trailing whitespace. "
  5186. << "This is now an error according to policy CMP0004.";
  5187. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  5188. this->GetBacktrace());
  5189. } break;
  5190. case cmPolicies::REQUIRED_IF_USED:
  5191. case cmPolicies::REQUIRED_ALWAYS: {
  5192. std::ostringstream e;
  5193. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  5194. << "Target \"" << this->GetName() << "\" links to item \"" << item
  5195. << "\" which has leading or trailing whitespace.";
  5196. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  5197. this->GetBacktrace());
  5198. } break;
  5199. }
  5200. }
  5201. return lib;
  5202. }
  5203. void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
  5204. const std::string& config) const
  5205. {
  5206. std::vector<cmSourceFile*> sourceFiles;
  5207. this->GetSourceFiles(sourceFiles, config);
  5208. for (cmSourceFile* src : sourceFiles) {
  5209. const std::string& lang = src->GetLanguage();
  5210. if (!lang.empty()) {
  5211. languages.insert(lang);
  5212. }
  5213. }
  5214. std::vector<cmGeneratorTarget*> objectLibraries;
  5215. std::vector<cmSourceFile const*> externalObjects;
  5216. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  5217. std::vector<cmGeneratorTarget*> objectTargets;
  5218. this->GetObjectLibrariesCMP0026(objectTargets);
  5219. objectLibraries.reserve(objectTargets.size());
  5220. for (cmGeneratorTarget* gt : objectTargets) {
  5221. objectLibraries.push_back(gt);
  5222. }
  5223. } else {
  5224. this->GetExternalObjects(externalObjects, config);
  5225. for (cmSourceFile const* extObj : externalObjects) {
  5226. std::string objLib = extObj->GetObjectLibrary();
  5227. if (cmGeneratorTarget* tgt =
  5228. this->LocalGenerator->FindGeneratorTargetToUse(objLib)) {
  5229. auto const objLibIt =
  5230. std::find_if(objectLibraries.cbegin(), objectLibraries.cend(),
  5231. [tgt](cmGeneratorTarget* t) { return t == tgt; });
  5232. if (objectLibraries.cend() == objLibIt) {
  5233. objectLibraries.push_back(tgt);
  5234. }
  5235. }
  5236. }
  5237. }
  5238. for (cmGeneratorTarget* objLib : objectLibraries) {
  5239. objLib->GetLanguages(languages, config);
  5240. }
  5241. }
  5242. bool cmGeneratorTarget::IsCSharpOnly() const
  5243. {
  5244. // Only certain target types may compile CSharp.
  5245. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  5246. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  5247. this->GetType() != cmStateEnums::EXECUTABLE) {
  5248. return false;
  5249. }
  5250. std::set<std::string> languages;
  5251. this->GetLanguages(languages, "");
  5252. // Consider an explicit linker language property, but *not* the
  5253. // computed linker language that may depend on linked targets.
  5254. const char* linkLang = this->GetProperty("LINKER_LANGUAGE");
  5255. if (linkLang && *linkLang) {
  5256. languages.insert(linkLang);
  5257. }
  5258. return languages.size() == 1 && languages.count("CSharp") > 0;
  5259. }
  5260. void cmGeneratorTarget::ComputeLinkImplementationLanguages(
  5261. const std::string& config, cmOptionalLinkImplementation& impl) const
  5262. {
  5263. // This target needs runtime libraries for its source languages.
  5264. std::set<std::string> languages;
  5265. // Get languages used in our source files.
  5266. this->GetLanguages(languages, config);
  5267. // Copy the set of languages to the link implementation.
  5268. impl.Languages.insert(impl.Languages.begin(), languages.begin(),
  5269. languages.end());
  5270. }
  5271. bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
  5272. {
  5273. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH")) {
  5274. return false;
  5275. }
  5276. if (this->GetProperty("BUILD_RPATH")) {
  5277. return true;
  5278. }
  5279. if (cmLinkImplementationLibraries const* impl =
  5280. this->GetLinkImplementationLibraries(config)) {
  5281. return !impl->Libraries.empty();
  5282. }
  5283. return false;
  5284. }
  5285. cmLinkImplementationLibraries const*
  5286. cmGeneratorTarget::GetLinkImplementationLibraries(
  5287. const std::string& config) const
  5288. {
  5289. return this->GetLinkImplementationLibrariesInternal(config, this);
  5290. }
  5291. cmLinkImplementationLibraries const*
  5292. cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
  5293. const std::string& config, cmGeneratorTarget const* head) const
  5294. {
  5295. // There is no link implementation for imported targets.
  5296. if (this->IsImported()) {
  5297. return nullptr;
  5298. }
  5299. // Populate the link implementation libraries for this configuration.
  5300. std::string CONFIG = cmSystemTools::UpperCase(config);
  5301. HeadToLinkImplementationMap& hm = this->LinkImplMap[CONFIG];
  5302. // If the link implementation does not depend on the head target
  5303. // then return the one we computed first.
  5304. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  5305. return &hm.begin()->second;
  5306. }
  5307. cmOptionalLinkImplementation& impl = hm[head];
  5308. if (!impl.LibrariesDone) {
  5309. impl.LibrariesDone = true;
  5310. this->ComputeLinkImplementationLibraries(config, impl, head);
  5311. }
  5312. return &impl;
  5313. }
  5314. bool cmGeneratorTarget::IsNullImpliedByLinkLibraries(
  5315. const std::string& p) const
  5316. {
  5317. return this->LinkImplicitNullProperties.find(p) !=
  5318. this->LinkImplicitNullProperties.end();
  5319. }
  5320. void cmGeneratorTarget::ComputeLinkImplementationLibraries(
  5321. const std::string& config, cmOptionalLinkImplementation& impl,
  5322. cmGeneratorTarget const* head) const
  5323. {
  5324. cmStringRange entryRange = this->Target->GetLinkImplementationEntries();
  5325. cmBacktraceRange btRange = this->Target->GetLinkImplementationBacktraces();
  5326. cmBacktraceRange::const_iterator btIt = btRange.begin();
  5327. // Collect libraries directly linked in this configuration.
  5328. for (cmStringRange::const_iterator le = entryRange.begin(),
  5329. end = entryRange.end();
  5330. le != end; ++le, ++btIt) {
  5331. std::vector<std::string> llibs;
  5332. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr,
  5333. nullptr);
  5334. cmGeneratorExpression ge(*btIt);
  5335. std::unique_ptr<cmCompiledGeneratorExpression> const cge = ge.Parse(*le);
  5336. std::string const& evaluated =
  5337. cge->Evaluate(this->LocalGenerator, config, false, head, &dagChecker);
  5338. cmSystemTools::ExpandListArgument(evaluated, llibs);
  5339. if (cge->GetHadHeadSensitiveCondition()) {
  5340. impl.HadHeadSensitiveCondition = true;
  5341. }
  5342. for (std::string const& lib : llibs) {
  5343. // Skip entries that resolve to the target itself or are empty.
  5344. std::string name = this->CheckCMP0004(lib);
  5345. if (name == this->GetName() || name.empty()) {
  5346. if (name == this->GetName()) {
  5347. bool noMessage = false;
  5348. MessageType messageType = MessageType::FATAL_ERROR;
  5349. std::ostringstream e;
  5350. switch (this->GetPolicyStatusCMP0038()) {
  5351. case cmPolicies::WARN: {
  5352. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  5353. messageType = MessageType::AUTHOR_WARNING;
  5354. } break;
  5355. case cmPolicies::OLD:
  5356. noMessage = true;
  5357. case cmPolicies::REQUIRED_IF_USED:
  5358. case cmPolicies::REQUIRED_ALWAYS:
  5359. case cmPolicies::NEW:
  5360. // Issue the fatal message.
  5361. break;
  5362. }
  5363. if (!noMessage) {
  5364. e << "Target \"" << this->GetName() << "\" links to itself.";
  5365. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  5366. messageType, e.str(), this->GetBacktrace());
  5367. if (messageType == MessageType::FATAL_ERROR) {
  5368. return;
  5369. }
  5370. }
  5371. }
  5372. continue;
  5373. }
  5374. // The entry is meant for this configuration.
  5375. impl.Libraries.emplace_back(this->ResolveLinkItem(name, *btIt),
  5376. evaluated != *le);
  5377. }
  5378. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  5379. for (std::string const& sp : seenProps) {
  5380. if (!this->GetProperty(sp)) {
  5381. this->LinkImplicitNullProperties.insert(sp);
  5382. }
  5383. }
  5384. cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards);
  5385. }
  5386. // Get the list of configurations considered to be DEBUG.
  5387. std::vector<std::string> debugConfigs =
  5388. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  5389. cmTargetLinkLibraryType linkType =
  5390. CMP0003_ComputeLinkType(config, debugConfigs);
  5391. cmTarget::LinkLibraryVectorType const& oldllibs =
  5392. this->Target->GetOriginalLinkLibraries();
  5393. for (cmTarget::LibraryID const& oldllib : oldllibs) {
  5394. if (oldllib.second != GENERAL_LibraryType && oldllib.second != linkType) {
  5395. std::string name = this->CheckCMP0004(oldllib.first);
  5396. if (name == this->GetName() || name.empty()) {
  5397. continue;
  5398. }
  5399. // Support OLD behavior for CMP0003.
  5400. impl.WrongConfigLibraries.push_back(
  5401. this->ResolveLinkItem(name, cmListFileBacktrace()));
  5402. }
  5403. }
  5404. }
  5405. cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
  5406. std::string const& name) const
  5407. {
  5408. cmLocalGenerator const* lg = this->LocalGenerator;
  5409. std::string const* lookupName = &name;
  5410. // When target_link_libraries() is called with a LHS target that is
  5411. // not created in the calling directory it adds a directory id suffix
  5412. // that we can use to look up the calling directory. It is that scope
  5413. // in which the item name is meaningful. This case is relatively rare
  5414. // so we allocate a separate string only when the directory id is present.
  5415. std::string::size_type pos = name.find(CMAKE_DIRECTORY_ID_SEP);
  5416. std::string plainName;
  5417. if (pos != std::string::npos) {
  5418. // We will look up the plain name without the directory id suffix.
  5419. plainName = name.substr(0, pos);
  5420. // We will look up in the scope of the directory id.
  5421. // If we do not recognize the id then leave the original
  5422. // syntax in place to produce an indicative error later.
  5423. cmDirectoryId const dirId =
  5424. name.substr(pos + sizeof(CMAKE_DIRECTORY_ID_SEP) - 1);
  5425. if (cmLocalGenerator const* otherLG =
  5426. this->GlobalGenerator->FindLocalGenerator(dirId)) {
  5427. lg = otherLG;
  5428. lookupName = &plainName;
  5429. }
  5430. }
  5431. TargetOrString resolved;
  5432. if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(*lookupName)) {
  5433. resolved.Target = tgt;
  5434. } else if (lookupName == &plainName) {
  5435. resolved.String = std::move(plainName);
  5436. } else {
  5437. resolved.String = name;
  5438. }
  5439. return resolved;
  5440. }
  5441. cmLinkItem cmGeneratorTarget::ResolveLinkItem(
  5442. std::string const& name, cmListFileBacktrace const& bt) const
  5443. {
  5444. TargetOrString resolved = this->ResolveTargetReference(name);
  5445. if (!resolved.Target) {
  5446. return cmLinkItem(resolved.String, bt);
  5447. }
  5448. // Skip targets that will not really be linked. This is probably a
  5449. // name conflict between an external library and an executable
  5450. // within the project.
  5451. if (resolved.Target->GetType() == cmStateEnums::EXECUTABLE &&
  5452. !resolved.Target->IsExecutableWithExports()) {
  5453. return cmLinkItem(resolved.Target->GetName(), bt);
  5454. }
  5455. return cmLinkItem(resolved.Target, bt);
  5456. }
  5457. std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
  5458. {
  5459. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  5460. // Return the directory in which the target will be built.
  5461. return info->PdbDir;
  5462. }
  5463. return "";
  5464. }
  5465. bool cmGeneratorTarget::HasImplibGNUtoMS(std::string const& config) const
  5466. {
  5467. return this->HasImportLibrary(config) && this->GetPropertyAsBool("GNUtoMS");
  5468. }
  5469. bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& config,
  5470. std::string const& gnuName,
  5471. std::string& out,
  5472. const char* newExt) const
  5473. {
  5474. if (this->HasImplibGNUtoMS(config) && gnuName.size() > 6 &&
  5475. gnuName.substr(gnuName.size() - 6) == ".dll.a") {
  5476. out = gnuName.substr(0, gnuName.size() - 6);
  5477. out += newExt ? newExt : ".lib";
  5478. return true;
  5479. }
  5480. return false;
  5481. }
  5482. bool cmGeneratorTarget::IsExecutableWithExports() const
  5483. {
  5484. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  5485. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  5486. }
  5487. bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const
  5488. {
  5489. return (this->IsDLLPlatform() &&
  5490. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5491. this->IsExecutableWithExports()) &&
  5492. // Assemblies which have only managed code do not have
  5493. // import libraries.
  5494. this->GetManagedType(config) != ManagedType::Managed);
  5495. }
  5496. std::string cmGeneratorTarget::GetSupportDirectory() const
  5497. {
  5498. std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory();
  5499. dir += cmake::GetCMakeFilesDirectory();
  5500. dir += "/";
  5501. dir += this->GetName();
  5502. #if defined(__VMS)
  5503. dir += "_dir";
  5504. #else
  5505. dir += ".dir";
  5506. #endif
  5507. return dir;
  5508. }
  5509. bool cmGeneratorTarget::IsLinkable() const
  5510. {
  5511. return (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  5512. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5513. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  5514. this->GetType() == cmStateEnums::UNKNOWN_LIBRARY ||
  5515. this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  5516. this->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
  5517. this->IsExecutableWithExports());
  5518. }
  5519. bool cmGeneratorTarget::IsFrameworkOnApple() const
  5520. {
  5521. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5522. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  5523. this->Makefile->IsOn("APPLE") &&
  5524. this->GetPropertyAsBool("FRAMEWORK"));
  5525. }
  5526. bool cmGeneratorTarget::IsAppBundleOnApple() const
  5527. {
  5528. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  5529. this->Makefile->IsOn("APPLE") &&
  5530. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  5531. }
  5532. bool cmGeneratorTarget::IsXCTestOnApple() const
  5533. {
  5534. return (this->IsCFBundleOnApple() && this->GetPropertyAsBool("XCTEST"));
  5535. }
  5536. bool cmGeneratorTarget::IsCFBundleOnApple() const
  5537. {
  5538. return (this->GetType() == cmStateEnums::MODULE_LIBRARY &&
  5539. this->Makefile->IsOn("APPLE") && this->GetPropertyAsBool("BUNDLE"));
  5540. }
  5541. cmGeneratorTarget::ManagedType cmGeneratorTarget::CheckManagedType(
  5542. std::string const& propval) const
  5543. {
  5544. // The type of the managed assembly (mixed unmanaged C++ and C++/CLI,
  5545. // or only C++/CLI) does only depend on whether the property is an empty
  5546. // string or contains any value at all. In Visual Studio generators
  5547. // this propval is prepended with /clr[:] which results in:
  5548. //
  5549. // 1. propval does not exist: no /clr flag, unmanaged target, has import
  5550. // lib
  5551. // 2. empty propval: add /clr as flag, mixed unmanaged/managed
  5552. // target, has import lib
  5553. // 3. any value (safe,pure): add /clr:[propval] as flag, target with
  5554. // managed code only, no import lib
  5555. return propval.empty() ? ManagedType::Mixed : ManagedType::Managed;
  5556. }
  5557. cmGeneratorTarget::ManagedType cmGeneratorTarget::GetManagedType(
  5558. const std::string& config) const
  5559. {
  5560. // Only libraries and executables can be managed targets.
  5561. if (this->GetType() > cmStateEnums::SHARED_LIBRARY) {
  5562. return ManagedType::Undefined;
  5563. }
  5564. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  5565. return ManagedType::Native;
  5566. }
  5567. // Check imported target.
  5568. if (this->IsImported()) {
  5569. if (cmGeneratorTarget::ImportInfo const* info =
  5570. this->GetImportInfo(config)) {
  5571. return info->Managed;
  5572. }
  5573. return ManagedType::Undefined;
  5574. }
  5575. // Check for explicitly set clr target property.
  5576. if (auto* clr = this->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  5577. return this->CheckManagedType(clr);
  5578. }
  5579. // C# targets are always managed. This language specific check
  5580. // is added to avoid that the COMMON_LANGUAGE_RUNTIME target property
  5581. // has to be set manually for C# targets.
  5582. return this->IsCSharpOnly() ? ManagedType::Managed : ManagedType::Native;
  5583. }