ax_boost_base.m4 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. ##### http://autoconf-archive.cryp.to/ax_boost_base.html
  2. #
  3. # SYNOPSIS
  4. #
  5. # AX_BOOST_BASE([MINIMUM-VERSION])
  6. #
  7. # DESCRIPTION
  8. #
  9. # Test for the Boost C++ libraries of a particular version (or newer)
  10. #
  11. # If no path to the installed boost library is given the macro
  12. # searchs under /usr, /usr/local, and /opt, and evaluates the
  13. # $BOOST_ROOT environment variable. Further documentation is
  14. # available at <http://randspringer.de/boost/index.html>.
  15. #
  16. # This macro calls:
  17. #
  18. # AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
  19. #
  20. # And sets:
  21. #
  22. # HAVE_BOOST
  23. #
  24. # LAST MODIFICATION
  25. #
  26. # 2007-03-15
  27. #
  28. # COPYLEFT
  29. #
  30. # Copyright (c) 2007 Thomas Porschberg <[email protected]>
  31. #
  32. # Copying and distribution of this file, with or without
  33. # modification, are permitted in any medium without royalty provided
  34. # the copyright notice and this notice are preserved.
  35. AC_DEFUN([AX_BOOST_BASE],
  36. [
  37. AC_ARG_WITH([boost],
  38. AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is yes) - it is possible to specify the root directory for boost (optional)]),
  39. [
  40. if test "$withval" = "no"; then
  41. want_boost="no"
  42. elif test "$withval" = "yes"; then
  43. want_boost="yes"
  44. ac_boost_path=""
  45. else
  46. want_boost="yes"
  47. ac_boost_path="$withval"
  48. fi
  49. ],
  50. [want_boost="yes"])
  51. if test "x$want_boost" = "xyes"; then
  52. boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
  53. boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
  54. boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
  55. boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
  56. boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  57. if test "x$boost_lib_version_req_sub_minor" = "x" ; then
  58. boost_lib_version_req_sub_minor="0"
  59. fi
  60. WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
  61. AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
  62. succeeded=no
  63. dnl first we check the system location for boost libraries
  64. dnl this location ist chosen if boost libraries are installed with the --layout=system option
  65. dnl or if you install boost with RPM
  66. if test "$ac_boost_path" != ""; then
  67. BOOST_LDFLAGS="-L$ac_boost_path/lib"
  68. BOOST_CPPFLAGS="-I$ac_boost_path/include"
  69. else
  70. for ac_boost_path_tmp in /usr /usr/local /opt ; do
  71. if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
  72. BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
  73. BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
  74. break;
  75. fi
  76. done
  77. fi
  78. CPPFLAGS_SAVED="$CPPFLAGS"
  79. CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
  80. export CPPFLAGS
  81. LDFLAGS_SAVED="$LDFLAGS"
  82. LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
  83. export LDFLAGS
  84. AC_LANG_PUSH(C++)
  85. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  86. @%:@include <boost/version.hpp>
  87. ]], [[
  88. #if BOOST_VERSION >= $WANT_BOOST_VERSION
  89. // Everything is okay
  90. #else
  91. # error Boost version is too old
  92. #endif
  93. ]])],[
  94. AC_MSG_RESULT(yes)
  95. succeeded=yes
  96. found_system=yes
  97. ],[
  98. ])
  99. AC_LANG_POP([C++])
  100. dnl if we found no boost with system layout we search for boost libraries
  101. dnl built and installed without the --layout=system option or for a staged(not installed) version
  102. if test "x$succeeded" != "xyes"; then
  103. _version=0
  104. if test "$ac_boost_path" != ""; then
  105. BOOST_LDFLAGS="-L$ac_boost_path/lib"
  106. if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
  107. for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
  108. _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
  109. V_CHECK=`expr $_version_tmp \> $_version`
  110. if test "$V_CHECK" = "1" ; then
  111. _version=$_version_tmp
  112. fi
  113. VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
  114. BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
  115. done
  116. fi
  117. else
  118. for ac_boost_path in /usr /usr/local /opt ; do
  119. if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
  120. for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
  121. _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
  122. V_CHECK=`expr $_version_tmp \> $_version`
  123. if test "$V_CHECK" = "1" ; then
  124. _version=$_version_tmp
  125. best_path=$ac_boost_path
  126. fi
  127. done
  128. fi
  129. done
  130. VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
  131. BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
  132. BOOST_LDFLAGS="-L$best_path/lib"
  133. if test "x$BOOST_ROOT" != "x"; then
  134. if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then
  135. version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
  136. stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
  137. stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
  138. V_CHECK=`expr $stage_version_shorten \>\= $_version`
  139. if test "$V_CHECK" = "1" ; then
  140. AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
  141. BOOST_CPPFLAGS="-I$BOOST_ROOT"
  142. BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib"
  143. fi
  144. fi
  145. fi
  146. fi
  147. CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
  148. export CPPFLAGS
  149. LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
  150. export LDFLAGS
  151. AC_LANG_PUSH(C++)
  152. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  153. @%:@include <boost/version.hpp>
  154. ]], [[
  155. #if BOOST_VERSION >= $WANT_BOOST_VERSION
  156. // Everything is okay
  157. #else
  158. # error Boost version is too old
  159. #endif
  160. ]])],[
  161. AC_MSG_RESULT(yes)
  162. succeeded=yes
  163. found_system=yes
  164. ],[
  165. ])
  166. AC_LANG_POP([C++])
  167. fi
  168. if test "$succeeded" != "yes" ; then
  169. if test "$_version" = "0" ; then
  170. AC_MSG_ERROR([[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.]])
  171. else
  172. AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
  173. fi
  174. else
  175. AC_SUBST(BOOST_CPPFLAGS)
  176. AC_SUBST(BOOST_LDFLAGS)
  177. AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
  178. fi
  179. CPPFLAGS="$CPPFLAGS_SAVED"
  180. LDFLAGS="$LDFLAGS_SAVED"
  181. fi
  182. ])