ax_boost_for_bind10.m4 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. dnl @synopsis AX_BOOST_FOR_BIND10
  2. dnl
  3. dnl Test for the Boost C++ header files intended to be used within BIND 10
  4. dnl
  5. dnl If no path to the installed boost header files is given via the
  6. dnl --with-boost-include option, the macro searchs under
  7. dnl /usr/local /usr/pkg /opt /opt/local directories.
  8. dnl If it cannot detect any workable path for Boost, this macro treats it
  9. dnl as a fatal error (so it cannot be called if the availability of Boost
  10. dnl is optional).
  11. dnl
  12. dnl This macro also tries to identify some known portability issues, and
  13. dnl sets corresponding variables so the caller can react to (or ignore,
  14. dnl depending on other configuration) specific issues appropriately.
  15. dnl
  16. dnl This macro calls:
  17. dnl
  18. dnl AC_SUBST(BOOST_INCLUDES)
  19. dnl
  20. dnl And possibly sets:
  21. dnl CPPFLAGS_BOOST_THREADCONF should be added to CPPFLAGS by caller
  22. dnl BOOST_OFFSET_PTR_WOULDFAIL set to "yes" if offset_ptr would cause build
  23. dnl error; otherwise set to "no"
  24. dnl BOOST_NUMERIC_CAST_WOULDFAIL set to "yes" if numeric_cast would cause
  25. dnl build error; otherwise set to "no"
  26. dnl
  27. AC_DEFUN([AX_BOOST_FOR_BIND10], [
  28. AC_LANG_SAVE
  29. AC_LANG([C++])
  30. #
  31. # Configure Boost header path
  32. #
  33. # If explicitly specified, use it.
  34. AC_ARG_WITH([boost-include],
  35. AC_HELP_STRING([--with-boost-include=PATH],
  36. [specify exact directory for Boost headers]),
  37. [boost_include_path="$withval"])
  38. # If not specified, try some common paths.
  39. if test -z "$with_boost_include"; then
  40. boostdirs="/usr/local /usr/pkg /opt /opt/local"
  41. for d in $boostdirs
  42. do
  43. if test -f $d/include/boost/shared_ptr.hpp; then
  44. boost_include_path=$d/include
  45. break
  46. fi
  47. done
  48. fi
  49. # Check the path with some specific headers.
  50. CPPFLAGS_SAVED="$CPPFLAGS"
  51. if test "${boost_include_path}" ; then
  52. BOOST_INCLUDES="-I${boost_include_path}"
  53. CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES"
  54. fi
  55. AC_CHECK_HEADERS([boost/shared_ptr.hpp boost/foreach.hpp boost/interprocess/sync/interprocess_upgradable_mutex.hpp boost/date_time/posix_time/posix_time_types.hpp boost/bind.hpp boost/function.hpp],,
  56. AC_MSG_ERROR([Missing required header files.]))
  57. # Detect whether Boost tries to use threads by default, and, if not,
  58. # make it sure explicitly. In some systems the automatic detection
  59. # may depend on preceding header files, and if inconsistency happens
  60. # it could lead to a critical disruption.
  61. AC_MSG_CHECKING([whether Boost tries to use threads])
  62. AC_TRY_COMPILE([
  63. #include <boost/config.hpp>
  64. #ifdef BOOST_HAS_THREADS
  65. #error "boost will use threads"
  66. #endif],,
  67. [AC_MSG_RESULT(no)
  68. CPPFLAGS_BOOST_THREADCONF="-DBOOST_DISABLE_THREADS=1"],
  69. [AC_MSG_RESULT(yes)])
  70. # Boost offset_ptr is known to not compile on some platforms, depending on
  71. # boost version, its local configuration, and compiler. Detect it.
  72. AC_MSG_CHECKING([Boost offset_ptr compiles])
  73. AC_TRY_COMPILE([
  74. #include <boost/interprocess/offset_ptr.hpp>
  75. ],,
  76. [AC_MSG_RESULT(yes)
  77. BOOST_OFFSET_PTR_WOULDFAIL=no],
  78. [AC_MSG_RESULT(no)
  79. BOOST_OFFSET_PTR_WOULDFAIL=yes])
  80. # Detect build failure case known to happen with Boost installed via
  81. # FreeBSD ports
  82. if test "X$GXX" = "Xyes"; then
  83. CXXFLAGS_SAVED="$CXXFLAGS"
  84. CXXFLAGS="$CXXFLAGS -Werror"
  85. AC_MSG_CHECKING([Boost numeric_cast compiles with -Werror])
  86. AC_TRY_COMPILE([
  87. #include <boost/numeric/conversion/cast.hpp>
  88. ],[
  89. return (boost::numeric_cast<short>(0));
  90. ],[AC_MSG_RESULT(yes)
  91. BOOST_NUMERIC_CAST_WOULDFAIL=no],
  92. [AC_MSG_RESULT(no)
  93. BOOST_NUMERIC_CAST_WOULDFAIL=yes])
  94. CXXFLAGS="$CXXFLAGS_SAVED"
  95. else
  96. # This doesn't matter for non-g++
  97. BOOST_NUMERIC_CAST_WOULDFAIL=no
  98. fi
  99. AC_SUBST(BOOST_INCLUDES)
  100. CPPFLAGS="$CPPFLAGS_SAVED"
  101. AC_LANG_RESTORE
  102. ])dnl AX_BOOST_FOR_BIND10