cmTarget.cxx 197 KB

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