cmTarget.cxx 222 KB

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