Use m4 macro ACX_PTHREAD for POSIX threads detection.
[m4-moved-to-github.git] / ax_boost_filesystem.m4
1 ##### http://autoconf-archive.cryp.to/ax_boost_filesystem.html
2 #
3 # SYNOPSIS
4 #
5 #   AX_BOOST_FILESYSTEM
6 #
7 # DESCRIPTION
8 #
9 #   Test for Filesystem 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_FILESYSTEM_LIB)
16 #
17 #   And sets:
18 #
19 #     HAVE_BOOST_FILESYSTEM
20 #
21 # LAST MODIFICATION
22 #
23 #   2006-12-28
24 #
25 # COPYLEFT
26 #
27 #   Copyright (c) 2006 Thomas Porschberg <thomas@randspringer.de>
28 #   Copyright (c) 2006 Michael Tindal <mtindal@paradoxpoint.com>
29 #
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.
33
34 AC_DEFUN([AX_BOOST_FILESYSTEM],
35 [
36         AC_ARG_WITH([boost-filesystem],
37         AS_HELP_STRING([--with-boost-filesystem@<:@=special-lib@:>@],
38                    [use the Filesystem library from boost - it is possible to specify a certain library for the linker
39                         e.g. --with-boost-filesystem=boost_filesystem-gcc-mt ]),
40         [
41         if test "$withval" = "no"; then
42                         want_boost="no"
43         elif test "$withval" = "yes"; then
44             want_boost="yes"
45             ax_boost_user_filesystem_lib=""
46         else
47                     want_boost="yes"
48                 ax_boost_user_filesystem_lib="$withval"
49                 fi
50         ],
51         [want_boost="yes"]
52         )
53
54         if test "x$want_boost" = "xyes"; then
55         AC_REQUIRE([AC_PROG_CC])
56                 CPPFLAGS_SAVED="$CPPFLAGS"
57                 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
58                 export CPPFLAGS
59
60                 LDFLAGS_SAVED="$LDFLAGS"
61                 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
62                 export LDFLAGS
63
64         AC_CACHE_CHECK(whether the Boost::Filesystem library is available,
65                                            ax_cv_boost_filesystem,
66         [AC_LANG_PUSH([C++])
67          AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/filesystem/path.hpp>]],
68                                    [[using namespace boost::filesystem;
69                                    path my_path( "foo/bar/data.txt" );
70                                    return 0;]]),
71                                                ax_cv_boost_filesystem=yes, ax_cv_boost_filesystem=no)
72          AC_LANG_POP([C++])
73                 ])
74                 if test "x$ax_cv_boost_filesystem" = "xyes"; then
75                         AC_DEFINE(HAVE_BOOST_FILESYSTEM,,[define if the Boost::Filesystem library is available])
76                         BN=boost_filesystem
77             if test "x$ax_boost_user_filesystem_lib" = "x"; then
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                                     AC_CHECK_LIB($ax_lib, main,
82                                  [BOOST_FILESYSTEM_LIB="-l$ax_lib" AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes" break],
83                                  [link_filesystem="no"])
84                                 done
85             else
86                for ax_lib in $ax_boost_user_filesystem_lib $BN-$ax_boost_user_filesystem_lib; do
87                                       AC_CHECK_LIB($ax_lib, main,
88                                    [BOOST_FILESYSTEM_LIB="-l$ax_lib" AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes" break],
89                                    [link_filesystem="no"])
90                   done
91
92             fi
93                         if test "x$link_filesystem" = "xno"; then
94                                 AC_MSG_ERROR(Could not link against $ax_lib !)
95                         fi
96                 fi
97
98                 CPPFLAGS="$CPPFLAGS_SAVED"
99         LDFLAGS="$LDFLAGS_SAVED"
100         fi
101 ])