ax_boost_for_kea.m4 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. dnl @synopsis AX_BOOST_FOR_KEA
  2. dnl
  3. dnl Test for the Boost C++ header files intended to be used within Kea
  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 Boost.Asio depends on Boost.System which can be header only with
  17. dnl versions >= 1.56. On older versions libboost_system is required.
  18. dnl
  19. dnl This macro calls:
  20. dnl
  21. dnl AC_SUBST(BOOST_INCLUDES)
  22. dnl AC_SUBST(BOOST_LIBS)
  23. dnl
  24. dnl And possibly sets:
  25. dnl CPPFLAGS_BOOST_THREADCONF should be added to CPPFLAGS by caller
  26. dnl BOOST_OFFSET_PTR_WOULDFAIL set to "yes" if offset_ptr would cause build
  27. dnl error; otherwise set to "no"
  28. dnl BOOST_NUMERIC_CAST_WOULDFAIL set to "yes" if numeric_cast would cause
  29. dnl build error; otherwise set to "no"
  30. dnl BOOST_STATIC_ASSERT_WOULDFAIL set to "yes" if BOOST_STATIC_ASSERT would
  31. dnl cause build error; otherwise set to "no"
  32. AC_DEFUN([AX_BOOST_FOR_KEA], [
  33. AC_LANG_SAVE
  34. AC_LANG([C++])
  35. # No library by default (and as goal)
  36. BOOST_LIBS=
  37. #
  38. # Configure Boost header path
  39. #
  40. # If explicitly specified, use it.
  41. AC_ARG_WITH([boost-include],
  42. AC_HELP_STRING([--with-boost-include=PATH],
  43. [specify exact directory for Boost headers]),
  44. [boost_include_path="$withval"])
  45. # If not specified, try some common paths.
  46. if test -z "$with_boost_include"; then
  47. boostdirs="/usr/local /usr/pkg /opt /opt/local"
  48. for d in $boostdirs
  49. do
  50. if test -f $d/include/boost/shared_ptr.hpp; then
  51. boost_include_path=$d/include
  52. break
  53. fi
  54. done
  55. fi
  56. # Check the path with some specific headers.
  57. CPPFLAGS_SAVED="$CPPFLAGS"
  58. if test "${boost_include_path}" ; then
  59. BOOST_INCLUDES="-I${boost_include_path}"
  60. CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES"
  61. fi
  62. 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 boost/asio.hpp boost/asio/ip/address.hpp boost/system/error_code.hpp],,
  63. AC_MSG_ERROR([Missing required header files.]))
  64. # clang can cause false positives with -Werror without -Qunused-arguments.
  65. # it can be triggered if used with ccache.
  66. AC_CHECK_DECL([__clang__], [CLANG_CXXFLAGS="-Qunused-arguments"], [])
  67. # Detect whether Boost tries to use threads by default, and, if not,
  68. # make it sure explicitly. In some systems the automatic detection
  69. # may depend on preceding header files, and if inconsistency happens
  70. # it could lead to a critical disruption.
  71. AC_MSG_CHECKING([whether Boost tries to use threads])
  72. AC_TRY_COMPILE([
  73. #include <boost/config.hpp>
  74. #ifdef BOOST_HAS_THREADS
  75. #error "boost will use threads"
  76. #endif],,
  77. [AC_MSG_RESULT(no)
  78. CPPFLAGS_BOOST_THREADCONF="-DBOOST_DISABLE_THREADS=1"],
  79. [AC_MSG_RESULT(yes)])
  80. # Boost offset_ptr is known to not compile on some platforms, depending on
  81. # boost version, its local configuration, and compiler. Detect it.
  82. CXXFLAGS_SAVED="$CXXFLAGS"
  83. CXXFLAGS="$CXXFLAGS $CLANG_CXXFLAGS -Werror"
  84. AC_MSG_CHECKING([Boost offset_ptr compiles])
  85. AC_TRY_COMPILE([
  86. #include <boost/interprocess/offset_ptr.hpp>
  87. ],,
  88. [AC_MSG_RESULT(yes)
  89. BOOST_OFFSET_PTR_WOULDFAIL=no],
  90. [AC_MSG_RESULT(no)
  91. BOOST_OFFSET_PTR_WOULDFAIL=yes])
  92. CXXFLAGS="$CXXFLAGS_SAVED"
  93. # Detect build failure case known to happen with Boost installed via
  94. # FreeBSD ports
  95. if test "X$GXX" = "Xyes"; then
  96. CXXFLAGS_SAVED="$CXXFLAGS"
  97. CXXFLAGS="$CXXFLAGS $CLANG_CXXFLAGS -Werror"
  98. AC_MSG_CHECKING([Boost numeric_cast compiles with -Werror])
  99. AC_TRY_COMPILE([
  100. #include <boost/numeric/conversion/cast.hpp>
  101. ],[
  102. return (boost::numeric_cast<short>(0));
  103. ],[AC_MSG_RESULT(yes)
  104. BOOST_NUMERIC_CAST_WOULDFAIL=no],
  105. [AC_MSG_RESULT(no)
  106. BOOST_NUMERIC_CAST_WOULDFAIL=yes])
  107. CXXFLAGS="$CXXFLAGS_SAVED"
  108. else
  109. # This doesn't matter for non-g++
  110. BOOST_NUMERIC_CAST_WOULDFAIL=no
  111. fi
  112. # BOOST_STATIC_ASSERT in versions below Boost 1.54.0 is known to result
  113. # in warnings with GCC 4.8. Detect it.
  114. AC_MSG_CHECKING([BOOST_STATIC_ASSERT compiles])
  115. AC_TRY_COMPILE([
  116. #include <boost/static_assert.hpp>
  117. void testfn(void) { BOOST_STATIC_ASSERT(true); }
  118. ],,
  119. [AC_MSG_RESULT(yes)
  120. BOOST_STATIC_ASSERT_WOULDFAIL=no],
  121. [AC_MSG_RESULT(no)
  122. BOOST_STATIC_ASSERT_WOULDFAIL=yes])
  123. # BOOST_ERROR_CODE_HEADER_ONLY in versions below Boost 1.56.0 can fail
  124. # to find the error_code.cpp file.
  125. AC_MSG_CHECKING([BOOST_ERROR_CODE_HEADER_ONLY works])
  126. CXXFLAGS_SAVED2="$CPPFLAGS"
  127. CPPFLAGS="$CPPFLAGS -DBOOST_ERROR_CODE_HEADER_ONLY"
  128. CPPFLAGS="$CPPFLAGS -DBOOST_SYSTEM_NO_DEPRECATED"
  129. AC_TRY_COMPILE([
  130. #include <boost/system/error_code.hpp>
  131. ],,
  132. [AC_MSG_RESULT(yes)],
  133. [AC_MSG_RESULT(no)
  134. AC_MSG_WARN([The Boost system library is required.])
  135. BOOST_LIBS="-lboost_system"
  136. LIBS_SAVED="$LIBS"
  137. LIBS="$BOOST_LIBS $LIBS"
  138. CPPFLAGS="$CXXFLAGS_SAVED2"
  139. AC_LINK_IFELSE(
  140. [AC_LANG_PROGRAM([#include <boost/system/error_code.hpp>],
  141. [boost::system::error_code ec;])],
  142. [AC_MSG_RESULT([checking for Boost system library... yes])],
  143. [AC_MSG_RESULT([checking for Boost system library... no])
  144. AC_MSG_ERROR([Linking with ${BOOST_LIBS} is not enough: please make sure libboost_system is installed])])
  145. LIBS="$LIBS_SAVED"])
  146. CXXFLAGS="$CXXFLAGS_SAVED"
  147. AC_SUBST(BOOST_INCLUDES)
  148. AC_SUBST(BOOST_LIBS)
  149. dnl Determine the Boost version, used mainly for config.report.
  150. AC_MSG_CHECKING([Boost version])
  151. cat > conftest.cpp << EOF
  152. #include <boost/version.hpp>
  153. AUTOCONF_BOOST_LIB_VERSION=BOOST_LIB_VERSION
  154. EOF
  155. 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`
  156. if test -z "$BOOST_VERSION"; then
  157. BOOST_VERSION="unknown"
  158. fi
  159. $RM -f conftest.cpp
  160. AC_MSG_RESULT([$BOOST_VERSION])
  161. CPPFLAGS="$CPPFLAGS_SAVED"
  162. AC_LANG_RESTORE
  163. ])dnl AX_BOOST_FOR_KEA