cmGeneratorTarget.cxx 188 KB

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