Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 1 | # =========================================================================== |
| 2 | # http://www.gnu.org/software/autoconf-archive/ax_boost_base.html |
| 3 | # =========================================================================== |
David Reiss | 2d2aa14 | 2008-03-26 07:22:26 +0000 | [diff] [blame] | 4 | # |
| 5 | # SYNOPSIS |
| 6 | # |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 7 | # AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
David Reiss | 2d2aa14 | 2008-03-26 07:22:26 +0000 | [diff] [blame] | 8 | # |
| 9 | # DESCRIPTION |
| 10 | # |
| 11 | # Test for the Boost C++ libraries of a particular version (or newer) |
| 12 | # |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 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>. |
David Reiss | 2d2aa14 | 2008-03-26 07:22:26 +0000 | [diff] [blame] | 17 | # |
| 18 | # This macro calls: |
| 19 | # |
| 20 | # AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS) |
| 21 | # |
| 22 | # And sets: |
| 23 | # |
| 24 | # HAVE_BOOST |
| 25 | # |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 26 | # LICENSE |
David Reiss | 2d2aa14 | 2008-03-26 07:22:26 +0000 | [diff] [blame] | 27 | # |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 28 | # Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de> |
| 29 | # Copyright (c) 2009 Peter Adolphs |
David Reiss | 2d2aa14 | 2008-03-26 07:22:26 +0000 | [diff] [blame] | 30 | # |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 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 | |
| 36 | #serial 23 |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 37 | |
| 38 | AC_DEFUN([AX_BOOST_BASE], |
| 39 | [ |
| 40 | AC_ARG_WITH([boost], |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 41 | [AS_HELP_STRING([--with-boost@<:@=ARG@:>@], |
| 42 | [use Boost library from a standard location (ARG=yes), |
| 43 | from the specified location (ARG=<path>), |
| 44 | or disable it (ARG=no) |
| 45 | @<:@ARG=yes@:>@ ])], |
| 46 | [ |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 47 | if test "$withval" = "no"; then |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 48 | want_boost="no" |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 49 | elif test "$withval" = "yes"; then |
| 50 | want_boost="yes" |
| 51 | ac_boost_path="" |
| 52 | else |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 53 | want_boost="yes" |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 54 | ac_boost_path="$withval" |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 55 | fi |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 56 | ], |
Marc Slemko | 75c2f70 | 2007-01-17 07:59:38 +0000 | [diff] [blame] | 57 | [want_boost="yes"]) |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 58 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 59 | |
| 60 | AC_ARG_WITH([boost-libdir], |
| 61 | AS_HELP_STRING([--with-boost-libdir=LIB_DIR], |
| 62 | [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.]), |
| 63 | [ |
| 64 | if test -d "$withval" |
| 65 | then |
| 66 | ac_boost_lib_path="$withval" |
| 67 | else |
| 68 | AC_MSG_ERROR(--with-boost-libdir expected directory name) |
| 69 | fi |
| 70 | ], |
| 71 | [ac_boost_lib_path=""] |
| 72 | ) |
| 73 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 74 | if test "x$want_boost" = "xyes"; then |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 75 | boost_lib_version_req=ifelse([$1], ,1.20.0,$1) |
| 76 | boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'` |
| 77 | boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'` |
| 78 | boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'` |
| 79 | boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` |
| 80 | if test "x$boost_lib_version_req_sub_minor" = "x" ; then |
| 81 | boost_lib_version_req_sub_minor="0" |
| 82 | fi |
| 83 | WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor` |
| 84 | AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req) |
| 85 | succeeded=no |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 86 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 87 | dnl On 64-bit systems check for system libraries in both lib64 and lib. |
| 88 | dnl The former is specified by FHS, but e.g. Debian does not adhere to |
| 89 | dnl this (as it rises problems for generic multi-arch support). |
| 90 | dnl The last entry in the list is chosen by default when no libraries |
| 91 | dnl are found, e.g. when only header-only libraries are installed! |
| 92 | libsubdirs="lib" |
| 93 | ax_arch=`uname -m` |
| 94 | case $ax_arch in |
| 95 | x86_64|ppc64|s390x|sparc64|aarch64) |
| 96 | libsubdirs="lib64 lib lib64" |
| 97 | ;; |
| 98 | esac |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 99 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 100 | dnl allow for real multi-arch paths e.g. /usr/lib/x86_64-linux-gnu. Give |
| 101 | dnl them priority over the other paths since, if libs are found there, they |
| 102 | dnl are almost assuredly the ones desired. |
| 103 | AC_REQUIRE([AC_CANONICAL_HOST]) |
| 104 | libsubdirs="lib/${host_cpu}-${host_os} $libsubdirs" |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 105 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 106 | case ${host_cpu} in |
| 107 | i?86) |
| 108 | libsubdirs="lib/i386-${host_os} $libsubdirs" |
| 109 | ;; |
| 110 | esac |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 111 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 112 | dnl first we check the system location for boost libraries |
| 113 | dnl this location ist chosen if boost libraries are installed with the --layout=system option |
| 114 | dnl or if you install boost with RPM |
| 115 | if test "$ac_boost_path" != ""; then |
| 116 | BOOST_CPPFLAGS="-I$ac_boost_path/include" |
| 117 | for ac_boost_path_tmp in $libsubdirs; do |
| 118 | if test -d "$ac_boost_path"/"$ac_boost_path_tmp" ; then |
| 119 | BOOST_LDFLAGS="-L$ac_boost_path/$ac_boost_path_tmp" |
| 120 | break |
| 121 | fi |
| 122 | done |
| 123 | elif test "$cross_compiling" != yes; then |
jfarrell | 4d3f937 | 2014-10-08 23:35:05 -0400 | [diff] [blame] | 124 | for ac_boost_path_tmp in $lt_sysroot/usr $lt_sysroot/usr/local $lt_sysroot/opt $lt_sysroot/opt/local ; do |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 125 | if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then |
| 126 | for libsubdir in $libsubdirs ; do |
| 127 | if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi |
| 128 | done |
| 129 | BOOST_LDFLAGS="-L$ac_boost_path_tmp/$libsubdir" |
| 130 | BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include" |
| 131 | break; |
| 132 | fi |
| 133 | done |
| 134 | fi |
Christian Lavoie | 4f42ef7 | 2010-11-04 18:51:42 +0000 | [diff] [blame] | 135 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 136 | dnl overwrite ld flags if we have required special directory with |
| 137 | dnl --with-boost-libdir parameter |
| 138 | if test "$ac_boost_lib_path" != ""; then |
| 139 | BOOST_LDFLAGS="-L$ac_boost_lib_path" |
| 140 | fi |
| 141 | |
| 142 | CPPFLAGS_SAVED="$CPPFLAGS" |
| 143 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" |
| 144 | export CPPFLAGS |
| 145 | |
| 146 | LDFLAGS_SAVED="$LDFLAGS" |
| 147 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" |
| 148 | export LDFLAGS |
| 149 | |
| 150 | AC_REQUIRE([AC_PROG_CXX]) |
| 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 | ]])],[ |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 161 | AC_MSG_RESULT(yes) |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 162 | succeeded=yes |
| 163 | found_system=yes |
| 164 | ],[ |
| 165 | ]) |
| 166 | AC_LANG_POP([C++]) |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 167 | |
| 168 | |
| 169 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 170 | dnl if we found no boost with system layout we search for boost libraries |
| 171 | dnl built and installed without the --layout=system option or for a staged(not installed) version |
| 172 | if test "x$succeeded" != "xyes"; then |
| 173 | _version=0 |
| 174 | if test "$ac_boost_path" != ""; then |
| 175 | if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then |
| 176 | for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do |
| 177 | _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` |
| 178 | V_CHECK=`expr $_version_tmp \> $_version` |
| 179 | if test "$V_CHECK" = "1" ; then |
| 180 | _version=$_version_tmp |
| 181 | fi |
| 182 | VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` |
| 183 | BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE" |
| 184 | done |
| 185 | fi |
| 186 | else |
| 187 | if test "$cross_compiling" != yes; then |
jfarrell | 4d3f937 | 2014-10-08 23:35:05 -0400 | [diff] [blame] | 188 | for ac_boost_path in $lt_sysroot/usr $lt_sysroot/usr/local $lt_sysroot/opt $lt_sysroot/opt/local ; do |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 189 | if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then |
| 190 | for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do |
| 191 | _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` |
| 192 | V_CHECK=`expr $_version_tmp \> $_version` |
| 193 | if test "$V_CHECK" = "1" ; then |
| 194 | _version=$_version_tmp |
| 195 | best_path=$ac_boost_path |
| 196 | fi |
| 197 | done |
| 198 | fi |
| 199 | done |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 200 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 201 | VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` |
| 202 | BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE" |
| 203 | if test "$ac_boost_lib_path" = ""; then |
| 204 | for libsubdir in $libsubdirs ; do |
| 205 | if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi |
| 206 | done |
| 207 | BOOST_LDFLAGS="-L$best_path/$libsubdir" |
| 208 | fi |
| 209 | fi |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 210 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 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 |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 228 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 229 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" |
| 230 | export CPPFLAGS |
| 231 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" |
| 232 | export LDFLAGS |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 233 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 234 | AC_LANG_PUSH(C++) |
| 235 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ |
| 236 | @%:@include <boost/version.hpp> |
| 237 | ]], [[ |
| 238 | #if BOOST_VERSION >= $WANT_BOOST_VERSION |
| 239 | // Everything is okay |
| 240 | #else |
| 241 | # error Boost version is too old |
| 242 | #endif |
| 243 | ]])],[ |
| 244 | AC_MSG_RESULT(yes) |
| 245 | succeeded=yes |
| 246 | found_system=yes |
| 247 | ],[ |
| 248 | ]) |
| 249 | AC_LANG_POP([C++]) |
| 250 | fi |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 251 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 252 | if test "$succeeded" != "yes" ; then |
| 253 | if test "$_version" = "0" ; then |
| 254 | 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.]]) |
| 255 | else |
| 256 | AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).]) |
| 257 | fi |
| 258 | # execute ACTION-IF-NOT-FOUND (if present): |
| 259 | ifelse([$3], , :, [$3]) |
| 260 | else |
| 261 | AC_SUBST(BOOST_CPPFLAGS) |
| 262 | AC_SUBST(BOOST_LDFLAGS) |
| 263 | AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available]) |
| 264 | # execute ACTION-IF-FOUND (if present): |
| 265 | ifelse([$2], , :, [$2]) |
| 266 | fi |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 267 | |
Roger Meier | 73b58a2 | 2014-05-11 17:39:34 +0200 | [diff] [blame] | 268 | CPPFLAGS="$CPPFLAGS_SAVED" |
| 269 | LDFLAGS="$LDFLAGS_SAVED" |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 270 | fi |
| 271 | |
| 272 | ]) |