cmTarget.cxx 251 KB

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