cmGeneratorTarget.cxx 191 KB

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