cmTarget.cxx 161 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 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 "cmTarget.h"
  11. #include "cmake.h"
  12. #include "cmMakefile.h"
  13. #include "cmSourceFile.h"
  14. #include "cmOutputConverter.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmListFileCache.h"
  18. #include "cmGeneratorExpression.h"
  19. #include "cmGeneratorExpressionDAGChecker.h"
  20. #include "cmAlgorithms.h"
  21. #include <cmsys/RegularExpression.hxx>
  22. #include <map>
  23. #include <set>
  24. #include <stdlib.h> // required for atof
  25. #include <assert.h>
  26. #include <errno.h>
  27. #if defined(CMAKE_BUILD_WITH_CMAKE)
  28. #include <cmsys/hash_set.hxx>
  29. #define UNORDERED_SET cmsys::hash_set
  30. #else
  31. #define UNORDERED_SET std::set
  32. #endif
  33. const char* cmTarget::GetTargetTypeName(TargetType targetType)
  34. {
  35. switch( targetType )
  36. {
  37. case cmTarget::STATIC_LIBRARY:
  38. return "STATIC_LIBRARY";
  39. case cmTarget::MODULE_LIBRARY:
  40. return "MODULE_LIBRARY";
  41. case cmTarget::SHARED_LIBRARY:
  42. return "SHARED_LIBRARY";
  43. case cmTarget::OBJECT_LIBRARY:
  44. return "OBJECT_LIBRARY";
  45. case cmTarget::EXECUTABLE:
  46. return "EXECUTABLE";
  47. case cmTarget::UTILITY:
  48. return "UTILITY";
  49. case cmTarget::GLOBAL_TARGET:
  50. return "GLOBAL_TARGET";
  51. case cmTarget::INTERFACE_LIBRARY:
  52. return "INTERFACE_LIBRARY";
  53. case cmTarget::UNKNOWN_LIBRARY:
  54. return "UNKNOWN_LIBRARY";
  55. }
  56. assert(0 && "Unexpected target type");
  57. return 0;
  58. }
  59. //----------------------------------------------------------------------------
  60. struct cmTarget::OutputInfo
  61. {
  62. std::string OutDir;
  63. std::string ImpDir;
  64. std::string PdbDir;
  65. bool empty() const
  66. { return OutDir.empty() && ImpDir.empty() && PdbDir.empty(); }
  67. };
  68. //----------------------------------------------------------------------------
  69. class cmTargetInternals
  70. {
  71. public:
  72. cmTargetInternals()
  73. : Backtrace()
  74. {
  75. this->PolicyWarnedCMP0022 = false;
  76. this->UtilityItemsDone = false;
  77. }
  78. cmTargetInternals(cmTargetInternals const&)
  79. : Backtrace()
  80. {
  81. this->PolicyWarnedCMP0022 = false;
  82. this->UtilityItemsDone = false;
  83. }
  84. ~cmTargetInternals();
  85. // The backtrace when the target was created.
  86. cmListFileBacktrace Backtrace;
  87. // Cache link interface computation from each configuration.
  88. struct OptionalLinkInterface: public cmTarget::LinkInterface
  89. {
  90. OptionalLinkInterface():
  91. LibrariesDone(false), AllDone(false),
  92. Exists(false), HadHeadSensitiveCondition(false),
  93. ExplicitLibraries(0) {}
  94. bool LibrariesDone;
  95. bool AllDone;
  96. bool Exists;
  97. bool HadHeadSensitiveCondition;
  98. const char* ExplicitLibraries;
  99. };
  100. void ComputeLinkInterface(cmTarget const* thisTarget,
  101. const std::string& config,
  102. OptionalLinkInterface& iface,
  103. cmTarget const* head) const;
  104. void ComputeLinkInterfaceLibraries(cmTarget const* thisTarget,
  105. const std::string& config,
  106. OptionalLinkInterface& iface,
  107. cmTarget const* head,
  108. bool usage_requirements_only);
  109. struct HeadToLinkInterfaceMap:
  110. public std::map<cmTarget const*, OptionalLinkInterface> {};
  111. typedef std::map<std::string, HeadToLinkInterfaceMap>
  112. LinkInterfaceMapType;
  113. LinkInterfaceMapType LinkInterfaceMap;
  114. LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap;
  115. bool PolicyWarnedCMP0022;
  116. typedef std::map<std::string, cmTarget::OutputInfo> OutputInfoMapType;
  117. OutputInfoMapType OutputInfoMap;
  118. typedef std::map<std::string, cmTarget::ImportInfo> ImportInfoMapType;
  119. ImportInfoMapType ImportInfoMap;
  120. // Cache link implementation computation from each configuration.
  121. struct OptionalLinkImplementation: public cmTarget::LinkImplementation
  122. {
  123. OptionalLinkImplementation():
  124. LibrariesDone(false), LanguagesDone(false),
  125. HadHeadSensitiveCondition(false) {}
  126. bool LibrariesDone;
  127. bool LanguagesDone;
  128. bool HadHeadSensitiveCondition;
  129. };
  130. void ComputeLinkImplementationLibraries(cmTarget const* thisTarget,
  131. const std::string& config,
  132. OptionalLinkImplementation& impl,
  133. cmTarget const* head) const;
  134. void ComputeLinkImplementationLanguages(cmTarget const* thisTarget,
  135. const std::string& config,
  136. OptionalLinkImplementation& impl
  137. ) const;
  138. struct HeadToLinkImplementationMap:
  139. public std::map<cmTarget const*, OptionalLinkImplementation> {};
  140. typedef std::map<std::string,
  141. HeadToLinkImplementationMap> LinkImplMapType;
  142. LinkImplMapType LinkImplMap;
  143. typedef std::map<std::string, std::vector<cmSourceFile*> >
  144. SourceFilesMapType;
  145. SourceFilesMapType SourceFilesMap;
  146. std::set<cmLinkItem> UtilityItems;
  147. bool UtilityItemsDone;
  148. class TargetPropertyEntry {
  149. static cmLinkImplItem NoLinkImplItem;
  150. public:
  151. TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  152. cmLinkImplItem const& item = NoLinkImplItem)
  153. : ge(cge), LinkImplItem(item)
  154. {}
  155. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  156. cmLinkImplItem const& LinkImplItem;
  157. };
  158. std::vector<std::string> IncludeDirectoriesEntries;
  159. std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces;
  160. std::vector<TargetPropertyEntry*> IncludeDirectoriesItems;
  161. std::vector<std::string> CompileOptionsEntries;
  162. std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
  163. std::vector<TargetPropertyEntry*> CompileOptionsItems;
  164. std::vector<std::string> CompileFeaturesEntries;
  165. std::vector<cmListFileBacktrace> CompileFeaturesBacktraces;
  166. std::vector<TargetPropertyEntry*> CompileFeaturesItems;
  167. std::vector<std::string> CompileDefinitionsEntries;
  168. std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
  169. std::vector<TargetPropertyEntry*> CompileDefinitionsItems;
  170. std::vector<TargetPropertyEntry*> SourceEntries;
  171. std::vector<cmValueWithOrigin> LinkImplementationPropertyEntries;
  172. void AddInterfaceEntries(
  173. cmTarget const* thisTarget, std::string const& config,
  174. std::string const& prop, std::vector<TargetPropertyEntry*>& entries);
  175. };
  176. cmLinkImplItem cmTargetInternals::TargetPropertyEntry::NoLinkImplItem;
  177. //----------------------------------------------------------------------------
  178. cmTargetInternals::~cmTargetInternals()
  179. {
  180. }
  181. //----------------------------------------------------------------------------
  182. cmTarget::cmTarget()
  183. {
  184. this->Makefile = 0;
  185. #if defined(_WIN32) && !defined(__CYGWIN__)
  186. this->LinkLibrariesForVS6Analyzed = false;
  187. #endif
  188. this->HaveInstallRule = false;
  189. this->DLLPlatform = false;
  190. this->IsAndroid = false;
  191. this->IsApple = false;
  192. this->IsImportedTarget = false;
  193. this->BuildInterfaceIncludesAppended = false;
  194. this->DebugIncludesDone = false;
  195. this->DebugCompileOptionsDone = false;
  196. this->DebugCompileFeaturesDone = false;
  197. this->DebugCompileDefinitionsDone = false;
  198. this->DebugSourcesDone = false;
  199. this->LinkImplementationLanguageIsContextDependent = true;
  200. }
  201. void cmTarget::SetType(TargetType type, const std::string& name)
  202. {
  203. this->Name = name;
  204. // only add dependency information for library targets
  205. this->TargetTypeValue = type;
  206. if(this->TargetTypeValue >= STATIC_LIBRARY
  207. && this->TargetTypeValue <= MODULE_LIBRARY)
  208. {
  209. this->RecordDependencies = true;
  210. }
  211. else
  212. {
  213. this->RecordDependencies = false;
  214. }
  215. }
  216. //----------------------------------------------------------------------------
  217. void cmTarget::SetMakefile(cmMakefile* mf)
  218. {
  219. // Set our makefile.
  220. this->Makefile = mf;
  221. // Check whether this is a DLL platform.
  222. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  223. this->Makefile->IsOn("CYGWIN") ||
  224. this->Makefile->IsOn("MINGW"));
  225. // Check whether we are targeting an Android platform.
  226. this->IsAndroid =
  227. strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
  228. "Android") == 0;
  229. // Check whether we are targeting an Apple platform.
  230. this->IsApple = this->Makefile->IsOn("APPLE");
  231. // Setup default property values.
  232. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  233. {
  234. this->SetPropertyDefault("ANDROID_API", 0);
  235. this->SetPropertyDefault("ANDROID_API_MIN", 0);
  236. this->SetPropertyDefault("ANDROID_ARCH", 0);
  237. this->SetPropertyDefault("ANDROID_STL_TYPE", 0);
  238. this->SetPropertyDefault("ANDROID_SKIP_ANT_STEP", 0);
  239. this->SetPropertyDefault("ANDROID_PROCESS_MAX", 0);
  240. this->SetPropertyDefault("ANDROID_PROGUARD", 0);
  241. this->SetPropertyDefault("ANDROID_PROGUARD_CONFIG_PATH", 0);
  242. this->SetPropertyDefault("ANDROID_SECURE_PROPS_PATH", 0);
  243. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DIRECTORIES", 0);
  244. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DEPENDENCIES", 0);
  245. this->SetPropertyDefault("ANDROID_JAVA_SOURCE_DIR", 0);
  246. this->SetPropertyDefault("ANDROID_JAR_DIRECTORIES", 0);
  247. this->SetPropertyDefault("ANDROID_JAR_DEPENDENCIES", 0);
  248. this->SetPropertyDefault("ANDROID_ASSETS_DIRECTORIES", 0);
  249. this->SetPropertyDefault("ANDROID_ANT_ADDITIONAL_OPTIONS", 0);
  250. this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
  251. this->SetPropertyDefault("INSTALL_RPATH", "");
  252. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  253. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  254. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  255. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  256. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  257. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  258. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  259. this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", 0);
  260. this->SetPropertyDefault("Fortran_FORMAT", 0);
  261. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  262. this->SetPropertyDefault("GNUtoMS", 0);
  263. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  264. this->SetPropertyDefault("AUTOMOC", 0);
  265. this->SetPropertyDefault("AUTOUIC", 0);
  266. this->SetPropertyDefault("AUTORCC", 0);
  267. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  268. this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
  269. this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
  270. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  271. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  272. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  273. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  274. this->SetPropertyDefault("MACOSX_RPATH", 0);
  275. this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
  276. this->SetPropertyDefault("C_COMPILER_LAUNCHER", 0);
  277. this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", 0);
  278. this->SetPropertyDefault("C_STANDARD", 0);
  279. this->SetPropertyDefault("C_STANDARD_REQUIRED", 0);
  280. this->SetPropertyDefault("C_EXTENSIONS", 0);
  281. this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", 0);
  282. this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", 0);
  283. this->SetPropertyDefault("CXX_STANDARD", 0);
  284. this->SetPropertyDefault("CXX_STANDARD_REQUIRED", 0);
  285. this->SetPropertyDefault("CXX_EXTENSIONS", 0);
  286. this->SetPropertyDefault("LINK_SEARCH_START_STATIC", 0);
  287. this->SetPropertyDefault("LINK_SEARCH_END_STATIC", 0);
  288. }
  289. // Collect the set of configuration types.
  290. std::vector<std::string> configNames;
  291. mf->GetConfigurations(configNames);
  292. // Setup per-configuration property default values.
  293. if (this->GetType() != UTILITY)
  294. {
  295. const char* configProps[] = {
  296. "ARCHIVE_OUTPUT_DIRECTORY_",
  297. "LIBRARY_OUTPUT_DIRECTORY_",
  298. "RUNTIME_OUTPUT_DIRECTORY_",
  299. "PDB_OUTPUT_DIRECTORY_",
  300. "COMPILE_PDB_OUTPUT_DIRECTORY_",
  301. "MAP_IMPORTED_CONFIG_",
  302. 0};
  303. for(std::vector<std::string>::iterator ci = configNames.begin();
  304. ci != configNames.end(); ++ci)
  305. {
  306. std::string configUpper = cmSystemTools::UpperCase(*ci);
  307. for(const char** p = configProps; *p; ++p)
  308. {
  309. if (this->TargetTypeValue == INTERFACE_LIBRARY
  310. && strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
  311. {
  312. continue;
  313. }
  314. std::string property = *p;
  315. property += configUpper;
  316. this->SetPropertyDefault(property, 0);
  317. }
  318. // Initialize per-configuration name postfix property from the
  319. // variable only for non-executable targets. This preserves
  320. // compatibility with previous CMake versions in which executables
  321. // did not support this variable. Projects may still specify the
  322. // property directly.
  323. if(this->TargetTypeValue != cmTarget::EXECUTABLE
  324. && this->TargetTypeValue != cmTarget::INTERFACE_LIBRARY)
  325. {
  326. std::string property = cmSystemTools::UpperCase(*ci);
  327. property += "_POSTFIX";
  328. this->SetPropertyDefault(property, 0);
  329. }
  330. }
  331. }
  332. // Save the backtrace of target construction.
  333. this->Internal->Backtrace = this->Makefile->GetBacktrace();
  334. if (!this->IsImported())
  335. {
  336. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  337. // of the same directory property:
  338. const cmStringRange parentIncludes =
  339. this->Makefile->GetIncludeDirectoriesEntries();
  340. const cmBacktraceRange parentIncludesBts =
  341. this->Makefile->GetIncludeDirectoriesBacktraces();
  342. this->Internal->IncludeDirectoriesEntries.insert(
  343. this->Internal->IncludeDirectoriesEntries.end(),
  344. parentIncludes.begin(), parentIncludes.end());
  345. this->Internal->IncludeDirectoriesBacktraces.insert(
  346. this->Internal->IncludeDirectoriesBacktraces.end(),
  347. parentIncludesBts.begin(), parentIncludesBts.end());
  348. const std::set<std::string> parentSystemIncludes =
  349. this->Makefile->GetSystemIncludeDirectories();
  350. this->SystemIncludeDirectories.insert(parentSystemIncludes.begin(),
  351. parentSystemIncludes.end());
  352. const cmStringRange parentOptions =
  353. this->Makefile->GetCompileOptionsEntries();
  354. const cmBacktraceRange parentOptionsBts =
  355. this->Makefile->GetCompileOptionsBacktraces();
  356. this->Internal->CompileOptionsEntries.insert(
  357. this->Internal->CompileOptionsEntries.end(),
  358. parentOptions.begin(), parentOptions.end());
  359. this->Internal->CompileOptionsBacktraces.insert(
  360. this->Internal->CompileOptionsBacktraces.end(),
  361. parentOptionsBts.begin(), parentOptionsBts.end());
  362. }
  363. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  364. {
  365. this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
  366. this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
  367. this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
  368. }
  369. if(this->TargetTypeValue == cmTarget::EXECUTABLE)
  370. {
  371. this->SetPropertyDefault("ANDROID_GUI", 0);
  372. this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", 0);
  373. }
  374. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
  375. || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
  376. {
  377. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  378. }
  379. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY)
  380. {
  381. this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", 0);
  382. }
  383. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  384. {
  385. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  386. }
  387. // Record current policies for later use.
  388. this->Makefile->RecordPolicies(this->PolicyMap);
  389. if (this->TargetTypeValue == INTERFACE_LIBRARY)
  390. {
  391. // This policy is checked in a few conditions. The properties relevant
  392. // to the policy are always ignored for INTERFACE_LIBRARY targets,
  393. // so ensure that the conditions don't lead to nonsense.
  394. this->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  395. }
  396. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  397. {
  398. this->SetPropertyDefault("JOB_POOL_COMPILE", 0);
  399. this->SetPropertyDefault("JOB_POOL_LINK", 0);
  400. }
  401. }
  402. void CreatePropertyGeneratorExpressions(
  403. std::vector<std::string> const& entries,
  404. std::vector<cmListFileBacktrace> const& backtraces,
  405. std::vector<cmTargetInternals::TargetPropertyEntry*>& items)
  406. {
  407. std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
  408. for (std::vector<std::string>::const_iterator it = entries.begin();
  409. it != entries.end(); ++it, ++btIt)
  410. {
  411. cmGeneratorExpression ge(*btIt);
  412. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
  413. items.push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  414. }
  415. }
  416. void cmTarget::Compute()
  417. {
  418. CreatePropertyGeneratorExpressions(
  419. this->Internal->IncludeDirectoriesEntries,
  420. this->Internal->IncludeDirectoriesBacktraces,
  421. this->Internal->IncludeDirectoriesItems);
  422. CreatePropertyGeneratorExpressions(
  423. this->Internal->CompileOptionsEntries,
  424. this->Internal->CompileOptionsBacktraces,
  425. this->Internal->CompileOptionsItems);
  426. CreatePropertyGeneratorExpressions(
  427. this->Internal->CompileFeaturesEntries,
  428. this->Internal->CompileFeaturesBacktraces,
  429. this->Internal->CompileFeaturesItems);
  430. CreatePropertyGeneratorExpressions(
  431. this->Internal->CompileDefinitionsEntries,
  432. this->Internal->CompileDefinitionsBacktraces,
  433. this->Internal->CompileDefinitionsItems);
  434. }
  435. //----------------------------------------------------------------------------
  436. void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile)
  437. {
  438. if(this->Utilities.insert(u).second && makefile)
  439. {
  440. UtilityBacktraces.insert(std::make_pair(u, makefile->GetBacktrace()));
  441. }
  442. }
  443. //----------------------------------------------------------------------------
  444. cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
  445. const std::string& u) const
  446. {
  447. std::map<std::string, cmListFileBacktrace>::const_iterator i =
  448. this->UtilityBacktraces.find(u);
  449. if(i == this->UtilityBacktraces.end()) return 0;
  450. return &i->second;
  451. }
  452. //----------------------------------------------------------------------------
  453. std::set<cmLinkItem> const& cmTarget::GetUtilityItems() const
  454. {
  455. if(!this->Internal->UtilityItemsDone)
  456. {
  457. this->Internal->UtilityItemsDone = true;
  458. for(std::set<std::string>::const_iterator i = this->Utilities.begin();
  459. i != this->Utilities.end(); ++i)
  460. {
  461. this->Internal->UtilityItems.insert(
  462. cmLinkItem(*i, this->Makefile->FindTargetToUse(*i)));
  463. }
  464. }
  465. return this->Internal->UtilityItems;
  466. }
  467. //----------------------------------------------------------------------------
  468. void cmTarget::FinishConfigure()
  469. {
  470. // Erase any cached link information that might have been comptued
  471. // on-demand during the configuration. This ensures that build
  472. // system generation uses up-to-date information even if other cache
  473. // invalidation code in this source file is buggy.
  474. this->ClearLinkMaps();
  475. #if defined(_WIN32) && !defined(__CYGWIN__)
  476. // Do old-style link dependency analysis only for CM_USE_OLD_VS6.
  477. if(this->Makefile->GetGlobalGenerator()->IsForVS6())
  478. {
  479. this->AnalyzeLibDependenciesForVS6(*this->Makefile);
  480. }
  481. #endif
  482. }
  483. //----------------------------------------------------------------------------
  484. void cmTarget::ClearLinkMaps()
  485. {
  486. this->LinkImplementationLanguageIsContextDependent = true;
  487. this->Internal->LinkImplMap.clear();
  488. this->Internal->LinkInterfaceMap.clear();
  489. this->Internal->LinkInterfaceUsageRequirementsOnlyMap.clear();
  490. this->Internal->SourceFilesMap.clear();
  491. }
  492. //----------------------------------------------------------------------------
  493. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  494. {
  495. return this->Internal->Backtrace;
  496. }
  497. //----------------------------------------------------------------------------
  498. std::string cmTarget::GetSupportDirectory() const
  499. {
  500. std::string dir = this->Makefile->GetCurrentBinaryDirectory();
  501. dir += cmake::GetCMakeFilesDirectory();
  502. dir += "/";
  503. dir += this->Name;
  504. #if defined(__VMS)
  505. dir += "_dir";
  506. #else
  507. dir += ".dir";
  508. #endif
  509. return dir;
  510. }
  511. //----------------------------------------------------------------------------
  512. bool cmTarget::IsExecutableWithExports() const
  513. {
  514. return (this->GetType() == cmTarget::EXECUTABLE &&
  515. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  516. }
  517. //----------------------------------------------------------------------------
  518. bool cmTarget::IsLinkable() const
  519. {
  520. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  521. this->GetType() == cmTarget::SHARED_LIBRARY ||
  522. this->GetType() == cmTarget::MODULE_LIBRARY ||
  523. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  524. this->GetType() == cmTarget::INTERFACE_LIBRARY ||
  525. this->IsExecutableWithExports());
  526. }
  527. //----------------------------------------------------------------------------
  528. bool cmTarget::HasImportLibrary() const
  529. {
  530. return (this->DLLPlatform &&
  531. (this->GetType() == cmTarget::SHARED_LIBRARY ||
  532. this->IsExecutableWithExports()));
  533. }
  534. //----------------------------------------------------------------------------
  535. bool cmTarget::IsFrameworkOnApple() const
  536. {
  537. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  538. this->Makefile->IsOn("APPLE") &&
  539. this->GetPropertyAsBool("FRAMEWORK"));
  540. }
  541. //----------------------------------------------------------------------------
  542. bool cmTarget::IsAppBundleOnApple() const
  543. {
  544. return (this->GetType() == cmTarget::EXECUTABLE &&
  545. this->Makefile->IsOn("APPLE") &&
  546. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  547. }
  548. //----------------------------------------------------------------------------
  549. bool cmTarget::IsCFBundleOnApple() const
  550. {
  551. return (this->GetType() == cmTarget::MODULE_LIBRARY &&
  552. this->Makefile->IsOn("APPLE") &&
  553. this->GetPropertyAsBool("BUNDLE"));
  554. }
  555. //----------------------------------------------------------------------------
  556. bool cmTarget::IsXCTestOnApple() const
  557. {
  558. return (this->IsCFBundleOnApple() &&
  559. this->GetPropertyAsBool("XCTEST"));
  560. }
  561. //----------------------------------------------------------------------------
  562. static bool processSources(cmTarget const* tgt,
  563. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  564. std::vector<std::string> &srcs,
  565. UNORDERED_SET<std::string> &uniqueSrcs,
  566. cmGeneratorExpressionDAGChecker *dagChecker,
  567. std::string const& config, bool debugSources)
  568. {
  569. cmMakefile *mf = tgt->GetMakefile();
  570. bool contextDependent = false;
  571. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  572. it = entries.begin(), end = entries.end(); it != end; ++it)
  573. {
  574. cmLinkImplItem const& item = (*it)->LinkImplItem;
  575. std::string const& targetName = item;
  576. std::vector<std::string> entrySources;
  577. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  578. config,
  579. false,
  580. tgt,
  581. tgt,
  582. dagChecker),
  583. entrySources);
  584. if ((*it)->ge->GetHadContextSensitiveCondition())
  585. {
  586. contextDependent = true;
  587. }
  588. for(std::vector<std::string>::iterator i = entrySources.begin();
  589. i != entrySources.end(); ++i)
  590. {
  591. std::string& src = *i;
  592. cmSourceFile* sf = mf->GetOrCreateSource(src);
  593. std::string e;
  594. std::string fullPath = sf->GetFullPath(&e);
  595. if(fullPath.empty())
  596. {
  597. if(!e.empty())
  598. {
  599. cmake* cm = mf->GetCMakeInstance();
  600. cm->IssueMessage(cmake::FATAL_ERROR, e,
  601. tgt->GetBacktrace());
  602. }
  603. return contextDependent;
  604. }
  605. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str()))
  606. {
  607. std::ostringstream err;
  608. if (!targetName.empty())
  609. {
  610. err << "Target \"" << targetName << "\" contains relative "
  611. "path in its INTERFACE_SOURCES:\n"
  612. " \"" << src << "\"";
  613. }
  614. else
  615. {
  616. err << "Found relative path while evaluating sources of "
  617. "\"" << tgt->GetName() << "\":\n \"" << src << "\"\n";
  618. }
  619. tgt->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, err.str());
  620. return contextDependent;
  621. }
  622. src = fullPath;
  623. }
  624. std::string usedSources;
  625. for(std::vector<std::string>::iterator
  626. li = entrySources.begin(); li != entrySources.end(); ++li)
  627. {
  628. std::string src = *li;
  629. if(uniqueSrcs.insert(src).second)
  630. {
  631. srcs.push_back(src);
  632. if (debugSources)
  633. {
  634. usedSources += " * " + src + "\n";
  635. }
  636. }
  637. }
  638. if (!usedSources.empty())
  639. {
  640. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  641. std::string("Used sources for target ")
  642. + tgt->GetName() + ":\n"
  643. + usedSources, (*it)->ge->GetBacktrace());
  644. }
  645. }
  646. return contextDependent;
  647. }
  648. //----------------------------------------------------------------------------
  649. void cmTarget::GetSourceFiles(std::vector<std::string> &files,
  650. const std::string& config) const
  651. {
  652. assert(this->GetType() != INTERFACE_LIBRARY);
  653. if (!this->Makefile->IsConfigured())
  654. {
  655. // At configure-time, this method can be called as part of getting the
  656. // LOCATION property or to export() a file to be include()d. However
  657. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  658. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  659. // behavior of CMP0024 and CMP0026 only.
  660. typedef cmTargetInternals::TargetPropertyEntry
  661. TargetPropertyEntry;
  662. for(std::vector<TargetPropertyEntry*>::const_iterator
  663. i = this->Internal->SourceEntries.begin();
  664. i != this->Internal->SourceEntries.end(); ++i)
  665. {
  666. std::string entry = (*i)->ge->GetInput();
  667. std::vector<std::string> items;
  668. cmSystemTools::ExpandListArgument(entry, items);
  669. for (std::vector<std::string>::const_iterator
  670. li = items.begin(); li != items.end(); ++li)
  671. {
  672. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  673. (*li)[li->size() - 1] == '>')
  674. {
  675. continue;
  676. }
  677. files.push_back(*li);
  678. }
  679. }
  680. return;
  681. }
  682. std::vector<std::string> debugProperties;
  683. const char *debugProp =
  684. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  685. if (debugProp)
  686. {
  687. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  688. }
  689. bool debugSources = !this->DebugSourcesDone
  690. && std::find(debugProperties.begin(),
  691. debugProperties.end(),
  692. "SOURCES")
  693. != debugProperties.end();
  694. if (this->Makefile->IsConfigured())
  695. {
  696. this->DebugSourcesDone = true;
  697. }
  698. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  699. "SOURCES", 0, 0);
  700. UNORDERED_SET<std::string> uniqueSrcs;
  701. bool contextDependentDirectSources = processSources(this,
  702. this->Internal->SourceEntries,
  703. files,
  704. uniqueSrcs,
  705. &dagChecker,
  706. config,
  707. debugSources);
  708. std::vector<cmTargetInternals::TargetPropertyEntry*>
  709. linkInterfaceSourcesEntries;
  710. this->Internal->AddInterfaceEntries(
  711. this, config, "INTERFACE_SOURCES",
  712. linkInterfaceSourcesEntries);
  713. std::vector<std::string>::size_type numFilesBefore = files.size();
  714. bool contextDependentInterfaceSources = processSources(this,
  715. linkInterfaceSourcesEntries,
  716. files,
  717. uniqueSrcs,
  718. &dagChecker,
  719. config,
  720. debugSources);
  721. if (!contextDependentDirectSources
  722. && !(contextDependentInterfaceSources && numFilesBefore < files.size()))
  723. {
  724. this->LinkImplementationLanguageIsContextDependent = false;
  725. }
  726. cmDeleteAll(linkInterfaceSourcesEntries);
  727. }
  728. //----------------------------------------------------------------------------
  729. bool
  730. cmTarget::GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const
  731. {
  732. std::vector<std::string> configs;
  733. this->Makefile->GetConfigurations(configs);
  734. if (configs.empty())
  735. {
  736. configs.push_back("");
  737. }
  738. std::vector<std::string>::const_iterator it = configs.begin();
  739. const std::string& firstConfig = *it;
  740. this->GetSourceFiles(files, firstConfig);
  741. for ( ; it != configs.end(); ++it)
  742. {
  743. std::vector<cmSourceFile*> configFiles;
  744. this->GetSourceFiles(configFiles, *it);
  745. if (configFiles != files)
  746. {
  747. std::string firstConfigFiles;
  748. const char* sep = "";
  749. for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
  750. fi != files.end(); ++fi)
  751. {
  752. firstConfigFiles += sep;
  753. firstConfigFiles += (*fi)->GetFullPath();
  754. sep = "\n ";
  755. }
  756. std::string thisConfigFiles;
  757. sep = "";
  758. for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
  759. fi != configFiles.end(); ++fi)
  760. {
  761. thisConfigFiles += sep;
  762. thisConfigFiles += (*fi)->GetFullPath();
  763. sep = "\n ";
  764. }
  765. std::ostringstream e;
  766. e << "Target \"" << this->Name << "\" has source files which vary by "
  767. "configuration. This is not supported by the \""
  768. << this->Makefile->GetGlobalGenerator()->GetName()
  769. << "\" generator.\n"
  770. "Config \"" << firstConfig << "\":\n"
  771. " " << firstConfigFiles << "\n"
  772. "Config \"" << *it << "\":\n"
  773. " " << thisConfigFiles << "\n";
  774. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  775. return false;
  776. }
  777. }
  778. return true;
  779. }
  780. //----------------------------------------------------------------------------
  781. void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  782. const std::string& config) const
  783. {
  784. // Lookup any existing link implementation for this configuration.
  785. std::string key = cmSystemTools::UpperCase(config);
  786. if(!this->LinkImplementationLanguageIsContextDependent)
  787. {
  788. files = this->Internal->SourceFilesMap.begin()->second;
  789. return;
  790. }
  791. cmTargetInternals::SourceFilesMapType::iterator
  792. it = this->Internal->SourceFilesMap.find(key);
  793. if(it != this->Internal->SourceFilesMap.end())
  794. {
  795. files = it->second;
  796. }
  797. else
  798. {
  799. std::vector<std::string> srcs;
  800. this->GetSourceFiles(srcs, config);
  801. std::set<cmSourceFile*> emitted;
  802. for(std::vector<std::string>::const_iterator i = srcs.begin();
  803. i != srcs.end(); ++i)
  804. {
  805. cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
  806. if (emitted.insert(sf).second)
  807. {
  808. files.push_back(sf);
  809. }
  810. }
  811. this->Internal->SourceFilesMap[key] = files;
  812. }
  813. }
  814. //----------------------------------------------------------------------------
  815. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  816. {
  817. std::string srcFiles = cmJoin(srcs, ";");
  818. if (!srcFiles.empty())
  819. {
  820. this->Internal->SourceFilesMap.clear();
  821. this->LinkImplementationLanguageIsContextDependent = true;
  822. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  823. cmGeneratorExpression ge(lfbt);
  824. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  825. cge->SetEvaluateForBuildsystem(true);
  826. this->Internal->SourceEntries.push_back(
  827. new cmTargetInternals::TargetPropertyEntry(cge));
  828. }
  829. }
  830. //----------------------------------------------------------------------------
  831. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  832. {
  833. std::string srcFiles;
  834. const char* sep = "";
  835. for(std::vector<std::string>::const_iterator i = srcs.begin();
  836. i != srcs.end(); ++i)
  837. {
  838. std::string filename = *i;
  839. const char* src = filename.c_str();
  840. if(!(src[0] == '$' && src[1] == '<'))
  841. {
  842. if(!filename.empty())
  843. {
  844. filename = this->ProcessSourceItemCMP0049(filename);
  845. if(filename.empty())
  846. {
  847. return;
  848. }
  849. }
  850. this->Makefile->GetOrCreateSource(filename);
  851. }
  852. srcFiles += sep;
  853. srcFiles += filename;
  854. sep = ";";
  855. }
  856. if (!srcFiles.empty())
  857. {
  858. this->Internal->SourceFilesMap.clear();
  859. this->LinkImplementationLanguageIsContextDependent = true;
  860. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  861. cmGeneratorExpression ge(lfbt);
  862. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  863. cge->SetEvaluateForBuildsystem(true);
  864. this->Internal->SourceEntries.push_back(
  865. new cmTargetInternals::TargetPropertyEntry(cge));
  866. }
  867. }
  868. //----------------------------------------------------------------------------
  869. std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
  870. {
  871. std::string src = s;
  872. // For backwards compatibility replace varibles in source names.
  873. // This should eventually be removed.
  874. this->Makefile->ExpandVariablesInString(src);
  875. if (src != s)
  876. {
  877. std::ostringstream e;
  878. bool noMessage = false;
  879. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  880. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0049))
  881. {
  882. case cmPolicies::WARN:
  883. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  884. break;
  885. case cmPolicies::OLD:
  886. noMessage = true;
  887. break;
  888. case cmPolicies::REQUIRED_ALWAYS:
  889. case cmPolicies::REQUIRED_IF_USED:
  890. case cmPolicies::NEW:
  891. messageType = cmake::FATAL_ERROR;
  892. }
  893. if (!noMessage)
  894. {
  895. e << "Legacy variable expansion in source file \""
  896. << s << "\" expanded to \"" << src << "\" in target \""
  897. << this->GetName() << "\". This behavior will be removed in a "
  898. "future version of CMake.";
  899. this->Makefile->IssueMessage(messageType, e.str());
  900. if (messageType == cmake::FATAL_ERROR)
  901. {
  902. return "";
  903. }
  904. }
  905. }
  906. return src;
  907. }
  908. //----------------------------------------------------------------------------
  909. cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
  910. {
  911. std::string src = this->ProcessSourceItemCMP0049(s);
  912. if(!s.empty() && src.empty())
  913. {
  914. return 0;
  915. }
  916. return this->AddSource(src);
  917. }
  918. //----------------------------------------------------------------------------
  919. struct CreateLocation
  920. {
  921. cmMakefile const* Makefile;
  922. CreateLocation(cmMakefile const* mf)
  923. : Makefile(mf)
  924. {
  925. }
  926. cmSourceFileLocation operator()(const std::string& filename)
  927. {
  928. return cmSourceFileLocation(this->Makefile, filename);
  929. }
  930. };
  931. //----------------------------------------------------------------------------
  932. struct LocationMatcher
  933. {
  934. const cmSourceFileLocation& Needle;
  935. LocationMatcher(const cmSourceFileLocation& needle)
  936. : Needle(needle)
  937. {
  938. }
  939. bool operator()(cmSourceFileLocation &loc)
  940. {
  941. return loc.Matches(this->Needle);
  942. }
  943. };
  944. //----------------------------------------------------------------------------
  945. struct TargetPropertyEntryFinder
  946. {
  947. private:
  948. const cmSourceFileLocation& Needle;
  949. public:
  950. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  951. : Needle(needle)
  952. {
  953. }
  954. bool operator()(cmTargetInternals::TargetPropertyEntry* entry)
  955. {
  956. std::vector<std::string> files;
  957. cmSystemTools::ExpandListArgument(entry->ge->GetInput(), files);
  958. std::vector<cmSourceFileLocation> locations(files.size());
  959. std::transform(files.begin(), files.end(), locations.begin(),
  960. CreateLocation(this->Needle.GetMakefile()));
  961. return std::find_if(locations.begin(), locations.end(),
  962. LocationMatcher(this->Needle)) != locations.end();
  963. }
  964. };
  965. //----------------------------------------------------------------------------
  966. cmSourceFile* cmTarget::AddSource(const std::string& src)
  967. {
  968. cmSourceFileLocation sfl(this->Makefile, src);
  969. if (std::find_if(this->Internal->SourceEntries.begin(),
  970. this->Internal->SourceEntries.end(),
  971. TargetPropertyEntryFinder(sfl))
  972. == this->Internal->SourceEntries.end())
  973. {
  974. this->Internal->SourceFilesMap.clear();
  975. this->LinkImplementationLanguageIsContextDependent = true;
  976. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  977. cmGeneratorExpression ge(lfbt);
  978. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  979. cge->SetEvaluateForBuildsystem(true);
  980. this->Internal->SourceEntries.push_back(
  981. new cmTargetInternals::TargetPropertyEntry(cge));
  982. }
  983. if (cmGeneratorExpression::Find(src) != std::string::npos)
  984. {
  985. return 0;
  986. }
  987. return this->Makefile->GetOrCreateSource(src);
  988. }
  989. //----------------------------------------------------------------------------
  990. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  991. const std::string& selfname,
  992. const LinkLibraryVectorType& libs )
  993. {
  994. // Only add on libraries we haven't added on before.
  995. // Assumption: the global link libraries could only grow, never shrink
  996. LinkLibraryVectorType::const_iterator i = libs.begin();
  997. i += this->PrevLinkedLibraries.size();
  998. for( ; i != libs.end(); ++i )
  999. {
  1000. // This is equivalent to the target_link_libraries plain signature.
  1001. this->AddLinkLibrary( mf, selfname, i->first, i->second );
  1002. this->AppendProperty("INTERFACE_LINK_LIBRARIES",
  1003. this->GetDebugGeneratorExpressions(i->first, i->second).c_str());
  1004. }
  1005. this->PrevLinkedLibraries = libs;
  1006. }
  1007. //----------------------------------------------------------------------------
  1008. void cmTarget::AddLinkDirectory(const std::string& d)
  1009. {
  1010. // Make sure we don't add unnecessary search directories.
  1011. if(this->LinkDirectoriesEmmitted.insert(d).second)
  1012. {
  1013. this->LinkDirectories.push_back(d);
  1014. }
  1015. }
  1016. //----------------------------------------------------------------------------
  1017. const std::vector<std::string>& cmTarget::GetLinkDirectories() const
  1018. {
  1019. return this->LinkDirectories;
  1020. }
  1021. //----------------------------------------------------------------------------
  1022. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(
  1023. const std::string& config) const
  1024. {
  1025. // No configuration is always optimized.
  1026. if(config.empty())
  1027. {
  1028. return cmTarget::OPTIMIZED;
  1029. }
  1030. // Get the list of configurations considered to be DEBUG.
  1031. std::vector<std::string> debugConfigs =
  1032. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1033. // Check if any entry in the list matches this configuration.
  1034. std::string configUpper = cmSystemTools::UpperCase(config);
  1035. if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
  1036. debugConfigs.end())
  1037. {
  1038. return cmTarget::DEBUG;
  1039. }
  1040. // The current configuration is not a debug configuration.
  1041. return cmTarget::OPTIMIZED;
  1042. }
  1043. //----------------------------------------------------------------------------
  1044. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  1045. const std::string& target )
  1046. {
  1047. // Clear the dependencies. The cache variable must exist iff we are
  1048. // recording dependency information for this target.
  1049. std::string depname = target;
  1050. depname += "_LIB_DEPENDS";
  1051. if (this->RecordDependencies)
  1052. {
  1053. mf.AddCacheDefinition(depname, "",
  1054. "Dependencies for target", cmState::STATIC);
  1055. }
  1056. else
  1057. {
  1058. if (mf.GetDefinition( depname ))
  1059. {
  1060. std::string message = "Target ";
  1061. message += target;
  1062. message += " has dependency information when it shouldn't.\n";
  1063. message += "Your cache is probably stale. Please remove the entry\n ";
  1064. message += depname;
  1065. message += "\nfrom the cache.";
  1066. cmSystemTools::Error( message.c_str() );
  1067. }
  1068. }
  1069. }
  1070. //----------------------------------------------------------------------------
  1071. bool cmTarget::NameResolvesToFramework(const std::string& libname) const
  1072. {
  1073. return this->Makefile->GetGlobalGenerator()->
  1074. NameResolvesToFramework(libname);
  1075. }
  1076. //----------------------------------------------------------------------------
  1077. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  1078. cmTarget::LinkLibraryType llt) const
  1079. {
  1080. if (llt == GENERAL)
  1081. {
  1082. return value;
  1083. }
  1084. // Get the list of configurations considered to be DEBUG.
  1085. std::vector<std::string> debugConfigs =
  1086. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1087. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  1088. if (debugConfigs.size() > 1)
  1089. {
  1090. for(std::vector<std::string>::const_iterator
  1091. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  1092. {
  1093. configString += ",$<CONFIG:" + *li + ">";
  1094. }
  1095. configString = "$<OR:" + configString + ">";
  1096. }
  1097. if (llt == OPTIMIZED)
  1098. {
  1099. configString = "$<NOT:" + configString + ">";
  1100. }
  1101. return "$<" + configString + ":" + value + ">";
  1102. }
  1103. //----------------------------------------------------------------------------
  1104. static std::string targetNameGenex(const std::string& lib)
  1105. {
  1106. return "$<TARGET_NAME:" + lib + ">";
  1107. }
  1108. //----------------------------------------------------------------------------
  1109. bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
  1110. cmListFileContext const& lfc)
  1111. {
  1112. bool ret = true;
  1113. if (!this->TLLCommands.empty())
  1114. {
  1115. if (this->TLLCommands.back().first != signature)
  1116. {
  1117. ret = false;
  1118. }
  1119. }
  1120. if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc)
  1121. {
  1122. this->TLLCommands.push_back(std::make_pair(signature, lfc));
  1123. }
  1124. return ret;
  1125. }
  1126. //----------------------------------------------------------------------------
  1127. void cmTarget::GetTllSignatureTraces(std::ostringstream &s,
  1128. TLLSignature sig) const
  1129. {
  1130. const char *sigString = (sig == cmTarget::KeywordTLLSignature ? "keyword"
  1131. : "plain");
  1132. s << "The uses of the " << sigString << " signature are here:\n";
  1133. typedef std::vector<std::pair<TLLSignature, cmListFileContext> > Container;
  1134. cmOutputConverter converter(this->GetMakefile()->GetStateSnapshot());
  1135. for(Container::const_iterator it = this->TLLCommands.begin();
  1136. it != this->TLLCommands.end(); ++it)
  1137. {
  1138. if (it->first == sig)
  1139. {
  1140. cmListFileContext lfc = it->second;
  1141. lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
  1142. s << " * " << lfc << std::endl;
  1143. }
  1144. }
  1145. }
  1146. //----------------------------------------------------------------------------
  1147. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  1148. const std::string& target,
  1149. const std::string& lib,
  1150. LinkLibraryType llt)
  1151. {
  1152. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  1153. {
  1154. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  1155. const std::string libName = (isNonImportedTarget && llt != GENERAL)
  1156. ? targetNameGenex(lib)
  1157. : lib;
  1158. this->AppendProperty("LINK_LIBRARIES",
  1159. this->GetDebugGeneratorExpressions(libName,
  1160. llt).c_str());
  1161. }
  1162. if (cmGeneratorExpression::Find(lib) != std::string::npos
  1163. || (tgt && tgt->GetType() == INTERFACE_LIBRARY)
  1164. || (target == lib ))
  1165. {
  1166. return;
  1167. }
  1168. cmTarget::LibraryID tmp;
  1169. tmp.first = lib;
  1170. tmp.second = llt;
  1171. #if defined(_WIN32) && !defined(__CYGWIN__)
  1172. this->LinkLibrariesForVS6.push_back( tmp );
  1173. #endif
  1174. this->OriginalLinkLibraries.push_back(tmp);
  1175. this->ClearLinkMaps();
  1176. // Add the explicit dependency information for this target. This is
  1177. // simply a set of libraries separated by ";". There should always
  1178. // be a trailing ";". These library names are not canonical, in that
  1179. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  1180. // We shouldn't remove duplicates here because external libraries
  1181. // may be purposefully duplicated to handle recursive dependencies,
  1182. // and we removing one instance will break the link line. Duplicates
  1183. // will be appropriately eliminated at emit time.
  1184. if(this->RecordDependencies)
  1185. {
  1186. std::string targetEntry = target;
  1187. targetEntry += "_LIB_DEPENDS";
  1188. std::string dependencies;
  1189. const char* old_val = mf.GetDefinition( targetEntry );
  1190. if( old_val )
  1191. {
  1192. dependencies += old_val;
  1193. }
  1194. switch (llt)
  1195. {
  1196. case cmTarget::GENERAL:
  1197. dependencies += "general";
  1198. break;
  1199. case cmTarget::DEBUG:
  1200. dependencies += "debug";
  1201. break;
  1202. case cmTarget::OPTIMIZED:
  1203. dependencies += "optimized";
  1204. break;
  1205. }
  1206. dependencies += ";";
  1207. dependencies += lib;
  1208. dependencies += ";";
  1209. mf.AddCacheDefinition( targetEntry, dependencies.c_str(),
  1210. "Dependencies for the target",
  1211. cmState::STATIC );
  1212. }
  1213. }
  1214. //----------------------------------------------------------------------------
  1215. void
  1216. cmTarget::AddSystemIncludeDirectories(const std::set<std::string> &incs)
  1217. {
  1218. this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  1219. }
  1220. #if defined(_WIN32) && !defined(__CYGWIN__)
  1221. //----------------------------------------------------------------------------
  1222. void
  1223. cmTarget::AnalyzeLibDependenciesForVS6( const cmMakefile& mf )
  1224. {
  1225. // There are two key parts of the dependency analysis: (1)
  1226. // determining the libraries in the link line, and (2) constructing
  1227. // the dependency graph for those libraries.
  1228. //
  1229. // The latter is done using the cache entries that record the
  1230. // dependencies of each library.
  1231. //
  1232. // The former is a more thorny issue, since it is not clear how to
  1233. // determine if two libraries listed on the link line refer to the a
  1234. // single library or not. For example, consider the link "libraries"
  1235. // /usr/lib/libtiff.so -ltiff
  1236. // Is this one library or two? The solution implemented here is the
  1237. // simplest (and probably the only practical) one: two libraries are
  1238. // the same if their "link strings" are identical. Thus, the two
  1239. // libraries above are considered distinct. This also means that for
  1240. // dependency analysis to be effective, the CMake user must specify
  1241. // libraries build by his project without using any linker flags or
  1242. // file extensions. That is,
  1243. // LINK_LIBRARIES( One Two )
  1244. // instead of
  1245. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  1246. // The former is probably what most users would do, but it never
  1247. // hurts to document the assumptions. :-) Therefore, in the analysis
  1248. // code, the "canonical name" of a library is simply its name as
  1249. // given to a LINK_LIBRARIES command.
  1250. //
  1251. // Also, we will leave the original link line intact; we will just add any
  1252. // dependencies that were missing.
  1253. //
  1254. // There is a problem with recursive external libraries
  1255. // (i.e. libraries with no dependency information that are
  1256. // recursively dependent). We must make sure that the we emit one of
  1257. // the libraries twice to satisfy the recursion, but we shouldn't
  1258. // emit it more times than necessary. In particular, we must make
  1259. // sure that handling this improbable case doesn't cost us when
  1260. // dealing with the common case of non-recursive libraries. The
  1261. // solution is to assume that the recursion is satisfied at one node
  1262. // of the dependency tree. To illustrate, assume libA and libB are
  1263. // extrenal and mutually dependent. Suppose libX depends on
  1264. // libA, and libY on libA and libX. Then
  1265. // TARGET_LINK_LIBRARIES( Y X A B A )
  1266. // TARGET_LINK_LIBRARIES( X A B A )
  1267. // TARGET_LINK_LIBRARIES( Exec Y )
  1268. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  1269. // specify the dependencies, since the mutual dependency of A and B
  1270. // is resolved *every time libA is specified*.
  1271. //
  1272. // Something like
  1273. // TARGET_LINK_LIBRARIES( Y X A B A )
  1274. // TARGET_LINK_LIBRARIES( X A B )
  1275. // TARGET_LINK_LIBRARIES( Exec Y )
  1276. // would result in "-lY -lX -lA -lB", and the mutual dependency
  1277. // information is lost. This is because in some case (Y), the mutual
  1278. // dependency of A and B is listed, while in another other case (X),
  1279. // it is not. Depending on which line actually emits A, the mutual
  1280. // dependency may or may not be on the final link line. We can't
  1281. // handle this pathalogical case cleanly without emitting extra
  1282. // libraries for the normal cases. Besides, the dependency
  1283. // information for X is wrong anyway: if we build an executable
  1284. // depending on X alone, we would not have the mutual dependency on
  1285. // A and B resolved.
  1286. //
  1287. // IMPROVEMENTS:
  1288. // -- The current algorithm will not always pick the "optimal" link line
  1289. // when recursive dependencies are present. It will instead break the
  1290. // cycles at an aribtrary point. The majority of projects won't have
  1291. // cyclic dependencies, so this is probably not a big deal. Note that
  1292. // the link line is always correct, just not necessary optimal.
  1293. {
  1294. // Expand variables in link library names. This is for backwards
  1295. // compatibility with very early CMake versions and should
  1296. // eventually be removed. This code was moved here from the end of
  1297. // old source list processing code which was called just before this
  1298. // method.
  1299. for(LinkLibraryVectorType::iterator p = this->LinkLibrariesForVS6.begin();
  1300. p != this->LinkLibrariesForVS6.end(); ++p)
  1301. {
  1302. this->Makefile->ExpandVariablesInString(p->first, true, true);
  1303. }
  1304. }
  1305. // The dependency map.
  1306. DependencyMap dep_map;
  1307. // 1. Build the dependency graph
  1308. //
  1309. for(LinkLibraryVectorType::reverse_iterator lib
  1310. = this->LinkLibrariesForVS6.rbegin();
  1311. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  1312. {
  1313. this->GatherDependenciesForVS6( mf, *lib, dep_map);
  1314. }
  1315. // 2. Remove any dependencies that are already satisfied in the original
  1316. // link line.
  1317. //
  1318. for(LinkLibraryVectorType::iterator lib = this->LinkLibrariesForVS6.begin();
  1319. lib != this->LinkLibrariesForVS6.end(); ++lib)
  1320. {
  1321. for( LinkLibraryVectorType::iterator lib2 = lib;
  1322. lib2 != this->LinkLibrariesForVS6.end(); ++lib2)
  1323. {
  1324. this->DeleteDependencyForVS6( dep_map, *lib, *lib2);
  1325. }
  1326. }
  1327. // 3. Create the new link line by simply emitting any dependencies that are
  1328. // missing. Start from the back and keep adding.
  1329. //
  1330. std::set<DependencyMap::key_type> done, visited;
  1331. std::vector<DependencyMap::key_type> newLinkLibrariesForVS6;
  1332. for(LinkLibraryVectorType::reverse_iterator lib =
  1333. this->LinkLibrariesForVS6.rbegin();
  1334. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  1335. {
  1336. // skip zero size library entries, this may happen
  1337. // if a variable expands to nothing.
  1338. if (!lib->first.empty())
  1339. {
  1340. this->EmitForVS6( *lib, dep_map, done, visited, newLinkLibrariesForVS6 );
  1341. }
  1342. }
  1343. // 4. Add the new libraries to the link line.
  1344. //
  1345. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  1346. newLinkLibrariesForVS6.rbegin();
  1347. k != newLinkLibrariesForVS6.rend(); ++k )
  1348. {
  1349. // get the llt from the dep_map
  1350. this->LinkLibrariesForVS6.push_back( std::make_pair(k->first,k->second) );
  1351. }
  1352. this->LinkLibrariesForVS6Analyzed = true;
  1353. }
  1354. //----------------------------------------------------------------------------
  1355. void cmTarget::InsertDependencyForVS6( DependencyMap& depMap,
  1356. const LibraryID& lib,
  1357. const LibraryID& dep)
  1358. {
  1359. depMap[lib].push_back(dep);
  1360. }
  1361. //----------------------------------------------------------------------------
  1362. void cmTarget::DeleteDependencyForVS6( DependencyMap& depMap,
  1363. const LibraryID& lib,
  1364. const LibraryID& dep)
  1365. {
  1366. // Make sure there is an entry in the map for lib. If so, delete all
  1367. // dependencies to dep. There may be repeated entries because of
  1368. // external libraries that are specified multiple times.
  1369. DependencyMap::iterator map_itr = depMap.find( lib );
  1370. if( map_itr != depMap.end() )
  1371. {
  1372. DependencyList& depList = map_itr->second;
  1373. DependencyList::iterator begin =
  1374. std::remove(depList.begin(), depList.end(), dep);
  1375. depList.erase(begin, depList.end());
  1376. }
  1377. }
  1378. //----------------------------------------------------------------------------
  1379. void cmTarget::EmitForVS6(const LibraryID lib,
  1380. const DependencyMap& dep_map,
  1381. std::set<LibraryID>& emitted,
  1382. std::set<LibraryID>& visited,
  1383. DependencyList& link_line )
  1384. {
  1385. // It's already been emitted
  1386. if( emitted.find(lib) != emitted.end() )
  1387. {
  1388. return;
  1389. }
  1390. // Emit the dependencies only if this library node hasn't been
  1391. // visited before. If it has, then we have a cycle. The recursion
  1392. // that got us here should take care of everything.
  1393. if( visited.insert(lib).second )
  1394. {
  1395. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  1396. {
  1397. const DependencyList& dep_on = dep_map.find( lib )->second;
  1398. DependencyList::const_reverse_iterator i;
  1399. // To cater for recursive external libraries, we must emit
  1400. // duplicates on this link line *unless* they were emitted by
  1401. // some other node, in which case we assume that the recursion
  1402. // was resolved then. We making the simplifying assumption that
  1403. // any duplicates on a single link line are on purpose, and must
  1404. // be preserved.
  1405. // This variable will keep track of the libraries that were
  1406. // emitted directly from the current node, and not from a
  1407. // recursive call. This way, if we come across a library that
  1408. // has already been emitted, we repeat it iff it has been
  1409. // emitted here.
  1410. std::set<DependencyMap::key_type> emitted_here;
  1411. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  1412. {
  1413. if( emitted_here.find(*i) != emitted_here.end() )
  1414. {
  1415. // a repeat. Must emit.
  1416. emitted.insert(*i);
  1417. link_line.push_back( *i );
  1418. }
  1419. else
  1420. {
  1421. // Emit only if no-one else has
  1422. if( emitted.find(*i) == emitted.end() )
  1423. {
  1424. // emit dependencies
  1425. this->EmitForVS6( *i, dep_map, emitted, visited, link_line );
  1426. // emit self
  1427. emitted.insert(*i);
  1428. emitted_here.insert(*i);
  1429. link_line.push_back( *i );
  1430. }
  1431. }
  1432. }
  1433. }
  1434. }
  1435. }
  1436. //----------------------------------------------------------------------------
  1437. void cmTarget::GatherDependenciesForVS6( const cmMakefile& mf,
  1438. const LibraryID& lib,
  1439. DependencyMap& dep_map)
  1440. {
  1441. // If the library is already in the dependency map, then it has
  1442. // already been fully processed.
  1443. if( dep_map.find(lib) != dep_map.end() )
  1444. {
  1445. return;
  1446. }
  1447. const char* deps = mf.GetDefinition( lib.first+"_LIB_DEPENDS" );
  1448. if( deps && strcmp(deps,"") != 0 )
  1449. {
  1450. // Make sure this library is in the map, even if it has an empty
  1451. // set of dependencies. This distinguishes the case of explicitly
  1452. // no dependencies with that of unspecified dependencies.
  1453. dep_map[lib];
  1454. // Parse the dependency information, which is a set of
  1455. // type, library pairs separated by ";". There is always a trailing ";".
  1456. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  1457. std::string depline = deps;
  1458. std::string::size_type start = 0;
  1459. std::string::size_type end;
  1460. end = depline.find( ";", start );
  1461. while( end != std::string::npos )
  1462. {
  1463. std::string l = depline.substr( start, end-start );
  1464. if(!l.empty())
  1465. {
  1466. if (l == "debug")
  1467. {
  1468. llt = cmTarget::DEBUG;
  1469. }
  1470. else if (l == "optimized")
  1471. {
  1472. llt = cmTarget::OPTIMIZED;
  1473. }
  1474. else if (l == "general")
  1475. {
  1476. llt = cmTarget::GENERAL;
  1477. }
  1478. else
  1479. {
  1480. LibraryID lib2(l,llt);
  1481. this->InsertDependencyForVS6( dep_map, lib, lib2);
  1482. this->GatherDependenciesForVS6( mf, lib2, dep_map);
  1483. llt = cmTarget::GENERAL;
  1484. }
  1485. }
  1486. start = end+1; // skip the ;
  1487. end = depline.find( ";", start );
  1488. }
  1489. // cannot depend on itself
  1490. this->DeleteDependencyForVS6( dep_map, lib, lib);
  1491. }
  1492. }
  1493. #endif
  1494. //----------------------------------------------------------------------------
  1495. static bool whiteListedInterfaceProperty(const std::string& prop)
  1496. {
  1497. if(cmHasLiteralPrefix(prop, "INTERFACE_"))
  1498. {
  1499. return true;
  1500. }
  1501. static UNORDERED_SET<std::string> builtIns;
  1502. if (builtIns.empty())
  1503. {
  1504. builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
  1505. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  1506. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  1507. builtIns.insert("COMPATIBLE_INTERFACE_STRING");
  1508. builtIns.insert("EXPORT_NAME");
  1509. builtIns.insert("IMPORTED");
  1510. builtIns.insert("NAME");
  1511. builtIns.insert("TYPE");
  1512. }
  1513. if (builtIns.count(prop))
  1514. {
  1515. return true;
  1516. }
  1517. if (cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_"))
  1518. {
  1519. return true;
  1520. }
  1521. return false;
  1522. }
  1523. //----------------------------------------------------------------------------
  1524. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1525. {
  1526. if (this->GetType() == INTERFACE_LIBRARY
  1527. && !whiteListedInterfaceProperty(prop))
  1528. {
  1529. std::ostringstream e;
  1530. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1531. "The property \"" << prop << "\" is not allowed.";
  1532. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1533. return;
  1534. }
  1535. else if (prop == "NAME")
  1536. {
  1537. std::ostringstream e;
  1538. e << "NAME property is read-only\n";
  1539. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1540. return;
  1541. }
  1542. else if(prop == "INCLUDE_DIRECTORIES")
  1543. {
  1544. this->Internal->IncludeDirectoriesEntries.clear();
  1545. this->Internal->IncludeDirectoriesBacktraces.clear();
  1546. this->Internal->IncludeDirectoriesEntries.push_back(value);
  1547. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1548. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  1549. }
  1550. else if(prop == "COMPILE_OPTIONS")
  1551. {
  1552. this->Internal->CompileOptionsEntries.clear();
  1553. this->Internal->CompileOptionsBacktraces.clear();
  1554. this->Internal->CompileOptionsEntries.push_back(value);
  1555. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1556. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  1557. }
  1558. else if(prop == "COMPILE_FEATURES")
  1559. {
  1560. this->Internal->CompileFeaturesEntries.clear();
  1561. this->Internal->CompileFeaturesBacktraces.clear();
  1562. this->Internal->CompileFeaturesEntries.push_back(value);
  1563. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1564. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  1565. }
  1566. else if(prop == "COMPILE_DEFINITIONS")
  1567. {
  1568. this->Internal->CompileDefinitionsEntries.clear();
  1569. this->Internal->CompileDefinitionsBacktraces.clear();
  1570. this->Internal->CompileDefinitionsEntries.push_back(value);
  1571. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1572. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  1573. }
  1574. else if(prop == "EXPORT_NAME" && this->IsImported())
  1575. {
  1576. std::ostringstream e;
  1577. e << "EXPORT_NAME property can't be set on imported targets (\""
  1578. << this->Name << "\")\n";
  1579. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1580. }
  1581. else if (prop == "LINK_LIBRARIES")
  1582. {
  1583. this->Internal->LinkImplementationPropertyEntries.clear();
  1584. if (value)
  1585. {
  1586. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1587. cmValueWithOrigin entry(value, lfbt);
  1588. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1589. }
  1590. }
  1591. else if (prop == "SOURCES")
  1592. {
  1593. if(this->IsImported())
  1594. {
  1595. std::ostringstream e;
  1596. e << "SOURCES property can't be set on imported targets (\""
  1597. << this->Name << "\")\n";
  1598. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1599. return;
  1600. }
  1601. this->Internal->SourceFilesMap.clear();
  1602. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1603. cmGeneratorExpression ge(lfbt);
  1604. this->Internal->SourceEntries.clear();
  1605. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1606. this->Internal->SourceEntries.push_back(
  1607. new cmTargetInternals::TargetPropertyEntry(cge));
  1608. }
  1609. else
  1610. {
  1611. this->Properties.SetProperty(prop, value);
  1612. this->MaybeInvalidatePropertyCache(prop);
  1613. }
  1614. }
  1615. //----------------------------------------------------------------------------
  1616. void cmTarget::AppendProperty(const std::string& prop, const char* value,
  1617. bool asString)
  1618. {
  1619. if (this->GetType() == INTERFACE_LIBRARY
  1620. && !whiteListedInterfaceProperty(prop))
  1621. {
  1622. std::ostringstream e;
  1623. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1624. "The property \"" << prop << "\" is not allowed.";
  1625. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1626. return;
  1627. }
  1628. else if (prop == "NAME")
  1629. {
  1630. std::ostringstream e;
  1631. e << "NAME property is read-only\n";
  1632. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1633. return;
  1634. }
  1635. else if(prop == "INCLUDE_DIRECTORIES")
  1636. {
  1637. this->Internal->IncludeDirectoriesEntries.push_back(value);
  1638. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1639. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  1640. }
  1641. else if(prop == "COMPILE_OPTIONS")
  1642. {
  1643. this->Internal->CompileOptionsEntries.push_back(value);
  1644. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1645. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  1646. }
  1647. else if(prop == "COMPILE_FEATURES")
  1648. {
  1649. this->Internal->CompileFeaturesEntries.push_back(value);
  1650. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1651. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  1652. }
  1653. else if(prop == "COMPILE_DEFINITIONS")
  1654. {
  1655. this->Internal->CompileDefinitionsEntries.push_back(value);
  1656. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1657. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  1658. }
  1659. else if(prop == "EXPORT_NAME" && this->IsImported())
  1660. {
  1661. std::ostringstream e;
  1662. e << "EXPORT_NAME property can't be set on imported targets (\""
  1663. << this->Name << "\")\n";
  1664. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1665. }
  1666. else if (prop == "LINK_LIBRARIES")
  1667. {
  1668. if (value)
  1669. {
  1670. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1671. cmValueWithOrigin entry(value, lfbt);
  1672. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1673. }
  1674. }
  1675. else if (prop == "SOURCES")
  1676. {
  1677. if(this->IsImported())
  1678. {
  1679. std::ostringstream e;
  1680. e << "SOURCES property can't be set on imported targets (\""
  1681. << this->Name << "\")\n";
  1682. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1683. return;
  1684. }
  1685. this->Internal->SourceFilesMap.clear();
  1686. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1687. cmGeneratorExpression ge(lfbt);
  1688. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1689. this->Internal->SourceEntries.push_back(
  1690. new cmTargetInternals::TargetPropertyEntry(cge));
  1691. }
  1692. else
  1693. {
  1694. this->Properties.AppendProperty(prop, value, asString);
  1695. this->MaybeInvalidatePropertyCache(prop);
  1696. }
  1697. }
  1698. //----------------------------------------------------------------------------
  1699. std::string cmTarget::GetExportName() const
  1700. {
  1701. const char *exportName = this->GetProperty("EXPORT_NAME");
  1702. if (exportName && *exportName)
  1703. {
  1704. if (!cmGeneratorExpression::IsValidTargetName(exportName))
  1705. {
  1706. std::ostringstream e;
  1707. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  1708. << this->GetName() << "\": is not valid.";
  1709. cmSystemTools::Error(e.str().c_str());
  1710. return "";
  1711. }
  1712. return exportName;
  1713. }
  1714. return this->GetName();
  1715. }
  1716. //----------------------------------------------------------------------------
  1717. void cmTarget::AppendBuildInterfaceIncludes()
  1718. {
  1719. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  1720. this->GetType() != cmTarget::STATIC_LIBRARY &&
  1721. this->GetType() != cmTarget::MODULE_LIBRARY &&
  1722. this->GetType() != cmTarget::INTERFACE_LIBRARY &&
  1723. !this->IsExecutableWithExports())
  1724. {
  1725. return;
  1726. }
  1727. if (this->BuildInterfaceIncludesAppended)
  1728. {
  1729. return;
  1730. }
  1731. this->BuildInterfaceIncludesAppended = true;
  1732. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
  1733. {
  1734. const char *binDir = this->Makefile->GetCurrentBinaryDirectory();
  1735. const char *srcDir = this->Makefile->GetCurrentSourceDirectory();
  1736. const std::string dirs = std::string(binDir ? binDir : "")
  1737. + std::string(binDir ? ";" : "")
  1738. + std::string(srcDir ? srcDir : "");
  1739. if (!dirs.empty())
  1740. {
  1741. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1742. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  1743. }
  1744. }
  1745. }
  1746. //----------------------------------------------------------------------------
  1747. void cmTarget::InsertInclude(std::string const& entry,
  1748. cmListFileBacktrace const& bt,
  1749. bool before)
  1750. {
  1751. std::vector<std::string>::iterator position =
  1752. before ? this->Internal->IncludeDirectoriesEntries.begin()
  1753. : this->Internal->IncludeDirectoriesEntries.end();
  1754. std::vector<cmListFileBacktrace>::iterator btPosition =
  1755. before ? this->Internal->IncludeDirectoriesBacktraces.begin()
  1756. : this->Internal->IncludeDirectoriesBacktraces.end();
  1757. this->Internal->IncludeDirectoriesEntries.insert(position, entry);
  1758. this->Internal->IncludeDirectoriesBacktraces.insert(btPosition, bt);
  1759. }
  1760. //----------------------------------------------------------------------------
  1761. void cmTarget::InsertCompileOption(std::string const& entry,
  1762. cmListFileBacktrace const& bt,
  1763. bool before)
  1764. {
  1765. std::vector<std::string>::iterator position =
  1766. before ? this->Internal->CompileOptionsEntries.begin()
  1767. : this->Internal->CompileOptionsEntries.end();
  1768. std::vector<cmListFileBacktrace>::iterator btPosition =
  1769. before ? this->Internal->CompileOptionsBacktraces.begin()
  1770. : this->Internal->CompileOptionsBacktraces.end();
  1771. this->Internal->CompileOptionsEntries.insert(position, entry);
  1772. this->Internal->CompileOptionsBacktraces.insert(btPosition, bt);
  1773. }
  1774. //----------------------------------------------------------------------------
  1775. void cmTarget::InsertCompileDefinition(std::string const& entry,
  1776. cmListFileBacktrace const& bt)
  1777. {
  1778. this->Internal->CompileDefinitionsEntries.push_back(entry);
  1779. this->Internal->CompileDefinitionsBacktraces.push_back(bt);
  1780. }
  1781. //----------------------------------------------------------------------------
  1782. static void processIncludeDirectories(cmTarget const* tgt,
  1783. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1784. std::vector<std::string> &includes,
  1785. UNORDERED_SET<std::string> &uniqueIncludes,
  1786. cmGeneratorExpressionDAGChecker *dagChecker,
  1787. const std::string& config, bool debugIncludes,
  1788. const std::string& language)
  1789. {
  1790. cmMakefile *mf = tgt->GetMakefile();
  1791. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  1792. it = entries.begin(), end = entries.end(); it != end; ++it)
  1793. {
  1794. cmLinkImplItem const& item = (*it)->LinkImplItem;
  1795. std::string const& targetName = item;
  1796. bool const fromImported = item.Target && item.Target->IsImported();
  1797. bool const checkCMP0027 = item.FromGenex;
  1798. std::vector<std::string> entryIncludes;
  1799. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1800. config,
  1801. false,
  1802. tgt,
  1803. dagChecker, language),
  1804. entryIncludes);
  1805. std::string usedIncludes;
  1806. for(std::vector<std::string>::iterator
  1807. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  1808. {
  1809. if (fromImported
  1810. && !cmSystemTools::FileExists(li->c_str()))
  1811. {
  1812. std::ostringstream e;
  1813. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1814. if (checkCMP0027)
  1815. {
  1816. switch(tgt->GetPolicyStatusCMP0027())
  1817. {
  1818. case cmPolicies::WARN:
  1819. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  1820. case cmPolicies::OLD:
  1821. messageType = cmake::AUTHOR_WARNING;
  1822. break;
  1823. case cmPolicies::REQUIRED_ALWAYS:
  1824. case cmPolicies::REQUIRED_IF_USED:
  1825. case cmPolicies::NEW:
  1826. break;
  1827. }
  1828. }
  1829. e << "Imported target \"" << targetName << "\" includes "
  1830. "non-existent path\n \"" << *li << "\"\nin its "
  1831. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  1832. "* The path was deleted, renamed, or moved to another "
  1833. "location.\n"
  1834. "* An install or uninstall procedure did not complete "
  1835. "successfully.\n"
  1836. "* The installation package was faulty and references files it "
  1837. "does not provide.\n";
  1838. tgt->GetMakefile()->IssueMessage(messageType, e.str());
  1839. return;
  1840. }
  1841. if (!cmSystemTools::FileIsFullPath(li->c_str()))
  1842. {
  1843. std::ostringstream e;
  1844. bool noMessage = false;
  1845. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1846. if (!targetName.empty())
  1847. {
  1848. e << "Target \"" << targetName << "\" contains relative "
  1849. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  1850. " \"" << *li << "\"";
  1851. }
  1852. else
  1853. {
  1854. switch(tgt->GetPolicyStatusCMP0021())
  1855. {
  1856. case cmPolicies::WARN:
  1857. {
  1858. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  1859. messageType = cmake::AUTHOR_WARNING;
  1860. }
  1861. break;
  1862. case cmPolicies::OLD:
  1863. noMessage = true;
  1864. case cmPolicies::REQUIRED_IF_USED:
  1865. case cmPolicies::REQUIRED_ALWAYS:
  1866. case cmPolicies::NEW:
  1867. // Issue the fatal message.
  1868. break;
  1869. }
  1870. e << "Found relative path while evaluating include directories of "
  1871. "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  1872. }
  1873. if (!noMessage)
  1874. {
  1875. tgt->GetMakefile()->IssueMessage(messageType, e.str());
  1876. if (messageType == cmake::FATAL_ERROR)
  1877. {
  1878. return;
  1879. }
  1880. }
  1881. }
  1882. if (!cmSystemTools::IsOff(li->c_str()))
  1883. {
  1884. cmSystemTools::ConvertToUnixSlashes(*li);
  1885. }
  1886. std::string inc = *li;
  1887. if(uniqueIncludes.insert(inc).second)
  1888. {
  1889. includes.push_back(inc);
  1890. if (debugIncludes)
  1891. {
  1892. usedIncludes += " * " + inc + "\n";
  1893. }
  1894. }
  1895. }
  1896. if (!usedIncludes.empty())
  1897. {
  1898. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  1899. std::string("Used includes for target ")
  1900. + tgt->GetName() + ":\n"
  1901. + usedIncludes, (*it)->ge->GetBacktrace());
  1902. }
  1903. }
  1904. }
  1905. //----------------------------------------------------------------------------
  1906. std::vector<std::string>
  1907. cmTarget::GetIncludeDirectories(const std::string& config,
  1908. const std::string& language) const
  1909. {
  1910. std::vector<std::string> includes;
  1911. UNORDERED_SET<std::string> uniqueIncludes;
  1912. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  1913. "INCLUDE_DIRECTORIES", 0, 0);
  1914. std::vector<std::string> debugProperties;
  1915. const char *debugProp =
  1916. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  1917. if (debugProp)
  1918. {
  1919. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  1920. }
  1921. bool debugIncludes = !this->DebugIncludesDone
  1922. && std::find(debugProperties.begin(),
  1923. debugProperties.end(),
  1924. "INCLUDE_DIRECTORIES")
  1925. != debugProperties.end();
  1926. if (this->Makefile->IsConfigured())
  1927. {
  1928. this->DebugIncludesDone = true;
  1929. }
  1930. processIncludeDirectories(this,
  1931. this->Internal->IncludeDirectoriesItems,
  1932. includes,
  1933. uniqueIncludes,
  1934. &dagChecker,
  1935. config,
  1936. debugIncludes,
  1937. language);
  1938. std::vector<cmTargetInternals::TargetPropertyEntry*>
  1939. linkInterfaceIncludeDirectoriesEntries;
  1940. this->Internal->AddInterfaceEntries(
  1941. this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  1942. linkInterfaceIncludeDirectoriesEntries);
  1943. if(this->Makefile->IsOn("APPLE"))
  1944. {
  1945. cmLinkImplementationLibraries const* impl =
  1946. this->GetLinkImplementationLibraries(config);
  1947. for(std::vector<cmLinkImplItem>::const_iterator
  1948. it = impl->Libraries.begin();
  1949. it != impl->Libraries.end(); ++it)
  1950. {
  1951. std::string libDir = cmSystemTools::CollapseFullPath(*it);
  1952. static cmsys::RegularExpression
  1953. frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  1954. if(!frameworkCheck.find(libDir))
  1955. {
  1956. continue;
  1957. }
  1958. libDir = frameworkCheck.match(1);
  1959. cmGeneratorExpression ge;
  1960. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1961. ge.Parse(libDir.c_str());
  1962. linkInterfaceIncludeDirectoriesEntries
  1963. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  1964. }
  1965. }
  1966. processIncludeDirectories(this,
  1967. linkInterfaceIncludeDirectoriesEntries,
  1968. includes,
  1969. uniqueIncludes,
  1970. &dagChecker,
  1971. config,
  1972. debugIncludes,
  1973. language);
  1974. cmDeleteAll(linkInterfaceIncludeDirectoriesEntries);
  1975. return includes;
  1976. }
  1977. //----------------------------------------------------------------------------
  1978. static void processCompileOptionsInternal(cmTarget const* tgt,
  1979. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1980. std::vector<std::string> &options,
  1981. UNORDERED_SET<std::string> &uniqueOptions,
  1982. cmGeneratorExpressionDAGChecker *dagChecker,
  1983. const std::string& config, bool debugOptions, const char *logName,
  1984. std::string const& language)
  1985. {
  1986. cmMakefile *mf = tgt->GetMakefile();
  1987. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  1988. it = entries.begin(), end = entries.end(); it != end; ++it)
  1989. {
  1990. std::vector<std::string> entryOptions;
  1991. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1992. config,
  1993. false,
  1994. tgt,
  1995. dagChecker,
  1996. language),
  1997. entryOptions);
  1998. std::string usedOptions;
  1999. for(std::vector<std::string>::iterator
  2000. li = entryOptions.begin(); li != entryOptions.end(); ++li)
  2001. {
  2002. std::string const& opt = *li;
  2003. if(uniqueOptions.insert(opt).second)
  2004. {
  2005. options.push_back(opt);
  2006. if (debugOptions)
  2007. {
  2008. usedOptions += " * " + opt + "\n";
  2009. }
  2010. }
  2011. }
  2012. if (!usedOptions.empty())
  2013. {
  2014. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2015. std::string("Used compile ") + logName
  2016. + std::string(" for target ")
  2017. + tgt->GetName() + ":\n"
  2018. + usedOptions, (*it)->ge->GetBacktrace());
  2019. }
  2020. }
  2021. }
  2022. //----------------------------------------------------------------------------
  2023. static void processCompileOptions(cmTarget const* tgt,
  2024. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2025. std::vector<std::string> &options,
  2026. UNORDERED_SET<std::string> &uniqueOptions,
  2027. cmGeneratorExpressionDAGChecker *dagChecker,
  2028. const std::string& config, bool debugOptions,
  2029. std::string const& language)
  2030. {
  2031. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2032. dagChecker, config, debugOptions, "options",
  2033. language);
  2034. }
  2035. //----------------------------------------------------------------------------
  2036. void cmTarget::GetCompileOptions(std::vector<std::string> &result,
  2037. const std::string& config,
  2038. const std::string& language) const
  2039. {
  2040. UNORDERED_SET<std::string> uniqueOptions;
  2041. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2042. "COMPILE_OPTIONS", 0, 0);
  2043. std::vector<std::string> debugProperties;
  2044. const char *debugProp =
  2045. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2046. if (debugProp)
  2047. {
  2048. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2049. }
  2050. bool debugOptions = !this->DebugCompileOptionsDone
  2051. && std::find(debugProperties.begin(),
  2052. debugProperties.end(),
  2053. "COMPILE_OPTIONS")
  2054. != debugProperties.end();
  2055. if (this->Makefile->IsConfigured())
  2056. {
  2057. this->DebugCompileOptionsDone = true;
  2058. }
  2059. processCompileOptions(this,
  2060. this->Internal->CompileOptionsItems,
  2061. result,
  2062. uniqueOptions,
  2063. &dagChecker,
  2064. config,
  2065. debugOptions,
  2066. language);
  2067. std::vector<cmTargetInternals::TargetPropertyEntry*>
  2068. linkInterfaceCompileOptionsEntries;
  2069. this->Internal->AddInterfaceEntries(
  2070. this, config, "INTERFACE_COMPILE_OPTIONS",
  2071. linkInterfaceCompileOptionsEntries);
  2072. processCompileOptions(this,
  2073. linkInterfaceCompileOptionsEntries,
  2074. result,
  2075. uniqueOptions,
  2076. &dagChecker,
  2077. config,
  2078. debugOptions,
  2079. language);
  2080. cmDeleteAll(linkInterfaceCompileOptionsEntries);
  2081. }
  2082. //----------------------------------------------------------------------------
  2083. static void processCompileDefinitions(cmTarget const* tgt,
  2084. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2085. std::vector<std::string> &options,
  2086. UNORDERED_SET<std::string> &uniqueOptions,
  2087. cmGeneratorExpressionDAGChecker *dagChecker,
  2088. const std::string& config, bool debugOptions,
  2089. std::string const& language)
  2090. {
  2091. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2092. dagChecker, config, debugOptions,
  2093. "definitions", language);
  2094. }
  2095. //----------------------------------------------------------------------------
  2096. void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
  2097. const std::string& config,
  2098. const std::string& language) const
  2099. {
  2100. UNORDERED_SET<std::string> uniqueOptions;
  2101. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2102. "COMPILE_DEFINITIONS", 0, 0);
  2103. std::vector<std::string> debugProperties;
  2104. const char *debugProp =
  2105. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2106. if (debugProp)
  2107. {
  2108. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2109. }
  2110. bool debugDefines = !this->DebugCompileDefinitionsDone
  2111. && std::find(debugProperties.begin(),
  2112. debugProperties.end(),
  2113. "COMPILE_DEFINITIONS")
  2114. != debugProperties.end();
  2115. if (this->Makefile->IsConfigured())
  2116. {
  2117. this->DebugCompileDefinitionsDone = true;
  2118. }
  2119. processCompileDefinitions(this,
  2120. this->Internal->CompileDefinitionsItems,
  2121. list,
  2122. uniqueOptions,
  2123. &dagChecker,
  2124. config,
  2125. debugDefines,
  2126. language);
  2127. std::vector<cmTargetInternals::TargetPropertyEntry*>
  2128. linkInterfaceCompileDefinitionsEntries;
  2129. this->Internal->AddInterfaceEntries(
  2130. this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2131. linkInterfaceCompileDefinitionsEntries);
  2132. if (!config.empty())
  2133. {
  2134. std::string configPropName = "COMPILE_DEFINITIONS_"
  2135. + cmSystemTools::UpperCase(config);
  2136. const char *configProp = this->GetProperty(configPropName);
  2137. if (configProp)
  2138. {
  2139. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
  2140. {
  2141. case cmPolicies::WARN:
  2142. {
  2143. std::ostringstream e;
  2144. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  2145. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
  2146. e.str());
  2147. }
  2148. case cmPolicies::OLD:
  2149. {
  2150. cmGeneratorExpression ge;
  2151. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2152. ge.Parse(configProp);
  2153. linkInterfaceCompileDefinitionsEntries
  2154. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  2155. }
  2156. break;
  2157. case cmPolicies::NEW:
  2158. case cmPolicies::REQUIRED_ALWAYS:
  2159. case cmPolicies::REQUIRED_IF_USED:
  2160. break;
  2161. }
  2162. }
  2163. }
  2164. processCompileDefinitions(this,
  2165. linkInterfaceCompileDefinitionsEntries,
  2166. list,
  2167. uniqueOptions,
  2168. &dagChecker,
  2169. config,
  2170. debugDefines,
  2171. language);
  2172. cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
  2173. }
  2174. //----------------------------------------------------------------------------
  2175. static void processCompileFeatures(cmTarget const* tgt,
  2176. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2177. std::vector<std::string> &options,
  2178. UNORDERED_SET<std::string> &uniqueOptions,
  2179. cmGeneratorExpressionDAGChecker *dagChecker,
  2180. const std::string& config, bool debugOptions)
  2181. {
  2182. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2183. dagChecker, config, debugOptions, "features",
  2184. std::string());
  2185. }
  2186. //----------------------------------------------------------------------------
  2187. void cmTarget::GetCompileFeatures(std::vector<std::string> &result,
  2188. const std::string& config) const
  2189. {
  2190. UNORDERED_SET<std::string> uniqueFeatures;
  2191. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2192. "COMPILE_FEATURES",
  2193. 0, 0);
  2194. std::vector<std::string> debugProperties;
  2195. const char *debugProp =
  2196. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2197. if (debugProp)
  2198. {
  2199. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2200. }
  2201. bool debugFeatures = !this->DebugCompileFeaturesDone
  2202. && std::find(debugProperties.begin(),
  2203. debugProperties.end(),
  2204. "COMPILE_FEATURES")
  2205. != debugProperties.end();
  2206. if (this->Makefile->IsConfigured())
  2207. {
  2208. this->DebugCompileFeaturesDone = true;
  2209. }
  2210. processCompileFeatures(this,
  2211. this->Internal->CompileFeaturesItems,
  2212. result,
  2213. uniqueFeatures,
  2214. &dagChecker,
  2215. config,
  2216. debugFeatures);
  2217. std::vector<cmTargetInternals::TargetPropertyEntry*>
  2218. linkInterfaceCompileFeaturesEntries;
  2219. this->Internal->AddInterfaceEntries(
  2220. this, config, "INTERFACE_COMPILE_FEATURES",
  2221. linkInterfaceCompileFeaturesEntries);
  2222. processCompileFeatures(this,
  2223. linkInterfaceCompileFeaturesEntries,
  2224. result,
  2225. uniqueFeatures,
  2226. &dagChecker,
  2227. config,
  2228. debugFeatures);
  2229. cmDeleteAll(linkInterfaceCompileFeaturesEntries);
  2230. }
  2231. //----------------------------------------------------------------------------
  2232. void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop)
  2233. {
  2234. // Wipe out maps caching information affected by this property.
  2235. if(this->IsImported() && cmHasLiteralPrefix(prop, "IMPORTED"))
  2236. {
  2237. this->Internal->ImportInfoMap.clear();
  2238. }
  2239. if(!this->IsImported() && cmHasLiteralPrefix(prop, "LINK_INTERFACE_"))
  2240. {
  2241. this->ClearLinkMaps();
  2242. }
  2243. }
  2244. //----------------------------------------------------------------------------
  2245. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  2246. const std::string& prop, const char* value, cmMakefile* context,
  2247. bool imported)
  2248. {
  2249. // Look for link-type keywords in the value.
  2250. static cmsys::RegularExpression
  2251. keys("(^|;)(debug|optimized|general)(;|$)");
  2252. if(!keys.find(value))
  2253. {
  2254. return;
  2255. }
  2256. // Support imported and non-imported versions of the property.
  2257. const char* base = (imported?
  2258. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  2259. "LINK_INTERFACE_LIBRARIES");
  2260. // Report an error.
  2261. std::ostringstream e;
  2262. e << "Property " << prop << " may not contain link-type keyword \""
  2263. << keys.match(2) << "\". "
  2264. << "The " << base << " property has a per-configuration "
  2265. << "version called " << base << "_<CONFIG> which may be "
  2266. << "used to specify per-configuration rules.";
  2267. if(!imported)
  2268. {
  2269. e << " "
  2270. << "Alternatively, an IMPORTED library may be created, configured "
  2271. << "with a per-configuration location, and then named in the "
  2272. << "property value. "
  2273. << "See the add_library command's IMPORTED mode for details."
  2274. << "\n"
  2275. << "If you have a list of libraries that already contains the "
  2276. << "keyword, use the target_link_libraries command with its "
  2277. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  2278. << "The command automatically recognizes link-type keywords and sets "
  2279. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  2280. << "properties accordingly.";
  2281. }
  2282. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2283. }
  2284. //----------------------------------------------------------------------------
  2285. static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
  2286. cmMakefile* context)
  2287. {
  2288. // Look for link-type keywords in the value.
  2289. static cmsys::RegularExpression
  2290. keys("(^|;)(debug|optimized|general)(;|$)");
  2291. if(!keys.find(value))
  2292. {
  2293. return;
  2294. }
  2295. // Report an error.
  2296. std::ostringstream e;
  2297. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  2298. "keyword \"" << keys.match(2) << "\". The INTERFACE_LINK_LIBRARIES "
  2299. "property may contain configuration-sensitive generator-expressions "
  2300. "which may be used to specify per-configuration rules.";
  2301. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2302. }
  2303. //----------------------------------------------------------------------------
  2304. void cmTarget::CheckProperty(const std::string& prop,
  2305. cmMakefile* context) const
  2306. {
  2307. // Certain properties need checking.
  2308. if(cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES"))
  2309. {
  2310. if(const char* value = this->GetProperty(prop))
  2311. {
  2312. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  2313. }
  2314. }
  2315. if(cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES"))
  2316. {
  2317. if(const char* value = this->GetProperty(prop))
  2318. {
  2319. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  2320. }
  2321. }
  2322. if(cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES"))
  2323. {
  2324. if(const char* value = this->GetProperty(prop))
  2325. {
  2326. cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
  2327. }
  2328. }
  2329. }
  2330. //----------------------------------------------------------------------------
  2331. void cmTarget::MarkAsImported()
  2332. {
  2333. this->IsImportedTarget = true;
  2334. }
  2335. //----------------------------------------------------------------------------
  2336. bool cmTarget::HaveWellDefinedOutputFiles() const
  2337. {
  2338. return
  2339. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2340. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2341. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2342. this->GetType() == cmTarget::EXECUTABLE;
  2343. }
  2344. //----------------------------------------------------------------------------
  2345. cmTarget::OutputInfo const* cmTarget::GetOutputInfo(
  2346. const std::string& config) const
  2347. {
  2348. // There is no output information for imported targets.
  2349. if(this->IsImported())
  2350. {
  2351. return 0;
  2352. }
  2353. // Only libraries and executables have well-defined output files.
  2354. if(!this->HaveWellDefinedOutputFiles())
  2355. {
  2356. std::string msg = "cmTarget::GetOutputInfo called for ";
  2357. msg += this->GetName();
  2358. msg += " which has type ";
  2359. msg += cmTarget::GetTargetTypeName(this->GetType());
  2360. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2361. return 0;
  2362. }
  2363. // Lookup/compute/cache the output information for this configuration.
  2364. std::string config_upper;
  2365. if(!config.empty())
  2366. {
  2367. config_upper = cmSystemTools::UpperCase(config);
  2368. }
  2369. typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
  2370. OutputInfoMapType::iterator i =
  2371. this->Internal->OutputInfoMap.find(config_upper);
  2372. if(i == this->Internal->OutputInfoMap.end())
  2373. {
  2374. // Add empty info in map to detect potential recursion.
  2375. OutputInfo info;
  2376. OutputInfoMapType::value_type entry(config_upper, info);
  2377. i = this->Internal->OutputInfoMap.insert(entry).first;
  2378. // Compute output directories.
  2379. this->ComputeOutputDir(config, false, info.OutDir);
  2380. this->ComputeOutputDir(config, true, info.ImpDir);
  2381. if(!this->ComputePDBOutputDir("PDB", config, info.PdbDir))
  2382. {
  2383. info.PdbDir = info.OutDir;
  2384. }
  2385. // Now update the previously-prepared map entry.
  2386. i->second = info;
  2387. }
  2388. else if(i->second.empty())
  2389. {
  2390. // An empty map entry indicates we have been called recursively
  2391. // from the above block.
  2392. this->Makefile->GetCMakeInstance()->IssueMessage(
  2393. cmake::FATAL_ERROR,
  2394. "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
  2395. this->GetBacktrace());
  2396. return 0;
  2397. }
  2398. return &i->second;
  2399. }
  2400. //----------------------------------------------------------------------------
  2401. std::string cmTarget::GetDirectory(const std::string& config,
  2402. bool implib) const
  2403. {
  2404. if (this->IsImported())
  2405. {
  2406. // Return the directory from which the target is imported.
  2407. return
  2408. cmSystemTools::GetFilenamePath(
  2409. this->ImportedGetFullPath(config, implib));
  2410. }
  2411. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2412. {
  2413. // Return the directory in which the target will be built.
  2414. return implib? info->ImpDir : info->OutDir;
  2415. }
  2416. return "";
  2417. }
  2418. //----------------------------------------------------------------------------
  2419. std::string cmTarget::GetPDBDirectory(const std::string& config) const
  2420. {
  2421. if(OutputInfo const* info = this->GetOutputInfo(config))
  2422. {
  2423. // Return the directory in which the target will be built.
  2424. return info->PdbDir;
  2425. }
  2426. return "";
  2427. }
  2428. //----------------------------------------------------------------------------
  2429. const char* cmTarget::ImportedGetLocation(const std::string& config) const
  2430. {
  2431. static std::string location;
  2432. assert(this->IsImported());
  2433. location = this->ImportedGetFullPath(config, false);
  2434. return location.c_str();
  2435. }
  2436. //----------------------------------------------------------------------------
  2437. void cmTarget::GetTargetVersion(int& major, int& minor) const
  2438. {
  2439. int patch;
  2440. this->GetTargetVersion(false, major, minor, patch);
  2441. }
  2442. //----------------------------------------------------------------------------
  2443. void cmTarget::GetTargetVersion(bool soversion,
  2444. int& major, int& minor, int& patch) const
  2445. {
  2446. // Set the default values.
  2447. major = 0;
  2448. minor = 0;
  2449. patch = 0;
  2450. assert(this->GetType() != INTERFACE_LIBRARY);
  2451. // Look for a VERSION or SOVERSION property.
  2452. const char* prop = soversion? "SOVERSION" : "VERSION";
  2453. if(const char* version = this->GetProperty(prop))
  2454. {
  2455. // Try to parse the version number and store the results that were
  2456. // successfully parsed.
  2457. int parsed_major;
  2458. int parsed_minor;
  2459. int parsed_patch;
  2460. switch(sscanf(version, "%d.%d.%d",
  2461. &parsed_major, &parsed_minor, &parsed_patch))
  2462. {
  2463. case 3: patch = parsed_patch; // no break!
  2464. case 2: minor = parsed_minor; // no break!
  2465. case 1: major = parsed_major; // no break!
  2466. default: break;
  2467. }
  2468. }
  2469. }
  2470. //----------------------------------------------------------------------------
  2471. bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const
  2472. {
  2473. if (this->IsImported())
  2474. {
  2475. return true;
  2476. }
  2477. std::ostringstream e;
  2478. const char *modal = 0;
  2479. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2480. switch (context->GetPolicyStatus(cmPolicies::CMP0026))
  2481. {
  2482. case cmPolicies::WARN:
  2483. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
  2484. modal = "should";
  2485. case cmPolicies::OLD:
  2486. break;
  2487. case cmPolicies::REQUIRED_ALWAYS:
  2488. case cmPolicies::REQUIRED_IF_USED:
  2489. case cmPolicies::NEW:
  2490. modal = "may";
  2491. messageType = cmake::FATAL_ERROR;
  2492. }
  2493. if (modal)
  2494. {
  2495. e << "The LOCATION property " << modal << " not be read from target \""
  2496. << this->GetName() << "\". Use the target name directly with "
  2497. "add_custom_command, or use the generator expression $<TARGET_FILE>, "
  2498. "as appropriate.\n";
  2499. context->IssueMessage(messageType, e.str());
  2500. }
  2501. return messageType != cmake::FATAL_ERROR;
  2502. }
  2503. //----------------------------------------------------------------------------
  2504. const char *cmTarget::GetProperty(const std::string& prop) const
  2505. {
  2506. return this->GetProperty(prop, this->Makefile);
  2507. }
  2508. //----------------------------------------------------------------------------
  2509. const char *cmTarget::GetProperty(const std::string& prop,
  2510. cmMakefile* context) const
  2511. {
  2512. if (this->GetType() == INTERFACE_LIBRARY
  2513. && !whiteListedInterfaceProperty(prop))
  2514. {
  2515. std::ostringstream e;
  2516. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  2517. "The property \"" << prop << "\" is not allowed.";
  2518. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2519. return 0;
  2520. }
  2521. // Watch for special "computed" properties that are dependent on
  2522. // other properties or variables. Always recompute them.
  2523. if(this->GetType() == cmTarget::EXECUTABLE ||
  2524. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2525. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2526. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2527. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2528. {
  2529. static const std::string propLOCATION = "LOCATION";
  2530. if(prop == propLOCATION)
  2531. {
  2532. if (!this->HandleLocationPropertyPolicy(context))
  2533. {
  2534. return 0;
  2535. }
  2536. // Set the LOCATION property of the target.
  2537. //
  2538. // For an imported target this is the location of an arbitrary
  2539. // available configuration.
  2540. //
  2541. if(this->IsImported())
  2542. {
  2543. this->Properties.SetProperty(
  2544. propLOCATION, this->ImportedGetFullPath("", false).c_str());
  2545. }
  2546. else
  2547. {
  2548. // For a non-imported target this is deprecated because it
  2549. // cannot take into account the per-configuration name of the
  2550. // target because the configuration type may not be known at
  2551. // CMake time.
  2552. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2553. gg->CreateGenerationObjects();
  2554. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2555. this->Properties.SetProperty(propLOCATION,
  2556. gt->GetLocationForBuild());
  2557. }
  2558. }
  2559. // Support "LOCATION_<CONFIG>".
  2560. else if(cmHasLiteralPrefix(prop, "LOCATION_"))
  2561. {
  2562. if (!this->HandleLocationPropertyPolicy(context))
  2563. {
  2564. return 0;
  2565. }
  2566. const char* configName = prop.c_str() + 9;
  2567. if (this->IsImported())
  2568. {
  2569. this->Properties.SetProperty(
  2570. prop, this->ImportedGetFullPath(configName, false).c_str());
  2571. }
  2572. else
  2573. {
  2574. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2575. gg->CreateGenerationObjects();
  2576. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2577. this->Properties.SetProperty(
  2578. prop, gt->GetFullPath(configName, false).c_str());
  2579. }
  2580. }
  2581. // Support "<CONFIG>_LOCATION".
  2582. else if(cmHasLiteralSuffix(prop, "_LOCATION"))
  2583. {
  2584. std::string configName(prop.c_str(), prop.size() - 9);
  2585. if(configName != "IMPORTED")
  2586. {
  2587. if (!this->HandleLocationPropertyPolicy(context))
  2588. {
  2589. return 0;
  2590. }
  2591. if (this->IsImported())
  2592. {
  2593. this->Properties.SetProperty(
  2594. prop, this->ImportedGetFullPath(configName, false).c_str());
  2595. }
  2596. else
  2597. {
  2598. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
  2599. gg->CreateGenerationObjects();
  2600. cmGeneratorTarget* gt = gg->GetGeneratorTarget(this);
  2601. this->Properties.SetProperty(
  2602. prop, gt->GetFullPath(configName, false).c_str());
  2603. }
  2604. }
  2605. }
  2606. }
  2607. static UNORDERED_SET<std::string> specialProps;
  2608. #define MAKE_STATIC_PROP(PROP) \
  2609. static const std::string prop##PROP = #PROP
  2610. MAKE_STATIC_PROP(LINK_LIBRARIES);
  2611. MAKE_STATIC_PROP(TYPE);
  2612. MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
  2613. MAKE_STATIC_PROP(COMPILE_FEATURES);
  2614. MAKE_STATIC_PROP(COMPILE_OPTIONS);
  2615. MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
  2616. MAKE_STATIC_PROP(IMPORTED);
  2617. MAKE_STATIC_PROP(NAME);
  2618. MAKE_STATIC_PROP(BINARY_DIR);
  2619. MAKE_STATIC_PROP(SOURCE_DIR);
  2620. MAKE_STATIC_PROP(SOURCES);
  2621. #undef MAKE_STATIC_PROP
  2622. if(specialProps.empty())
  2623. {
  2624. specialProps.insert(propLINK_LIBRARIES);
  2625. specialProps.insert(propTYPE);
  2626. specialProps.insert(propINCLUDE_DIRECTORIES);
  2627. specialProps.insert(propCOMPILE_FEATURES);
  2628. specialProps.insert(propCOMPILE_OPTIONS);
  2629. specialProps.insert(propCOMPILE_DEFINITIONS);
  2630. specialProps.insert(propIMPORTED);
  2631. specialProps.insert(propNAME);
  2632. specialProps.insert(propBINARY_DIR);
  2633. specialProps.insert(propSOURCE_DIR);
  2634. specialProps.insert(propSOURCES);
  2635. }
  2636. if(specialProps.count(prop))
  2637. {
  2638. if(prop == propLINK_LIBRARIES)
  2639. {
  2640. if (this->Internal->LinkImplementationPropertyEntries.empty())
  2641. {
  2642. return 0;
  2643. }
  2644. static std::string output;
  2645. output = "";
  2646. std::string sep;
  2647. for (std::vector<cmValueWithOrigin>::const_iterator
  2648. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  2649. end = this->Internal->LinkImplementationPropertyEntries.end();
  2650. it != end; ++it)
  2651. {
  2652. output += sep;
  2653. output += it->Value;
  2654. sep = ";";
  2655. }
  2656. return output.c_str();
  2657. }
  2658. // the type property returns what type the target is
  2659. else if (prop == propTYPE)
  2660. {
  2661. return cmTarget::GetTargetTypeName(this->GetType());
  2662. }
  2663. else if(prop == propINCLUDE_DIRECTORIES)
  2664. {
  2665. if (this->Internal->IncludeDirectoriesEntries.empty())
  2666. {
  2667. return 0;
  2668. }
  2669. static std::string output;
  2670. output = cmJoin(this->Internal->IncludeDirectoriesEntries, ";");
  2671. return output.c_str();
  2672. }
  2673. else if(prop == propCOMPILE_FEATURES)
  2674. {
  2675. if (this->Internal->CompileFeaturesEntries.empty())
  2676. {
  2677. return 0;
  2678. }
  2679. static std::string output;
  2680. output = cmJoin(this->Internal->CompileFeaturesEntries, ";");
  2681. return output.c_str();
  2682. }
  2683. else if(prop == propCOMPILE_OPTIONS)
  2684. {
  2685. if (this->Internal->CompileOptionsEntries.empty())
  2686. {
  2687. return 0;
  2688. }
  2689. static std::string output;
  2690. output = cmJoin(this->Internal->CompileOptionsEntries, ";");
  2691. return output.c_str();
  2692. }
  2693. else if(prop == propCOMPILE_DEFINITIONS)
  2694. {
  2695. if (this->Internal->CompileDefinitionsEntries.empty())
  2696. {
  2697. return 0;
  2698. }
  2699. static std::string output;
  2700. output = cmJoin(this->Internal->CompileDefinitionsEntries, ";");
  2701. return output.c_str();
  2702. }
  2703. else if (prop == propIMPORTED)
  2704. {
  2705. return this->IsImported()?"TRUE":"FALSE";
  2706. }
  2707. else if (prop == propNAME)
  2708. {
  2709. return this->GetName().c_str();
  2710. }
  2711. else if (prop == propBINARY_DIR)
  2712. {
  2713. return this->GetMakefile()->GetCurrentBinaryDirectory();
  2714. }
  2715. else if (prop == propSOURCE_DIR)
  2716. {
  2717. return this->GetMakefile()->GetCurrentSourceDirectory();
  2718. }
  2719. else if(prop == propSOURCES)
  2720. {
  2721. if (this->Internal->SourceEntries.empty())
  2722. {
  2723. return 0;
  2724. }
  2725. std::ostringstream ss;
  2726. const char* sep = "";
  2727. typedef cmTargetInternals::TargetPropertyEntry
  2728. TargetPropertyEntry;
  2729. for(std::vector<TargetPropertyEntry*>::const_iterator
  2730. i = this->Internal->SourceEntries.begin();
  2731. i != this->Internal->SourceEntries.end(); ++i)
  2732. {
  2733. std::string entry = (*i)->ge->GetInput();
  2734. std::vector<std::string> files;
  2735. cmSystemTools::ExpandListArgument(entry, files);
  2736. for (std::vector<std::string>::const_iterator
  2737. li = files.begin(); li != files.end(); ++li)
  2738. {
  2739. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  2740. (*li)[li->size() - 1] == '>')
  2741. {
  2742. std::string objLibName = li->substr(17, li->size()-18);
  2743. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  2744. {
  2745. ss << sep;
  2746. sep = ";";
  2747. ss << *li;
  2748. continue;
  2749. }
  2750. bool addContent = false;
  2751. bool noMessage = true;
  2752. std::ostringstream e;
  2753. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2754. switch(context->GetPolicyStatus(cmPolicies::CMP0051))
  2755. {
  2756. case cmPolicies::WARN:
  2757. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  2758. noMessage = false;
  2759. case cmPolicies::OLD:
  2760. break;
  2761. case cmPolicies::REQUIRED_ALWAYS:
  2762. case cmPolicies::REQUIRED_IF_USED:
  2763. case cmPolicies::NEW:
  2764. addContent = true;
  2765. }
  2766. if (!noMessage)
  2767. {
  2768. e << "Target \"" << this->Name << "\" contains "
  2769. "$<TARGET_OBJECTS> generator expression in its sources list. "
  2770. "This content was not previously part of the SOURCES property "
  2771. "when that property was read at configure time. Code reading "
  2772. "that property needs to be adapted to ignore the generator "
  2773. "expression using the string(GENEX_STRIP) command.";
  2774. context->IssueMessage(messageType, e.str());
  2775. }
  2776. if (addContent)
  2777. {
  2778. ss << sep;
  2779. sep = ";";
  2780. ss << *li;
  2781. }
  2782. }
  2783. else if (cmGeneratorExpression::Find(*li) == std::string::npos)
  2784. {
  2785. ss << sep;
  2786. sep = ";";
  2787. ss << *li;
  2788. }
  2789. else
  2790. {
  2791. cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li);
  2792. // Construct what is known about this source file location.
  2793. cmSourceFileLocation const& location = sf->GetLocation();
  2794. std::string sname = location.GetDirectory();
  2795. if(!sname.empty())
  2796. {
  2797. sname += "/";
  2798. }
  2799. sname += location.GetName();
  2800. ss << sep;
  2801. sep = ";";
  2802. // Append this list entry.
  2803. ss << sname;
  2804. }
  2805. }
  2806. }
  2807. this->Properties.SetProperty("SOURCES", ss.str().c_str());
  2808. }
  2809. }
  2810. const char *retVal = this->Properties.GetPropertyValue(prop);
  2811. if (!retVal)
  2812. {
  2813. const bool chain = this->GetMakefile()->GetState()->
  2814. IsPropertyChained(prop, cmProperty::TARGET);
  2815. if (chain)
  2816. {
  2817. return this->Makefile->GetProperty(prop, chain);
  2818. }
  2819. }
  2820. return retVal;
  2821. }
  2822. //----------------------------------------------------------------------------
  2823. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  2824. {
  2825. return cmSystemTools::IsOn(this->GetProperty(prop));
  2826. }
  2827. //----------------------------------------------------------------------------
  2828. void cmTarget::ExpandLinkItems(std::string const& prop,
  2829. std::string const& value,
  2830. std::string const& config,
  2831. cmTarget const* headTarget,
  2832. bool usage_requirements_only,
  2833. std::vector<cmLinkItem>& items,
  2834. bool& hadHeadSensitiveCondition) const
  2835. {
  2836. cmGeneratorExpression ge;
  2837. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
  2838. // The $<LINK_ONLY> expression may be in a link interface to specify private
  2839. // link dependencies that are otherwise excluded from usage requirements.
  2840. if(usage_requirements_only)
  2841. {
  2842. dagChecker.SetTransitivePropertiesOnly();
  2843. }
  2844. std::vector<std::string> libs;
  2845. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  2846. cmSystemTools::ExpandListArgument(cge->Evaluate(
  2847. this->Makefile,
  2848. config,
  2849. false,
  2850. headTarget,
  2851. this, &dagChecker), libs);
  2852. this->LookupLinkItems(libs, items);
  2853. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  2854. }
  2855. //----------------------------------------------------------------------------
  2856. void cmTarget::LookupLinkItems(std::vector<std::string> const& names,
  2857. std::vector<cmLinkItem>& items) const
  2858. {
  2859. for(std::vector<std::string>::const_iterator i = names.begin();
  2860. i != names.end(); ++i)
  2861. {
  2862. std::string name = this->CheckCMP0004(*i);
  2863. if(name == this->GetName() || name.empty())
  2864. {
  2865. continue;
  2866. }
  2867. items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
  2868. }
  2869. }
  2870. //----------------------------------------------------------------------------
  2871. const char* cmTarget::GetSuffixVariableInternal(bool implib) const
  2872. {
  2873. switch(this->GetType())
  2874. {
  2875. case cmTarget::STATIC_LIBRARY:
  2876. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  2877. case cmTarget::SHARED_LIBRARY:
  2878. return (implib
  2879. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2880. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  2881. case cmTarget::MODULE_LIBRARY:
  2882. return (implib
  2883. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2884. : "CMAKE_SHARED_MODULE_SUFFIX");
  2885. case cmTarget::EXECUTABLE:
  2886. return (implib
  2887. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2888. // Android GUI application packages store the native
  2889. // binary as a shared library.
  2890. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  2891. "CMAKE_SHARED_LIBRARY_SUFFIX" : "CMAKE_EXECUTABLE_SUFFIX"));
  2892. default:
  2893. break;
  2894. }
  2895. return "";
  2896. }
  2897. //----------------------------------------------------------------------------
  2898. const char* cmTarget::GetPrefixVariableInternal(bool implib) const
  2899. {
  2900. switch(this->GetType())
  2901. {
  2902. case cmTarget::STATIC_LIBRARY:
  2903. return "CMAKE_STATIC_LIBRARY_PREFIX";
  2904. case cmTarget::SHARED_LIBRARY:
  2905. return (implib
  2906. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2907. : "CMAKE_SHARED_LIBRARY_PREFIX");
  2908. case cmTarget::MODULE_LIBRARY:
  2909. return (implib
  2910. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2911. : "CMAKE_SHARED_MODULE_PREFIX");
  2912. case cmTarget::EXECUTABLE:
  2913. return (implib
  2914. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2915. // Android GUI application packages store the native
  2916. // binary as a shared library.
  2917. : (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
  2918. "CMAKE_SHARED_LIBRARY_PREFIX" : ""));
  2919. default:
  2920. break;
  2921. }
  2922. return "";
  2923. }
  2924. //----------------------------------------------------------------------------
  2925. bool cmTarget::HasMacOSXRpathInstallNameDir(const std::string& config) const
  2926. {
  2927. bool install_name_is_rpath = false;
  2928. bool macosx_rpath = false;
  2929. if(!this->IsImportedTarget)
  2930. {
  2931. if(this->GetType() != cmTarget::SHARED_LIBRARY)
  2932. {
  2933. return false;
  2934. }
  2935. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  2936. bool use_install_name =
  2937. this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  2938. if(install_name && use_install_name &&
  2939. std::string(install_name) == "@rpath")
  2940. {
  2941. install_name_is_rpath = true;
  2942. }
  2943. else if(install_name && use_install_name)
  2944. {
  2945. return false;
  2946. }
  2947. if(!install_name_is_rpath)
  2948. {
  2949. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  2950. }
  2951. }
  2952. else
  2953. {
  2954. // Lookup the imported soname.
  2955. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2956. {
  2957. if(!info->NoSOName && !info->SOName.empty())
  2958. {
  2959. if(info->SOName.find("@rpath/") == 0)
  2960. {
  2961. install_name_is_rpath = true;
  2962. }
  2963. }
  2964. else
  2965. {
  2966. std::string install_name;
  2967. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  2968. if(install_name.find("@rpath") != std::string::npos)
  2969. {
  2970. install_name_is_rpath = true;
  2971. }
  2972. }
  2973. }
  2974. }
  2975. if(!install_name_is_rpath && !macosx_rpath)
  2976. {
  2977. return false;
  2978. }
  2979. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  2980. {
  2981. std::ostringstream w;
  2982. w << "Attempting to use";
  2983. if(macosx_rpath)
  2984. {
  2985. w << " MACOSX_RPATH";
  2986. }
  2987. else
  2988. {
  2989. w << " @rpath";
  2990. }
  2991. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  2992. w << " This could be because you are using a Mac OS X version";
  2993. w << " less than 10.5 or because CMake's platform configuration is";
  2994. w << " corrupt.";
  2995. cmake* cm = this->Makefile->GetCMakeInstance();
  2996. cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
  2997. }
  2998. return true;
  2999. }
  3000. //----------------------------------------------------------------------------
  3001. bool cmTarget::MacOSXRpathInstallNameDirDefault() const
  3002. {
  3003. // we can't do rpaths when unsupported
  3004. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  3005. {
  3006. return false;
  3007. }
  3008. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  3009. if(macosx_rpath_str)
  3010. {
  3011. return this->GetPropertyAsBool("MACOSX_RPATH");
  3012. }
  3013. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  3014. if(cmp0042 == cmPolicies::WARN)
  3015. {
  3016. this->Makefile->GetGlobalGenerator()->
  3017. AddCMP0042WarnTarget(this->GetName());
  3018. }
  3019. if(cmp0042 == cmPolicies::NEW)
  3020. {
  3021. return true;
  3022. }
  3023. return false;
  3024. }
  3025. //----------------------------------------------------------------------------
  3026. bool cmTarget::IsImportedSharedLibWithoutSOName(
  3027. const std::string& config) const
  3028. {
  3029. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  3030. {
  3031. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3032. {
  3033. return info->NoSOName;
  3034. }
  3035. }
  3036. return false;
  3037. }
  3038. //----------------------------------------------------------------------------
  3039. std::string
  3040. cmTarget::GetFullNameImported(const std::string& config, bool implib) const
  3041. {
  3042. return cmSystemTools::GetFilenameName(
  3043. this->ImportedGetFullPath(config, implib));
  3044. }
  3045. //----------------------------------------------------------------------------
  3046. std::string
  3047. cmTarget::ImportedGetFullPath(const std::string& config, bool implib) const
  3048. {
  3049. std::string result;
  3050. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3051. {
  3052. result = implib? info->ImportLibrary : info->Location;
  3053. }
  3054. if(result.empty())
  3055. {
  3056. result = this->GetName();
  3057. result += "-NOTFOUND";
  3058. }
  3059. return result;
  3060. }
  3061. //----------------------------------------------------------------------------
  3062. void cmTarget::ComputeVersionedName(std::string& vName,
  3063. std::string const& prefix,
  3064. std::string const& base,
  3065. std::string const& suffix,
  3066. std::string const& name,
  3067. const char* version) const
  3068. {
  3069. vName = this->IsApple? (prefix+base) : name;
  3070. if(version)
  3071. {
  3072. vName += ".";
  3073. vName += version;
  3074. }
  3075. vName += this->IsApple? suffix : std::string();
  3076. }
  3077. //----------------------------------------------------------------------------
  3078. bool cmTarget::HasImplibGNUtoMS() const
  3079. {
  3080. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  3081. }
  3082. //----------------------------------------------------------------------------
  3083. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  3084. std::string& out, const char* newExt) const
  3085. {
  3086. if(this->HasImplibGNUtoMS() &&
  3087. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  3088. {
  3089. out = gnuName.substr(0, gnuName.size()-6);
  3090. out += newExt? newExt : ".lib";
  3091. return true;
  3092. }
  3093. return false;
  3094. }
  3095. //----------------------------------------------------------------------------
  3096. void cmTarget::SetPropertyDefault(const std::string& property,
  3097. const char* default_value)
  3098. {
  3099. // Compute the name of the variable holding the default value.
  3100. std::string var = "CMAKE_";
  3101. var += property;
  3102. if(const char* value = this->Makefile->GetDefinition(var))
  3103. {
  3104. this->SetProperty(property, value);
  3105. }
  3106. else if(default_value)
  3107. {
  3108. this->SetProperty(property, default_value);
  3109. }
  3110. }
  3111. //----------------------------------------------------------------------------
  3112. bool cmTarget::HaveBuildTreeRPATH(const std::string& config) const
  3113. {
  3114. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3115. {
  3116. return false;
  3117. }
  3118. if(cmLinkImplementationLibraries const* impl =
  3119. this->GetLinkImplementationLibraries(config))
  3120. {
  3121. return !impl->Libraries.empty();
  3122. }
  3123. return false;
  3124. }
  3125. //----------------------------------------------------------------------------
  3126. bool cmTarget::HaveInstallTreeRPATH() const
  3127. {
  3128. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3129. return (install_rpath && *install_rpath) &&
  3130. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3131. }
  3132. //----------------------------------------------------------------------------
  3133. const char* cmTarget::GetOutputTargetType(bool implib) const
  3134. {
  3135. switch(this->GetType())
  3136. {
  3137. case cmTarget::SHARED_LIBRARY:
  3138. if(this->DLLPlatform)
  3139. {
  3140. if(implib)
  3141. {
  3142. // A DLL import library is treated as an archive target.
  3143. return "ARCHIVE";
  3144. }
  3145. else
  3146. {
  3147. // A DLL shared library is treated as a runtime target.
  3148. return "RUNTIME";
  3149. }
  3150. }
  3151. else
  3152. {
  3153. // For non-DLL platforms shared libraries are treated as
  3154. // library targets.
  3155. return "LIBRARY";
  3156. }
  3157. case cmTarget::STATIC_LIBRARY:
  3158. // Static libraries are always treated as archive targets.
  3159. return "ARCHIVE";
  3160. case cmTarget::MODULE_LIBRARY:
  3161. if(implib)
  3162. {
  3163. // Module libraries are always treated as library targets.
  3164. return "ARCHIVE";
  3165. }
  3166. else
  3167. {
  3168. // Module import libraries are treated as archive targets.
  3169. return "LIBRARY";
  3170. }
  3171. case cmTarget::EXECUTABLE:
  3172. if(implib)
  3173. {
  3174. // Executable import libraries are treated as archive targets.
  3175. return "ARCHIVE";
  3176. }
  3177. else
  3178. {
  3179. // Executables are always treated as runtime targets.
  3180. return "RUNTIME";
  3181. }
  3182. default:
  3183. break;
  3184. }
  3185. return "";
  3186. }
  3187. //----------------------------------------------------------------------------
  3188. bool cmTarget::ComputeOutputDir(const std::string& config,
  3189. bool implib, std::string& out) const
  3190. {
  3191. bool usesDefaultOutputDir = false;
  3192. std::string conf = config;
  3193. // Look for a target property defining the target output directory
  3194. // based on the target type.
  3195. std::string targetTypeName = this->GetOutputTargetType(implib);
  3196. const char* propertyName = 0;
  3197. std::string propertyNameStr = targetTypeName;
  3198. if(!propertyNameStr.empty())
  3199. {
  3200. propertyNameStr += "_OUTPUT_DIRECTORY";
  3201. propertyName = propertyNameStr.c_str();
  3202. }
  3203. // Check for a per-configuration output directory target property.
  3204. std::string configUpper = cmSystemTools::UpperCase(conf);
  3205. const char* configProp = 0;
  3206. std::string configPropStr = targetTypeName;
  3207. if(!configPropStr.empty())
  3208. {
  3209. configPropStr += "_OUTPUT_DIRECTORY_";
  3210. configPropStr += configUpper;
  3211. configProp = configPropStr.c_str();
  3212. }
  3213. // Select an output directory.
  3214. if(const char* config_outdir = this->GetProperty(configProp))
  3215. {
  3216. // Use the user-specified per-configuration output directory.
  3217. cmGeneratorExpression ge;
  3218. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  3219. ge.Parse(config_outdir);
  3220. out = cge->Evaluate(this->Makefile, config);
  3221. // Skip per-configuration subdirectory.
  3222. conf = "";
  3223. }
  3224. else if(const char* outdir = this->GetProperty(propertyName))
  3225. {
  3226. // Use the user-specified output directory.
  3227. cmGeneratorExpression ge;
  3228. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  3229. ge.Parse(outdir);
  3230. out = cge->Evaluate(this->Makefile, config);
  3231. // Skip per-configuration subdirectory if the value contained a
  3232. // generator expression.
  3233. if (out != outdir)
  3234. {
  3235. conf = "";
  3236. }
  3237. }
  3238. else if(this->GetType() == cmTarget::EXECUTABLE)
  3239. {
  3240. // Lookup the output path for executables.
  3241. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  3242. }
  3243. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3244. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3245. this->GetType() == cmTarget::MODULE_LIBRARY)
  3246. {
  3247. // Lookup the output path for libraries.
  3248. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  3249. }
  3250. if(out.empty())
  3251. {
  3252. // Default to the current output directory.
  3253. usesDefaultOutputDir = true;
  3254. out = ".";
  3255. }
  3256. // Convert the output path to a full path in case it is
  3257. // specified as a relative path. Treat a relative path as
  3258. // relative to the current output directory for this makefile.
  3259. out = (cmSystemTools::CollapseFullPath
  3260. (out, this->Makefile->GetCurrentBinaryDirectory()));
  3261. // The generator may add the configuration's subdirectory.
  3262. if(!conf.empty())
  3263. {
  3264. bool iosPlatform = this->Makefile->PlatformIsAppleIos();
  3265. std::string suffix =
  3266. usesDefaultOutputDir && iosPlatform ? "${EFFECTIVE_PLATFORM_NAME}" : "";
  3267. this->Makefile->GetGlobalGenerator()->
  3268. AppendDirectoryForConfig("/", conf, suffix, out);
  3269. }
  3270. return usesDefaultOutputDir;
  3271. }
  3272. //----------------------------------------------------------------------------
  3273. bool cmTarget::ComputePDBOutputDir(const std::string& kind,
  3274. const std::string& config,
  3275. std::string& out) const
  3276. {
  3277. // Look for a target property defining the target output directory
  3278. // based on the target type.
  3279. const char* propertyName = 0;
  3280. std::string propertyNameStr = kind;
  3281. if(!propertyNameStr.empty())
  3282. {
  3283. propertyNameStr += "_OUTPUT_DIRECTORY";
  3284. propertyName = propertyNameStr.c_str();
  3285. }
  3286. std::string conf = config;
  3287. // Check for a per-configuration output directory target property.
  3288. std::string configUpper = cmSystemTools::UpperCase(conf);
  3289. const char* configProp = 0;
  3290. std::string configPropStr = kind;
  3291. if(!configPropStr.empty())
  3292. {
  3293. configPropStr += "_OUTPUT_DIRECTORY_";
  3294. configPropStr += configUpper;
  3295. configProp = configPropStr.c_str();
  3296. }
  3297. // Select an output directory.
  3298. if(const char* config_outdir = this->GetProperty(configProp))
  3299. {
  3300. // Use the user-specified per-configuration output directory.
  3301. out = config_outdir;
  3302. // Skip per-configuration subdirectory.
  3303. conf = "";
  3304. }
  3305. else if(const char* outdir = this->GetProperty(propertyName))
  3306. {
  3307. // Use the user-specified output directory.
  3308. out = outdir;
  3309. }
  3310. if(out.empty())
  3311. {
  3312. return false;
  3313. }
  3314. // Convert the output path to a full path in case it is
  3315. // specified as a relative path. Treat a relative path as
  3316. // relative to the current output directory for this makefile.
  3317. out = (cmSystemTools::CollapseFullPath
  3318. (out, this->Makefile->GetCurrentBinaryDirectory()));
  3319. // The generator may add the configuration's subdirectory.
  3320. if(!conf.empty())
  3321. {
  3322. this->Makefile->GetGlobalGenerator()->
  3323. AppendDirectoryForConfig("/", conf, "", out);
  3324. }
  3325. return true;
  3326. }
  3327. //----------------------------------------------------------------------------
  3328. bool cmTarget::UsesDefaultOutputDir(const std::string& config,
  3329. bool implib) const
  3330. {
  3331. std::string dir;
  3332. return this->ComputeOutputDir(config, implib, dir);
  3333. }
  3334. //----------------------------------------------------------------------------
  3335. std::string cmTarget::GetFrameworkVersion() const
  3336. {
  3337. assert(this->GetType() != INTERFACE_LIBRARY);
  3338. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  3339. {
  3340. return fversion;
  3341. }
  3342. else if(const char* tversion = this->GetProperty("VERSION"))
  3343. {
  3344. return tversion;
  3345. }
  3346. else
  3347. {
  3348. return "A";
  3349. }
  3350. }
  3351. //----------------------------------------------------------------------------
  3352. const char* cmTarget::GetExportMacro() const
  3353. {
  3354. // Define the symbol for targets that export symbols.
  3355. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3356. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3357. this->IsExecutableWithExports())
  3358. {
  3359. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  3360. {
  3361. this->ExportMacro = custom_export_name;
  3362. }
  3363. else
  3364. {
  3365. std::string in = this->GetName();
  3366. in += "_EXPORTS";
  3367. this->ExportMacro = cmSystemTools::MakeCindentifier(in);
  3368. }
  3369. return this->ExportMacro.c_str();
  3370. }
  3371. else
  3372. {
  3373. return 0;
  3374. }
  3375. }
  3376. //----------------------------------------------------------------------------
  3377. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
  3378. {
  3379. return this->LinkImplicitNullProperties.find(p)
  3380. != this->LinkImplicitNullProperties.end();
  3381. }
  3382. //----------------------------------------------------------------------------
  3383. void
  3384. cmTarget::GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const
  3385. {
  3386. // At configure-time, this method can be called as part of getting the
  3387. // LOCATION property or to export() a file to be include()d. However
  3388. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  3389. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  3390. // behavior of CMP0024 and CMP0026 only.
  3391. typedef cmTargetInternals::TargetPropertyEntry
  3392. TargetPropertyEntry;
  3393. for(std::vector<TargetPropertyEntry*>::const_iterator
  3394. i = this->Internal->SourceEntries.begin();
  3395. i != this->Internal->SourceEntries.end(); ++i)
  3396. {
  3397. std::string entry = (*i)->ge->GetInput();
  3398. std::vector<std::string> files;
  3399. cmSystemTools::ExpandListArgument(entry, files);
  3400. for (std::vector<std::string>::const_iterator
  3401. li = files.begin(); li != files.end(); ++li)
  3402. {
  3403. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  3404. (*li)[li->size() - 1] == '>')
  3405. {
  3406. std::string objLibName = li->substr(17, li->size()-18);
  3407. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  3408. {
  3409. continue;
  3410. }
  3411. cmTarget *objLib = this->Makefile->FindTargetToUse(objLibName);
  3412. if(objLib)
  3413. {
  3414. objlibs.push_back(objLib);
  3415. }
  3416. }
  3417. }
  3418. }
  3419. }
  3420. //----------------------------------------------------------------------------
  3421. void cmTarget::GetLanguages(std::set<std::string>& languages,
  3422. const std::string& config) const
  3423. {
  3424. std::vector<cmSourceFile*> sourceFiles;
  3425. this->GetSourceFiles(sourceFiles, config);
  3426. for(std::vector<cmSourceFile*>::const_iterator
  3427. i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
  3428. {
  3429. const std::string& lang = (*i)->GetLanguage();
  3430. if(!lang.empty())
  3431. {
  3432. languages.insert(lang);
  3433. }
  3434. }
  3435. std::vector<cmTarget*> objectLibraries;
  3436. std::vector<cmSourceFile const*> externalObjects;
  3437. if (!this->Makefile->IsConfigured())
  3438. {
  3439. this->GetObjectLibrariesCMP0026(objectLibraries);
  3440. }
  3441. else
  3442. {
  3443. cmGeneratorTarget* gt = this->Makefile->GetGlobalGenerator()
  3444. ->GetGeneratorTarget(this);
  3445. gt->GetExternalObjects(externalObjects, config);
  3446. for(std::vector<cmSourceFile const*>::const_iterator
  3447. i = externalObjects.begin(); i != externalObjects.end(); ++i)
  3448. {
  3449. std::string objLib = (*i)->GetObjectLibrary();
  3450. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  3451. {
  3452. objectLibraries.push_back(tgt);
  3453. }
  3454. }
  3455. }
  3456. for(std::vector<cmTarget*>::const_iterator
  3457. i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
  3458. {
  3459. (*i)->GetLanguages(languages, config);
  3460. }
  3461. }
  3462. //----------------------------------------------------------------------------
  3463. cmTarget::ImportInfo const*
  3464. cmTarget::GetImportInfo(const std::string& config) const
  3465. {
  3466. // There is no imported information for non-imported targets.
  3467. if(!this->IsImported())
  3468. {
  3469. return 0;
  3470. }
  3471. // Lookup/compute/cache the import information for this
  3472. // configuration.
  3473. std::string config_upper;
  3474. if(!config.empty())
  3475. {
  3476. config_upper = cmSystemTools::UpperCase(config);
  3477. }
  3478. else
  3479. {
  3480. config_upper = "NOCONFIG";
  3481. }
  3482. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  3483. ImportInfoMapType::const_iterator i =
  3484. this->Internal->ImportInfoMap.find(config_upper);
  3485. if(i == this->Internal->ImportInfoMap.end())
  3486. {
  3487. ImportInfo info;
  3488. this->ComputeImportInfo(config_upper, info);
  3489. ImportInfoMapType::value_type entry(config_upper, info);
  3490. i = this->Internal->ImportInfoMap.insert(entry).first;
  3491. }
  3492. if(this->GetType() == INTERFACE_LIBRARY)
  3493. {
  3494. return &i->second;
  3495. }
  3496. // If the location is empty then the target is not available for
  3497. // this configuration.
  3498. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  3499. {
  3500. return 0;
  3501. }
  3502. // Return the import information.
  3503. return &i->second;
  3504. }
  3505. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  3506. const char** loc,
  3507. const char** imp,
  3508. std::string& suffix) const
  3509. {
  3510. if (this->GetType() == INTERFACE_LIBRARY)
  3511. {
  3512. // This method attempts to find a config-specific LOCATION for the
  3513. // IMPORTED library. In the case of INTERFACE_LIBRARY, there is no
  3514. // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
  3515. // and valid response.
  3516. return true;
  3517. }
  3518. // Track the configuration-specific property suffix.
  3519. suffix = "_";
  3520. suffix += desired_config;
  3521. std::vector<std::string> mappedConfigs;
  3522. {
  3523. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  3524. mapProp += desired_config;
  3525. if(const char* mapValue = this->GetProperty(mapProp))
  3526. {
  3527. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  3528. }
  3529. }
  3530. // If we needed to find one of the mapped configurations but did not
  3531. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  3532. // library or an executable with exports.
  3533. bool allowImp = this->HasImportLibrary();
  3534. // If a mapping was found, check its configurations.
  3535. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  3536. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  3537. {
  3538. // Look for this configuration.
  3539. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  3540. std::string locProp = "IMPORTED_LOCATION_";
  3541. locProp += mcUpper;
  3542. *loc = this->GetProperty(locProp);
  3543. if(allowImp)
  3544. {
  3545. std::string impProp = "IMPORTED_IMPLIB_";
  3546. impProp += mcUpper;
  3547. *imp = this->GetProperty(impProp);
  3548. }
  3549. // If it was found, use it for all properties below.
  3550. if(*loc || *imp)
  3551. {
  3552. suffix = "_";
  3553. suffix += mcUpper;
  3554. }
  3555. }
  3556. // If we needed to find one of the mapped configurations but did not
  3557. // then the target is not found. The project does not want any
  3558. // other configuration.
  3559. if(!mappedConfigs.empty() && !*loc && !*imp)
  3560. {
  3561. return false;
  3562. }
  3563. // If we have not yet found it then there are no mapped
  3564. // configurations. Look for an exact-match.
  3565. if(!*loc && !*imp)
  3566. {
  3567. std::string locProp = "IMPORTED_LOCATION";
  3568. locProp += suffix;
  3569. *loc = this->GetProperty(locProp);
  3570. if(allowImp)
  3571. {
  3572. std::string impProp = "IMPORTED_IMPLIB";
  3573. impProp += suffix;
  3574. *imp = this->GetProperty(impProp);
  3575. }
  3576. }
  3577. // If we have not yet found it then there are no mapped
  3578. // configurations and no exact match.
  3579. if(!*loc && !*imp)
  3580. {
  3581. // The suffix computed above is not useful.
  3582. suffix = "";
  3583. // Look for a configuration-less location. This may be set by
  3584. // manually-written code.
  3585. *loc = this->GetProperty("IMPORTED_LOCATION");
  3586. if(allowImp)
  3587. {
  3588. *imp = this->GetProperty("IMPORTED_IMPLIB");
  3589. }
  3590. }
  3591. // If we have not yet found it then the project is willing to try
  3592. // any available configuration.
  3593. if(!*loc && !*imp)
  3594. {
  3595. std::vector<std::string> availableConfigs;
  3596. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  3597. {
  3598. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  3599. }
  3600. for(std::vector<std::string>::const_iterator
  3601. aci = availableConfigs.begin();
  3602. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  3603. {
  3604. suffix = "_";
  3605. suffix += cmSystemTools::UpperCase(*aci);
  3606. std::string locProp = "IMPORTED_LOCATION";
  3607. locProp += suffix;
  3608. *loc = this->GetProperty(locProp);
  3609. if(allowImp)
  3610. {
  3611. std::string impProp = "IMPORTED_IMPLIB";
  3612. impProp += suffix;
  3613. *imp = this->GetProperty(impProp);
  3614. }
  3615. }
  3616. }
  3617. // If we have not yet found it then the target is not available.
  3618. if(!*loc && !*imp)
  3619. {
  3620. return false;
  3621. }
  3622. return true;
  3623. }
  3624. //----------------------------------------------------------------------------
  3625. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  3626. ImportInfo& info) const
  3627. {
  3628. // This method finds information about an imported target from its
  3629. // properties. The "IMPORTED_" namespace is reserved for properties
  3630. // defined by the project exporting the target.
  3631. // Initialize members.
  3632. info.NoSOName = false;
  3633. const char* loc = 0;
  3634. const char* imp = 0;
  3635. std::string suffix;
  3636. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  3637. {
  3638. return;
  3639. }
  3640. // Get the link interface.
  3641. {
  3642. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  3643. const char *propertyLibs = this->GetProperty(linkProp);
  3644. if (this->GetType() != INTERFACE_LIBRARY)
  3645. {
  3646. if(!propertyLibs)
  3647. {
  3648. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  3649. linkProp += suffix;
  3650. propertyLibs = this->GetProperty(linkProp);
  3651. }
  3652. if(!propertyLibs)
  3653. {
  3654. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  3655. propertyLibs = this->GetProperty(linkProp);
  3656. }
  3657. }
  3658. if(propertyLibs)
  3659. {
  3660. info.LibrariesProp = linkProp;
  3661. info.Libraries = propertyLibs;
  3662. }
  3663. }
  3664. if(this->GetType() == INTERFACE_LIBRARY)
  3665. {
  3666. return;
  3667. }
  3668. // A provided configuration has been chosen. Load the
  3669. // configuration's properties.
  3670. // Get the location.
  3671. if(loc)
  3672. {
  3673. info.Location = loc;
  3674. }
  3675. else
  3676. {
  3677. std::string impProp = "IMPORTED_LOCATION";
  3678. impProp += suffix;
  3679. if(const char* config_location = this->GetProperty(impProp))
  3680. {
  3681. info.Location = config_location;
  3682. }
  3683. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  3684. {
  3685. info.Location = location;
  3686. }
  3687. }
  3688. // Get the soname.
  3689. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3690. {
  3691. std::string soProp = "IMPORTED_SONAME";
  3692. soProp += suffix;
  3693. if(const char* config_soname = this->GetProperty(soProp))
  3694. {
  3695. info.SOName = config_soname;
  3696. }
  3697. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  3698. {
  3699. info.SOName = soname;
  3700. }
  3701. }
  3702. // Get the "no-soname" mark.
  3703. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3704. {
  3705. std::string soProp = "IMPORTED_NO_SONAME";
  3706. soProp += suffix;
  3707. if(const char* config_no_soname = this->GetProperty(soProp))
  3708. {
  3709. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  3710. }
  3711. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  3712. {
  3713. info.NoSOName = cmSystemTools::IsOn(no_soname);
  3714. }
  3715. }
  3716. // Get the import library.
  3717. if(imp)
  3718. {
  3719. info.ImportLibrary = imp;
  3720. }
  3721. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3722. this->IsExecutableWithExports())
  3723. {
  3724. std::string impProp = "IMPORTED_IMPLIB";
  3725. impProp += suffix;
  3726. if(const char* config_implib = this->GetProperty(impProp))
  3727. {
  3728. info.ImportLibrary = config_implib;
  3729. }
  3730. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  3731. {
  3732. info.ImportLibrary = implib;
  3733. }
  3734. }
  3735. // Get the link dependencies.
  3736. {
  3737. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  3738. linkProp += suffix;
  3739. if(const char* config_libs = this->GetProperty(linkProp))
  3740. {
  3741. info.SharedDeps = config_libs;
  3742. }
  3743. else if(const char* libs =
  3744. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  3745. {
  3746. info.SharedDeps = libs;
  3747. }
  3748. }
  3749. // Get the link languages.
  3750. if(this->LinkLanguagePropagatesToDependents())
  3751. {
  3752. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  3753. linkProp += suffix;
  3754. if(const char* config_libs = this->GetProperty(linkProp))
  3755. {
  3756. info.Languages = config_libs;
  3757. }
  3758. else if(const char* libs =
  3759. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  3760. {
  3761. info.Languages = libs;
  3762. }
  3763. }
  3764. // Get the cyclic repetition count.
  3765. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3766. {
  3767. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  3768. linkProp += suffix;
  3769. if(const char* config_reps = this->GetProperty(linkProp))
  3770. {
  3771. sscanf(config_reps, "%u", &info.Multiplicity);
  3772. }
  3773. else if(const char* reps =
  3774. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  3775. {
  3776. sscanf(reps, "%u", &info.Multiplicity);
  3777. }
  3778. }
  3779. }
  3780. //----------------------------------------------------------------------------
  3781. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(
  3782. const std::string& config,
  3783. cmTarget const* head) const
  3784. {
  3785. // Imported targets have their own link interface.
  3786. if(this->IsImported())
  3787. {
  3788. return this->GetImportLinkInterface(config, head, false);
  3789. }
  3790. // Link interfaces are not supported for executables that do not
  3791. // export symbols.
  3792. if(this->GetType() == cmTarget::EXECUTABLE &&
  3793. !this->IsExecutableWithExports())
  3794. {
  3795. return 0;
  3796. }
  3797. // Lookup any existing link interface for this configuration.
  3798. std::string CONFIG = cmSystemTools::UpperCase(config);
  3799. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  3800. this->Internal->LinkInterfaceMap[CONFIG];
  3801. // If the link interface does not depend on the head target
  3802. // then return the one we computed first.
  3803. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3804. {
  3805. return &hm.begin()->second;
  3806. }
  3807. cmTargetInternals::OptionalLinkInterface& iface = hm[head];
  3808. if(!iface.LibrariesDone)
  3809. {
  3810. iface.LibrariesDone = true;
  3811. this->Internal->ComputeLinkInterfaceLibraries(
  3812. this, config, iface, head, false);
  3813. }
  3814. if(!iface.AllDone)
  3815. {
  3816. iface.AllDone = true;
  3817. if(iface.Exists)
  3818. {
  3819. this->Internal->ComputeLinkInterface(this, config, iface, head);
  3820. }
  3821. }
  3822. return iface.Exists? &iface : 0;
  3823. }
  3824. //----------------------------------------------------------------------------
  3825. cmTarget::LinkInterfaceLibraries const*
  3826. cmTarget::GetLinkInterfaceLibraries(const std::string& config,
  3827. cmTarget const* head,
  3828. bool usage_requirements_only) const
  3829. {
  3830. // Imported targets have their own link interface.
  3831. if(this->IsImported())
  3832. {
  3833. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  3834. }
  3835. // Link interfaces are not supported for executables that do not
  3836. // export symbols.
  3837. if(this->GetType() == cmTarget::EXECUTABLE &&
  3838. !this->IsExecutableWithExports())
  3839. {
  3840. return 0;
  3841. }
  3842. // Lookup any existing link interface for this configuration.
  3843. std::string CONFIG = cmSystemTools::UpperCase(config);
  3844. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  3845. (usage_requirements_only ?
  3846. this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] :
  3847. this->Internal->LinkInterfaceMap[CONFIG]);
  3848. // If the link interface does not depend on the head target
  3849. // then return the one we computed first.
  3850. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3851. {
  3852. return &hm.begin()->second;
  3853. }
  3854. cmTargetInternals::OptionalLinkInterface& iface = hm[head];
  3855. if(!iface.LibrariesDone)
  3856. {
  3857. iface.LibrariesDone = true;
  3858. this->Internal->ComputeLinkInterfaceLibraries(
  3859. this, config, iface, head, usage_requirements_only);
  3860. }
  3861. return iface.Exists? &iface : 0;
  3862. }
  3863. //----------------------------------------------------------------------------
  3864. cmTarget::LinkInterface const*
  3865. cmTarget::GetImportLinkInterface(const std::string& config,
  3866. cmTarget const* headTarget,
  3867. bool usage_requirements_only) const
  3868. {
  3869. cmTarget::ImportInfo const* info = this->GetImportInfo(config);
  3870. if(!info)
  3871. {
  3872. return 0;
  3873. }
  3874. std::string CONFIG = cmSystemTools::UpperCase(config);
  3875. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  3876. (usage_requirements_only ?
  3877. this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] :
  3878. this->Internal->LinkInterfaceMap[CONFIG]);
  3879. // If the link interface does not depend on the head target
  3880. // then return the one we computed first.
  3881. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3882. {
  3883. return &hm.begin()->second;
  3884. }
  3885. cmTargetInternals::OptionalLinkInterface& iface = hm[headTarget];
  3886. if(!iface.AllDone)
  3887. {
  3888. iface.AllDone = true;
  3889. iface.Multiplicity = info->Multiplicity;
  3890. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  3891. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  3892. headTarget, usage_requirements_only,
  3893. iface.Libraries,
  3894. iface.HadHeadSensitiveCondition);
  3895. std::vector<std::string> deps;
  3896. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  3897. this->LookupLinkItems(deps, iface.SharedDeps);
  3898. }
  3899. return &iface;
  3900. }
  3901. //----------------------------------------------------------------------------
  3902. void
  3903. cmTargetInternals::ComputeLinkInterfaceLibraries(
  3904. cmTarget const* thisTarget,
  3905. const std::string& config,
  3906. OptionalLinkInterface& iface,
  3907. cmTarget const* headTarget,
  3908. bool usage_requirements_only)
  3909. {
  3910. // Construct the property name suffix for this configuration.
  3911. std::string suffix = "_";
  3912. if(!config.empty())
  3913. {
  3914. suffix += cmSystemTools::UpperCase(config);
  3915. }
  3916. else
  3917. {
  3918. suffix += "NOCONFIG";
  3919. }
  3920. // An explicit list of interface libraries may be set for shared
  3921. // libraries and executables that export symbols.
  3922. const char* explicitLibraries = 0;
  3923. std::string linkIfaceProp;
  3924. if(thisTarget->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  3925. thisTarget->GetPolicyStatusCMP0022() != cmPolicies::WARN)
  3926. {
  3927. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  3928. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  3929. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  3930. }
  3931. else if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY ||
  3932. thisTarget->IsExecutableWithExports())
  3933. {
  3934. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  3935. // shared lib or executable.
  3936. // Lookup the per-configuration property.
  3937. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  3938. linkIfaceProp += suffix;
  3939. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  3940. // If not set, try the generic property.
  3941. if(!explicitLibraries)
  3942. {
  3943. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  3944. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  3945. }
  3946. }
  3947. if(explicitLibraries &&
  3948. thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  3949. !this->PolicyWarnedCMP0022)
  3950. {
  3951. // Compare the explicitly set old link interface properties to the
  3952. // preferred new link interface property one and warn if different.
  3953. const char* newExplicitLibraries =
  3954. thisTarget->GetProperty("INTERFACE_LINK_LIBRARIES");
  3955. if (newExplicitLibraries
  3956. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  3957. {
  3958. std::ostringstream w;
  3959. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  3960. "Target \"" << thisTarget->GetName() << "\" has an "
  3961. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  3962. linkIfaceProp << " properties."
  3963. "\n"
  3964. "INTERFACE_LINK_LIBRARIES:\n"
  3965. " " << newExplicitLibraries << "\n" <<
  3966. linkIfaceProp << ":\n"
  3967. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  3968. thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  3969. this->PolicyWarnedCMP0022 = true;
  3970. }
  3971. }
  3972. // There is no implicit link interface for executables or modules
  3973. // so if none was explicitly set then there is no link interface.
  3974. if(!explicitLibraries &&
  3975. (thisTarget->GetType() == cmTarget::EXECUTABLE ||
  3976. (thisTarget->GetType() == cmTarget::MODULE_LIBRARY)))
  3977. {
  3978. return;
  3979. }
  3980. iface.Exists = true;
  3981. iface.ExplicitLibraries = explicitLibraries;
  3982. if(explicitLibraries)
  3983. {
  3984. // The interface libraries have been explicitly set.
  3985. thisTarget->ExpandLinkItems(linkIfaceProp, explicitLibraries, config,
  3986. headTarget, usage_requirements_only,
  3987. iface.Libraries,
  3988. iface.HadHeadSensitiveCondition);
  3989. }
  3990. else if (thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN
  3991. || thisTarget->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  3992. // If CMP0022 is NEW then the plain tll signature sets the
  3993. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  3994. // cleared the property explicitly and we should not fall back
  3995. // to the link implementation.
  3996. {
  3997. // The link implementation is the default link interface.
  3998. cmLinkImplementationLibraries const* impl =
  3999. thisTarget->GetLinkImplementationLibrariesInternal(config, headTarget);
  4000. iface.Libraries.insert(iface.Libraries.end(),
  4001. impl->Libraries.begin(), impl->Libraries.end());
  4002. if(thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4003. !this->PolicyWarnedCMP0022 && !usage_requirements_only)
  4004. {
  4005. // Compare the link implementation fallback link interface to the
  4006. // preferred new link interface property and warn if different.
  4007. std::vector<cmLinkItem> ifaceLibs;
  4008. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  4009. if(const char* newExplicitLibraries = thisTarget->GetProperty(newProp))
  4010. {
  4011. bool hadHeadSensitiveConditionDummy = false;
  4012. thisTarget->ExpandLinkItems(newProp, newExplicitLibraries, config,
  4013. headTarget, usage_requirements_only,
  4014. ifaceLibs, hadHeadSensitiveConditionDummy);
  4015. }
  4016. if (ifaceLibs != iface.Libraries)
  4017. {
  4018. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  4019. std::string newLibraries = cmJoin(ifaceLibs, ";");
  4020. if(oldLibraries.empty())
  4021. { oldLibraries = "(empty)"; }
  4022. if(newLibraries.empty())
  4023. { newLibraries = "(empty)"; }
  4024. std::ostringstream w;
  4025. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4026. "Target \"" << thisTarget->GetName() << "\" has an "
  4027. "INTERFACE_LINK_LIBRARIES property. "
  4028. "This should be preferred as the source of the link interface "
  4029. "for this library but because CMP0022 is not set CMake is "
  4030. "ignoring the property and using the link implementation "
  4031. "as the link interface instead."
  4032. "\n"
  4033. "INTERFACE_LINK_LIBRARIES:\n"
  4034. " " << newLibraries << "\n"
  4035. "Link implementation:\n"
  4036. " " << oldLibraries << "\n";
  4037. thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  4038. this->PolicyWarnedCMP0022 = true;
  4039. }
  4040. }
  4041. }
  4042. }
  4043. //----------------------------------------------------------------------------
  4044. void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
  4045. const std::string& config,
  4046. OptionalLinkInterface& iface,
  4047. cmTarget const* headTarget) const
  4048. {
  4049. if(iface.ExplicitLibraries)
  4050. {
  4051. if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY
  4052. || thisTarget->GetType() == cmTarget::STATIC_LIBRARY
  4053. || thisTarget->GetType() == cmTarget::INTERFACE_LIBRARY)
  4054. {
  4055. // Shared libraries may have runtime implementation dependencies
  4056. // on other shared libraries that are not in the interface.
  4057. UNORDERED_SET<std::string> emitted;
  4058. for(std::vector<cmLinkItem>::const_iterator
  4059. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  4060. {
  4061. emitted.insert(*li);
  4062. }
  4063. if (thisTarget->GetType() != cmTarget::INTERFACE_LIBRARY)
  4064. {
  4065. cmTarget::LinkImplementation const* impl =
  4066. thisTarget->GetLinkImplementation(config);
  4067. for(std::vector<cmLinkImplItem>::const_iterator
  4068. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  4069. {
  4070. if(emitted.insert(*li).second)
  4071. {
  4072. if(li->Target)
  4073. {
  4074. // This is a runtime dependency on another shared library.
  4075. if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
  4076. {
  4077. iface.SharedDeps.push_back(*li);
  4078. }
  4079. }
  4080. else
  4081. {
  4082. // TODO: Recognize shared library file names. Perhaps this
  4083. // should be moved to cmComputeLinkInformation, but that creates
  4084. // a chicken-and-egg problem since this list is needed for its
  4085. // construction.
  4086. }
  4087. }
  4088. }
  4089. }
  4090. }
  4091. }
  4092. else if (thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN
  4093. || thisTarget->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  4094. {
  4095. // The link implementation is the default link interface.
  4096. cmLinkImplementationLibraries const*
  4097. impl = thisTarget->GetLinkImplementationLibrariesInternal(config,
  4098. headTarget);
  4099. iface.ImplementationIsInterface = true;
  4100. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  4101. }
  4102. if(thisTarget->LinkLanguagePropagatesToDependents())
  4103. {
  4104. // Targets using this archive need its language runtime libraries.
  4105. if(cmTarget::LinkImplementation const* impl =
  4106. thisTarget->GetLinkImplementation(config))
  4107. {
  4108. iface.Languages = impl->Languages;
  4109. }
  4110. }
  4111. if(thisTarget->GetType() == cmTarget::STATIC_LIBRARY)
  4112. {
  4113. // Construct the property name suffix for this configuration.
  4114. std::string suffix = "_";
  4115. if(!config.empty())
  4116. {
  4117. suffix += cmSystemTools::UpperCase(config);
  4118. }
  4119. else
  4120. {
  4121. suffix += "NOCONFIG";
  4122. }
  4123. // How many repetitions are needed if this library has cyclic
  4124. // dependencies?
  4125. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4126. propName += suffix;
  4127. if(const char* config_reps = thisTarget->GetProperty(propName))
  4128. {
  4129. sscanf(config_reps, "%u", &iface.Multiplicity);
  4130. }
  4131. else if(const char* reps =
  4132. thisTarget->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  4133. {
  4134. sscanf(reps, "%u", &iface.Multiplicity);
  4135. }
  4136. }
  4137. }
  4138. //----------------------------------------------------------------------------
  4139. void cmTargetInternals::AddInterfaceEntries(
  4140. cmTarget const* thisTarget, std::string const& config,
  4141. std::string const& prop, std::vector<TargetPropertyEntry*>& entries)
  4142. {
  4143. if(cmLinkImplementationLibraries const* impl =
  4144. thisTarget->GetLinkImplementationLibraries(config))
  4145. {
  4146. for (std::vector<cmLinkImplItem>::const_iterator
  4147. it = impl->Libraries.begin(), end = impl->Libraries.end();
  4148. it != end; ++it)
  4149. {
  4150. if(it->Target)
  4151. {
  4152. std::string genex =
  4153. "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  4154. cmGeneratorExpression ge(it->Backtrace);
  4155. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  4156. cge->SetEvaluateForBuildsystem(true);
  4157. entries.push_back(
  4158. new cmTargetInternals::TargetPropertyEntry(cge, *it));
  4159. }
  4160. }
  4161. }
  4162. }
  4163. //----------------------------------------------------------------------------
  4164. cmTarget::LinkImplementation const*
  4165. cmTarget::GetLinkImplementation(const std::string& config) const
  4166. {
  4167. // There is no link implementation for imported targets.
  4168. if(this->IsImported())
  4169. {
  4170. return 0;
  4171. }
  4172. // Populate the link implementation for this configuration.
  4173. std::string CONFIG = cmSystemTools::UpperCase(config);
  4174. cmTargetInternals::OptionalLinkImplementation&
  4175. impl = this->Internal->LinkImplMap[CONFIG][this];
  4176. if(!impl.LibrariesDone)
  4177. {
  4178. impl.LibrariesDone = true;
  4179. this->Internal
  4180. ->ComputeLinkImplementationLibraries(this, config, impl, this);
  4181. }
  4182. if(!impl.LanguagesDone)
  4183. {
  4184. impl.LanguagesDone = true;
  4185. this->Internal->ComputeLinkImplementationLanguages(this, config, impl);
  4186. }
  4187. return &impl;
  4188. }
  4189. //----------------------------------------------------------------------------
  4190. cmLinkImplementationLibraries const*
  4191. cmTarget::GetLinkImplementationLibraries(const std::string& config) const
  4192. {
  4193. return this->GetLinkImplementationLibrariesInternal(config, this);
  4194. }
  4195. //----------------------------------------------------------------------------
  4196. cmLinkImplementationLibraries const*
  4197. cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config,
  4198. cmTarget const* head) const
  4199. {
  4200. // There is no link implementation for imported targets.
  4201. if(this->IsImported())
  4202. {
  4203. return 0;
  4204. }
  4205. // Populate the link implementation libraries for this configuration.
  4206. std::string CONFIG = cmSystemTools::UpperCase(config);
  4207. cmTargetInternals::HeadToLinkImplementationMap& hm =
  4208. this->Internal->LinkImplMap[CONFIG];
  4209. // If the link implementation does not depend on the head target
  4210. // then return the one we computed first.
  4211. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4212. {
  4213. return &hm.begin()->second;
  4214. }
  4215. cmTargetInternals::OptionalLinkImplementation& impl = hm[head];
  4216. if(!impl.LibrariesDone)
  4217. {
  4218. impl.LibrariesDone = true;
  4219. this->Internal
  4220. ->ComputeLinkImplementationLibraries(this, config, impl, head);
  4221. }
  4222. return &impl;
  4223. }
  4224. //----------------------------------------------------------------------------
  4225. void
  4226. cmTargetInternals::ComputeLinkImplementationLibraries(
  4227. cmTarget const* thisTarget,
  4228. const std::string& config,
  4229. OptionalLinkImplementation& impl,
  4230. cmTarget const* head) const
  4231. {
  4232. // Collect libraries directly linked in this configuration.
  4233. for (std::vector<cmValueWithOrigin>::const_iterator
  4234. le = this->LinkImplementationPropertyEntries.begin(),
  4235. end = this->LinkImplementationPropertyEntries.end();
  4236. le != end; ++le)
  4237. {
  4238. std::vector<std::string> llibs;
  4239. cmGeneratorExpressionDAGChecker dagChecker(
  4240. thisTarget->GetName(),
  4241. "LINK_LIBRARIES", 0, 0);
  4242. cmGeneratorExpression ge(le->Backtrace);
  4243. cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge =
  4244. ge.Parse(le->Value);
  4245. std::string const evaluated =
  4246. cge->Evaluate(thisTarget->Makefile, config, false, head, &dagChecker);
  4247. cmSystemTools::ExpandListArgument(evaluated, llibs);
  4248. if(cge->GetHadHeadSensitiveCondition())
  4249. {
  4250. impl.HadHeadSensitiveCondition = true;
  4251. }
  4252. for(std::vector<std::string>::const_iterator li = llibs.begin();
  4253. li != llibs.end(); ++li)
  4254. {
  4255. // Skip entries that resolve to the target itself or are empty.
  4256. std::string name = thisTarget->CheckCMP0004(*li);
  4257. if(name == thisTarget->GetName() || name.empty())
  4258. {
  4259. if(name == thisTarget->GetName())
  4260. {
  4261. bool noMessage = false;
  4262. cmake::MessageType messageType = cmake::FATAL_ERROR;
  4263. std::ostringstream e;
  4264. switch(thisTarget->GetPolicyStatusCMP0038())
  4265. {
  4266. case cmPolicies::WARN:
  4267. {
  4268. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  4269. messageType = cmake::AUTHOR_WARNING;
  4270. }
  4271. break;
  4272. case cmPolicies::OLD:
  4273. noMessage = true;
  4274. case cmPolicies::REQUIRED_IF_USED:
  4275. case cmPolicies::REQUIRED_ALWAYS:
  4276. case cmPolicies::NEW:
  4277. // Issue the fatal message.
  4278. break;
  4279. }
  4280. if(!noMessage)
  4281. {
  4282. e << "Target \"" << thisTarget->GetName() << "\" links to itself.";
  4283. thisTarget->Makefile->GetCMakeInstance()->IssueMessage(
  4284. messageType, e.str(), thisTarget->GetBacktrace());
  4285. if (messageType == cmake::FATAL_ERROR)
  4286. {
  4287. return;
  4288. }
  4289. }
  4290. }
  4291. continue;
  4292. }
  4293. // The entry is meant for this configuration.
  4294. impl.Libraries.push_back(
  4295. cmLinkImplItem(name, thisTarget->FindTargetToLink(name),
  4296. le->Backtrace, evaluated != le->Value));
  4297. }
  4298. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  4299. for (std::set<std::string>::const_iterator it = seenProps.begin();
  4300. it != seenProps.end(); ++it)
  4301. {
  4302. if (!thisTarget->GetProperty(*it))
  4303. {
  4304. thisTarget->LinkImplicitNullProperties.insert(*it);
  4305. }
  4306. }
  4307. cge->GetMaxLanguageStandard(thisTarget, thisTarget->MaxLanguageStandards);
  4308. }
  4309. cmTarget::LinkLibraryType linkType = thisTarget->ComputeLinkType(config);
  4310. cmTarget::LinkLibraryVectorType const& oldllibs =
  4311. thisTarget->GetOriginalLinkLibraries();
  4312. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  4313. li != oldllibs.end(); ++li)
  4314. {
  4315. if(li->second != cmTarget::GENERAL && li->second != linkType)
  4316. {
  4317. std::string name = thisTarget->CheckCMP0004(li->first);
  4318. if(name == thisTarget->GetName() || name.empty())
  4319. {
  4320. continue;
  4321. }
  4322. // Support OLD behavior for CMP0003.
  4323. impl.WrongConfigLibraries.push_back(
  4324. cmLinkItem(name, thisTarget->FindTargetToLink(name)));
  4325. }
  4326. }
  4327. }
  4328. //----------------------------------------------------------------------------
  4329. void
  4330. cmTargetInternals::ComputeLinkImplementationLanguages(
  4331. cmTarget const* thisTarget,
  4332. const std::string& config,
  4333. OptionalLinkImplementation& impl) const
  4334. {
  4335. // This target needs runtime libraries for its source languages.
  4336. std::set<std::string> languages;
  4337. // Get languages used in our source files.
  4338. thisTarget->GetLanguages(languages, config);
  4339. // Copy the set of langauges to the link implementation.
  4340. impl.Languages.insert(impl.Languages.begin(),
  4341. languages.begin(), languages.end());
  4342. }
  4343. //----------------------------------------------------------------------------
  4344. cmTarget const* cmTarget::FindTargetToLink(std::string const& name) const
  4345. {
  4346. cmTarget const* tgt = this->Makefile->FindTargetToUse(name);
  4347. // Skip targets that will not really be linked. This is probably a
  4348. // name conflict between an external library and an executable
  4349. // within the project.
  4350. if(tgt && tgt->GetType() == cmTarget::EXECUTABLE &&
  4351. !tgt->IsExecutableWithExports())
  4352. {
  4353. tgt = 0;
  4354. }
  4355. if(tgt && tgt->GetType() == cmTarget::OBJECT_LIBRARY)
  4356. {
  4357. std::ostringstream e;
  4358. e << "Target \"" << this->GetName() << "\" links to "
  4359. "OBJECT library \"" << tgt->GetName() << "\" but this is not "
  4360. "allowed. "
  4361. "One may link only to STATIC or SHARED libraries, or to executables "
  4362. "with the ENABLE_EXPORTS property set.";
  4363. cmake* cm = this->Makefile->GetCMakeInstance();
  4364. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4365. tgt = 0;
  4366. }
  4367. // Return the target found, if any.
  4368. return tgt;
  4369. }
  4370. //----------------------------------------------------------------------------
  4371. std::string cmTarget::CheckCMP0004(std::string const& item) const
  4372. {
  4373. // Strip whitespace off the library names because we used to do this
  4374. // in case variables were expanded at generate time. We no longer
  4375. // do the expansion but users link to libraries like " ${VAR} ".
  4376. std::string lib = item;
  4377. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  4378. if(pos != lib.npos)
  4379. {
  4380. lib = lib.substr(pos, lib.npos);
  4381. }
  4382. pos = lib.find_last_not_of(" \t\r\n");
  4383. if(pos != lib.npos)
  4384. {
  4385. lib = lib.substr(0, pos+1);
  4386. }
  4387. if(lib != item)
  4388. {
  4389. cmake* cm = this->Makefile->GetCMakeInstance();
  4390. switch(this->GetPolicyStatusCMP0004())
  4391. {
  4392. case cmPolicies::WARN:
  4393. {
  4394. std::ostringstream w;
  4395. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  4396. << "Target \"" << this->GetName() << "\" links to item \""
  4397. << item << "\" which has leading or trailing whitespace.";
  4398. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  4399. this->GetBacktrace());
  4400. }
  4401. case cmPolicies::OLD:
  4402. break;
  4403. case cmPolicies::NEW:
  4404. {
  4405. std::ostringstream e;
  4406. e << "Target \"" << this->GetName() << "\" links to item \""
  4407. << item << "\" which has leading or trailing whitespace. "
  4408. << "This is now an error according to policy CMP0004.";
  4409. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4410. }
  4411. break;
  4412. case cmPolicies::REQUIRED_IF_USED:
  4413. case cmPolicies::REQUIRED_ALWAYS:
  4414. {
  4415. std::ostringstream e;
  4416. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  4417. << "Target \"" << this->GetName() << "\" links to item \""
  4418. << item << "\" which has leading or trailing whitespace.";
  4419. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4420. }
  4421. break;
  4422. }
  4423. }
  4424. return lib;
  4425. }
  4426. //----------------------------------------------------------------------------
  4427. cmTargetInternalPointer::cmTargetInternalPointer()
  4428. {
  4429. this->Pointer = new cmTargetInternals;
  4430. }
  4431. //----------------------------------------------------------------------------
  4432. cmTargetInternalPointer
  4433. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  4434. {
  4435. // Ideally cmTarget instances should never be copied. However until
  4436. // we can make a sweep to remove that, this copy constructor avoids
  4437. // allowing the resources (Internals) to be copied.
  4438. this->Pointer = new cmTargetInternals(*r.Pointer);
  4439. }
  4440. //----------------------------------------------------------------------------
  4441. cmTargetInternalPointer::~cmTargetInternalPointer()
  4442. {
  4443. cmDeleteAll(this->Pointer->IncludeDirectoriesItems);
  4444. cmDeleteAll(this->Pointer->CompileOptionsItems);
  4445. cmDeleteAll(this->Pointer->CompileFeaturesItems);
  4446. cmDeleteAll(this->Pointer->CompileDefinitionsItems);
  4447. cmDeleteAll(this->Pointer->SourceEntries);
  4448. delete this->Pointer;
  4449. }
  4450. //----------------------------------------------------------------------------
  4451. cmTargetInternalPointer&
  4452. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  4453. {
  4454. if(this == &r) { return *this; } // avoid warning on HP about self check
  4455. // Ideally cmTarget instances should never be copied. However until
  4456. // we can make a sweep to remove that, this copy constructor avoids
  4457. // allowing the resources (Internals) to be copied.
  4458. cmTargetInternals* oldPointer = this->Pointer;
  4459. this->Pointer = new cmTargetInternals(*r.Pointer);
  4460. delete oldPointer;
  4461. return *this;
  4462. }