cmGeneratorTarget.cxx 159 KB

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