cmTarget.cxx 235 KB

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