Handle Boost.System and adjust the code to handle the binary dependencies.
[boost.m4.git] / build-aux / boost.m4
blobff27d083e4696f5ca160d0bc697af8c2e4b0bb34
1 # boost.m4: Locate Boost headers and libraries for autoconf-based projects.
2 # Copyright (C) 2007  Benoit Sigoure <tsuna@lrde.epita.fr>
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # Additional permission under section 7 of the GNU General Public
10 # License, version 3 ("GPLv3"):
12 # If you convey this file as part of a work that contains a
13 # configuration script generated by Autoconf, you may do so under
14 # terms of your choice.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
24 # serial 8
25 # Original sources can be found at http://repo.or.cz/w/boost.m4.git
26 # You can fetch the latest version of the script by doing:
27 #   wget 'http://repo.or.cz/w/boost.m4.git?a=blob_plain;f=build-aux/boost.m4;hb=HEAD' -O boost.m4
29 # ------ #
30 # README #
31 # ------ #
33 # This file provides several macros to use the various Boost libraries.
34 # The first macro is BOOST_REQUIRE.  It will simply check if it's possible to
35 # find the Boost headers of a given (optional) minimum version and it will
36 # define BOOST_CPPFLAGS accordingly.  It will add an option --with-boost to
37 # your configure so that users can specify non standard locations.
38 # For more README and documentation, go to http://repo.or.cz/w/boost.m4.git
39 # Note: THESE MACROS ASSUME THAT YOU USE LIBTOOL.  If you don't, don't worry,
40 # simply read the README, it will show you what to do step by step.
42 m4_pattern_forbid([^_?BOOST_])
44 # BOOST_REQUIRE([VERSION])
45 # ------------------------
46 # Look for Boost.  If version is given, it must either be a literal of the form
47 # "X.Y.Z" where X, Y and Z are integers (the ".Z" part being optional) or a
48 # variable "$var".
49 # Defines the value BOOST_CPPFLAGS.  This macro only checks for headers with
50 # the required version, it does not check for any of the Boost libraries.
51 # FIXME: Add a 2nd optional argument so that it's not fatal if Boost isn't found
52 # and add an AC_DEFINE to tell whether HAVE_BOOST.
53 AC_DEFUN([BOOST_REQUIRE],
54 [dnl First find out what kind of argument we have.
55 dnl If we have an empty argument, there is no constraint on the version of
56 dnl Boost to use.  If it's a literal version number, we can split it in M4 (so
57 dnl the resulting configure script will be smaller/faster).  Otherwise we do
58 dnl the splitting at runtime.
59 m4_bmatch([$1],
60   [^ *$], [m4_pushdef([BOOST_VERSION_REQ], [])dnl
61            boost_version_major=0
62            boost_version_minor=0
63            boost_version_subminor=0
65   [^[0-9]+\([-._][0-9]+\)*$],
66     [m4_pushdef([BOOST_VERSION_REQ], [ version >= $1])dnl
67      boost_version_major=m4_bregexp([$1], [^\([0-9]+\)], [\1])
68      boost_version_minor=m4_bregexp([$1], [^[0-9]+[-._]\([0-9]+\)], [\1])
69      boost_version_subminor=m4_bregexp([$1], [^[0-9]+[-._][0-9]+[-._]\([0-9]+\)], [\1])
71   [^\$[a-zA-Z_]+$],
72     [m4_pushdef([BOOST_VERSION_REQ], [])dnl
73      boost_version_major=`expr "X$1" : 'X\([[^-._]]*\)'`
74      boost_version_minor=`expr "X$1" : 'X[[0-9]]*[[-._]]\([[^-._]]*\)'`
75      boost_version_subminor=`expr "X$1" : 'X[[0-9]]*[[-._]][[0-9]]*[[-._]]\([[0-9]]*\)'`
76      case $boost_version_major:$boost_version_minor in #(
77        *: | :* | *[[^0-9]]*:* | *:*[[^0-9]]*)
78          AC_MSG_ERROR([[Invalid argument for REQUIRE_BOOST: `$1']])
79          ;;
80      esac
82   [m4_fatal(Invalid argument: `$1')]
83 )dnl
84 AC_ARG_WITH([boost],
85    [AS_HELP_STRING([--with-boost=DIR],
86                    [prefix of Boost]BOOST_VERSION_REQ[ @<:@guess@:>@])])dnl
87 AC_SUBST([DISTCHECK_CONFIGURE_FLAGS],
88          ["$DISTCHECK_CONFIGURE_FLAGS '--with-boost=$with_boost'"])
89   AC_CACHE_CHECK([for Boost headers[]BOOST_VERSION_REQ],
90     [boost_cv_inc_path],
91     [boost_cv_inc_path=no
92 AC_LANG_PUSH([C++])dnl
93     boost_subminor_chk=
94     test x"$boost_version_subminor" != x \
95       && boost_subminor_chk="|| (B_V_MAJ == $boost_version_major \
96 && B_V_MIN == $boost_version_minor \
97 && B_V_SUB < $boost_version_subminor)"
98     for boost_dir in "$with_boost/include" '' \
99              /opt/local/include /usr/local/include /opt/include /usr/include \
100              "$with_boost" C:/Boost/include
101     do
102     # Without --layout=system, Boost (or at least some versions) installs
103     # itself in <prefix>/include/boost-<version>.  This inner loop helps to
104     # find headers in such directories.
105     # I didn't indent this loop on purpose (to avoid over-indented code)
106     for boost_inc in "$boost_dir" "$boost_dir"/boost-*
107     do
108       # $boost_inc can often be a symlink, so keep -e here.
109       test -e "$boost_inc" || continue
110       # Ensure that version.hpp exists: we're going to read it.  Moreover,
111       # Boost could be reachable thanks to the default include path so we can
112       # mistakenly accept a wrong include path without this check.
113       test -e "$boost_inc/boost/version.hpp" || continue
114       boost_save_CPPFLAGS=$CPPFLAGS
115       test x"$boost_inc" != x && CPPFLAGS="$CPPFLAGS -I$boost_inc"
116 m4_pattern_allow([^BOOST_VERSION$])dnl
117       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <boost/version.hpp>
118 #ifndef BOOST_VERSION
119 # error BOOST_VERSION is not defined
120 #endif
121 #define B_V_MAJ (BOOST_VERSION / 100000)
122 #define B_V_MIN (BOOST_VERSION / 100 % 1000)
123 #define B_V_SUB (BOOST_VERSION % 100)
124 #if (B_V_MAJ < $boost_version_major) \
125    || (B_V_MAJ == $boost_version_major \
126        && B_V_MIN < $boost_version_minor) $boost_subminor_chk
127 # error Boost headers version < $1
128 #endif
129 ]])], [boost_cv_inc_path=yes], [boost_cv_version=no])
130       CPPFLAGS=$boost_save_CPPFLAGS
131       if test x"$boost_cv_inc_path" = xyes; then
132         if test x"$boost_inc" != x; then
133           boost_cv_inc_path=$boost_inc
134         fi
135         break 2
136       fi
137     done
138     done
139 AC_LANG_POP([C++])dnl
140     ])
141     case $boost_cv_inc_path in #(
142       no)
143         AC_MSG_ERROR([Could not find Boost headers[]BOOST_VERSION_REQ])
144         ;;#(
145       yes)
146         BOOST_CPPFLAGS=
147         ;;#(
148       *)
149         BOOST_CPPFLAGS="-I$boost_cv_inc_path"
150         ;;
151     esac
152 AC_SUBST([BOOST_CPPFLAGS])dnl
153   AC_CACHE_CHECK([for Boost's header version],
154     [boost_cv_lib_version],
155     [m4_pattern_allow([^BOOST_LIB_VERSION$])dnl
156     boost_cv_lib_version=unknown
157     boost_sed_version='/^.*BOOST_LIB_VERSION.*"\([[^"]]*\)".*$/!d;s//\1/'
158     boost_version_hpp="$boost_inc/boost/version.hpp"
159     test -e "$boost_version_hpp" \
160       && boost_cv_lib_version=`sed "$boost_sed_version" "$boost_version_hpp"`
161     ])
162     # e.g. "134" for 1_34_1 or "135" for 1_35
163     boost_major_version=`echo "$boost_cv_lib_version" | sed 's/_//;s/_.*//'`
164     case $boost_major_version in
165       '' | *[[^0-9]]*)
166         AC_MSG_ERROR([Invalid value: boost_major_version=$boost_major_version])
167         ;;
168     esac
169 m4_popdef([BOOST_VERSION_REQ])dnl
170 ])# BOOST_REQUIRE
173 # BOOST_FIND_HEADER([HEADER-NAME], [ACTION-IF-NOT-FOUND], [ACTION-IF-FOUND])
174 # --------------------------------------------------------------------------
175 # Wrapper around AC_CHECK_HEADER for Boost headers.  Useful to check for
176 # some parts of the Boost library which are only made of headers and don't
177 # require linking (such as Boost.Foreach).
179 # Default ACTION-IF-NOT-FOUND: Fail with a fatal error.
181 # Default ACTION-IF-FOUND: define the preprocessor symbol HAVE_<HEADER-NAME> in
182 # case of success # (where HEADER-NAME is written LIKE_THIS, e.g.,
183 # HAVE_BOOST_FOREACH_HPP).
184 AC_DEFUN([BOOST_FIND_HEADER],
185 [AC_REQUIRE([BOOST_REQUIRE])dnl
186 AC_LANG_PUSH([C++])dnl
187 boost_save_CPPFLAGS=$CPPFLAGS
188 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
189 AC_CHECK_HEADER([$1],
190   [m4_default([$3], [AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1],
191                                [Define to 1 if you have <$1>])])],
192   [m4_default([$2], [AC_MSG_ERROR([cannot find $1])])])
193 CPPFLAGS=$boost_save_CPPFLAGS
194 AC_LANG_POP([C++])dnl
195 ])# BOOST_FIND_HEADER
198 # BOOST_FIND_LIB([LIB-NAME], [PREFERRED-RT-OPT], [HEADER-NAME], [CXX-TEST],
199 #                [CXX-PROLOGUE])
200 # -------------------------------------------------------------------------
201 # Look for the Boost library LIB-NAME (e.g., LIB-NAME = `thread', for
202 # libboost_thread).  Check that HEADER-NAME works and check that
203 # libboost_LIB-NAME can link with the code CXX-TEST.  The optional argument
204 # CXX-PROLOGUE can be used to include some C++ code before the `main'
205 # function.
207 # Invokes BOOST_FIND_HEADER([HEADER-NAME]) (see above).
209 # Boost libraries typically come compiled with several flavors (with different
210 # runtime options) so PREFERRED-RT-OPT is the preferred suffix.  A suffix is one
211 # or more of the following letters: sgdpn (in that order).  s = static
212 # runtime, d = debug build, g = debug/diagnostic runtime, p = STLPort build,
213 # n = (unsure) STLPort build without iostreams from STLPort (it looks like `n'
214 # must always be used along with `p').  Additionally, PREFERRED-RT-OPT can
215 # start with `mt-' to indicate that there is a preference for multi-thread
216 # builds.  Some sample values for PREFERRED-RT-OPT: (nothing), mt, d, mt-d, gdp
217 # ...  If you want to make sure you have a specific version of Boost
218 # (eg, >= 1.33) you *must* invoke BOOST_REQUIRE before this macro.
219 AC_DEFUN([BOOST_FIND_LIB],
220 [AC_REQUIRE([_BOOST_FIND_COMPILER_TAG])dnl
221 AC_REQUIRE([BOOST_REQUIRE])dnl
222 AC_REQUIRE([_BOOST_GUESS_WHETHER_TO_USE_MT])dnl
223 AC_LANG_PUSH([C++])dnl
224 AS_VAR_PUSHDEF([Boost_lib], [boost_cv_lib_$1])dnl
225 AS_VAR_PUSHDEF([Boost_lib_LDFLAGS], [boost_cv_lib_$1_LDFLAGS])dnl
226 AS_VAR_PUSHDEF([Boost_lib_LIBS], [boost_cv_lib_$1_LIBS])dnl
227 BOOST_FIND_HEADER([$3])
228 boost_save_CPPFLAGS=$CPPFLAGS
229 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
230 # Now let's try to find the library.  The algorithm is as follows: first look
231 # for a given library name according to the user's PREFERRED-RT-OPT.  For each
232 # library name, we prefer to use the ones that carry the tag (toolset name).
233 # Each library is searched through the various standard paths were Boost is
234 # usually installed.  If we can't find the standard variants, we try to
235 # enforce -mt (for instance on MacOSX, libboost_threads.dylib doesn't exist
236 # but there's -obviously- libboost_threads-mt.dylib).
237 AC_CACHE_CHECK([for the Boost $1 library], [Boost_lib],
238   [Boost_lib=no
239   case "$2" in #(
240     mt | mt-) boost_mt=-mt; boost_rtopt=;; #(
241     mt* | mt-*) boost_mt=-mt; boost_rtopt=`expr "X$2" : 'Xmt-*\(.*\)'`;; #(
242     *) boost_mt=; boost_rtopt=$2;;
243   esac
244   # Find the proper debug variant depending on what we've been asked to find.
245   case $boost_rtopt in #(
246     *d*) boost_rt_d=$boost_rtopt;; #(
247     *[[sgpn]]*) # Insert the `d' at the right place (in between `sg' and `pn')
248       boost_rt_d=`echo "$boost_rtopt" | sed 's/\(s*g*\)\(p*n*\)/\1\2/'`;; #(
249     *) boost_rt_d='-d';;
250   esac
251   # If the PREFERRED-RT-OPT are not empty, prepend a `-'.
252   test -n "$boost_rtopt" && boost_rtopt="-$boost_rtopt"
253   $boost_guess_use_mt && boost_mt=-mt
254   # Look for the abs path the static archive.
255   # $libext is computed by Libtool but let's make sure it's non empty.
256   test -z "$libext" &&
257     AC_MSG_ERROR([the libext variable is empty, did you invoke Libtool?])
258   boost_save_ac_objext=$ac_objext
259   # Generate the test file.
260   AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <$3>
261 $5], [$4])])
262 dnl Optimization hacks: compiling C++ is slow, especially with Boost.  What
263 dnl we're trying to do here is guess the right combination of link flags
264 dnl (LIBS / LDFLAGS) to use a given library.  This can take several
265 dnl iterations before it succeeds and is thus *very* slow.  So what we do
266 dnl instead is that we compile the code first (and thus get an object file,
267 dnl typically conftest.o).  Then we try various combinations of link flags
268 dnl until we succeed to link conftest.o in an executable.  The problem is
269 dnl that the various TRY_LINK / COMPILE_IFELSE macros of Autoconf always
270 dnl remove all the temporary files including conftest.o.  So the trick here
271 dnl is to temporarily change the value of ac_objext so that conftest.o is
272 dnl preserved accross tests.  This is obviously fragile and I will burn in
273 dnl hell for not respecting Autoconf's documented interfaces, but in the
274 dnl mean time, it optimizes the macro by a factor of 5 to 30.
275 dnl Another small optimization: the first argument of AC_COMPILE_IFELSE left
276 dnl empty because the test file is generated only once above (before we
277 dnl start the for loops).
278   AC_COMPILE_IFELSE([],
279     [ac_objext=do_not_rm_me_plz],
280     [AC_MSG_ERROR([Cannot compile a test that uses Boost $1])])
281   ac_objext=$boost_save_ac_objext
282   boost_failed_libs=
283 # Don't bother to ident the 6 nested for loops, only the 2 innermost ones
284 # matter.
285 for boost_tag_ in -$boost_cv_lib_tag ''; do
286 for boost_ver_ in -$boost_cv_lib_version ''; do
287 for boost_mt_ in $boost_mt -mt ''; do
288 for boost_rtopt_ in $boost_rtopt '' -d; do
289   for boost_lib in \
290     boost_$1$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ \
291     boost_$1$boost_tag_$boost_rtopt_$boost_ver_ \
292     boost_$1$boost_tag_$boost_mt_$boost_ver_ \
293     boost_$1$boost_tag_$boost_ver_
294   do
295     # Avoid testing twice the same lib
296     case $boost_failed_libs in #(
297       *@$boost_lib@*) continue;;
298     esac
299     # If with_boost is empty, we'll search in /lib first, which is not quite
300     # right so instead we'll try to a location based on where the headers are.
301     boost_tmp_lib=$with_boost
302     test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include}
303     for boost_ldpath in "$boost_tmp_lib/lib" '' \
304              /opt/local/lib /usr/local/lib /opt/lib /usr/lib \
305              "$with_boost" C:/Boost/lib /lib /usr/lib64 /lib64
306     do
307       test -e "$boost_ldpath" || continue
308       boost_save_LDFLAGS=$LDFLAGS
309       # Are we looking for a static library?
310       case $boost_ldpath:$boost_rtopt_ in #(
311         *?*:*s*) # Yes (Non empty boost_ldpath + s in rt opt)
312           Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext"
313           test -e "$Boost_lib_LIBS" || continue;; #(
314         *) # No: use -lboost_foo to find the shared library.
315           Boost_lib_LIBS="-l$boost_lib";;
316       esac
317       boost_save_LIBS=$LIBS
318       LIBS="$Boost_lib_LIBS $LIBS"
319       test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"
320 dnl First argument of AC_LINK_IFELSE left empty because the test file is
321 dnl generated only once above (before we start the for loops).
322       _BOOST_AC_LINK_IFELSE([],
323                             [Boost_lib=yes], [Boost_lib=no])
324       ac_objext=$boost_save_ac_objext
325       LDFLAGS=$boost_save_LDFLAGS
326       LIBS=$boost_save_LIBS
327       if test x"$Boost_lib" = xyes; then
328         Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath"
329         break 6
330       else
331         boost_failed_libs="$boost_failed_libs@$boost_lib@"
332       fi
333     done
334   done
335 done
336 done
337 done
338 done
339 rm -f conftest.$ac_objext
341 case $Boost_lib in #(
342   no) AC_MSG_ERROR([Could not find the flags to link with Boost $1])
343     ;;
344 esac
345 AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS])
346 AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS])
347 CPPFLAGS=$boost_save_CPPFLAGS
348 AS_VAR_POPDEF([Boost_lib])dnl
349 AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl
350 AS_VAR_POPDEF([Boost_lib_LIBS])dnl
351 AC_LANG_POP([C++])dnl
352 ])# BOOST_FIND_LIB
355 # --------------------------------------- #
356 # Checks for the various Boost libraries. #
357 # --------------------------------------- #
359 # List of boost libraries: http://www.boost.org/libs/libraries.htm
360 # The page http://beta.boost.org/doc/libs is useful: it gives the first release
361 # version of each library (among other things).
364 # BOOST_BIND()
365 # ------------
366 # Look for Boost.Bind
367 AC_DEFUN([BOOST_BIND],
368 [BOOST_FIND_HEADER([boost/bind.hpp])])
371 # BOOST_CONVERSION()
372 # ------------------
373 # Look for Boost.Conversion (cast / lexical_cast)
374 AC_DEFUN([BOOST_CONVERSION],
375 [BOOST_FIND_HEADER([boost/cast.hpp])
376 BOOST_FIND_HEADER([boost/lexical_cast.hpp])
377 ])# BOOST_CONVERSION
380 # BOOST_DATE_TIME([PREFERRED-RT-OPT])
381 # -----------------------------------
382 # Look for Boost.Date_Time.  For the documentation of PREFERRED-RT-OPT, see the
383 # documentation of BOOST_FIND_LIB above.
384 AC_DEFUN([BOOST_DATE_TIME],
385 [BOOST_FIND_LIB([date_time], [$1],
386                 [boost/date_time/posix_time/posix_time.hpp],
387                 [boost::posix_time::ptime t;])
388 ])# BOOST_DATE_TIME
391 # BOOST_FILESYSTEM([PREFERRED-RT-OPT])
392 # ------------------------------------
393 # Look for Boost.Filesystem.  For the documentation of PREFERRED-RT-OPT, see
394 # the documentation of BOOST_FIND_LIB above.
395 # Do not check for boost/filesystem.hpp because this file was introduced in
396 # 1.34.
397 AC_DEFUN([BOOST_FILESYSTEM],
398 [# Do we have to check for Boost.System?  This link-time dependency was
399 # added as of 1.35.0.  If we have a version <1.35, we must not attempt to
400 # find Boost.System as it didn't exist by then.
401 if test $boost_major_version -ge 135; then
402 BOOST_SYSTEM([$1])
403 fi # end of the Boost.System check.
404 boost_filesystem_save_LIBS=$LIBS
405 boost_filesystem_save_LDFLAGS=$LDFLAGS
406 m4_pattern_allow([^BOOST_SYSTEM_(LIBS|LDFLAGS)$])dnl
407 LIBS="$LIBS $BOOST_SYSTEM_LIBS"
408 LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS"
409 BOOST_FIND_LIB([filesystem], [$1],
410                 [boost/filesystem/path.hpp], [boost::filesystem::path p;])
411 LIBS=$boost_filesystem_save_LIBS
412 LDFLAGS=$boost_filesystem_save_LDFLAGS
413 ])# BOOST_FILESYSTEM
416 # BOOST_FOREACH()
417 # ---------------
418 # Look for Boost.Foreach
419 AC_DEFUN([BOOST_FOREACH],
420 [BOOST_FIND_HEADER([boost/foreach.hpp])])
423 # BOOST_FORMAT()
424 # --------------
425 # Look for Boost.Format
426 # Note: we can't check for boost/format/format_fwd.hpp because the header isn't
427 # standalone.  It can't be compiled because it triggers the following error:
428 # boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std'
429 #                                                  does not name a type
430 AC_DEFUN([BOOST_FORMAT],
431 [BOOST_FIND_HEADER([boost/format.hpp])])
434 # BOOST_FUNCTION()
435 # ----------------
436 # Look for Boost.Function
437 AC_DEFUN([BOOST_FUNCTION],
438 [BOOST_FIND_HEADER([boost/function.hpp])])
441 # BOOST_GRAPH([PREFERRED-RT-OPT])
442 # -------------------------------
443 # Look for Boost.Graphs.  For the documentation of PREFERRED-RT-OPT, see the
444 # documentation of BOOST_FIND_LIB above.
445 AC_DEFUN([BOOST_GRAPH],
446 [BOOST_FIND_LIB([graph], [$1],
447                 [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;])
448 ])# BOOST_GRAPH
451 # BOOST_IOSTREAMS([PREFERRED-RT-OPT])
452 # -------------------------------
453 # Look for Boost.IOStreams.  For the documentation of PREFERRED-RT-OPT, see the
454 # documentation of BOOST_FIND_LIB above.
455 AC_DEFUN([BOOST_IOSTREAMS],
456 [BOOST_FIND_LIB([iostreams], [$1],
457                 [boost/iostreams/device/file_descriptor.hpp],
458                 [boost::iostreams::file_descriptor fd(0); fd.close();])
459 ])# BOOST_IOSTREAMS
462 # BOOST_HASH()
463 # ------------
464 # Look for Boost.Functional/Hash
465 AC_DEFUN([BOOST_HASH],
466 [BOOST_FIND_HEADER([boost/functional/hash.hpp])])
469 # BOOST_LAMBDA()
470 # --------------
471 # Look for Boost.Lambda
472 AC_DEFUN([BOOST_LAMBDA],
473 [BOOST_FIND_HEADER([boost/lambda/lambda.hpp])])
476 # BOOST_PREPROCESSOR()
477 # --------------------
478 # Look for Boost.Preprocessor
479 AC_DEFUN([BOOST_PREPROCESSOR],
480 [BOOST_FIND_HEADER([boost/preprocessor/repeat.hpp])])
483 # BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT])
484 # -----------------------------------------
485 # Look for Boost.Program_options.  For the documentation of PREFERRED-RT-OPT, see
486 # the documentation of BOOST_FIND_LIB above.
487 AC_DEFUN([BOOST_PROGRAM_OPTIONS],
488 [BOOST_FIND_LIB([program_options], [$1],
489                 [boost/program_options.hpp],
490                 [boost::program_options::options_description d("test");])
491 ])# BOOST_PROGRAM_OPTIONS
494 # BOOST_REF()
495 # -----------
496 # Look for Boost.Ref
497 AC_DEFUN([BOOST_REF],
498 [BOOST_FIND_HEADER([boost/ref.hpp])])
501 # BOOST_REGEX([PREFERRED-RT-OPT])
502 # -------------------------------
503 # Look for Boost.Regex.  For the documentation of PREFERRED-RT-OPT, see the
504 # documentation of BOOST_FIND_LIB above.
505 AC_DEFUN([BOOST_REGEX],
506 [BOOST_FIND_LIB([regex], [$1],
507                 [boost/regex.hpp],
508                 [boost::regex exp("*"); boost::regex_match("foo", exp);])
509 ])# BOOST_REGEX
512 # BOOST_SERIALIZATION([PREFERRED-RT-OPT])
513 # ---------------------------------------
514 # Look for Boost.Serialization.  For the documentation of PREFERRED-RT-OPT, see
515 # the documentation of BOOST_FIND_LIB above.
516 AC_DEFUN([BOOST_SERIALIZATION],
517 [BOOST_FIND_LIB([serialization], [$1],
518                 [boost/archive/text_oarchive.hpp],
519                 [std::ostream* o = 0; // Cheap way to get an ostream...
520                 boost::archive::text_oarchive t(*o);])
521 ])# BOOST_SIGNALS
524 # BOOST_SIGNALS([PREFERRED-RT-OPT])
525 # ---------------------------------
526 # Look for Boost.Signals.  For the documentation of PREFERRED-RT-OPT, see the
527 # documentation of BOOST_FIND_LIB above.
528 AC_DEFUN([BOOST_SIGNALS],
529 [BOOST_FIND_LIB([signals], [$1],
530                 [boost/signal.hpp],
531                 [boost::signal<void ()> s;])
532 ])# BOOST_SIGNALS
535 # BOOST_SMART_PTR()
536 # -----------------
537 # Look for Boost.SmartPtr
538 AC_DEFUN([BOOST_SMART_PTR],
539 [BOOST_FIND_HEADER([boost/scoped_ptr.hpp])
540 BOOST_FIND_HEADER([boost/shared_ptr.hpp])
544 # BOOST_STRING_ALGO()
545 # -------------------
546 # Look for Boost.StringAlgo
547 AC_DEFUN([BOOST_STRING_ALGO],
548 [BOOST_FIND_HEADER([boost/algorithm/string.hpp])
552 # BOOST_SYSTEM([PREFERRED-RT-OPT])
553 # --------------------------------
554 # Look for Boost.System.  For the documentation of PREFERRED-RT-OPT, see the
555 # documentation of BOOST_FIND_LIB above.  This library was introduced in Boost
556 # 1.35.0.
557 AC_DEFUN([BOOST_SYSTEM],
558 [BOOST_FIND_LIB([system], [$1],
559                 [boost/system/error_code.hpp],
560                 [boost::system::error_code e; e.clear();])
561 ])# BOOST_SYSTEM
564 # BOOST_TEST([PREFERRED-RT-OPT])
565 # ------------------------------
566 # Look for Boost.Test.  For the documentation of PREFERRED-RT-OPT, see the
567 # documentation of BOOST_FIND_LIB above.
568 AC_DEFUN([BOOST_TEST],
569 [m4_pattern_allow([^BOOST_CHECK$])dnl
570 BOOST_FIND_LIB([unit_test_framework], [$1],
571                [boost/test/unit_test.hpp], [BOOST_CHECK(2 == 2);],
572                [using boost::unit_test::test_suite;
573                test_suite* init_unit_test_suite(int argc, char ** argv)
574                { return NULL; }])
575 ])# BOOST_TEST
578 # BOOST_THREADS([PREFERRED-RT-OPT])
579 # ---------------------------------
580 # Look for Boost.Thread.  For the documentation of PREFERRED-RT-OPT, see the
581 # documentation of BOOST_FIND_LIB above.
582 # FIXME: Provide an alias "BOOST_THREAD".
583 AC_DEFUN([BOOST_THREADS],
584 [dnl Having the pthread flag is required at least on GCC3 where
585 dnl boost/thread.hpp would complain if we try to compile without
586 dnl -pthread on GNU/Linux.
587 AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
588 boost_threads_save_LIBS=$LIBS
589 boost_threads_save_CPPFLAGS=$CPPFLAGS
590 LIBS="$LIBS $boost_cv_pthread_flag"
591 # Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
592 # boost/thread.hpp will trigger a #error if -pthread isn't used:
593 #   boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
594 #   is not turned on. Please set the correct command line options for
595 #   threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
596 CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag"
597 BOOST_FIND_LIB([thread], [$1],
598                 [boost/thread.hpp], [boost::thread t; boost::mutex m;])
599 BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $boost_cv_pthread_flag"
600 BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag"
601 LIBS=$boost_threads_save_LIBS
602 CPPFLAGS=$boost_threads_save_CPPFLAGS
603 ])# BOOST_THREADS
606 # BOOST_TOKENIZER()
607 # -----------------
608 # Look for Boost.Tokenizer
609 AC_DEFUN([BOOST_TOKENIZER],
610 [BOOST_FIND_HEADER([boost/tokenizer.hpp])])
613 # BOOST_TRIBOOL()
614 # ---------------
615 # Look for Boost.Tribool
616 AC_DEFUN([BOOST_TRIBOOL],
617 [BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp])
618 BOOST_FIND_HEADER([boost/logic/tribool.hpp])
622 # BOOST_TUPLE()
623 # -------------
624 # Look for Boost.Tuple
625 AC_DEFUN([BOOST_TUPLE],
626 [BOOST_FIND_HEADER([boost/tuple/tuple.hpp])])
629 # BOOST_UTILITY()
630 # ---------------
631 # Look for Boost.Utility (noncopyable, result_of, base-from-member idiom,
632 # etc.)
633 AC_DEFUN([BOOST_UTILITY],
634 [BOOST_FIND_HEADER([boost/utility.hpp])])
637 # BOOST_VARIANT()
638 # ---------------
639 # Look for Boost.Variant.
640 AC_DEFUN([BOOST_VARIANT],
641 [BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp])
642 BOOST_FIND_HEADER([boost/variant.hpp])])
645 # BOOST_WAVE([PREFERRED-RT-OPT])
646 # ------------------------------
647 # NOTE: If you intend to use Wave/Spirit with thread support, make sure you
648 # call BOOST_THREADS first.
649 # Look for Boost.Wave.  For the documentation of PREFERRED-RT-OPT, see the
650 # documentation of BOOST_FIND_LIB above.
651 AC_DEFUN([BOOST_WAVE],
652 [AC_REQUIRE([BOOST_FILESYSTEM])dnl
653 AC_REQUIRE([BOOST_DATE_TIME])dnl
654 boost_wave_save_LIBS=$LIBS
655 boost_wave_save_LDFLAGS=$LDFLAGS
656 m4_pattern_allow([^BOOST_((FILE)?SYSTEM|DATE_TIME|THREAD)_(LIBS|LDFLAGS)$])dnl
657 LIBS="$LIBS $BOOST_SYSTEM_LIBS $BOOST_FILESYSTEM_LIBS $BOOST_DATE_TIME_LIBS\
658 $BOOST_THREAD_LIBS"
659 LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS $BOOST_FILESYSTEM_LDFLAGS\
660 $BOOST_DATE_TIME_LDFLAGS $BOOST_THREAD_LDFLAGS"
661 BOOST_FIND_LIB([wave], [$1],
662                 [boost/wave.hpp],
663                 [boost::wave::token_id id; get_token_name(id);])
664 LIBS=$boost_wave_save_LIBS
665 LDFLAGS=$boost_wave_save_LDFLAGS
666 ])# BOOST_WAVE
669 # ----------------- #
670 # Internal helpers. #
671 # ----------------- #
674 # _BOOST_PTHREAD_FLAG()
675 # ---------------------
676 # Internal helper for BOOST_THREADS.  Based on ACX_PTHREAD:
677 # http://autoconf-archive.cryp.to/acx_pthread.html
678 AC_DEFUN([_BOOST_PTHREAD_FLAG],
679 [AC_REQUIRE([AC_PROG_CXX])dnl
680 AC_REQUIRE([AC_CANONICAL_HOST])dnl
681 AC_LANG_PUSH([C++])dnl
682 AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag],
683 [ boost_cv_pthread_flag=
684   # The ordering *is* (sometimes) important.  Some notes on the
685   # individual items follow:
686   # (none): in case threads are in libc; should be tried before -Kthread and
687   #       other compiler flags to prevent continual compiler warnings
688   # -lpthreads: AIX (must check this before -lpthread)
689   # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
690   # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
691   # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
692   # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
693   # -pthreads: Solaris/GCC
694   # -mthreads: MinGW32/GCC, Lynx/GCC
695   # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
696   #      doesn't hurt to check since this sometimes defines pthreads too;
697   #      also defines -D_REENTRANT)
698   #      ... -mt is also the pthreads flag for HP/aCC
699   # -lpthread: GNU Linux, etc.
700   # --thread-safe: KAI C++
701   case $host_os in #(
702     *solaris*)
703       # On Solaris (at least, for some versions), libc contains stubbed
704       # (non-functional) versions of the pthreads routines, so link-based
705       # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
706       # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
707       # a function called by this macro, so we could check for that, but
708       # who knows whether they'll stub that too in a future libc.)  So,
709       # we'll just look for -pthreads and -lpthread first:
710       boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #(
711     *)
712       boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \
713                            -pthreads -mthreads -lpthread --thread-safe -mt";;
714   esac
715   # Generate the test file.
716   AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <pthread.h>],
717     [pthread_t th; pthread_join(th, 0);
718     pthread_attr_init(0); pthread_cleanup_push(0, 0);
719     pthread_create(0,0,0,0); pthread_cleanup_pop(0);])])
720   for boost_pthread_flag in '' $boost_pthread_flags; do
721     boost_pthread_ok=false
722 dnl Re-use the test file already generated.
723     boost_pthreads__save_LIBS=$LIBS
724     LIBS="$LIBS $boost_pthread_flag"
725     AC_LINK_IFELSE([],
726       [if grep ".*$boost_pthread_flag" conftest.err; then
727          echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD
728        else
729          boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag
730        fi])
731     LIBS=$boost_pthreads__save_LIBS
732     $boost_pthread_ok && break
733   done
735 AC_LANG_POP([C++])dnl
736 ])# _BOOST_PTHREAD_FLAG
739 # _BOOST_gcc_test(MAJOR, MINOR)
740 # -----------------------------
741 # Internal helper for _BOOST_FIND_COMPILER_TAG.
742 m4_define([_BOOST_gcc_test],
743 ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl
746 # _BOOST_FIND_COMPILER_TAG()
747 # --------------------------
748 # Internal.  When Boost is installed without --layout=system, each library
749 # filename will hold a suffix that encodes the compiler used during the
750 # build.  The Boost build system seems to call this a `tag'.
751 AC_DEFUN([_BOOST_FIND_COMPILER_TAG],
752 [AC_REQUIRE([AC_PROG_CXX])dnl
753 AC_CACHE_CHECK([for the toolset name used by Boost for $CXX], [boost_cv_lib_tag],
754 [AC_LANG_PUSH([C++])dnl
755   boost_cv_lib_tag=unknown
756   # The following tests are mostly inspired by boost/config/auto_link.hpp
757   # The list is sorted to most recent/common to oldest compiler (in order
758   # to increase the likelihood of finding the right compiler with the
759   # least number of compilation attempt).
760   # Beware that some tests are sensible to the order (for instance, we must
761   # look for MinGW before looking for GCC3).
762   # I used one compilation test per compiler with a #error to recognize
763   # each compiler so that it works even when cross-compiling (let me know
764   # if you know a better approach).
765   # Known missing tags (known from Boost's tools/build/v2/tools/common.jam):
766   #   como, edg, kcc, bck, mp, sw, tru, xlc
767   # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines
768   # the same defines as GCC's).
769   # TODO: Move the test on GCC 4.3 up once it's released.
770   for i in \
771     _BOOST_gcc_test(4, 2) \
772     _BOOST_gcc_test(4, 1) \
773     _BOOST_gcc_test(4, 0) \
774     "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \
775      && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
776          || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \
777     _BOOST_gcc_test(3, 4) \
778     _BOOST_gcc_test(3, 3) \
779     "defined _MSC_VER && _MSC_VER >= 1400 @ vc80" \
780     _BOOST_gcc_test(3, 2) \
781     "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \
782     _BOOST_gcc_test(3, 1) \
783     _BOOST_gcc_test(3, 0) \
784     "defined __BORLANDC__ @ bcb" \
785     "defined __ICC && (defined __unix || defined __unix__) @ il" \
786     "defined __ICL @ iw" \
787     "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \
788     _BOOST_gcc_test(4, 3) \
789     _BOOST_gcc_test(2, 95) \
790     "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \
791     "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \
792     "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \
793     "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8"
794   do
795     boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '`
796     boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'`
797     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
798 #if $boost_tag_test
799 /* OK */
800 #else
801 # error $boost_tag_test
802 #endif
803 ]])], [boost_cv_lib_tag=$boost_tag; break], [])
804   done
805 AC_LANG_POP([C++])dnl
807   case $boost_cv_lib_tag in #(
808     # Some newer (>= 1.35?) versions of Boost seem to only use "gcc" as opposed
809     # to "gcc41" for instance.
810     gcc*)
811       # We can specify multiple tags in this variable because it's used by
812       # BOOST_FIND_LIB that does a `for tag in -$boost_cv_lib_tag' ...
813       boost_cv_lib_tag="$boost_cv_lib_tag -gcc"
814       ;; #(
815     unknown)
816       AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]])
817       boost_cv_lib_tag=
818       ;;
819   esac
820 ])# _BOOST_FIND_COMPILER_TAG
823 # _BOOST_GUESS_WHETHER_TO_USE_MT()
824 # --------------------------------
825 # Compile a small test to try to guess whether we should favor MT (Multi
826 # Thread) flavors of Boost.  Sets boost_guess_use_mt accordingly.
827 AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT],
828 [# Check whether we do better use `mt' even though we weren't ask to.
829 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
830 #if defined _REENTRANT || defined _MT || defined __MT__
831 /* use -mt */
832 #else
833 # error MT not needed
834 #endif
835 ]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false])
838 # _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
839 # -------------------------------------------------------------------
840 # Fork of _AC_LINK_IFELSE that preserves conftest.o across calls.  Fragile,
841 # will break when Autoconf changes its internals.  Requires that you manually
842 # rm -f conftest.$ac_objext in between to really different tests, otherwise
843 # you will try to link a conftest.o left behind by a previous test.
844 # Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this
845 # macro)
846 m4_define([_BOOST_AC_LINK_IFELSE],
847 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
848 rm -f conftest$ac_exeext
849 boost_ac_ext_save=$ac_ext
850 boost_use_source=:
851 # If we already have a .o, re-use it.  We change $ac_ext so that $ac_link
852 # tries to link the existing object file instead of compiling from source.
853 test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false &&
854   _AS_ECHO_LOG([re-using the existing conftest.$ac_objext])
855 AS_IF([_AC_DO_STDERR($ac_link) && {
856          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
857          test ! -s conftest.err
858        } && test -s conftest$ac_exeext && {
859          test "$cross_compiling" = yes ||
860          $as_executable_p conftest$ac_exeext
861 dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough.
862        }],
863       [$2],
864       [if $boost_use_source; then
865          _AC_MSG_LOG_CONFTEST
866        fi
867        $3])
868 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
869 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
870 dnl as it would interfere with the next link command.
871 rm -f core conftest.err conftest_ipa8_conftest.oo \
872       conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl
873 ])# _BOOST_AC_LINK_IFELSE