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