cmTarget.cxx 162 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688
  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 "cmLocalGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmDocumentCompileDefinitions.h"
  18. #include "cmListFileCache.h"
  19. #include "cmGeneratorExpression.h"
  20. #include <cmsys/RegularExpression.hxx>
  21. #include <map>
  22. #include <set>
  23. #include <queue>
  24. #include <stdlib.h> // required for atof
  25. #include <assert.h>
  26. const char* cmTarget::GetTargetTypeName(TargetType targetType)
  27. {
  28. switch( targetType )
  29. {
  30. case cmTarget::STATIC_LIBRARY:
  31. return "STATIC_LIBRARY";
  32. case cmTarget::MODULE_LIBRARY:
  33. return "MODULE_LIBRARY";
  34. case cmTarget::SHARED_LIBRARY:
  35. return "SHARED_LIBRARY";
  36. case cmTarget::EXECUTABLE:
  37. return "EXECUTABLE";
  38. case cmTarget::UTILITY:
  39. return "UTILITY";
  40. case cmTarget::GLOBAL_TARGET:
  41. return "GLOBAL_TARGET";
  42. case cmTarget::INSTALL_FILES:
  43. return "INSTALL_FILES";
  44. case cmTarget::INSTALL_PROGRAMS:
  45. return "INSTALL_PROGRAMS";
  46. case cmTarget::INSTALL_DIRECTORY:
  47. return "INSTALL_DIRECTORY";
  48. case cmTarget::UNKNOWN_LIBRARY:
  49. return "UNKNOWN_LIBRARY";
  50. }
  51. assert(0 && "Unexpected target type");
  52. return 0;
  53. }
  54. //----------------------------------------------------------------------------
  55. struct cmTarget::OutputInfo
  56. {
  57. std::string OutDir;
  58. std::string ImpDir;
  59. };
  60. //----------------------------------------------------------------------------
  61. struct cmTarget::ImportInfo
  62. {
  63. bool NoSOName;
  64. std::string Location;
  65. std::string SOName;
  66. std::string ImportLibrary;
  67. cmTarget::LinkInterface LinkInterface;
  68. };
  69. //----------------------------------------------------------------------------
  70. class cmTargetInternals
  71. {
  72. public:
  73. cmTargetInternals()
  74. {
  75. this->SourceFileFlagsConstructed = false;
  76. }
  77. cmTargetInternals(cmTargetInternals const& r)
  78. {
  79. this->SourceFileFlagsConstructed = false;
  80. // Only some of these entries are part of the object state.
  81. // Others not copied here are result caches.
  82. this->SourceEntries = r.SourceEntries;
  83. }
  84. typedef cmTarget::SourceFileFlags SourceFileFlags;
  85. std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
  86. bool SourceFileFlagsConstructed;
  87. // The backtrace when the target was created.
  88. cmListFileBacktrace Backtrace;
  89. // Cache link interface computation from each configuration.
  90. struct OptionalLinkInterface: public cmTarget::LinkInterface
  91. {
  92. OptionalLinkInterface(): Exists(false) {}
  93. bool Exists;
  94. };
  95. typedef std::map<cmStdString, OptionalLinkInterface> LinkInterfaceMapType;
  96. LinkInterfaceMapType LinkInterfaceMap;
  97. typedef std::map<cmStdString, cmTarget::OutputInfo> OutputInfoMapType;
  98. OutputInfoMapType OutputInfoMap;
  99. typedef std::map<cmStdString, cmTarget::ImportInfo> ImportInfoMapType;
  100. ImportInfoMapType ImportInfoMap;
  101. // Cache link implementation computation from each configuration.
  102. typedef std::map<cmStdString, cmTarget::LinkImplementation> LinkImplMapType;
  103. LinkImplMapType LinkImplMap;
  104. typedef std::map<cmStdString, cmTarget::LinkClosure> LinkClosureMapType;
  105. LinkClosureMapType LinkClosureMap;
  106. struct SourceEntry { std::vector<cmSourceFile*> Depends; };
  107. typedef std::map<cmSourceFile*, SourceEntry> SourceEntriesType;
  108. SourceEntriesType SourceEntries;
  109. };
  110. //----------------------------------------------------------------------------
  111. cmTarget::cmTarget()
  112. {
  113. this->Makefile = 0;
  114. this->PolicyStatusCMP0003 = cmPolicies::WARN;
  115. this->PolicyStatusCMP0004 = cmPolicies::WARN;
  116. this->PolicyStatusCMP0008 = cmPolicies::WARN;
  117. this->LinkLibrariesAnalyzed = false;
  118. this->HaveInstallRule = false;
  119. this->DLLPlatform = false;
  120. this->IsImportedTarget = false;
  121. }
  122. //----------------------------------------------------------------------------
  123. void cmTarget::DefineProperties(cmake *cm)
  124. {
  125. cm->DefineProperty
  126. ("AUTOMOC", cmProperty::TARGET,
  127. "Should the target be processed with automoc (for Qt projects).",
  128. "AUTOMOC is a boolean specifying whether CMake will handle "
  129. "the Qt moc preprocessor automatically, i.e. without having to use "
  130. "the QT4_WRAP_CPP() macro. Currently Qt4 is supported. "
  131. "When this property is set to TRUE, CMake will scan the source files "
  132. "at build time and invoke moc accordingly. "
  133. "If an #include statement like #include \"moc_foo.cpp\" is found, "
  134. "the Q_OBJECT class declaration is expected in the header, and moc is "
  135. "run on the header file. "
  136. "If an #include statement like #include \"foo.moc\" is found, "
  137. "then a Q_OBJECT is expected in the current source file and moc "
  138. "is run on the file itself. "
  139. "Additionally, all header files are parsed for Q_OBJECT macros, "
  140. "and if found, moc is also executed on those files. The resulting "
  141. "moc files, which are not included as shown above in any of the source "
  142. "files are included in a generated <targetname>_automoc.cpp file, "
  143. "which is compiled as part of the target."
  144. "This property is initialized by the value of the variable "
  145. "CMAKE_AUTOMOC if it is set when a target is created.\n"
  146. "Additional command line options for moc can be set via the "
  147. "AUTOMOC_MOC_OPTIONS property."
  148. );
  149. cm->DefineProperty
  150. ("AUTOMOC_MOC_OPTIONS", cmProperty::TARGET,
  151. "Additional options for moc when using automoc (see the AUTOMOC property)",
  152. "This property is only used if the AUTOMOC property is set to TRUE for "
  153. "this target. In this case, it holds additional command line options "
  154. "which will be used when moc is executed during the build, i.e. it is "
  155. "equivalent to the optional OPTIONS argument of the qt4_wrap_cpp() "
  156. "macro.\n"
  157. "By default it is empty.");
  158. cm->DefineProperty
  159. ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
  160. "Should build tree targets have install tree rpaths.",
  161. "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
  162. "the target in the build tree with the INSTALL_RPATH. This takes "
  163. "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
  164. "before installation. "
  165. "This property is initialized by the value of the variable "
  166. "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
  167. cm->DefineProperty
  168. ("COMPILE_FLAGS", cmProperty::TARGET,
  169. "Additional flags to use when compiling this target's sources.",
  170. "The COMPILE_FLAGS property sets additional compiler flags used "
  171. "to build sources within the target. Use COMPILE_DEFINITIONS "
  172. "to pass additional preprocessor definitions.");
  173. cm->DefineProperty
  174. ("COMPILE_DEFINITIONS", cmProperty::TARGET,
  175. "Preprocessor definitions for compiling a target's sources.",
  176. "The COMPILE_DEFINITIONS property may be set to a "
  177. "semicolon-separated list of preprocessor "
  178. "definitions using the syntax VAR or VAR=value. Function-style "
  179. "definitions are not supported. CMake will automatically escape "
  180. "the value correctly for the native build system (note that CMake "
  181. "language syntax may require escapes to specify some values). "
  182. "This property may be set on a per-configuration basis using the name "
  183. "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
  184. "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
  185. "CMake will automatically drop some definitions that "
  186. "are not supported by the native build tool. "
  187. "The VS6 IDE does not support definition values with spaces "
  188. "(but NMake does).\n"
  189. CM_DOCUMENT_COMPILE_DEFINITIONS_DISCLAIMER);
  190. cm->DefineProperty
  191. ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
  192. "Per-configuration preprocessor definitions on a target.",
  193. "This is the configuration-specific version of COMPILE_DEFINITIONS.");
  194. cm->DefineProperty
  195. ("DEFINE_SYMBOL", cmProperty::TARGET,
  196. "Define a symbol when compiling this target's sources.",
  197. "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
  198. "compiling sources in a shared library. "
  199. "If not set here then it is set to target_EXPORTS by default "
  200. "(with some substitutions if the target is not a valid C "
  201. "identifier). This is useful for headers to know whether they are "
  202. "being included from inside their library our outside to properly "
  203. "setup dllexport/dllimport decorations. ");
  204. cm->DefineProperty
  205. ("DEBUG_POSTFIX", cmProperty::TARGET,
  206. "See target property <CONFIG>_POSTFIX.",
  207. "This property is a special case of the more-general <CONFIG>_POSTFIX "
  208. "property for the DEBUG configuration.");
  209. cm->DefineProperty
  210. ("<CONFIG>_POSTFIX", cmProperty::TARGET,
  211. "Postfix to append to the target file name for configuration <CONFIG>.",
  212. "When building with configuration <CONFIG> the value of this property "
  213. "is appended to the target file name built on disk. "
  214. "For non-executable targets, this property is initialized by the value "
  215. "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
  216. "created. "
  217. "This property is ignored on the Mac for Frameworks and App Bundles.");
  218. cm->DefineProperty
  219. ("EchoString", cmProperty::TARGET,
  220. "A message to be displayed when the target is built.",
  221. "A message to display on some generators (such as makefiles) when "
  222. "the target is built.");
  223. cm->DefineProperty
  224. ("BUNDLE", cmProperty::TARGET,
  225. "This target is a CFBundle on the Mac.",
  226. "If a module library target has this property set to true it will "
  227. "be built as a CFBundle when built on the mac. It will have the "
  228. "directory structure required for a CFBundle and will be suitable "
  229. "to be used for creating Browser Plugins or other application "
  230. "resources.");
  231. cm->DefineProperty
  232. ("BUNDLE_EXTENSION", cmProperty::TARGET,
  233. "The file extension used to name a BUNDLE target on the Mac.",
  234. "The default value is \"bundle\" - you can also use \"plugin\" or "
  235. "whatever file extension is required by the host app for your "
  236. "bundle.");
  237. cm->DefineProperty
  238. ("FRAMEWORK", cmProperty::TARGET,
  239. "This target is a framework on the Mac.",
  240. "If a shared library target has this property set to true it will "
  241. "be built as a framework when built on the mac. It will have the "
  242. "directory structure required for a framework and will be suitable "
  243. "to be used with the -framework option");
  244. cm->DefineProperty
  245. ("HAS_CXX", cmProperty::TARGET,
  246. "Link the target using the C++ linker tool (obsolete).",
  247. "This is equivalent to setting the LINKER_LANGUAGE property to CXX. "
  248. "See that property's documentation for details.");
  249. cm->DefineProperty
  250. ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
  251. "Specify #include line transforms for dependencies in a target.",
  252. "This property specifies rules to transform macro-like #include lines "
  253. "during implicit dependency scanning of C and C++ source files. "
  254. "The list of rules must be semicolon-separated with each entry of "
  255. "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
  256. "During dependency scanning occurrences of A_MACRO(...) on #include "
  257. "lines will be replaced by the value given with the macro argument "
  258. "substituted for '%'. For example, the entry\n"
  259. " MYDIR(%)=<mydir/%>\n"
  260. "will convert lines of the form\n"
  261. " #include MYDIR(myheader.h)\n"
  262. "to\n"
  263. " #include <mydir/myheader.h>\n"
  264. "allowing the dependency to be followed.\n"
  265. "This property applies to sources in the target on which it is set.");
  266. cm->DefineProperty
  267. ("IMPORT_PREFIX", cmProperty::TARGET,
  268. "What comes before the import library name.",
  269. "Similar to the target property PREFIX, but used for import libraries "
  270. "(typically corresponding to a DLL) instead of regular libraries. "
  271. "A target property that can be set to override the prefix "
  272. "(such as \"lib\") on an import library name.");
  273. cm->DefineProperty
  274. ("IMPORT_SUFFIX", cmProperty::TARGET,
  275. "What comes after the import library name.",
  276. "Similar to the target property SUFFIX, but used for import libraries "
  277. "(typically corresponding to a DLL) instead of regular libraries. "
  278. "A target property that can be set to override the suffix "
  279. "(such as \".lib\") on an import library name.");
  280. cm->DefineProperty
  281. ("IMPORTED", cmProperty::TARGET,
  282. "Read-only indication of whether a target is IMPORTED.",
  283. "The boolean value of this property is true for targets created with "
  284. "the IMPORTED option to add_executable or add_library. "
  285. "It is false for targets built within the project.");
  286. cm->DefineProperty
  287. ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
  288. "Configurations provided for an IMPORTED target.",
  289. "Lists configuration names available for an IMPORTED target. "
  290. "The names correspond to configurations defined in the project from "
  291. "which the target is imported. "
  292. "If the importing project uses a different set of configurations "
  293. "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
  294. "property. "
  295. "Ignored for non-imported targets.");
  296. cm->DefineProperty
  297. ("IMPORTED_IMPLIB", cmProperty::TARGET,
  298. "Full path to the import library for an IMPORTED target.",
  299. "Specifies the location of the \".lib\" part of a windows DLL. "
  300. "Ignored for non-imported targets.");
  301. cm->DefineProperty
  302. ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
  303. "Per-configuration version of IMPORTED_IMPLIB property.",
  304. "This property is used when loading settings for the <CONFIG> "
  305. "configuration of an imported target. "
  306. "Configuration names correspond to those provided by the project "
  307. "from which the target is imported.");
  308. cm->DefineProperty
  309. ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
  310. "Dependent shared libraries of an imported shared library.",
  311. "Shared libraries may be linked to other shared libraries as part "
  312. "of their implementation. On some platforms the linker searches "
  313. "for the dependent libraries of shared libraries they are including "
  314. "in the link. This property lists "
  315. "the dependent shared libraries of an imported library. The list "
  316. "should be disjoint from the list of interface libraries in the "
  317. "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring "
  318. "dependent shared libraries to be found at link time CMake uses this "
  319. "list to add appropriate files or paths to the link command line. "
  320. "Ignored for non-imported targets.");
  321. cm->DefineProperty
  322. ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  323. "Per-configuration version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
  324. "This property is used when loading settings for the <CONFIG> "
  325. "configuration of an imported target. "
  326. "Configuration names correspond to those provided by the project "
  327. "from which the target is imported. "
  328. "If set, this property completely overrides the generic property "
  329. "for the named configuration.");
  330. cm->DefineProperty
  331. ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
  332. "Transitive link interface of an IMPORTED target.",
  333. "Lists libraries whose interface is included when an IMPORTED library "
  334. "target is linked to another target. "
  335. "The libraries will be included on the link line for the target. "
  336. "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
  337. "to all imported target types, including STATIC libraries. "
  338. "This property is ignored for non-imported targets.");
  339. cm->DefineProperty
  340. ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  341. "Per-configuration version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
  342. "This property is used when loading settings for the <CONFIG> "
  343. "configuration of an imported target. "
  344. "Configuration names correspond to those provided by the project "
  345. "from which the target is imported. "
  346. "If set, this property completely overrides the generic property "
  347. "for the named configuration.");
  348. cm->DefineProperty
  349. ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET,
  350. "Languages compiled into an IMPORTED static library.",
  351. "Lists languages of soure files compiled to produce a STATIC IMPORTED "
  352. "library (such as \"C\" or \"CXX\"). "
  353. "CMake accounts for these languages when computing how to link a "
  354. "target to the imported library. "
  355. "For example, when a C executable links to an imported C++ static "
  356. "library CMake chooses the C++ linker to satisfy language runtime "
  357. "dependencies of the static library. "
  358. "\n"
  359. "This property is ignored for targets that are not STATIC libraries. "
  360. "This property is ignored for non-imported targets.");
  361. cm->DefineProperty
  362. ("IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>", cmProperty::TARGET,
  363. "Per-configuration version of IMPORTED_LINK_INTERFACE_LANGUAGES.",
  364. "This property is used when loading settings for the <CONFIG> "
  365. "configuration of an imported target. "
  366. "Configuration names correspond to those provided by the project "
  367. "from which the target is imported. "
  368. "If set, this property completely overrides the generic property "
  369. "for the named configuration.");
  370. cm->DefineProperty
  371. ("IMPORTED_LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
  372. "Repetition count for cycles of IMPORTED static libraries.",
  373. "This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.");
  374. cm->DefineProperty
  375. ("IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
  376. "Per-configuration repetition count for cycles of IMPORTED archives.",
  377. "This is the configuration-specific version of "
  378. "IMPORTED_LINK_INTERFACE_MULTIPLICITY. "
  379. "If set, this property completely overrides the generic property "
  380. "for the named configuration.");
  381. cm->DefineProperty
  382. ("IMPORTED_LOCATION", cmProperty::TARGET,
  383. "Full path to the main file on disk for an IMPORTED target.",
  384. "Specifies the location of an IMPORTED target file on disk. "
  385. "For executables this is the location of the executable file. "
  386. "For bundles on OS X this is the location of the executable file "
  387. "inside Contents/MacOS under the application bundle folder. "
  388. "For static libraries and modules this is the location of the "
  389. "library or module. "
  390. "For shared libraries on non-DLL platforms this is the location of "
  391. "the shared library. "
  392. "For frameworks on OS X this is the location of the library file "
  393. "symlink just inside the framework folder. "
  394. "For DLLs this is the location of the \".dll\" part of the library. "
  395. "For UNKNOWN libraries this is the location of the file to be linked. "
  396. "Ignored for non-imported targets.");
  397. cm->DefineProperty
  398. ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
  399. "Per-configuration version of IMPORTED_LOCATION property.",
  400. "This property is used when loading settings for the <CONFIG> "
  401. "configuration of an imported target. "
  402. "Configuration names correspond to those provided by the project "
  403. "from which the target is imported.");
  404. cm->DefineProperty
  405. ("IMPORTED_SONAME", cmProperty::TARGET,
  406. "The \"soname\" of an IMPORTED target of shared library type.",
  407. "Specifies the \"soname\" embedded in an imported shared library. "
  408. "This is meaningful only on platforms supporting the feature. "
  409. "Ignored for non-imported targets.");
  410. cm->DefineProperty
  411. ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
  412. "Per-configuration version of IMPORTED_SONAME property.",
  413. "This property is used when loading settings for the <CONFIG> "
  414. "configuration of an imported target. "
  415. "Configuration names correspond to those provided by the project "
  416. "from which the target is imported.");
  417. cm->DefineProperty
  418. ("IMPORTED_NO_SONAME", cmProperty::TARGET,
  419. "Specifies that an IMPORTED shared library target has no \"soname\". ",
  420. "Set this property to true for an imported shared library file that "
  421. "has no \"soname\" field. "
  422. "CMake may adjust generated link commands for some platforms to prevent "
  423. "the linker from using the path to the library in place of its missing "
  424. "soname. "
  425. "Ignored for non-imported targets.");
  426. cm->DefineProperty
  427. ("IMPORTED_NO_SONAME_<CONFIG>", cmProperty::TARGET,
  428. "Per-configuration version of IMPORTED_NO_SONAME property.",
  429. "This property is used when loading settings for the <CONFIG> "
  430. "configuration of an imported target. "
  431. "Configuration names correspond to those provided by the project "
  432. "from which the target is imported.");
  433. cm->DefineProperty
  434. ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
  435. "Exclude the target from the all target.",
  436. "A property on a target that indicates if the target is excluded "
  437. "from the default build target. If it is not, then with a Makefile "
  438. "for example typing make will cause this target to be built. "
  439. "The same concept applies to the default build of other generators. "
  440. "Installing a target with EXCLUDE_FROM_ALL set to true has "
  441. "undefined behavior.");
  442. cm->DefineProperty
  443. ("INSTALL_NAME_DIR", cmProperty::TARGET,
  444. "Mac OSX directory name for installed targets.",
  445. "INSTALL_NAME_DIR is a string specifying the "
  446. "directory portion of the \"install_name\" field of shared libraries "
  447. "on Mac OSX to use in the installed targets. ");
  448. cm->DefineProperty
  449. ("INSTALL_RPATH", cmProperty::TARGET,
  450. "The rpath to use for installed targets.",
  451. "A semicolon-separated list specifying the rpath "
  452. "to use in installed targets (for platforms that support it). "
  453. "This property is initialized by the value of the variable "
  454. "CMAKE_INSTALL_RPATH if it is set when a target is created.");
  455. cm->DefineProperty
  456. ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
  457. "Add paths to linker search and installed rpath.",
  458. "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
  459. "append directories in the linker search path and outside the "
  460. "project to the INSTALL_RPATH. "
  461. "This property is initialized by the value of the variable "
  462. "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
  463. "created.");
  464. cm->DefineProperty
  465. ("INTERPROCEDURAL_OPTIMIZATION", cmProperty::TARGET,
  466. "Enable interprocedural optimization for a target.",
  467. "If set to true, enables interprocedural optimizations "
  468. "if they are known to be supported by the compiler.");
  469. cm->DefineProperty
  470. ("INTERPROCEDURAL_OPTIMIZATION_<CONFIG>", cmProperty::TARGET,
  471. "Per-configuration interprocedural optimization for a target.",
  472. "This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION. "
  473. "If set, this property overrides the generic property "
  474. "for the named configuration.");
  475. cm->DefineProperty
  476. ("LABELS", cmProperty::TARGET,
  477. "Specify a list of text labels associated with a target.",
  478. "Target label semantics are currently unspecified.");
  479. cm->DefineProperty
  480. ("LINK_FLAGS", cmProperty::TARGET,
  481. "Additional flags to use when linking this target.",
  482. "The LINK_FLAGS property can be used to add extra flags to the "
  483. "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
  484. "configuration <CONFIG>, "
  485. "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
  486. cm->DefineProperty
  487. ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
  488. "Per-configuration linker flags for a target.",
  489. "This is the configuration-specific version of LINK_FLAGS.");
  490. #define CM_LINK_SEARCH_SUMMARY \
  491. "Some linkers support switches such as -Bstatic and -Bdynamic " \
  492. "to determine whether to use static or shared libraries for -lXXX " \
  493. "options. CMake uses these options to set the link type for " \
  494. "libraries whose full paths are not known or (in some cases) are in " \
  495. "implicit link directories for the platform. "
  496. cm->DefineProperty
  497. ("LINK_SEARCH_START_STATIC", cmProperty::TARGET,
  498. "Assume the linker looks for static libraries by default.",
  499. CM_LINK_SEARCH_SUMMARY
  500. "By default the linker search type is assumed to be -Bdynamic at "
  501. "the beginning of the library list. This property switches the "
  502. "assumption to -Bstatic. It is intended for use when linking an "
  503. "executable statically (e.g. with the GNU -static option). "
  504. "See also LINK_SEARCH_END_STATIC.");
  505. cm->DefineProperty
  506. ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
  507. "End a link line such that static system libraries are used.",
  508. CM_LINK_SEARCH_SUMMARY
  509. "By default CMake adds an option at the end of the library list (if "
  510. "necessary) to set the linker search type back to its starting type. "
  511. "This property switches the final linker search type to -Bstatic "
  512. "regardless of how it started. "
  513. "See also LINK_SEARCH_START_STATIC.");
  514. cm->DefineProperty
  515. ("LINKER_LANGUAGE", cmProperty::TARGET,
  516. "Specifies language whose compiler will invoke the linker.",
  517. "For executables, shared libraries, and modules, this sets the "
  518. "language whose compiler is used to link the target "
  519. "(such as \"C\" or \"CXX\"). "
  520. "A typical value for an executable is the language of the source "
  521. "file providing the program entry point (main). "
  522. "If not set, the language with the highest linker preference "
  523. "value is the default. "
  524. "See documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables.");
  525. #define CM_LOCATION_UNDEFINED_BEHAVIOR \
  526. "\n" \
  527. "Do not set properties that affect the location of the target after " \
  528. "reading this property. These include properties whose names match " \
  529. "\"(RUNTIME|LIBRARY|ARCHIVE)_OUTPUT_(NAME|DIRECTORY)(_<CONFIG>)?\" " \
  530. "or \"(IMPLIB_)?(PREFIX|SUFFIX)\". " \
  531. "Failure to follow this rule is not diagnosed and leaves the location " \
  532. "of the target undefined."
  533. cm->DefineProperty
  534. ("LOCATION", cmProperty::TARGET,
  535. "Read-only location of a target on disk.",
  536. "For an imported target, this read-only property returns the value of "
  537. "the LOCATION_<CONFIG> property for an unspecified configuration "
  538. "<CONFIG> provided by the target.\n"
  539. "For a non-imported target, this property is provided for compatibility "
  540. "with CMake 2.4 and below. "
  541. "It was meant to get the location of an executable target's output file "
  542. "for use in add_custom_command. "
  543. "The path may contain a build-system-specific portion that "
  544. "is replaced at build time with the configuration getting built "
  545. "(such as \"$(ConfigurationName)\" in VS). "
  546. "In CMake 2.6 and above add_custom_command automatically recognizes a "
  547. "target name in its COMMAND and DEPENDS options and computes the "
  548. "target location. "
  549. "In CMake 2.8.4 and above add_custom_command recognizes generator "
  550. "expressions to refer to target locations anywhere in the command. "
  551. "Therefore this property is not needed for creating custom commands."
  552. CM_LOCATION_UNDEFINED_BEHAVIOR);
  553. cm->DefineProperty
  554. ("LOCATION_<CONFIG>", cmProperty::TARGET,
  555. "Read-only property providing a target location on disk.",
  556. "A read-only property that indicates where a target's main file is "
  557. "located on disk for the configuration <CONFIG>. "
  558. "The property is defined only for library and executable targets. "
  559. "An imported target may provide a set of configurations different "
  560. "from that of the importing project. "
  561. "By default CMake looks for an exact-match but otherwise uses an "
  562. "arbitrary available configuration. "
  563. "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
  564. "configurations explicitly."
  565. CM_LOCATION_UNDEFINED_BEHAVIOR);
  566. cm->DefineProperty
  567. ("LINK_DEPENDS", cmProperty::TARGET,
  568. "Additional files on which a target binary depends for linking.",
  569. "Specifies a semicolon-separated list of full-paths to files on which "
  570. "the link rule for this target depends. "
  571. "The target binary will be linked if any of the named files is newer "
  572. "than it."
  573. "\n"
  574. "This property is ignored by non-Makefile generators. "
  575. "It is intended to specify dependencies on \"linker scripts\" for "
  576. "custom Makefile link rules.");
  577. cm->DefineProperty
  578. ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
  579. "List public interface libraries for a shared library or executable.",
  580. "By default linking to a shared library target transitively "
  581. "links to targets with which the library itself was linked. "
  582. "For an executable with exports (see the ENABLE_EXPORTS property) "
  583. "no default transitive link dependencies are used. "
  584. "This property replaces the default transitive link dependencies with "
  585. "an explicit list. "
  586. "When the target is linked into another target the libraries "
  587. "listed (and recursively their link interface libraries) will be "
  588. "provided to the other target also. "
  589. "If the list is empty then no transitive link dependencies will be "
  590. "incorporated when this target is linked into another target even if "
  591. "the default set is non-empty. "
  592. "This property is initialized by the value of the variable "
  593. "CMAKE_LINK_INTERFACE_LIBRARIES if it is set when a target is "
  594. "created. "
  595. "This property is ignored for STATIC libraries.");
  596. cm->DefineProperty
  597. ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  598. "Per-configuration list of public interface libraries for a target.",
  599. "This is the configuration-specific version of "
  600. "LINK_INTERFACE_LIBRARIES. "
  601. "If set, this property completely overrides the generic property "
  602. "for the named configuration.");
  603. cm->DefineProperty
  604. ("LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
  605. "Repetition count for STATIC libraries with cyclic dependencies.",
  606. "When linking to a STATIC library target with cyclic dependencies the "
  607. "linker may need to scan more than once through the archives in the "
  608. "strongly connected component of the dependency graph. "
  609. "CMake by default constructs the link line so that the linker will "
  610. "scan through the component at least twice. "
  611. "This property specifies the minimum number of scans if it is larger "
  612. "than the default. "
  613. "CMake uses the largest value specified by any target in a component.");
  614. cm->DefineProperty
  615. ("LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
  616. "Per-configuration repetition count for cycles of STATIC libraries.",
  617. "This is the configuration-specific version of "
  618. "LINK_INTERFACE_MULTIPLICITY. "
  619. "If set, this property completely overrides the generic property "
  620. "for the named configuration.");
  621. cm->DefineProperty
  622. ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
  623. "Map from project configuration to IMPORTED target's configuration.",
  624. "List configurations of an imported target that may be used for "
  625. "the current project's <CONFIG> configuration. "
  626. "Targets imported from another project may not provide the same set "
  627. "of configuration names available in the current project. "
  628. "Setting this property tells CMake what imported configurations are "
  629. "suitable for use when building the <CONFIG> configuration. "
  630. "The first configuration in the list found to be provided by the "
  631. "imported target is selected. If no matching configurations are "
  632. "available the imported target is considered to be not found. "
  633. "This property is ignored for non-imported targets.",
  634. false /* TODO: make this chained */ );
  635. cm->DefineProperty
  636. ("OSX_ARCHITECTURES", cmProperty::TARGET,
  637. "Target specific architectures for OS X.",
  638. "The OSX_ARCHITECTURES property sets the target binary architecture "
  639. "for targets on OS X. "
  640. "This property is initialized by the value of the variable "
  641. "CMAKE_OSX_ARCHITECTURES if it is set when a target is created. "
  642. "Use OSX_ARCHITECTURES_<CONFIG> to set the binary architectures on a "
  643. "per-configuration basis. "
  644. "<CONFIG> is an upper-case name (ex: \"OSX_ARCHITECTURES_DEBUG\").");
  645. cm->DefineProperty
  646. ("OSX_ARCHITECTURES_<CONFIG>", cmProperty::TARGET,
  647. "Per-configuration OS X binary architectures for a target.",
  648. "This property is the configuration-specific version of "
  649. "OSX_ARCHITECTURES.");
  650. cm->DefineProperty
  651. ("OUTPUT_NAME", cmProperty::TARGET,
  652. "Output name for target files.",
  653. "This sets the base name for output files created for an executable or "
  654. "library target. "
  655. "If not set, the logical target name is used by default.");
  656. cm->DefineProperty
  657. ("OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  658. "Per-configuration target file base name.",
  659. "This is the configuration-specific version of OUTPUT_NAME.");
  660. cm->DefineProperty
  661. ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET,
  662. "Old per-configuration target file base name.",
  663. "This is a configuration-specific version of OUTPUT_NAME. "
  664. "Use OUTPUT_NAME_<CONFIG> instead.");
  665. cm->DefineProperty
  666. ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
  667. "Deprecated install support.",
  668. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  669. "old way to specify CMake scripts to run before and after "
  670. "installing a target. They are used only when the old "
  671. "INSTALL_TARGETS command is used to install the target. Use the "
  672. "INSTALL command instead.");
  673. cm->DefineProperty
  674. ("PREFIX", cmProperty::TARGET,
  675. "What comes before the library name.",
  676. "A target property that can be set to override the prefix "
  677. "(such as \"lib\") on a library name.");
  678. cm->DefineProperty
  679. ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
  680. "Deprecated install support.",
  681. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  682. "old way to specify CMake scripts to run before and after "
  683. "installing a target. They are used only when the old "
  684. "INSTALL_TARGETS command is used to install the target. Use the "
  685. "INSTALL command instead.");
  686. cm->DefineProperty
  687. ("PRIVATE_HEADER", cmProperty::TARGET,
  688. "Specify private header files in a FRAMEWORK shared library target.",
  689. "Shared library targets marked with the FRAMEWORK property generate "
  690. "frameworks on OS X and normal shared libraries on other platforms. "
  691. "This property may be set to a list of header files to be placed "
  692. "in the PrivateHeaders directory inside the framework folder. "
  693. "On non-Apple platforms these headers may be installed using the "
  694. "PRIVATE_HEADER option to the install(TARGETS) command.");
  695. cm->DefineProperty
  696. ("PUBLIC_HEADER", cmProperty::TARGET,
  697. "Specify public header files in a FRAMEWORK shared library target.",
  698. "Shared library targets marked with the FRAMEWORK property generate "
  699. "frameworks on OS X and normal shared libraries on other platforms. "
  700. "This property may be set to a list of header files to be placed "
  701. "in the Headers directory inside the framework folder. "
  702. "On non-Apple platforms these headers may be installed using the "
  703. "PUBLIC_HEADER option to the install(TARGETS) command.");
  704. cm->DefineProperty
  705. ("RESOURCE", cmProperty::TARGET,
  706. "Specify resource files in a FRAMEWORK shared library target.",
  707. "Shared library targets marked with the FRAMEWORK property generate "
  708. "frameworks on OS X and normal shared libraries on other platforms. "
  709. "This property may be set to a list of files to be placed "
  710. "in the Resources directory inside the framework folder. "
  711. "On non-Apple platforms these files may be installed using the "
  712. "RESOURCE option to the install(TARGETS) command.");
  713. cm->DefineProperty
  714. ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
  715. "Specify a launcher for compile rules.",
  716. "See the global property of the same name for details. "
  717. "This overrides the global and directory property for a target.",
  718. true);
  719. cm->DefineProperty
  720. ("RULE_LAUNCH_LINK", cmProperty::TARGET,
  721. "Specify a launcher for link rules.",
  722. "See the global property of the same name for details. "
  723. "This overrides the global and directory property for a target.",
  724. true);
  725. cm->DefineProperty
  726. ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
  727. "Specify a launcher for custom rules.",
  728. "See the global property of the same name for details. "
  729. "This overrides the global and directory property for a target.",
  730. true);
  731. cm->DefineProperty
  732. ("SKIP_BUILD_RPATH", cmProperty::TARGET,
  733. "Should rpaths be used for the build tree.",
  734. "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
  735. "generation of an rpath allowing the target to run from the "
  736. "build tree. "
  737. "This property is initialized by the value of the variable "
  738. "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
  739. cm->DefineProperty
  740. ("SOVERSION", cmProperty::TARGET,
  741. "What version number is this target.",
  742. "For shared libraries VERSION and SOVERSION can be used to specify "
  743. "the build version and api version respectively. When building or "
  744. "installing appropriate symlinks are created if the platform "
  745. "supports symlinks and the linker supports so-names. "
  746. "If only one of both is specified the missing is assumed to have "
  747. "the same version number. "
  748. "For shared libraries and executables on Windows the VERSION "
  749. "attribute is parsed to extract a \"major.minor\" version number. "
  750. "These numbers are used as the image version of the binary. ");
  751. cm->DefineProperty
  752. ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
  753. "Extra flags to use when linking static libraries.",
  754. "Extra flags to use when linking a static library.");
  755. cm->DefineProperty
  756. ("STATIC_LIBRARY_FLAGS_<CONFIG>", cmProperty::TARGET,
  757. "Per-configuration flags for creating a static library.",
  758. "This is the configuration-specific version of STATIC_LIBRARY_FLAGS.");
  759. cm->DefineProperty
  760. ("SUFFIX", cmProperty::TARGET,
  761. "What comes after the library name.",
  762. "A target property that can be set to override the suffix "
  763. "(such as \".so\") on a library name.");
  764. cm->DefineProperty
  765. ("TYPE", cmProperty::TARGET,
  766. "The type of the target.",
  767. "This read-only property can be used to test the type of the given "
  768. "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
  769. "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
  770. cm->DefineProperty
  771. ("VERSION", cmProperty::TARGET,
  772. "What version number is this target.",
  773. "For shared libraries VERSION and SOVERSION can be used to specify "
  774. "the build version and api version respectively. When building or "
  775. "installing appropriate symlinks are created if the platform "
  776. "supports symlinks and the linker supports so-names. "
  777. "If only one of both is specified the missing is assumed to have "
  778. "the same version number. "
  779. "For executables VERSION can be used to specify the build version. "
  780. "When building or installing appropriate symlinks are created if "
  781. "the platform supports symlinks. "
  782. "For shared libraries and executables on Windows the VERSION "
  783. "attribute is parsed to extract a \"major.minor\" version number. "
  784. "These numbers are used as the image version of the binary. ");
  785. cm->DefineProperty
  786. ("WIN32_EXECUTABLE", cmProperty::TARGET,
  787. "Build an executable with a WinMain entry point on windows.",
  788. "When this property is set to true the executable when linked "
  789. "on Windows will be created with a WinMain() entry point instead "
  790. "of of just main()."
  791. "This makes it a GUI executable instead of a console application. "
  792. "See the CMAKE_MFC_FLAG variable documentation to configure use "
  793. "of MFC for WinMain executables.");
  794. cm->DefineProperty
  795. ("MACOSX_BUNDLE", cmProperty::TARGET,
  796. "Build an executable as an application bundle on Mac OS X.",
  797. "When this property is set to true the executable when built "
  798. "on Mac OS X will be created as an application bundle. "
  799. "This makes it a GUI executable that can be launched from "
  800. "the Finder. "
  801. "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
  802. "about creation of the Info.plist file for the application bundle.");
  803. cm->DefineProperty
  804. ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
  805. "Specify a custom Info.plist template for a Mac OS X App Bundle.",
  806. "An executable target with MACOSX_BUNDLE enabled will be built as an "
  807. "application bundle on Mac OS X. "
  808. "By default its Info.plist file is created by configuring a template "
  809. "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
  810. "This property specifies an alternative template file name which "
  811. "may be a full path.\n"
  812. "The following target properties may be set to specify content to "
  813. "be configured into the file:\n"
  814. " MACOSX_BUNDLE_INFO_STRING\n"
  815. " MACOSX_BUNDLE_ICON_FILE\n"
  816. " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
  817. " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
  818. " MACOSX_BUNDLE_BUNDLE_NAME\n"
  819. " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
  820. " MACOSX_BUNDLE_BUNDLE_VERSION\n"
  821. " MACOSX_BUNDLE_COPYRIGHT\n"
  822. "CMake variables of the same name may be set to affect all targets "
  823. "in a directory that do not have each specific property set. "
  824. "If a custom Info.plist is specified by this property it may of course "
  825. "hard-code all the settings instead of using the target properties.");
  826. cm->DefineProperty
  827. ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
  828. "Specify a custom Info.plist template for a Mac OS X Framework.",
  829. "An library target with FRAMEWORK enabled will be built as a "
  830. "framework on Mac OS X. "
  831. "By default its Info.plist file is created by configuring a template "
  832. "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
  833. "This property specifies an alternative template file name which "
  834. "may be a full path.\n"
  835. "The following target properties may be set to specify content to "
  836. "be configured into the file:\n"
  837. " MACOSX_FRAMEWORK_ICON_FILE\n"
  838. " MACOSX_FRAMEWORK_IDENTIFIER\n"
  839. " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
  840. " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
  841. "CMake variables of the same name may be set to affect all targets "
  842. "in a directory that do not have each specific property set. "
  843. "If a custom Info.plist is specified by this property it may of course "
  844. "hard-code all the settings instead of using the target properties.");
  845. cm->DefineProperty
  846. ("ENABLE_EXPORTS", cmProperty::TARGET,
  847. "Specify whether an executable exports symbols for loadable modules.",
  848. "Normally an executable does not export any symbols because it is "
  849. "the final program. It is possible for an executable to export "
  850. "symbols to be used by loadable modules. When this property is "
  851. "set to true CMake will allow other targets to \"link\" to the "
  852. "executable with the TARGET_LINK_LIBRARIES command. "
  853. "On all platforms a target-level dependency on the executable is "
  854. "created for targets that link to it. "
  855. "For DLL platforms an import library will be created for the "
  856. "exported symbols and then used for linking. "
  857. "All Windows-based systems including Cygwin are DLL platforms. "
  858. "For non-DLL platforms that require all symbols to be resolved at "
  859. "link time, such as Mac OS X, the module will \"link\" to the "
  860. "executable using a flag like \"-bundle_loader\". "
  861. "For other non-DLL platforms the link rule is simply ignored since "
  862. "the dynamic loader will automatically bind symbols when the "
  863. "module is loaded. "
  864. );
  865. cm->DefineProperty
  866. ("Fortran_FORMAT", cmProperty::TARGET,
  867. "Set to FIXED or FREE to indicate the Fortran source layout.",
  868. "This property tells CMake whether the Fortran source files "
  869. "in a target use fixed-format or free-format. "
  870. "CMake will pass the corresponding format flag to the compiler. "
  871. "Use the source-specific Fortran_FORMAT property to change the "
  872. "format of a specific source file. "
  873. "If the variable CMAKE_Fortran_FORMAT is set when a target "
  874. "is created its value is used to initialize this property.");
  875. cm->DefineProperty
  876. ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
  877. "Specify output directory for Fortran modules provided by the target.",
  878. "If the target contains Fortran source files that provide modules "
  879. "and the compiler supports a module output directory this specifies "
  880. "the directory in which the modules will be placed. "
  881. "When this property is not set the modules will be placed in the "
  882. "build directory corresponding to the target's source directory. "
  883. "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
  884. "is created its value is used to initialize this property.");
  885. cm->DefineProperty
  886. ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
  887. "Set Xcode target attributes directly.",
  888. "Tell the Xcode generator to set '<an-attribute>' to a given value "
  889. "in the generated Xcode project. Ignored on other generators.");
  890. cm->DefineProperty
  891. ("GENERATOR_FILE_NAME", cmProperty::TARGET,
  892. "Generator's file for this target.",
  893. "An internal property used by some generators to record the name of "
  894. "project or dsp file associated with this target.");
  895. cm->DefineProperty
  896. ("SOURCES", cmProperty::TARGET,
  897. "Source names specified for a target.",
  898. "Read-only list of sources specified for a target. "
  899. "The names returned are suitable for passing to the "
  900. "set_source_files_properties command.");
  901. cm->DefineProperty
  902. ("FOLDER", cmProperty::TARGET,
  903. "Set the folder name. Use to organize targets in an IDE.",
  904. "Targets with no FOLDER property will appear as top level "
  905. "entities in IDEs like Visual Studio. Targets with the same "
  906. "FOLDER property value will appear next to each other in a "
  907. "folder of that name. To nest folders, use FOLDER values such "
  908. "as 'GUI/Dialogs' with '/' characters separating folder levels.");
  909. cm->DefineProperty
  910. ("PROJECT_LABEL", cmProperty::TARGET,
  911. "Change the name of a target in an IDE.",
  912. "Can be used to change the name of the target in an IDE "
  913. "like Visual Studio. ");
  914. cm->DefineProperty
  915. ("VS_KEYWORD", cmProperty::TARGET,
  916. "Visual Studio project keyword.",
  917. "Can be set to change the visual studio keyword, for example "
  918. "QT integration works better if this is set to Qt4VSv1.0. ");
  919. cm->DefineProperty
  920. ("VS_SCC_PROVIDER", cmProperty::TARGET,
  921. "Visual Studio Source Code Control Provider.",
  922. "Can be set to change the visual studio source code control "
  923. "provider property.");
  924. cm->DefineProperty
  925. ("VS_SCC_LOCALPATH", cmProperty::TARGET,
  926. "Visual Studio Source Code Control Local Path.",
  927. "Can be set to change the visual studio source code control "
  928. "local path property.");
  929. cm->DefineProperty
  930. ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
  931. "Visual Studio Source Code Control Project.",
  932. "Can be set to change the visual studio source code control "
  933. "project name property.");
  934. cm->DefineProperty
  935. ("VS_SCC_AUXPATH", cmProperty::TARGET,
  936. "Visual Studio Source Code Control Aux Path.",
  937. "Can be set to change the visual studio source code control "
  938. "auxpath property.");
  939. cm->DefineProperty
  940. ("VS_GLOBAL_<variable>", cmProperty::TARGET,
  941. "Visual Studio project-specific global variable.",
  942. "Tell the Visual Studio generator to set the global variable "
  943. "'<variable>' to a given value in the generated Visual Studio "
  944. "project. Ignored on other generators. Qt integration works "
  945. "better if VS_GLOBAL_QtVersion is set to the version "
  946. "FindQt4.cmake found. For example, \"4.7.3\"");
  947. #if 0
  948. cm->DefineProperty
  949. ("OBJECT_FILES", cmProperty::TARGET,
  950. "Used to get the resulting list of object files that make up a "
  951. "target.",
  952. "This can be used to put object files from one library "
  953. "into another library. It is a read only property. It "
  954. "converts the source list for the target into a list of full "
  955. "paths to object names that will be produced by the target.");
  956. #endif
  957. #define CM_TARGET_FILE_TYPES_DOC \
  958. "There are three kinds of target files that may be built: " \
  959. "archive, library, and runtime. " \
  960. "Executables are always treated as runtime targets. " \
  961. "Static libraries are always treated as archive targets. " \
  962. "Module libraries are always treated as library targets. " \
  963. "For non-DLL platforms shared libraries are treated as library " \
  964. "targets. " \
  965. "For DLL platforms the DLL part of a shared library is treated as " \
  966. "a runtime target and the corresponding import library is treated as " \
  967. "an archive target. " \
  968. "All Windows-based systems including Cygwin are DLL platforms."
  969. #define CM_TARGET_OUTDIR_DOC(TYPE, type) \
  970. "This property specifies the directory into which " #type " target " \
  971. "files should be built. " \
  972. "Multi-configuration generators (VS, Xcode) append " \
  973. "a per-configuration subdirectory to the specified directory. " \
  974. CM_TARGET_FILE_TYPES_DOC " " \
  975. "This property is initialized by the value of the variable " \
  976. "CMAKE_" #TYPE "_OUTPUT_DIRECTORY if it is set when a target is created."
  977. #define CM_TARGET_OUTDIR_CONFIG_DOC(TYPE) \
  978. "This is a per-configuration version of " #TYPE "_OUTPUT_DIRECTORY, " \
  979. "but multi-configuration generators (VS, Xcode) do NOT append " \
  980. "a per-configuration subdirectory to the specified directory. " \
  981. "This property is initialized by the value of the variable " \
  982. "CMAKE_" #TYPE "_OUTPUT_DIRECTORY_<CONFIG> " \
  983. "if it is set when a target is created."
  984. cm->DefineProperty
  985. ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
  986. "Output directory in which to build ARCHIVE target files.",
  987. CM_TARGET_OUTDIR_DOC(ARCHIVE, archive));
  988. cm->DefineProperty
  989. ("ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  990. "Per-configuration output directory for ARCHIVE target files.",
  991. CM_TARGET_OUTDIR_CONFIG_DOC(ARCHIVE));
  992. cm->DefineProperty
  993. ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
  994. "Output directory in which to build LIBRARY target files.",
  995. CM_TARGET_OUTDIR_DOC(LIBRARY, library));
  996. cm->DefineProperty
  997. ("LIBRARY_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  998. "Per-configuration output directory for LIBRARY target files.",
  999. CM_TARGET_OUTDIR_CONFIG_DOC(LIBRARY));
  1000. cm->DefineProperty
  1001. ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1002. "Output directory in which to build RUNTIME target files.",
  1003. CM_TARGET_OUTDIR_DOC(RUNTIME, runtime));
  1004. cm->DefineProperty
  1005. ("RUNTIME_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1006. "Per-configuration output directory for RUNTIME target files.",
  1007. CM_TARGET_OUTDIR_CONFIG_DOC(RUNTIME));
  1008. cm->DefineProperty
  1009. ("ARCHIVE_OUTPUT_NAME", cmProperty::TARGET,
  1010. "Output name for ARCHIVE target files.",
  1011. "This property specifies the base name for archive target files. "
  1012. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1013. CM_TARGET_FILE_TYPES_DOC);
  1014. cm->DefineProperty
  1015. ("ARCHIVE_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1016. "Per-configuration output name for ARCHIVE target files.",
  1017. "This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.");
  1018. cm->DefineProperty
  1019. ("LIBRARY_OUTPUT_NAME", cmProperty::TARGET,
  1020. "Output name for LIBRARY target files.",
  1021. "This property specifies the base name for library target files. "
  1022. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1023. CM_TARGET_FILE_TYPES_DOC);
  1024. cm->DefineProperty
  1025. ("LIBRARY_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1026. "Per-configuration output name for LIBRARY target files.",
  1027. "This is the configuration-specific version of LIBRARY_OUTPUT_NAME.");
  1028. cm->DefineProperty
  1029. ("RUNTIME_OUTPUT_NAME", cmProperty::TARGET,
  1030. "Output name for RUNTIME target files.",
  1031. "This property specifies the base name for runtime target files. "
  1032. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1033. CM_TARGET_FILE_TYPES_DOC);
  1034. cm->DefineProperty
  1035. ("RUNTIME_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1036. "Per-configuration output name for RUNTIME target files.",
  1037. "This is the configuration-specific version of RUNTIME_OUTPUT_NAME.");
  1038. }
  1039. void cmTarget::SetType(TargetType type, const char* name)
  1040. {
  1041. this->Name = name;
  1042. if(type == cmTarget::INSTALL_FILES ||
  1043. type == cmTarget::INSTALL_PROGRAMS ||
  1044. type == cmTarget::INSTALL_DIRECTORY)
  1045. {
  1046. this->Makefile->
  1047. IssueMessage(cmake::INTERNAL_ERROR,
  1048. "SetType called on cmTarget for INSTALL_FILES, "
  1049. "INSTALL_PROGRAMS, or INSTALL_DIRECTORY ");
  1050. return;
  1051. }
  1052. // only add dependency information for library targets
  1053. this->TargetTypeValue = type;
  1054. if(this->TargetTypeValue >= STATIC_LIBRARY
  1055. && this->TargetTypeValue <= MODULE_LIBRARY)
  1056. {
  1057. this->RecordDependencies = true;
  1058. }
  1059. else
  1060. {
  1061. this->RecordDependencies = false;
  1062. }
  1063. }
  1064. //----------------------------------------------------------------------------
  1065. void cmTarget::SetMakefile(cmMakefile* mf)
  1066. {
  1067. // Set our makefile.
  1068. this->Makefile = mf;
  1069. // set the cmake instance of the properties
  1070. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  1071. // Check whether this is a DLL platform.
  1072. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  1073. this->Makefile->IsOn("CYGWIN") ||
  1074. this->Makefile->IsOn("MINGW"));
  1075. // Setup default property values.
  1076. this->SetPropertyDefault("INSTALL_NAME_DIR", "");
  1077. this->SetPropertyDefault("INSTALL_RPATH", "");
  1078. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  1079. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  1080. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  1081. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  1082. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  1083. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  1084. this->SetPropertyDefault("Fortran_FORMAT", 0);
  1085. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  1086. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  1087. this->SetPropertyDefault("AUTOMOC", 0);
  1088. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  1089. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  1090. // Collect the set of configuration types.
  1091. std::vector<std::string> configNames;
  1092. mf->GetConfigurations(configNames);
  1093. // Setup per-configuration property default values.
  1094. const char* configProps[] = {
  1095. "ARCHIVE_OUTPUT_DIRECTORY_",
  1096. "LIBRARY_OUTPUT_DIRECTORY_",
  1097. "RUNTIME_OUTPUT_DIRECTORY_",
  1098. 0};
  1099. for(std::vector<std::string>::iterator ci = configNames.begin();
  1100. ci != configNames.end(); ++ci)
  1101. {
  1102. std::string configUpper = cmSystemTools::UpperCase(*ci);
  1103. for(const char** p = configProps; *p; ++p)
  1104. {
  1105. std::string property = *p;
  1106. property += configUpper;
  1107. this->SetPropertyDefault(property.c_str(), 0);
  1108. }
  1109. // Initialize per-configuration name postfix property from the
  1110. // variable only for non-executable targets. This preserves
  1111. // compatibility with previous CMake versions in which executables
  1112. // did not support this variable. Projects may still specify the
  1113. // property directly. TODO: Make this depend on backwards
  1114. // compatibility setting.
  1115. if(this->TargetTypeValue != cmTarget::EXECUTABLE)
  1116. {
  1117. std::string property = cmSystemTools::UpperCase(*ci);
  1118. property += "_POSTFIX";
  1119. this->SetPropertyDefault(property.c_str(), 0);
  1120. }
  1121. }
  1122. // Save the backtrace of target construction.
  1123. this->Makefile->GetBacktrace(this->Internal->Backtrace);
  1124. // Record current policies for later use.
  1125. this->PolicyStatusCMP0003 =
  1126. this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
  1127. this->PolicyStatusCMP0004 =
  1128. this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
  1129. this->PolicyStatusCMP0008 =
  1130. this->Makefile->GetPolicyStatus(cmPolicies::CMP0008);
  1131. }
  1132. //----------------------------------------------------------------------------
  1133. void cmTarget::FinishConfigure()
  1134. {
  1135. // Erase any cached link information that might have been comptued
  1136. // on-demand during the configuration. This ensures that build
  1137. // system generation uses up-to-date information even if other cache
  1138. // invalidation code in this source file is buggy.
  1139. this->ClearLinkMaps();
  1140. // Do old-style link dependency analysis.
  1141. this->AnalyzeLibDependencies(*this->Makefile);
  1142. }
  1143. //----------------------------------------------------------------------------
  1144. void cmTarget::ClearLinkMaps()
  1145. {
  1146. this->Internal->LinkImplMap.clear();
  1147. this->Internal->LinkInterfaceMap.clear();
  1148. this->Internal->LinkClosureMap.clear();
  1149. }
  1150. //----------------------------------------------------------------------------
  1151. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  1152. {
  1153. return this->Internal->Backtrace;
  1154. }
  1155. //----------------------------------------------------------------------------
  1156. std::string cmTarget::GetSupportDirectory() const
  1157. {
  1158. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  1159. dir += cmake::GetCMakeFilesDirectory();
  1160. dir += "/";
  1161. dir += this->Name;
  1162. #if defined(__VMS)
  1163. dir += "_dir";
  1164. #else
  1165. dir += ".dir";
  1166. #endif
  1167. return dir;
  1168. }
  1169. //----------------------------------------------------------------------------
  1170. bool cmTarget::IsExecutableWithExports()
  1171. {
  1172. return (this->GetType() == cmTarget::EXECUTABLE &&
  1173. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  1174. }
  1175. //----------------------------------------------------------------------------
  1176. bool cmTarget::IsLinkable()
  1177. {
  1178. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  1179. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1180. this->GetType() == cmTarget::MODULE_LIBRARY ||
  1181. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  1182. this->IsExecutableWithExports());
  1183. }
  1184. //----------------------------------------------------------------------------
  1185. bool cmTarget::HasImportLibrary()
  1186. {
  1187. return (this->DLLPlatform &&
  1188. (this->GetType() == cmTarget::SHARED_LIBRARY ||
  1189. this->IsExecutableWithExports()));
  1190. }
  1191. //----------------------------------------------------------------------------
  1192. bool cmTarget::IsFrameworkOnApple()
  1193. {
  1194. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  1195. this->Makefile->IsOn("APPLE") &&
  1196. this->GetPropertyAsBool("FRAMEWORK"));
  1197. }
  1198. //----------------------------------------------------------------------------
  1199. bool cmTarget::IsAppBundleOnApple()
  1200. {
  1201. return (this->GetType() == cmTarget::EXECUTABLE &&
  1202. this->Makefile->IsOn("APPLE") &&
  1203. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  1204. }
  1205. //----------------------------------------------------------------------------
  1206. bool cmTarget::IsCFBundleOnApple()
  1207. {
  1208. return (this->GetType() == cmTarget::MODULE_LIBRARY &&
  1209. this->Makefile->IsOn("APPLE") &&
  1210. this->GetPropertyAsBool("BUNDLE"));
  1211. }
  1212. //----------------------------------------------------------------------------
  1213. class cmTargetTraceDependencies
  1214. {
  1215. public:
  1216. cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
  1217. const char* vsProjectFile);
  1218. void Trace();
  1219. private:
  1220. cmTarget* Target;
  1221. cmTargetInternals* Internal;
  1222. cmMakefile* Makefile;
  1223. cmGlobalGenerator* GlobalGenerator;
  1224. typedef cmTargetInternals::SourceEntry SourceEntry;
  1225. SourceEntry* CurrentEntry;
  1226. std::queue<cmSourceFile*> SourceQueue;
  1227. std::set<cmSourceFile*> SourcesQueued;
  1228. typedef std::map<cmStdString, cmSourceFile*> NameMapType;
  1229. NameMapType NameMap;
  1230. void QueueSource(cmSourceFile* sf);
  1231. void FollowName(std::string const& name);
  1232. void FollowNames(std::vector<std::string> const& names);
  1233. bool IsUtility(std::string const& dep);
  1234. void CheckCustomCommand(cmCustomCommand const& cc);
  1235. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1236. };
  1237. //----------------------------------------------------------------------------
  1238. cmTargetTraceDependencies
  1239. ::cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
  1240. const char* vsProjectFile):
  1241. Target(target), Internal(internal)
  1242. {
  1243. // Convenience.
  1244. this->Makefile = this->Target->GetMakefile();
  1245. this->GlobalGenerator =
  1246. this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  1247. this->CurrentEntry = 0;
  1248. // Queue all the source files already specified for the target.
  1249. std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
  1250. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1251. si != sources.end(); ++si)
  1252. {
  1253. this->QueueSource(*si);
  1254. }
  1255. // Queue the VS project file to check dependencies on the rule to
  1256. // generate it.
  1257. if(vsProjectFile)
  1258. {
  1259. this->FollowName(vsProjectFile);
  1260. }
  1261. // Queue pre-build, pre-link, and post-build rule dependencies.
  1262. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  1263. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  1264. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  1265. }
  1266. //----------------------------------------------------------------------------
  1267. void cmTargetTraceDependencies::Trace()
  1268. {
  1269. // Process one dependency at a time until the queue is empty.
  1270. while(!this->SourceQueue.empty())
  1271. {
  1272. // Get the next source from the queue.
  1273. cmSourceFile* sf = this->SourceQueue.front();
  1274. this->SourceQueue.pop();
  1275. this->CurrentEntry = &this->Internal->SourceEntries[sf];
  1276. // Queue dependencies added explicitly by the user.
  1277. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  1278. {
  1279. std::vector<std::string> objDeps;
  1280. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1281. this->FollowNames(objDeps);
  1282. }
  1283. // Queue the source needed to generate this file, if any.
  1284. this->FollowName(sf->GetFullPath());
  1285. // Queue dependencies added programatically by commands.
  1286. this->FollowNames(sf->GetDepends());
  1287. // Queue custom command dependencies.
  1288. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  1289. {
  1290. this->CheckCustomCommand(*cc);
  1291. }
  1292. }
  1293. this->CurrentEntry = 0;
  1294. }
  1295. //----------------------------------------------------------------------------
  1296. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1297. {
  1298. if(this->SourcesQueued.insert(sf).second)
  1299. {
  1300. this->SourceQueue.push(sf);
  1301. // Make sure this file is in the target.
  1302. this->Target->AddSourceFile(sf);
  1303. }
  1304. }
  1305. //----------------------------------------------------------------------------
  1306. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1307. {
  1308. NameMapType::iterator i = this->NameMap.find(name);
  1309. if(i == this->NameMap.end())
  1310. {
  1311. // Check if we know how to generate this file.
  1312. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
  1313. NameMapType::value_type entry(name, sf);
  1314. i = this->NameMap.insert(entry).first;
  1315. }
  1316. if(cmSourceFile* sf = i->second)
  1317. {
  1318. // Record the dependency we just followed.
  1319. if(this->CurrentEntry)
  1320. {
  1321. this->CurrentEntry->Depends.push_back(sf);
  1322. }
  1323. this->QueueSource(sf);
  1324. }
  1325. }
  1326. //----------------------------------------------------------------------------
  1327. void
  1328. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  1329. {
  1330. for(std::vector<std::string>::const_iterator i = names.begin();
  1331. i != names.end(); ++i)
  1332. {
  1333. this->FollowName(*i);
  1334. }
  1335. }
  1336. //----------------------------------------------------------------------------
  1337. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1338. {
  1339. // Dependencies on targets (utilities) are supposed to be named by
  1340. // just the target name. However for compatibility we support
  1341. // naming the output file generated by the target (assuming there is
  1342. // no output-name property which old code would not have set). In
  1343. // that case the target name will be the file basename of the
  1344. // dependency.
  1345. std::string util = cmSystemTools::GetFilenameName(dep);
  1346. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  1347. {
  1348. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  1349. }
  1350. // Check for a target with this name.
  1351. if(cmTarget* t = this->Makefile->FindTargetToUse(util.c_str()))
  1352. {
  1353. // If we find the target and the dep was given as a full path,
  1354. // then make sure it was not a full path to something else, and
  1355. // the fact that the name matched a target was just a coincidence.
  1356. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  1357. {
  1358. if(t->GetType() >= cmTarget::EXECUTABLE &&
  1359. t->GetType() <= cmTarget::MODULE_LIBRARY)
  1360. {
  1361. // This is really only for compatibility so we do not need to
  1362. // worry about configuration names and output names.
  1363. std::string tLocation = t->GetLocation(0);
  1364. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1365. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  1366. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  1367. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  1368. if(depLocation == tLocation)
  1369. {
  1370. this->Target->AddUtility(util.c_str());
  1371. return true;
  1372. }
  1373. }
  1374. }
  1375. else
  1376. {
  1377. // The original name of the dependency was not a full path. It
  1378. // must name a target, so add the target-level dependency.
  1379. this->Target->AddUtility(util.c_str());
  1380. return true;
  1381. }
  1382. }
  1383. // The dependency does not name a target built in this project.
  1384. return false;
  1385. }
  1386. //----------------------------------------------------------------------------
  1387. void
  1388. cmTargetTraceDependencies
  1389. ::CheckCustomCommand(cmCustomCommand const& cc)
  1390. {
  1391. // Transform command names that reference targets built in this
  1392. // project to corresponding target-level dependencies.
  1393. cmGeneratorExpression ge(this->Makefile, 0, cc.GetBacktrace(), true);
  1394. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1395. cit != cc.GetCommandLines().end(); ++cit)
  1396. {
  1397. std::string const& command = *cit->begin();
  1398. // Check for a target with this name.
  1399. if(cmTarget* t = this->Makefile->FindTargetToUse(command.c_str()))
  1400. {
  1401. if(t->GetType() == cmTarget::EXECUTABLE)
  1402. {
  1403. // The command refers to an executable target built in
  1404. // this project. Add the target-level dependency to make
  1405. // sure the executable is up to date before this custom
  1406. // command possibly runs.
  1407. this->Target->AddUtility(command.c_str());
  1408. }
  1409. }
  1410. // Check for target references in generator expressions.
  1411. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  1412. cli != cit->end(); ++cli)
  1413. {
  1414. ge.Process(*cli);
  1415. }
  1416. }
  1417. // Add target-level dependencies referenced by generator expressions.
  1418. std::set<cmTarget*> targets = ge.GetTargets();
  1419. for(std::set<cmTarget*>::iterator ti = targets.begin();
  1420. ti != targets.end(); ++ti)
  1421. {
  1422. this->Target->AddUtility((*ti)->GetName());
  1423. }
  1424. // Queue the custom command dependencies.
  1425. std::vector<std::string> const& depends = cc.GetDepends();
  1426. for(std::vector<std::string>::const_iterator di = depends.begin();
  1427. di != depends.end(); ++di)
  1428. {
  1429. std::string const& dep = *di;
  1430. if(!this->IsUtility(dep))
  1431. {
  1432. // The dependency does not name a target and may be a file we
  1433. // know how to generate. Queue it.
  1434. this->FollowName(dep);
  1435. }
  1436. }
  1437. }
  1438. //----------------------------------------------------------------------------
  1439. void
  1440. cmTargetTraceDependencies
  1441. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1442. {
  1443. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1444. cli != commands.end(); ++cli)
  1445. {
  1446. this->CheckCustomCommand(*cli);
  1447. }
  1448. }
  1449. //----------------------------------------------------------------------------
  1450. void cmTarget::TraceDependencies(const char* vsProjectFile)
  1451. {
  1452. // CMake-generated targets have no dependencies to trace. Normally tracing
  1453. // would find nothing anyway, but when building CMake itself the "install"
  1454. // target command ends up referencing the "cmake" target but we do not
  1455. // really want the dependency because "install" depend on "all" anyway.
  1456. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1457. {
  1458. return;
  1459. }
  1460. // Use a helper object to trace the dependencies.
  1461. cmTargetTraceDependencies tracer(this, this->Internal.Get(), vsProjectFile);
  1462. tracer.Trace();
  1463. }
  1464. //----------------------------------------------------------------------------
  1465. bool cmTarget::FindSourceFiles()
  1466. {
  1467. for(std::vector<cmSourceFile*>::const_iterator
  1468. si = this->SourceFiles.begin();
  1469. si != this->SourceFiles.end(); ++si)
  1470. {
  1471. std::string e;
  1472. if((*si)->GetFullPath(&e).empty())
  1473. {
  1474. if(!e.empty())
  1475. {
  1476. cmake* cm = this->Makefile->GetCMakeInstance();
  1477. cm->IssueMessage(cmake::FATAL_ERROR, e,
  1478. this->GetBacktrace());
  1479. }
  1480. return false;
  1481. }
  1482. }
  1483. return true;
  1484. }
  1485. //----------------------------------------------------------------------------
  1486. std::vector<cmSourceFile*> const& cmTarget::GetSourceFiles()
  1487. {
  1488. return this->SourceFiles;
  1489. }
  1490. //----------------------------------------------------------------------------
  1491. void cmTarget::AddSourceFile(cmSourceFile* sf)
  1492. {
  1493. typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
  1494. SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
  1495. if(i == this->Internal->SourceEntries.end())
  1496. {
  1497. typedef cmTargetInternals::SourceEntry SourceEntry;
  1498. SourceEntriesType::value_type entry(sf, SourceEntry());
  1499. i = this->Internal->SourceEntries.insert(entry).first;
  1500. this->SourceFiles.push_back(sf);
  1501. }
  1502. }
  1503. //----------------------------------------------------------------------------
  1504. std::vector<cmSourceFile*> const*
  1505. cmTarget::GetSourceDepends(cmSourceFile* sf)
  1506. {
  1507. typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
  1508. SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
  1509. if(i != this->Internal->SourceEntries.end())
  1510. {
  1511. return &i->second.Depends;
  1512. }
  1513. return 0;
  1514. }
  1515. //----------------------------------------------------------------------------
  1516. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  1517. {
  1518. for(std::vector<std::string>::const_iterator i = srcs.begin();
  1519. i != srcs.end(); ++i)
  1520. {
  1521. this->AddSource(i->c_str());
  1522. }
  1523. }
  1524. //----------------------------------------------------------------------------
  1525. cmSourceFile* cmTarget::AddSource(const char* s)
  1526. {
  1527. std::string src = s;
  1528. // For backwards compatibility replace varibles in source names.
  1529. // This should eventually be removed.
  1530. this->Makefile->ExpandVariablesInString(src);
  1531. cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
  1532. this->AddSourceFile(sf);
  1533. return sf;
  1534. }
  1535. //----------------------------------------------------------------------------
  1536. struct cmTarget::SourceFileFlags
  1537. cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
  1538. {
  1539. struct SourceFileFlags flags;
  1540. this->ConstructSourceFileFlags();
  1541. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  1542. this->Internal->SourceFlagsMap.find(sf);
  1543. if(si != this->Internal->SourceFlagsMap.end())
  1544. {
  1545. flags = si->second;
  1546. }
  1547. return flags;
  1548. }
  1549. //----------------------------------------------------------------------------
  1550. void cmTarget::ConstructSourceFileFlags()
  1551. {
  1552. if(this->Internal->SourceFileFlagsConstructed)
  1553. {
  1554. return;
  1555. }
  1556. this->Internal->SourceFileFlagsConstructed = true;
  1557. // Process public headers to mark the source files.
  1558. if(const char* files = this->GetProperty("PUBLIC_HEADER"))
  1559. {
  1560. std::vector<std::string> relFiles;
  1561. cmSystemTools::ExpandListArgument(files, relFiles);
  1562. for(std::vector<std::string>::iterator it = relFiles.begin();
  1563. it != relFiles.end(); ++it)
  1564. {
  1565. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1566. {
  1567. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1568. flags.MacFolder = "Headers";
  1569. flags.Type = cmTarget::SourceFileTypePublicHeader;
  1570. }
  1571. }
  1572. }
  1573. // Process private headers after public headers so that they take
  1574. // precedence if a file is listed in both.
  1575. if(const char* files = this->GetProperty("PRIVATE_HEADER"))
  1576. {
  1577. std::vector<std::string> relFiles;
  1578. cmSystemTools::ExpandListArgument(files, relFiles);
  1579. for(std::vector<std::string>::iterator it = relFiles.begin();
  1580. it != relFiles.end(); ++it)
  1581. {
  1582. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1583. {
  1584. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1585. flags.MacFolder = "PrivateHeaders";
  1586. flags.Type = cmTarget::SourceFileTypePrivateHeader;
  1587. }
  1588. }
  1589. }
  1590. // Mark sources listed as resources.
  1591. if(const char* files = this->GetProperty("RESOURCE"))
  1592. {
  1593. std::vector<std::string> relFiles;
  1594. cmSystemTools::ExpandListArgument(files, relFiles);
  1595. for(std::vector<std::string>::iterator it = relFiles.begin();
  1596. it != relFiles.end(); ++it)
  1597. {
  1598. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1599. {
  1600. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1601. flags.MacFolder = "Resources";
  1602. flags.Type = cmTarget::SourceFileTypeResource;
  1603. }
  1604. }
  1605. }
  1606. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  1607. // were not listed in one of the other lists.
  1608. std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
  1609. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1610. si != sources.end(); ++si)
  1611. {
  1612. cmSourceFile* sf = *si;
  1613. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  1614. {
  1615. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1616. if(flags.Type == cmTarget::SourceFileTypeNormal)
  1617. {
  1618. flags.MacFolder = location;
  1619. if(strcmp(location, "Resources") == 0)
  1620. {
  1621. flags.Type = cmTarget::SourceFileTypeResource;
  1622. }
  1623. else
  1624. {
  1625. flags.Type = cmTarget::SourceFileTypeMacContent;
  1626. }
  1627. }
  1628. }
  1629. }
  1630. }
  1631. //----------------------------------------------------------------------------
  1632. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  1633. const char *selfname,
  1634. const LinkLibraryVectorType& libs )
  1635. {
  1636. // Only add on libraries we haven't added on before.
  1637. // Assumption: the global link libraries could only grow, never shrink
  1638. LinkLibraryVectorType::const_iterator i = libs.begin();
  1639. i += this->PrevLinkedLibraries.size();
  1640. for( ; i != libs.end(); ++i )
  1641. {
  1642. // We call this so that the dependencies get written to the cache
  1643. this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
  1644. }
  1645. this->PrevLinkedLibraries = libs;
  1646. }
  1647. //----------------------------------------------------------------------------
  1648. void cmTarget::AddLinkDirectory(const char* d)
  1649. {
  1650. // Make sure we don't add unnecessary search directories.
  1651. if(this->LinkDirectoriesEmmitted.insert(d).second)
  1652. {
  1653. this->LinkDirectories.push_back(d);
  1654. }
  1655. }
  1656. //----------------------------------------------------------------------------
  1657. const std::vector<std::string>& cmTarget::GetLinkDirectories()
  1658. {
  1659. return this->LinkDirectories;
  1660. }
  1661. //----------------------------------------------------------------------------
  1662. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
  1663. {
  1664. // No configuration is always optimized.
  1665. if(!(config && *config))
  1666. {
  1667. return cmTarget::OPTIMIZED;
  1668. }
  1669. // Get the list of configurations considered to be DEBUG.
  1670. std::vector<std::string> const& debugConfigs =
  1671. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1672. // Check if any entry in the list matches this configuration.
  1673. std::string configUpper = cmSystemTools::UpperCase(config);
  1674. for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
  1675. i != debugConfigs.end(); ++i)
  1676. {
  1677. if(*i == configUpper)
  1678. {
  1679. return cmTarget::DEBUG;
  1680. }
  1681. }
  1682. // The current configuration is not a debug configuration.
  1683. return cmTarget::OPTIMIZED;
  1684. }
  1685. //----------------------------------------------------------------------------
  1686. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  1687. const char* target )
  1688. {
  1689. // Clear the dependencies. The cache variable must exist iff we are
  1690. // recording dependency information for this target.
  1691. std::string depname = target;
  1692. depname += "_LIB_DEPENDS";
  1693. if (this->RecordDependencies)
  1694. {
  1695. mf.AddCacheDefinition(depname.c_str(), "",
  1696. "Dependencies for target", cmCacheManager::STATIC);
  1697. }
  1698. else
  1699. {
  1700. if (mf.GetDefinition( depname.c_str() ))
  1701. {
  1702. std::string message = "Target ";
  1703. message += target;
  1704. message += " has dependency information when it shouldn't.\n";
  1705. message += "Your cache is probably stale. Please remove the entry\n ";
  1706. message += depname;
  1707. message += "\nfrom the cache.";
  1708. cmSystemTools::Error( message.c_str() );
  1709. }
  1710. }
  1711. }
  1712. //----------------------------------------------------------------------------
  1713. bool cmTarget::NameResolvesToFramework(const std::string& libname)
  1714. {
  1715. return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
  1716. NameResolvesToFramework(libname);
  1717. }
  1718. //----------------------------------------------------------------------------
  1719. bool cmTarget::AddFramework(const std::string& libname, LinkLibraryType llt)
  1720. {
  1721. (void)llt; // TODO: What is this?
  1722. if(this->NameResolvesToFramework(libname.c_str()))
  1723. {
  1724. std::string frameworkDir = libname;
  1725. frameworkDir += "/../";
  1726. frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
  1727. std::vector<std::string>::iterator i =
  1728. std::find(this->Frameworks.begin(),
  1729. this->Frameworks.end(), frameworkDir);
  1730. if(i == this->Frameworks.end())
  1731. {
  1732. this->Frameworks.push_back(frameworkDir);
  1733. }
  1734. return true;
  1735. }
  1736. return false;
  1737. }
  1738. //----------------------------------------------------------------------------
  1739. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  1740. const char *target, const char* lib,
  1741. LinkLibraryType llt)
  1742. {
  1743. // Never add a self dependency, even if the user asks for it.
  1744. if(strcmp( target, lib ) == 0)
  1745. {
  1746. return;
  1747. }
  1748. this->AddFramework(lib, llt);
  1749. cmTarget::LibraryID tmp;
  1750. tmp.first = lib;
  1751. tmp.second = llt;
  1752. this->LinkLibraries.push_back( tmp );
  1753. this->OriginalLinkLibraries.push_back(tmp);
  1754. this->ClearLinkMaps();
  1755. // Add the explicit dependency information for this target. This is
  1756. // simply a set of libraries separated by ";". There should always
  1757. // be a trailing ";". These library names are not canonical, in that
  1758. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  1759. // We shouldn't remove duplicates here because external libraries
  1760. // may be purposefully duplicated to handle recursive dependencies,
  1761. // and we removing one instance will break the link line. Duplicates
  1762. // will be appropriately eliminated at emit time.
  1763. if(this->RecordDependencies)
  1764. {
  1765. std::string targetEntry = target;
  1766. targetEntry += "_LIB_DEPENDS";
  1767. std::string dependencies;
  1768. const char* old_val = mf.GetDefinition( targetEntry.c_str() );
  1769. if( old_val )
  1770. {
  1771. dependencies += old_val;
  1772. }
  1773. switch (llt)
  1774. {
  1775. case cmTarget::GENERAL:
  1776. dependencies += "general";
  1777. break;
  1778. case cmTarget::DEBUG:
  1779. dependencies += "debug";
  1780. break;
  1781. case cmTarget::OPTIMIZED:
  1782. dependencies += "optimized";
  1783. break;
  1784. }
  1785. dependencies += ";";
  1786. dependencies += lib;
  1787. dependencies += ";";
  1788. mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
  1789. "Dependencies for the target",
  1790. cmCacheManager::STATIC );
  1791. }
  1792. }
  1793. //----------------------------------------------------------------------------
  1794. void
  1795. cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
  1796. {
  1797. // There are two key parts of the dependency analysis: (1)
  1798. // determining the libraries in the link line, and (2) constructing
  1799. // the dependency graph for those libraries.
  1800. //
  1801. // The latter is done using the cache entries that record the
  1802. // dependencies of each library.
  1803. //
  1804. // The former is a more thorny issue, since it is not clear how to
  1805. // determine if two libraries listed on the link line refer to the a
  1806. // single library or not. For example, consider the link "libraries"
  1807. // /usr/lib/libtiff.so -ltiff
  1808. // Is this one library or two? The solution implemented here is the
  1809. // simplest (and probably the only practical) one: two libraries are
  1810. // the same if their "link strings" are identical. Thus, the two
  1811. // libraries above are considered distinct. This also means that for
  1812. // dependency analysis to be effective, the CMake user must specify
  1813. // libraries build by his project without using any linker flags or
  1814. // file extensions. That is,
  1815. // LINK_LIBRARIES( One Two )
  1816. // instead of
  1817. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  1818. // The former is probably what most users would do, but it never
  1819. // hurts to document the assumptions. :-) Therefore, in the analysis
  1820. // code, the "canonical name" of a library is simply its name as
  1821. // given to a LINK_LIBRARIES command.
  1822. //
  1823. // Also, we will leave the original link line intact; we will just add any
  1824. // dependencies that were missing.
  1825. //
  1826. // There is a problem with recursive external libraries
  1827. // (i.e. libraries with no dependency information that are
  1828. // recursively dependent). We must make sure that the we emit one of
  1829. // the libraries twice to satisfy the recursion, but we shouldn't
  1830. // emit it more times than necessary. In particular, we must make
  1831. // sure that handling this improbable case doesn't cost us when
  1832. // dealing with the common case of non-recursive libraries. The
  1833. // solution is to assume that the recursion is satisfied at one node
  1834. // of the dependency tree. To illustrate, assume libA and libB are
  1835. // extrenal and mutually dependent. Suppose libX depends on
  1836. // libA, and libY on libA and libX. Then
  1837. // TARGET_LINK_LIBRARIES( Y X A B A )
  1838. // TARGET_LINK_LIBRARIES( X A B A )
  1839. // TARGET_LINK_LIBRARIES( Exec Y )
  1840. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  1841. // specify the dependencies, since the mutual dependency of A and B
  1842. // is resolved *every time libA is specified*.
  1843. //
  1844. // Something like
  1845. // TARGET_LINK_LIBRARIES( Y X A B A )
  1846. // TARGET_LINK_LIBRARIES( X A B )
  1847. // TARGET_LINK_LIBRARIES( Exec Y )
  1848. // would result in "-lY -lX -lA -lB", and the mutual dependency
  1849. // information is lost. This is because in some case (Y), the mutual
  1850. // dependency of A and B is listed, while in another other case (X),
  1851. // it is not. Depending on which line actually emits A, the mutual
  1852. // dependency may or may not be on the final link line. We can't
  1853. // handle this pathalogical case cleanly without emitting extra
  1854. // libraries for the normal cases. Besides, the dependency
  1855. // information for X is wrong anyway: if we build an executable
  1856. // depending on X alone, we would not have the mutual dependency on
  1857. // A and B resolved.
  1858. //
  1859. // IMPROVEMENTS:
  1860. // -- The current algorithm will not always pick the "optimal" link line
  1861. // when recursive dependencies are present. It will instead break the
  1862. // cycles at an aribtrary point. The majority of projects won't have
  1863. // cyclic dependencies, so this is probably not a big deal. Note that
  1864. // the link line is always correct, just not necessary optimal.
  1865. {
  1866. // Expand variables in link library names. This is for backwards
  1867. // compatibility with very early CMake versions and should
  1868. // eventually be removed. This code was moved here from the end of
  1869. // old source list processing code which was called just before this
  1870. // method.
  1871. for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
  1872. p != this->LinkLibraries.end(); ++p)
  1873. {
  1874. this->Makefile->ExpandVariablesInString(p->first, true, true);
  1875. }
  1876. }
  1877. typedef std::vector< std::string > LinkLine;
  1878. // The dependency map.
  1879. DependencyMap dep_map;
  1880. // 1. Build the dependency graph
  1881. //
  1882. for(LinkLibraryVectorType::reverse_iterator lib
  1883. = this->LinkLibraries.rbegin();
  1884. lib != this->LinkLibraries.rend(); ++lib)
  1885. {
  1886. this->GatherDependencies( mf, *lib, dep_map);
  1887. }
  1888. // 2. Remove any dependencies that are already satisfied in the original
  1889. // link line.
  1890. //
  1891. for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
  1892. lib != this->LinkLibraries.end(); ++lib)
  1893. {
  1894. for( LinkLibraryVectorType::iterator lib2 = lib;
  1895. lib2 != this->LinkLibraries.end(); ++lib2)
  1896. {
  1897. this->DeleteDependency( dep_map, *lib, *lib2);
  1898. }
  1899. }
  1900. // 3. Create the new link line by simply emitting any dependencies that are
  1901. // missing. Start from the back and keep adding.
  1902. //
  1903. std::set<DependencyMap::key_type> done, visited;
  1904. std::vector<DependencyMap::key_type> newLinkLibraries;
  1905. for(LinkLibraryVectorType::reverse_iterator lib =
  1906. this->LinkLibraries.rbegin();
  1907. lib != this->LinkLibraries.rend(); ++lib)
  1908. {
  1909. // skip zero size library entries, this may happen
  1910. // if a variable expands to nothing.
  1911. if (lib->first.size() != 0)
  1912. {
  1913. this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
  1914. }
  1915. }
  1916. // 4. Add the new libraries to the link line.
  1917. //
  1918. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  1919. newLinkLibraries.rbegin();
  1920. k != newLinkLibraries.rend(); ++k )
  1921. {
  1922. // get the llt from the dep_map
  1923. this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
  1924. }
  1925. this->LinkLibrariesAnalyzed = true;
  1926. }
  1927. //----------------------------------------------------------------------------
  1928. void cmTarget::InsertDependency( DependencyMap& depMap,
  1929. const LibraryID& lib,
  1930. const LibraryID& dep)
  1931. {
  1932. depMap[lib].push_back(dep);
  1933. }
  1934. //----------------------------------------------------------------------------
  1935. void cmTarget::DeleteDependency( DependencyMap& depMap,
  1936. const LibraryID& lib,
  1937. const LibraryID& dep)
  1938. {
  1939. // Make sure there is an entry in the map for lib. If so, delete all
  1940. // dependencies to dep. There may be repeated entries because of
  1941. // external libraries that are specified multiple times.
  1942. DependencyMap::iterator map_itr = depMap.find( lib );
  1943. if( map_itr != depMap.end() )
  1944. {
  1945. DependencyList& depList = map_itr->second;
  1946. DependencyList::iterator itr;
  1947. while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
  1948. depList.end() )
  1949. {
  1950. depList.erase( itr );
  1951. }
  1952. }
  1953. }
  1954. //----------------------------------------------------------------------------
  1955. void cmTarget::Emit(const LibraryID lib,
  1956. const DependencyMap& dep_map,
  1957. std::set<LibraryID>& emitted,
  1958. std::set<LibraryID>& visited,
  1959. DependencyList& link_line )
  1960. {
  1961. // It's already been emitted
  1962. if( emitted.find(lib) != emitted.end() )
  1963. {
  1964. return;
  1965. }
  1966. // Emit the dependencies only if this library node hasn't been
  1967. // visited before. If it has, then we have a cycle. The recursion
  1968. // that got us here should take care of everything.
  1969. if( visited.insert(lib).second )
  1970. {
  1971. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  1972. {
  1973. const DependencyList& dep_on = dep_map.find( lib )->second;
  1974. DependencyList::const_reverse_iterator i;
  1975. // To cater for recursive external libraries, we must emit
  1976. // duplicates on this link line *unless* they were emitted by
  1977. // some other node, in which case we assume that the recursion
  1978. // was resolved then. We making the simplifying assumption that
  1979. // any duplicates on a single link line are on purpose, and must
  1980. // be preserved.
  1981. // This variable will keep track of the libraries that were
  1982. // emitted directory from the current node, and not from a
  1983. // recursive call. This way, if we come across a library that
  1984. // has already been emitted, we repeat it iff it has been
  1985. // emitted here.
  1986. std::set<DependencyMap::key_type> emitted_here;
  1987. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  1988. {
  1989. if( emitted_here.find(*i) != emitted_here.end() )
  1990. {
  1991. // a repeat. Must emit.
  1992. emitted.insert(*i);
  1993. link_line.push_back( *i );
  1994. }
  1995. else
  1996. {
  1997. // Emit only if no-one else has
  1998. if( emitted.find(*i) == emitted.end() )
  1999. {
  2000. // emit dependencies
  2001. Emit( *i, dep_map, emitted, visited, link_line );
  2002. // emit self
  2003. emitted.insert(*i);
  2004. emitted_here.insert(*i);
  2005. link_line.push_back( *i );
  2006. }
  2007. }
  2008. }
  2009. }
  2010. }
  2011. }
  2012. //----------------------------------------------------------------------------
  2013. void cmTarget::GatherDependencies( const cmMakefile& mf,
  2014. const LibraryID& lib,
  2015. DependencyMap& dep_map)
  2016. {
  2017. // If the library is already in the dependency map, then it has
  2018. // already been fully processed.
  2019. if( dep_map.find(lib) != dep_map.end() )
  2020. {
  2021. return;
  2022. }
  2023. const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
  2024. if( deps && strcmp(deps,"") != 0 )
  2025. {
  2026. // Make sure this library is in the map, even if it has an empty
  2027. // set of dependencies. This distinguishes the case of explicitly
  2028. // no dependencies with that of unspecified dependencies.
  2029. dep_map[lib];
  2030. // Parse the dependency information, which is a set of
  2031. // type, library pairs separated by ";". There is always a trailing ";".
  2032. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  2033. std::string depline = deps;
  2034. std::string::size_type start = 0;
  2035. std::string::size_type end;
  2036. end = depline.find( ";", start );
  2037. while( end != std::string::npos )
  2038. {
  2039. std::string l = depline.substr( start, end-start );
  2040. if( l.size() != 0 )
  2041. {
  2042. if (l == "debug")
  2043. {
  2044. llt = cmTarget::DEBUG;
  2045. }
  2046. else if (l == "optimized")
  2047. {
  2048. llt = cmTarget::OPTIMIZED;
  2049. }
  2050. else if (l == "general")
  2051. {
  2052. llt = cmTarget::GENERAL;
  2053. }
  2054. else
  2055. {
  2056. LibraryID lib2(l,llt);
  2057. this->InsertDependency( dep_map, lib, lib2);
  2058. this->GatherDependencies( mf, lib2, dep_map);
  2059. llt = cmTarget::GENERAL;
  2060. }
  2061. }
  2062. start = end+1; // skip the ;
  2063. end = depline.find( ";", start );
  2064. }
  2065. // cannot depend on itself
  2066. this->DeleteDependency( dep_map, lib, lib);
  2067. }
  2068. }
  2069. //----------------------------------------------------------------------------
  2070. void cmTarget::SetProperty(const char* prop, const char* value)
  2071. {
  2072. if (!prop)
  2073. {
  2074. return;
  2075. }
  2076. this->Properties.SetProperty(prop, value, cmProperty::TARGET);
  2077. this->MaybeInvalidatePropertyCache(prop);
  2078. }
  2079. //----------------------------------------------------------------------------
  2080. void cmTarget::AppendProperty(const char* prop, const char* value,
  2081. bool asString)
  2082. {
  2083. if (!prop)
  2084. {
  2085. return;
  2086. }
  2087. this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
  2088. this->MaybeInvalidatePropertyCache(prop);
  2089. }
  2090. //----------------------------------------------------------------------------
  2091. void cmTarget::MaybeInvalidatePropertyCache(const char* prop)
  2092. {
  2093. // Wipe wipe out maps caching information affected by this property.
  2094. if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
  2095. {
  2096. this->Internal->ImportInfoMap.clear();
  2097. }
  2098. if(!this->IsImported() && strncmp(prop, "LINK_INTERFACE_", 15) == 0)
  2099. {
  2100. this->ClearLinkMaps();
  2101. }
  2102. }
  2103. //----------------------------------------------------------------------------
  2104. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  2105. const char* prop, const char* value, cmMakefile* context, bool imported
  2106. )
  2107. {
  2108. // Look for link-type keywords in the value.
  2109. static cmsys::RegularExpression
  2110. keys("(^|;)(debug|optimized|general)(;|$)");
  2111. if(!keys.find(value))
  2112. {
  2113. return;
  2114. }
  2115. // Support imported and non-imported versions of the property.
  2116. const char* base = (imported?
  2117. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  2118. "LINK_INTERFACE_LIBRARIES");
  2119. // Report an error.
  2120. cmOStringStream e;
  2121. e << "Property " << prop << " may not contain link-type keyword \""
  2122. << keys.match(2) << "\". "
  2123. << "The " << base << " property has a per-configuration "
  2124. << "version called " << base << "_<CONFIG> which may be "
  2125. << "used to specify per-configuration rules.";
  2126. if(!imported)
  2127. {
  2128. e << " "
  2129. << "Alternatively, an IMPORTED library may be created, configured "
  2130. << "with a per-configuration location, and then named in the "
  2131. << "property value. "
  2132. << "See the add_library command's IMPORTED mode for details."
  2133. << "\n"
  2134. << "If you have a list of libraries that already contains the "
  2135. << "keyword, use the target_link_libraries command with its "
  2136. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  2137. << "The command automatically recognizes link-type keywords and sets "
  2138. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  2139. << "properties accordingly.";
  2140. }
  2141. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2142. }
  2143. //----------------------------------------------------------------------------
  2144. void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
  2145. {
  2146. // Certain properties need checking.
  2147. if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
  2148. {
  2149. if(const char* value = this->GetProperty(prop))
  2150. {
  2151. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  2152. }
  2153. }
  2154. if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
  2155. {
  2156. if(const char* value = this->GetProperty(prop))
  2157. {
  2158. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  2159. }
  2160. }
  2161. }
  2162. //----------------------------------------------------------------------------
  2163. void cmTarget::MarkAsImported()
  2164. {
  2165. this->IsImportedTarget = true;
  2166. }
  2167. //----------------------------------------------------------------------------
  2168. cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
  2169. {
  2170. // There is no output information for imported targets.
  2171. if(this->IsImported())
  2172. {
  2173. return 0;
  2174. }
  2175. // Only libraries and executables have well-defined output files.
  2176. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  2177. this->GetType() != cmTarget::SHARED_LIBRARY &&
  2178. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2179. this->GetType() != cmTarget::EXECUTABLE)
  2180. {
  2181. std::string msg = "cmTarget::GetOutputInfo called for ";
  2182. msg += this->GetName();
  2183. msg += " which has type ";
  2184. msg += cmTarget::GetTargetTypeName(this->GetType());
  2185. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2186. abort();
  2187. return 0;
  2188. }
  2189. // Lookup/compute/cache the output information for this configuration.
  2190. std::string config_upper;
  2191. if(config && *config)
  2192. {
  2193. config_upper = cmSystemTools::UpperCase(config);
  2194. }
  2195. typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
  2196. OutputInfoMapType::const_iterator i =
  2197. this->Internal->OutputInfoMap.find(config_upper);
  2198. if(i == this->Internal->OutputInfoMap.end())
  2199. {
  2200. OutputInfo info;
  2201. this->ComputeOutputDir(config, false, info.OutDir);
  2202. this->ComputeOutputDir(config, true, info.ImpDir);
  2203. OutputInfoMapType::value_type entry(config_upper, info);
  2204. i = this->Internal->OutputInfoMap.insert(entry).first;
  2205. }
  2206. return &i->second;
  2207. }
  2208. //----------------------------------------------------------------------------
  2209. std::string cmTarget::GetDirectory(const char* config, bool implib)
  2210. {
  2211. if (this->IsImported())
  2212. {
  2213. // Return the directory from which the target is imported.
  2214. return
  2215. cmSystemTools::GetFilenamePath(
  2216. this->ImportedGetFullPath(config, implib));
  2217. }
  2218. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2219. {
  2220. // Return the directory in which the target will be built.
  2221. return implib? info->ImpDir : info->OutDir;
  2222. }
  2223. return "";
  2224. }
  2225. //----------------------------------------------------------------------------
  2226. const char* cmTarget::GetLocation(const char* config)
  2227. {
  2228. if (this->IsImported())
  2229. {
  2230. return this->ImportedGetLocation(config);
  2231. }
  2232. else
  2233. {
  2234. return this->NormalGetLocation(config);
  2235. }
  2236. }
  2237. //----------------------------------------------------------------------------
  2238. const char* cmTarget::ImportedGetLocation(const char* config)
  2239. {
  2240. this->Location = this->ImportedGetFullPath(config, false);
  2241. return this->Location.c_str();
  2242. }
  2243. //----------------------------------------------------------------------------
  2244. const char* cmTarget::NormalGetLocation(const char* config)
  2245. {
  2246. // Handle the configuration-specific case first.
  2247. if(config)
  2248. {
  2249. this->Location = this->GetFullPath(config, false);
  2250. return this->Location.c_str();
  2251. }
  2252. // Now handle the deprecated build-time configuration location.
  2253. this->Location = this->GetDirectory();
  2254. if(!this->Location.empty())
  2255. {
  2256. this->Location += "/";
  2257. }
  2258. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  2259. if(cfgid && strcmp(cfgid, ".") != 0)
  2260. {
  2261. this->Location += cfgid;
  2262. this->Location += "/";
  2263. }
  2264. if(this->IsAppBundleOnApple())
  2265. {
  2266. this->Location += this->GetFullName(config, false);
  2267. this->Location += ".app/Contents/MacOS/";
  2268. }
  2269. if(this->IsFrameworkOnApple())
  2270. {
  2271. this->Location += this->GetFullName(config, false);
  2272. this->Location += ".framework/Versions/";
  2273. this->Location += this->GetFrameworkVersion();
  2274. this->Location += "/";
  2275. }
  2276. this->Location += this->GetFullName(config, false);
  2277. return this->Location.c_str();
  2278. }
  2279. //----------------------------------------------------------------------------
  2280. void cmTarget::GetTargetVersion(int& major, int& minor)
  2281. {
  2282. int patch;
  2283. this->GetTargetVersion(false, major, minor, patch);
  2284. }
  2285. //----------------------------------------------------------------------------
  2286. void cmTarget::GetTargetVersion(bool soversion,
  2287. int& major, int& minor, int& patch)
  2288. {
  2289. // Set the default values.
  2290. major = 0;
  2291. minor = 0;
  2292. patch = 0;
  2293. // Look for a VERSION or SOVERSION property.
  2294. const char* prop = soversion? "SOVERSION" : "VERSION";
  2295. if(const char* version = this->GetProperty(prop))
  2296. {
  2297. // Try to parse the version number and store the results that were
  2298. // successfully parsed.
  2299. int parsed_major;
  2300. int parsed_minor;
  2301. int parsed_patch;
  2302. switch(sscanf(version, "%d.%d.%d",
  2303. &parsed_major, &parsed_minor, &parsed_patch))
  2304. {
  2305. case 3: patch = parsed_patch; // no break!
  2306. case 2: minor = parsed_minor; // no break!
  2307. case 1: major = parsed_major; // no break!
  2308. default: break;
  2309. }
  2310. }
  2311. }
  2312. //----------------------------------------------------------------------------
  2313. const char* cmTarget::GetFeature(const char* feature, const char* config)
  2314. {
  2315. if(config && *config)
  2316. {
  2317. std::string featureConfig = feature;
  2318. featureConfig += "_";
  2319. featureConfig += cmSystemTools::UpperCase(config);
  2320. if(const char* value = this->GetProperty(featureConfig.c_str()))
  2321. {
  2322. return value;
  2323. }
  2324. }
  2325. if(const char* value = this->GetProperty(feature))
  2326. {
  2327. return value;
  2328. }
  2329. return this->Makefile->GetFeature(feature, config);
  2330. }
  2331. //----------------------------------------------------------------------------
  2332. const char *cmTarget::GetProperty(const char* prop)
  2333. {
  2334. return this->GetProperty(prop, cmProperty::TARGET);
  2335. }
  2336. //----------------------------------------------------------------------------
  2337. void cmTarget::ComputeObjectFiles()
  2338. {
  2339. if (this->IsImported())
  2340. {
  2341. return;
  2342. }
  2343. #if 0
  2344. std::vector<std::string> dirs;
  2345. this->Makefile->GetLocalGenerator()->
  2346. GetTargetObjectFileDirectories(this,
  2347. dirs);
  2348. std::string objectFiles;
  2349. std::string objExtensionLookup1 = "CMAKE_";
  2350. std::string objExtensionLookup2 = "_OUTPUT_EXTENSION";
  2351. for(std::vector<std::string>::iterator d = dirs.begin();
  2352. d != dirs.end(); ++d)
  2353. {
  2354. for(std::vector<cmSourceFile*>::iterator s = this->SourceFiles.begin();
  2355. s != this->SourceFiles.end(); ++s)
  2356. {
  2357. cmSourceFile* sf = *s;
  2358. if(const char* lang = sf->GetLanguage())
  2359. {
  2360. std::string lookupObj = objExtensionLookup1 + lang;
  2361. lookupObj += objExtensionLookup2;
  2362. const char* obj = this->Makefile->GetDefinition(lookupObj.c_str());
  2363. if(obj)
  2364. {
  2365. if(objectFiles.size())
  2366. {
  2367. objectFiles += ";";
  2368. }
  2369. std::string objFile = *d;
  2370. objFile += "/";
  2371. objFile += this->Makefile->GetLocalGenerator()->
  2372. GetSourceObjectName(*sf);
  2373. objFile += obj;
  2374. objectFiles += objFile;
  2375. }
  2376. }
  2377. }
  2378. }
  2379. this->SetProperty("OBJECT_FILES", objectFiles.c_str());
  2380. #endif
  2381. }
  2382. //----------------------------------------------------------------------------
  2383. const char *cmTarget::GetProperty(const char* prop,
  2384. cmProperty::ScopeType scope)
  2385. {
  2386. if(!prop)
  2387. {
  2388. return 0;
  2389. }
  2390. // Watch for special "computed" properties that are dependent on
  2391. // other properties or variables. Always recompute them.
  2392. if(this->GetType() == cmTarget::EXECUTABLE ||
  2393. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2394. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2395. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2396. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2397. {
  2398. if(strcmp(prop,"LOCATION") == 0)
  2399. {
  2400. // Set the LOCATION property of the target.
  2401. //
  2402. // For an imported target this is the location of an arbitrary
  2403. // available configuration.
  2404. //
  2405. // For a non-imported target this is deprecated because it
  2406. // cannot take into account the per-configuration name of the
  2407. // target because the configuration type may not be known at
  2408. // CMake time.
  2409. this->SetProperty("LOCATION", this->GetLocation(0));
  2410. }
  2411. // Support "LOCATION_<CONFIG>".
  2412. if(strncmp(prop, "LOCATION_", 9) == 0)
  2413. {
  2414. std::string configName = prop+9;
  2415. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  2416. }
  2417. else
  2418. {
  2419. // Support "<CONFIG>_LOCATION" for compatiblity.
  2420. int len = static_cast<int>(strlen(prop));
  2421. if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
  2422. {
  2423. std::string configName(prop, len-9);
  2424. if(configName != "IMPORTED")
  2425. {
  2426. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  2427. }
  2428. }
  2429. }
  2430. }
  2431. if (strcmp(prop,"IMPORTED") == 0)
  2432. {
  2433. return this->IsImported()?"TRUE":"FALSE";
  2434. }
  2435. if(!strcmp(prop,"SOURCES"))
  2436. {
  2437. cmOStringStream ss;
  2438. const char* sep = "";
  2439. for(std::vector<cmSourceFile*>::const_iterator
  2440. i = this->SourceFiles.begin();
  2441. i != this->SourceFiles.end(); ++i)
  2442. {
  2443. // Separate from the previous list entries.
  2444. ss << sep;
  2445. sep = ";";
  2446. // Construct what is known about this source file location.
  2447. cmSourceFileLocation const& location = (*i)->GetLocation();
  2448. std::string sname = location.GetDirectory();
  2449. if(!sname.empty())
  2450. {
  2451. sname += "/";
  2452. }
  2453. sname += location.GetName();
  2454. // Append this list entry.
  2455. ss << sname;
  2456. }
  2457. this->SetProperty("SOURCES", ss.str().c_str());
  2458. }
  2459. // the type property returns what type the target is
  2460. if (!strcmp(prop,"TYPE"))
  2461. {
  2462. return cmTarget::GetTargetTypeName(this->GetType());
  2463. }
  2464. bool chain = false;
  2465. const char *retVal =
  2466. this->Properties.GetPropertyValue(prop, scope, chain);
  2467. if (chain)
  2468. {
  2469. return this->Makefile->GetProperty(prop,scope);
  2470. }
  2471. return retVal;
  2472. }
  2473. //----------------------------------------------------------------------------
  2474. bool cmTarget::GetPropertyAsBool(const char* prop)
  2475. {
  2476. return cmSystemTools::IsOn(this->GetProperty(prop));
  2477. }
  2478. //----------------------------------------------------------------------------
  2479. class cmTargetCollectLinkLanguages
  2480. {
  2481. public:
  2482. cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
  2483. std::set<cmStdString>& languages):
  2484. Config(config), Languages(languages) { this->Visited.insert(target); }
  2485. void Visit(cmTarget* target)
  2486. {
  2487. if(!target || !this->Visited.insert(target).second)
  2488. {
  2489. return;
  2490. }
  2491. cmTarget::LinkInterface const* iface =
  2492. target->GetLinkInterface(this->Config);
  2493. if(!iface) { return; }
  2494. for(std::vector<std::string>::const_iterator
  2495. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  2496. {
  2497. this->Languages.insert(*li);
  2498. }
  2499. cmMakefile* mf = target->GetMakefile();
  2500. for(std::vector<std::string>::const_iterator
  2501. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  2502. {
  2503. this->Visit(mf->FindTargetToUse(li->c_str()));
  2504. }
  2505. }
  2506. private:
  2507. const char* Config;
  2508. std::set<cmStdString>& Languages;
  2509. std::set<cmTarget*> Visited;
  2510. };
  2511. //----------------------------------------------------------------------------
  2512. const char* cmTarget::GetLinkerLanguage(const char* config)
  2513. {
  2514. const char* lang = this->GetLinkClosure(config)->LinkerLanguage.c_str();
  2515. return *lang? lang : 0;
  2516. }
  2517. //----------------------------------------------------------------------------
  2518. cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config)
  2519. {
  2520. std::string key = cmSystemTools::UpperCase(config? config : "");
  2521. cmTargetInternals::LinkClosureMapType::iterator
  2522. i = this->Internal->LinkClosureMap.find(key);
  2523. if(i == this->Internal->LinkClosureMap.end())
  2524. {
  2525. LinkClosure lc;
  2526. this->ComputeLinkClosure(config, lc);
  2527. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  2528. i = this->Internal->LinkClosureMap.insert(entry).first;
  2529. }
  2530. return &i->second;
  2531. }
  2532. //----------------------------------------------------------------------------
  2533. class cmTargetSelectLinker
  2534. {
  2535. int Preference;
  2536. cmTarget* Target;
  2537. cmMakefile* Makefile;
  2538. cmGlobalGenerator* GG;
  2539. std::set<cmStdString> Preferred;
  2540. public:
  2541. cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
  2542. {
  2543. this->Makefile = this->Target->GetMakefile();
  2544. this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  2545. }
  2546. void Consider(const char* lang)
  2547. {
  2548. int preference = this->GG->GetLinkerPreference(lang);
  2549. if(preference > this->Preference)
  2550. {
  2551. this->Preference = preference;
  2552. this->Preferred.clear();
  2553. }
  2554. if(preference == this->Preference)
  2555. {
  2556. this->Preferred.insert(lang);
  2557. }
  2558. }
  2559. std::string Choose()
  2560. {
  2561. if(this->Preferred.empty())
  2562. {
  2563. return "";
  2564. }
  2565. else if(this->Preferred.size() > 1)
  2566. {
  2567. cmOStringStream e;
  2568. e << "Target " << this->Target->GetName()
  2569. << " contains multiple languages with the highest linker preference"
  2570. << " (" << this->Preference << "):\n";
  2571. for(std::set<cmStdString>::const_iterator
  2572. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  2573. {
  2574. e << " " << *li << "\n";
  2575. }
  2576. e << "Set the LINKER_LANGUAGE property for this target.";
  2577. cmake* cm = this->Makefile->GetCMakeInstance();
  2578. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  2579. this->Target->GetBacktrace());
  2580. }
  2581. return *this->Preferred.begin();
  2582. }
  2583. };
  2584. //----------------------------------------------------------------------------
  2585. void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc)
  2586. {
  2587. // Get languages built in this target.
  2588. std::set<cmStdString> languages;
  2589. LinkImplementation const* impl = this->GetLinkImplementation(config);
  2590. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  2591. li != impl->Languages.end(); ++li)
  2592. {
  2593. languages.insert(*li);
  2594. }
  2595. // Add interface languages from linked targets.
  2596. cmTargetCollectLinkLanguages cll(this, config, languages);
  2597. for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
  2598. li != impl->Libraries.end(); ++li)
  2599. {
  2600. cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
  2601. }
  2602. // Store the transitive closure of languages.
  2603. for(std::set<cmStdString>::const_iterator li = languages.begin();
  2604. li != languages.end(); ++li)
  2605. {
  2606. lc.Languages.push_back(*li);
  2607. }
  2608. // Choose the language whose linker should be used.
  2609. if(this->GetProperty("HAS_CXX"))
  2610. {
  2611. lc.LinkerLanguage = "CXX";
  2612. }
  2613. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  2614. {
  2615. lc.LinkerLanguage = linkerLang;
  2616. }
  2617. else
  2618. {
  2619. // Find the language with the highest preference value.
  2620. cmTargetSelectLinker tsl(this);
  2621. // First select from the languages compiled directly in this target.
  2622. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  2623. li != impl->Languages.end(); ++li)
  2624. {
  2625. tsl.Consider(li->c_str());
  2626. }
  2627. // Now consider languages that propagate from linked targets.
  2628. for(std::set<cmStdString>::const_iterator sit = languages.begin();
  2629. sit != languages.end(); ++sit)
  2630. {
  2631. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  2632. if(this->Makefile->IsOn(propagates.c_str()))
  2633. {
  2634. tsl.Consider(sit->c_str());
  2635. }
  2636. }
  2637. lc.LinkerLanguage = tsl.Choose();
  2638. }
  2639. }
  2640. //----------------------------------------------------------------------------
  2641. const char* cmTarget::GetCreateRuleVariable()
  2642. {
  2643. switch(this->GetType())
  2644. {
  2645. case cmTarget::STATIC_LIBRARY:
  2646. return "_CREATE_STATIC_LIBRARY";
  2647. case cmTarget::SHARED_LIBRARY:
  2648. return "_CREATE_SHARED_LIBRARY";
  2649. case cmTarget::MODULE_LIBRARY:
  2650. return "_CREATE_SHARED_MODULE";
  2651. case cmTarget::EXECUTABLE:
  2652. return "_LINK_EXECUTABLE";
  2653. default:
  2654. break;
  2655. }
  2656. return "";
  2657. }
  2658. //----------------------------------------------------------------------------
  2659. const char* cmTarget::GetSuffixVariableInternal(bool implib)
  2660. {
  2661. switch(this->GetType())
  2662. {
  2663. case cmTarget::STATIC_LIBRARY:
  2664. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  2665. case cmTarget::SHARED_LIBRARY:
  2666. return (implib
  2667. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2668. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  2669. case cmTarget::MODULE_LIBRARY:
  2670. return (implib
  2671. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2672. : "CMAKE_SHARED_MODULE_SUFFIX");
  2673. case cmTarget::EXECUTABLE:
  2674. return (implib
  2675. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2676. : "CMAKE_EXECUTABLE_SUFFIX");
  2677. default:
  2678. break;
  2679. }
  2680. return "";
  2681. }
  2682. //----------------------------------------------------------------------------
  2683. const char* cmTarget::GetPrefixVariableInternal(bool implib)
  2684. {
  2685. switch(this->GetType())
  2686. {
  2687. case cmTarget::STATIC_LIBRARY:
  2688. return "CMAKE_STATIC_LIBRARY_PREFIX";
  2689. case cmTarget::SHARED_LIBRARY:
  2690. return (implib
  2691. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2692. : "CMAKE_SHARED_LIBRARY_PREFIX");
  2693. case cmTarget::MODULE_LIBRARY:
  2694. return (implib
  2695. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2696. : "CMAKE_SHARED_MODULE_PREFIX");
  2697. case cmTarget::EXECUTABLE:
  2698. return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
  2699. default:
  2700. break;
  2701. }
  2702. return "";
  2703. }
  2704. //----------------------------------------------------------------------------
  2705. std::string cmTarget::GetPDBName(const char* config)
  2706. {
  2707. std::string prefix;
  2708. std::string base;
  2709. std::string suffix;
  2710. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2711. return prefix+base+".pdb";
  2712. }
  2713. //----------------------------------------------------------------------------
  2714. std::string cmTarget::GetSOName(const char* config)
  2715. {
  2716. if(this->IsImported())
  2717. {
  2718. // Lookup the imported soname.
  2719. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2720. {
  2721. if(info->NoSOName)
  2722. {
  2723. // The imported library has no builtin soname so the name
  2724. // searched at runtime will be just the filename.
  2725. return cmSystemTools::GetFilenameName(info->Location);
  2726. }
  2727. else
  2728. {
  2729. // Use the soname given if any.
  2730. return info->SOName;
  2731. }
  2732. }
  2733. else
  2734. {
  2735. return "";
  2736. }
  2737. }
  2738. else
  2739. {
  2740. // Compute the soname that will be built.
  2741. std::string name;
  2742. std::string soName;
  2743. std::string realName;
  2744. std::string impName;
  2745. std::string pdbName;
  2746. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2747. return soName;
  2748. }
  2749. }
  2750. //----------------------------------------------------------------------------
  2751. bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
  2752. {
  2753. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  2754. {
  2755. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2756. {
  2757. return info->NoSOName;
  2758. }
  2759. }
  2760. return false;
  2761. }
  2762. //----------------------------------------------------------------------------
  2763. std::string cmTarget::NormalGetRealName(const char* config)
  2764. {
  2765. // This should not be called for imported targets.
  2766. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2767. // enforcement of the limited imported target API.
  2768. if(this->IsImported())
  2769. {
  2770. std::string msg = "NormalGetRealName called on imported target: ";
  2771. msg += this->GetName();
  2772. this->GetMakefile()->
  2773. IssueMessage(cmake::INTERNAL_ERROR,
  2774. msg.c_str());
  2775. }
  2776. if(this->GetType() == cmTarget::EXECUTABLE)
  2777. {
  2778. // Compute the real name that will be built.
  2779. std::string name;
  2780. std::string realName;
  2781. std::string impName;
  2782. std::string pdbName;
  2783. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2784. return realName;
  2785. }
  2786. else
  2787. {
  2788. // Compute the real name that will be built.
  2789. std::string name;
  2790. std::string soName;
  2791. std::string realName;
  2792. std::string impName;
  2793. std::string pdbName;
  2794. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2795. return realName;
  2796. }
  2797. }
  2798. //----------------------------------------------------------------------------
  2799. std::string cmTarget::GetFullName(const char* config, bool implib)
  2800. {
  2801. if(this->IsImported())
  2802. {
  2803. return this->GetFullNameImported(config, implib);
  2804. }
  2805. else
  2806. {
  2807. return this->GetFullNameInternal(config, implib);
  2808. }
  2809. }
  2810. //----------------------------------------------------------------------------
  2811. std::string cmTarget::GetFullNameImported(const char* config, bool implib)
  2812. {
  2813. return cmSystemTools::GetFilenameName(
  2814. this->ImportedGetFullPath(config, implib));
  2815. }
  2816. //----------------------------------------------------------------------------
  2817. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  2818. std::string& suffix, const char* config,
  2819. bool implib)
  2820. {
  2821. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2822. }
  2823. //----------------------------------------------------------------------------
  2824. std::string cmTarget::GetFullPath(const char* config, bool implib,
  2825. bool realname)
  2826. {
  2827. if(this->IsImported())
  2828. {
  2829. return this->ImportedGetFullPath(config, implib);
  2830. }
  2831. else
  2832. {
  2833. return this->NormalGetFullPath(config, implib, realname);
  2834. }
  2835. }
  2836. //----------------------------------------------------------------------------
  2837. std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
  2838. bool realname)
  2839. {
  2840. // Start with the output directory for the target.
  2841. std::string fpath = this->GetDirectory(config, implib);
  2842. fpath += "/";
  2843. if(this->IsAppBundleOnApple())
  2844. {
  2845. fpath += this->GetFullName(config, false);
  2846. fpath += ".app/Contents/MacOS/";
  2847. }
  2848. if(this->IsFrameworkOnApple())
  2849. {
  2850. fpath += this->GetFullName(config, false);
  2851. fpath += ".framework/Versions/";
  2852. fpath += this->GetFrameworkVersion();
  2853. fpath += "/";
  2854. }
  2855. // Add the full name of the target.
  2856. if(implib)
  2857. {
  2858. fpath += this->GetFullName(config, true);
  2859. }
  2860. else if(realname)
  2861. {
  2862. fpath += this->NormalGetRealName(config);
  2863. }
  2864. else
  2865. {
  2866. fpath += this->GetFullName(config, false);
  2867. }
  2868. return fpath;
  2869. }
  2870. //----------------------------------------------------------------------------
  2871. std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
  2872. {
  2873. std::string result;
  2874. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2875. {
  2876. result = implib? info->ImportLibrary : info->Location;
  2877. }
  2878. if(result.empty())
  2879. {
  2880. result = this->GetName();
  2881. result += "-NOTFOUND";
  2882. }
  2883. return result;
  2884. }
  2885. //----------------------------------------------------------------------------
  2886. std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
  2887. {
  2888. std::string prefix;
  2889. std::string base;
  2890. std::string suffix;
  2891. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2892. return prefix+base+suffix;
  2893. }
  2894. //----------------------------------------------------------------------------
  2895. void cmTarget::GetFullNameInternal(const char* config,
  2896. bool implib,
  2897. std::string& outPrefix,
  2898. std::string& outBase,
  2899. std::string& outSuffix)
  2900. {
  2901. // Use just the target name for non-main target types.
  2902. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  2903. this->GetType() != cmTarget::SHARED_LIBRARY &&
  2904. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2905. this->GetType() != cmTarget::EXECUTABLE)
  2906. {
  2907. outPrefix = "";
  2908. outBase = this->GetName();
  2909. outSuffix = "";
  2910. return;
  2911. }
  2912. // Return an empty name for the import library if this platform
  2913. // does not support import libraries.
  2914. if(implib &&
  2915. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  2916. {
  2917. outPrefix = "";
  2918. outBase = "";
  2919. outSuffix = "";
  2920. return;
  2921. }
  2922. // The implib option is only allowed for shared libraries, module
  2923. // libraries, and executables.
  2924. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  2925. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2926. this->GetType() != cmTarget::EXECUTABLE)
  2927. {
  2928. implib = false;
  2929. }
  2930. // Compute the full name for main target types.
  2931. const char* targetPrefix = (implib
  2932. ? this->GetProperty("IMPORT_PREFIX")
  2933. : this->GetProperty("PREFIX"));
  2934. const char* targetSuffix = (implib
  2935. ? this->GetProperty("IMPORT_SUFFIX")
  2936. : this->GetProperty("SUFFIX"));
  2937. const char* configPostfix = 0;
  2938. if(config && *config)
  2939. {
  2940. std::string configProp = cmSystemTools::UpperCase(config);
  2941. configProp += "_POSTFIX";
  2942. configPostfix = this->GetProperty(configProp.c_str());
  2943. // Mac application bundles and frameworks have no postfix.
  2944. if(configPostfix &&
  2945. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  2946. {
  2947. configPostfix = 0;
  2948. }
  2949. }
  2950. const char* prefixVar = this->GetPrefixVariableInternal(implib);
  2951. const char* suffixVar = this->GetSuffixVariableInternal(implib);
  2952. // Check for language-specific default prefix and suffix.
  2953. if(const char* ll = this->GetLinkerLanguage(config))
  2954. {
  2955. if(!targetSuffix && suffixVar && *suffixVar)
  2956. {
  2957. std::string langSuff = suffixVar + std::string("_") + ll;
  2958. targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
  2959. }
  2960. if(!targetPrefix && prefixVar && *prefixVar)
  2961. {
  2962. std::string langPrefix = prefixVar + std::string("_") + ll;
  2963. targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
  2964. }
  2965. }
  2966. // if there is no prefix on the target use the cmake definition
  2967. if(!targetPrefix && prefixVar)
  2968. {
  2969. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2970. }
  2971. // if there is no suffix on the target use the cmake definition
  2972. if(!targetSuffix && suffixVar)
  2973. {
  2974. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2975. }
  2976. // frameworks do not have a prefix or a suffix
  2977. if(this->IsFrameworkOnApple())
  2978. {
  2979. targetPrefix = 0;
  2980. targetSuffix = 0;
  2981. }
  2982. // Begin the final name with the prefix.
  2983. outPrefix = targetPrefix?targetPrefix:"";
  2984. // Append the target name or property-specified name.
  2985. outBase += this->GetOutputName(config, implib);
  2986. // Append the per-configuration postfix.
  2987. outBase += configPostfix?configPostfix:"";
  2988. // Name shared libraries with their version number on some platforms.
  2989. if(const char* soversion = this->GetProperty("SOVERSION"))
  2990. {
  2991. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  2992. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  2993. {
  2994. outBase += "-";
  2995. outBase += soversion;
  2996. }
  2997. }
  2998. // Append the suffix.
  2999. outSuffix = targetSuffix?targetSuffix:"";
  3000. }
  3001. //----------------------------------------------------------------------------
  3002. void cmTarget::GetLibraryNames(std::string& name,
  3003. std::string& soName,
  3004. std::string& realName,
  3005. std::string& impName,
  3006. std::string& pdbName,
  3007. const char* config)
  3008. {
  3009. // This should not be called for imported targets.
  3010. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3011. // enforcement of the limited imported target API.
  3012. if(this->IsImported())
  3013. {
  3014. std::string msg = "GetLibraryNames called on imported target: ";
  3015. msg += this->GetName();
  3016. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  3017. msg.c_str());
  3018. return;
  3019. }
  3020. // Construct the name of the soname flag variable for this language.
  3021. const char* ll = this->GetLinkerLanguage(config);
  3022. std::string sonameFlag = "CMAKE_SHARED_LIBRARY_SONAME";
  3023. if(ll)
  3024. {
  3025. sonameFlag += "_";
  3026. sonameFlag += ll;
  3027. }
  3028. sonameFlag += "_FLAG";
  3029. // Check for library version properties.
  3030. const char* version = this->GetProperty("VERSION");
  3031. const char* soversion = this->GetProperty("SOVERSION");
  3032. if((this->GetType() != cmTarget::SHARED_LIBRARY &&
  3033. this->GetType() != cmTarget::MODULE_LIBRARY) ||
  3034. !this->Makefile->GetDefinition(sonameFlag.c_str()) ||
  3035. this->IsFrameworkOnApple())
  3036. {
  3037. // Versioning is supported only for shared libraries and modules,
  3038. // and then only when the platform supports an soname flag.
  3039. version = 0;
  3040. soversion = 0;
  3041. }
  3042. if(version && !soversion)
  3043. {
  3044. // The soversion must be set if the library version is set. Use
  3045. // the library version as the soversion.
  3046. soversion = version;
  3047. }
  3048. bool isApple = this->Makefile->IsOn("APPLE");
  3049. // Get the components of the library name.
  3050. std::string prefix;
  3051. std::string base;
  3052. std::string suffix;
  3053. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3054. // The library name.
  3055. name = prefix+base+suffix;
  3056. // The library's soname.
  3057. if(isApple)
  3058. {
  3059. soName = prefix+base;
  3060. }
  3061. else
  3062. {
  3063. soName = name;
  3064. }
  3065. if(soversion)
  3066. {
  3067. soName += ".";
  3068. soName += soversion;
  3069. }
  3070. if(isApple)
  3071. {
  3072. soName += suffix;
  3073. }
  3074. // The library's real name on disk.
  3075. if(isApple)
  3076. {
  3077. realName = prefix+base;
  3078. }
  3079. else
  3080. {
  3081. realName = name;
  3082. }
  3083. if(version)
  3084. {
  3085. realName += ".";
  3086. realName += version;
  3087. }
  3088. else if(soversion)
  3089. {
  3090. realName += ".";
  3091. realName += soversion;
  3092. }
  3093. if(isApple)
  3094. {
  3095. realName += suffix;
  3096. }
  3097. // The import library name.
  3098. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3099. this->GetType() == cmTarget::MODULE_LIBRARY)
  3100. {
  3101. impName = this->GetFullNameInternal(config, true);
  3102. }
  3103. else
  3104. {
  3105. impName = "";
  3106. }
  3107. // The program database file name.
  3108. pdbName = prefix+base+".pdb";
  3109. }
  3110. //----------------------------------------------------------------------------
  3111. void cmTarget::GetExecutableNames(std::string& name,
  3112. std::string& realName,
  3113. std::string& impName,
  3114. std::string& pdbName,
  3115. const char* config)
  3116. {
  3117. // This should not be called for imported targets.
  3118. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3119. // enforcement of the limited imported target API.
  3120. if(this->IsImported())
  3121. {
  3122. std::string msg =
  3123. "GetExecutableNames called on imported target: ";
  3124. msg += this->GetName();
  3125. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
  3126. }
  3127. // This versioning is supported only for executables and then only
  3128. // when the platform supports symbolic links.
  3129. #if defined(_WIN32) && !defined(__CYGWIN__)
  3130. const char* version = 0;
  3131. #else
  3132. // Check for executable version properties.
  3133. const char* version = this->GetProperty("VERSION");
  3134. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3135. {
  3136. version = 0;
  3137. }
  3138. #endif
  3139. // Get the components of the executable name.
  3140. std::string prefix;
  3141. std::string base;
  3142. std::string suffix;
  3143. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3144. // The executable name.
  3145. name = prefix+base+suffix;
  3146. // The executable's real name on disk.
  3147. #if defined(__CYGWIN__)
  3148. realName = prefix+base;
  3149. #else
  3150. realName = name;
  3151. #endif
  3152. if(version)
  3153. {
  3154. realName += "-";
  3155. realName += version;
  3156. }
  3157. #if defined(__CYGWIN__)
  3158. realName += suffix;
  3159. #endif
  3160. // The import library name.
  3161. impName = this->GetFullNameInternal(config, true);
  3162. // The program database file name.
  3163. pdbName = prefix+base+".pdb";
  3164. }
  3165. //----------------------------------------------------------------------------
  3166. void cmTarget::GenerateTargetManifest(const char* config)
  3167. {
  3168. cmMakefile* mf = this->Makefile;
  3169. cmLocalGenerator* lg = mf->GetLocalGenerator();
  3170. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  3171. // Get the names.
  3172. std::string name;
  3173. std::string soName;
  3174. std::string realName;
  3175. std::string impName;
  3176. std::string pdbName;
  3177. if(this->GetType() == cmTarget::EXECUTABLE)
  3178. {
  3179. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3180. }
  3181. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3182. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3183. this->GetType() == cmTarget::MODULE_LIBRARY)
  3184. {
  3185. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3186. }
  3187. else
  3188. {
  3189. return;
  3190. }
  3191. // Get the directory.
  3192. std::string dir = this->GetDirectory(config, false);
  3193. // Add each name.
  3194. std::string f;
  3195. if(!name.empty())
  3196. {
  3197. f = dir;
  3198. f += "/";
  3199. f += name;
  3200. gg->AddToManifest(config? config:"", f);
  3201. }
  3202. if(!soName.empty())
  3203. {
  3204. f = dir;
  3205. f += "/";
  3206. f += soName;
  3207. gg->AddToManifest(config? config:"", f);
  3208. }
  3209. if(!realName.empty())
  3210. {
  3211. f = dir;
  3212. f += "/";
  3213. f += realName;
  3214. gg->AddToManifest(config? config:"", f);
  3215. }
  3216. if(!pdbName.empty())
  3217. {
  3218. f = dir;
  3219. f += "/";
  3220. f += pdbName;
  3221. gg->AddToManifest(config? config:"", f);
  3222. }
  3223. if(!impName.empty())
  3224. {
  3225. f = this->GetDirectory(config, true);
  3226. f += "/";
  3227. f += impName;
  3228. gg->AddToManifest(config? config:"", f);
  3229. }
  3230. }
  3231. //----------------------------------------------------------------------------
  3232. void cmTarget::SetPropertyDefault(const char* property,
  3233. const char* default_value)
  3234. {
  3235. // Compute the name of the variable holding the default value.
  3236. std::string var = "CMAKE_";
  3237. var += property;
  3238. if(const char* value = this->Makefile->GetDefinition(var.c_str()))
  3239. {
  3240. this->SetProperty(property, value);
  3241. }
  3242. else if(default_value)
  3243. {
  3244. this->SetProperty(property, default_value);
  3245. }
  3246. }
  3247. //----------------------------------------------------------------------------
  3248. bool cmTarget::HaveBuildTreeRPATH()
  3249. {
  3250. return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
  3251. !this->LinkLibraries.empty());
  3252. }
  3253. //----------------------------------------------------------------------------
  3254. bool cmTarget::HaveInstallTreeRPATH()
  3255. {
  3256. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3257. return install_rpath && *install_rpath;
  3258. }
  3259. //----------------------------------------------------------------------------
  3260. bool cmTarget::NeedRelinkBeforeInstall(const char* config)
  3261. {
  3262. // Only executables and shared libraries can have an rpath and may
  3263. // need relinking.
  3264. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  3265. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  3266. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  3267. {
  3268. return false;
  3269. }
  3270. // If there is no install location this target will not be installed
  3271. // and therefore does not need relinking.
  3272. if(!this->GetHaveInstallRule())
  3273. {
  3274. return false;
  3275. }
  3276. // If skipping all rpaths completely then no relinking is needed.
  3277. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3278. {
  3279. return false;
  3280. }
  3281. // If building with the install-tree rpath no relinking is needed.
  3282. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3283. {
  3284. return false;
  3285. }
  3286. // If chrpath is going to be used no relinking is needed.
  3287. if(this->IsChrpathUsed(config))
  3288. {
  3289. return false;
  3290. }
  3291. // Check for rpath support on this platform.
  3292. if(const char* ll = this->GetLinkerLanguage(config))
  3293. {
  3294. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3295. flagVar += ll;
  3296. flagVar += "_FLAG";
  3297. if(!this->Makefile->IsSet(flagVar.c_str()))
  3298. {
  3299. // There is no rpath support on this platform so nothing needs
  3300. // relinking.
  3301. return false;
  3302. }
  3303. }
  3304. else
  3305. {
  3306. // No linker language is known. This error will be reported by
  3307. // other code.
  3308. return false;
  3309. }
  3310. // If either a build or install tree rpath is set then the rpath
  3311. // will likely change between the build tree and install tree and
  3312. // this target must be relinked.
  3313. return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
  3314. }
  3315. //----------------------------------------------------------------------------
  3316. std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
  3317. bool for_xcode)
  3318. {
  3319. // If building directly for installation then the build tree install_name
  3320. // is the same as the install tree.
  3321. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3322. {
  3323. return GetInstallNameDirForInstallTree(config, for_xcode);
  3324. }
  3325. // Use the build tree directory for the target.
  3326. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  3327. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3328. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3329. {
  3330. std::string dir = this->GetDirectory(config);
  3331. dir += "/";
  3332. if(this->IsFrameworkOnApple() && !for_xcode)
  3333. {
  3334. dir += this->GetFullName(config, false);
  3335. dir += ".framework/Versions/";
  3336. dir += this->GetFrameworkVersion();
  3337. dir += "/";
  3338. }
  3339. return dir;
  3340. }
  3341. else
  3342. {
  3343. return "";
  3344. }
  3345. }
  3346. //----------------------------------------------------------------------------
  3347. std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
  3348. bool for_xcode)
  3349. {
  3350. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  3351. {
  3352. std::string dir;
  3353. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3354. {
  3355. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  3356. if(install_name_dir && *install_name_dir)
  3357. {
  3358. dir = install_name_dir;
  3359. dir += "/";
  3360. }
  3361. }
  3362. if(this->IsFrameworkOnApple() && !for_xcode)
  3363. {
  3364. dir += this->GetFullName(config, false);
  3365. dir += ".framework/Versions/";
  3366. dir += this->GetFrameworkVersion();
  3367. dir += "/";
  3368. }
  3369. return dir;
  3370. }
  3371. else
  3372. {
  3373. return "";
  3374. }
  3375. }
  3376. //----------------------------------------------------------------------------
  3377. const char* cmTarget::GetOutputTargetType(bool implib)
  3378. {
  3379. switch(this->GetType())
  3380. {
  3381. case cmTarget::SHARED_LIBRARY:
  3382. if(this->DLLPlatform)
  3383. {
  3384. if(implib)
  3385. {
  3386. // A DLL import library is treated as an archive target.
  3387. return "ARCHIVE";
  3388. }
  3389. else
  3390. {
  3391. // A DLL shared library is treated as a runtime target.
  3392. return "RUNTIME";
  3393. }
  3394. }
  3395. else
  3396. {
  3397. // For non-DLL platforms shared libraries are treated as
  3398. // library targets.
  3399. return "LIBRARY";
  3400. }
  3401. case cmTarget::STATIC_LIBRARY:
  3402. // Static libraries are always treated as archive targets.
  3403. return "ARCHIVE";
  3404. case cmTarget::MODULE_LIBRARY:
  3405. if(implib)
  3406. {
  3407. // Module libraries are always treated as library targets.
  3408. return "ARCHIVE";
  3409. }
  3410. else
  3411. {
  3412. // Module import libraries are treated as archive targets.
  3413. return "LIBRARY";
  3414. }
  3415. case cmTarget::EXECUTABLE:
  3416. if(implib)
  3417. {
  3418. // Executable import libraries are treated as archive targets.
  3419. return "ARCHIVE";
  3420. }
  3421. else
  3422. {
  3423. // Executables are always treated as runtime targets.
  3424. return "RUNTIME";
  3425. }
  3426. default:
  3427. break;
  3428. }
  3429. return "";
  3430. }
  3431. //----------------------------------------------------------------------------
  3432. bool cmTarget::ComputeOutputDir(const char* config,
  3433. bool implib, std::string& out)
  3434. {
  3435. bool usesDefaultOutputDir = false;
  3436. // Look for a target property defining the target output directory
  3437. // based on the target type.
  3438. std::string targetTypeName = this->GetOutputTargetType(implib);
  3439. const char* propertyName = 0;
  3440. std::string propertyNameStr = targetTypeName;
  3441. if(!propertyNameStr.empty())
  3442. {
  3443. propertyNameStr += "_OUTPUT_DIRECTORY";
  3444. propertyName = propertyNameStr.c_str();
  3445. }
  3446. // Check for a per-configuration output directory target property.
  3447. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3448. const char* configProp = 0;
  3449. std::string configPropStr = targetTypeName;
  3450. if(!configPropStr.empty())
  3451. {
  3452. configPropStr += "_OUTPUT_DIRECTORY_";
  3453. configPropStr += configUpper;
  3454. configProp = configPropStr.c_str();
  3455. }
  3456. // Select an output directory.
  3457. if(const char* config_outdir = this->GetProperty(configProp))
  3458. {
  3459. // Use the user-specified per-configuration output directory.
  3460. out = config_outdir;
  3461. // Skip per-configuration subdirectory.
  3462. config = 0;
  3463. }
  3464. else if(const char* outdir = this->GetProperty(propertyName))
  3465. {
  3466. // Use the user-specified output directory.
  3467. out = outdir;
  3468. }
  3469. else if(this->GetType() == cmTarget::EXECUTABLE)
  3470. {
  3471. // Lookup the output path for executables.
  3472. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  3473. }
  3474. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3475. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3476. this->GetType() == cmTarget::MODULE_LIBRARY)
  3477. {
  3478. // Lookup the output path for libraries.
  3479. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  3480. }
  3481. if(out.empty())
  3482. {
  3483. // Default to the current output directory.
  3484. usesDefaultOutputDir = true;
  3485. out = ".";
  3486. }
  3487. // Convert the output path to a full path in case it is
  3488. // specified as a relative path. Treat a relative path as
  3489. // relative to the current output directory for this makefile.
  3490. out = (cmSystemTools::CollapseFullPath
  3491. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  3492. // The generator may add the configuration's subdirectory.
  3493. if(config && *config)
  3494. {
  3495. const char *platforms = this->Makefile->GetDefinition(
  3496. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  3497. std::string suffix =
  3498. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  3499. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3500. AppendDirectoryForConfig("/", config, suffix.c_str(), out);
  3501. }
  3502. return usesDefaultOutputDir;
  3503. }
  3504. //----------------------------------------------------------------------------
  3505. bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib)
  3506. {
  3507. std::string dir;
  3508. return this->ComputeOutputDir(config, implib, dir);
  3509. }
  3510. //----------------------------------------------------------------------------
  3511. std::string cmTarget::GetOutputName(const char* config, bool implib)
  3512. {
  3513. std::vector<std::string> props;
  3514. std::string type = this->GetOutputTargetType(implib);
  3515. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3516. if(!type.empty() && !configUpper.empty())
  3517. {
  3518. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  3519. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  3520. }
  3521. if(!type.empty())
  3522. {
  3523. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  3524. props.push_back(type + "_OUTPUT_NAME");
  3525. }
  3526. if(!configUpper.empty())
  3527. {
  3528. // OUTPUT_NAME_<CONFIG>
  3529. props.push_back("OUTPUT_NAME_" + configUpper);
  3530. // <CONFIG>_OUTPUT_NAME
  3531. props.push_back(configUpper + "_OUTPUT_NAME");
  3532. }
  3533. // OUTPUT_NAME
  3534. props.push_back("OUTPUT_NAME");
  3535. for(std::vector<std::string>::const_iterator i = props.begin();
  3536. i != props.end(); ++i)
  3537. {
  3538. if(const char* outName = this->GetProperty(i->c_str()))
  3539. {
  3540. return outName;
  3541. }
  3542. }
  3543. return this->GetName();
  3544. }
  3545. //----------------------------------------------------------------------------
  3546. std::string cmTarget::GetFrameworkVersion()
  3547. {
  3548. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  3549. {
  3550. return fversion;
  3551. }
  3552. else if(const char* tversion = this->GetProperty("VERSION"))
  3553. {
  3554. return tversion;
  3555. }
  3556. else
  3557. {
  3558. return "A";
  3559. }
  3560. }
  3561. //----------------------------------------------------------------------------
  3562. const char* cmTarget::GetExportMacro()
  3563. {
  3564. // Define the symbol for targets that export symbols.
  3565. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3566. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3567. this->IsExecutableWithExports())
  3568. {
  3569. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  3570. {
  3571. this->ExportMacro = custom_export_name;
  3572. }
  3573. else
  3574. {
  3575. std::string in = this->GetName();
  3576. in += "_EXPORTS";
  3577. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  3578. }
  3579. return this->ExportMacro.c_str();
  3580. }
  3581. else
  3582. {
  3583. return 0;
  3584. }
  3585. }
  3586. //----------------------------------------------------------------------------
  3587. void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
  3588. {
  3589. for(std::vector<cmSourceFile*>::const_iterator
  3590. i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  3591. {
  3592. if(const char* lang = (*i)->GetLanguage())
  3593. {
  3594. languages.insert(lang);
  3595. }
  3596. }
  3597. }
  3598. //----------------------------------------------------------------------------
  3599. void cmTarget::GetAppleArchs(const char* config,
  3600. std::vector<std::string>& archVec)
  3601. {
  3602. const char* archs = 0;
  3603. if(config && *config)
  3604. {
  3605. std::string defVarName = "OSX_ARCHITECTURES_";
  3606. defVarName += cmSystemTools::UpperCase(config);
  3607. archs = this->GetProperty(defVarName.c_str());
  3608. }
  3609. if(!archs)
  3610. {
  3611. archs = this->GetProperty("OSX_ARCHITECTURES");
  3612. }
  3613. if(archs)
  3614. {
  3615. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  3616. }
  3617. }
  3618. //----------------------------------------------------------------------------
  3619. bool cmTarget::IsChrpathUsed(const char* config)
  3620. {
  3621. #if defined(CMAKE_USE_ELF_PARSER)
  3622. // Only certain target types have an rpath.
  3623. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3624. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3625. this->GetType() == cmTarget::EXECUTABLE))
  3626. {
  3627. return false;
  3628. }
  3629. // If the target will not be installed we do not need to change its
  3630. // rpath.
  3631. if(!this->GetHaveInstallRule())
  3632. {
  3633. return false;
  3634. }
  3635. // Skip chrpath if skipping rpath altogether.
  3636. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3637. {
  3638. return false;
  3639. }
  3640. // Skip chrpath if it does not need to be changed at install time.
  3641. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3642. {
  3643. return false;
  3644. }
  3645. // Allow the user to disable builtin chrpath explicitly.
  3646. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  3647. {
  3648. return false;
  3649. }
  3650. // Enable if the rpath flag uses a separator and the target uses ELF
  3651. // binaries.
  3652. if(const char* ll = this->GetLinkerLanguage(config))
  3653. {
  3654. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3655. sepVar += ll;
  3656. sepVar += "_FLAG_SEP";
  3657. const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
  3658. if(sep && *sep)
  3659. {
  3660. // TODO: Add ELF check to ABI detection and get rid of
  3661. // CMAKE_EXECUTABLE_FORMAT.
  3662. if(const char* fmt =
  3663. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  3664. {
  3665. return strcmp(fmt, "ELF") == 0;
  3666. }
  3667. }
  3668. }
  3669. #endif
  3670. static_cast<void>(config);
  3671. return false;
  3672. }
  3673. //----------------------------------------------------------------------------
  3674. cmTarget::ImportInfo const*
  3675. cmTarget::GetImportInfo(const char* config)
  3676. {
  3677. // There is no imported information for non-imported targets.
  3678. if(!this->IsImported())
  3679. {
  3680. return 0;
  3681. }
  3682. // Lookup/compute/cache the import information for this
  3683. // configuration.
  3684. std::string config_upper;
  3685. if(config && *config)
  3686. {
  3687. config_upper = cmSystemTools::UpperCase(config);
  3688. }
  3689. else
  3690. {
  3691. config_upper = "NOCONFIG";
  3692. }
  3693. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  3694. ImportInfoMapType::const_iterator i =
  3695. this->Internal->ImportInfoMap.find(config_upper);
  3696. if(i == this->Internal->ImportInfoMap.end())
  3697. {
  3698. ImportInfo info;
  3699. this->ComputeImportInfo(config_upper, info);
  3700. ImportInfoMapType::value_type entry(config_upper, info);
  3701. i = this->Internal->ImportInfoMap.insert(entry).first;
  3702. }
  3703. // If the location is empty then the target is not available for
  3704. // this configuration.
  3705. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  3706. {
  3707. return 0;
  3708. }
  3709. // Return the import information.
  3710. return &i->second;
  3711. }
  3712. //----------------------------------------------------------------------------
  3713. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  3714. ImportInfo& info)
  3715. {
  3716. // This method finds information about an imported target from its
  3717. // properties. The "IMPORTED_" namespace is reserved for properties
  3718. // defined by the project exporting the target.
  3719. // Initialize members.
  3720. info.NoSOName = false;
  3721. // Track the configuration-specific property suffix.
  3722. std::string suffix = "_";
  3723. suffix += desired_config;
  3724. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  3725. // library or an executable with exports.
  3726. bool allowImp = this->HasImportLibrary();
  3727. // Look for a mapping from the current project's configuration to
  3728. // the imported project's configuration.
  3729. std::vector<std::string> mappedConfigs;
  3730. {
  3731. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  3732. mapProp += desired_config;
  3733. if(const char* mapValue = this->GetProperty(mapProp.c_str()))
  3734. {
  3735. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  3736. }
  3737. }
  3738. // If a mapping was found, check its configurations.
  3739. const char* loc = 0;
  3740. const char* imp = 0;
  3741. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  3742. !loc && !imp && mci != mappedConfigs.end(); ++mci)
  3743. {
  3744. // Look for this configuration.
  3745. std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
  3746. std::string locProp = "IMPORTED_LOCATION_";
  3747. locProp += mcUpper;
  3748. loc = this->GetProperty(locProp.c_str());
  3749. if(allowImp)
  3750. {
  3751. std::string impProp = "IMPORTED_IMPLIB_";
  3752. impProp += mcUpper;
  3753. imp = this->GetProperty(impProp.c_str());
  3754. }
  3755. // If it was found, use it for all properties below.
  3756. if(loc || imp)
  3757. {
  3758. suffix = "_";
  3759. suffix += mcUpper;
  3760. }
  3761. }
  3762. // If we needed to find one of the mapped configurations but did not
  3763. // then the target is not found. The project does not want any
  3764. // other configuration.
  3765. if(!mappedConfigs.empty() && !loc && !imp)
  3766. {
  3767. return;
  3768. }
  3769. // If we have not yet found it then there are no mapped
  3770. // configurations. Look for an exact-match.
  3771. if(!loc && !imp)
  3772. {
  3773. std::string locProp = "IMPORTED_LOCATION";
  3774. locProp += suffix;
  3775. loc = this->GetProperty(locProp.c_str());
  3776. if(allowImp)
  3777. {
  3778. std::string impProp = "IMPORTED_IMPLIB";
  3779. impProp += suffix;
  3780. imp = this->GetProperty(impProp.c_str());
  3781. }
  3782. }
  3783. // If we have not yet found it then there are no mapped
  3784. // configurations and no exact match.
  3785. if(!loc && !imp)
  3786. {
  3787. // The suffix computed above is not useful.
  3788. suffix = "";
  3789. // Look for a configuration-less location. This may be set by
  3790. // manually-written code.
  3791. loc = this->GetProperty("IMPORTED_LOCATION");
  3792. if(allowImp)
  3793. {
  3794. imp = this->GetProperty("IMPORTED_IMPLIB");
  3795. }
  3796. }
  3797. // If we have not yet found it then the project is willing to try
  3798. // any available configuration.
  3799. if(!loc && !imp)
  3800. {
  3801. std::vector<std::string> availableConfigs;
  3802. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  3803. {
  3804. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  3805. }
  3806. for(std::vector<std::string>::const_iterator
  3807. aci = availableConfigs.begin();
  3808. !loc && !imp && aci != availableConfigs.end(); ++aci)
  3809. {
  3810. suffix = "_";
  3811. suffix += cmSystemTools::UpperCase(*aci);
  3812. std::string locProp = "IMPORTED_LOCATION";
  3813. locProp += suffix;
  3814. loc = this->GetProperty(locProp.c_str());
  3815. if(allowImp)
  3816. {
  3817. std::string impProp = "IMPORTED_IMPLIB";
  3818. impProp += suffix;
  3819. imp = this->GetProperty(impProp.c_str());
  3820. }
  3821. }
  3822. }
  3823. // If we have not yet found it then the target is not available.
  3824. if(!loc && !imp)
  3825. {
  3826. return;
  3827. }
  3828. // A provided configuration has been chosen. Load the
  3829. // configuration's properties.
  3830. // Get the location.
  3831. if(loc)
  3832. {
  3833. info.Location = loc;
  3834. }
  3835. else
  3836. {
  3837. std::string impProp = "IMPORTED_LOCATION";
  3838. impProp += suffix;
  3839. if(const char* config_location = this->GetProperty(impProp.c_str()))
  3840. {
  3841. info.Location = config_location;
  3842. }
  3843. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  3844. {
  3845. info.Location = location;
  3846. }
  3847. }
  3848. // Get the soname.
  3849. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3850. {
  3851. std::string soProp = "IMPORTED_SONAME";
  3852. soProp += suffix;
  3853. if(const char* config_soname = this->GetProperty(soProp.c_str()))
  3854. {
  3855. info.SOName = config_soname;
  3856. }
  3857. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  3858. {
  3859. info.SOName = soname;
  3860. }
  3861. }
  3862. // Get the "no-soname" mark.
  3863. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3864. {
  3865. std::string soProp = "IMPORTED_NO_SONAME";
  3866. soProp += suffix;
  3867. if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
  3868. {
  3869. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  3870. }
  3871. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  3872. {
  3873. info.NoSOName = cmSystemTools::IsOn(no_soname);
  3874. }
  3875. }
  3876. // Get the import library.
  3877. if(imp)
  3878. {
  3879. info.ImportLibrary = imp;
  3880. }
  3881. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3882. this->IsExecutableWithExports())
  3883. {
  3884. std::string impProp = "IMPORTED_IMPLIB";
  3885. impProp += suffix;
  3886. if(const char* config_implib = this->GetProperty(impProp.c_str()))
  3887. {
  3888. info.ImportLibrary = config_implib;
  3889. }
  3890. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  3891. {
  3892. info.ImportLibrary = implib;
  3893. }
  3894. }
  3895. // Get the link interface.
  3896. {
  3897. std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  3898. linkProp += suffix;
  3899. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  3900. {
  3901. cmSystemTools::ExpandListArgument(config_libs,
  3902. info.LinkInterface.Libraries);
  3903. }
  3904. else if(const char* libs =
  3905. this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
  3906. {
  3907. cmSystemTools::ExpandListArgument(libs,
  3908. info.LinkInterface.Libraries);
  3909. }
  3910. }
  3911. // Get the link dependencies.
  3912. {
  3913. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  3914. linkProp += suffix;
  3915. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  3916. {
  3917. cmSystemTools::ExpandListArgument(config_libs,
  3918. info.LinkInterface.SharedDeps);
  3919. }
  3920. else if(const char* libs =
  3921. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  3922. {
  3923. cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
  3924. }
  3925. }
  3926. // Get the link languages.
  3927. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3928. {
  3929. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  3930. linkProp += suffix;
  3931. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  3932. {
  3933. cmSystemTools::ExpandListArgument(config_libs,
  3934. info.LinkInterface.Languages);
  3935. }
  3936. else if(const char* libs =
  3937. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  3938. {
  3939. cmSystemTools::ExpandListArgument(libs,
  3940. info.LinkInterface.Languages);
  3941. }
  3942. }
  3943. // Get the cyclic repetition count.
  3944. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3945. {
  3946. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  3947. linkProp += suffix;
  3948. if(const char* config_reps = this->GetProperty(linkProp.c_str()))
  3949. {
  3950. sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
  3951. }
  3952. else if(const char* reps =
  3953. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  3954. {
  3955. sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
  3956. }
  3957. }
  3958. }
  3959. //----------------------------------------------------------------------------
  3960. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config)
  3961. {
  3962. // Imported targets have their own link interface.
  3963. if(this->IsImported())
  3964. {
  3965. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3966. {
  3967. return &info->LinkInterface;
  3968. }
  3969. return 0;
  3970. }
  3971. // Link interfaces are not supported for executables that do not
  3972. // export symbols.
  3973. if(this->GetType() == cmTarget::EXECUTABLE &&
  3974. !this->IsExecutableWithExports())
  3975. {
  3976. return 0;
  3977. }
  3978. // Lookup any existing link interface for this configuration.
  3979. std::string key = cmSystemTools::UpperCase(config? config : "");
  3980. cmTargetInternals::LinkInterfaceMapType::iterator
  3981. i = this->Internal->LinkInterfaceMap.find(key);
  3982. if(i == this->Internal->LinkInterfaceMap.end())
  3983. {
  3984. // Compute the link interface for this configuration.
  3985. cmTargetInternals::OptionalLinkInterface iface;
  3986. iface.Exists = this->ComputeLinkInterface(config, iface);
  3987. // Store the information for this configuration.
  3988. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  3989. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  3990. }
  3991. return i->second.Exists? &i->second : 0;
  3992. }
  3993. //----------------------------------------------------------------------------
  3994. bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface)
  3995. {
  3996. // Construct the property name suffix for this configuration.
  3997. std::string suffix = "_";
  3998. if(config && *config)
  3999. {
  4000. suffix += cmSystemTools::UpperCase(config);
  4001. }
  4002. else
  4003. {
  4004. suffix += "NOCONFIG";
  4005. }
  4006. // An explicit list of interface libraries may be set for shared
  4007. // libraries and executables that export symbols.
  4008. const char* explicitLibraries = 0;
  4009. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4010. this->IsExecutableWithExports())
  4011. {
  4012. // Lookup the per-configuration property.
  4013. std::string propName = "LINK_INTERFACE_LIBRARIES";
  4014. propName += suffix;
  4015. explicitLibraries = this->GetProperty(propName.c_str());
  4016. // If not set, try the generic property.
  4017. if(!explicitLibraries)
  4018. {
  4019. explicitLibraries = this->GetProperty("LINK_INTERFACE_LIBRARIES");
  4020. }
  4021. }
  4022. // There is no implicit link interface for executables or modules
  4023. // so if none was explicitly set then there is no link interface.
  4024. // Note that CMake versions 2.2 and below allowed linking to modules.
  4025. bool canLinkModules = this->Makefile->NeedBackwardsCompatibility(2,2);
  4026. if(!explicitLibraries &&
  4027. (this->GetType() == cmTarget::EXECUTABLE ||
  4028. (this->GetType() == cmTarget::MODULE_LIBRARY && !canLinkModules)))
  4029. {
  4030. return false;
  4031. }
  4032. if(explicitLibraries)
  4033. {
  4034. // The interface libraries have been explicitly set.
  4035. cmSystemTools::ExpandListArgument(explicitLibraries, iface.Libraries);
  4036. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4037. {
  4038. // Shared libraries may have runtime implementation dependencies
  4039. // on other shared libraries that are not in the interface.
  4040. std::set<cmStdString> emitted;
  4041. for(std::vector<std::string>::const_iterator
  4042. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  4043. {
  4044. emitted.insert(*li);
  4045. }
  4046. LinkImplementation const* impl = this->GetLinkImplementation(config);
  4047. for(std::vector<std::string>::const_iterator
  4048. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  4049. {
  4050. if(emitted.insert(*li).second)
  4051. {
  4052. if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
  4053. {
  4054. // This is a runtime dependency on another shared library.
  4055. if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
  4056. {
  4057. iface.SharedDeps.push_back(*li);
  4058. }
  4059. }
  4060. else
  4061. {
  4062. // TODO: Recognize shared library file names. Perhaps this
  4063. // should be moved to cmComputeLinkInformation, but that creates
  4064. // a chicken-and-egg problem since this list is needed for its
  4065. // construction.
  4066. }
  4067. }
  4068. }
  4069. }
  4070. }
  4071. else
  4072. {
  4073. // The link implementation is the default link interface.
  4074. LinkImplementation const* impl = this->GetLinkImplementation(config);
  4075. iface.Libraries = impl->Libraries;
  4076. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  4077. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4078. {
  4079. // Targets using this archive need its language runtime libraries.
  4080. iface.Languages = impl->Languages;
  4081. }
  4082. }
  4083. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4084. {
  4085. // How many repetitions are needed if this library has cyclic
  4086. // dependencies?
  4087. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4088. propName += suffix;
  4089. if(const char* config_reps = this->GetProperty(propName.c_str()))
  4090. {
  4091. sscanf(config_reps, "%u", &iface.Multiplicity);
  4092. }
  4093. else if(const char* reps =
  4094. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  4095. {
  4096. sscanf(reps, "%u", &iface.Multiplicity);
  4097. }
  4098. }
  4099. return true;
  4100. }
  4101. //----------------------------------------------------------------------------
  4102. cmTarget::LinkImplementation const*
  4103. cmTarget::GetLinkImplementation(const char* config)
  4104. {
  4105. // There is no link implementation for imported targets.
  4106. if(this->IsImported())
  4107. {
  4108. return 0;
  4109. }
  4110. // Lookup any existing link implementation for this configuration.
  4111. std::string key = cmSystemTools::UpperCase(config? config : "");
  4112. cmTargetInternals::LinkImplMapType::iterator
  4113. i = this->Internal->LinkImplMap.find(key);
  4114. if(i == this->Internal->LinkImplMap.end())
  4115. {
  4116. // Compute the link implementation for this configuration.
  4117. LinkImplementation impl;
  4118. this->ComputeLinkImplementation(config, impl);
  4119. // Store the information for this configuration.
  4120. cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
  4121. i = this->Internal->LinkImplMap.insert(entry).first;
  4122. }
  4123. return &i->second;
  4124. }
  4125. //----------------------------------------------------------------------------
  4126. void cmTarget::ComputeLinkImplementation(const char* config,
  4127. LinkImplementation& impl)
  4128. {
  4129. // Compute which library configuration to link.
  4130. cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  4131. // Collect libraries directly linked in this configuration.
  4132. LinkLibraryVectorType const& llibs = this->GetOriginalLinkLibraries();
  4133. for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
  4134. li != llibs.end(); ++li)
  4135. {
  4136. // Skip entries that resolve to the target itself or are empty.
  4137. std::string item = this->CheckCMP0004(li->first);
  4138. if(item == this->GetName() || item.empty())
  4139. {
  4140. continue;
  4141. }
  4142. if(li->second == cmTarget::GENERAL || li->second == linkType)
  4143. {
  4144. // The entry is meant for this configuration.
  4145. impl.Libraries.push_back(item);
  4146. }
  4147. else
  4148. {
  4149. // Support OLD behavior for CMP0003.
  4150. impl.WrongConfigLibraries.push_back(item);
  4151. }
  4152. }
  4153. // This target needs runtime libraries for its source languages.
  4154. std::set<cmStdString> languages;
  4155. this->GetLanguages(languages);
  4156. for(std::set<cmStdString>::iterator li = languages.begin();
  4157. li != languages.end(); ++li)
  4158. {
  4159. impl.Languages.push_back(*li);
  4160. }
  4161. }
  4162. //----------------------------------------------------------------------------
  4163. std::string cmTarget::CheckCMP0004(std::string const& item)
  4164. {
  4165. // Strip whitespace off the library names because we used to do this
  4166. // in case variables were expanded at generate time. We no longer
  4167. // do the expansion but users link to libraries like " ${VAR} ".
  4168. std::string lib = item;
  4169. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  4170. if(pos != lib.npos)
  4171. {
  4172. lib = lib.substr(pos, lib.npos);
  4173. }
  4174. pos = lib.find_last_not_of(" \t\r\n");
  4175. if(pos != lib.npos)
  4176. {
  4177. lib = lib.substr(0, pos+1);
  4178. }
  4179. if(lib != item)
  4180. {
  4181. cmake* cm = this->Makefile->GetCMakeInstance();
  4182. switch(this->PolicyStatusCMP0004)
  4183. {
  4184. case cmPolicies::WARN:
  4185. {
  4186. cmOStringStream w;
  4187. w << (this->Makefile->GetPolicies()
  4188. ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
  4189. << "Target \"" << this->GetName() << "\" links to item \""
  4190. << item << "\" which has leading or trailing whitespace.";
  4191. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  4192. this->GetBacktrace());
  4193. }
  4194. case cmPolicies::OLD:
  4195. break;
  4196. case cmPolicies::NEW:
  4197. {
  4198. cmOStringStream e;
  4199. e << "Target \"" << this->GetName() << "\" links to item \""
  4200. << item << "\" which has leading or trailing whitespace. "
  4201. << "This is now an error according to policy CMP0004.";
  4202. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4203. }
  4204. break;
  4205. case cmPolicies::REQUIRED_IF_USED:
  4206. case cmPolicies::REQUIRED_ALWAYS:
  4207. {
  4208. cmOStringStream e;
  4209. e << (this->Makefile->GetPolicies()
  4210. ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
  4211. << "Target \"" << this->GetName() << "\" links to item \""
  4212. << item << "\" which has leading or trailing whitespace.";
  4213. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4214. }
  4215. break;
  4216. }
  4217. }
  4218. return lib;
  4219. }
  4220. //----------------------------------------------------------------------------
  4221. cmComputeLinkInformation*
  4222. cmTarget::GetLinkInformation(const char* config)
  4223. {
  4224. // Lookup any existing information for this configuration.
  4225. std::map<cmStdString, cmComputeLinkInformation*>::iterator
  4226. i = this->LinkInformation.find(config?config:"");
  4227. if(i == this->LinkInformation.end())
  4228. {
  4229. // Compute information for this configuration.
  4230. cmComputeLinkInformation* info =
  4231. new cmComputeLinkInformation(this, config);
  4232. if(!info || !info->Compute())
  4233. {
  4234. delete info;
  4235. info = 0;
  4236. }
  4237. // Store the information for this configuration.
  4238. std::map<cmStdString, cmComputeLinkInformation*>::value_type
  4239. entry(config?config:"", info);
  4240. i = this->LinkInformation.insert(entry).first;
  4241. }
  4242. return i->second;
  4243. }
  4244. //----------------------------------------------------------------------------
  4245. cmTargetLinkInformationMap
  4246. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  4247. {
  4248. // Ideally cmTarget instances should never be copied. However until
  4249. // we can make a sweep to remove that, this copy constructor avoids
  4250. // allowing the resources (LinkInformation) from getting copied. In
  4251. // the worst case this will lead to extra cmComputeLinkInformation
  4252. // instances. We also enforce in debug mode that the map be emptied
  4253. // when copied.
  4254. static_cast<void>(r);
  4255. assert(r.empty());
  4256. }
  4257. //----------------------------------------------------------------------------
  4258. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  4259. {
  4260. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  4261. {
  4262. delete i->second;
  4263. }
  4264. }
  4265. //----------------------------------------------------------------------------
  4266. cmTargetInternalPointer::cmTargetInternalPointer()
  4267. {
  4268. this->Pointer = new cmTargetInternals;
  4269. }
  4270. //----------------------------------------------------------------------------
  4271. cmTargetInternalPointer
  4272. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  4273. {
  4274. // Ideally cmTarget instances should never be copied. However until
  4275. // we can make a sweep to remove that, this copy constructor avoids
  4276. // allowing the resources (Internals) to be copied.
  4277. this->Pointer = new cmTargetInternals(*r.Pointer);
  4278. }
  4279. //----------------------------------------------------------------------------
  4280. cmTargetInternalPointer::~cmTargetInternalPointer()
  4281. {
  4282. delete this->Pointer;
  4283. }
  4284. //----------------------------------------------------------------------------
  4285. cmTargetInternalPointer&
  4286. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  4287. {
  4288. if(this == &r) { return *this; } // avoid warning on HP about self check
  4289. // Ideally cmTarget instances should never be copied. However until
  4290. // we can make a sweep to remove that, this copy constructor avoids
  4291. // allowing the resources (Internals) to be copied.
  4292. cmTargetInternals* oldPointer = this->Pointer;
  4293. this->Pointer = new cmTargetInternals(*r.Pointer);
  4294. delete oldPointer;
  4295. return *this;
  4296. }