cmTarget.cxx 188 KB

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