cmTarget.cxx 210 KB

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