ax_boost_for_kea.m4 6.9 KB

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