cmTarget.cxx 199 KB

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