cmTarget.cxx 160 KB

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