cmTarget.cxx 222 KB

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