cmTarget.cxx 214 KB

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