cmTarget.cxx 223 KB

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