cmTarget.cxx 212 KB

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