1# ===========================================================================
2#      http://www.gnu.org/software/autoconf-archive/ax_boost_thread.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_BOOST_THREAD
8#
9# DESCRIPTION
10#
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>.
14#
15#   This macro calls:
16#
17#     AC_SUBST(BOOST_THREAD_LIB)
18#
19#   And sets:
20#
21#     HAVE_BOOST_THREAD
22#
23# LICENSE
24#
25#   Copyright (c) 2009 Thomas Porschberg <thomas@randspringer.de>
26#   Copyright (c) 2009 Michael Tindal
27#
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
31#   warranty.
32
33#serial 27
34
35AC_DEFUN([AX_BOOST_THREAD],
36[
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 ]),
41        [
42        if test "$withval" = "no"; then
43			want_boost="no"
44        elif test "$withval" = "yes"; then
45            want_boost="yes"
46            ax_boost_user_thread_lib=""
47        else
48		    want_boost="yes"
49		ax_boost_user_thread_lib="$withval"
50		fi
51        ],
52        [want_boost="yes"]
53	)
54
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"
60		export CPPFLAGS
61
62		LDFLAGS_SAVED="$LDFLAGS"
63		LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
64		export LDFLAGS
65
66        AC_CACHE_CHECK(whether the Boost::Thread library is available,
67					   ax_cv_boost_thread,
68        [AC_LANG_PUSH([C++])
69			 CXXFLAGS_SAVE=$CXXFLAGS
70
71			 if test "x$host_os" = "xsolaris" ; then
72				 CXXFLAGS="-pthreads $CXXFLAGS"
73			 elif test "x$host_os" = "xmingw32" ; then
74				 CXXFLAGS="-mthreads $CXXFLAGS"
75			 else
76				CXXFLAGS="-pthread $CXXFLAGS"
77			 fi
78			 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/thread/thread.hpp>]],
79                                   [[boost::thread_group thrds;
80                                   return 0;]])],
81                   ax_cv_boost_thread=yes, ax_cv_boost_thread=no)
82			 CXXFLAGS=$CXXFLAGS_SAVE
83             AC_LANG_POP([C++])
84		])
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"
90		   else
91			  BOOST_CPPFLAGS="-pthread $BOOST_CPPFLAGS"
92		   fi
93
94			AC_SUBST(BOOST_CPPFLAGS)
95
96			AC_DEFINE(HAVE_BOOST_THREAD,,[define if the Boost::Thread library is available])
97            BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
98
99			LDFLAGS_SAVE=$LDFLAGS
100                        case "x$host_os" in
101                          *bsd* )
102                               LDFLAGS="-pthread $LDFLAGS"
103                          break;
104                          ;;
105                        esac
106            if test "x$ax_boost_user_thread_lib" = "x"; then
107                ax_lib=
108                for libextension in `ls -r $BOOSTLIBDIR/libboost_thread* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'`; 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],
112                                 [link_thread="no"])
113				done
114                if test "x$link_thread" != "xyes"; then
115                for libextension in `ls -r $BOOSTLIBDIR/boost_thread* 2>/dev/null | sed 's,.*/,,' | sed 's,\..*,,'`; 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],
119                                 [link_thread="no"])
120				done
121                fi
122
123            else
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],
127                                   [link_thread="no"])
128                  done
129
130            fi
131            if test "x$ax_lib" = "x"; then
132                AC_MSG_ERROR(Could not find a version of the boost_thread library!)
133            fi
134			if test "x$link_thread" = "xno"; then
135				AC_MSG_ERROR(Could not link against $ax_lib !)
136                        else
137                           case "x$host_os" in
138                              *bsd* )
139				BOOST_LDFLAGS="-pthread $BOOST_LDFLAGS"
140                              break;
141                              ;;
142                           esac
143
144			fi
145		fi
146
147		CPPFLAGS="$CPPFLAGS_SAVED"
148	LDFLAGS="$LDFLAGS_SAVED"
149	fi
150])
151