cmTarget.cxx 221 KB

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