cmTarget.cxx 198 KB

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