cmTarget.cxx 200 KB

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