cmTarget.cxx 198 KB

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