1 # ===========================================================================
2 # http://autoconf-archive.cryp.to/ax_boost_base.html
3 # ===========================================================================
7 # AX_BOOST_BASE([MINIMUM-VERSION],[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
11 # Test for the Boost C++ libraries of a particular version (or newer)
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>.
20 # AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
28 # 2008-04-12 - original
29 # 2008-06-13 - AIF/AINF parameters
33 # Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
35 # Copyright (c) 2008 Roman Rybalko <libtorrent@romanr.info> (under RbLibtorrent project)
36 # (ACTION-IF-FOUND/ACTION-IF-NOT-FOUND options, re-enterability fixes)
38 # Copying and distribution of this file, with or without modification, are
39 # permitted in any medium without royalty provided the copyright notice
40 # and this notice are preserved.
42 AC_DEFUN([AX_BOOST_BASE],
45 AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is yes) - it is possible to specify the root directory for boost (optional)]),
47 if test "$withval" = "no"; then
49 elif test "$withval" = "yes"; then
54 ac_boost_path="$withval"
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 overwrite library path detection, so use this parameter only if default library detection fails and you know exactly where your boost libraries are located.]),
66 ac_boost_lib_path="$withval"
68 AC_MSG_ERROR(--with-boost-libdir expected directory name)
71 [ac_boost_lib_path=""]
74 if test "x$want_boost" = "xyes"; then
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"
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)
87 dnl first we check the system location for boost libraries
88 dnl this location ist chosen if boost libraries are installed with the --layout=system option
89 dnl or if you install boost with RPM
90 if test "$ac_boost_path" != ""; then
91 BOOST_LDFLAGS="-L$ac_boost_path/lib"
92 BOOST_CPPFLAGS="-I$ac_boost_path/include"
94 for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
95 if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
96 BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
97 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
103 dnl overwrite ld flags if we have required special directory with
104 dnl --with-boost-libdir parameter
105 if test "$ac_boost_lib_path" != ""; then
106 BOOST_LDFLAGS="-L$ac_boost_lib_path"
109 CPPFLAGS_SAVED="$CPPFLAGS"
110 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
113 LDFLAGS_SAVED="$LDFLAGS"
114 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
118 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
119 @%:@include <boost/version.hpp>
121 #if BOOST_VERSION >= $WANT_BOOST_VERSION
122 // Everything is okay
124 # error Boost version is too old
136 dnl if we found no boost with system layout we search for boost libraries
137 dnl built and installed without the --layout=system option or for a staged(not installed) version
138 if test "x$succeeded" != "xyes"; then
140 if test "$ac_boost_path" != ""; then
141 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
142 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
143 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
144 V_CHECK=`expr $_version_tmp \> $_version`
145 if test "$V_CHECK" = "1" ; then
146 _version=$_version_tmp
148 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
149 BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
153 for ac_boost_path in /usr /usr/local /opt /opt/local ; do
154 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
155 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
156 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
157 V_CHECK=`expr $_version_tmp \> $_version`
158 if test "$V_CHECK" = "1" ; then
159 _version=$_version_tmp
160 best_path=$ac_boost_path
166 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
167 BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
168 if test "$ac_boost_lib_path" = ""
170 BOOST_LDFLAGS="-L$best_path/lib"
173 if test "x$BOOST_ROOT" != "x"; then
174 if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then
175 version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
176 stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
177 stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
178 V_CHECK=`expr $stage_version_shorten \>\= $_version`
179 if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then
180 AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
181 BOOST_CPPFLAGS="-I$BOOST_ROOT"
182 BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib"
188 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
190 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
194 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
195 @%:@include <boost/version.hpp>
197 #if BOOST_VERSION >= $WANT_BOOST_VERSION
198 // Everything is okay
200 # error Boost version is too old
211 CPPFLAGS="$CPPFLAGS_SAVED"
212 LDFLAGS="$LDFLAGS_SAVED"
213 unset ac_boost_path # re-enterability
215 if test "$succeeded" != "yes" ; then
217 if test "$_version" = "0" ; then
218 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.]])
220 AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
228 AC_SUBST(BOOST_CPPFLAGS)
229 AC_SUBST(BOOST_LDFLAGS)
230 AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])