cmTarget.cxx 134 KB

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