cmTarget.cxx 220 KB

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