1 # ===========================================================================
2 # http://autoconf-archive.cryp.to/ax_boost_base.html
3 # ===========================================================================
7 # AX_BOOST_BASE([MINIMUM-VERSION])
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)
32 # Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
33 # Copyright (c) 2008 Free Software Foundation, Inc.
35 # Copying and distribution of this file, with or without modification, are
36 # permitted in any medium without royalty provided the copyright notice
37 # and this notice are preserved.
39 AC_DEFUN([AX_BOOST_BASE],
41 AC_REQUIRE([GR_LIB64])
43 AS_HELP_STRING([--with-boost@<:@=DIR@:>@],
44 [use boost (default is yes) - it is possible to specify the root directory for boost (optional)]),
46 if test "$withval" = "no"; then
48 elif test "$withval" = "yes"; then
53 ac_boost_path="$withval"
59 AC_ARG_WITH([boost-libdir],
60 AS_HELP_STRING([--with-boost-libdir=LIB_DIR],
61 [Force given directory for boost libraries. Note that this
62 will overwrite library path detection, so use this parameter
63 only if default library detection fails and you know exactly
64 where your boost libraries are located.]),
68 ac_boost_lib_path="$withval"
70 AC_MSG_ERROR(--with-boost-libdir expected directory name)
73 [ac_boost_lib_path=""]
76 if test "x$want_boost" = "xyes"; then
77 boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
78 boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
79 boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
80 boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
81 boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
82 if test "x$boost_lib_version_req_sub_minor" = "x" ; then
83 boost_lib_version_req_sub_minor="0"
85 WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
86 AC_MSG_CHECKING(for boost >= $boost_lib_version_req)
89 dnl first we check the system location for boost libraries
90 dnl this location ist chosen if boost libraries are installed with the --layout=system option
91 dnl or if you install boost with RPM
92 if test "$ac_boost_path" != ""; then
93 dnl Look first where we think they ought to be, accounting for a possible "64" suffix on lib.
94 dnl If that directory doesn't exist, fall back to the default behavior
95 if test -d "$ac_boost_path/lib${gr_libdir_suffix}"; then
96 BOOST_LDFLAGS="-L$ac_boost_path/lib${gr_libdir_suffix}"
98 BOOST_LDFLAGS="-L$ac_boost_path/lib"
100 BOOST_CPPFLAGS="-I$ac_boost_path/include"
102 for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
103 if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
104 dnl Look first where we think they ought to be, accounting for a possible "64" suffix on lib.
105 dnl If that directory doesn't exist, fall back to the default behavior
106 if test -d "$ac_boost_path_tmp/lib${gr_libdir_suffix}"; then
107 BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib${gr_libdir_suffix}"
109 BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
111 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
117 dnl overwrite ld flags if we have required special directory with
118 dnl --with-boost-libdir parameter
119 if test "$ac_boost_lib_path" != ""; then
120 BOOST_LDFLAGS="-L$ac_boost_lib_path"
123 CPPFLAGS_SAVED="$CPPFLAGS"
124 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
127 LDFLAGS_SAVED="$LDFLAGS"
128 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
132 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
133 @%:@include <boost/version.hpp>
135 #if BOOST_VERSION >= $WANT_BOOST_VERSION
136 // Everything is okay
138 # error Boost version is too old
140 ]])],[AC_MSG_RESULT(yes)
146 CPPFLAGS="$CPPFLAGS_SAVED"
147 LDFLAGS="$LDFLAGS_SAVED"
150 dnl if we found no boost with system layout we search for boost libraries
151 dnl built and installed without the --layout=system option
152 if test "$succeeded" != "yes"; then
155 if test "$ac_boost_path" != ""; then
156 path_list="$ac_boost_path"
158 path_list="/usr /usr/local /opt /opt/local"
160 for ac_boost_path in $path_list ; do
161 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
162 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
163 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's,/include/boost-,,; s,_,.,'`
164 V_CHECK=`expr $_version_tmp \> $_version`
165 if test "$V_CHECK" = "1" ; then
166 _version=$_version_tmp
167 best_path=$ac_boost_path
173 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
174 BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
176 if test "$ac_boost_lib_path" = ""; then
177 dnl Look first where we think they ought to be, accounting for a possible "64" suffix on lib.
178 dnl If that directory doesn't exist, fall back to the default behavior
179 if test -d "$best_path/lib${gr_libdir_suffix}"; then
180 BOOST_LDFLAGS="-L$best_path/lib${gr_libdir_suffix}"
182 BOOST_LDFLAGS="-L$best_path/lib"
186 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
188 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
192 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
193 @%:@include <boost/version.hpp>
195 #if BOOST_VERSION >= $WANT_BOOST_VERSION
196 // Everything is okay
198 # error Boost version is too old
200 ]])],[AC_MSG_RESULT(yes)
206 CPPFLAGS="$CPPFLAGS_SAVED"
207 LDFLAGS="$LDFLAGS_SAVED"
210 if test "$succeeded" != "yes" ; then
212 if test "$_version" = "0" ; then
213 AC_MSG_ERROR([[we could not detect the boost libraries (version $boost_lib_version_req_shorten or higher).
214 If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>.]])
216 AC_MSG_ERROR([your boost libraries seem to old (version $_version).])
219 AC_SUBST(BOOST_CPPFLAGS)
220 AC_SUBST(BOOST_LDFLAGS)
221 AC_DEFINE(HAVE_BOOST,1,[Define if the Boost headers are available])
227 dnl Macros used by the boost items that need libraries.
230 dnl $1 is unit name. E.g., boost_thread
231 AC_DEFUN([_AX_BOOST_CHECK_LIB],[
232 _AX_BOOST_CHECK_LIB_($1,HAVE_[]m4_toupper($1),m4_toupper($1)_LIB)
235 dnl $1 is unit name. E.g., boost_thread
236 dnl $2 is AC_DEFINE name. E.g., HAVE_BOOST_THREAD
237 dnl $3 is lib var name. E.g., BOOST_THREAD_LIB
238 AC_DEFUN([_AX_BOOST_CHECK_LIB_],[
240 AC_DEFINE($2,1,[Define if the $1 library is available])
241 BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
243 dnl See if we can find a usable library
245 if test "$ax_boost_user_lib" != ""; then
246 dnl use what the user supplied
247 for ax_lib in $ax_boost_user_lib $1-${ax_boost_user_lib}; do
248 AC_CHECK_LIB($ax_lib, exit,
249 [$3="-l$ax_lib"; AC_SUBST($3) link_ok="yes"; break])
252 dnl Look in BOOSTLIBDIR for possible candidates
253 head=$BOOSTLIBDIR/lib[]$1
254 for f in ${head}*.so* ${head}*.a* ${head}*.dll* ${head}*.dylib; do
259 f=`echo $f | sed -e 's,.*/,,' -e 's,^lib,,'`
261 f=`echo $f | sed -e 's,\($1.*\)\.so.*$,\1,' -e 's,\($1.*\)\.a.*$,\1,' -e 's,\($1.*\)\.dll.*$,\1,' -e 's,\($1.*\)\.dylib.*$,\1,'`
265 AC_CHECK_LIB($ax_lib, exit,
266 [$3="-l$ax_lib"; AC_SUBST($3) link_ok="yes"; break])
270 if test "$link_ok" != "yes"; then
271 AC_MSG_ERROR([Could not link against lib[$1]!])
277 dnl $1 is unit name. E.g., boost_thread
278 AC_DEFUN([_AX_BOOST_WITH],[
279 _AX_BOOST_WITH_($1,m4_bpatsubst($1,_,-))
282 dnl $1 is unit name. E.g., boost_thread
283 dnl $2 is hyphenated unit name. E.g., boost-thread
284 AC_DEFUN([_AX_BOOST_WITH_],[
286 AC_HELP_STRING([--with-$2@<:@=special-lib@:>@],
287 [Use the m4_substr($1,6) library from boost. It is possible to specify a certain
288 library to the linker. E.g., --with-$2=$1-gcc41-mt-1_35]),
290 if test "$withval" = "no"; then
292 elif test "$withval" = "yes"; then
297 ax_boost_user_lib="$withval"
303 dnl $1 is unit name. E.g., boost_thread
304 dnl $2 is AC_LANG_PROGRAM argument 1
305 dnl $3 is AC_LANG_PROGRAM argument 2
306 dnl $4 is cv variable name. E.g., ax_cv_boost_thread
307 AC_DEFUN([_AX_BOOST_CHECK_],[
309 if test "$want_boost" = "yes"; then
310 AC_REQUIRE([AC_PROG_CC])
311 AC_REQUIRE([AC_PROG_CXX])
312 CPPFLAGS_SAVED="$CPPFLAGS"
313 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
314 LDFLAGS_SAVED="$LDFLAGS"
315 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
316 AC_CACHE_CHECK([whether the boost::m4_substr([$1],6) includes are available], [$4],
318 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$2],[$3]),[$4]=yes,[$4]=no)
321 if test "$[$4]" = "yes"; then
322 _AX_BOOST_CHECK_LIB([$1])
324 CPPFLAGS="$CPPFLAGS_SAVED"
325 LDFLAGS="$LDFLAGS_SAVED"
329 dnl $1 is unit name. E.g., boost_thread
330 dnl $2 is AC_LANG_PROGRAM argument 1
331 dnl $3 is AC_LANG_PROGRAM argument 2
332 AC_DEFUN([_AX_BOOST_CHECK],[
333 _AX_BOOST_CHECK_($1,$2,$3,ax_cv_$1)