cmTarget.cxx 217 KB

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