David Reiss | 2d2aa14 | 2008-03-26 07:22:26 +0000 | [diff] [blame] | 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, /opt and /opt/local and evaluates |
| 13 | # the $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-07-28 |
David Reiss | ef5e81b | 2010-08-31 16:51:28 +0000 | [diff] [blame] | 27 | # Modified for use in Thrift |
David Reiss | 2d2aa14 | 2008-03-26 07:22:26 +0000 | [diff] [blame] | 28 | # |
| 29 | # COPYLEFT |
| 30 | # |
| 31 | # Copyright (c) 2007 Thomas Porschberg <thomas@randspringer.de> |
| 32 | # |
| 33 | # Copying and distribution of this file, with or without |
| 34 | # modification, are permitted in any medium without royalty provided |
| 35 | # the copyright notice and this notice are preserved. |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 36 | |
| 37 | AC_DEFUN([AX_BOOST_BASE], |
| 38 | [ |
| 39 | AC_ARG_WITH([boost], |
Jake Farrell | 2fd8a15 | 2012-09-29 00:26:36 +0000 | [diff] [blame] | 40 | AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost [default=yes]. Optionally specify the root prefix dir where boost is installed]), |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 41 | [ |
| 42 | if test "$withval" = "no"; then |
| 43 | want_boost="no" |
| 44 | elif test "$withval" = "yes"; then |
| 45 | want_boost="yes" |
| 46 | ac_boost_path="" |
| 47 | else |
David Reiss | 2d2aa14 | 2008-03-26 07:22:26 +0000 | [diff] [blame] | 48 | want_boost="yes" |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 49 | ac_boost_path="$withval" |
| 50 | fi |
| 51 | ], |
Marc Slemko | 75c2f70 | 2007-01-17 07:59:38 +0000 | [diff] [blame] | 52 | [want_boost="yes"]) |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 53 | |
| 54 | if test "x$want_boost" = "xyes"; then |
| 55 | boost_lib_version_req=ifelse([$1], ,1.20.0,$1) |
| 56 | boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'` |
| 57 | boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'` |
| 58 | boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'` |
| 59 | boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` |
| 60 | if test "x$boost_lib_version_req_sub_minor" = "x" ; then |
| 61 | boost_lib_version_req_sub_minor="0" |
| 62 | fi |
| 63 | WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor` |
| 64 | AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req) |
| 65 | succeeded=no |
| 66 | |
| 67 | dnl first we check the system location for boost libraries |
| 68 | dnl this location ist chosen if boost libraries are installed with the --layout=system option |
| 69 | dnl or if you install boost with RPM |
| 70 | if test "$ac_boost_path" != ""; then |
| 71 | BOOST_LDFLAGS="-L$ac_boost_path/lib" |
| 72 | BOOST_CPPFLAGS="-I$ac_boost_path/include" |
Christian Lavoie | 4f42ef7 | 2010-11-04 18:51:42 +0000 | [diff] [blame] | 73 | BOOST_ROOT_PATH="$ac_boost_path" |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 74 | else |
David Reiss | 2d2aa14 | 2008-03-26 07:22:26 +0000 | [diff] [blame] | 75 | for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 76 | if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then |
| 77 | BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib" |
| 78 | BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include" |
Christian Lavoie | 4f42ef7 | 2010-11-04 18:51:42 +0000 | [diff] [blame] | 79 | BOOST_ROOT_PATH="$ac_boost_path_tmp" |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 80 | break; |
| 81 | fi |
| 82 | done |
| 83 | fi |
| 84 | |
| 85 | CPPFLAGS_SAVED="$CPPFLAGS" |
| 86 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" |
| 87 | export CPPFLAGS |
| 88 | |
| 89 | LDFLAGS_SAVED="$LDFLAGS" |
| 90 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" |
| 91 | export LDFLAGS |
| 92 | |
Christian Lavoie | 4f42ef7 | 2010-11-04 18:51:42 +0000 | [diff] [blame] | 93 | export BOOST_ROOT_PATH |
| 94 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 95 | AC_LANG_PUSH(C++) |
| 96 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ |
| 97 | @%:@include <boost/version.hpp> |
| 98 | ]], [[ |
| 99 | #if BOOST_VERSION >= $WANT_BOOST_VERSION |
| 100 | // Everything is okay |
| 101 | #else |
| 102 | # error Boost version is too old |
| 103 | #endif |
| 104 | ]])],[ |
| 105 | AC_MSG_RESULT(yes) |
| 106 | succeeded=yes |
| 107 | found_system=yes |
| 108 | ],[ |
| 109 | ]) |
| 110 | AC_LANG_POP([C++]) |
| 111 | |
| 112 | |
| 113 | |
| 114 | dnl if we found no boost with system layout we search for boost libraries |
| 115 | dnl built and installed without the --layout=system option or for a staged(not installed) version |
| 116 | if test "x$succeeded" != "xyes"; then |
| 117 | _version=0 |
| 118 | if test "$ac_boost_path" != ""; then |
| 119 | BOOST_LDFLAGS="-L$ac_boost_path/lib" |
| 120 | if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then |
| 121 | for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do |
| 122 | _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` |
| 123 | V_CHECK=`expr $_version_tmp \> $_version` |
| 124 | if test "$V_CHECK" = "1" ; then |
| 125 | _version=$_version_tmp |
| 126 | fi |
| 127 | VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` |
| 128 | BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE" |
| 129 | done |
| 130 | fi |
| 131 | else |
David Reiss | 2d2aa14 | 2008-03-26 07:22:26 +0000 | [diff] [blame] | 132 | for ac_boost_path in /usr /usr/local /opt /opt/local ; do |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 133 | if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then |
| 134 | for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do |
| 135 | _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` |
| 136 | V_CHECK=`expr $_version_tmp \> $_version` |
| 137 | if test "$V_CHECK" = "1" ; then |
| 138 | _version=$_version_tmp |
| 139 | best_path=$ac_boost_path |
| 140 | fi |
| 141 | done |
| 142 | fi |
| 143 | done |
| 144 | |
| 145 | VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` |
| 146 | BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE" |
| 147 | BOOST_LDFLAGS="-L$best_path/lib" |
Christian Lavoie | 4f42ef7 | 2010-11-04 18:51:42 +0000 | [diff] [blame] | 148 | BOOST_ROOT_PATH="$best_path" |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 149 | |
| 150 | if test "x$BOOST_ROOT" != "x"; then |
| 151 | if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then |
| 152 | version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'` |
| 153 | stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'` |
| 154 | stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'` |
| 155 | V_CHECK=`expr $stage_version_shorten \>\= $_version` |
| 156 | if test "$V_CHECK" = "1" ; then |
| 157 | AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT) |
| 158 | BOOST_CPPFLAGS="-I$BOOST_ROOT" |
| 159 | BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib" |
Christian Lavoie | 4f42ef7 | 2010-11-04 18:51:42 +0000 | [diff] [blame] | 160 | BOOST_ROOT_PATH="$BOOST_ROOT" |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 161 | fi |
| 162 | fi |
| 163 | fi |
| 164 | fi |
| 165 | |
| 166 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" |
| 167 | export CPPFLAGS |
| 168 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" |
| 169 | export LDFLAGS |
Christian Lavoie | 4f42ef7 | 2010-11-04 18:51:42 +0000 | [diff] [blame] | 170 | export BOOST_ROOT_PATH |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 171 | |
| 172 | AC_LANG_PUSH(C++) |
| 173 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ |
| 174 | @%:@include <boost/version.hpp> |
| 175 | ]], [[ |
| 176 | #if BOOST_VERSION >= $WANT_BOOST_VERSION |
| 177 | // Everything is okay |
| 178 | #else |
| 179 | # error Boost version is too old |
| 180 | #endif |
| 181 | ]])],[ |
| 182 | AC_MSG_RESULT(yes) |
| 183 | succeeded=yes |
| 184 | found_system=yes |
| 185 | ],[ |
| 186 | ]) |
| 187 | AC_LANG_POP([C++]) |
| 188 | fi |
| 189 | |
| 190 | if test "$succeeded" != "yes" ; then |
| 191 | if test "$_version" = "0" ; then |
David Reiss | ef5e81b | 2010-08-31 16:51:28 +0000 | [diff] [blame] | 192 | AC_MSG_WARN([[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.]]) |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 193 | else |
David Reiss | ef5e81b | 2010-08-31 16:51:28 +0000 | [diff] [blame] | 194 | AC_MSG_WARN([Your boost libraries seems to old (version $_version).]) |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 195 | fi |
| 196 | else |
| 197 | AC_SUBST(BOOST_CPPFLAGS) |
| 198 | AC_SUBST(BOOST_LDFLAGS) |
Christian Lavoie | 4f42ef7 | 2010-11-04 18:51:42 +0000 | [diff] [blame] | 199 | AC_SUBST(BOOST_ROOT_PATH) |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 200 | AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available]) |
| 201 | fi |
| 202 | |
| 203 | CPPFLAGS="$CPPFLAGS_SAVED" |
| 204 | LDFLAGS="$LDFLAGS_SAVED" |
| 205 | fi |
| 206 | |
| 207 | ]) |