ax_boost_for_bind10.m4 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 BOOST_MAPPED_FILE_WOULDFAIL set to "yes" if managed_mapped_file would
  27. dnl cause build failure; otherwise set to "no"
  28. dnl BOOST_MAPPED_FILE_CXXFLAG set to the compiler flag that would need to
  29. dnl compile managed_mapped_file (can be empty).
  30. dnl It is of no use if "WOULDFAIL" is yes.
  31. dnl BOOST_STATIC_ASSERT_WOULDFAIL set to "yes" if BOOST_STATIC_ASSERT would
  32. dnl cause build error; otherwise set to "no"
  33. dnl BOOST_OFFSET_PTR_OLD set to "yes" if the version of boost is older than
  34. dnl 1.48. Older versions of boost have a bug which
  35. dnl causes segfaults in offset_ptr implementation when
  36. dnl compiled by GCC with optimisations enabled.
  37. dnl See ticket no. 3025 for details.
  38. AC_DEFUN([AX_BOOST_FOR_BIND10], [
  39. AC_LANG_SAVE
  40. AC_LANG([C++])
  41. #
  42. # Configure Boost header path
  43. #
  44. # If explicitly specified, use it.
  45. AC_ARG_WITH([boost-include],
  46. AC_HELP_STRING([--with-boost-include=PATH],
  47. [specify exact directory for Boost headers]),
  48. [boost_include_path="$withval"])
  49. # If not specified, try some common paths.
  50. if test -z "$with_boost_include"; then
  51. boostdirs="/usr/local /usr/pkg /opt /opt/local"
  52. for d in $boostdirs
  53. do
  54. if test -f $d/include/boost/shared_ptr.hpp; then
  55. boost_include_path=$d/include
  56. break
  57. fi
  58. done
  59. fi
  60. # Check the path with some specific headers.
  61. CPPFLAGS_SAVED="$CPPFLAGS"
  62. if test "${boost_include_path}" ; then
  63. BOOST_INCLUDES="-I${boost_include_path}"
  64. CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES"
  65. fi
  66. 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],,
  67. AC_MSG_ERROR([Missing required header files.]))
  68. # Detect whether Boost tries to use threads by default, and, if not,
  69. # make it sure explicitly. In some systems the automatic detection
  70. # may depend on preceding header files, and if inconsistency happens
  71. # it could lead to a critical disruption.
  72. AC_MSG_CHECKING([whether Boost tries to use threads])
  73. AC_TRY_COMPILE([
  74. #include <boost/config.hpp>
  75. #ifdef BOOST_HAS_THREADS
  76. #error "boost will use threads"
  77. #endif],,
  78. [AC_MSG_RESULT(no)
  79. CPPFLAGS_BOOST_THREADCONF="-DBOOST_DISABLE_THREADS=1"],
  80. [AC_MSG_RESULT(yes)])
  81. # Boost offset_ptr is known to not compile on some platforms, depending on
  82. # boost version, its local configuration, and compiler. Detect it.
  83. CXXFLAGS_SAVED="$CXXFLAGS"
  84. CXXFLAGS="$CXXFLAGS -Werror"
  85. AC_MSG_CHECKING([Boost offset_ptr compiles])
  86. AC_TRY_COMPILE([
  87. #include <boost/interprocess/offset_ptr.hpp>
  88. ],,
  89. [AC_MSG_RESULT(yes)
  90. BOOST_OFFSET_PTR_WOULDFAIL=no],
  91. [AC_MSG_RESULT(no)
  92. BOOST_OFFSET_PTR_WOULDFAIL=yes])
  93. CXXFLAGS="$CXXFLAGS_SAVED"
  94. # Detect build failure case known to happen with Boost installed via
  95. # FreeBSD ports
  96. if test "X$GXX" = "Xyes"; then
  97. CXXFLAGS_SAVED="$CXXFLAGS"
  98. CXXFLAGS="$CXXFLAGS -Werror"
  99. AC_MSG_CHECKING([Boost numeric_cast compiles with -Werror])
  100. AC_TRY_COMPILE([
  101. #include <boost/numeric/conversion/cast.hpp>
  102. ],[
  103. return (boost::numeric_cast<short>(0));
  104. ],[AC_MSG_RESULT(yes)
  105. BOOST_NUMERIC_CAST_WOULDFAIL=no],
  106. [AC_MSG_RESULT(no)
  107. BOOST_NUMERIC_CAST_WOULDFAIL=yes])
  108. CXXFLAGS="$CXXFLAGS_SAVED"
  109. AC_MSG_CHECKING([Boost rbtree is old])
  110. AC_TRY_COMPILE([
  111. #include <boost/version.hpp>
  112. #if BOOST_VERSION < 104800
  113. #error Too old
  114. #endif
  115. ],,[AC_MSG_RESULT(no)
  116. BOOST_OFFSET_PTR_OLD=no
  117. ],[AC_MSG_RESULT(yes)
  118. BOOST_OFFSET_PTR_OLD=yes])
  119. else
  120. # This doesn't matter for non-g++
  121. BOOST_NUMERIC_CAST_WOULDFAIL=no
  122. BOOST_OFFSET_PTR_OLD=no
  123. fi
  124. # Boost interprocess::managed_mapped_file is highly system dependent and
  125. # can cause many portability issues. We are going to check if it could
  126. # compile at all, possibly with being lenient about compiler warnings.
  127. BOOST_MAPPED_FILE_WOULDFAIL=yes
  128. BOOST_MAPPED_FILE_CXXFLAG=
  129. CXXFLAGS_SAVED="$CXXFLAGS"
  130. try_flags="no"
  131. if test "X$GXX" = "Xyes"; then
  132. CXXFLAGS="$CXXFLAGS -Wall -Wextra -Werror"
  133. try_flags="$try_flags -Wno-error"
  134. fi
  135. # clang can cause false positives with -Werror without -Qunused-arguments
  136. AC_CHECK_DECL([__clang__], [CXXFLAGS="$CXXFLAGS -Qunused-arguments"], [])
  137. AC_MSG_CHECKING([Boost managed_mapped_file compiles])
  138. CXXFLAGS_SAVED2="$CXXFLAGS"
  139. for flag in $try_flags; do
  140. if test "$flag" != no; then
  141. BOOST_MAPPED_FILE_CXXFLAG="$flag"
  142. fi
  143. CXXFLAGS="$CXXFLAGS $BOOST_MAPPED_FILE_CXXFLAG"
  144. AC_TRY_COMPILE([
  145. #include <boost/interprocess/managed_mapped_file.hpp>
  146. ],[
  147. return (boost::interprocess::managed_mapped_file().all_memory_deallocated());
  148. ],[AC_MSG_RESULT([yes, with $flag flag])
  149. BOOST_MAPPED_FILE_WOULDFAIL=no
  150. break
  151. ],[])
  152. CXXFLAGS="$CXXFLAGS_SAVED2"
  153. done
  154. if test $BOOST_MAPPED_FILE_WOULDFAIL = yes; then
  155. AC_MSG_RESULT(no)
  156. fi
  157. # BOOST_STATIC_ASSERT in versions below Boost 1.54.0 is known to result
  158. # in warnings with GCC 4.8. Detect it.
  159. AC_MSG_CHECKING([BOOST_STATIC_ASSERT compiles])
  160. AC_TRY_COMPILE([
  161. #include <boost/static_assert.hpp>
  162. void testfn(void) { BOOST_STATIC_ASSERT(true); }
  163. ],,
  164. [AC_MSG_RESULT(yes)
  165. BOOST_STATIC_ASSERT_WOULDFAIL=no],
  166. [AC_MSG_RESULT(no)
  167. BOOST_STATIC_ASSERT_WOULDFAIL=yes])
  168. CXXFLAGS="$CXXFLAGS_SAVED"
  169. AC_SUBST(BOOST_INCLUDES)
  170. dnl Determine the Boost version, used mainly for config.report.
  171. AC_MSG_CHECKING([Boost version])
  172. cat > conftest.cpp << EOF
  173. #include "boost/version.hpp"
  174. AUTOCONF_BOOST_LIB_VERSION=BOOST_LIB_VERSION
  175. EOF
  176. BOOST_VERSION=`$CPP conftest.cpp | grep '^AUTOCONF_BOOST_LIB_VERSION=' | $SED -e 's/^AUTOCONF_BOOST_LIB_VERSION=//' -e 's/_/./g' -e 's/"//g' 2> /dev/null`
  177. if test -z "$BOOST_VERSION"; then
  178. BOOST_VERSION="unknown"
  179. fi
  180. $RM -f conftest.cpp
  181. AC_MSG_RESULT([$BOOST_VERSION])
  182. CPPFLAGS="$CPPFLAGS_SAVED"
  183. AC_LANG_RESTORE
  184. ])dnl AX_BOOST_FOR_BIND10