ax_boost_for_bind10.m4 5.1 KB

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