cmTarget.cxx 199 KB

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