configure: check if tests can get built before enabled

The current approach for disabling tests is not a good solution because
it forces you to pass --disable-tests, rather than auto-detect if your
system can support the tests in the first place.  Many (most?) systems
do not have C++11.  This also causes issues when chain-building c-ares,
the hosting system needs to be updated to support passing this
additional flag if necessary, it doesn't seem reasonable to add this
requirement which breaks compatibility.

This change auto-detects if the system can build the tests and
automatically disable them if it cannot.  If you pass --enable-tests to
configure and the system cannot build them either due to lack of system
support, or because cross-compilation is being used, it will throw an
appropriate error since the user indicated they really did want the
tests.
pull/49/head
Brad House 9 years ago committed by Daniel Stenberg
parent 0b7a497ab7
commit c64a374a24
  1. 41
      configure.ac

@ -82,6 +82,7 @@ dnl Get system canonical name
AC_DEFINE_UNQUOTED(OS, "${host}", [cpu-machine-OS]) AC_DEFINE_UNQUOTED(OS, "${host}", [cpu-machine-OS])
XC_CHECK_PROG_CC XC_CHECK_PROG_CC
AX_CXX_COMPILE_STDCXX_11([noext],[optional])
XC_AUTOMAKE XC_AUTOMAKE
@ -877,28 +878,30 @@ squeeze CARES_PRIVATE_LIBS
XC_CHECK_BUILD_FLAGS XC_CHECK_BUILD_FLAGS
BUILDTESTS="yes" AC_MSG_CHECKING([whether to build tests])
AC_MSG_CHECKING([whether to build the tests])
AC_ARG_ENABLE(tests, AC_ARG_ENABLE(tests,
AC_HELP_STRING([--disable-tests],[skip building the tests]), AC_HELP_STRING([--enable-tests], [build test suite]),
[ case "$enableval" in [ build_tests="$enableval" ],
no) [ if test "x$HAVE_CXX11" = "x1" && test "x$cross_compiling" = "xno" ; then
BUILDTESTS="no" build_tests="yes"
AC_MSG_RESULT(no) else
;; build_tests="no"
yes) fi
AC_MSG_RESULT(yes) ]
;;
*) AC_MSG_RESULT(yes)
;;
esac ],
AC_MSG_RESULT(yes)
) )
if test "$BUILDTESTS" = "yes"; then if test "x$build_tests" = "xyes" ; then
if test "x$cross_compiling" = "xno"; then if test "x$HAVE_CXX11" = "0" ; then
AC_CONFIG_SUBDIRS([test]) AC_MSG_ERROR([*** Building tests requires a CXX11 compiler])
fi fi
if test "x$cross_compiling" = "xyes" ; then
AC_MSG_ERROR([*** Tests not supported when cross compiling])
fi
fi
AC_MSG_RESULT([$build_tests])
if test "x$build_tests" = "xyes" ; then
AC_CONFIG_SUBDIRS([test])
fi fi
AC_CONFIG_FILES([Makefile libcares.pc]) AC_CONFIG_FILES([Makefile libcares.pc])

Loading…
Cancel
Save