cmGeneratorTarget.cxx 186 KB

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