cmTarget.cxx 197 KB

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