Fixed source directory
[m4-moved-to-github.git] / boost.m4
1 # configure for Boost libs
2 #
3 # ID_BOOST([components],[libs])
4 #
5 # Sets the following variables:
6 #
7 #   BOOST_CPPFLAGS
8 #   BOOST_LIB
9 # If components include "thread":
10 #   BOOST_THREAD_LIB
11 # If components include "test":
12 #   BOOST_TEST_LIB
13
14 AC_DEFUN([ID_BOOST],
15     [
16         AC_SUBST([BOOST_CPPFLAGS])
17         AC_SUBST([BOOST_LIB])
18         
19         AC_MSG_CHECKING([for Boost])
20         AC_LANG_PUSH([C++])
21         oldCPPFLAGS="$CPPFLAGS"
22         oldLIBS="$LIBS"
23         BOOST_REQ_VERSION=`echo "$2" | awk 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 100 + [$]3;}'`
24         CPPFLAGS="$CPPFLAGS -DBOOST_REQ_VERSION=${BOOST_REQ_VERSION}"
25
26         AC_ARG_WITH([boost],[  --with-boost=DIR        use Boost in prefix DIR])
27         if test "$with_boost" = "yes" -o -z "$with_boost"; then
28             BOOST_CPPFLAGS=""
29             BOOST_LIB=""
30         else
31             BOOST_LIB="-L${with_boost}/lib"
32             BOOST_CPPFLAGS="-I${with_boost}/include"
33             if test ! -f "${with_boost}/include/version.hpp"; then
34                 for b in ${with_boost}/include/boost-*; do
35                     BOOST_CPPFLAGS="-I$b"
36                 done
37             fi
38         fi
39         AC_ARG_WITH([boost-toolset],[  --with-boost-toolset=x  use Boost toolset (eg gcc43)])
40         if test "$with_boost_toolset" = "yes" -o -z "$with_boost_toolset"; then
41             BOOST_TOOLSET=""
42         else
43             BOOST_TOOLSET="-${with_boost_toolset}"
44         fi
45         if test "${with_boost}" = "no"; then
46             AC_MSG_RESULT([disabled])
47         else
48             CPPFLAGS="${CPPFLAGS} ${BOOST_CPPFLAGS}"
49             LIBS="${LIBS} ${BOOST_LIB}"
50             AC_LANG_CONFTEST(
51                [AC_LANG_SOURCE([[
52 #include <boost/version.hpp>
53 version_is:BOOST_VERSION
54 ]])])
55             BOOST_GOT_VERSION=`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | $EGREP version_is 2>/dev/null | cut -d ":" -f2`
56             if test "$BOOST_GOT_VERSION" = "BOOST_VERSION"; then
57                 AC_MSG_RESULT([no])
58                 AC_MSG_ERROR([Boost development libraries required])
59             fi
60             AC_MSG_RESULT([yes ($BOOST_GOT_VERSION)])
61             if test "$BOOST_GOT_VERSION" -lt $BOOST_REQ_VERSION; then
62                 AC_MSG_ERROR([Boost version $BOOST_REQ_VERSION required])
63             fi
64             for c in $1; do
65                 case $c in 
66                     thread)
67                         AC_MSG_CHECKING([Boost threads])
68                         AC_SUBST([BOOST_THREAD_LIB])
69                         saveLIBS="${LIBS}"
70                         BOOST_THREAD_LIB=""
71                         for l in boost_thread${BOOST_TOOLSET}-mt boost_thread${BOOST_TOOLSET}; do
72                             LIBS="${saveLIBS} -l${l}"
73                         AC_LINK_IFELSE([AC_LANG_PROGRAM([[
74 #include <boost/version.hpp>
75 #include <boost/thread/thread.hpp>
76 ]],[[ 
77 int x = BOOST_VERSION;
78 ]])],[
79                             BOOST_THREAD_LIB="-l${l}"
80                             break],[])
81                         done
82                         if test "${BOOST_THREAD_LIB}"; then
83                             AC_MSG_RESULT([yes])
84                         else
85                             AC_MSG_RESULT([no])
86                         fi
87                         ;;
88                     test)
89                         AC_MSG_CHECKING([Boost unit test framework])
90                         saveLIBS="${LIBS}"
91                         AC_SUBST([BOOST_TEST_LIB])
92                         BOOST_TEST_LIB=""
93                         for l in boost_unit_test_framework${BOOST_TOOLSET}-mt boost_unit_test_framework${BOOST_TOOLSET}; do
94                             LIBS="${saveLIBS} -l${l}"
95                             AC_LINK_IFELSE([AC_LANG_SOURCE([[
96 #define BOOST_TEST_DYN_LINK
97 #define BOOST_AUTO_TEST_MAIN
98 #include <boost/test/auto_unit_test.hpp>
99 BOOST_AUTO_TEST_CASE( t ) 
100 {
101     BOOST_CHECK(1);
102 }
103 ]])],[
104                               BOOST_TEST_LIB="-l${l}"
105                               break
106 ],[])
107                         done
108                         if test "${BOOST_TEST_LIB}"; then
109                             AC_MSG_RESULT([yes])
110                         else
111                             AC_MSG_RESULT([no])
112                         fi
113                         LIBS="${saveLIBS}"
114                         ;;
115                 esac
116             done
117         fi
118         CPPFLAGS="$oldCPPFLAGS"
119         LIBS="$oldLIBS"
120         AC_LANG_POP([C++])
121     ])
122
123 dnl Local Variables:
124 dnl mode:shell-script
125 dnl sh-indentation: 2
126 dnl sh-basic-offset: 4
127 dnl End: