cmTarget.cxx 205 KB

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