cmTarget.cxx 232 KB

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