From 11d90ddeabf3926cf503baa78d095972f80f6f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Wed, 27 Jun 2012 16:25:46 +0200 Subject: [PATCH] Add AC macro to determine how to link Boost.Test Details: Test suites based on Boost.Test must know how to include the library support code into the executables. If the Boost.Test library is dynamically linked, then test suites must define the pre-processor symbol "BOOST_TEST_DYN_LINK". Otherwise, this symbol must *not* be defined. Resolution: Introduce a new Autoconf macro, OPM_DYNLINK_BOOST_TEST, that defines a secondary symbol--HAVE_DYNAMIC_BOOST_TEST--if the local computer system uses dynamic linking. Test suites (e.g., tests/param_test.cpp) may then inspect this symbol to determine whether or not to #define BOOST_TEST_DYN_LINK. Call the macro from "configure.ac". Suggested by: Joakim Hove --- configure.ac | 2 + m4/opm_dynlink_boost_test.m4 | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 m4/opm_dynlink_boost_test.m4 diff --git a/configure.ac b/configure.ac index 7f82ebcc..ef5fc0d8 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,8 @@ AX_BOOST_UNIT_TEST_FRAMEWORK AX_DUNE_ISTL OPM_AGMG +OPM_DYNLINK_BOOST_TEST + # Checks for header files. AC_CHECK_HEADERS([float.h limits.h stddef.h stdlib.h string.h]) diff --git a/m4/opm_dynlink_boost_test.m4 b/m4/opm_dynlink_boost_test.m4 new file mode 100644 index 00000000..89c82908 --- /dev/null +++ b/m4/opm_dynlink_boost_test.m4 @@ -0,0 +1,80 @@ +# _OPM_DYNLINK_BOOST_TEST_SRC(Symbol) +# Generate source text for use in AC_LINK_IFELSE when determining +# how to link the Boost.Test library. +# +# Note: +# We use AC_LANG_SOURCE rather than AC_LANG_PROGRAM to avoid +# multiple definitions of "main()" (defined by both the UTF +# *and* the AC_LANG_PROGRAM macro). +AC_DEFUN([_OPM_DYNLINK_BOOST_TEST_SRC], +[AC_LANG_SOURCE( +[[$1 +#define BOOST_TEST_MODULE OPM_DYNLINK_TEST +#include + +int f(int x) { return 2 * x; } + +BOOST_AUTO_TEST_CASE(DynlinkConfigureTest) { + BOOST_CHECK_MESSAGE(f(2) == 4, + "Apparently, multiplication doesn't " + "work: f(2) = " << f(2)); +} +]]dnl +)[]dnl +]) + +dnl ------------------------------------------------------------------- + +# OPM_DYNLINK_BOOST_TEST +# Determine how to link (or compile+link) tests based on the UTF. +# +# If the system uses dynamic linking, then all tests need to +# +# #define BOOST_TEST_DYN_LINK +# +# Otherwise, this symbol must *not* be #define'd. +# +# Macro defines the symbol HAVE_DYNAMIC_BOOST_TEST (to 1) if the +# system uses dynamic linking of Boost.Test . +AC_DEFUN([OPM_DYNLINK_BOOST_TEST], +[ +AC_REQUIRE([AX_BOOST_BASE]) +AC_REQUIRE([AX_BOOST_UNIT_TEST_FRAMEWORK]) + +_opm_LIBS_SAVE="$LIBS" +_opm_CPPFLAGS_SAVE="$CPPFLAGS" + +LIBS="${BOOST_LDFLAGS} ${BOOST_UNIT_TEST_FRAMEWORK_LIB} ${LIBS}" +CPPFLAGS="${BOOST_CPPFLAGS} ${CPPFLAGS}" + +AC_LANG_PUSH([C++]) + +AC_CACHE_CHECK([if the Boost.Test library can be linked statically],dnl +[opm_cv_boost_link_static],dnl +[AC_LINK_IFELSE([_OPM_DYNLINK_BOOST_TEST_SRC([])], + [opm_cv_boost_link_static=yes],dnl + [opm_cv_boost_link_static=no])[]dnl +])[]dnl + +AC_CACHE_CHECK([if the Boost.Test library can be linked dynamically],dnl +[opm_cv_boost_link_dynamic],dnl +[AC_LINK_IFELSE([_OPM_DYNLINK_BOOST_TEST_SRC(dnl +[#define BOOST_TEST_DYN_LINK])], + [opm_cv_boost_link_dynamic=yes],dnl + [opm_cv_boost_link_dynamic=no])[]dnl +])[]dnl + +AC_LANG_POP([C++]) + +LIBS="$_opm_LIBS_SAVE" +CPPFLAGS="$_opm_CPPFLAGS_SAVE" + +AS_IF([test x"$opm_cv_boost_link_static" = x"yes" -o \ + x"$opm_cv_boost_link_dynamic" = x"yes"], +[AS_IF([test x"$opm_cv_boost_link_dynamic" = x"yes"], + [AC_DEFINE([HAVE_DYNAMIC_BOOST_TEST], [1], + [Define to `1' if Boost.Test should use BOOST_TEST_DYN_LINK])] + [:])[]dnl +],dnl +[AC_MSG_NOTICE([Boost.Test is not supported on this system])]) +])[]dnl