ax_boost_for_kea.m4 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. dnl @synopsis AX_BOOST_FOR_KEA
  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_KEA], [
  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. # clang can cause false positives with -Werror without -Qunused-arguments.
  69. # it can be triggered if used with ccache.
  70. AC_CHECK_DECL([__clang__], [CLANG_CXXFLAGS="-Qunused-arguments"], [])
  71. # Detect whether Boost tries to use threads by default, and, if not,
  72. # make it sure explicitly. In some systems the automatic detection
  73. # may depend on preceding header files, and if inconsistency happens
  74. # it could lead to a critical disruption.
  75. AC_MSG_CHECKING([whether Boost tries to use threads])
  76. AC_TRY_COMPILE([
  77. #include <boost/config.hpp>
  78. #ifdef BOOST_HAS_THREADS
  79. #error "boost will use threads"
  80. #endif],,
  81. [AC_MSG_RESULT(no)
  82. CPPFLAGS_BOOST_THREADCONF="-DBOOST_DISABLE_THREADS=1"],
  83. [AC_MSG_RESULT(yes)])
  84. # Boost offset_ptr is known to not compile on some platforms, depending on
  85. # boost version, its local configuration, and compiler. Detect it.
  86. CXXFLAGS_SAVED="$CXXFLAGS"
  87. CXXFLAGS="$CXXFLAGS $CLANG_CXXFLAGS -Werror"
  88. AC_MSG_CHECKING([Boost offset_ptr compiles])
  89. AC_TRY_COMPILE([
  90. #include <boost/interprocess/offset_ptr.hpp>
  91. ],,
  92. [AC_MSG_RESULT(yes)
  93. BOOST_OFFSET_PTR_WOULDFAIL=no],
  94. [AC_MSG_RESULT(no)
  95. BOOST_OFFSET_PTR_WOULDFAIL=yes])
  96. CXXFLAGS="$CXXFLAGS_SAVED"
  97. # Detect build failure case known to happen with Boost installed via
  98. # FreeBSD ports
  99. if test "X$GXX" = "Xyes"; then
  100. CXXFLAGS_SAVED="$CXXFLAGS"
  101. CXXFLAGS="$CXXFLAGS $CLANG_CXXFLAGS -Werror"
  102. AC_MSG_CHECKING([Boost numeric_cast compiles with -Werror])
  103. AC_TRY_COMPILE([
  104. #include <boost/numeric/conversion/cast.hpp>
  105. ],[
  106. return (boost::numeric_cast<short>(0));
  107. ],[AC_MSG_RESULT(yes)
  108. BOOST_NUMERIC_CAST_WOULDFAIL=no],
  109. [AC_MSG_RESULT(no)
  110. BOOST_NUMERIC_CAST_WOULDFAIL=yes])
  111. CXXFLAGS="$CXXFLAGS_SAVED"
  112. AC_MSG_CHECKING([Boost rbtree is old])
  113. AC_TRY_COMPILE([
  114. #include <boost/version.hpp>
  115. #if BOOST_VERSION < 104800
  116. #error Too old
  117. #endif
  118. ],,[AC_MSG_RESULT(no)
  119. BOOST_OFFSET_PTR_OLD=no
  120. ],[AC_MSG_RESULT(yes)
  121. BOOST_OFFSET_PTR_OLD=yes])
  122. else
  123. # This doesn't matter for non-g++
  124. BOOST_NUMERIC_CAST_WOULDFAIL=no
  125. BOOST_OFFSET_PTR_OLD=no
  126. fi
  127. # Boost interprocess::managed_mapped_file is highly system dependent and
  128. # can cause many portability issues. We are going to check if it could
  129. # compile at all, possibly with being lenient about compiler warnings.
  130. BOOST_MAPPED_FILE_WOULDFAIL=yes
  131. BOOST_MAPPED_FILE_CXXFLAG=
  132. CXXFLAGS_SAVED="$CXXFLAGS"
  133. try_flags="no"
  134. if test "X$GXX" = "Xyes"; then
  135. CXXFLAGS="$CXXFLAGS $CLANG_CXXFLAGS -Wall -Wextra -Werror"
  136. try_flags="$try_flags -Wno-error"
  137. fi
  138. AC_MSG_CHECKING([Boost managed_mapped_file compiles])
  139. CXXFLAGS_SAVED2="$CXXFLAGS"
  140. for flag in $try_flags; do
  141. if test "$flag" != no; then
  142. BOOST_MAPPED_FILE_CXXFLAG="$flag"
  143. fi
  144. CXXFLAGS="$CXXFLAGS $CLANG_CXXFLAGS $BOOST_MAPPED_FILE_CXXFLAG"
  145. AC_TRY_COMPILE([
  146. #include <boost/interprocess/managed_mapped_file.hpp>
  147. ],[
  148. return (boost::interprocess::managed_mapped_file().all_memory_deallocated());
  149. ],[AC_MSG_RESULT([yes, with $flag flag])
  150. BOOST_MAPPED_FILE_WOULDFAIL=no
  151. break
  152. ],[])
  153. CXXFLAGS="$CXXFLAGS_SAVED2"
  154. done
  155. if test $BOOST_MAPPED_FILE_WOULDFAIL = yes; then
  156. AC_MSG_RESULT(no)
  157. fi
  158. # BOOST_STATIC_ASSERT in versions below Boost 1.54.0 is known to result
  159. # in warnings with GCC 4.8. Detect it.
  160. AC_MSG_CHECKING([BOOST_STATIC_ASSERT compiles])
  161. AC_TRY_COMPILE([
  162. #include <boost/static_assert.hpp>
  163. void testfn(void) { BOOST_STATIC_ASSERT(true); }
  164. ],,
  165. [AC_MSG_RESULT(yes)
  166. BOOST_STATIC_ASSERT_WOULDFAIL=no],
  167. [AC_MSG_RESULT(no)
  168. BOOST_STATIC_ASSERT_WOULDFAIL=yes])
  169. CXXFLAGS="$CXXFLAGS_SAVED"
  170. AC_SUBST(BOOST_INCLUDES)
  171. dnl Determine the Boost version, used mainly for config.report.
  172. AC_MSG_CHECKING([Boost version])
  173. cat > conftest.cpp << EOF
  174. #include <boost/version.hpp>
  175. AUTOCONF_BOOST_LIB_VERSION=BOOST_LIB_VERSION
  176. EOF
  177. BOOST_VERSION=`$CPP $CPPFLAGS conftest.cpp | grep '^AUTOCONF_BOOST_LIB_VERSION=' | $SED -e 's/^AUTOCONF_BOOST_LIB_VERSION=//' -e 's/_/./g' -e 's/"//g' 2> /dev/null`
  178. if test -z "$BOOST_VERSION"; then
  179. BOOST_VERSION="unknown"
  180. fi
  181. $RM -f conftest.cpp
  182. AC_MSG_RESULT([$BOOST_VERSION])
  183. CPPFLAGS="$CPPFLAGS_SAVED"
  184. AC_LANG_RESTORE
  185. ])dnl AX_BOOST_FOR_KEA