cmGeneratorTarget.cxx 180 KB

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