cmTarget.cxx 214 KB

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