cmGeneratorTarget.cxx 192 KB

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