cmTarget.cxx 197 KB

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