cmTarget.cxx 137 KB

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