cmTarget.cxx 88 KB

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