cmGeneratorTarget.cxx 191 KB

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