cmTarget.cxx 142 KB

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