cmTarget.cxx 188 KB

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