cmTarget.cxx 249 KB

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