1 ##### http://autoconf-archive.cryp.to/ax_boost_unit_test_framework.html
5 # AX_BOOST_UNIT_TEST_FRAMEWORK
9 # Test for Unit_Test_Framework library from the Boost C++ libraries.
10 # The macro requires a preceding call to AX_BOOST_BASE. Further
11 # documentation is available at
12 # <http://randspringer.de/boost/index.html>.
16 # AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
20 # HAVE_BOOST_UNIT_TEST_FRAMEWORK
28 # Copyright (c) 2006 Thomas Porschberg <thomas@randspringer.de>
30 # Copying and distribution of this file, with or without
31 # modification, are permitted in any medium without royalty provided
32 # the copyright notice and this notice are preserved.
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 BN=boost_unit_test_framework
76 if test "x$ax_boost_user_unit_test_framework_lib" = "x"; then
77 saved_ldflags="${LDFLAGS}"
78 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
79 lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
80 $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
81 LDFLAGS="${LDFLAGS} -l$ax_lib"
82 AC_CACHE_CHECK(Boost::UnitTestFramework library linkage,
83 ax_cv_boost_unit_test_framework_link,
85 AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/test/unit_test.hpp>
86 using boost::unit_test::test_suite;
87 test_suite* init_unit_test_suite( int argc, char * argv[] ) {
88 test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" );
93 link_unit_test_framework="yes",link_unit_test_framework="no")
96 LDFLAGS="${saved_ldflags}"
98 if test "x$link_unit_test_framework" = "xyes"; then
99 BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
100 AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
105 saved_ldflags="${LDFLAGS}"
106 for ax_lib in $ax_boost_user_unit_test_framework_lib $BN-$ax_boost_user_unit_test_framework_lib; do
107 LDFLAGS="${LDFLAGS} -l$ax_lib"
108 AC_CACHE_CHECK(Boost::UnitTestFramework library linkage,
109 ax_cv_boost_unit_test_framework_link,
111 AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/test/unit_test.hpp>
112 using boost::unit_test::test_suite;
113 test_suite* init_unit_test_suite( int argc, char * argv[] ) {
114 test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" );
119 link_unit_test_framework="yes",link_unit_test_framework="no")
122 LDFLAGS="${saved_ldflags}"
123 if test "x$link_unit_test_framework" = "xyes"; then
124 BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
125 AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
130 if test "x$link_unit_test_framework" = "xno"; then
131 AC_MSG_ERROR(Could not link against $ax_lib !)
135 CPPFLAGS="$CPPFLAGS_SAVED"
136 LDFLAGS="$LDFLAGS_SAVED"