cmTarget.cxx 103 KB

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