1# =========================================================================== 2# http://www.nongnu.org/autoconf-archive/ax_boost_base.html 3# =========================================================================== 4# 5# SYNOPSIS 6# 7# AX_BOOST_BASE([MINIMUM-VERSION]) 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# 30# Copying and distribution of this file, with or without modification, are 31# permitted in any medium without royalty provided the copyright notice 32# and this notice are preserved. 33 34AC_DEFUN([AX_BOOST_BASE], 35[ 36AC_ARG_WITH([boost], 37 AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is yes) - it is possible to specify the root directory for boost (optional)]), 38 [ 39 if test "$withval" = "no"; then 40 want_boost="no" 41 elif test "$withval" = "yes"; then 42 want_boost="yes" 43 ac_boost_path="" 44 else 45 want_boost="yes" 46 ac_boost_path="$withval" 47 fi 48 ], 49 [want_boost="yes"]) 50 51 52AC_ARG_WITH([boost-libdir], 53 AS_HELP_STRING([--with-boost-libdir=LIB_DIR], 54 [Force given directory for boost libraries. Note that this will overwrite library path detection, so use this parameter only if default library detection fails and you know exactly where your boost libraries are located.]), 55 [ 56 if test -d $withval 57 then 58 ac_boost_lib_path="$withval" 59 else 60 AC_MSG_ERROR(--with-boost-libdir expected directory name) 61 fi 62 ], 63 [ac_boost_lib_path=""] 64) 65 66if test "x$want_boost" = "xyes"; then 67 boost_lib_version_req=ifelse([$1], ,1.20.0,$1) 68 boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'` 69 boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'` 70 boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'` 71 boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` 72 if test "x$boost_lib_version_req_sub_minor" = "x" ; then 73 boost_lib_version_req_sub_minor="0" 74 fi 75 WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor` 76 AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req) 77 succeeded=no 78 79 dnl first we check the system location for boost libraries 80 dnl this location ist chosen if boost libraries are installed with the --layout=system option 81 dnl or if you install boost with RPM 82 if test "$ac_boost_path" != ""; then 83 BOOST_LDFLAGS="-L$ac_boost_path/lib" 84 BOOST_CPPFLAGS="-I$ac_boost_path/include" 85 else 86 for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do 87 if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then 88 BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib" 89 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include" 90 break; 91 fi 92 done 93 fi 94 95 dnl overwrite ld flags if we have required special directory with 96 dnl --with-boost-libdir parameter 97 if test "$ac_boost_lib_path" != ""; then 98 BOOST_LDFLAGS="-L$ac_boost_lib_path" 99 fi 100 101 CPPFLAGS_SAVED="$CPPFLAGS" 102 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 103 export CPPFLAGS 104 105 LDFLAGS_SAVED="$LDFLAGS" 106 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 107 export LDFLAGS 108 109 AC_LANG_PUSH(C++) 110 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 111 @%:@include <boost/version.hpp> 112 ]], [[ 113 #if BOOST_VERSION >= $WANT_BOOST_VERSION 114 // Everything is okay 115 #else 116 # error Boost version is too old 117 #endif 118 ]])],[ 119 AC_MSG_RESULT(yes) 120 succeeded=yes 121 found_system=yes 122 ],[ 123 ]) 124 AC_LANG_POP([C++]) 125 126 127 128 dnl if we found no boost with system layout we search for boost libraries 129 dnl built and installed without the --layout=system option or for a staged(not installed) version 130 if test "x$succeeded" != "xyes"; then 131 _version=0 132 if test "$ac_boost_path" != ""; then 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 fi 140 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` 141 BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE" 142 done 143 fi 144 else 145 for ac_boost_path in /usr /usr/local /opt /opt/local ; do 146 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then 147 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do 148 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` 149 V_CHECK=`expr $_version_tmp \> $_version` 150 if test "$V_CHECK" = "1" ; then 151 _version=$_version_tmp 152 best_path=$ac_boost_path 153 fi 154 done 155 fi 156 done 157 158 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` 159 BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE" 160 if test "$ac_boost_lib_path" = "" 161 then 162 BOOST_LDFLAGS="-L$best_path/lib" 163 fi 164 165 if test "x$BOOST_ROOT" != "x"; then 166 if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then 167 version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'` 168 stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'` 169 stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'` 170 V_CHECK=`expr $stage_version_shorten \>\= $_version` 171 if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then 172 AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT) 173 BOOST_CPPFLAGS="-I$BOOST_ROOT" 174 BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib" 175 fi 176 fi 177 fi 178 fi 179 180 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 181 export CPPFLAGS 182 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 183 export LDFLAGS 184 185 AC_LANG_PUSH(C++) 186 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 187 @%:@include <boost/version.hpp> 188 ]], [[ 189 #if BOOST_VERSION >= $WANT_BOOST_VERSION 190 // Everything is okay 191 #else 192 # error Boost version is too old 193 #endif 194 ]])],[ 195 AC_MSG_RESULT(yes) 196 succeeded=yes 197 found_system=yes 198 ],[ 199 ]) 200 AC_LANG_POP([C++]) 201 fi 202 203 if test "$succeeded" != "yes" ; then 204 if test "$_version" = "0" ; then 205 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.]]) 206 else 207 AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).]) 208 fi 209 else 210 AC_SUBST(BOOST_CPPFLAGS) 211 AC_SUBST(BOOST_LDFLAGS) 212 AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available]) 213 fi 214 215 CPPFLAGS="$CPPFLAGS_SAVED" 216 LDFLAGS="$LDFLAGS_SAVED" 217fi 218 219]) 220