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