cmTarget.cxx 225 KB

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