ax_boost_for_kea.m4 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 forcing link with a Boost library,
  20. dnl e.g., --with-boost-libs=-lboost_system
  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_DIR=
  43. boost_lib_path=
  44. #
  45. # Configure Boost header path
  46. #
  47. # If explicitly specified, use it.
  48. AC_ARG_WITH([boost-include],
  49. AC_HELP_STRING([--with-boost-include=PATH],
  50. [specify exact directory for Boost headers]),
  51. [boost_include_path="$withval"])
  52. # If not specified, try some common paths.
  53. if test -z "$with_boost_include"; then
  54. boostdirs="/usr/local /usr/pkg /opt /opt/local"
  55. for d in $boostdirs
  56. do
  57. if test -f $d/include/boost/shared_ptr.hpp; then
  58. boost_include_path=$d/include
  59. boost_lib_path=$d/lib
  60. break
  61. fi
  62. done
  63. else
  64. DISTCHECK_BOOST_CONFIGURE_FLAG="--with-boost-include=${boost_include_path}"
  65. fi
  66. # Check the path with some specific headers.
  67. CPPFLAGS_SAVED="$CPPFLAGS"
  68. if test "${boost_include_path}" ; then
  69. BOOST_INCLUDES="-I${boost_include_path}"
  70. CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES"
  71. fi
  72. 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],,
  73. AC_MSG_ERROR([Missing required header files.]))
  74. # clang can cause false positives with -Werror without -Qunused-arguments.
  75. # it can be triggered if used with ccache.
  76. AC_CHECK_DECL([__clang__], [CLANG_CXXFLAGS="-Qunused-arguments"], [])
  77. # Detect whether Boost tries to use threads by default, and, if not,
  78. # make it sure explicitly. In some systems the automatic detection
  79. # may depend on preceding header files, and if inconsistency happens
  80. # it could lead to a critical disruption.
  81. AC_MSG_CHECKING([whether Boost tries to use threads])
  82. AC_TRY_COMPILE([
  83. #include <boost/config.hpp>
  84. #ifdef BOOST_HAS_THREADS
  85. #error "boost will use threads"
  86. #endif],,
  87. [AC_MSG_RESULT(no)
  88. CPPFLAGS_BOOST_THREADCONF="-DBOOST_DISABLE_THREADS=1"],
  89. [AC_MSG_RESULT(yes)])
  90. # Boost offset_ptr is known to not compile on some platforms, depending on
  91. # boost version, its local configuration, and compiler. Detect it.
  92. CXXFLAGS_SAVED="$CXXFLAGS"
  93. CXXFLAGS="$CXXFLAGS $CLANG_CXXFLAGS -Werror"
  94. AC_MSG_CHECKING([Boost offset_ptr compiles])
  95. AC_TRY_COMPILE([
  96. #include <boost/interprocess/offset_ptr.hpp>
  97. ],,
  98. [AC_MSG_RESULT(yes)
  99. BOOST_OFFSET_PTR_WOULDFAIL=no],
  100. [AC_MSG_RESULT(no)
  101. BOOST_OFFSET_PTR_WOULDFAIL=yes])
  102. CXXFLAGS="$CXXFLAGS_SAVED"
  103. # Detect build failure case known to happen with Boost installed via
  104. # FreeBSD ports
  105. if test "X$GXX" = "Xyes"; then
  106. CXXFLAGS_SAVED="$CXXFLAGS"
  107. CXXFLAGS="$CXXFLAGS $CLANG_CXXFLAGS -Werror"
  108. AC_MSG_CHECKING([Boost numeric_cast compiles with -Werror])
  109. AC_TRY_COMPILE([
  110. #include <boost/numeric/conversion/cast.hpp>
  111. ],[
  112. return (boost::numeric_cast<short>(0));
  113. ],[AC_MSG_RESULT(yes)
  114. BOOST_NUMERIC_CAST_WOULDFAIL=no],
  115. [AC_MSG_RESULT(no)
  116. BOOST_NUMERIC_CAST_WOULDFAIL=yes])
  117. CXXFLAGS="$CXXFLAGS_SAVED"
  118. else
  119. # This doesn't matter for non-g++
  120. BOOST_NUMERIC_CAST_WOULDFAIL=no
  121. fi
  122. # BOOST_STATIC_ASSERT in versions below Boost 1.54.0 is known to result
  123. # in warnings with GCC 4.8. Detect it.
  124. AC_MSG_CHECKING([BOOST_STATIC_ASSERT compiles])
  125. AC_TRY_COMPILE([
  126. #include <boost/static_assert.hpp>
  127. void testfn(void) { BOOST_STATIC_ASSERT(true); }
  128. ],,
  129. [AC_MSG_RESULT(yes)
  130. BOOST_STATIC_ASSERT_WOULDFAIL=no],
  131. [AC_MSG_RESULT(no)
  132. BOOST_STATIC_ASSERT_WOULDFAIL=yes])
  133. # Get libs when explicitly configured
  134. AC_ARG_WITH([boost-libs],
  135. AC_HELP_STRING([--with-boost-libs=SPEC],
  136. [specify Boost libraries to link with, e.g., '-lboost_system']),
  137. [BOOST_LIBS="$withval"
  138. DISTCHECK_BOOST_CONFIGURE_FLAG="$DISTCHECK_BOOST_CONFIGURE_FLAG --with-boost-libs=$withval"])
  139. # Get lib dir when explicitly configured
  140. AC_ARG_WITH([boost-lib-dir],
  141. AC_HELP_STRING([--with-boost-lib-dir=PATH],
  142. [specify directory where to find Boost libraries]),
  143. [BOOST_LIB_DIR="$withval"
  144. DISTCHECK_BOOST_CONFIGURE_FLAG="$DISTCHECK_BOOST_CONFIGURE_FLAG --with-boot-lib-dir=$withval"])
  145. # BOOST_ERROR_CODE_HEADER_ONLY in versions below Boost 1.56.0 can fail
  146. # to find the error_code.cpp file.
  147. if test "x${BOOST_LIBS}" = "x"; then
  148. AC_MSG_CHECKING([BOOST_ERROR_CODE_HEADER_ONLY works])
  149. CXXFLAGS_SAVED2="$CPPFLAGS"
  150. CPPFLAGS="$CPPFLAGS -DBOOST_ERROR_CODE_HEADER_ONLY"
  151. CPPFLAGS="$CPPFLAGS -DBOOST_SYSTEM_NO_DEPRECATED"
  152. AC_TRY_COMPILE([
  153. #include <boost/system/error_code.hpp>
  154. ],,
  155. [AC_MSG_RESULT(yes)],
  156. [AC_MSG_RESULT(no)
  157. AC_MSG_WARN([The Boost system library is required.])
  158. BOOST_LIBS="-lboost_system"
  159. if test "x${BOOST_LIB_DIR}" = "x"; then
  160. BOOST_LIB_DIR="$boost_lib_path"
  161. fi])
  162. CPPFLAGS="$CXXFLAGS_SAVED2"
  163. fi
  164. # A Boost library is used.
  165. if test "x${BOOST_LIBS}" != "x"; then
  166. if test "x${BOOST_LIB_DIR}" != "x"; then
  167. BOOST_LIBS="-L$BOOST_LIB_DIR $BOOST_LIBS"
  168. fi
  169. LIBS_SAVED="$LIBS"
  170. LIBS="$BOOST_LIBS $LIBS"
  171. AC_LINK_IFELSE(
  172. [AC_LANG_PROGRAM([#include <boost/system/error_code.hpp>],
  173. [boost::system::error_code ec;])],
  174. [AC_MSG_RESULT([checking for Boost system library... yes])],
  175. [AC_MSG_RESULT([checking for Boost system library... no])
  176. AC_MSG_ERROR([Linking with ${BOOST_LIBS} is not enough: please make sure libboost_system is installed])])
  177. LIBS="$LIBS_SAVED"
  178. fi
  179. CXXFLAGS="$CXXFLAGS_SAVED"
  180. AC_SUBST(BOOST_INCLUDES)
  181. AC_SUBST(BOOST_LIBS)
  182. AC_SUBST(DISTCHECK_BOOST_CONFIGURE_FLAG)
  183. dnl Determine the Boost version, used mainly for config.report.
  184. AC_MSG_CHECKING([Boost version])
  185. cat > conftest.cpp << EOF
  186. #include <boost/version.hpp>
  187. AUTOCONF_BOOST_LIB_VERSION=BOOST_LIB_VERSION
  188. EOF
  189. 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`
  190. if test -z "$BOOST_VERSION"; then
  191. BOOST_VERSION="unknown"
  192. fi
  193. $RM -f conftest.cpp
  194. AC_MSG_RESULT([$BOOST_VERSION])
  195. CPPFLAGS="$CPPFLAGS_SAVED"
  196. AC_LANG_RESTORE
  197. ])dnl AX_BOOST_FOR_KEA