auto_link.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. // (C) Copyright John Maddock 2003.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. /*
  6. * LOCATION: see http://www.boost.org for most recent version.
  7. * FILE auto_link.hpp
  8. * VERSION see <boost/version.hpp>
  9. * DESCRIPTION: Automatic library inclusion for Borland/Microsoft compilers.
  10. */
  11. /*************************************************************************
  12. USAGE:
  13. ~~~~~~
  14. Before including this header you must define one or more of define the following macros:
  15. BOOST_LIB_NAME: Required: A string containing the basename of the library,
  16. for example boost_regex.
  17. BOOST_LIB_TOOLSET: Optional: the base name of the toolset.
  18. BOOST_DYN_LINK: Optional: when set link to dll rather than static library.
  19. BOOST_LIB_DIAGNOSTIC: Optional: when set the header will print out the name
  20. of the library selected (useful for debugging).
  21. BOOST_AUTO_LINK_NOMANGLE: Specifies that we should link to BOOST_LIB_NAME.lib,
  22. rather than a mangled-name version.
  23. These macros will be undef'ed at the end of the header, further this header
  24. has no include guards - so be sure to include it only once from your library!
  25. Algorithm:
  26. ~~~~~~~~~~
  27. Libraries for Borland and Microsoft compilers are automatically
  28. selected here, the name of the lib is selected according to the following
  29. formula:
  30. BOOST_LIB_PREFIX
  31. + BOOST_LIB_NAME
  32. + "_"
  33. + BOOST_LIB_TOOLSET
  34. + BOOST_LIB_THREAD_OPT
  35. + BOOST_LIB_RT_OPT
  36. "-"
  37. + BOOST_LIB_VERSION
  38. These are defined as:
  39. BOOST_LIB_PREFIX: "lib" for static libraries otherwise "".
  40. BOOST_LIB_NAME: The base name of the lib ( for example boost_regex).
  41. BOOST_LIB_TOOLSET: The compiler toolset name (vc6, vc7, bcb5 etc).
  42. BOOST_LIB_THREAD_OPT: "-mt" for multithread builds, otherwise nothing.
  43. BOOST_LIB_RT_OPT: A suffix that indicates the runtime library used,
  44. contains one or more of the following letters after
  45. a hiphen:
  46. s static runtime (dynamic if not present).
  47. d debug build (release if not present).
  48. g debug/diagnostic runtime (release if not present).
  49. p STLPort Build.
  50. BOOST_LIB_VERSION: The Boost version, in the form x_y, for Boost version x.y.
  51. ***************************************************************************/
  52. #ifdef __cplusplus
  53. # ifndef BOOST_CONFIG_HPP
  54. # include <boost/config.hpp>
  55. # endif
  56. #elif defined(_MSC_VER) && !defined(__MWERKS__) && !defined(__EDG_VERSION__)
  57. //
  58. // C language compatability (no, honestly)
  59. //
  60. # define BOOST_MSVC _MSC_VER
  61. # define BOOST_STRINGIZE(X) BOOST_DO_STRINGIZE(X)
  62. # define BOOST_DO_STRINGIZE(X) #X
  63. #endif
  64. //
  65. // Only include what follows for known and supported compilers:
  66. //
  67. #if defined(BOOST_MSVC) \
  68. || defined(__BORLANDC__) \
  69. || (defined(__MWERKS__) && defined(_WIN32) && (__MWERKS__ >= 0x3000)) \
  70. || (defined(__ICL) && defined(_MSC_EXTENSIONS) && (_MSC_VER >= 1200))
  71. #ifndef BOOST_VERSION_HPP
  72. # include <boost/version.hpp>
  73. #endif
  74. #ifndef BOOST_LIB_NAME
  75. # error "Macro BOOST_LIB_NAME not set (internal error)"
  76. #endif
  77. //
  78. // error check:
  79. //
  80. #if defined(__MSVC_RUNTIME_CHECKS) && !defined(_DEBUG)
  81. # pragma message("Using the /RTC option without specifying a debug runtime will lead to linker errors")
  82. # pragma message("Hint: go to the code generation options and switch to one of the debugging runtimes")
  83. # error "Incompatible build options"
  84. #endif
  85. //
  86. // select toolset if not defined already:
  87. //
  88. #ifndef BOOST_LIB_TOOLSET
  89. // Note: no compilers before 1200 are supported
  90. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  91. # ifdef UNDER_CE
  92. // vc6:
  93. # define BOOST_LIB_TOOLSET "evc4"
  94. # else
  95. // vc6:
  96. # define BOOST_LIB_TOOLSET "vc6"
  97. # endif
  98. #elif defined(BOOST_MSVC) && (BOOST_MSVC == 1300)
  99. // vc7:
  100. # define BOOST_LIB_TOOLSET "vc7"
  101. #elif defined(BOOST_MSVC) && (BOOST_MSVC == 1310)
  102. // vc71:
  103. # define BOOST_LIB_TOOLSET "vc71"
  104. #elif defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
  105. // vc80:
  106. # define BOOST_LIB_TOOLSET "vc80"
  107. #elif defined(BOOST_MSVC) && (BOOST_MSVC == 1500)
  108. // vc90:
  109. # define BOOST_LIB_TOOLSET "vc90"
  110. #elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1600)
  111. // vc10:
  112. # define BOOST_LIB_TOOLSET "vc100"
  113. #elif defined(__BORLANDC__)
  114. // CBuilder 6:
  115. # define BOOST_LIB_TOOLSET "bcb"
  116. #elif defined(__ICL)
  117. // Intel C++, no version number:
  118. # define BOOST_LIB_TOOLSET "iw"
  119. #elif defined(__MWERKS__) && (__MWERKS__ <= 0x31FF )
  120. // Metrowerks CodeWarrior 8.x
  121. # define BOOST_LIB_TOOLSET "cw8"
  122. #elif defined(__MWERKS__) && (__MWERKS__ <= 0x32FF )
  123. // Metrowerks CodeWarrior 9.x
  124. # define BOOST_LIB_TOOLSET "cw9"
  125. #endif
  126. #endif // BOOST_LIB_TOOLSET
  127. //
  128. // select thread opt:
  129. //
  130. #if defined(_MT) || defined(__MT__)
  131. # define BOOST_LIB_THREAD_OPT "-mt"
  132. #else
  133. # define BOOST_LIB_THREAD_OPT
  134. #endif
  135. #if defined(_MSC_VER) || defined(__MWERKS__)
  136. # ifdef _DLL
  137. # if (defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) && (defined(_STLP_OWN_IOSTREAMS) || defined(__STL_OWN_IOSTREAMS))
  138. # if defined(_DEBUG) && (defined(__STL_DEBUG) || defined(_STLP_DEBUG))
  139. # define BOOST_LIB_RT_OPT "-gdp"
  140. # elif defined(_DEBUG)
  141. # define BOOST_LIB_RT_OPT "-gdp"
  142. # pragma message("warning: STLPort debug versions are built with /D_STLP_DEBUG=1")
  143. # error "Build options aren't compatible with pre-built libraries"
  144. # else
  145. # define BOOST_LIB_RT_OPT "-p"
  146. # endif
  147. # elif defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
  148. # if defined(_DEBUG) && (defined(__STL_DEBUG) || defined(_STLP_DEBUG))
  149. # define BOOST_LIB_RT_OPT "-gdpn"
  150. # elif defined(_DEBUG)
  151. # define BOOST_LIB_RT_OPT "-gdpn"
  152. # pragma message("warning: STLPort debug versions are built with /D_STLP_DEBUG=1")
  153. # error "Build options aren't compatible with pre-built libraries"
  154. # else
  155. # define BOOST_LIB_RT_OPT "-pn"
  156. # endif
  157. # else
  158. # if defined(_DEBUG)
  159. # define BOOST_LIB_RT_OPT "-gd"
  160. # else
  161. # define BOOST_LIB_RT_OPT
  162. # endif
  163. # endif
  164. # else
  165. # if (defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) && (defined(_STLP_OWN_IOSTREAMS) || defined(__STL_OWN_IOSTREAMS))
  166. # if defined(_DEBUG) && (defined(__STL_DEBUG) || defined(_STLP_DEBUG))
  167. # define BOOST_LIB_RT_OPT "-sgdp"
  168. # elif defined(_DEBUG)
  169. # define BOOST_LIB_RT_OPT "-sgdp"
  170. # pragma message("warning: STLPort debug versions are built with /D_STLP_DEBUG=1")
  171. # error "Build options aren't compatible with pre-built libraries"
  172. # else
  173. # define BOOST_LIB_RT_OPT "-sp"
  174. # endif
  175. # elif defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
  176. # if defined(_DEBUG) && (defined(__STL_DEBUG) || defined(_STLP_DEBUG))
  177. # define BOOST_LIB_RT_OPT "-sgdpn"
  178. # elif defined(_DEBUG)
  179. # define BOOST_LIB_RT_OPT "-sgdpn"
  180. # pragma message("warning: STLPort debug versions are built with /D_STLP_DEBUG=1")
  181. # error "Build options aren't compatible with pre-built libraries"
  182. # else
  183. # define BOOST_LIB_RT_OPT "-spn"
  184. # endif
  185. # else
  186. # if defined(_DEBUG)
  187. # define BOOST_LIB_RT_OPT "-sgd"
  188. # else
  189. # define BOOST_LIB_RT_OPT "-s"
  190. # endif
  191. # endif
  192. # endif
  193. #elif defined(__BORLANDC__)
  194. //
  195. // figure out whether we want the debug builds or not:
  196. //
  197. #if __BORLANDC__ > 0x561
  198. #pragma defineonoption BOOST_BORLAND_DEBUG -v
  199. #endif
  200. //
  201. // sanity check:
  202. //
  203. #if defined(__STL_DEBUG) || defined(_STLP_DEBUG)
  204. #error "Pre-built versions of the Boost libraries are not provided in STLPort-debug form"
  205. #endif
  206. # ifdef _RTLDLL
  207. # ifdef BOOST_BORLAND_DEBUG
  208. # define BOOST_LIB_RT_OPT "-d"
  209. # else
  210. # define BOOST_LIB_RT_OPT
  211. # endif
  212. # else
  213. # ifdef BOOST_BORLAND_DEBUG
  214. # define BOOST_LIB_RT_OPT "-sd"
  215. # else
  216. # define BOOST_LIB_RT_OPT "-s"
  217. # endif
  218. # endif
  219. #endif
  220. //
  221. // select linkage opt:
  222. //
  223. #if (defined(_DLL) || defined(_RTLDLL)) && defined(BOOST_DYN_LINK)
  224. # define BOOST_LIB_PREFIX
  225. #elif defined(BOOST_DYN_LINK)
  226. # error "Mixing a dll boost library with a static runtime is a really bad idea..."
  227. #else
  228. # define BOOST_LIB_PREFIX "lib"
  229. #endif
  230. //
  231. // now include the lib:
  232. //
  233. #if defined(BOOST_LIB_NAME) \
  234. && defined(BOOST_LIB_PREFIX) \
  235. && defined(BOOST_LIB_TOOLSET) \
  236. && defined(BOOST_LIB_THREAD_OPT) \
  237. && defined(BOOST_LIB_RT_OPT) \
  238. && defined(BOOST_LIB_VERSION)
  239. #ifndef BOOST_AUTO_LINK_NOMANGLE
  240. # pragma comment(lib, BOOST_LIB_PREFIX BOOST_STRINGIZE(BOOST_LIB_NAME) "-" BOOST_LIB_TOOLSET BOOST_LIB_THREAD_OPT BOOST_LIB_RT_OPT "-" BOOST_LIB_VERSION ".lib")
  241. # ifdef BOOST_LIB_DIAGNOSTIC
  242. # pragma message ("Linking to lib file: " BOOST_LIB_PREFIX BOOST_STRINGIZE(BOOST_LIB_NAME) "-" BOOST_LIB_TOOLSET BOOST_LIB_THREAD_OPT BOOST_LIB_RT_OPT "-" BOOST_LIB_VERSION ".lib")
  243. # endif
  244. #else
  245. # pragma comment(lib, BOOST_STRINGIZE(BOOST_LIB_NAME) ".lib")
  246. # ifdef BOOST_LIB_DIAGNOSTIC
  247. # pragma message ("Linking to lib file: " BOOST_STRINGIZE(BOOST_LIB_NAME) ".lib")
  248. # endif
  249. #endif
  250. #else
  251. # error "some required macros where not defined (internal logic error)."
  252. #endif
  253. #endif // _MSC_VER || __BORLANDC__
  254. //
  255. // finally undef any macros we may have set:
  256. //
  257. #ifdef BOOST_LIB_PREFIX
  258. # undef BOOST_LIB_PREFIX
  259. #endif
  260. #if defined(BOOST_LIB_NAME)
  261. # undef BOOST_LIB_NAME
  262. #endif
  263. // Don't undef this one: it can be set by the user and should be the
  264. // same for all libraries:
  265. //#if defined(BOOST_LIB_TOOLSET)
  266. //# undef BOOST_LIB_TOOLSET
  267. //#endif
  268. #if defined(BOOST_LIB_THREAD_OPT)
  269. # undef BOOST_LIB_THREAD_OPT
  270. #endif
  271. #if defined(BOOST_LIB_RT_OPT)
  272. # undef BOOST_LIB_RT_OPT
  273. #endif
  274. #if defined(BOOST_LIB_LINK_OPT)
  275. # undef BOOST_LIB_LINK_OPT
  276. #endif
  277. #if defined(BOOST_LIB_DEBUG_OPT)
  278. # undef BOOST_LIB_DEBUG_OPT
  279. #endif
  280. #if defined(BOOST_DYN_LINK)
  281. # undef BOOST_DYN_LINK
  282. #endif
  283. #if defined(BOOST_AUTO_LINK_NOMANGLE)
  284. # undef BOOST_AUTO_LINK_NOMANGLE
  285. #endif