cmTarget.cxx 135 KB

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