cmTarget.cxx 221 KB

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