1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_boost_thread.html
3 # ===========================================================================
11 # Test for Thread library from the Boost C++ libraries. The macro requires
12 # a preceding call to AX_BOOST_BASE. Further documentation is available at
13 # <http://randspringer.de/boost/index.html>.
17 # AC_SUBST(BOOST_THREAD_LIB)
25 # Copyright (c) 2009 Thomas Porschberg <thomas@randspringer.de>
26 # Copyright (c) 2009 Michael Tindal
28 # Copying and distribution of this file, with or without modification, are
29 # permitted in any medium without royalty provided the copyright notice
30 # and this notice are preserved. This file is offered as-is, without any
35 AC_DEFUN([AX_BOOST_THREAD],
37 AC_ARG_WITH([boost-thread],
38 AS_HELP_STRING([--with-boost-thread@<:@=special-lib@:>@],
39 [use the Thread library from boost - it is possible to specify a certain library for the linker
40 e.g. --with-boost-thread=boost_thread-gcc-mt ]),
42 if test "$withval" = "no"; then
44 elif test "$withval" = "yes"; then
46 ax_boost_user_thread_lib=""
49 ax_boost_user_thread_lib="$withval"
55 if test "x$want_boost" = "xyes"; then
56 AC_REQUIRE([AC_PROG_CC])
57 AC_REQUIRE([AC_CANONICAL_BUILD])
58 CPPFLAGS_SAVED="$CPPFLAGS"
59 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
62 LDFLAGS_SAVED="$LDFLAGS"
63 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
66 AC_CACHE_CHECK(whether the Boost::Thread library is available,
69 CXXFLAGS_SAVE=$CXXFLAGS
71 if test "x$host_os" = "xsolaris" ; then
72 CXXFLAGS="-pthreads $CXXFLAGS"
73 elif test "x$host_os" = "xmingw32" ; then
74 CXXFLAGS="-mthreads $CXXFLAGS"
76 CXXFLAGS="-pthread $CXXFLAGS"
78 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/thread/thread.hpp>]],
79 [[boost::thread_group thrds;
81 ax_cv_boost_thread=yes, ax_cv_boost_thread=no)
82 CXXFLAGS=$CXXFLAGS_SAVE
85 if test "x$ax_cv_boost_thread" = "xyes"; then
86 if test "x$host_os" = "xsolaris" ; then
87 BOOST_CPPFLAGS="-pthreads $BOOST_CPPFLAGS"
88 elif test "x$host_os" = "xmingw32" ; then
89 BOOST_CPPFLAGS="-mthreads $BOOST_CPPFLAGS"
91 BOOST_CPPFLAGS="-pthread $BOOST_CPPFLAGS"
94 AC_SUBST(BOOST_CPPFLAGS)
96 AC_DEFINE(HAVE_BOOST_THREAD,,[define if the Boost::Thread library is available])
97 BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
102 LDFLAGS="-pthread $LDFLAGS"
106 if test "x$ax_boost_user_thread_lib" = "x"; then
107 for libextension in `ls -r $BOOSTLIBDIR/libboost_thread* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'`; do
108 ax_lib=${libextension}
109 AC_CHECK_LIB($ax_lib, exit,
110 [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
113 if test "x$link_thread" != "xyes"; then
114 for libextension in `ls -r $BOOSTLIBDIR/boost_thread* 2>/dev/null | sed 's,.*/,,' | sed 's,\..*,,'`; do
115 ax_lib=${libextension}
116 AC_CHECK_LIB($ax_lib, exit,
117 [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
123 for ax_lib in $ax_boost_user_thread_lib boost_thread-$ax_boost_user_thread_lib; do
124 AC_CHECK_LIB($ax_lib, exit,
125 [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
130 if test "x$ax_lib" = "x"; then
131 AC_MSG_ERROR(Could not find a version of the library!)
133 if test "x$link_thread" = "xno"; then
134 AC_MSG_ERROR(Could not link against $ax_lib !)
138 BOOST_LDFLAGS="-pthread $BOOST_LDFLAGS"
146 CPPFLAGS="$CPPFLAGS_SAVED"
147 LDFLAGS="$LDFLAGS_SAVED"