You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ax_boost_base.m4 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 27
  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)
  90. libsubdirs="lib64 libx32 lib lib64"
  91. ;;
  92. ppc64|s390x|sparc64|aarch64|ppc64le)
  93. libsubdirs="lib64 lib lib64"
  94. ;;
  95. esac
  96. dnl allow for real multi-arch paths e.g. /usr/lib/x86_64-linux-gnu. Give
  97. dnl them priority over the other paths since, if libs are found there, they
  98. dnl are almost assuredly the ones desired.
  99. AC_REQUIRE([AC_CANONICAL_HOST])
  100. libsubdirs="lib/${host_cpu}-${host_os} $libsubdirs"
  101. case ${host_cpu} in
  102. i?86)
  103. libsubdirs="lib/i386-${host_os} $libsubdirs"
  104. ;;
  105. esac
  106. dnl some arches may advertise a cpu type that doesn't line up with their
  107. dnl prefix's cpu type. For example, uname may report armv7l while libs are
  108. dnl installed to /usr/lib/arm-linux-gnueabihf. Try getting the compiler's
  109. dnl value for an extra chance of finding the correct path.
  110. libsubdirs="lib/`$CXX -dumpmachine 2>/dev/null` $libsubdirs"
  111. dnl first we check the system location for boost libraries
  112. dnl this location ist chosen if boost libraries are installed with the --layout=system option
  113. dnl or if you install boost with RPM
  114. if test "$ac_boost_path" != ""; then
  115. BOOST_CPPFLAGS="-I$ac_boost_path/include"
  116. for ac_boost_path_tmp in $libsubdirs; do
  117. if test -d "$ac_boost_path"/"$ac_boost_path_tmp" ; then
  118. BOOST_LDFLAGS="-L$ac_boost_path/$ac_boost_path_tmp"
  119. break
  120. fi
  121. done
  122. elif test "$cross_compiling" != yes; then
  123. for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
  124. if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
  125. for libsubdir in $libsubdirs ; do
  126. if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
  127. done
  128. BOOST_LDFLAGS="-L$ac_boost_path_tmp/$libsubdir"
  129. BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
  130. break;
  131. fi
  132. done
  133. fi
  134. dnl overwrite ld flags if we have required special directory with
  135. dnl --with-boost-libdir parameter
  136. if test "$ac_boost_lib_path" != ""; then
  137. BOOST_LDFLAGS="-L$ac_boost_lib_path"
  138. fi
  139. CPPFLAGS_SAVED="$CPPFLAGS"
  140. CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
  141. export CPPFLAGS
  142. LDFLAGS_SAVED="$LDFLAGS"
  143. LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
  144. export LDFLAGS
  145. AC_REQUIRE([AC_PROG_CXX])
  146. AC_LANG_PUSH(C++)
  147. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  148. @%:@include <boost/version.hpp>
  149. ]], [[
  150. #if BOOST_VERSION >= $WANT_BOOST_VERSION
  151. // Everything is okay
  152. #else
  153. # error Boost version is too old
  154. #endif
  155. ]])],[
  156. AC_MSG_RESULT(yes)
  157. succeeded=yes
  158. found_system=yes
  159. ],[
  160. ])
  161. AC_LANG_POP([C++])
  162. dnl if we found no boost with system layout we search for boost libraries
  163. dnl built and installed without the --layout=system option or for a staged(not installed) version
  164. if test "x$succeeded" != "xyes"; then
  165. CPPFLAGS="$CPPFLAGS_SAVED"
  166. LDFLAGS="$LDFLAGS_SAVED"
  167. BOOST_CPPFLAGS=
  168. BOOST_LDFLAGS=
  169. _version=0
  170. if test "$ac_boost_path" != ""; then
  171. if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
  172. for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
  173. _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
  174. V_CHECK=`expr $_version_tmp \> $_version`
  175. if test "$V_CHECK" = "1" ; then
  176. _version=$_version_tmp
  177. fi
  178. VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
  179. BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
  180. done
  181. dnl if nothing found search for layout used in Windows distributions
  182. if test -z "$BOOST_CPPFLAGS"; then
  183. if test -d "$ac_boost_path/boost" && test -r "$ac_boost_path/boost"; then
  184. BOOST_CPPFLAGS="-I$ac_boost_path"
  185. fi
  186. fi
  187. fi
  188. else
  189. if test "$cross_compiling" != yes; then
  190. for ac_boost_path in /usr /usr/local /opt /opt/local ; do
  191. if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
  192. for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
  193. _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
  194. V_CHECK=`expr $_version_tmp \> $_version`
  195. if test "$V_CHECK" = "1" ; then
  196. _version=$_version_tmp
  197. best_path=$ac_boost_path
  198. fi
  199. done
  200. fi
  201. done
  202. VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
  203. BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
  204. if test "$ac_boost_lib_path" = ""; then
  205. for libsubdir in $libsubdirs ; do
  206. if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
  207. done
  208. BOOST_LDFLAGS="-L$best_path/$libsubdir"
  209. fi
  210. fi
  211. if test "x$BOOST_ROOT" != "x"; then
  212. for libsubdir in $libsubdirs ; do
  213. if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
  214. done
  215. if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then
  216. version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
  217. stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
  218. stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
  219. V_CHECK=`expr $stage_version_shorten \>\= $_version`
  220. if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then
  221. AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
  222. BOOST_CPPFLAGS="-I$BOOST_ROOT"
  223. BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
  224. fi
  225. fi
  226. fi
  227. fi
  228. CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
  229. export CPPFLAGS
  230. LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
  231. export LDFLAGS
  232. AC_LANG_PUSH(C++)
  233. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  234. @%:@include <boost/version.hpp>
  235. ]], [[
  236. #if BOOST_VERSION >= $WANT_BOOST_VERSION
  237. // Everything is okay
  238. #else
  239. # error Boost version is too old
  240. #endif
  241. ]])],[
  242. AC_MSG_RESULT(yes)
  243. succeeded=yes
  244. found_system=yes
  245. ],[
  246. ])
  247. AC_LANG_POP([C++])
  248. fi
  249. if test "$succeeded" != "yes" ; then
  250. if test "$_version" = "0" ; then
  251. 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.]])
  252. else
  253. AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
  254. fi
  255. # execute ACTION-IF-NOT-FOUND (if present):
  256. ifelse([$3], , :, [$3])
  257. else
  258. AC_SUBST(BOOST_CPPFLAGS)
  259. AC_SUBST(BOOST_LDFLAGS)
  260. AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
  261. # execute ACTION-IF-FOUND (if present):
  262. ifelse([$2], , :, [$2])
  263. fi
  264. CPPFLAGS="$CPPFLAGS_SAVED"
  265. LDFLAGS="$LDFLAGS_SAVED"
  266. fi
  267. ])