| 1 | # =========================================================================== | 
|---|
| 2 | #     https://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 31 | 
|---|
| 34 |  | 
|---|
| 35 | AC_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 - | 
|---|
| 40 | 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" = "yes"; then | 
|---|
| 44 | want_boost="yes" | 
|---|
| 45 | ax_boost_user_thread_lib="" | 
|---|
| 46 | else | 
|---|
| 47 | want_boost="yes" | 
|---|
| 48 | ax_boost_user_thread_lib="$withval" | 
|---|
| 49 | fi | 
|---|
| 50 | ], | 
|---|
| 51 | [want_boost="yes"] | 
|---|
| 52 | ) | 
|---|
| 53 |  | 
|---|
| 54 | if test "x$want_boost" = "xyes"; then | 
|---|
| 55 | AC_REQUIRE([AC_PROG_CC]) | 
|---|
| 56 | AC_REQUIRE([AC_CANONICAL_BUILD]) | 
|---|
| 57 | CPPFLAGS_SAVED="$CPPFLAGS" | 
|---|
| 58 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" | 
|---|
| 59 | export CPPFLAGS | 
|---|
| 60 |  | 
|---|
| 61 | LDFLAGS_SAVED="$LDFLAGS" | 
|---|
| 62 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" | 
|---|
| 63 | export LDFLAGS | 
|---|
| 64 |  | 
|---|
| 65 | AC_CACHE_CHECK(whether the Boost::Thread library is available, | 
|---|
| 66 | ax_cv_boost_thread, | 
|---|
| 67 | [AC_LANG_PUSH([C++]) | 
|---|
| 68 | CXXFLAGS_SAVE=$CXXFLAGS | 
|---|
| 69 |  | 
|---|
| 70 | if test "x$host_os" = "xsolaris" ; then | 
|---|
| 71 | CXXFLAGS="-pthreads $CXXFLAGS" | 
|---|
| 72 | elif test "x$host_os" = "xmingw32" ; then | 
|---|
| 73 | CXXFLAGS="-mthreads $CXXFLAGS" | 
|---|
| 74 | else | 
|---|
| 75 | CXXFLAGS="-pthread $CXXFLAGS" | 
|---|
| 76 | fi | 
|---|
| 77 | AC_COMPILE_IFELSE([ | 
|---|
| 78 | AC_LANG_PROGRAM( | 
|---|
| 79 | [[@%:@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$host_os" = "xsolaris" ; then | 
|---|
| 88 | BOOST_CPPFLAGS="-pthreads $BOOST_CPPFLAGS" | 
|---|
| 89 | elif test "x$host_os" = "xmingw32" ; then | 
|---|
| 90 | BOOST_CPPFLAGS="-mthreads $BOOST_CPPFLAGS" | 
|---|
| 91 | else | 
|---|
| 92 | BOOST_CPPFLAGS="-pthread $BOOST_CPPFLAGS" | 
|---|
| 93 | fi | 
|---|
| 94 |  | 
|---|
| 95 | AC_SUBST(BOOST_CPPFLAGS) | 
|---|
| 96 |  | 
|---|
| 97 | AC_DEFINE(HAVE_BOOST_THREAD,, | 
|---|
| 98 | [define if the Boost::Thread library is available]) | 
|---|
| 99 | BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` | 
|---|
| 100 |  | 
|---|
| 101 | LDFLAGS_SAVE=$LDFLAGS | 
|---|
| 102 | case "x$host_os" in | 
|---|
| 103 | *bsd* ) | 
|---|
| 104 | LDFLAGS="-pthread $LDFLAGS" | 
|---|
| 105 | break; | 
|---|
| 106 | ;; | 
|---|
| 107 | esac | 
|---|
| 108 | if test "x$ax_boost_user_thread_lib" = "x"; then | 
|---|
| 109 | for libextension in `ls -r $BOOSTLIBDIR/libboost_thread* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'`; do | 
|---|
| 110 | ax_lib=${libextension} | 
|---|
| 111 | AC_CHECK_LIB($ax_lib, exit, | 
|---|
| 112 | [link_thread="yes"; break], | 
|---|
| 113 | [link_thread="no"]) | 
|---|
| 114 | done | 
|---|
| 115 | if test "x$link_thread" != "xyes"; then | 
|---|
| 116 | for libextension in `ls -r $BOOSTLIBDIR/boost_thread* 2>/dev/null | sed 's,.*/,,' | sed 's,\..*,,'`; do | 
|---|
| 117 | ax_lib=${libextension} | 
|---|
| 118 | AC_CHECK_LIB($ax_lib, exit, | 
|---|
| 119 | [link_thread="yes"; break], | 
|---|
| 120 | [link_thread="no"]) | 
|---|
| 121 | done | 
|---|
| 122 | fi | 
|---|
| 123 |  | 
|---|
| 124 | else | 
|---|
| 125 | for ax_lib in $ax_boost_user_thread_lib boost_thread-$ax_boost_user_thread_lib; do | 
|---|
| 126 | AC_CHECK_LIB($ax_lib, exit, | 
|---|
| 127 | [link_thread="yes"; break], | 
|---|
| 128 | [link_thread="no"]) | 
|---|
| 129 | done | 
|---|
| 130 |  | 
|---|
| 131 | fi | 
|---|
| 132 | if test "x$ax_lib" = "x"; then | 
|---|
| 133 | AC_MSG_ERROR(Could not find a version of the library!) | 
|---|
| 134 | fi | 
|---|
| 135 | if test "x$link_thread" = "xno"; then | 
|---|
| 136 | AC_MSG_ERROR(Could not link against $ax_lib !) | 
|---|
| 137 | else | 
|---|
| 138 | BOOST_THREAD_LIB="-l$ax_lib" | 
|---|
| 139 | case "x$host_os" in | 
|---|
| 140 | *bsd* ) | 
|---|
| 141 | BOOST_LDFLAGS="-pthread $BOOST_LDFLAGS" | 
|---|
| 142 | break; | 
|---|
| 143 | ;; | 
|---|
| 144 | xsolaris ) | 
|---|
| 145 | BOOST_THREAD_LIB="$BOOST_THREAD_LIB -lpthread" | 
|---|
| 146 | break; | 
|---|
| 147 | ;; | 
|---|
| 148 | xmingw32 ) | 
|---|
| 149 | break; | 
|---|
| 150 | ;; | 
|---|
| 151 | * ) | 
|---|
| 152 | BOOST_THREAD_LIB="$BOOST_THREAD_LIB -lpthread" | 
|---|
| 153 | break; | 
|---|
| 154 | ;; | 
|---|
| 155 | esac | 
|---|
| 156 | AC_SUBST(BOOST_THREAD_LIB) | 
|---|
| 157 | fi | 
|---|
| 158 | fi | 
|---|
| 159 |  | 
|---|
| 160 | CPPFLAGS="$CPPFLAGS_SAVED" | 
|---|
| 161 | LDFLAGS="$LDFLAGS_SAVED" | 
|---|
| 162 | fi | 
|---|
| 163 | ]) | 
|---|