2014-08-12 13:09:33 +02:00
dnl @synopsis AX_BOOST_FOR_KEA
2012-12-27 17:54:42 -08:00
dnl
2015-09-03 20:05:00 +02:00
dnl Test for the Boost C++ header files intended to be used within Kea
2012-12-27 17:54:42 -08:00
dnl
dnl If no path to the installed boost header files is given via the
dnl --with-boost-include option, the macro searchs under
dnl /usr/local /usr/pkg /opt /opt/local directories.
dnl If it cannot detect any workable path for Boost, this macro treats it
dnl as a fatal error (so it cannot be called if the availability of Boost
dnl is optional).
dnl
dnl This macro also tries to identify some known portability issues, and
dnl sets corresponding variables so the caller can react to (or ignore,
dnl depending on other configuration) specific issues appropriately.
dnl
2015-09-04 10:42:21 +02:00
dnl Boost.Asio depends on Boost.System which can be header only with
2015-09-07 13:52:25 +02:00
dnl versions >= 1.56. On older and perhaps some recent versions
dnl libboost_system is required.
2015-09-24 15:18:35 +02:00
dnl --with-boost-libs can help forcing link with a Boost library,
dnl e.g., --with-boost-libs=-lboost_system
2015-09-04 10:42:21 +02:00
dnl
2012-12-27 17:54:42 -08:00
dnl This macro calls:
dnl
dnl AC_SUBST(BOOST_INCLUDES)
2015-09-04 10:42:21 +02:00
dnl AC_SUBST(BOOST_LIBS)
2015-09-07 13:52:25 +02:00
dnl AC_SUBST(DISTCHECK_BOOST_CONFIGURE_FLAG)
2012-12-27 17:54:42 -08:00
dnl
dnl And possibly sets:
dnl CPPFLAGS_BOOST_THREADCONF should be added to CPPFLAGS by caller
2012-12-27 18:14:36 -08:00
dnl BOOST_OFFSET_PTR_WOULDFAIL set to "yes" if offset_ptr would cause build
dnl error; otherwise set to "no"
dnl BOOST_NUMERIC_CAST_WOULDFAIL set to "yes" if numeric_cast would cause
dnl build error; otherwise set to "no"
2013-07-08 08:19:31 +05:30
dnl BOOST_STATIC_ASSERT_WOULDFAIL set to "yes" if BOOST_STATIC_ASSERT would
dnl cause build error; otherwise set to "no"
2013-08-13 17:20:47 +05:30
2014-08-12 13:09:33 +02:00
AC_DEFUN([AX_BOOST_FOR_KEA], [
2012-12-27 17:54:42 -08:00
AC_LANG_SAVE
AC_LANG([C++])
2015-09-07 13:52:25 +02:00
DISTCHECK_BOOST_CONFIGURE_FLAG=
2017-07-14 14:04:21 -04:00
# We'll attempt to Use Boost system library by default
2015-09-04 10:42:21 +02:00
BOOST_LIBS=
2015-09-23 22:30:55 +02:00
BOOST_LIB_DIR=
2015-09-23 16:22:00 +02:00
boost_lib_path=
2015-09-04 10:42:21 +02:00
2012-12-27 17:54:42 -08:00
#
# Configure Boost header path
#
# If explicitly specified, use it.
AC_ARG_WITH([boost-include],
2022-01-10 16:04:56 +01:00
[AS_HELP_STRING([--with-boost-include=PATH],
[specify exact directory for Boost headers])],
2021-01-04 15:47:04 +02:00
[boost_include_path="$withval"])
2012-12-27 17:54:42 -08:00
# If not specified, try some common paths.
if test -z "$with_boost_include"; then
2021-01-06 15:37:08 +01:00
boostdirs="/usr/local /usr/pkg /opt /opt/local"
for d in $boostdirs
do
if test -f $d/include/boost/shared_ptr.hpp; then
boost_include_path=$d/include
boost_lib_path=$d/lib
break
fi
done
2015-09-07 13:52:25 +02:00
else
2021-01-06 15:37:08 +01:00
DISTCHECK_BOOST_CONFIGURE_FLAG="--with-boost-include=${boost_include_path}"
2012-12-27 17:54:42 -08:00
fi
# Check the path with some specific headers.
CPPFLAGS_SAVED="$CPPFLAGS"
if test "${boost_include_path}" ; then
2021-01-06 15:37:08 +01:00
BOOST_INCLUDES="-isystem ${boost_include_path}"
CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES"
2012-12-27 17:54:42 -08:00
fi
2022-10-12 20:50:20 +03:00
# Some boost headers need the <utility> header to be included for some Boost versions under C++20.
# Include it in all situations for simplicity.
AC_CHECK_HEADERS(
[ \
boost/asio.hpp \
boost/asio/ip/address.hpp \
boost/asio/signal_set.hpp \
boost/atomic.hpp \
boost/circular_buffer.hpp \
boost/date_time/posix_time/posix_time_types.hpp \
boost/foreach.hpp \
boost/functional/hash.hpp \
boost/interprocess/sync/interprocess_upgradable_mutex.hpp \
boost/shared_ptr.hpp \
boost/system/error_code.hpp \
],,
AC_MSG_ERROR([Missing required boost header files]),
[[
#include <utility>
]]
)
2012-12-27 17:54:42 -08:00
2018-11-28 20:44:25 +01:00
AC_CHECK_HEADERS(boost/asio/coroutine.hpp,,AC_MSG_RESULT(not found, using built-in header.))
2018-11-28 17:52:00 +01:00
2019-10-06 21:53:12 +02:00
AC_CHECK_HEADERS(boost/integer/common_factor.hpp)
2024-12-20 14:40:47 +01:00
AC_CHECK_HEADERS(boost/asio/io_context.hpp,,AC_MSG_ERROR([Missing boost asio io_context header: boost version must be at least 1.66]))
2019-02-12 14:08:22 +01:00
# Verify that the path does not include standard headers by mistake.
# There are two regex.h headers: one is a standard system header (usually
# in /usr/include) and the second one is provided by boost. If you specify the
# path to boost in a way that specifies the actual directory, this will mess up
# the code and we'll end up using the system header rather than the boost. For
# example, if your boost headers are in /usr/local/include/boost, you should
# use --with-boost-include=/usr/local/include
2021-01-04 15:46:21 +02:00
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2019-01-02 15:33:59 +01:00
#include <regex.h>
#ifdef BOOST_RE_REGEX_H
#error "boost/regex.h"
2021-01-04 15:47:04 +02:00
#endif]], [[]])],[],
[AC_MSG_ERROR([${boost_include_path}/regex.h is used in place of /usr/include/regex.h: when specifying path to boost, please omit the /boost at the end of the include path.])])
2019-01-02 15:33:59 +01:00
2013-10-28 00:12:12 -07:00
# clang can cause false positives with -Werror without -Qunused-arguments.
# it can be triggered if used with ccache.
AC_CHECK_DECL([__clang__], [CLANG_CXXFLAGS="-Qunused-arguments"], [])
2012-12-27 17:54:42 -08:00
# Detect whether Boost tries to use threads by default, and, if not,
# make it sure explicitly. In some systems the automatic detection
# may depend on preceding header files, and if inconsistency happens
# it could lead to a critical disruption.
AC_MSG_CHECKING([whether Boost tries to use threads])
2021-01-04 15:47:04 +02:00
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
#include <boost/config.hpp>
#ifdef BOOST_HAS_THREADS
#error "boost will use threads"
#endif]], [[]])],
[AC_MSG_RESULT(no)
CPPFLAGS_BOOST_THREADCONF="-DBOOST_DISABLE_THREADS=1"],
[AC_MSG_RESULT(yes)])
2012-12-27 17:54:42 -08:00
# Boost offset_ptr is known to not compile on some platforms, depending on
# boost version, its local configuration, and compiler. Detect it.
2013-08-16 09:59:55 +02:00
CXXFLAGS_SAVED="$CXXFLAGS"
2013-10-28 00:12:12 -07:00
CXXFLAGS="$CXXFLAGS $CLANG_CXXFLAGS -Werror"
2012-12-27 17:54:42 -08:00
AC_MSG_CHECKING([Boost offset_ptr compiles])
2021-01-04 15:46:21 +02:00
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2021-01-04 15:47:04 +02:00
#include <boost/interprocess/offset_ptr.hpp>
]], [[]])],
[AC_MSG_RESULT(yes)
BOOST_OFFSET_PTR_WOULDFAIL=no],
[AC_MSG_RESULT(no)
BOOST_OFFSET_PTR_WOULDFAIL=yes]
)
2013-08-16 09:59:55 +02:00
CXXFLAGS="$CXXFLAGS_SAVED"
2012-12-27 17:54:42 -08:00
2012-12-27 18:14:36 -08:00
# Detect build failure case known to happen with Boost installed via
# FreeBSD ports
2012-12-27 18:36:49 -08:00
if test "X$GXX" = "Xyes"; then
CXXFLAGS_SAVED="$CXXFLAGS"
2013-10-28 00:12:12 -07:00
CXXFLAGS="$CXXFLAGS $CLANG_CXXFLAGS -Werror"
2012-12-27 18:36:49 -08:00
AC_MSG_CHECKING([Boost numeric_cast compiles with -Werror])
2021-01-04 15:46:21 +02:00
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2021-01-04 15:47:04 +02:00
#include <boost/numeric/conversion/cast.hpp>
2021-01-04 15:46:21 +02:00
]], [[
2021-01-04 15:47:04 +02:00
return (boost::numeric_cast<short>(0));
]])],
[AC_MSG_RESULT(yes)
BOOST_NUMERIC_CAST_WOULDFAIL=no],
[AC_MSG_RESULT(no)
BOOST_NUMERIC_CAST_WOULDFAIL=yes]
)
2012-12-27 18:36:49 -08:00
CXXFLAGS="$CXXFLAGS_SAVED"
else
2013-03-13 14:24:31 -07:00
# This doesn't matter for non-g++
2013-04-10 14:31:07 -07:00
BOOST_NUMERIC_CAST_WOULDFAIL=no
2013-03-13 14:24:31 -07:00
fi
2013-07-08 08:19:31 +05:30
# BOOST_STATIC_ASSERT in versions below Boost 1.54.0 is known to result
# in warnings with GCC 4.8. Detect it.
AC_MSG_CHECKING([BOOST_STATIC_ASSERT compiles])
2021-01-04 15:46:21 +02:00
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2013-07-08 08:19:31 +05:30
#include <boost/static_assert.hpp>
void testfn(void) { BOOST_STATIC_ASSERT(true); }
2021-01-04 15:46:21 +02:00
]], [[]])],[AC_MSG_RESULT(yes)
BOOST_STATIC_ASSERT_WOULDFAIL=no],[AC_MSG_RESULT(no)
2013-07-08 08:19:31 +05:30
BOOST_STATIC_ASSERT_WOULDFAIL=yes])
2015-09-07 13:52:25 +02:00
# Get libs when explicitly configured
AC_ARG_WITH([boost-libs],
2022-01-10 16:04:56 +01:00
[AS_HELP_STRING([--with-boost-libs=SPEC],
[specify Boost libraries to link with, e.g., '-lboost_system'])],
2021-01-04 15:47:04 +02:00
[BOOST_LIBS="$withval"
DISTCHECK_BOOST_CONFIGURE_FLAG="$DISTCHECK_BOOST_CONFIGURE_FLAG --with-boost-libs=$withval"])
2015-09-07 13:52:25 +02:00
2015-09-23 22:30:55 +02:00
# Get lib dir when explicitly configured
AC_ARG_WITH([boost-lib-dir],
2022-01-10 16:04:56 +01:00
[AS_HELP_STRING([--with-boost-lib-dir=PATH],[specify directory where to find Boost libraries])],
2015-09-23 22:30:55 +02:00
[BOOST_LIB_DIR="$withval"
2017-07-18 16:39:16 +02:00
DISTCHECK_BOOST_CONFIGURE_FLAG="$DISTCHECK_BOOST_CONFIGURE_FLAG --with-boost-lib-dir=$withval"])
2015-09-23 22:30:55 +02:00
2017-07-14 14:04:21 -04:00
AC_ARG_ENABLE([boost-headers-only],
[AS_HELP_STRING([--enable-boost-headers-only],
[Build with boost headers only rather than link
with boost_system library. This is NOT recommended
as it may result in non-optimized code on some
platforms or introduce runtime errors on others.])],
[enable_boost_header="yes"; BOOST_LIBS=""],
[BOOST_LIBS="${BOOST_LIBS} -lboost_system"])
2015-09-04 10:42:21 +02:00
# BOOST_ERROR_CODE_HEADER_ONLY in versions below Boost 1.56.0 can fail
# to find the error_code.cpp file.
2015-09-07 13:52:25 +02:00
if test "x${BOOST_LIBS}" = "x"; then
AC_MSG_CHECKING([BOOST_ERROR_CODE_HEADER_ONLY works])
CXXFLAGS_SAVED2="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -DBOOST_ERROR_CODE_HEADER_ONLY"
CPPFLAGS="$CPPFLAGS -DBOOST_SYSTEM_NO_DEPRECATED"
2021-01-04 15:46:21 +02:00
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2015-09-07 13:52:25 +02:00
#include <boost/system/error_code.hpp>
2021-01-04 15:46:21 +02:00
]], [[]])],[AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)
2015-09-07 13:52:25 +02:00
AC_MSG_WARN([The Boost system library is required.])
2015-09-23 22:30:55 +02:00
BOOST_LIBS="-lboost_system"
if test "x${BOOST_LIB_DIR}" = "x"; then
BOOST_LIB_DIR="$boost_lib_path"
fi])
2015-09-07 13:52:25 +02:00
CPPFLAGS="$CXXFLAGS_SAVED2"
fi
# A Boost library is used.
if test "x${BOOST_LIBS}" != "x"; then
2015-09-23 22:30:55 +02:00
if test "x${BOOST_LIB_DIR}" != "x"; then
BOOST_LIBS="-L$BOOST_LIB_DIR $BOOST_LIBS"
fi
2015-09-07 13:52:25 +02:00
LIBS_SAVED="$LIBS"
LIBS="$BOOST_LIBS $LIBS"
2017-07-24 09:10:12 -04:00
if test $enable_static_link = yes; then
LIBS="-static $LIBS"
fi
2015-09-07 13:52:25 +02:00
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <boost/system/error_code.hpp>],
[boost::system::error_code ec;])],
[AC_MSG_RESULT([checking for Boost system library... yes])],
2018-12-29 14:37:31 +01:00
[if test "x${BOOST_LIB_DIR}" = "x"; then
BOOST_LIB_DIR="$boost_lib_path"
fi
if test "x${BOOST_LIB_DIR}" != "x"; then
BOOST_LIBS="-L$BOOST_LIB_DIR $BOOST_LIBS"
fi
LIBS="$BOOST_LIBS $LIBS_SAVED"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <boost/system/error_code.hpp>],
[boost::system::error_code ec;])],
[AC_MSG_RESULT([checking for Boost system library... yes])],
[AC_MSG_RESULT([checking for Boost system library... no])
AC_MSG_ERROR([Linking with ${BOOST_LIBS} is not enough: please make sure libboost_system is installed in an expected location; Check config.log for details, you may be missing other libraries.])])])
2015-09-07 13:52:25 +02:00
2017-07-25 14:00:33 -04:00
LIBS="$LIBS_SAVED"
2015-09-07 13:52:25 +02:00
fi
2015-09-04 10:42:21 +02:00
2013-03-13 14:24:31 -07:00
CXXFLAGS="$CXXFLAGS_SAVED"
2012-12-27 18:14:36 -08:00
2012-12-27 17:54:42 -08:00
AC_SUBST(BOOST_INCLUDES)
2015-09-04 10:42:21 +02:00
AC_SUBST(BOOST_LIBS)
2015-09-07 13:52:25 +02:00
AC_SUBST(DISTCHECK_BOOST_CONFIGURE_FLAG)
2012-12-27 17:54:42 -08:00
2013-09-10 11:33:32 +02:00
dnl Determine the Boost version, used mainly for config.report.
AC_MSG_CHECKING([Boost version])
cat > conftest.cpp << EOF
2013-09-16 15:29:58 +02:00
#include <boost/version.hpp>
2013-09-10 11:33:32 +02:00
AUTOCONF_BOOST_LIB_VERSION=BOOST_LIB_VERSION
EOF
2017-04-15 15:34:30 +02:00
dnl CPPP is defined in configure to $CPP or $CPP -P
2015-12-16 00:00:45 +01:00
BOOST_VERSION=`$CPPP $CPPFLAGS conftest.cpp | grep '^AUTOCONF_BOOST_LIB_VERSION=' | $SED -e 's/^AUTOCONF_BOOST_LIB_VERSION=//' -e 's/_/./g' -e 's/"//g' 2> /dev/null`
2013-09-10 11:33:32 +02:00
if test -z "$BOOST_VERSION"; then
BOOST_VERSION="unknown"
fi
$RM -f conftest.cpp
AC_MSG_RESULT([$BOOST_VERSION])
2012-12-27 17:54:42 -08:00
CPPFLAGS="$CPPFLAGS_SAVED"
AC_LANG_RESTORE
2024-08-13 13:45:25 +03:00
])