PageRenderTime 37ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/m4/ax_boost_base.m4

http://github.com/mozy/mordor
m4 | 272 lines | 204 code | 23 blank | 45 comment | 0 complexity | f94f18bf075f75bcc02c6ea3f73bee08 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_boost_base.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Test for the Boost C++ libraries of a particular version (or newer)
  12. #
  13. # If no path to the installed boost library is given the macro searchs
  14. # under /usr, /usr/local, /opt and /opt/local and evaluates the
  15. # $BOOST_ROOT environment variable. Further documentation is available at
  16. # <http://randspringer.de/boost/index.html>.
  17. #
  18. # This macro calls:
  19. #
  20. # AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
  21. #
  22. # And sets:
  23. #
  24. # HAVE_BOOST
  25. #
  26. # LICENSE
  27. #
  28. # Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
  29. # Copyright (c) 2009 Peter Adolphs
  30. #
  31. # Copying and distribution of this file, with or without modification, are
  32. # permitted in any medium without royalty provided the copyright notice
  33. # and this notice are preserved. This file is offered as-is, without any
  34. # warranty.
  35. #serial 23
  36. AC_DEFUN([AX_BOOST_BASE],
  37. [
  38. AC_ARG_WITH([boost],
  39. [AS_HELP_STRING([--with-boost@<:@=ARG@:>@],
  40. [use Boost library from a standard location (ARG=yes),
  41. from the specified location (ARG=<path>),
  42. or disable it (ARG=no)
  43. @<:@ARG=yes@:>@ ])],
  44. [
  45. if test "$withval" = "no"; then
  46. want_boost="no"
  47. elif test "$withval" = "yes"; then
  48. want_boost="yes"
  49. ac_boost_path=""
  50. else
  51. want_boost="yes"
  52. ac_boost_path="$withval"
  53. fi
  54. ],
  55. [want_boost="yes"])
  56. AC_ARG_WITH([boost-libdir],
  57. AS_HELP_STRING([--with-boost-libdir=LIB_DIR],
  58. [Force given directory for boost libraries. Note that this will override library path detection, so use this parameter only if default library detection fails and you know exactly where your boost libraries are located.]),
  59. [
  60. if test -d "$withval"
  61. then
  62. ac_boost_lib_path="$withval"
  63. else
  64. AC_MSG_ERROR(--with-boost-libdir expected directory name)
  65. fi
  66. ],
  67. [ac_boost_lib_path=""]
  68. )
  69. if test "x$want_boost" = "xyes"; then
  70. boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
  71. boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
  72. boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
  73. boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
  74. boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  75. if test "x$boost_lib_version_req_sub_minor" = "x" ; then
  76. boost_lib_version_req_sub_minor="0"
  77. fi
  78. WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
  79. AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
  80. succeeded=no
  81. dnl On 64-bit systems check for system libraries in both lib64 and lib.
  82. dnl The former is specified by FHS, but e.g. Debian does not adhere to
  83. dnl this (as it rises problems for generic multi-arch support).
  84. dnl The last entry in the list is chosen by default when no libraries
  85. dnl are found, e.g. when only header-only libraries are installed!
  86. libsubdirs="lib"
  87. ax_arch=`uname -m`
  88. case $ax_arch in
  89. x86_64|ppc64|s390x|sparc64|aarch64)
  90. libsubdirs="lib64 lib lib64"
  91. ;;
  92. esac
  93. dnl allow for real multi-arch paths e.g. /usr/lib/x86_64-linux-gnu. Give
  94. dnl them priority over the other paths since, if libs are found there, they
  95. dnl are almost assuredly the ones desired.
  96. AC_REQUIRE([AC_CANONICAL_HOST])
  97. libsubdirs="lib/${host_cpu}-${host_os} $libsubdirs"
  98. case ${host_cpu} in
  99. i?86)
  100. libsubdirs="lib/i386-${host_os} $libsubdirs"
  101. ;;
  102. esac
  103. dnl first we check the system location for boost libraries
  104. dnl this location ist chosen if boost libraries are installed with the --layout=system option
  105. dnl or if you install boost with RPM
  106. if test "$ac_boost_path" != ""; then
  107. BOOST_CPPFLAGS="-I$ac_boost_path/include"
  108. for ac_boost_path_tmp in $libsubdirs; do
  109. if test -d "$ac_boost_path"/"$ac_boost_path_tmp" ; then
  110. BOOST_LDFLAGS="-L$ac_boost_path/$ac_boost_path_tmp"
  111. break
  112. fi
  113. done
  114. elif test "$cross_compiling" != yes; then
  115. for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
  116. if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
  117. for libsubdir in $libsubdirs ; do
  118. if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
  119. done
  120. BOOST_LDFLAGS="-L$ac_boost_path_tmp/$libsubdir"
  121. BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
  122. break;
  123. fi
  124. done
  125. fi
  126. dnl overwrite ld flags if we have required special directory with
  127. dnl --with-boost-libdir parameter
  128. if test "$ac_boost_lib_path" != ""; then
  129. BOOST_LDFLAGS="-L$ac_boost_lib_path"
  130. fi
  131. CPPFLAGS_SAVED="$CPPFLAGS"
  132. CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
  133. export CPPFLAGS
  134. LDFLAGS_SAVED="$LDFLAGS"
  135. LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
  136. export LDFLAGS
  137. AC_REQUIRE([AC_PROG_CXX])
  138. AC_LANG_PUSH(C++)
  139. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  140. @%:@include <boost/version.hpp>
  141. ]], [[
  142. #if BOOST_VERSION >= $WANT_BOOST_VERSION
  143. // Everything is okay
  144. #else
  145. # error Boost version is too old
  146. #endif
  147. ]])],[
  148. AC_MSG_RESULT(yes)
  149. succeeded=yes
  150. found_system=yes
  151. ],[
  152. ])
  153. AC_LANG_POP([C++])
  154. dnl if we found no boost with system layout we search for boost libraries
  155. dnl built and installed without the --layout=system option or for a staged(not installed) version
  156. if test "x$succeeded" != "xyes"; then
  157. _version=0
  158. if test "$ac_boost_path" != ""; then
  159. if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
  160. for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
  161. _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
  162. V_CHECK=`expr $_version_tmp \> $_version`
  163. if test "$V_CHECK" = "1" ; then
  164. _version=$_version_tmp
  165. fi
  166. VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
  167. BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
  168. done
  169. fi
  170. else
  171. if test "$cross_compiling" != yes; then
  172. for ac_boost_path in /usr /usr/local /opt /opt/local ; do
  173. if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
  174. for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
  175. _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
  176. V_CHECK=`expr $_version_tmp \> $_version`
  177. if test "$V_CHECK" = "1" ; then
  178. _version=$_version_tmp
  179. best_path=$ac_boost_path
  180. fi
  181. done
  182. fi
  183. done
  184. VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
  185. BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
  186. if test "$ac_boost_lib_path" = ""; then
  187. for libsubdir in $libsubdirs ; do
  188. if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
  189. done
  190. BOOST_LDFLAGS="-L$best_path/$libsubdir"
  191. fi
  192. fi
  193. if test "x$BOOST_ROOT" != "x"; then
  194. for libsubdir in $libsubdirs ; do
  195. if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
  196. done
  197. if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then
  198. version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
  199. stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
  200. stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
  201. V_CHECK=`expr $stage_version_shorten \>\= $_version`
  202. if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then
  203. AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
  204. BOOST_CPPFLAGS="-I$BOOST_ROOT"
  205. BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
  206. fi
  207. fi
  208. fi
  209. fi
  210. CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
  211. export CPPFLAGS
  212. LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
  213. export LDFLAGS
  214. AC_LANG_PUSH(C++)
  215. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  216. @%:@include <boost/version.hpp>
  217. ]], [[
  218. #if BOOST_VERSION >= $WANT_BOOST_VERSION
  219. // Everything is okay
  220. #else
  221. # error Boost version is too old
  222. #endif
  223. ]])],[
  224. AC_MSG_RESULT(yes)
  225. succeeded=yes
  226. found_system=yes
  227. ],[
  228. ])
  229. AC_LANG_POP([C++])
  230. fi
  231. if test "$succeeded" != "yes" ; then
  232. if test "$_version" = "0" ; then
  233. AC_MSG_NOTICE([[We could not detect the boost libraries (version $boost_lib_version_req_shorten or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.]])
  234. else
  235. AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
  236. fi
  237. # execute ACTION-IF-NOT-FOUND (if present):
  238. ifelse([$3], , :, [$3])
  239. else
  240. AC_SUBST(BOOST_CPPFLAGS)
  241. AC_SUBST(BOOST_LDFLAGS)
  242. AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
  243. # execute ACTION-IF-FOUND (if present):
  244. ifelse([$2], , :, [$2])
  245. fi
  246. CPPFLAGS="$CPPFLAGS_SAVED"
  247. LDFLAGS="$LDFLAGS_SAVED"
  248. fi
  249. ])