Synopsis - Cross-Reference

File: /config/boost.m4
  1# Copyright (C) 2007 Stefan Seefeld
  2# All rights reserved.
  3# Licensed to the public under the terms of the GNU LGPL (>= 2),
  4# see the file COPYING for details.
  5
  6#
  7# The code in this file got heavily inspired from monotone's m4 code.
  8#
  9
 10
 11
 12#   AC_BOOST([MINIMUM-VERSION])
 13#
 14#   Test for the Boost C++ libraries of a particular version (or newer)
 15#
 16#   If no path to the installed boost library is given the macro
 17#   searchs under /usr, /usr/local, and /opt, and evaluates the
 18#   $BOOST_ROOT environment variable.
 19#
 20#   This macro substitutes:
 21#
 22#     BOOST_VERSION, BOOST_CPPFLAGS, and BOOST_LDFLAGS
 23#
 24#   and sets:
 25#
 26#     HAVE_BOOST
 27#
 28AC_DEFUN([AC_BOOST],
 29[
 30AC_ARG_WITH([boost_prefix],
 31	    AS_HELP_STRING([--with-boost-prefix=PREFIX],
 32                           [specify boost installation prefix]))
 33AC_ARG_WITH([boost_version],
 34	    AS_HELP_STRING([--with-boost-version=VERSION],
 35                           [specify boost version]),
 36  [boost_version="$withval"],[boost_version=$1])
 37
 38boost_version_req=ifelse([$boost_version], ,1.33.0,$boost_version)
 39boost_version_req_shorten=`expr $boost_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
 40boost_version_req_major=`expr $boost_version_req : '\([[0-9]]*\)'`
 41boost_version_req_minor=`expr $boost_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
 42boost_version_req_sub_minor=`expr $boost_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
 43if test "x$boost_version_req_sub_minor" = "x" ; then
 44  boost_version_req_sub_minor="0"
 45fi
 46REQ_BOOST_VERSION=`expr $boost_version_req_major \* 100000 \+  $boost_version_req_minor \* 100 \+ $boost_version_req_sub_minor`
 47AC_MSG_CHECKING(for boost >= $boost_version_req)
 48succeeded=no
 49
 50dnl first we check the system location for boost libraries
 51dnl this location ist chosen if boost libraries are installed 
 52dnl with the --layout=system option.
 53if test "$with_boost_prefix" != ""; then
 54  BOOST_LDFLAGS="-L$with_boost_prefix/lib"
 55  BOOST_CPPFLAGS="-I$with_boost_prefix/include"
 56else
 57  for prefix in /usr /usr/local /opt ; do
 58    if test -d "$prefix/include/boost" && test -r "$prefix/include/boost"; then
 59      BOOST_LDFLAGS="-L$prefix/lib"
 60      BOOST_CPPFLAGS="-I$prefix/include"
 61      break;
 62    fi
 63  done
 64fi
 65
 66CPPFLAGS_SAVED="$CPPFLAGS"
 67CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
 68
 69LDFLAGS_SAVED="$LDFLAGS"
 70LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
 71
 72AC_LANG_PUSH(C++)
 73AC_RUN_IFELSE([
 74  AC_LANG_PROGRAM(
 75  [
 76   #include <boost/version.hpp>
 77   #include <fstream>
 78  ],
 79  [dnl
 80#if BOOST_VERSION >= $REQ_BOOST_VERSION
 81  std::ofstream ofs("conftest.out");
 82  ofs << BOOST_VERSION / 100000 << '.' << BOOST_VERSION / 100 % 1000;
 83#else
 84#  error Boost version is too old
 85#endif
 86  ])],
 87  [
 88    BOOST_VERSION=`cat conftest.out`
 89    AC_MSG_RESULT(yes)
 90    succeeded=yes
 91    found_system=yes
 92  ],
 93  [])
 94
 95AC_LANG_POP([C++])
 96
 97dnl if we found no boost with system layout we search for boost libraries
 98dnl built and installed without the --layout=system option 
 99dnl or for a staged(not installed) version
100if test "x$succeeded" != "xyes"; then
101  _version=0
102  if test "$with_boost_prefix" != ""; then
103    BOOST_LDFLAGS="-L$with_boost_prefix/lib"
104    if test -d "$with_boost_prefix" && test -r "$with_boost_prefix"; then
105      for i in `ls -d $with_boost_prefix/include/boost-* 2>/dev/null`; do
106        _version_tmp=`echo $i | sed "s#$with_boost_prefix##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
107        V_CHECK=`expr $_version_tmp \> $_version`
108        if test "$V_CHECK" = "1" ; then
109          _version=$_version_tmp
110        fi
111        VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
112        BOOST_CPPFLAGS="-I$with_boost_prefix/include/boost-$VERSION_UNDERSCORE"
113      done
114    fi
115  else
116    for prefix in /usr /usr/local /opt ; do
117      if test -d "$prefix" && test -r "$prefix"; then
118        for i in `ls -d $prefix/include/boost-* 2>/dev/null`; do
119          _version_tmp=`echo $i | sed "s#$prefix##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
120          V_CHECK=`expr $_version_tmp \> $_version`
121          if test "$V_CHECK" = "1" ; then
122            _version=$_version_tmp
123            best_path=$prefix
124          fi
125        done
126      fi
127    done
128
129    VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
130    BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
131    BOOST_LDFLAGS="-L$best_path/lib"
132
133    if test "x$BOOST_ROOT" != "x"; then
134      if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then
135        version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
136        stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
137        stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
138        V_CHECK=`expr $stage_version_shorten \>\= $_version`
139        if test "$V_CHECK" = "1" ; then
140          AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
141          BOOST_CPPFLAGS="-I$BOOST_ROOT"
142          BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib"
143        fi
144      fi
145    fi
146  fi
147  CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
148  LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
149
150  AC_LANG_PUSH(C++)
151  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
152    [[#include <boost/version.hpp>]],
153    [[#if BOOST_VERSION >= $REQ_BOOST_VERSION
154      // Everything is okay
155      #else
156      # error Boost version is too old
157      #endif
158    ]])],
159    [
160      AC_MSG_RESULT(yes)
161      succeeded=yes
162      found_system=yes
163    ],[])
164  AC_LANG_POP([C++])
165  BOOST_VERSION="$_version"
166fi
167
168if test "$succeeded" != "yes" ; then
169  if test "$_version" = "0" ; then
170    AC_MSG_ERROR([We could not detect the boost libraries (version $boost_version_req_shorten or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option.  If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.])
171  else
172    AC_MSG_ERROR([boost $_version too old; version $boost_version_req or newer required.])
173  fi
174else
175  AC_SUBST(BOOST_VERSION)
176  AC_SUBST(BOOST_CPPFLAGS)
177  AC_SUBST(BOOST_LDFLAGS)
178  AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
179fi
180
181CPPFLAGS="$CPPFLAGS_SAVED"
182LDFLAGS="$LDFLAGS_SAVED"
183
184])
185
186
187# Boost libraries have a string suffix that identifies the compiler
188# they were built with, among other details.  For example, it can be
189# '-gcc', '-gcc-mt', '-gcc-mt-1_31', and many other combinations
190# depending on the build system.  Some systems provide symlinks that
191# hide these suffixes, avoiding this mess.  However, other systems
192# don't; we have to provide a way to let the user manually specify a
193# suffix.  Guessing can be very difficult, given the variety of
194# possibilities.  Note that you cannot expand a variable inside the
195# second argument to AC_ARG_VAR, so we're stuck listing it twice.
196AC_DEFUN([BOOST_LIB_SUFFIX_ARG],
197[AC_ARG_VAR([BOOST_LIB_SUFFIX],
198            [Space-separated list of suffixes to try appending to the names
199	     of Boost libraries.  "none" means no suffix. The default is:
200	     "none -gcc -mipspro -mt -sunpro -sw -mgw -gcc-mt -gcc-mt-s"])
201if test x"$BOOST_LIB_SUFFIX" = x; then
202  BOOST_LIB_SUFFIX="none -gcc -mipspro -mt -sunpro -sw -mgw -gcc-mt -gcc-mt-s"
203fi
204])
205
206# Alteratively, allow users to set the suffix (list) via --with-boost-suffix
207AC_DEFUN([WITH_BOOST_LIB_SUFFIX],
208[AC_ARG_WITH([boost-lib-suffix],
209   AS_HELP_STRING([--with-boost-lib-suffix=list],
210                  [use the given list of suffixes when searching for boost libraries.]),
211[ BOOST_LIB_SUFFIX="$withval"],
212[ BOOST_LIB_SUFFIX="none -gcc -mipspro -mt -sunpro -sw -mgw -gcc-mt -gcc-mt-s"])]
213)
214
215
216# BOOST_LIB_IFELSE(library, testprog, if_found, if_not_found)
217# This is tricksome, as we only want to process a list of suffixes
218# until we've selected one; once we've done that, it must be used for
219# all libraries.  (But we need the shell loop in all uses, as previous
220# scans might be unsuccessful.)
221AC_DEFUN([BOOST_LIB_IFELSE],
222[AC_LANG_ASSERT(C++)
223 AC_REQUIRE([WITH_BOOST_LIB_SUFFIX])
224dnl AC_REQUIRE([BOOST_STATIC_LINK_OPTION])
225 found=no
226 LIBS_SAVED="$LIBS"
227 CPPFLAGS_SAVED="$CPPFLAGS"
228 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
229
230 LDFLAGS_SAVED="$LDFLAGS"
231 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
232
233 for s in $BOOST_LIB_SUFFIX
234   do
235     if test "x$s" = xnone; then
236       s=''
237     fi
238     if test "x${BOOST_LIBDIR}" != x; then
239       lib="${BOOST_LIBDIR}/libboost_$1${s}.a"
240     else
241       lib="-lboost_$1$s"
242     fi
243
244     LIBS="$lib $BOOST_LIBS $LIBS_SAVED"
245     cv=AS_TR_SH([ac_cv_boost_lib_$1${s}_${BOOST_LIBDIR}])
246     AC_CACHE_CHECK([for the boost_$1$s library],
247     		    $cv,
248       [AC_LINK_IFELSE([$2],
249	 	       [eval $cv=yes],
250		       [eval $cv=no])])
251     if eval "test \"\${$cv}\" = yes"; then
252        found=yes
253        break
254     fi
255   done
256 CPPFLAGS="$CPPFLAGS_SAVED"
257 LDFLAGS="$LDFLAGS_SAVED"
258 LIBS="$LIBS_SAVED"
259 AS_IF([test $found = yes],
260        [BOOST_LIB_SUFFIX=${s:-none}
261	 $3],
262        [$4])
263])
264
265# Checks for specific boost libraries.
266# These are named SYN_BOOST_* because their actions are synopsis-specific.
267
268AC_DEFUN([SYN_NEED_BOOST_LIB],
269[BOOST_LIB_IFELSE([$1], [$2],
270    [BOOST_LIBS="$lib $BOOST_LIBS"],
271    [AC_MSG_FAILURE([the boost_$1 library is required])])
272 AC_SUBST(BOOST_LIBS)
273])
274
275AC_DEFUN([SYN_MAY_NEED_BOOST_LIB],
276[BOOST_LIB_IFELSE([$1], [$2],
277    [BOOST_LIBS="$lib $BOOST_LIBS"])
278 AC_SUBST(BOOST_LIBS)
279])
280
281AC_DEFUN([SYN_BOOST_LIB_FILESYSTEM],
282[SYN_MAY_NEED_BOOST_LIB([system],
283  [AC_LANG_PROGRAM([[
284      #include <boost/system/error_code.hpp>
285      using namespace boost::system;
286    ]],[[
287      error_code c;
288    ]])])
289 SYN_NEED_BOOST_LIB([filesystem],
290  [AC_LANG_PROGRAM([[
291      #include <boost/filesystem/path.hpp>
292      #include <boost/filesystem/operations.hpp>
293      using namespace boost::filesystem;
294    ]],[[
295      exists(path("/boot"));
296    ]])])])
297
298AC_DEFUN([SYN_BOOST_LIB_REGEX],
299[SYN_NEED_BOOST_LIB([regex],
300  [AC_LANG_PROGRAM([[
301      #include <boost/regex.hpp>
302      using namespace boost;
303    ]],[[
304      regex expr("foo");
305    ]])])])
306
307AC_DEFUN([SYN_BOOST_LIB_WAVE],
308[SYN_MAY_NEED_BOOST_LIB([thread],
309  [AC_LANG_PROGRAM([[
310      #include <boost/thread.hpp>
311      using namespace boost;
312    ]],[[
313      thread t;
314    ]])])
315 SYN_NEED_BOOST_LIB([wave],
316  [AC_LANG_PROGRAM([[
317     #include <boost/wave.hpp>
318     #include <boost/wave/cpplexer/cpp_lex_token.hpp>
319     #include <boost/wave/cpplexer/cpp_lex_iterator.hpp>
320
321     using namespace boost::wave;
322
323     typedef cpplexer::lex_token<> Token;
324     typedef cpplexer::lex_iterator<Token> lex_iterator_type;
325    ]],[[
326      return 0;
327    ]])])])
328
329AC_DEFUN([SYN_BOOST_LIB_PYTHON],
330[
331save_LIBS=$LIBS
332LIBS="$LIBS $PYTHON_LIBS"
333SYN_NEED_BOOST_LIB([python],
334  [AC_LANG_PROGRAM([[
335      #include <boost/python.hpp>
336      using namespace boost::python;
337    ]],[[
338      object("dummy");
339    ]])])
340LIBS=$save_LIBS
341])
342