cmTarget.cxx 157 KB

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