1 dnl @synopsis AX_BOOST([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
3 dnl Test for the Boost C++ libraries of a particular version (or newer)
5 dnl If no path to the installed boost library is given the macro
6 dnl searchs under /usr, /usr/local, and /opt, and evaluates the
7 dnl $BOOST_ROOT environment variable.
9 dnl http://autoconf-archive.cryp.to/ax_boost.m4
13 dnl AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
14 dnl AC_SUBST(BOOST_FILESYSTEM_LIB)
15 dnl AC_SUBST(BOOST_PROGRAM_OPTIONS_LIB)
16 dnl AC_SUBST(BOOST_THREAD_LIB)
17 dnl AC_SUBST(BOOST_IOSTREAMS_LIB)
18 dnl AC_SUBST(BOOST_SERIALIZATION_LIB)
19 dnl AC_SUBST(BOOST_WSERIALIZATION_LIB)
20 dnl AC_SUBST(BOOST_SIGNALS_LIB)
21 dnl AC_SUBST(BOOST_DATE_TIME_LIB)
22 dnl AC_SUBST(BOOST_REGEX_LIB)
23 dnl AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
28 dnl HAVE_BOOST_FILESYSTEM
29 dnl HAVE_BOOST_PROGRAM_OPTIONS
31 dnl HAVE_BOOST_IOSTREAMS
32 dnl HAVE_BOOST_SERIALIZATION
33 dnl HAVE_BOOST_SIGNALS
34 dnl HAVE_BOOST_DATE_TIME
36 dnl HAVE_BOOST_UNIT_TEST_FRAMEWORK
38 dnl @category InstalledPackages
39 dnl @author Thomas Porschberg <thomas@randspringer.de>
40 dnl @version 2006-01-02
41 dnl @license AllPermissive
46 AC_HELP_STRING([--with-boost=DIR],
47 [use boost (default is NO) , specify the root directory for boost library (optional)]),
49 if test "$withval" = "no"; then
51 elif test "$withval" = "yes"; then
56 ac_boost_path="$withval"
62 if test "x$want_boost" = "xyes"; then
63 boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
64 boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
65 boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
66 boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
67 boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
68 if test "x$boost_lib_version_req_sub_minor" = "x" ; then
69 boost_lib_version_req_sub_minor="0"
71 WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
72 AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
75 dnl first we check the system location for boost libraries
76 dnl this location ist chosen if boost libraries are installed with the --layout=system option
77 dnl or if you install boost with RPM
78 if test "$ac_boost_path" != ""; then
79 BOOST_LDFLAGS="-L$ac_boost_path/lib"
80 BOOST_CPPFLAGS="-I$ac_boost_path/include"
82 for ac_boost_path_tmp in /usr /usr/local /opt ; do
83 if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
84 BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
85 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
91 CPPFLAGS_SAVED="$CPPFLAGS"
92 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
95 LDFLAGS_SAVED="$LDFLAGS"
96 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
101 @%:@include <boost/version.hpp>
104 #if BOOST_VERSION >= $WANT_BOOST_VERSION
105 // Everything is okay
107 # error Boost version is too old
115 ifelse([$2], , :, [$2])
120 dnl if we found no boost with system layout we search for boost libraries
121 dnl built and installed without the --layout=system option or for a staged(not installed) version
122 if test "x$succeeded" != "xyes"; then
124 if test "$ac_boost_path" != ""; then
125 BOOST_LDFLAGS="-L$ac_boost_path/lib"
126 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
127 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
128 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
129 V_CHECK=`expr $_version_tmp \> $_version`
130 if test "$V_CHECK" = "1" ; then
131 _version=$_version_tmp
133 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
134 BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
138 for ac_boost_path in /usr /usr/local /opt ; do
139 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
140 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
141 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
142 V_CHECK=`expr $_version_tmp \> $_version`
143 if test "$V_CHECK" = "1" ; then
144 _version=$_version_tmp
145 best_path=$ac_boost_path
151 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
152 BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
153 BOOST_LDFLAGS="-L$best_path/lib"
155 if test "x$BOOST_ROOT" != "x"; then
156 if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT"; then
157 version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
158 stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
159 stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
160 V_CHECK=`expr $stage_version_shorten \>\= $_version`
161 if test "$V_CHECK" = "1" ; then
162 AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
163 BOOST_CPPFLAGS="-I$BOOST_ROOT"
164 BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib"
170 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
172 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
177 @%:@include <boost/version.hpp>
180 #if BOOST_VERSION >= $WANT_BOOST_VERSION
181 // Everything is okay
183 # error Boost version is too old
188 AC_MSG_RESULT(yes ($_version))
190 ifelse([$2], , :, [$2])
193 AC_MSG_RESULT(no ($_version))
194 ifelse([$3], , :, [$3])
198 if test "$succeeded" != "yes" ; then
199 if test "$_version" = "0" ; then
200 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>.]])
202 AC_MSG_ERROR('Your boost libraries seems to old (version $_version). We need at least $boost_lib_version_shorten')
205 AC_SUBST(BOOST_CPPFLAGS)
206 AC_SUBST(BOOST_LDFLAGS)
207 AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
209 AC_CACHE_CHECK([whether the Boost::Filesystem library is available],
210 ax_cv_boost_filesystem,
213 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/filesystem/path.hpp>]],
214 [[using namespace boost::filesystem;
215 path my_path( "foo/bar/data.txt" );
217 ax_cv_boost_filesystem=yes, ax_cv_boost_filesystem=no)
220 if test "$ax_cv_boost_filesystem" = "yes"; then
221 AC_DEFINE(HAVE_BOOST_FILESYSTEM,,[define if the Boost::FILESYSTEM library is available])
223 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
224 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
225 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
226 AC_CHECK_LIB($ax_lib, main,
227 [BOOST_FILESYSTEM_LIB="-l$ax_lib" AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes" break],
228 [link_filesystem="no"])
230 if test "x$link_filesystem" = "xno"; then
231 AC_MSG_NOTICE(Could not link against $ax_lib !)
235 AC_CACHE_CHECK([whether the Boost::Program_Options library is available],
236 ax_cv_boost_program_options,
239 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/program_options.hpp>]],
240 [[boost::program_options::options_description generic("Generic options");
242 ax_cv_boost_program_options=yes, ax_cv_boost_program_options=no)
245 if test "$ax_cv_boost_program_options" = yes; then
246 AC_DEFINE(HAVE_BOOST_PROGRAM_OPTIONS,,[define if the Boost::PROGRAM_OPTIONS library is available])
247 BN=boost_program_options
248 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
249 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
250 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
251 AC_CHECK_LIB($ax_lib, main,
252 [BOOST_PROGRAM_OPTIONS_LIB="-l$ax_lib" AC_SUBST(BOOST_PROGRAM_OPTIONS_LIB) link_program_options="yes" break],
253 [link_program_options="no"])
255 if test "x$link_program_options="no"" = "xno"; then
256 AC_MSG_NOTICE(Could not link against $ax_lib !)
260 AC_CACHE_CHECK(whether the Boost::Thread library is available,
264 CXXFLAGS_SAVE=$CXXFLAGS
266 if test "x$build_os" = "xsolaris" ; then
267 CXXFLAGS="-pthreads $CXXFLAGS"
268 elif test "x$build_os" = "xming32" ; then
269 CXXFLAGS="-mthreads $CXXFLAGS"
271 CXXFLAGS="-pthread $CXXFLAGS"
273 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/thread/thread.hpp>]],
274 [[boost::thread_group thrds;
276 ax_cv_boost_thread=yes, ax_cv_boost_thread=no)
277 CXXFLAGS=$CXXFLAGS_SAVE
280 if test "x$ax_cv_boost_thread" = "xyes"; then
281 if test "x$build_os" = "xsolaris" ; then
282 BOOST_CPPFLAGS="-pthreads $BOOST_CPPFLAGS"
283 elif test "x$build_os" = "xming32" ; then
284 BOOST_CPPFLAGS="-mthreads $BOOST_CPPFLAGS"
286 BOOST_CPPFLAGS="-pthread $BOOST_CPPFLAGS"
289 AC_SUBST(BOOST_CPPFLAGS)
290 AC_DEFINE(HAVE_BOOST_THREAD,,[define if the Boost::THREAD library is available])
292 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
293 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
294 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
295 AC_CHECK_LIB($ax_lib, main, [BOOST_THREAD_LIB="-l$ax_lib" AC_SUBST(BOOST_THREAD_LIB) link_thread="yes" break],
298 if test "x$link_thread" = "xno"; then
299 AC_MSG_NOTICE(Could not link against $ax_lib !)
303 AC_CACHE_CHECK(whether the Boost::IOStreams library is available,
304 ax_cv_boost_iostreams,
307 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/iostreams/filtering_stream.hpp>
308 @%:@include <boost/range/iterator_range.hpp>
310 [[std::string input = "Hello World!";
311 namespace io = boost::iostreams;
312 io::filtering_istream in(boost::make_iterator_range(input));
315 ax_cv_boost_iostreams=yes, ax_cv_boost_iostreams=no)
318 if test "x$ax_cv_boost_iostreams" = "xyes"; then
319 AC_DEFINE(HAVE_BOOST_IOSTREAMS,,[define if the Boost::IOStreams library is available])
321 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
322 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
323 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
324 AC_CHECK_LIB($ax_lib, main, [BOOST_IOSTREAMS_LIB="-l$ax_lib" AC_SUBST(BOOST_IOSTREAMS_LIB) link_thread="yes" break],
327 if test "x$link_thread" = "xno"; then
328 AC_MSG_NOTICE(Could not link against $ax_lib !)
332 AC_CACHE_CHECK(whether the Boost::Serialization library is available,
333 ax_cv_boost_serialization,
336 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <fstream>
337 @%:@include <boost/archive/text_oarchive.hpp>
338 @%:@include <boost/archive/text_iarchive.hpp>
340 [[std::ofstream ofs("filename");
341 boost::archive::text_oarchive oa(ofs);
344 ax_cv_boost_serialization=yes, ax_cv_boost_serialization=no)
347 if test "x$ax_cv_boost_serialization" = "xyes"; then
348 AC_DEFINE(HAVE_BOOST_SERIALIZATION,,[define if the Boost::Serialization library is available])
349 BN=boost_serialization
350 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
351 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
352 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
353 AC_CHECK_LIB($ax_lib, main,
354 [BOOST_SERIALIZATION_LIB="-l$ax_lib" AC_SUBST(BOOST_SERIALIZATION_LIB) link_thread="yes" break],
357 BN=boost_wserialization
358 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
359 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
360 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
361 AC_CHECK_LIB($ax_lib, main,
362 [BOOST_WSERIALIZATION_LIB="-l$ax_lib" AC_SUBST(BOOST_WSERIALIZATION_LIB) link_thread="yes" break],
365 if test "x$link_thread" = "xno"; then
366 AC_MSG_NOTICE(Could not link against $ax_lib !)
370 AC_CACHE_CHECK(whether the Boost::Signals library is available,
374 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/signal.hpp>
376 [[boost::signal<void ()> sig;
379 ax_cv_boost_signals=yes, ax_cv_boost_signals=no)
382 if test "x$ax_cv_boost_signals" = "xyes"; then
383 AC_DEFINE(HAVE_BOOST_SIGNALS,,[define if the Boost::Signals library is available])
385 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
386 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
387 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
388 AC_CHECK_LIB($ax_lib, main, [BOOST_SIGNALS_LIB="-l$ax_lib" AC_SUBST(BOOST_SIGNALS_LIB) link_thread="yes" break],
391 if test "x$link_thread" = "xno"; then
392 AC_MSG_NOTICE(Could not link against $ax_lib !)
396 AC_CACHE_CHECK(whether the Boost::Date_Time library is available,
397 ax_cv_boost_date_time,
400 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/date_time/gregorian/gregorian_types.hpp>
402 [[using namespace boost::gregorian; date d(2002,Jan,10);
405 ax_cv_boost_date_time=yes, ax_cv_boost_date_time=no)
408 if test "x$ax_cv_boost_date_time" = "xyes"; then
409 AC_DEFINE(HAVE_BOOST_DATE_TIME,,[define if the Boost::Date_Time library is available])
411 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
412 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
413 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
414 AC_CHECK_LIB($ax_lib, main, [BOOST_DATE_TIME_LIB="-l$ax_lib" AC_SUBST(BOOST_DATE_TIME_LIB) link_thread="yes" break],
417 if test "x$link_thread"="no" = "xno"; then
418 AC_MSG_NOTICE(Could not link against $ax_lib !)
422 AC_CACHE_CHECK(whether the Boost::Regex library is available,
426 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/regex.hpp>
428 [[boost::regex r(); return 0;]]),
429 ax_cv_boost_regex=yes, ax_cv_boost_regex=no)
432 if test "x$ax_cv_boost_regex" = "xyes"; then
433 AC_DEFINE(HAVE_BOOST_REGEX,,[define if the Boost::Regex library is available])
435 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
436 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
437 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
438 AC_CHECK_LIB($ax_lib, main, [BOOST_REGEX_LIB="-l$ax_lib" AC_SUBST(BOOST_REGEX_LIB) link_thread="yes" break],
441 if test "x$link_thread" = "xno"; then
442 AC_MSG_NOTICE(Could not link against $ax_lib !)
446 AC_CACHE_CHECK(whether the Boost::UnitTestFramework library is available,
447 ax_cv_boost_unit_test_framework,
450 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/test/unit_test.hpp>]],
451 [[using boost::unit_test::test_suite;
452 test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" ); return 0;]]),
453 ax_cv_boost_unit_test_framework=yes, ax_cv_boost_unit_test_framework=no)
456 if test "x$ax_cv_boost_unit_test_framework" = "xyes"; then
457 AC_DEFINE(HAVE_BOOST_UNIT_TEST_FRAMEWORK,,[define if the Boost::Unit_test_framework library is available])
458 BN=boost_unit_test_framework
459 saved_ldflags="${LDFLAGS}"
460 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
461 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
462 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
463 LDFLAGS="${LDFLAGS} -l$ax_lib"
464 AC_CACHE_CHECK(the name of the Boost::UnitTestFramework library,
465 ax_cv_boost_unit_test_framework,
468 AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/test/unit_test.hpp>]],
469 [[using boost::unit_test::test_suite;
470 test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" ); return 0;]])],
471 [link_thread="yes"],[link_thread="no"])
475 LDFLAGS="${saved_ldflags}"
476 if test "x$link_thread" = "xyes"; then
477 BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
478 AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
482 if test "x$link_thread" = "xno"; then
483 AC_MSG_NOTICE(Could not link against $ax_lib !)
487 CPPFLAGS="$CPPFLAGS_SAVED"
488 LDFLAGS="$LDFLAGS_SAVED"