cmTarget.cxx 239 KB

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