added m4 macros for boost C++ headers and libs, hopefully making better autoconf...
[m4-moved-to-github.git] / ax_boost_iostreams.m4
1 ##### http://autoconf-archive.cryp.to/ax_boost_iostreams.html
2 #
3 # SYNOPSIS
4 #
5 #   AX_BOOST_IOSTREAMS
6 #
7 # DESCRIPTION
8 #
9 #   Test for IOStreams library from the Boost C++ libraries. The macro
10 #   requires a preceding call to AX_BOOST_BASE. Further documentation
11 #   is available at <http://randspringer.de/boost/index.html>.
12 #
13 #   This macro calls:
14 #
15 #     AC_SUBST(BOOST_IOSTREAMS_LIB)
16 #
17 #   And sets:
18 #
19 #     HAVE_BOOST_IOSTREAMS
20 #
21 # LAST MODIFICATION
22 #
23 #   2006-12-28
24 #
25 # COPYLEFT
26 #
27 #   Copyright (c) 2006 Thomas Porschberg <thomas@randspringer.de>
28 #
29 #   Copying and distribution of this file, with or without
30 #   modification, are permitted in any medium without royalty provided
31 #   the copyright notice and this notice are preserved.
32
33 AC_DEFUN([AX_BOOST_IOSTREAMS],
34 [
35         AC_ARG_WITH([boost-iostreams],
36         AS_HELP_STRING([--with-boost-iostreams@<:@=special-lib@:>@],
37                    [use the IOStreams library from boost - it is possible to specify a certain library for the linker
38                         e.g. --with-boost-iostreams=boost_iostreams-gcc-mt-d-1_33_1 ]),
39         [
40         if test "$withval" = "no"; then
41                         want_boost="no"
42         elif test "$withval" = "yes"; then
43             want_boost="yes"
44             ax_boost_user_iostreams_lib=""
45         else
46                     want_boost="yes"
47                 ax_boost_user_iostreams_lib="$withval"
48                 fi
49         ],
50         [want_boost="yes"]
51         )
52
53         if test "x$want_boost" = "xyes"; then
54         AC_REQUIRE([AC_PROG_CC])
55                 CPPFLAGS_SAVED="$CPPFLAGS"
56                 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
57                 export CPPFLAGS
58
59                 LDFLAGS_SAVED="$LDFLAGS"
60                 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
61                 export LDFLAGS
62
63         AC_CACHE_CHECK(whether the Boost::IOStreams library is available,
64                                            ax_cv_boost_iostreams,
65         [AC_LANG_PUSH([C++])
66                  AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/iostreams/filtering_stream.hpp>
67                                                                                          @%:@include <boost/range/iterator_range.hpp>
68                                                                                         ]],
69                                   [[std::string  input = "Hello World!";
70                                                                  namespace io = boost::iostreams;
71                                                                          io::filtering_istream  in(boost::make_iterator_range(input));
72                                                                          return 0;
73                                    ]]),
74                              ax_cv_boost_iostreams=yes, ax_cv_boost_iostreams=no)
75          AC_LANG_POP([C++])
76                 ])
77                 if test "x$ax_cv_boost_iostreams" = "xyes"; then
78                         AC_DEFINE(HAVE_BOOST_IOSTREAMS,,[define if the Boost::IOStreams library is available])
79                         BN=boost_iostreams
80             if test "x$ax_boost_user_iostreams_lib" = "x"; then
81                                 for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
82                               lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
83                               $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
84                                     AC_CHECK_LIB($ax_lib, main, [BOOST_IOSTREAMS_LIB="-l$ax_lib" AC_SUBST(BOOST_IOSTREAMS_LIB) link_thread="yes" break],
85                                  [link_thread="no"])
86                                 done
87             else
88                for ax_lib in $ax_boost_user_iostreams_lib $BN-$ax_boost_user_iostreams_lib; do
89                                       AC_CHECK_LIB($ax_lib, main,
90                                    [BOOST_IOSTREAMS_LIB="-l$ax_lib" AC_SUBST(BOOST_IOSTREAMS_LIB) link_iostreams="yes" break],
91                                    [link_iostreams="no"])
92                   done
93
94             fi
95                         if test "x$link_iostreams" = "xno"; then
96                                 AC_MSG_ERROR(Could not link against $ax_lib !)
97                         fi
98                 fi
99
100                 CPPFLAGS="$CPPFLAGS_SAVED"
101         LDFLAGS="$LDFLAGS_SAVED"
102         fi
103 ])