1 # ================================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_boost_unit_test_framework.html
3 # ================================================================================
7 # AX_BOOST_UNIT_TEST_FRAMEWORK
11 # Test for Unit_Test_Framework library from the Boost C++ libraries. The
12 # macro requires a preceding call to AX_BOOST_BASE. Further documentation
13 # is available at <http://randspringer.de/boost/index.html>.
17 # AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
21 # HAVE_BOOST_UNIT_TEST_FRAMEWORK
25 # Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
27 # Copying and distribution of this file, with or without modification, are
28 # permitted in any medium without royalty provided the copyright notice
29 # and this notice are preserved. This file is offered as-is, without any
34 AC_DEFUN([AX_BOOST_UNIT_TEST_FRAMEWORK],
36 AC_ARG_WITH([boost-unit-test-framework],
37 AS_HELP_STRING([--with-boost-unit-test-framework@<:@=special-lib@:>@],
38 [use the Unit_Test_Framework library from boost - it is possible to specify a certain library for the linker
39 e.g. --with-boost-unit-test-framework=boost_unit_test_framework-gcc ]),
41 if test "$withval" = "no"; then
43 elif test "$withval" = "yes"; then
45 ax_boost_user_unit_test_framework_lib=""
48 ax_boost_user_unit_test_framework_lib="$withval"
54 if test "x$want_boost" = "xyes"; then
55 AC_REQUIRE([AC_PROG_CC])
56 CPPFLAGS_SAVED="$CPPFLAGS"
57 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
60 LDFLAGS_SAVED="$LDFLAGS"
61 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
64 AC_CACHE_CHECK(whether the Boost::Unit_Test_Framework library is available,
65 ax_cv_boost_unit_test_framework,
67 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/test/unit_test.hpp>]],
68 [[using boost::unit_test::test_suite;
69 test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" ); return 0;]])],
70 ax_cv_boost_unit_test_framework=yes, ax_cv_boost_unit_test_framework=no)
73 if test "x$ax_cv_boost_unit_test_framework" = "xyes"; then
74 AC_DEFINE(HAVE_BOOST_UNIT_TEST_FRAMEWORK,,[define if the Boost::Unit_Test_Framework library is available])
75 BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
77 if test "x$ax_boost_user_unit_test_framework_lib" = "x"; then
78 saved_ldflags="${LDFLAGS}"
79 for monitor_library in `ls $BOOSTLIBDIR/libboost_unit_test_framework*.so* $BOOSTLIBDIR/libboost_unit_test_framework*.a* 2>/dev/null` ; do
80 if test -r $monitor_library ; then
81 libextension=`echo $monitor_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a*$;\1;'`
82 ax_lib=${libextension}
83 link_unit_test_framework="yes"
85 link_unit_test_framework="no"
88 if test "x$link_unit_test_framework" = "xyes"; then
89 BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
90 AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
94 if test "x$link_unit_test_framework" != "xyes"; then
95 for libextension in `ls $BOOSTLIBDIR/boost_unit_test_framework*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_unit_test_framework.*\)\.dll.*$;\1;' -e 's;^\(boost_unit_test_framework.*\)\.a*$;\1;'` ; do
96 ax_lib=${libextension}
97 AC_CHECK_LIB($ax_lib, exit,
98 [BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"; AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) link_unit_test_framework="yes"; break],
99 [link_unit_test_framework="no"])
103 link_unit_test_framework="no"
104 saved_ldflags="${LDFLAGS}"
105 for ax_lib in boost_unit_test_framework-$ax_boost_user_unit_test_framework_lib $ax_boost_user_unit_test_framework_lib ; do
106 if test "x$link_unit_test_framework" = "xyes"; then
109 for unittest_library in `ls $BOOSTLIBDIR/lib${ax_lib}.so* $BOOSTLIBDIR/lib${ax_lib}.a* 2>/dev/null` ; do
110 if test -r $unittest_library ; then
111 libextension=`echo $unittest_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a*$;\1;'`
112 ax_lib=${libextension}
113 link_unit_test_framework="yes"
115 link_unit_test_framework="no"
118 if test "x$link_unit_test_framework" = "xyes"; then
119 BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
120 AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
126 if test "x$ax_lib" = "x"; then
127 AC_MSG_ERROR(Could not find a version of the library!)
129 if test "x$link_unit_test_framework" != "xyes"; then
130 AC_MSG_ERROR(Could not link against $ax_lib !)
134 CPPFLAGS="$CPPFLAGS_SAVED"
135 LDFLAGS="$LDFLAGS_SAVED"