cmGeneratorTarget.cxx 175 KB

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