You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ax_boost_thread.m4 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #serial 27
  33. AC_DEFUN([AX_BOOST_THREAD],
  34. [
  35. AC_ARG_WITH([boost-thread],
  36. AS_HELP_STRING([--with-boost-thread@<:@=special-lib@:>@],
  37. [use the Thread library from boost - it is possible to specify a certain library for the linker
  38. e.g. --with-boost-thread=boost_thread-gcc-mt ]),
  39. [
  40. if test "$withval" = "no"; then
  41. want_boost="no"
  42. elif test "$withval" = "yes"; then
  43. want_boost="yes"
  44. ax_boost_user_thread_lib=""
  45. else
  46. want_boost="yes"
  47. ax_boost_user_thread_lib="$withval"
  48. fi
  49. ],
  50. [want_boost="yes"]
  51. )
  52. if test "x$want_boost" = "xyes"; then
  53. AC_REQUIRE([AC_PROG_CC])
  54. AC_REQUIRE([AC_CANONICAL_BUILD])
  55. CPPFLAGS_SAVED="$CPPFLAGS"
  56. CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
  57. export CPPFLAGS
  58. LDFLAGS_SAVED="$LDFLAGS"
  59. LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
  60. export LDFLAGS
  61. AC_CACHE_CHECK(whether the Boost::Thread library is available,
  62. ax_cv_boost_thread,
  63. [AC_LANG_PUSH([C++])
  64. CXXFLAGS_SAVE=$CXXFLAGS
  65. if test "x$host_os" = "xsolaris" ; then
  66. CXXFLAGS="-pthreads $CXXFLAGS"
  67. elif test "x$host_os" = "xmingw32" ; then
  68. CXXFLAGS="-mthreads $CXXFLAGS"
  69. else
  70. CXXFLAGS="-pthread $CXXFLAGS"
  71. fi
  72. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/thread/thread.hpp>]],
  73. [[boost::thread_group thrds;
  74. return 0;]])],
  75. ax_cv_boost_thread=yes, ax_cv_boost_thread=no)
  76. CXXFLAGS=$CXXFLAGS_SAVE
  77. AC_LANG_POP([C++])
  78. ])
  79. if test "x$ax_cv_boost_thread" = "xyes"; then
  80. if test "x$host_os" = "xsolaris" ; then
  81. BOOST_CPPFLAGS="-pthreads $BOOST_CPPFLAGS"
  82. elif test "x$host_os" = "xmingw32" ; then
  83. BOOST_CPPFLAGS="-mthreads $BOOST_CPPFLAGS"
  84. else
  85. BOOST_CPPFLAGS="-pthread $BOOST_CPPFLAGS"
  86. fi
  87. AC_SUBST(BOOST_CPPFLAGS)
  88. AC_DEFINE(HAVE_BOOST_THREAD,,[define if the Boost::Thread library is available])
  89. BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
  90. LDFLAGS_SAVE=$LDFLAGS
  91. case "x$host_os" in
  92. *bsd* )
  93. LDFLAGS="-pthread $LDFLAGS"
  94. break;
  95. ;;
  96. esac
  97. if test "x$ax_boost_user_thread_lib" = "x"; then
  98. ax_lib=
  99. for libextension in `ls -r $BOOSTLIBDIR/libboost_thread* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'`; do
  100. ax_lib=${libextension}
  101. AC_CHECK_LIB($ax_lib, exit,
  102. [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
  103. [link_thread="no"])
  104. done
  105. if test "x$link_thread" != "xyes"; then
  106. for libextension in `ls -r $BOOSTLIBDIR/boost_thread* 2>/dev/null | sed 's,.*/,,' | sed 's,\..*,,'`; do
  107. ax_lib=${libextension}
  108. AC_CHECK_LIB($ax_lib, exit,
  109. [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
  110. [link_thread="no"])
  111. done
  112. fi
  113. else
  114. for ax_lib in $ax_boost_user_thread_lib boost_thread-$ax_boost_user_thread_lib; do
  115. AC_CHECK_LIB($ax_lib, exit,
  116. [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
  117. [link_thread="no"])
  118. done
  119. fi
  120. if test "x$ax_lib" = "x"; then
  121. AC_MSG_ERROR(Could not find a version of the boost_thread library!)
  122. fi
  123. if test "x$link_thread" = "xno"; then
  124. AC_MSG_ERROR(Could not link against $ax_lib !)
  125. else
  126. case "x$host_os" in
  127. *bsd* )
  128. BOOST_LDFLAGS="-pthread $BOOST_LDFLAGS"
  129. break;
  130. ;;
  131. esac
  132. fi
  133. fi
  134. CPPFLAGS="$CPPFLAGS_SAVED"
  135. LDFLAGS="$LDFLAGS_SAVED"
  136. fi
  137. ])