cmTarget.cxx 150 KB

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