cmTarget.cxx 122 KB

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