cmTarget.cxx 199 KB

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