cmTarget.cxx 210 KB

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