Check for Boost libs ending with suffix "-mt" and without.
[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_CPPFLAGS="-I${with_boost}/include"
32             BOOST_LIB="-L${with_boost}/lib"
33         fi
34         if test "${with_boost}" = "no"; then
35             AC_MSG_RESULT([disabled])
36         else
37             CPPFLAGS="${CPPFLAGS} ${BOOST_CPPFLAGS}"
38             LIBS="${LIBS} ${BOOST_LIB}"
39             AC_LANG_CONFTEST(
40                [AC_LANG_SOURCE([[
41 #include <boost/version.hpp>
42 version_is:BOOST_VERSION
43 ]])])
44             BOOST_GOT_VERSION=`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | $EGREP version_is 2>/dev/null | cut -d ":" -f2`
45             if test $BOOST_GOT_VERSION = "BOOST_VERSION"; then
46                 AC_MSG_RESULT([no])
47                 AC_MSG_ERROR([Boost development libraries required])
48             fi
49             AC_MSG_RESULT([yes ($BOOST_GOT_VERSION)])
50             if test $BOOST_GOT_VERSION -lt $BOOST_REQ_VERSION; then
51                 AC_MSG_ERROR([Boost version $BOOST_REQ_VERSION required])
52             fi
53             for c in $1; do
54                 case $c in 
55                     thread)
56                         AC_SUBST([BOOST_THREAD_LIB])
57                         BOOST_THREAD_LIB=""
58                         for l in boost_thread-mt boost_thread; do
59                             AC_CHECK_LIB([${l}],[main],[
60                                     BOOST_THREAD_LIB="-l${l}"
61                                     break
62                                     ],[])
63                         done
64                         if test -z "${BOOST_THREAD_LIB}"; then
65                             AC_MSG_ERROR([Boost thread libs not found])
66                         fi
67                         LIBS="${LIBS} ${BOOST_THREAD_LIB}"
68                         AC_MSG_CHECKING([Boost threads])
69                         AC_LINK_IFELSE([AC_LANG_PROGRAM([[
70 #include <boost/version.hpp>
71 #include <boost/thread/thread.hpp>
72 ]],[[ 
73 int x = BOOST_VERSION;
74 ]])],[AC_MSG_RESULT([yes])],[
75 AC_MSG_RESULT([no])
76 AC_MSG_ERROR([Boost thread libraries required])
77                             ])
78                         ;;
79                     test)
80                         AC_SUBST([BOOST_TEST_LIB])
81                         BOOST_TEST_LIB=""
82                         for l in boost_unit_test_framework-mt boost_unit_test_framework; do
83                             AC_CHECK_LIB([${l}],[main],[
84                                     BOOST_TEST_LIB="-l${l}"
85                                     break
86                                     ],[])
87                         done
88                         if test -z "${BOOST_TEST_LIB}"; then
89                             AC_MSG_ERROR([Boost unit test libs not found])
90                         fi
91                         saveLIBS="${LIBS}"
92                         LIBS="${LIBS} ${BOOST_TEST_LIB}"
93                         AC_MSG_CHECKING([Boost unit test framework])
94                         AC_LINK_IFELSE([AC_LANG_PROGRAM([[
95 #define BOOST_TEST_DYN_LINK
96 #include <boost/test/auto_unit_test.hpp>
97 BOOST_AUTO_TEST_CASE( t ) 
98 {
99     BOOST_CHECK(1);
100 }
101 ]],[[ 
102 ]])],[AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])
103 AC_MSG_ERROR([Boost unit test framework libraries required])])
104                         LIBS="${saveLIBS}"
105                         ;;
106                 esac
107             done
108         fi
109         CPPFLAGS="$oldCPPFLAGS"
110         LIBS="$oldLIBS"
111         AC_LANG_POP([C++])
112     ])
113  
114