1 # ===========================================================================
2 # http://autoconf-archive.cryp.to/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)
29 # Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
30 # Copyright (c) 2008 Michael Tindal
32 # Copying and distribution of this file, with or without modification, are
33 # permitted in any medium without royalty provided the copyright notice
34 # and this notice are preserved.
36 AC_DEFUN([AX_BOOST_THREAD],
38 AC_ARG_WITH([boost-thread],
39 AS_HELP_STRING([--with-boost-thread@<:@=special-lib@:>@],
40 [use the Thread library from boost - it is possible to specify a certain library for the linker
41 e.g. --with-boost-thread=boost_thread-gcc-mt ]),
43 if test "$withval" = "no"; then
45 elif test "$withval" = "yes"; then
47 ax_boost_user_thread_lib=""
50 ax_boost_user_thread_lib="$withval"
56 if test "x$want_boost" = "xyes"; then
57 AC_REQUIRE([AC_PROG_CC])
58 AC_REQUIRE([AC_CANONICAL_BUILD])
59 CPPFLAGS_SAVED="$CPPFLAGS"
60 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
63 LDFLAGS_SAVED="$LDFLAGS"
64 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
67 AC_CACHE_CHECK(whether the Boost::Thread library is available,
70 CXXFLAGS_SAVE=$CXXFLAGS
72 if test "x$build_os" = "xsolaris" ; then
73 CXXFLAGS="-pthreads $CXXFLAGS"
74 elif test "x$build_os" = "xming32" ; then
75 CXXFLAGS="-mthreads $CXXFLAGS"
77 CXXFLAGS="-pthread $CXXFLAGS"
79 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/thread/thread.hpp>]],
80 [[boost::thread_group thrds;
82 ax_cv_boost_thread=yes, ax_cv_boost_thread=no)
83 CXXFLAGS=$CXXFLAGS_SAVE
86 if test "x$ax_cv_boost_thread" = "xyes"; then
87 if test "x$build_os" = "xsolaris" ; then
88 BOOST_CPPFLAGS="-pthreads $BOOST_CPPFLAGS"
89 elif test "x$build_os" = "xming32" ; then
90 BOOST_CPPFLAGS="-mthreads $BOOST_CPPFLAGS"
92 BOOST_CPPFLAGS="-pthread $BOOST_CPPFLAGS"
95 AC_SUBST(BOOST_CPPFLAGS)
97 AC_DEFINE(HAVE_BOOST_THREAD,,[define if the Boost::Thread library is available])
98 BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
100 LDFLAGS_SAVE=$LDFLAGS
103 LDFLAGS="-pthread $LDFLAGS"
107 if test "x$ax_boost_user_thread_lib" = "x"; then
108 for libextension in `ls $BOOSTLIBDIR/libboost_thread*.{so,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_thread.*\)\.so.*$;\1;' -e 's;^lib\(boost_thread.*\)\.a*$;\1;'` ; do
109 ax_lib=${libextension}
110 AC_CHECK_LIB($ax_lib, exit,
111 [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
114 if test "x$link_thread" != "xyes"; then
115 for libextension in `ls $BOOSTLIBDIR/boost_thread*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_thread.*\)\.dll.*$;\1;' -e 's;^\(boost_thread.*\)\.a*$;\1;'` ; do
116 ax_lib=${libextension}
117 AC_CHECK_LIB($ax_lib, exit,
118 [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
124 for ax_lib in $ax_boost_user_thread_lib boost_thread-$ax_boost_user_thread_lib; do
125 AC_CHECK_LIB($ax_lib, exit,
126 [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
131 if test "x$link_thread" = "xno"; then
132 AC_MSG_ERROR(Could not link against $ax_lib !)
136 BOOST_LDFLAGS="-pthread $BOOST_LDFLAGS"
144 CPPFLAGS="$CPPFLAGS_SAVED"
145 LDFLAGS="$LDFLAGS_SAVED"