Initial fix of Libt2n.cmake.
[libt2n] / m4 / ax_boost_serialization.m4
1 # ===========================================================================
2 #         http://autoconf-archive.cryp.to/ax_boost_serialization.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AX_BOOST_SERIALIZATION
8 #
9 # DESCRIPTION
10 #
11 #   Test for Serialization library from the Boost C++ libraries. The macro
12 #   requires a preceding call to AX_BOOST_BASE. Further documentation is
13 #   available at <http://randspringer.de/boost/index.html>.
14 #
15 #   This macro calls:
16 #
17 #     AC_SUBST(BOOST_SERIALIZATION_LIB)
18 #
19 #   And sets:
20 #
21 #     HAVE_BOOST_SERIALIZATION
22 #
23 # LAST MODIFICATION
24 #
25 #   2008-04-12
26 #
27 # COPYLEFT
28 #
29 #   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
30 #
31 #   Copying and distribution of this file, with or without modification, are
32 #   permitted in any medium without royalty provided the copyright notice
33 #   and this notice are preserved.
34
35 AC_DEFUN([AX_BOOST_SERIALIZATION],
36 [
37         AC_ARG_WITH([boost-serialization],
38         AS_HELP_STRING([--with-boost-serialization@<:@=special-lib@:>@],
39                    [use the Serialization library from boost - it is possible to specify a certain library for the linker
40                         e.g. --with-boost-serialization=boost_serialization-gcc-mt-d-1_33_1 ]),
41         [
42         if test "$withval" = "no"; then
43                         want_boost="no"
44         elif test "$withval" = "yes"; then
45             want_boost="yes"
46             ax_boost_user_serialization_lib=""
47         else
48                     want_boost="yes"
49                 ax_boost_user_serialization_lib="$withval"
50                 fi
51         ],
52         [want_boost="yes"]
53         )
54
55         if test "x$want_boost" = "xyes"; then
56         AC_REQUIRE([AC_PROG_CC])
57                 CPPFLAGS_SAVED="$CPPFLAGS"
58                 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
59             AC_MSG_WARN(BOOST_CPPFLAGS $BOOST_CPPFLAGS)
60                 export CPPFLAGS
61
62                 LDFLAGS_SAVED="$LDFLAGS"
63                 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
64                 export LDFLAGS
65
66         AC_CACHE_CHECK(whether the Boost::Serialization library is available,
67                                            ax_cv_boost_serialization,
68         [AC_LANG_PUSH([C++])
69                          AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <fstream>
70                                                                                                  @%:@include <boost/archive/text_oarchive.hpp>
71                                                  @%:@include <boost/archive/text_iarchive.hpp>
72                                                                                                 ]],
73                                    [[std::ofstream ofs("filename");
74                                                                         boost::archive::text_oarchive oa(ofs);
75                                                                          return 0;
76                                    ]]),
77                    ax_cv_boost_serialization=yes, ax_cv_boost_serialization=no)
78          AC_LANG_POP([C++])
79                 ])
80                 if test "x$ax_cv_boost_serialization" = "xyes"; then
81                         AC_DEFINE(HAVE_BOOST_SERIALIZATION,,[define if the Boost::Serialization library is available])
82             BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
83             if test "x$ax_boost_user_serialization_lib" = "x"; then
84                 for libextension in `ls $BOOSTLIBDIR/libboost_serialization*.{so,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_serialization.*\)\.so.*$;\1;' -e 's;^lib\(boost_serialization.*\)\.a*$;\1;'` ; do
85                      ax_lib=${libextension}
86                                     AC_CHECK_LIB($ax_lib, exit,
87                                  [BOOST_SERIALIZATION_LIB="-l$ax_lib"; AC_SUBST(BOOST_SERIALIZATION_LIB) link_serialization="yes"; break],
88                                  [link_serialization="no"])
89                                 done
90                 if test "x$link_serialization" != "xyes"; then
91                 for libextension in `ls $BOOSTLIBDIR/boost_serialization*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_serialization.*\)\.dll.*$;\1;' -e 's;^\(boost_serialization.*\)\.a*$;\1;'` ; do
92                      ax_lib=${libextension}
93                                     AC_CHECK_LIB($ax_lib, exit,
94                                  [BOOST_SERIALIZATION_LIB="-l$ax_lib"; AC_SUBST(BOOST_SERIALIZATION_LIB) link_serialization="yes"; break],
95                                  [link_serialization="no"])
96                                 done
97                 fi
98
99             else
100                for ax_lib in $ax_boost_user_serialization_lib boost_serialization-$ax_boost_user_serialization_lib; do
101                                       AC_CHECK_LIB($ax_lib, main,
102                                    [BOOST_SERIALIZATION_LIB="-l$ax_lib"; AC_SUBST(BOOST_SERIALIZATION_LIB) link_serialization="yes"; break],
103                                    [link_serialization="no"])
104                   done
105
106             fi
107                         if test "x$link_serialization" != "xyes"; then
108                                 AC_MSG_ERROR(Could not link against $ax_lib !)
109                         fi
110                 fi
111
112                 CPPFLAGS="$CPPFLAGS_SAVED"
113         LDFLAGS="$LDFLAGS_SAVED"
114         fi
115 ])