cmTarget.cxx 223 KB

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