cmGeneratorTarget.cxx 183 KB

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