cmTarget.cxx 220 KB

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