cmGeneratorTarget.cxx 172 KB

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