cmTarget.cxx 158 KB

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