cmTarget.cxx 230 KB

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