improved error reporting of file errors (uses boost.system's error_code). Now permiss...
[libtorrent.git] / m4 / ax_boost_thread.m4
blob94ab82e114d3bea3b2a0d50190138ffa94694815
1 # ===========================================================================
2 #            http://autoconf-archive.cryp.to/ax_boost_thread.html
3 # ===========================================================================
5 # SYNOPSIS
7 #   AX_BOOST_THREAD
9 # DESCRIPTION
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>.
15 #   This macro calls:
17 #     AC_SUBST(BOOST_THREAD_LIB)
19 #   And sets:
21 #     HAVE_BOOST_THREAD
23 # LAST MODIFICATION
25 #   2008-04-12
27 # COPYLEFT
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 ]),
42         [
43         if test "$withval" = "no"; then
44                         want_boost="no"
45         elif test "$withval" = "yes"; then
46             want_boost="yes"
47             ax_boost_user_thread_lib=""
48         else
49                     want_boost="yes"
50                 ax_boost_user_thread_lib="$withval"
51                 fi
52         ],
53         [want_boost="yes"]
54         )
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"
61                 export CPPFLAGS
63                 LDFLAGS_SAVED="$LDFLAGS"
64                 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
65                 export LDFLAGS
67         AC_CACHE_CHECK(whether the Boost::Thread library is available,
68                                            ax_cv_boost_thread,
69         [AC_LANG_PUSH([C++])
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"
76                          else
77                                 CXXFLAGS="-pthread $CXXFLAGS"
78                          fi
79                          AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/thread/thread.hpp>]],
80                                    [[boost::thread_group thrds;
81                                    return 0;]]),
82                    ax_cv_boost_thread=yes, ax_cv_boost_thread=no)
83                          CXXFLAGS=$CXXFLAGS_SAVE
84              AC_LANG_POP([C++])
85                 ])
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"
91                    else
92                           BOOST_CPPFLAGS="-pthread $BOOST_CPPFLAGS"
93                    fi
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
101                         case "x$build_os" in
102                           *bsd* )
103                                LDFLAGS="-pthread $LDFLAGS"
104                           break;
105                           ;;
106                         esac
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],
112                                  [link_thread="no"])
113                                 done
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],
119                                  [link_thread="no"])
120                                 done
121                 fi
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
130             fi
131                         if test "x$link_thread" = "xno"; then
132                                 AC_MSG_ERROR(Could not link against $ax_lib !)
133                         else
134                            case "x$build_os" in
135                               *bsd* )
136                                 BOOST_LDFLAGS="-pthread $BOOST_LDFLAGS"
137                               break;
138                               ;;
139                            esac
141                         fi
142                 fi
144                 CPPFLAGS="$CPPFLAGS_SAVED"
145         LDFLAGS="$LDFLAGS_SAVED"
146         fi