cmTarget.cxx 158 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611
  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 explict 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. {
  1997. if (!prop)
  1998. {
  1999. return;
  2000. }
  2001. this->Properties.AppendProperty(prop, value, cmProperty::TARGET);
  2002. this->MaybeInvalidatePropertyCache(prop);
  2003. }
  2004. //----------------------------------------------------------------------------
  2005. void cmTarget::MaybeInvalidatePropertyCache(const char* prop)
  2006. {
  2007. // Wipe wipe out maps caching information affected by this property.
  2008. if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
  2009. {
  2010. this->Internal->ImportInfoMap.clear();
  2011. }
  2012. if(!this->IsImported() && strncmp(prop, "LINK_INTERFACE_", 15) == 0)
  2013. {
  2014. this->ClearLinkMaps();
  2015. }
  2016. }
  2017. //----------------------------------------------------------------------------
  2018. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  2019. const char* prop, const char* value, cmMakefile* context, bool imported
  2020. )
  2021. {
  2022. // Look for link-type keywords in the value.
  2023. static cmsys::RegularExpression
  2024. keys("(^|;)(debug|optimized|general)(;|$)");
  2025. if(!keys.find(value))
  2026. {
  2027. return;
  2028. }
  2029. // Support imported and non-imported versions of the property.
  2030. const char* base = (imported?
  2031. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  2032. "LINK_INTERFACE_LIBRARIES");
  2033. // Report an error.
  2034. cmOStringStream e;
  2035. e << "Property " << prop << " may not contain link-type keyword \""
  2036. << keys.match(2) << "\". "
  2037. << "The " << base << " property has a per-configuration "
  2038. << "version called " << base << "_<CONFIG> which may be "
  2039. << "used to specify per-configuration rules.";
  2040. if(!imported)
  2041. {
  2042. e << " "
  2043. << "Alternatively, an IMPORTED library may be created, configured "
  2044. << "with a per-configuration location, and then named in the "
  2045. << "property value. "
  2046. << "See the add_library command's IMPORTED mode for details."
  2047. << "\n"
  2048. << "If you have a list of libraries that already contains the "
  2049. << "keyword, use the target_link_libraries command with its "
  2050. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  2051. << "The command automatically recognizes link-type keywords and sets "
  2052. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  2053. << "properties accordingly.";
  2054. }
  2055. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2056. }
  2057. //----------------------------------------------------------------------------
  2058. void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
  2059. {
  2060. // Certain properties need checking.
  2061. if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
  2062. {
  2063. if(const char* value = this->GetProperty(prop))
  2064. {
  2065. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  2066. }
  2067. }
  2068. if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
  2069. {
  2070. if(const char* value = this->GetProperty(prop))
  2071. {
  2072. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  2073. }
  2074. }
  2075. }
  2076. //----------------------------------------------------------------------------
  2077. void cmTarget::MarkAsImported()
  2078. {
  2079. this->IsImportedTarget = true;
  2080. }
  2081. //----------------------------------------------------------------------------
  2082. cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
  2083. {
  2084. // There is no output information for imported targets.
  2085. if(this->IsImported())
  2086. {
  2087. return 0;
  2088. }
  2089. // Only libraries and executables have well-defined output files.
  2090. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  2091. this->GetType() != cmTarget::SHARED_LIBRARY &&
  2092. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2093. this->GetType() != cmTarget::EXECUTABLE)
  2094. {
  2095. std::string msg = "cmTarget::GetOutputInfo called for ";
  2096. msg += this->GetName();
  2097. msg += " which has type ";
  2098. msg += cmTarget::TargetTypeNames[this->GetType()];
  2099. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2100. abort();
  2101. return 0;
  2102. }
  2103. // Lookup/compute/cache the output information for this configuration.
  2104. std::string config_upper;
  2105. if(config && *config)
  2106. {
  2107. config_upper = cmSystemTools::UpperCase(config);
  2108. }
  2109. typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
  2110. OutputInfoMapType::const_iterator i =
  2111. this->Internal->OutputInfoMap.find(config_upper);
  2112. if(i == this->Internal->OutputInfoMap.end())
  2113. {
  2114. OutputInfo info;
  2115. this->ComputeOutputDir(config, false, info.OutDir);
  2116. this->ComputeOutputDir(config, true, info.ImpDir);
  2117. OutputInfoMapType::value_type entry(config_upper, info);
  2118. i = this->Internal->OutputInfoMap.insert(entry).first;
  2119. }
  2120. return &i->second;
  2121. }
  2122. //----------------------------------------------------------------------------
  2123. std::string cmTarget::GetDirectory(const char* config, bool implib)
  2124. {
  2125. if (this->IsImported())
  2126. {
  2127. // Return the directory from which the target is imported.
  2128. return
  2129. cmSystemTools::GetFilenamePath(
  2130. this->ImportedGetFullPath(config, implib));
  2131. }
  2132. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2133. {
  2134. // Return the directory in which the target will be built.
  2135. return implib? info->ImpDir : info->OutDir;
  2136. }
  2137. return "";
  2138. }
  2139. //----------------------------------------------------------------------------
  2140. const char* cmTarget::GetLocation(const char* config)
  2141. {
  2142. if (this->IsImported())
  2143. {
  2144. return this->ImportedGetLocation(config);
  2145. }
  2146. else
  2147. {
  2148. return this->NormalGetLocation(config);
  2149. }
  2150. }
  2151. //----------------------------------------------------------------------------
  2152. const char* cmTarget::ImportedGetLocation(const char* config)
  2153. {
  2154. this->Location = this->ImportedGetFullPath(config, false);
  2155. return this->Location.c_str();
  2156. }
  2157. //----------------------------------------------------------------------------
  2158. const char* cmTarget::NormalGetLocation(const char* config)
  2159. {
  2160. // Handle the configuration-specific case first.
  2161. if(config)
  2162. {
  2163. this->Location = this->GetFullPath(config, false);
  2164. return this->Location.c_str();
  2165. }
  2166. // Now handle the deprecated build-time configuration location.
  2167. this->Location = this->GetDirectory();
  2168. if(!this->Location.empty())
  2169. {
  2170. this->Location += "/";
  2171. }
  2172. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  2173. if(cfgid && strcmp(cfgid, ".") != 0)
  2174. {
  2175. this->Location += cfgid;
  2176. this->Location += "/";
  2177. }
  2178. if(this->IsAppBundleOnApple())
  2179. {
  2180. this->Location += this->GetFullName(config, false);
  2181. this->Location += ".app/Contents/MacOS/";
  2182. }
  2183. if(this->IsFrameworkOnApple())
  2184. {
  2185. this->Location += this->GetFullName(config, false);
  2186. this->Location += ".framework/Versions/";
  2187. this->Location += this->GetFrameworkVersion();
  2188. this->Location += "/";
  2189. }
  2190. this->Location += this->GetFullName(config, false);
  2191. return this->Location.c_str();
  2192. }
  2193. //----------------------------------------------------------------------------
  2194. void cmTarget::GetTargetVersion(int& major, int& minor)
  2195. {
  2196. int patch;
  2197. this->GetTargetVersion(false, major, minor, patch);
  2198. }
  2199. //----------------------------------------------------------------------------
  2200. void cmTarget::GetTargetVersion(bool soversion,
  2201. int& major, int& minor, int& patch)
  2202. {
  2203. // Set the default values.
  2204. major = 0;
  2205. minor = 0;
  2206. patch = 0;
  2207. // Look for a VERSION or SOVERSION property.
  2208. const char* prop = soversion? "SOVERSION" : "VERSION";
  2209. if(const char* version = this->GetProperty(prop))
  2210. {
  2211. // Try to parse the version number and store the results that were
  2212. // successfully parsed.
  2213. int parsed_major;
  2214. int parsed_minor;
  2215. int parsed_patch;
  2216. switch(sscanf(version, "%d.%d.%d",
  2217. &parsed_major, &parsed_minor, &parsed_patch))
  2218. {
  2219. case 3: patch = parsed_patch; // no break!
  2220. case 2: minor = parsed_minor; // no break!
  2221. case 1: major = parsed_major; // no break!
  2222. default: break;
  2223. }
  2224. }
  2225. }
  2226. //----------------------------------------------------------------------------
  2227. const char* cmTarget::GetFeature(const char* feature, const char* config)
  2228. {
  2229. if(config && *config)
  2230. {
  2231. std::string featureConfig = feature;
  2232. featureConfig += "_";
  2233. featureConfig += cmSystemTools::UpperCase(config);
  2234. if(const char* value = this->GetProperty(featureConfig.c_str()))
  2235. {
  2236. return value;
  2237. }
  2238. }
  2239. if(const char* value = this->GetProperty(feature))
  2240. {
  2241. return value;
  2242. }
  2243. return this->Makefile->GetFeature(feature, config);
  2244. }
  2245. //----------------------------------------------------------------------------
  2246. const char *cmTarget::GetProperty(const char* prop)
  2247. {
  2248. return this->GetProperty(prop, cmProperty::TARGET);
  2249. }
  2250. //----------------------------------------------------------------------------
  2251. void cmTarget::ComputeObjectFiles()
  2252. {
  2253. if (this->IsImported())
  2254. {
  2255. return;
  2256. }
  2257. #if 0
  2258. std::vector<std::string> dirs;
  2259. this->Makefile->GetLocalGenerator()->
  2260. GetTargetObjectFileDirectories(this,
  2261. dirs);
  2262. std::string objectFiles;
  2263. std::string objExtensionLookup1 = "CMAKE_";
  2264. std::string objExtensionLookup2 = "_OUTPUT_EXTENSION";
  2265. for(std::vector<std::string>::iterator d = dirs.begin();
  2266. d != dirs.end(); ++d)
  2267. {
  2268. for(std::vector<cmSourceFile*>::iterator s = this->SourceFiles.begin();
  2269. s != this->SourceFiles.end(); ++s)
  2270. {
  2271. cmSourceFile* sf = *s;
  2272. if(const char* lang = sf->GetLanguage())
  2273. {
  2274. std::string lookupObj = objExtensionLookup1 + lang;
  2275. lookupObj += objExtensionLookup2;
  2276. const char* obj = this->Makefile->GetDefinition(lookupObj.c_str());
  2277. if(obj)
  2278. {
  2279. if(objectFiles.size())
  2280. {
  2281. objectFiles += ";";
  2282. }
  2283. std::string objFile = *d;
  2284. objFile += "/";
  2285. objFile += this->Makefile->GetLocalGenerator()->
  2286. GetSourceObjectName(*sf);
  2287. objFile += obj;
  2288. objectFiles += objFile;
  2289. }
  2290. }
  2291. }
  2292. }
  2293. this->SetProperty("OBJECT_FILES", objectFiles.c_str());
  2294. #endif
  2295. }
  2296. //----------------------------------------------------------------------------
  2297. const char *cmTarget::GetProperty(const char* prop,
  2298. cmProperty::ScopeType scope)
  2299. {
  2300. if(!prop)
  2301. {
  2302. return 0;
  2303. }
  2304. // Watch for special "computed" properties that are dependent on
  2305. // other properties or variables. Always recompute them.
  2306. if(this->GetType() == cmTarget::EXECUTABLE ||
  2307. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2308. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2309. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2310. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2311. {
  2312. if(strcmp(prop,"LOCATION") == 0)
  2313. {
  2314. // Set the LOCATION property of the target.
  2315. //
  2316. // For an imported target this is the location of an arbitrary
  2317. // available configuration.
  2318. //
  2319. // For a non-imported target this is deprecated because it
  2320. // cannot take into account the per-configuration name of the
  2321. // target because the configuration type may not be known at
  2322. // CMake time.
  2323. this->SetProperty("LOCATION", this->GetLocation(0));
  2324. }
  2325. // Support "LOCATION_<CONFIG>".
  2326. if(strncmp(prop, "LOCATION_", 9) == 0)
  2327. {
  2328. std::string configName = prop+9;
  2329. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  2330. }
  2331. else
  2332. {
  2333. // Support "<CONFIG>_LOCATION" for compatiblity.
  2334. int len = static_cast<int>(strlen(prop));
  2335. if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
  2336. {
  2337. std::string configName(prop, len-9);
  2338. if(configName != "IMPORTED")
  2339. {
  2340. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  2341. }
  2342. }
  2343. }
  2344. }
  2345. if (strcmp(prop,"IMPORTED") == 0)
  2346. {
  2347. return this->IsImported()?"TRUE":"FALSE";
  2348. }
  2349. if(!strcmp(prop,"SOURCES"))
  2350. {
  2351. cmOStringStream ss;
  2352. const char* sep = "";
  2353. for(std::vector<cmSourceFile*>::const_iterator
  2354. i = this->SourceFiles.begin();
  2355. i != this->SourceFiles.end(); ++i)
  2356. {
  2357. // Separate from the previous list entries.
  2358. ss << sep;
  2359. sep = ";";
  2360. // Construct what is known about this source file location.
  2361. cmSourceFileLocation const& location = (*i)->GetLocation();
  2362. std::string sname = location.GetDirectory();
  2363. if(!sname.empty())
  2364. {
  2365. sname += "/";
  2366. }
  2367. sname += location.GetName();
  2368. // Append this list entry.
  2369. ss << sname;
  2370. }
  2371. this->SetProperty("SOURCES", ss.str().c_str());
  2372. }
  2373. // the type property returns what type the target is
  2374. if (!strcmp(prop,"TYPE"))
  2375. {
  2376. switch( this->GetType() )
  2377. {
  2378. case cmTarget::STATIC_LIBRARY:
  2379. return "STATIC_LIBRARY";
  2380. // break; /* unreachable */
  2381. case cmTarget::MODULE_LIBRARY:
  2382. return "MODULE_LIBRARY";
  2383. // break; /* unreachable */
  2384. case cmTarget::SHARED_LIBRARY:
  2385. return "SHARED_LIBRARY";
  2386. // break; /* unreachable */
  2387. case cmTarget::EXECUTABLE:
  2388. return "EXECUTABLE";
  2389. // break; /* unreachable */
  2390. case cmTarget::UTILITY:
  2391. return "UTILITY";
  2392. // break; /* unreachable */
  2393. case cmTarget::GLOBAL_TARGET:
  2394. return "GLOBAL_TARGET";
  2395. // break; /* unreachable */
  2396. case cmTarget::INSTALL_FILES:
  2397. return "INSTALL_FILES";
  2398. // break; /* unreachable */
  2399. case cmTarget::INSTALL_PROGRAMS:
  2400. return "INSTALL_PROGRAMS";
  2401. // break; /* unreachable */
  2402. case cmTarget::INSTALL_DIRECTORY:
  2403. return "INSTALL_DIRECTORY";
  2404. // break; /* unreachable */
  2405. case cmTarget::UNKNOWN_LIBRARY:
  2406. return "UNKNOWN_LIBRARY";
  2407. // break; /* unreachable */
  2408. }
  2409. return 0;
  2410. }
  2411. bool chain = false;
  2412. const char *retVal =
  2413. this->Properties.GetPropertyValue(prop, scope, chain);
  2414. if (chain)
  2415. {
  2416. return this->Makefile->GetProperty(prop,scope);
  2417. }
  2418. return retVal;
  2419. }
  2420. //----------------------------------------------------------------------------
  2421. bool cmTarget::GetPropertyAsBool(const char* prop)
  2422. {
  2423. return cmSystemTools::IsOn(this->GetProperty(prop));
  2424. }
  2425. //----------------------------------------------------------------------------
  2426. class cmTargetCollectLinkLanguages
  2427. {
  2428. public:
  2429. cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
  2430. std::set<cmStdString>& languages):
  2431. Config(config), Languages(languages) { this->Visited.insert(target); }
  2432. void Visit(cmTarget* target)
  2433. {
  2434. if(!target || !this->Visited.insert(target).second)
  2435. {
  2436. return;
  2437. }
  2438. cmTarget::LinkInterface const* iface =
  2439. target->GetLinkInterface(this->Config);
  2440. if(!iface) { return; }
  2441. for(std::vector<std::string>::const_iterator
  2442. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  2443. {
  2444. this->Languages.insert(*li);
  2445. }
  2446. cmMakefile* mf = target->GetMakefile();
  2447. for(std::vector<std::string>::const_iterator
  2448. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  2449. {
  2450. this->Visit(mf->FindTargetToUse(li->c_str()));
  2451. }
  2452. }
  2453. private:
  2454. const char* Config;
  2455. std::set<cmStdString>& Languages;
  2456. std::set<cmTarget*> Visited;
  2457. };
  2458. //----------------------------------------------------------------------------
  2459. const char* cmTarget::GetLinkerLanguage(const char* config)
  2460. {
  2461. const char* lang = this->GetLinkClosure(config)->LinkerLanguage.c_str();
  2462. return *lang? lang : 0;
  2463. }
  2464. //----------------------------------------------------------------------------
  2465. cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config)
  2466. {
  2467. std::string key = cmSystemTools::UpperCase(config? config : "");
  2468. cmTargetInternals::LinkClosureMapType::iterator
  2469. i = this->Internal->LinkClosureMap.find(key);
  2470. if(i == this->Internal->LinkClosureMap.end())
  2471. {
  2472. LinkClosure lc;
  2473. this->ComputeLinkClosure(config, lc);
  2474. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  2475. i = this->Internal->LinkClosureMap.insert(entry).first;
  2476. }
  2477. return &i->second;
  2478. }
  2479. //----------------------------------------------------------------------------
  2480. class cmTargetSelectLinker
  2481. {
  2482. int Preference;
  2483. cmTarget* Target;
  2484. cmMakefile* Makefile;
  2485. cmGlobalGenerator* GG;
  2486. std::set<cmStdString> Preferred;
  2487. public:
  2488. cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
  2489. {
  2490. this->Makefile = this->Target->GetMakefile();
  2491. this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  2492. }
  2493. void Consider(const char* lang)
  2494. {
  2495. int preference = this->GG->GetLinkerPreference(lang);
  2496. if(preference > this->Preference)
  2497. {
  2498. this->Preference = preference;
  2499. this->Preferred.clear();
  2500. }
  2501. if(preference == this->Preference)
  2502. {
  2503. this->Preferred.insert(lang);
  2504. }
  2505. }
  2506. std::string Choose()
  2507. {
  2508. if(this->Preferred.empty())
  2509. {
  2510. return "";
  2511. }
  2512. else if(this->Preferred.size() > 1)
  2513. {
  2514. cmOStringStream e;
  2515. e << "Target " << this->Target->GetName()
  2516. << " contains multiple languages with the highest linker preference"
  2517. << " (" << this->Preference << "):\n";
  2518. for(std::set<cmStdString>::const_iterator
  2519. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  2520. {
  2521. e << " " << *li << "\n";
  2522. }
  2523. e << "Set the LINKER_LANGUAGE property for this target.";
  2524. cmake* cm = this->Makefile->GetCMakeInstance();
  2525. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  2526. this->Target->GetBacktrace());
  2527. }
  2528. return *this->Preferred.begin();
  2529. }
  2530. };
  2531. //----------------------------------------------------------------------------
  2532. void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc)
  2533. {
  2534. // Get languages built in this target.
  2535. std::set<cmStdString> languages;
  2536. LinkImplementation const* impl = this->GetLinkImplementation(config);
  2537. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  2538. li != impl->Languages.end(); ++li)
  2539. {
  2540. languages.insert(*li);
  2541. }
  2542. // Add interface languages from linked targets.
  2543. cmTargetCollectLinkLanguages cll(this, config, languages);
  2544. for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
  2545. li != impl->Libraries.end(); ++li)
  2546. {
  2547. cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
  2548. }
  2549. // Store the transitive closure of languages.
  2550. for(std::set<cmStdString>::const_iterator li = languages.begin();
  2551. li != languages.end(); ++li)
  2552. {
  2553. lc.Languages.push_back(*li);
  2554. }
  2555. // Choose the language whose linker should be used.
  2556. if(this->GetProperty("HAS_CXX"))
  2557. {
  2558. lc.LinkerLanguage = "CXX";
  2559. }
  2560. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  2561. {
  2562. lc.LinkerLanguage = linkerLang;
  2563. }
  2564. else
  2565. {
  2566. // Find the language with the highest preference value.
  2567. cmTargetSelectLinker tsl(this);
  2568. // First select from the languages compiled directly in this target.
  2569. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  2570. li != impl->Languages.end(); ++li)
  2571. {
  2572. tsl.Consider(li->c_str());
  2573. }
  2574. // Now consider languages that propagate from linked targets.
  2575. for(std::set<cmStdString>::const_iterator sit = languages.begin();
  2576. sit != languages.end(); ++sit)
  2577. {
  2578. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  2579. if(this->Makefile->IsOn(propagates.c_str()))
  2580. {
  2581. tsl.Consider(sit->c_str());
  2582. }
  2583. }
  2584. lc.LinkerLanguage = tsl.Choose();
  2585. }
  2586. }
  2587. //----------------------------------------------------------------------------
  2588. const char* cmTarget::GetCreateRuleVariable()
  2589. {
  2590. switch(this->GetType())
  2591. {
  2592. case cmTarget::STATIC_LIBRARY:
  2593. return "_CREATE_STATIC_LIBRARY";
  2594. case cmTarget::SHARED_LIBRARY:
  2595. return "_CREATE_SHARED_LIBRARY";
  2596. case cmTarget::MODULE_LIBRARY:
  2597. return "_CREATE_SHARED_MODULE";
  2598. case cmTarget::EXECUTABLE:
  2599. return "_LINK_EXECUTABLE";
  2600. default:
  2601. break;
  2602. }
  2603. return "";
  2604. }
  2605. //----------------------------------------------------------------------------
  2606. const char* cmTarget::GetSuffixVariableInternal(bool implib)
  2607. {
  2608. switch(this->GetType())
  2609. {
  2610. case cmTarget::STATIC_LIBRARY:
  2611. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  2612. case cmTarget::SHARED_LIBRARY:
  2613. return (implib
  2614. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2615. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  2616. case cmTarget::MODULE_LIBRARY:
  2617. return (implib
  2618. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2619. : "CMAKE_SHARED_MODULE_SUFFIX");
  2620. case cmTarget::EXECUTABLE:
  2621. return (implib
  2622. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2623. : "CMAKE_EXECUTABLE_SUFFIX");
  2624. default:
  2625. break;
  2626. }
  2627. return "";
  2628. }
  2629. //----------------------------------------------------------------------------
  2630. const char* cmTarget::GetPrefixVariableInternal(bool implib)
  2631. {
  2632. switch(this->GetType())
  2633. {
  2634. case cmTarget::STATIC_LIBRARY:
  2635. return "CMAKE_STATIC_LIBRARY_PREFIX";
  2636. case cmTarget::SHARED_LIBRARY:
  2637. return (implib
  2638. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2639. : "CMAKE_SHARED_LIBRARY_PREFIX");
  2640. case cmTarget::MODULE_LIBRARY:
  2641. return (implib
  2642. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2643. : "CMAKE_SHARED_MODULE_PREFIX");
  2644. case cmTarget::EXECUTABLE:
  2645. return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
  2646. default:
  2647. break;
  2648. }
  2649. return "";
  2650. }
  2651. //----------------------------------------------------------------------------
  2652. std::string cmTarget::GetPDBName(const char* config)
  2653. {
  2654. std::string prefix;
  2655. std::string base;
  2656. std::string suffix;
  2657. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2658. return prefix+base+".pdb";
  2659. }
  2660. //----------------------------------------------------------------------------
  2661. std::string cmTarget::GetSOName(const char* config)
  2662. {
  2663. if(this->IsImported())
  2664. {
  2665. // Lookup the imported soname.
  2666. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2667. {
  2668. if(info->NoSOName)
  2669. {
  2670. // The imported library has no builtin soname so the name
  2671. // searched at runtime will be just the filename.
  2672. return cmSystemTools::GetFilenameName(info->Location);
  2673. }
  2674. else
  2675. {
  2676. // Use the soname given if any.
  2677. return info->SOName;
  2678. }
  2679. }
  2680. else
  2681. {
  2682. return "";
  2683. }
  2684. }
  2685. else
  2686. {
  2687. // Compute the soname that will be built.
  2688. std::string name;
  2689. std::string soName;
  2690. std::string realName;
  2691. std::string impName;
  2692. std::string pdbName;
  2693. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2694. return soName;
  2695. }
  2696. }
  2697. //----------------------------------------------------------------------------
  2698. bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
  2699. {
  2700. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  2701. {
  2702. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2703. {
  2704. return info->NoSOName;
  2705. }
  2706. }
  2707. return false;
  2708. }
  2709. //----------------------------------------------------------------------------
  2710. std::string cmTarget::NormalGetRealName(const char* config)
  2711. {
  2712. // This should not be called for imported targets.
  2713. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2714. // enforcement of the limited imported target API.
  2715. if(this->IsImported())
  2716. {
  2717. std::string msg = "NormalGetRealName called on imported target: ";
  2718. msg += this->GetName();
  2719. this->GetMakefile()->
  2720. IssueMessage(cmake::INTERNAL_ERROR,
  2721. msg.c_str());
  2722. }
  2723. if(this->GetType() == cmTarget::EXECUTABLE)
  2724. {
  2725. // Compute the real name that will be built.
  2726. std::string name;
  2727. std::string realName;
  2728. std::string impName;
  2729. std::string pdbName;
  2730. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2731. return realName;
  2732. }
  2733. else
  2734. {
  2735. // Compute the real name that will be built.
  2736. std::string name;
  2737. std::string soName;
  2738. std::string realName;
  2739. std::string impName;
  2740. std::string pdbName;
  2741. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2742. return realName;
  2743. }
  2744. }
  2745. //----------------------------------------------------------------------------
  2746. std::string cmTarget::GetFullName(const char* config, bool implib)
  2747. {
  2748. if(this->IsImported())
  2749. {
  2750. return this->GetFullNameImported(config, implib);
  2751. }
  2752. else
  2753. {
  2754. return this->GetFullNameInternal(config, implib);
  2755. }
  2756. }
  2757. //----------------------------------------------------------------------------
  2758. std::string cmTarget::GetFullNameImported(const char* config, bool implib)
  2759. {
  2760. return cmSystemTools::GetFilenameName(
  2761. this->ImportedGetFullPath(config, implib));
  2762. }
  2763. //----------------------------------------------------------------------------
  2764. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  2765. std::string& suffix, const char* config,
  2766. bool implib)
  2767. {
  2768. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2769. }
  2770. //----------------------------------------------------------------------------
  2771. std::string cmTarget::GetFullPath(const char* config, bool implib,
  2772. bool realname)
  2773. {
  2774. if(this->IsImported())
  2775. {
  2776. return this->ImportedGetFullPath(config, implib);
  2777. }
  2778. else
  2779. {
  2780. return this->NormalGetFullPath(config, implib, realname);
  2781. }
  2782. }
  2783. //----------------------------------------------------------------------------
  2784. std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
  2785. bool realname)
  2786. {
  2787. // Start with the output directory for the target.
  2788. std::string fpath = this->GetDirectory(config, implib);
  2789. fpath += "/";
  2790. if(this->IsAppBundleOnApple())
  2791. {
  2792. fpath += this->GetFullName(config, false);
  2793. fpath += ".app/Contents/MacOS/";
  2794. }
  2795. if(this->IsFrameworkOnApple())
  2796. {
  2797. fpath += this->GetFullName(config, false);
  2798. fpath += ".framework/Versions/";
  2799. fpath += this->GetFrameworkVersion();
  2800. fpath += "/";
  2801. }
  2802. // Add the full name of the target.
  2803. if(implib)
  2804. {
  2805. fpath += this->GetFullName(config, true);
  2806. }
  2807. else if(realname)
  2808. {
  2809. fpath += this->NormalGetRealName(config);
  2810. }
  2811. else
  2812. {
  2813. fpath += this->GetFullName(config, false);
  2814. }
  2815. return fpath;
  2816. }
  2817. //----------------------------------------------------------------------------
  2818. std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
  2819. {
  2820. std::string result;
  2821. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2822. {
  2823. result = implib? info->ImportLibrary : info->Location;
  2824. }
  2825. if(result.empty())
  2826. {
  2827. result = this->GetName();
  2828. result += "-NOTFOUND";
  2829. }
  2830. return result;
  2831. }
  2832. //----------------------------------------------------------------------------
  2833. std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
  2834. {
  2835. std::string prefix;
  2836. std::string base;
  2837. std::string suffix;
  2838. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2839. return prefix+base+suffix;
  2840. }
  2841. //----------------------------------------------------------------------------
  2842. void cmTarget::GetFullNameInternal(const char* config,
  2843. bool implib,
  2844. std::string& outPrefix,
  2845. std::string& outBase,
  2846. std::string& outSuffix)
  2847. {
  2848. // Use just the target name for non-main target types.
  2849. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  2850. this->GetType() != cmTarget::SHARED_LIBRARY &&
  2851. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2852. this->GetType() != cmTarget::EXECUTABLE)
  2853. {
  2854. outPrefix = "";
  2855. outBase = this->GetName();
  2856. outSuffix = "";
  2857. return;
  2858. }
  2859. // Return an empty name for the import library if this platform
  2860. // does not support import libraries.
  2861. if(implib &&
  2862. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  2863. {
  2864. outPrefix = "";
  2865. outBase = "";
  2866. outSuffix = "";
  2867. return;
  2868. }
  2869. // The implib option is only allowed for shared libraries, module
  2870. // libraries, and executables.
  2871. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  2872. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2873. this->GetType() != cmTarget::EXECUTABLE)
  2874. {
  2875. implib = false;
  2876. }
  2877. // Compute the full name for main target types.
  2878. const char* targetPrefix = (implib
  2879. ? this->GetProperty("IMPORT_PREFIX")
  2880. : this->GetProperty("PREFIX"));
  2881. const char* targetSuffix = (implib
  2882. ? this->GetProperty("IMPORT_SUFFIX")
  2883. : this->GetProperty("SUFFIX"));
  2884. const char* configPostfix = 0;
  2885. if(config && *config)
  2886. {
  2887. std::string configProp = cmSystemTools::UpperCase(config);
  2888. configProp += "_POSTFIX";
  2889. configPostfix = this->GetProperty(configProp.c_str());
  2890. // Mac application bundles and frameworks have no postfix.
  2891. if(configPostfix &&
  2892. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  2893. {
  2894. configPostfix = 0;
  2895. }
  2896. }
  2897. const char* prefixVar = this->GetPrefixVariableInternal(implib);
  2898. const char* suffixVar = this->GetSuffixVariableInternal(implib);
  2899. // Check for language-specific default prefix and suffix.
  2900. if(const char* ll = this->GetLinkerLanguage(config))
  2901. {
  2902. if(!targetSuffix && suffixVar && *suffixVar)
  2903. {
  2904. std::string langSuff = suffixVar + std::string("_") + ll;
  2905. targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
  2906. }
  2907. if(!targetPrefix && prefixVar && *prefixVar)
  2908. {
  2909. std::string langPrefix = prefixVar + std::string("_") + ll;
  2910. targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
  2911. }
  2912. }
  2913. // if there is no prefix on the target use the cmake definition
  2914. if(!targetPrefix && prefixVar)
  2915. {
  2916. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2917. }
  2918. // if there is no suffix on the target use the cmake definition
  2919. if(!targetSuffix && suffixVar)
  2920. {
  2921. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2922. }
  2923. // frameworks do not have a prefix or a suffix
  2924. if(this->IsFrameworkOnApple())
  2925. {
  2926. targetPrefix = 0;
  2927. targetSuffix = 0;
  2928. }
  2929. // Begin the final name with the prefix.
  2930. outPrefix = targetPrefix?targetPrefix:"";
  2931. // Append the target name or property-specified name.
  2932. outBase += this->GetOutputName(config, implib);
  2933. // Append the per-configuration postfix.
  2934. outBase += configPostfix?configPostfix:"";
  2935. // Name shared libraries with their version number on some platforms.
  2936. if(const char* soversion = this->GetProperty("SOVERSION"))
  2937. {
  2938. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  2939. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  2940. {
  2941. outBase += "-";
  2942. outBase += soversion;
  2943. }
  2944. }
  2945. // Append the suffix.
  2946. outSuffix = targetSuffix?targetSuffix:"";
  2947. }
  2948. //----------------------------------------------------------------------------
  2949. void cmTarget::GetLibraryNames(std::string& name,
  2950. std::string& soName,
  2951. std::string& realName,
  2952. std::string& impName,
  2953. std::string& pdbName,
  2954. const char* config)
  2955. {
  2956. // This should not be called for imported targets.
  2957. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2958. // enforcement of the limited imported target API.
  2959. if(this->IsImported())
  2960. {
  2961. std::string msg = "GetLibraryNames called on imported target: ";
  2962. msg += this->GetName();
  2963. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  2964. msg.c_str());
  2965. return;
  2966. }
  2967. // Construct the name of the soname flag variable for this language.
  2968. const char* ll = this->GetLinkerLanguage(config);
  2969. std::string sonameFlag = "CMAKE_SHARED_LIBRARY_SONAME";
  2970. if(ll)
  2971. {
  2972. sonameFlag += "_";
  2973. sonameFlag += ll;
  2974. }
  2975. sonameFlag += "_FLAG";
  2976. // Check for library version properties.
  2977. const char* version = this->GetProperty("VERSION");
  2978. const char* soversion = this->GetProperty("SOVERSION");
  2979. if((this->GetType() != cmTarget::SHARED_LIBRARY &&
  2980. this->GetType() != cmTarget::MODULE_LIBRARY) ||
  2981. !this->Makefile->GetDefinition(sonameFlag.c_str()) ||
  2982. this->IsFrameworkOnApple())
  2983. {
  2984. // Versioning is supported only for shared libraries and modules,
  2985. // and then only when the platform supports an soname flag.
  2986. version = 0;
  2987. soversion = 0;
  2988. }
  2989. if(version && !soversion)
  2990. {
  2991. // The soversion must be set if the library version is set. Use
  2992. // the library version as the soversion.
  2993. soversion = version;
  2994. }
  2995. bool isApple = this->Makefile->IsOn("APPLE");
  2996. // Get the components of the library name.
  2997. std::string prefix;
  2998. std::string base;
  2999. std::string suffix;
  3000. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3001. // The library name.
  3002. name = prefix+base+suffix;
  3003. // The library's soname.
  3004. if(isApple)
  3005. {
  3006. soName = prefix+base;
  3007. }
  3008. else
  3009. {
  3010. soName = name;
  3011. }
  3012. if(soversion)
  3013. {
  3014. soName += ".";
  3015. soName += soversion;
  3016. }
  3017. if(isApple)
  3018. {
  3019. soName += suffix;
  3020. }
  3021. // The library's real name on disk.
  3022. if(isApple)
  3023. {
  3024. realName = prefix+base;
  3025. }
  3026. else
  3027. {
  3028. realName = name;
  3029. }
  3030. if(version)
  3031. {
  3032. realName += ".";
  3033. realName += version;
  3034. }
  3035. else if(soversion)
  3036. {
  3037. realName += ".";
  3038. realName += soversion;
  3039. }
  3040. if(isApple)
  3041. {
  3042. realName += suffix;
  3043. }
  3044. // The import library name.
  3045. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3046. this->GetType() == cmTarget::MODULE_LIBRARY)
  3047. {
  3048. impName = this->GetFullNameInternal(config, true);
  3049. }
  3050. else
  3051. {
  3052. impName = "";
  3053. }
  3054. // The program database file name.
  3055. pdbName = prefix+base+".pdb";
  3056. }
  3057. //----------------------------------------------------------------------------
  3058. void cmTarget::GetExecutableNames(std::string& name,
  3059. std::string& realName,
  3060. std::string& impName,
  3061. std::string& pdbName,
  3062. const char* config)
  3063. {
  3064. // This should not be called for imported targets.
  3065. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3066. // enforcement of the limited imported target API.
  3067. if(this->IsImported())
  3068. {
  3069. std::string msg =
  3070. "GetExecutableNames called on imported target: ";
  3071. msg += this->GetName();
  3072. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
  3073. }
  3074. // This versioning is supported only for executables and then only
  3075. // when the platform supports symbolic links.
  3076. #if defined(_WIN32) && !defined(__CYGWIN__)
  3077. const char* version = 0;
  3078. #else
  3079. // Check for executable version properties.
  3080. const char* version = this->GetProperty("VERSION");
  3081. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3082. {
  3083. version = 0;
  3084. }
  3085. #endif
  3086. // Get the components of the executable name.
  3087. std::string prefix;
  3088. std::string base;
  3089. std::string suffix;
  3090. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3091. // The executable name.
  3092. name = prefix+base+suffix;
  3093. // The executable's real name on disk.
  3094. #if defined(__CYGWIN__)
  3095. realName = prefix+base;
  3096. #else
  3097. realName = name;
  3098. #endif
  3099. if(version)
  3100. {
  3101. realName += "-";
  3102. realName += version;
  3103. }
  3104. #if defined(__CYGWIN__)
  3105. realName += suffix;
  3106. #endif
  3107. // The import library name.
  3108. impName = this->GetFullNameInternal(config, true);
  3109. // The program database file name.
  3110. pdbName = prefix+base+".pdb";
  3111. }
  3112. //----------------------------------------------------------------------------
  3113. void cmTarget::GenerateTargetManifest(const char* config)
  3114. {
  3115. cmMakefile* mf = this->Makefile;
  3116. cmLocalGenerator* lg = mf->GetLocalGenerator();
  3117. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  3118. // Get the names.
  3119. std::string name;
  3120. std::string soName;
  3121. std::string realName;
  3122. std::string impName;
  3123. std::string pdbName;
  3124. if(this->GetType() == cmTarget::EXECUTABLE)
  3125. {
  3126. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3127. }
  3128. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3129. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3130. this->GetType() == cmTarget::MODULE_LIBRARY)
  3131. {
  3132. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3133. }
  3134. else
  3135. {
  3136. return;
  3137. }
  3138. // Get the directory.
  3139. std::string dir = this->GetDirectory(config, false);
  3140. // Add each name.
  3141. std::string f;
  3142. if(!name.empty())
  3143. {
  3144. f = dir;
  3145. f += "/";
  3146. f += name;
  3147. gg->AddToManifest(config? config:"", f);
  3148. }
  3149. if(!soName.empty())
  3150. {
  3151. f = dir;
  3152. f += "/";
  3153. f += soName;
  3154. gg->AddToManifest(config? config:"", f);
  3155. }
  3156. if(!realName.empty())
  3157. {
  3158. f = dir;
  3159. f += "/";
  3160. f += realName;
  3161. gg->AddToManifest(config? config:"", f);
  3162. }
  3163. if(!pdbName.empty())
  3164. {
  3165. f = dir;
  3166. f += "/";
  3167. f += pdbName;
  3168. gg->AddToManifest(config? config:"", f);
  3169. }
  3170. if(!impName.empty())
  3171. {
  3172. f = this->GetDirectory(config, true);
  3173. f += "/";
  3174. f += impName;
  3175. gg->AddToManifest(config? config:"", f);
  3176. }
  3177. }
  3178. //----------------------------------------------------------------------------
  3179. void cmTarget::SetPropertyDefault(const char* property,
  3180. const char* default_value)
  3181. {
  3182. // Compute the name of the variable holding the default value.
  3183. std::string var = "CMAKE_";
  3184. var += property;
  3185. if(const char* value = this->Makefile->GetDefinition(var.c_str()))
  3186. {
  3187. this->SetProperty(property, value);
  3188. }
  3189. else if(default_value)
  3190. {
  3191. this->SetProperty(property, default_value);
  3192. }
  3193. }
  3194. //----------------------------------------------------------------------------
  3195. bool cmTarget::HaveBuildTreeRPATH()
  3196. {
  3197. return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
  3198. !this->LinkLibraries.empty());
  3199. }
  3200. //----------------------------------------------------------------------------
  3201. bool cmTarget::HaveInstallTreeRPATH()
  3202. {
  3203. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3204. return install_rpath && *install_rpath;
  3205. }
  3206. //----------------------------------------------------------------------------
  3207. bool cmTarget::NeedRelinkBeforeInstall(const char* config)
  3208. {
  3209. // Only executables and shared libraries can have an rpath and may
  3210. // need relinking.
  3211. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  3212. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  3213. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  3214. {
  3215. return false;
  3216. }
  3217. // If there is no install location this target will not be installed
  3218. // and therefore does not need relinking.
  3219. if(!this->GetHaveInstallRule())
  3220. {
  3221. return false;
  3222. }
  3223. // If skipping all rpaths completely then no relinking is needed.
  3224. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3225. {
  3226. return false;
  3227. }
  3228. // If building with the install-tree rpath no relinking is needed.
  3229. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3230. {
  3231. return false;
  3232. }
  3233. // If chrpath is going to be used no relinking is needed.
  3234. if(this->IsChrpathUsed(config))
  3235. {
  3236. return false;
  3237. }
  3238. // Check for rpath support on this platform.
  3239. if(const char* ll = this->GetLinkerLanguage(config))
  3240. {
  3241. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3242. flagVar += ll;
  3243. flagVar += "_FLAG";
  3244. if(!this->Makefile->IsSet(flagVar.c_str()))
  3245. {
  3246. // There is no rpath support on this platform so nothing needs
  3247. // relinking.
  3248. return false;
  3249. }
  3250. }
  3251. else
  3252. {
  3253. // No linker language is known. This error will be reported by
  3254. // other code.
  3255. return false;
  3256. }
  3257. // If either a build or install tree rpath is set then the rpath
  3258. // will likely change between the build tree and install tree and
  3259. // this target must be relinked.
  3260. return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
  3261. }
  3262. //----------------------------------------------------------------------------
  3263. std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
  3264. bool for_xcode)
  3265. {
  3266. // If building directly for installation then the build tree install_name
  3267. // is the same as the install tree.
  3268. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3269. {
  3270. return GetInstallNameDirForInstallTree(config, for_xcode);
  3271. }
  3272. // Use the build tree directory for the target.
  3273. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  3274. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3275. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3276. {
  3277. std::string dir = this->GetDirectory(config);
  3278. dir += "/";
  3279. if(this->IsFrameworkOnApple() && !for_xcode)
  3280. {
  3281. dir += this->GetFullName(config, false);
  3282. dir += ".framework/Versions/";
  3283. dir += this->GetFrameworkVersion();
  3284. dir += "/";
  3285. }
  3286. return dir;
  3287. }
  3288. else
  3289. {
  3290. return "";
  3291. }
  3292. }
  3293. //----------------------------------------------------------------------------
  3294. std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
  3295. bool for_xcode)
  3296. {
  3297. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  3298. {
  3299. std::string dir;
  3300. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3301. {
  3302. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  3303. if(install_name_dir && *install_name_dir)
  3304. {
  3305. dir = install_name_dir;
  3306. dir += "/";
  3307. }
  3308. }
  3309. if(this->IsFrameworkOnApple() && !for_xcode)
  3310. {
  3311. dir += this->GetFullName(config, false);
  3312. dir += ".framework/Versions/";
  3313. dir += this->GetFrameworkVersion();
  3314. dir += "/";
  3315. }
  3316. return dir;
  3317. }
  3318. else
  3319. {
  3320. return "";
  3321. }
  3322. }
  3323. //----------------------------------------------------------------------------
  3324. const char* cmTarget::GetOutputTargetType(bool implib)
  3325. {
  3326. switch(this->GetType())
  3327. {
  3328. case cmTarget::SHARED_LIBRARY:
  3329. if(this->DLLPlatform)
  3330. {
  3331. if(implib)
  3332. {
  3333. // A DLL import library is treated as an archive target.
  3334. return "ARCHIVE";
  3335. }
  3336. else
  3337. {
  3338. // A DLL shared library is treated as a runtime target.
  3339. return "RUNTIME";
  3340. }
  3341. }
  3342. else
  3343. {
  3344. // For non-DLL platforms shared libraries are treated as
  3345. // library targets.
  3346. return "LIBRARY";
  3347. }
  3348. case cmTarget::STATIC_LIBRARY:
  3349. // Static libraries are always treated as archive targets.
  3350. return "ARCHIVE";
  3351. case cmTarget::MODULE_LIBRARY:
  3352. if(implib)
  3353. {
  3354. // Module libraries are always treated as library targets.
  3355. return "ARCHIVE";
  3356. }
  3357. else
  3358. {
  3359. // Module import libraries are treated as archive targets.
  3360. return "LIBRARY";
  3361. }
  3362. case cmTarget::EXECUTABLE:
  3363. if(implib)
  3364. {
  3365. // Executable import libraries are treated as archive targets.
  3366. return "ARCHIVE";
  3367. }
  3368. else
  3369. {
  3370. // Executables are always treated as runtime targets.
  3371. return "RUNTIME";
  3372. }
  3373. default:
  3374. break;
  3375. }
  3376. return "";
  3377. }
  3378. //----------------------------------------------------------------------------
  3379. void cmTarget::ComputeOutputDir(const char* config,
  3380. bool implib, std::string& out)
  3381. {
  3382. // Look for a target property defining the target output directory
  3383. // based on the target type.
  3384. std::string targetTypeName = this->GetOutputTargetType(implib);
  3385. const char* propertyName = 0;
  3386. std::string propertyNameStr = targetTypeName;
  3387. if(!propertyNameStr.empty())
  3388. {
  3389. propertyNameStr += "_OUTPUT_DIRECTORY";
  3390. propertyName = propertyNameStr.c_str();
  3391. }
  3392. // Check for a per-configuration output directory target property.
  3393. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3394. const char* configProp = 0;
  3395. std::string configPropStr = targetTypeName;
  3396. if(!configPropStr.empty())
  3397. {
  3398. configPropStr += "_OUTPUT_DIRECTORY_";
  3399. configPropStr += configUpper;
  3400. configProp = configPropStr.c_str();
  3401. }
  3402. // Select an output directory.
  3403. if(const char* config_outdir = this->GetProperty(configProp))
  3404. {
  3405. // Use the user-specified per-configuration output directory.
  3406. out = config_outdir;
  3407. // Skip per-configuration subdirectory.
  3408. config = 0;
  3409. }
  3410. else if(const char* outdir = this->GetProperty(propertyName))
  3411. {
  3412. // Use the user-specified output directory.
  3413. out = outdir;
  3414. }
  3415. else if(this->GetType() == cmTarget::EXECUTABLE)
  3416. {
  3417. // Lookup the output path for executables.
  3418. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  3419. }
  3420. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3421. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3422. this->GetType() == cmTarget::MODULE_LIBRARY)
  3423. {
  3424. // Lookup the output path for libraries.
  3425. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  3426. }
  3427. if(out.empty())
  3428. {
  3429. // Default to the current output directory.
  3430. out = ".";
  3431. }
  3432. // Convert the output path to a full path in case it is
  3433. // specified as a relative path. Treat a relative path as
  3434. // relative to the current output directory for this makefile.
  3435. out = (cmSystemTools::CollapseFullPath
  3436. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  3437. // The generator may add the configuration's subdirectory.
  3438. if(config && *config)
  3439. {
  3440. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3441. AppendDirectoryForConfig("/", config, "", out);
  3442. }
  3443. }
  3444. //----------------------------------------------------------------------------
  3445. std::string cmTarget::GetOutputName(const char* config, bool implib)
  3446. {
  3447. std::vector<std::string> props;
  3448. std::string type = this->GetOutputTargetType(implib);
  3449. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3450. if(!type.empty() && !configUpper.empty())
  3451. {
  3452. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  3453. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  3454. }
  3455. if(!type.empty())
  3456. {
  3457. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  3458. props.push_back(type + "_OUTPUT_NAME");
  3459. }
  3460. if(!configUpper.empty())
  3461. {
  3462. // OUTPUT_NAME_<CONFIG>
  3463. props.push_back("OUTPUT_NAME_" + configUpper);
  3464. // <CONFIG>_OUTPUT_NAME
  3465. props.push_back(configUpper + "_OUTPUT_NAME");
  3466. }
  3467. // OUTPUT_NAME
  3468. props.push_back("OUTPUT_NAME");
  3469. for(std::vector<std::string>::const_iterator i = props.begin();
  3470. i != props.end(); ++i)
  3471. {
  3472. if(const char* outName = this->GetProperty(i->c_str()))
  3473. {
  3474. return outName;
  3475. }
  3476. }
  3477. return this->GetName();
  3478. }
  3479. //----------------------------------------------------------------------------
  3480. std::string cmTarget::GetFrameworkVersion()
  3481. {
  3482. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  3483. {
  3484. return fversion;
  3485. }
  3486. else if(const char* tversion = this->GetProperty("VERSION"))
  3487. {
  3488. return tversion;
  3489. }
  3490. else
  3491. {
  3492. return "A";
  3493. }
  3494. }
  3495. //----------------------------------------------------------------------------
  3496. const char* cmTarget::GetExportMacro()
  3497. {
  3498. // Define the symbol for targets that export symbols.
  3499. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3500. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3501. this->IsExecutableWithExports())
  3502. {
  3503. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  3504. {
  3505. this->ExportMacro = custom_export_name;
  3506. }
  3507. else
  3508. {
  3509. std::string in = this->GetName();
  3510. in += "_EXPORTS";
  3511. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  3512. }
  3513. return this->ExportMacro.c_str();
  3514. }
  3515. else
  3516. {
  3517. return 0;
  3518. }
  3519. }
  3520. //----------------------------------------------------------------------------
  3521. void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
  3522. {
  3523. for(std::vector<cmSourceFile*>::const_iterator
  3524. i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  3525. {
  3526. if(const char* lang = (*i)->GetLanguage())
  3527. {
  3528. languages.insert(lang);
  3529. }
  3530. }
  3531. }
  3532. //----------------------------------------------------------------------------
  3533. void cmTarget::GetAppleArchs(const char* config,
  3534. std::vector<std::string>& archVec)
  3535. {
  3536. const char* archs = 0;
  3537. if(config && *config)
  3538. {
  3539. std::string defVarName = "OSX_ARCHITECTURES_";
  3540. defVarName += cmSystemTools::UpperCase(config);
  3541. archs = this->GetProperty(defVarName.c_str());
  3542. }
  3543. if(!archs)
  3544. {
  3545. archs = this->GetProperty("OSX_ARCHITECTURES");
  3546. }
  3547. if(archs)
  3548. {
  3549. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  3550. }
  3551. }
  3552. //----------------------------------------------------------------------------
  3553. bool cmTarget::IsChrpathUsed(const char* config)
  3554. {
  3555. #if defined(CMAKE_USE_ELF_PARSER)
  3556. // Only certain target types have an rpath.
  3557. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3558. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3559. this->GetType() == cmTarget::EXECUTABLE))
  3560. {
  3561. return false;
  3562. }
  3563. // If the target will not be installed we do not need to change its
  3564. // rpath.
  3565. if(!this->GetHaveInstallRule())
  3566. {
  3567. return false;
  3568. }
  3569. // Skip chrpath if skipping rpath altogether.
  3570. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3571. {
  3572. return false;
  3573. }
  3574. // Skip chrpath if it does not need to be changed at install time.
  3575. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3576. {
  3577. return false;
  3578. }
  3579. // Allow the user to disable builtin chrpath explicitly.
  3580. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  3581. {
  3582. return false;
  3583. }
  3584. // Enable if the rpath flag uses a separator and the target uses ELF
  3585. // binaries.
  3586. if(const char* ll = this->GetLinkerLanguage(config))
  3587. {
  3588. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3589. sepVar += ll;
  3590. sepVar += "_FLAG_SEP";
  3591. const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
  3592. if(sep && *sep)
  3593. {
  3594. // TODO: Add ELF check to ABI detection and get rid of
  3595. // CMAKE_EXECUTABLE_FORMAT.
  3596. if(const char* fmt =
  3597. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  3598. {
  3599. return strcmp(fmt, "ELF") == 0;
  3600. }
  3601. }
  3602. }
  3603. #endif
  3604. static_cast<void>(config);
  3605. return false;
  3606. }
  3607. //----------------------------------------------------------------------------
  3608. cmTarget::ImportInfo const*
  3609. cmTarget::GetImportInfo(const char* config)
  3610. {
  3611. // There is no imported information for non-imported targets.
  3612. if(!this->IsImported())
  3613. {
  3614. return 0;
  3615. }
  3616. // Lookup/compute/cache the import information for this
  3617. // configuration.
  3618. std::string config_upper;
  3619. if(config && *config)
  3620. {
  3621. config_upper = cmSystemTools::UpperCase(config);
  3622. }
  3623. else
  3624. {
  3625. config_upper = "NOCONFIG";
  3626. }
  3627. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  3628. ImportInfoMapType::const_iterator i =
  3629. this->Internal->ImportInfoMap.find(config_upper);
  3630. if(i == this->Internal->ImportInfoMap.end())
  3631. {
  3632. ImportInfo info;
  3633. this->ComputeImportInfo(config_upper, info);
  3634. ImportInfoMapType::value_type entry(config_upper, info);
  3635. i = this->Internal->ImportInfoMap.insert(entry).first;
  3636. }
  3637. // If the location is empty then the target is not available for
  3638. // this configuration.
  3639. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  3640. {
  3641. return 0;
  3642. }
  3643. // Return the import information.
  3644. return &i->second;
  3645. }
  3646. //----------------------------------------------------------------------------
  3647. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  3648. ImportInfo& info)
  3649. {
  3650. // This method finds information about an imported target from its
  3651. // properties. The "IMPORTED_" namespace is reserved for properties
  3652. // defined by the project exporting the target.
  3653. // Initialize members.
  3654. info.NoSOName = false;
  3655. // Track the configuration-specific property suffix.
  3656. std::string suffix = "_";
  3657. suffix += desired_config;
  3658. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  3659. // library or an executable with exports.
  3660. bool allowImp = this->HasImportLibrary();
  3661. // Look for a mapping from the current project's configuration to
  3662. // the imported project's configuration.
  3663. std::vector<std::string> mappedConfigs;
  3664. {
  3665. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  3666. mapProp += desired_config;
  3667. if(const char* mapValue = this->GetProperty(mapProp.c_str()))
  3668. {
  3669. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  3670. }
  3671. }
  3672. // If a mapping was found, check its configurations.
  3673. const char* loc = 0;
  3674. const char* imp = 0;
  3675. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  3676. !loc && !imp && mci != mappedConfigs.end(); ++mci)
  3677. {
  3678. // Look for this configuration.
  3679. std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
  3680. std::string locProp = "IMPORTED_LOCATION_";
  3681. locProp += mcUpper;
  3682. loc = this->GetProperty(locProp.c_str());
  3683. if(allowImp)
  3684. {
  3685. std::string impProp = "IMPORTED_IMPLIB_";
  3686. impProp += mcUpper;
  3687. imp = this->GetProperty(impProp.c_str());
  3688. }
  3689. // If it was found, use it for all properties below.
  3690. if(loc || imp)
  3691. {
  3692. suffix = "_";
  3693. suffix += mcUpper;
  3694. }
  3695. }
  3696. // If we needed to find one of the mapped configurations but did not
  3697. // then the target is not found. The project does not want any
  3698. // other configuration.
  3699. if(!mappedConfigs.empty() && !loc && !imp)
  3700. {
  3701. return;
  3702. }
  3703. // If we have not yet found it then there are no mapped
  3704. // configurations. Look for an exact-match.
  3705. if(!loc && !imp)
  3706. {
  3707. std::string locProp = "IMPORTED_LOCATION";
  3708. locProp += suffix;
  3709. loc = this->GetProperty(locProp.c_str());
  3710. if(allowImp)
  3711. {
  3712. std::string impProp = "IMPORTED_IMPLIB";
  3713. impProp += suffix;
  3714. imp = this->GetProperty(impProp.c_str());
  3715. }
  3716. }
  3717. // If we have not yet found it then there are no mapped
  3718. // configurations and no exact match.
  3719. if(!loc && !imp)
  3720. {
  3721. // The suffix computed above is not useful.
  3722. suffix = "";
  3723. // Look for a configuration-less location. This may be set by
  3724. // manually-written code.
  3725. loc = this->GetProperty("IMPORTED_LOCATION");
  3726. if(allowImp)
  3727. {
  3728. imp = this->GetProperty("IMPORTED_IMPLIB");
  3729. }
  3730. }
  3731. // If we have not yet found it then the project is willing to try
  3732. // any available configuration.
  3733. if(!loc && !imp)
  3734. {
  3735. std::vector<std::string> availableConfigs;
  3736. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  3737. {
  3738. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  3739. }
  3740. for(std::vector<std::string>::const_iterator
  3741. aci = availableConfigs.begin();
  3742. !loc && !imp && aci != availableConfigs.end(); ++aci)
  3743. {
  3744. suffix = "_";
  3745. suffix += cmSystemTools::UpperCase(*aci);
  3746. std::string locProp = "IMPORTED_LOCATION";
  3747. locProp += suffix;
  3748. loc = this->GetProperty(locProp.c_str());
  3749. if(allowImp)
  3750. {
  3751. std::string impProp = "IMPORTED_IMPLIB";
  3752. impProp += suffix;
  3753. imp = this->GetProperty(impProp.c_str());
  3754. }
  3755. }
  3756. }
  3757. // If we have not yet found it then the target is not available.
  3758. if(!loc && !imp)
  3759. {
  3760. return;
  3761. }
  3762. // A provided configuration has been chosen. Load the
  3763. // configuration's properties.
  3764. // Get the location.
  3765. if(loc)
  3766. {
  3767. info.Location = loc;
  3768. }
  3769. else
  3770. {
  3771. std::string impProp = "IMPORTED_LOCATION";
  3772. impProp += suffix;
  3773. if(const char* config_location = this->GetProperty(impProp.c_str()))
  3774. {
  3775. info.Location = config_location;
  3776. }
  3777. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  3778. {
  3779. info.Location = location;
  3780. }
  3781. }
  3782. // Get the soname.
  3783. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3784. {
  3785. std::string soProp = "IMPORTED_SONAME";
  3786. soProp += suffix;
  3787. if(const char* config_soname = this->GetProperty(soProp.c_str()))
  3788. {
  3789. info.SOName = config_soname;
  3790. }
  3791. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  3792. {
  3793. info.SOName = soname;
  3794. }
  3795. }
  3796. // Get the "no-soname" mark.
  3797. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3798. {
  3799. std::string soProp = "IMPORTED_NO_SONAME";
  3800. soProp += suffix;
  3801. if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
  3802. {
  3803. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  3804. }
  3805. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  3806. {
  3807. info.NoSOName = cmSystemTools::IsOn(no_soname);
  3808. }
  3809. }
  3810. // Get the import library.
  3811. if(imp)
  3812. {
  3813. info.ImportLibrary = imp;
  3814. }
  3815. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3816. this->IsExecutableWithExports())
  3817. {
  3818. std::string impProp = "IMPORTED_IMPLIB";
  3819. impProp += suffix;
  3820. if(const char* config_implib = this->GetProperty(impProp.c_str()))
  3821. {
  3822. info.ImportLibrary = config_implib;
  3823. }
  3824. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  3825. {
  3826. info.ImportLibrary = implib;
  3827. }
  3828. }
  3829. // Get the link interface.
  3830. {
  3831. std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  3832. linkProp += suffix;
  3833. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  3834. {
  3835. cmSystemTools::ExpandListArgument(config_libs,
  3836. info.LinkInterface.Libraries);
  3837. }
  3838. else if(const char* libs =
  3839. this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
  3840. {
  3841. cmSystemTools::ExpandListArgument(libs,
  3842. info.LinkInterface.Libraries);
  3843. }
  3844. }
  3845. // Get the link dependencies.
  3846. {
  3847. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  3848. linkProp += suffix;
  3849. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  3850. {
  3851. cmSystemTools::ExpandListArgument(config_libs,
  3852. info.LinkInterface.SharedDeps);
  3853. }
  3854. else if(const char* libs =
  3855. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  3856. {
  3857. cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
  3858. }
  3859. }
  3860. // Get the link languages.
  3861. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3862. {
  3863. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  3864. linkProp += suffix;
  3865. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  3866. {
  3867. cmSystemTools::ExpandListArgument(config_libs,
  3868. info.LinkInterface.Languages);
  3869. }
  3870. else if(const char* libs =
  3871. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  3872. {
  3873. cmSystemTools::ExpandListArgument(libs,
  3874. info.LinkInterface.Languages);
  3875. }
  3876. }
  3877. // Get the cyclic repetition count.
  3878. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3879. {
  3880. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  3881. linkProp += suffix;
  3882. if(const char* config_reps = this->GetProperty(linkProp.c_str()))
  3883. {
  3884. sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
  3885. }
  3886. else if(const char* reps =
  3887. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  3888. {
  3889. sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
  3890. }
  3891. }
  3892. }
  3893. //----------------------------------------------------------------------------
  3894. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config)
  3895. {
  3896. // Imported targets have their own link interface.
  3897. if(this->IsImported())
  3898. {
  3899. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3900. {
  3901. return &info->LinkInterface;
  3902. }
  3903. return 0;
  3904. }
  3905. // Link interfaces are not supported for executables that do not
  3906. // export symbols.
  3907. if(this->GetType() == cmTarget::EXECUTABLE &&
  3908. !this->IsExecutableWithExports())
  3909. {
  3910. return 0;
  3911. }
  3912. // Lookup any existing link interface for this configuration.
  3913. std::string key = cmSystemTools::UpperCase(config? config : "");
  3914. cmTargetInternals::LinkInterfaceMapType::iterator
  3915. i = this->Internal->LinkInterfaceMap.find(key);
  3916. if(i == this->Internal->LinkInterfaceMap.end())
  3917. {
  3918. // Compute the link interface for this configuration.
  3919. cmTargetInternals::OptionalLinkInterface iface;
  3920. iface.Exists = this->ComputeLinkInterface(config, iface);
  3921. // Store the information for this configuration.
  3922. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  3923. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  3924. }
  3925. return i->second.Exists? &i->second : 0;
  3926. }
  3927. //----------------------------------------------------------------------------
  3928. bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface)
  3929. {
  3930. // Construct the property name suffix for this configuration.
  3931. std::string suffix = "_";
  3932. if(config && *config)
  3933. {
  3934. suffix += cmSystemTools::UpperCase(config);
  3935. }
  3936. else
  3937. {
  3938. suffix += "NOCONFIG";
  3939. }
  3940. // An explicit list of interface libraries may be set for shared
  3941. // libraries and executables that export symbols.
  3942. const char* explicitLibraries = 0;
  3943. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3944. this->IsExecutableWithExports())
  3945. {
  3946. // Lookup the per-configuration property.
  3947. std::string propName = "LINK_INTERFACE_LIBRARIES";
  3948. propName += suffix;
  3949. explicitLibraries = this->GetProperty(propName.c_str());
  3950. // If not set, try the generic property.
  3951. if(!explicitLibraries)
  3952. {
  3953. explicitLibraries = this->GetProperty("LINK_INTERFACE_LIBRARIES");
  3954. }
  3955. }
  3956. // There is no implicit link interface for executables, so if none
  3957. // was explicitly set, there is no link interface.
  3958. if(!explicitLibraries && this->GetType() == cmTarget::EXECUTABLE)
  3959. {
  3960. return false;
  3961. }
  3962. if(explicitLibraries)
  3963. {
  3964. // The interface libraries have been explicitly set.
  3965. cmSystemTools::ExpandListArgument(explicitLibraries, iface.Libraries);
  3966. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  3967. {
  3968. // Shared libraries may have runtime implementation dependencies
  3969. // on other shared libraries that are not in the interface.
  3970. std::set<cmStdString> emitted;
  3971. for(std::vector<std::string>::const_iterator
  3972. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  3973. {
  3974. emitted.insert(*li);
  3975. }
  3976. LinkImplementation const* impl = this->GetLinkImplementation(config);
  3977. for(std::vector<std::string>::const_iterator
  3978. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  3979. {
  3980. if(emitted.insert(*li).second)
  3981. {
  3982. if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
  3983. {
  3984. // This is a runtime dependency on another shared library.
  3985. if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
  3986. {
  3987. iface.SharedDeps.push_back(*li);
  3988. }
  3989. }
  3990. else
  3991. {
  3992. // TODO: Recognize shared library file names. Perhaps this
  3993. // should be moved to cmComputeLinkInformation, but that creates
  3994. // a chicken-and-egg problem since this list is needed for its
  3995. // construction.
  3996. }
  3997. }
  3998. }
  3999. }
  4000. }
  4001. else
  4002. {
  4003. // The link implementation is the default link interface.
  4004. LinkImplementation const* impl = this->GetLinkImplementation(config);
  4005. iface.Libraries = impl->Libraries;
  4006. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  4007. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4008. {
  4009. // Targets using this archive need its language runtime libraries.
  4010. iface.Languages = impl->Languages;
  4011. }
  4012. }
  4013. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4014. {
  4015. // How many repetitions are needed if this library has cyclic
  4016. // dependencies?
  4017. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4018. propName += suffix;
  4019. if(const char* config_reps = this->GetProperty(propName.c_str()))
  4020. {
  4021. sscanf(config_reps, "%u", &iface.Multiplicity);
  4022. }
  4023. else if(const char* reps =
  4024. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  4025. {
  4026. sscanf(reps, "%u", &iface.Multiplicity);
  4027. }
  4028. }
  4029. return true;
  4030. }
  4031. //----------------------------------------------------------------------------
  4032. cmTarget::LinkImplementation const*
  4033. cmTarget::GetLinkImplementation(const char* config)
  4034. {
  4035. // There is no link implementation for imported targets.
  4036. if(this->IsImported())
  4037. {
  4038. return 0;
  4039. }
  4040. // Lookup any existing link implementation for this configuration.
  4041. std::string key = cmSystemTools::UpperCase(config? config : "");
  4042. cmTargetInternals::LinkImplMapType::iterator
  4043. i = this->Internal->LinkImplMap.find(key);
  4044. if(i == this->Internal->LinkImplMap.end())
  4045. {
  4046. // Compute the link implementation for this configuration.
  4047. LinkImplementation impl;
  4048. this->ComputeLinkImplementation(config, impl);
  4049. // Store the information for this configuration.
  4050. cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
  4051. i = this->Internal->LinkImplMap.insert(entry).first;
  4052. }
  4053. return &i->second;
  4054. }
  4055. //----------------------------------------------------------------------------
  4056. void cmTarget::ComputeLinkImplementation(const char* config,
  4057. LinkImplementation& impl)
  4058. {
  4059. // Compute which library configuration to link.
  4060. cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  4061. // Collect libraries directly linked in this configuration.
  4062. LinkLibraryVectorType const& llibs = this->GetOriginalLinkLibraries();
  4063. for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
  4064. li != llibs.end(); ++li)
  4065. {
  4066. // Skip entries that resolve to the target itself or are empty.
  4067. std::string item = this->CheckCMP0004(li->first);
  4068. if(item == this->GetName() || item.empty())
  4069. {
  4070. continue;
  4071. }
  4072. if(li->second == cmTarget::GENERAL || li->second == linkType)
  4073. {
  4074. // The entry is meant for this configuration.
  4075. impl.Libraries.push_back(item);
  4076. }
  4077. else
  4078. {
  4079. // Support OLD behavior for CMP0003.
  4080. impl.WrongConfigLibraries.push_back(item);
  4081. }
  4082. }
  4083. // This target needs runtime libraries for its source languages.
  4084. std::set<cmStdString> languages;
  4085. this->GetLanguages(languages);
  4086. for(std::set<cmStdString>::iterator li = languages.begin();
  4087. li != languages.end(); ++li)
  4088. {
  4089. impl.Languages.push_back(*li);
  4090. }
  4091. }
  4092. //----------------------------------------------------------------------------
  4093. std::string cmTarget::CheckCMP0004(std::string const& item)
  4094. {
  4095. // Strip whitespace off the library names because we used to do this
  4096. // in case variables were expanded at generate time. We no longer
  4097. // do the expansion but users link to libraries like " ${VAR} ".
  4098. std::string lib = item;
  4099. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  4100. if(pos != lib.npos)
  4101. {
  4102. lib = lib.substr(pos, lib.npos);
  4103. }
  4104. pos = lib.find_last_not_of(" \t\r\n");
  4105. if(pos != lib.npos)
  4106. {
  4107. lib = lib.substr(0, pos+1);
  4108. }
  4109. if(lib != item)
  4110. {
  4111. cmake* cm = this->Makefile->GetCMakeInstance();
  4112. switch(this->PolicyStatusCMP0004)
  4113. {
  4114. case cmPolicies::WARN:
  4115. {
  4116. cmOStringStream w;
  4117. w << (this->Makefile->GetPolicies()
  4118. ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
  4119. << "Target \"" << this->GetName() << "\" links to item \""
  4120. << item << "\" which has leading or trailing whitespace.";
  4121. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  4122. this->GetBacktrace());
  4123. }
  4124. case cmPolicies::OLD:
  4125. break;
  4126. case cmPolicies::NEW:
  4127. {
  4128. cmOStringStream e;
  4129. e << "Target \"" << this->GetName() << "\" links to item \""
  4130. << item << "\" which has leading or trailing whitespace. "
  4131. << "This is now an error according to policy CMP0004.";
  4132. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4133. }
  4134. break;
  4135. case cmPolicies::REQUIRED_IF_USED:
  4136. case cmPolicies::REQUIRED_ALWAYS:
  4137. {
  4138. cmOStringStream e;
  4139. e << (this->Makefile->GetPolicies()
  4140. ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
  4141. << "Target \"" << this->GetName() << "\" links to item \""
  4142. << item << "\" which has leading or trailing whitespace.";
  4143. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  4144. }
  4145. break;
  4146. }
  4147. }
  4148. return lib;
  4149. }
  4150. //----------------------------------------------------------------------------
  4151. cmComputeLinkInformation*
  4152. cmTarget::GetLinkInformation(const char* config)
  4153. {
  4154. // Lookup any existing information for this configuration.
  4155. std::map<cmStdString, cmComputeLinkInformation*>::iterator
  4156. i = this->LinkInformation.find(config?config:"");
  4157. if(i == this->LinkInformation.end())
  4158. {
  4159. // Compute information for this configuration.
  4160. cmComputeLinkInformation* info =
  4161. new cmComputeLinkInformation(this, config);
  4162. if(!info || !info->Compute())
  4163. {
  4164. delete info;
  4165. info = 0;
  4166. }
  4167. // Store the information for this configuration.
  4168. std::map<cmStdString, cmComputeLinkInformation*>::value_type
  4169. entry(config?config:"", info);
  4170. i = this->LinkInformation.insert(entry).first;
  4171. }
  4172. return i->second;
  4173. }
  4174. //----------------------------------------------------------------------------
  4175. cmTargetLinkInformationMap
  4176. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  4177. {
  4178. // Ideally cmTarget instances should never be copied. However until
  4179. // we can make a sweep to remove that, this copy constructor avoids
  4180. // allowing the resources (LinkInformation) from getting copied. In
  4181. // the worst case this will lead to extra cmComputeLinkInformation
  4182. // instances. We also enforce in debug mode that the map be emptied
  4183. // when copied.
  4184. static_cast<void>(r);
  4185. assert(r.empty());
  4186. }
  4187. //----------------------------------------------------------------------------
  4188. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  4189. {
  4190. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  4191. {
  4192. delete i->second;
  4193. }
  4194. }
  4195. //----------------------------------------------------------------------------
  4196. cmTargetInternalPointer::cmTargetInternalPointer()
  4197. {
  4198. this->Pointer = new cmTargetInternals;
  4199. }
  4200. //----------------------------------------------------------------------------
  4201. cmTargetInternalPointer
  4202. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  4203. {
  4204. // Ideally cmTarget instances should never be copied. However until
  4205. // we can make a sweep to remove that, this copy constructor avoids
  4206. // allowing the resources (Internals) to be copied.
  4207. this->Pointer = new cmTargetInternals(*r.Pointer);
  4208. }
  4209. //----------------------------------------------------------------------------
  4210. cmTargetInternalPointer::~cmTargetInternalPointer()
  4211. {
  4212. delete this->Pointer;
  4213. }
  4214. //----------------------------------------------------------------------------
  4215. cmTargetInternalPointer&
  4216. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  4217. {
  4218. if(this == &r) { return *this; } // avoid warning on HP about self check
  4219. // Ideally cmTarget instances should never be copied. However until
  4220. // we can make a sweep to remove that, this copy constructor avoids
  4221. // allowing the resources (Internals) to be copied.
  4222. cmTargetInternals* oldPointer = this->Pointer;
  4223. this->Pointer = new cmTargetInternals(*r.Pointer);
  4224. delete oldPointer;
  4225. return *this;
  4226. }