1# =========================================================================== 2# http://www.gnu.org/software/autoconf-archive/ax_boost_base.html 3# =========================================================================== 4# 5# SYNOPSIS 6# 7# AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 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# Copyright (c) 2009 Peter Adolphs 30# 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 20 37 38AC_DEFUN([AX_BOOST_BASE], [ 39AC_ARG_WITH([boost], 40 [AS_HELP_STRING([--with-boost=PATH], [use Boost library from the specified location])], 41 [ac_boost_path="$withval"], 42 [ac_boost_path=""]) 43 44AC_ARG_WITH([boost-libdir], 45 AS_HELP_STRING([--with-boost-libdir=LIB_DIR], 46 [Force given directory for boost libraries. 47 Note that this will override library path detection, 48 so use this parameter only if default library 49 detection fails and you know exactly where your 50 boost libraries are located.]), 51 [ac_boost_lib_path="$withval"], 52 [ac_boost_lib_path=""]) 53 54boost_lib_version_req=ifelse([$1], ,1.20.0,$1) 55boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'` 56boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'` 57boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'` 58boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` 59if test "x$boost_lib_version_req_sub_minor" = "x"; then 60 boost_lib_version_req_sub_minor="0" 61fi 62WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor` 63AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req) 64succeeded=no 65 66dnl On 64-bit systems check for system libraries in both lib64 and lib. 67dnl The former is specified by FHS, but e.g. Debian does not adhere to 68dnl this (as it rises problems for generic multi-arch support). 69dnl The last entry in the list is chosen by default when no libraries 70dnl are found, e.g. when only header-only libraries are installed! 71libsubdirs="lib" 72ax_arch=`uname -m` 73if test $ax_arch = x86_64 -o $ax_arch = ppc64 -o $ax_arch = s390x -o $ax_arch = sparc64; then 74 libsubdirs="lib64 lib lib64" 75fi 76 77dnl first we check the system location for boost libraries 78dnl this location ist chosen if boost libraries are installed with the --layout=system option 79dnl or if you install boost with RPM 80if test "$ac_boost_path" != ""; then 81 BOOST_CPPFLAGS="-I$ac_boost_path/include" 82 for ac_boost_path_tmp in $libsubdirs; do 83 if test -d "$ac_boost_path"/"$ac_boost_path_tmp" ; then 84 BOOST_LDFLAGS="-L$ac_boost_path/$ac_boost_path_tmp" 85 break 86 fi 87 done 88elif test "$cross_compiling" != yes; then 89 for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do 90 if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then 91 for libsubdir in $libsubdirs ; do 92 if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi 93 done 94 BOOST_LDFLAGS="-L$ac_boost_path_tmp/$libsubdir" 95 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include" 96 break; 97 fi 98 done 99fi 100 101dnl overwrite ld flags if we have required special directory with 102dnl --with-boost-libdir parameter 103if test "$ac_boost_lib_path" != ""; then 104 BOOST_LDFLAGS="-L$ac_boost_lib_path" 105fi 106 107CPPFLAGS_SAVED="$CPPFLAGS" 108CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 109export CPPFLAGS 110 111LDFLAGS_SAVED="$LDFLAGS" 112LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 113export LDFLAGS 114 115AC_REQUIRE([AC_PROG_CXX]) 116AC_LANG_PUSH(C++) 117 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 118@%:@include <boost/version.hpp> 119]], [[ 120#if BOOST_VERSION >= $WANT_BOOST_VERSION 121// Everything is okay 122#else 123# error Boost version is too old 124#endif 125]])],[ 126 AC_MSG_RESULT(yes) 127succeeded=yes 128found_system=yes 129 ],[ 130 ]) 131AC_LANG_POP([C++]) 132 133dnl if we found no boost with system layout we search for boost libraries 134dnl built and installed without the --layout=system option or for a staged(not installed) version 135if test "x$succeeded" != "xyes"; then 136 _version=0 137 if test "$ac_boost_path" != ""; then 138 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then 139 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do 140 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` 141 V_CHECK=`expr $_version_tmp \> $_version` 142 if test "$V_CHECK" = "1" ; then 143 _version=$_version_tmp 144 fi 145 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` 146 BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE" 147 done 148 fi 149 else 150 if test "$cross_compiling" != yes; then 151 for ac_boost_path in /usr /usr/local /opt /opt/local ; do 152 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then 153 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do 154 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` 155 V_CHECK=`expr $_version_tmp \> $_version` 156 if test "$V_CHECK" = "1" ; then 157 _version=$_version_tmp 158 best_path=$ac_boost_path 159 fi 160 done 161 fi 162 done 163 164 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` 165 BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE" 166 if test "$ac_boost_lib_path" = ""; then 167 for libsubdir in $libsubdirs ; do 168 if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi 169 done 170 BOOST_LDFLAGS="-L$best_path/$libsubdir" 171 fi 172 fi 173 174 if test "x$BOOST_ROOT" != "x"; then 175 for libsubdir in $libsubdirs ; do 176 if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi 177 done 178 if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then 179 version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'` 180 stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'` 181 stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'` 182 V_CHECK=`expr $stage_version_shorten \>\= $_version` 183 if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then 184 AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT) 185 BOOST_CPPFLAGS="-I$BOOST_ROOT" 186 BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir" 187 fi 188 fi 189 fi 190 fi 191 192 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 193 export CPPFLAGS 194 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 195 export LDFLAGS 196 197 AC_LANG_PUSH(C++) 198 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 199 @%:@include <boost/version.hpp> 200 ]], [[ 201 #if BOOST_VERSION >= $WANT_BOOST_VERSION 202 // Everything is okay 203 #else 204 # error Boost version is too old 205 #endif 206 ]])],[ 207 AC_MSG_RESULT(yes) 208 succeeded=yes 209 found_system=yes 210 ],[ 211 ]) 212 AC_LANG_POP([C++]) 213fi 214 215if test "$succeeded" != "yes" ; then 216 if test "$_version" = "0" ; then 217 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.]]) 218 else 219 AC_MSG_ERROR([Your boost libraries seem too old (version $_version).]) 220 fi 221 # execute ACTION-IF-NOT-FOUND (if present): 222 ifelse([$3], , :, [$3]) 223else 224 BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` 225 AC_SUBST(BOOST_CPPFLAGS) 226 AC_SUBST(BOOST_LDFLAGS) 227 # execute ACTION-IF-FOUND (if present): 228 ifelse([$2], , :, [$2]) 229fi 230 231CPPFLAGS="$CPPFLAGS_SAVED" 232LDFLAGS="$LDFLAGS_SAVED" 233]) 234 235AC_DEFUN([AX_BOOST_LIB], [ 236AC_ARG_WITH([boost-$1], 237 AS_HELP_STRING([--with-boost-$1=LIBNAME], 238 [Override the name of the library for boost.$1 239 e.g. --with-boost-$1=boost_$1-gcc-mt]), 240 [ax_boost_lib="$withval"], 241 [ax_boost_lib="boost_$1"]) 242 243CPPFLAGS_SAVED="$CPPFLAGS" 244CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 245export CPPFLAGS 246 247LDFLAGS_SAVED="$LDFLAGS" 248LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 249export LDFLAGS 250 251AS_IF([test x$enable_sanity_checks != xno], 252 [AC_CHECK_LIB($ax_boost_lib, exit, [ax_boost_actual_lib="-l$ax_boost_lib"])], 253 [ax_boost_actual_lib="-l$ax_boost_lib"]) 254 255if test "x$ax_boost_actual_lib" = "x"; then 256 for lib in `ls -r $BOOSTLIBDIR/libboost_$1* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'`; do 257 ax_boost_lib=${lib} 258 AC_CHECK_LIB($ax_boost_lib, exit, [ax_boost_actual_lib="-l$ax_boost_lib"; break]) 259 done 260fi 261 262if test "x$ax_boost_actual_lib" = "x"; then 263 for lib in `ls -r $BOOSTLIBDIR/boost_$1* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do 264 ax_boost_lib=${lib} 265 AC_CHECK_LIB($ax_boost_lib, exit, [ax_boost_actual_lib="-l$ax_boost_lib"; break]) 266 done 267fi 268 269if test "x$ax_boost_actual_lib" = "x"; then 270 AC_MSG_ERROR(Could not find a working version of the library!) 271fi 272 273eval $2="$ax_boost_actual_lib" 274AC_SUBST($2) 275CPPFLAGS="$CPPFLAGS_SAVED" 276LDFLAGS="$LDFLAGS_SAVED" 277]) 278 279