cmTarget.cxx 222 KB

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