cmTarget.cxx 198 KB

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