ax_boost_for_bind10.m4 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. AC_DEFUN([AX_BOOST_FOR_BIND10], [
  34. AC_LANG_SAVE
  35. AC_LANG([C++])
  36. #
  37. # Configure Boost header path
  38. #
  39. # If explicitly specified, use it.
  40. AC_ARG_WITH([boost-include],
  41. AC_HELP_STRING([--with-boost-include=PATH],
  42. [specify exact directory for Boost headers]),
  43. [boost_include_path="$withval"])
  44. # If not specified, try some common paths.
  45. if test -z "$with_boost_include"; then
  46. boostdirs="/usr/local /usr/pkg /opt /opt/local"
  47. for d in $boostdirs
  48. do
  49. if test -f $d/include/boost/shared_ptr.hpp; then
  50. boost_include_path=$d/include
  51. break
  52. fi
  53. done
  54. fi
  55. # Check the path with some specific headers.
  56. CPPFLAGS_SAVED="$CPPFLAGS"
  57. if test "${boost_include_path}" ; then
  58. BOOST_INCLUDES="-I${boost_include_path}"
  59. CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES"
  60. fi
  61. 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],,
  62. AC_MSG_ERROR([Missing required header files.]))
  63. # Detect whether Boost tries to use threads by default, and, if not,
  64. # make it sure explicitly. In some systems the automatic detection
  65. # may depend on preceding header files, and if inconsistency happens
  66. # it could lead to a critical disruption.
  67. AC_MSG_CHECKING([whether Boost tries to use threads])
  68. AC_TRY_COMPILE([
  69. #include <boost/config.hpp>
  70. #ifdef BOOST_HAS_THREADS
  71. #error "boost will use threads"
  72. #endif],,
  73. [AC_MSG_RESULT(no)
  74. CPPFLAGS_BOOST_THREADCONF="-DBOOST_DISABLE_THREADS=1"],
  75. [AC_MSG_RESULT(yes)])
  76. # Boost offset_ptr is known to not compile on some platforms, depending on
  77. # boost version, its local configuration, and compiler. Detect it.
  78. AC_MSG_CHECKING([Boost offset_ptr compiles])
  79. AC_TRY_COMPILE([
  80. #include <boost/interprocess/offset_ptr.hpp>
  81. ],,
  82. [AC_MSG_RESULT(yes)
  83. BOOST_OFFSET_PTR_WOULDFAIL=no],
  84. [AC_MSG_RESULT(no)
  85. BOOST_OFFSET_PTR_WOULDFAIL=yes])
  86. # Detect build failure case known to happen with Boost installed via
  87. # FreeBSD ports
  88. if test "X$GXX" = "Xyes"; then
  89. CXXFLAGS_SAVED="$CXXFLAGS"
  90. CXXFLAGS="$CXXFLAGS -Werror"
  91. AC_MSG_CHECKING([Boost numeric_cast compiles with -Werror])
  92. AC_TRY_COMPILE([
  93. #include <boost/numeric/conversion/cast.hpp>
  94. ],[
  95. return (boost::numeric_cast<short>(0));
  96. ],[AC_MSG_RESULT(yes)
  97. BOOST_NUMERIC_CAST_WOULDFAIL=no],
  98. [AC_MSG_RESULT(no)
  99. BOOST_NUMERIC_CAST_WOULDFAIL=yes])
  100. CXXFLAGS="$CXXFLAGS_SAVED"
  101. else
  102. # This doesn't matter for non-g++
  103. BOOST_NUMERIC_CAST_WOULDFAIL=no
  104. fi
  105. # Boost interprocess::managed_mapped_file is highly system dependent and
  106. # can cause many portability issues. We are going to check if it could
  107. # compile at all, possibly with being lenient about compiler warnings.
  108. BOOST_MAPPED_FILE_WOULDFAIL=yes
  109. BOOST_MAPPED_FILE_CXXFLAG=
  110. CXXFLAGS_SAVED="$CXXFLAGS"
  111. try_flags="no"
  112. if test "X$GXX" = "Xyes"; then
  113. CXXFLAGS="$CXXFLAGS -Wall -Wextra -Werror"
  114. try_flags="$try_flags -Wno-error"
  115. fi
  116. # clang can cause false positives with -Werror without -Qunused-arguments
  117. AC_CHECK_DECL([__clang__], [CXXFLAGS="$CXXFLAGS -Qunused-arguments"], [])
  118. AC_MSG_CHECKING([Boost managed_mapped_file compiles])
  119. CXXFLAGS_SAVED2="$CXXFLAGS"
  120. for flag in $try_flags; do
  121. if test "$flag" != no; then
  122. BOOST_MAPPED_FILE_CXXFLAG="$flag"
  123. fi
  124. CXXFLAGS="$CXXFLAGS $BOOST_MAPPED_FILE_CXXFLAG"
  125. AC_TRY_COMPILE([
  126. #include <boost/interprocess/managed_mapped_file.hpp>
  127. ],[
  128. return (boost::interprocess::managed_mapped_file().all_memory_deallocated());
  129. ],[AC_MSG_RESULT([yes, with $flag flag])
  130. BOOST_MAPPED_FILE_WOULDFAIL=no
  131. break
  132. ],[])
  133. CXXFLAGS="$CXXFLAGS_SAVED2"
  134. done
  135. if test $BOOST_MAPPED_FILE_WOULDFAIL = yes; then
  136. AC_MSG_RESULT(no)
  137. fi
  138. # BOOST_STATIC_ASSERT in versions below Boost 1.54.0 is known to result
  139. # in warnings with GCC 4.8. Detect it.
  140. AC_MSG_CHECKING([BOOST_STATIC_ASSERT compiles])
  141. AC_TRY_COMPILE([
  142. #include <boost/static_assert.hpp>
  143. void testfn(void) { BOOST_STATIC_ASSERT(true); }
  144. ],,
  145. [AC_MSG_RESULT(yes)
  146. BOOST_STATIC_ASSERT_WOULDFAIL=no],
  147. [AC_MSG_RESULT(no)
  148. BOOST_STATIC_ASSERT_WOULDFAIL=yes])
  149. CXXFLAGS="$CXXFLAGS_SAVED"
  150. AC_SUBST(BOOST_INCLUDES)
  151. CPPFLAGS="$CPPFLAGS_SAVED"
  152. AC_LANG_RESTORE
  153. ])dnl AX_BOOST_FOR_BIND10