summaryrefslogtreecommitdiff
path: root/m4/ax_boost_thread.m4
blob: 9590ee61e66503f00a165fdc9ed9dc98f2daa524 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
dnl @synopsis AX_BOOST_THREAD
dnl
dnl This macro checks to see if the Boost.Thread library is installed.
dnl It also attempts to guess the currect library name using several
dnl attempts. It tries to build the library name using a user supplied
dnl name or suffix and then just the raw library.
dnl
dnl If the library is found, HAVE_BOOST_THREAD is defined and
dnl BOOST_THREAD_LIBS is set to the name of the library.
dnl
dnl This macro calls AC_SUBST(BOOST_THREAD_LIBS).
dnl
dnl @category InstalledPackages
dnl @author Michael Tindal <mtindal@paradoxpoint.com>
dnl @version 2004-09-20
dnl @license GPLWithACException

AC_DEFUN([AX_BOOST_THREAD],
[AC_REQUIRE([AC_CXX_NAMESPACES])dnl

AC_LANG_SAVE
AC_LANG_CPLUSPLUS
CXXFLAGS_SAVE=$CXXFLAGS
LIBS_SAVE=$LIBS
dnl FIXME: need to include a generic way to check for the flag
dnl to turn on threading support.
CXXFLAGS="-pthread $CXXFLAGS"

AC_CACHE_CHECK(whether the Boost::Thread library is available,
ax_cv_boost_thread,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <boost/thread/thread.hpp>]],
                       [[boost::thread_group thrds; return 0;]])],
               ax_cv_boost_thread=yes, ax_cv_boost_thread=no)
])

if test "$ax_cv_boost_thread" = yes; then
  AC_DEFINE(HAVE_BOOST_THREAD,,[define if the Boost::Thread library is available])
  dnl Now determine the appropriate file names
  AC_ARG_WITH([boost-thread],AS_HELP_STRING([--with-boost-thread],
  [specify the boost thread library suffix to use]),
  [if test "x$with_boost_thread" != "xno"; then
    ax_boost_thread_lib=boost_thread$with_boost_thread
  fi])
  for ax_lib in $ax_boost_thread_lib boost_thread boost_thread-mt; do
    AC_CHECK_LIB($ax_lib, main, [BOOST_THREAD_LIBS=-l$ax_lib; break])
  done

  # OXullo 2012-07-18: since boost 1.50, boost::thread depends on boost::system
  AC_CACHE_CHECK(whether Boost::Thread needs Boost::System library,
  ax_cv_boost_thread_system,
  [LIBS="$LIBS $BOOST_THREAD_LIBS"
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <boost/thread/thread.hpp>]],
            [[boost::thread_group thrds; return 0;]])],
            [ax_cv_boost_thread_system=no],
            [LIBS="$LIBS $BOOST_THREAD_LIBS -lboost_system$with_boost_thread"
                AC_LINK_IFELSE([
                    AC_LANG_PROGRAM([[#include <boost/thread/thread.hpp>]],
                        [[boost::thread_group thrds; return 0;]])
                    ],
                    [BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS -lboost_system$with_boost_thread"
                        ax_cv_boost_thread_system=yes],
                    [AC_ERROR([Cannot use Boost::Thread])]
                    )])
  ])
  
  CXXFLAGS=$CXXFLAGS_SAVE
  LIBS=$LIBS_SAVE
  AC_LANG_RESTORE

  AC_SUBST(BOOST_THREAD_LIBS)
fi
])dnl