Add GPL license exception.
[boost.m4.git] / build-aux / boost.m4
blob4b93862d24e1476e8a2061391db44c38209096fd
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 6
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 m4_popdef([BOOST_VERSION_REQ])dnl
163 ])# BOOST_REQUIRE
166 # BOOST_FIND_HEADER([HEADER-NAME], [ACTION-IF-NOT-FOUND], [ACTION-IF-FOUND])
167 # --------------------------------------------------------------------------
168 # Wrapper around AC_CHECK_HEADER for Boost headers.  Useful to check for
169 # some parts of the Boost library which are only made of headers and don't
170 # require linking (such as Boost.Foreach).
172 # Default ACTION-IF-NOT-FOUND: Fail with a fatal error.
174 # Default ACTION-IF-FOUND: define the preprocessor symbol HAVE_<HEADER-NAME> in
175 # case of success # (where HEADER-NAME is written LIKE_THIS, e.g.,
176 # HAVE_BOOST_FOREACH_HPP).
177 AC_DEFUN([BOOST_FIND_HEADER],
178 [AC_REQUIRE([BOOST_REQUIRE])dnl
179 AC_LANG_PUSH([C++])dnl
180 boost_save_CPPFLAGS=$CPPFLAGS
181 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
182 AC_CHECK_HEADER([$1],
183   [m4_default([$3], [AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1],
184                                [Define to 1 if you have <$1>])])],
185   [m4_default([$2], [AC_MSG_ERROR([cannot find $1])])])
186 CPPFLAGS=$boost_save_CPPFLAGS
187 AC_LANG_POP([C++])dnl
188 ])# BOOST_FIND_HEADER
191 # BOOST_FIND_LIB([LIB-NAME], [PREFERRED-RT-OPT], [HEADER-NAME], [CXX-TEST],
192 #                [CXX-PROLOGUE])
193 # -------------------------------------------------------------------------
194 # Look for the Boost library LIB-NAME (e.g., LIB-NAME = `thread', for
195 # libboost_thread).  Check that HEADER-NAME works and check that
196 # libboost_LIB-NAME can link with the code CXX-TEST.  The optional argument
197 # CXX-PROLOGUE can be used to include some C++ code before the `main'
198 # function.
200 # Invokes BOOST_FIND_HEADER([HEADER-NAME]) (see above).
202 # Boost libraries typically come compiled with several flavors (with different
203 # runtime options) so PREFERRED-RT-OPT is the preferred suffix.  A suffix is one
204 # or more of the following letters: sgdpn (in that order).  s = static
205 # runtime, d = debug build, g = debug/diagnostic runtime, p = STLPort build,
206 # n = (unsure) STLPort build without iostreams from STLPort (it looks like `n'
207 # must always be used along with `p').  Additionally, PREFERRED-RT-OPT can
208 # start with `mt-' to indicate that there is a preference for multi-thread
209 # builds.  Some sample values for PREFERRED-RT-OPT: (nothing), mt, d, mt-d, gdp
210 # ...  If you want to make sure you have a specific version of Boost
211 # (eg, >= 1.33) you *must* invoke BOOST_REQUIRE before this macro.
212 AC_DEFUN([BOOST_FIND_LIB],
213 [AC_REQUIRE([_BOOST_FIND_COMPILER_TAG])dnl
214 AC_REQUIRE([BOOST_REQUIRE])dnl
215 AC_REQUIRE([_BOOST_GUESS_WHETHER_TO_USE_MT])dnl
216 AC_LANG_PUSH([C++])dnl
217 AS_VAR_PUSHDEF([Boost_lib], [boost_cv_lib_$1])dnl
218 AS_VAR_PUSHDEF([Boost_lib_LDFLAGS], [boost_cv_lib_$1_LDFLAGS])dnl
219 AS_VAR_PUSHDEF([Boost_lib_LIBS], [boost_cv_lib_$1_LIBS])dnl
220 BOOST_FIND_HEADER([$3])
221 boost_save_CPPFLAGS=$CPPFLAGS
222 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
223 # Now let's try to find the library.  The algorithm is as follows: first look
224 # for a given library name according to the user's PREFERRED-RT-OPT.  For each
225 # library name, we prefer to use the ones that carry the tag (toolset name).
226 # Each library is searched through the various standard paths were Boost is
227 # usually installed.  If we can't find the standard variants, we try to
228 # enforce -mt (for instance on MacOSX, libboost_threads.dylib doesn't exist
229 # but there's -obviously- libboost_threads-mt.dylib).
230 AC_CACHE_CHECK([for the Boost $1 library], [Boost_lib],
231   [Boost_lib=no
232   case "$2" in #(
233     mt | mt-) boost_mt=-mt; boost_rtopt=;; #(
234     mt* | mt-*) boost_mt=-mt; boost_rtopt=`expr "X$2" : 'Xmt-*\(.*\)'`;; #(
235     *) boost_mt=; boost_rtopt=$2;;
236   esac
237   # If the PREFERRED-RT-OPT are not empty, prepend a `-'.
238   case $boost_rtopt in #(
239     *[[a-z0-9A-Z]]*) boost_rtopt="-$boost_rtopt";;
240   esac
241   $boost_guess_use_mt && boost_mt=-mt
242   # Look for the abs path the static archive.
243   # $libext is computed by Libtool but let's make sure it's non empty.
244   test -z "$libext" &&
245     AC_MSG_ERROR([the libext variable is empty, did you invoke Libtool?])
246   boost_save_ac_objext=$ac_objext
247   # Generate the test file.
248   AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <$3>
249 $5], [$4])])
250 dnl Optimization hacks: compiling C++ is slow, especially with Boost.  What
251 dnl we're trying to do here is guess the right combination of link flags
252 dnl (LIBS / LDFLAGS) to use a given library.  This can take several
253 dnl iterations before it succeeds and is thus *very* slow.  So what we do
254 dnl instead is that we compile the code first (and thus get an object file,
255 dnl typically conftest.o).  Then we try various combinations of link flags
256 dnl until we succeed to link conftest.o in an executable.  The problem is
257 dnl that the various TRY_LINK / COMPILE_IFELSE macros of Autoconf always
258 dnl remove all the temporary files including conftest.o.  So the trick here
259 dnl is to temporarily change the value of ac_objext so that conftest.o is
260 dnl preserved accross tests.  This is obviously fragile and I will burn in
261 dnl hell for not respecting Autoconf's documented interfaces, but in the
262 dnl mean time, it optimizes the macro by a factor of 5 to 30.
263 dnl Another small optimization: the first argument of AC_COMPILE_IFELSE left
264 dnl empty because the test file is generated only once above (before we
265 dnl start the for loops).
266   AC_COMPILE_IFELSE([],
267     [ac_objext=do_not_rm_me_plz],
268     [AC_MSG_ERROR([Cannot compile a test that uses Boost $1])])
269   ac_objext=$boost_save_ac_objext
270   boost_failed_libs=
271 # Don't bother to ident the 6 nested for loops, only the 2 innermost ones
272 # matter.
273 for boost_tag_ in -$boost_cv_lib_tag ''; do
274 for boost_ver_ in -$boost_cv_lib_version ''; do
275 for boost_mt_ in $boost_mt -mt ''; do
276 for boost_rtopt_ in $boost_rtopt '' -d; do
277   for boost_lib in \
278     boost_$1$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ \
279     boost_$1$boost_tag_$boost_mt_$boost_ver_ \
280     boost_$1$boost_tag_$boost_rtopt_$boost_ver_ \
281     boost_$1$boost_tag_$boost_mt_ \
282     boost_$1$boost_tag_$boost_ver_
283   do
284     # Avoid testing twice the same lib
285     case $boost_failed_libs in #(
286       *@$boost_lib@*) continue;;
287     esac
288     # If with_boost is empty, we'll search in /lib first, which is not quite
289     # right so instead we'll try to a location based on where the headers are.
290     boost_tmp_lib=$with_boost
291     test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include}
292     for boost_ldpath in "$boost_tmp_lib/lib" '' \
293              /opt/local/lib /usr/local/lib /opt/lib /usr/lib \
294              "$with_boost" C:/Boost/lib /lib /usr/lib64 /lib64
295     do
296       test -e "$boost_ldpath" || continue
297       boost_save_LDFLAGS=$LDFLAGS
298       # Are we looking for a static library?
299       case $boost_ldpath:$boost_rtopt_ in #(
300         *?*:*s*) # Yes (Non empty boost_ldpath + s in rt opt)
301           Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext"
302           test -e "$Boost_lib_LIBS" || continue;; #(
303         *) # No: use -lboost_foo to find the shared library.
304           Boost_lib_LIBS="-l$boost_lib";;
305       esac
306       boost_save_LIBS=$LIBS
307       LIBS="$Boost_lib_LIBS $LIBS"
308       test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"
309 dnl First argument of AC_LINK_IFELSE left empty because the test file is
310 dnl generated only once above (before we start the for loops).
311       _BOOST_AC_LINK_IFELSE([],
312                             [Boost_lib=yes], [Boost_lib=no])
313       ac_objext=$boost_save_ac_objext
314       LDFLAGS=$boost_save_LDFLAGS
315       LIBS=$boost_save_LIBS
316       if test x"$Boost_lib" = xyes; then
317         Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath"
318         break 6
319       else
320         boost_failed_libs="$boost_failed_libs@$boost_lib@"
321       fi
322     done
323   done
324 done
325 done
326 done
327 done
328 rm -f conftest.$ac_objext
330 case $Boost_lib in #(
331   no) AC_MSG_ERROR([Could not find the flags to link with Boost $1])
332     ;;
333 esac
334 AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS])
335 AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS])
336 CPPFLAGS=$boost_save_CPPFLAGS
337 AS_VAR_POPDEF([Boost_lib])dnl
338 AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl
339 AS_VAR_POPDEF([Boost_lib_LIBS])dnl
340 AC_LANG_POP([C++])dnl
341 ])# BOOST_FIND_LIB
344 # --------------------------------------- #
345 # Checks for the various Boost libraries. #
346 # --------------------------------------- #
348 # List of boost libraries: http://www.boost.org/libs/libraries.htm
349 # The page http://beta.boost.org/doc/libs is useful: it gives the first release
350 # version of each library (among other things).
353 # BOOST_BIND()
354 # ------------
355 # Look for Boost.Bind
356 AC_DEFUN([BOOST_BIND],
357 [BOOST_FIND_HEADER([boost/bind.hpp])])
360 # BOOST_CONVERSION()
361 # ------------------
362 # Look for Boost.Conversion (cast / lexical_cast)
363 AC_DEFUN([BOOST_CONVERSION],
364 [BOOST_FIND_HEADER([boost/cast.hpp])
365 BOOST_FIND_HEADER([boost/lexical_cast.hpp])
366 ])# BOOST_CONVERSION
369 # BOOST_DATE_TIME([PREFERRED-RT-OPT])
370 # -----------------------------------
371 # Look for Boost.Date_Time.  For the documentation of PREFERRED-RT-OPT, see the
372 # documentation of BOOST_FIND_LIB above.
373 AC_DEFUN([BOOST_DATE_TIME],
374 [BOOST_FIND_LIB([date_time], [$1],
375                 [boost/date_time/posix_time/posix_time.hpp],
376                 [boost::posix_time::ptime t;])
377 ])# BOOST_DATE_TIME
380 # BOOST_FILESYSTEM([PREFERRED-RT-OPT])
381 # ------------------------------------
382 # Look for Boost.Filesystem.  For the documentation of PREFERRED-RT-OPT, see the
383 # documentation of BOOST_FIND_LIB above.
384 # Do not check for boost/filesystem.hpp because this file was introduced in 1.34.
385 AC_DEFUN([BOOST_FILESYSTEM],
386 [BOOST_FIND_LIB([filesystem], [$1],
387                 [boost/filesystem/path.hpp], [boost::filesystem::path p;])
388 ])# BOOST_FILESYSTEM
391 # BOOST_FOREACH()
392 # ---------------
393 # Look for Boost.Foreach
394 AC_DEFUN([BOOST_FOREACH],
395 [BOOST_FIND_HEADER([boost/foreach.hpp])])
398 # BOOST_FORMAT()
399 # --------------
400 # Look for Boost.Format
401 # Note: we can't check for boost/format/format_fwd.hpp because the header isn't
402 # standalone.  It can't be compiled because it triggers the following error:
403 # boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std'
404 #                                                  does not name a type
405 AC_DEFUN([BOOST_FORMAT],
406 [BOOST_FIND_HEADER([boost/format.hpp])])
409 # BOOST_FUNCTION()
410 # ----------------
411 # Look for Boost.Function
412 AC_DEFUN([BOOST_FUNCTION],
413 [BOOST_FIND_HEADER([boost/function.hpp])])
416 # BOOST_GRAPH([PREFERRED-RT-OPT])
417 # -------------------------------
418 # Look for Boost.Graphs.  For the documentation of PREFERRED-RT-OPT, see the
419 # documentation of BOOST_FIND_LIB above.
420 AC_DEFUN([BOOST_GRAPH],
421 [BOOST_FIND_LIB([graph], [$1],
422                 [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;])
423 ])# BOOST_GRAPH
426 # BOOST_IOSTREAMS([PREFERRED-RT-OPT])
427 # -------------------------------
428 # Look for Boost.IOStreams.  For the documentation of PREFERRED-RT-OPT, see the
429 # documentation of BOOST_FIND_LIB above.
430 AC_DEFUN([BOOST_IOSTREAMS],
431 [BOOST_FIND_LIB([iostreams], [$1],
432                 [boost/iostreams/device/file_descriptor.hpp],
433                 [boost::iostreams::file_descriptor fd(0); fd.close();])
434 ])# BOOST_IOSTREAMS
437 # BOOST_HASH()
438 # ------------
439 # Look for Boost.Functional/Hash
440 AC_DEFUN([BOOST_HASH],
441 [BOOST_FIND_HEADER([boost/functional/hash.hpp])])
444 # BOOST_LAMBDA()
445 # --------------
446 # Look for Boost.Lambda
447 AC_DEFUN([BOOST_LAMBDA],
448 [BOOST_FIND_HEADER([boost/lambda/lambda.hpp])])
451 # BOOST_PREPROCESSOR()
452 # --------------------
453 # Look for Boost.Preprocessor
454 AC_DEFUN([BOOST_PREPROCESSOR],
455 [BOOST_FIND_HEADER([boost/preprocessor/repeat.hpp])])
458 # BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT])
459 # -----------------------------------------
460 # Look for Boost.Program_options.  For the documentation of PREFERRED-RT-OPT, see
461 # the documentation of BOOST_FIND_LIB above.
462 AC_DEFUN([BOOST_PROGRAM_OPTIONS],
463 [BOOST_FIND_LIB([program_options], [$1],
464                 [boost/program_options.hpp],
465                 [boost::program_options::options_description d("test");])
466 ])# BOOST_PROGRAM_OPTIONS
469 # BOOST_REF()
470 # -----------
471 # Look for Boost.Ref
472 AC_DEFUN([BOOST_REF],
473 [BOOST_FIND_HEADER([boost/ref.hpp])])
476 # BOOST_REGEX([PREFERRED-RT-OPT])
477 # -------------------------------
478 # Look for Boost.Regex.  For the documentation of PREFERRED-RT-OPT, see the
479 # documentation of BOOST_FIND_LIB above.
480 AC_DEFUN([BOOST_REGEX],
481 [BOOST_FIND_LIB([regex], [$1],
482                 [boost/regex.hpp],
483                 [boost::regex exp("*"); boost::regex_match("foo", exp);])
484 ])# BOOST_REGEX
487 # BOOST_SERIALIZATION([PREFERRED-RT-OPT])
488 # ---------------------------------------
489 # Look for Boost.Serialization.  For the documentation of PREFERRED-RT-OPT, see
490 # the documentation of BOOST_FIND_LIB above.
491 AC_DEFUN([BOOST_SERIALIZATION],
492 [BOOST_FIND_LIB([serialization], [$1],
493                 [boost/archive/text_oarchive.hpp],
494                 [std::ostream* o = 0; // Cheap way to get an ostream...
495                 boost::archive::text_oarchive t(*o);])
496 ])# BOOST_SIGNALS
499 # BOOST_SIGNALS([PREFERRED-RT-OPT])
500 # ---------------------------------
501 # Look for Boost.Signals.  For the documentation of PREFERRED-RT-OPT, see the
502 # documentation of BOOST_FIND_LIB above.
503 AC_DEFUN([BOOST_SIGNALS],
504 [BOOST_FIND_LIB([signals], [$1],
505                 [boost/signal.hpp],
506                 [boost::signal<void ()> s;])
507 ])# BOOST_SIGNALS
510 # BOOST_SMART_PTR()
511 # -----------------
512 # Look for Boost.SmartPtr
513 AC_DEFUN([BOOST_SMART_PTR],
514 [BOOST_FIND_HEADER([boost/scoped_ptr.hpp])
515 BOOST_FIND_HEADER([boost/shared_ptr.hpp])
519 # BOOST_STRING_ALGO()
520 # -------------------
521 # Look for Boost.StringAlgo
522 AC_DEFUN([BOOST_STRING_ALGO],
523 [BOOST_FIND_HEADER([boost/algorithm/string.hpp])
527 # BOOST_TEST([PREFERRED-RT-OPT])
528 # ------------------------------
529 # Look for Boost.Test.  For the documentation of PREFERRED-RT-OPT, see the
530 # documentation of BOOST_FIND_LIB above.
531 AC_DEFUN([BOOST_TEST],
532 [m4_pattern_allow([^BOOST_CHECK$])dnl
533 BOOST_FIND_LIB([unit_test_framework], [$1],
534                [boost/test/unit_test.hpp], [BOOST_CHECK(2 == 2);],
535                [using boost::unit_test::test_suite;
536                test_suite* init_unit_test_suite(int argc, char ** argv)
537                { return NULL; }])
538 ])# BOOST_TEST
541 # BOOST_THREADS([PREFERRED-RT-OPT])
542 # ---------------------------------
543 # Look for Boost.Thread.  For the documentation of PREFERRED-RT-OPT, see the
544 # documentation of BOOST_FIND_LIB above.
545 # FIXME: Provide an alias "BOOST_THREAD".
546 AC_DEFUN([BOOST_THREADS],
547 [dnl Having the pthread flag is required at least on GCC3 where
548 dnl boost/thread.hpp would complain if we try to compile without
549 dnl -pthread on GNU/Linux.
550 AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
551 boost_threads_save_LIBS=$LIBS
552 boost_threads_save_CPPFLAGS=$CPPFLAGS
553 LIBS="$LIBS $boost_cv_pthread_flag"
554 # Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
555 # boost/thread.hpp will trigger a #error if -pthread isn't used:
556 #   boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
557 #   is not turned on. Please set the correct command line options for
558 #   threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
559 CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag"
560 BOOST_FIND_LIB([thread], [$1],
561                 [boost/thread.hpp], [boost::thread t; boost::mutex m;])
562 BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $boost_cv_pthread_flag"
563 BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag"
564 LIBS=$boost_threads_save_LIBS
565 CPPFLAGS=$boost_threads_save_CPPFLAGS
566 ])# BOOST_THREADS
569 # BOOST_TOKENIZER()
570 # -----------------
571 # Look for Boost.Tokenizer
572 AC_DEFUN([BOOST_TOKENIZER],
573 [BOOST_FIND_HEADER([boost/tokenizer.hpp])])
576 # BOOST_TRIBOOL()
577 # ---------------
578 # Look for Boost.Tribool
579 AC_DEFUN([BOOST_TRIBOOL],
580 [BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp])
581 BOOST_FIND_HEADER([boost/logic/tribool.hpp])
585 # BOOST_TUPLE()
586 # -------------
587 # Look for Boost.Tuple
588 AC_DEFUN([BOOST_TUPLE],
589 [BOOST_FIND_HEADER([boost/tuple/tuple.hpp])])
592 # BOOST_UTILITY()
593 # ---------------
594 # Look for Boost.Utility (noncopyable, result_of, base-from-member idiom,
595 # etc.)
596 AC_DEFUN([BOOST_UTILITY],
597 [BOOST_FIND_HEADER([boost/utility.hpp])])
600 # BOOST_VARIANT()
601 # ---------------
602 # Look for Boost.Variant.
603 AC_DEFUN([BOOST_VARIANT],
604 [BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp])
605 BOOST_FIND_HEADER([boost/variant.hpp])])
608 # BOOST_WAVE([PREFERRED-RT-OPT])
609 # ------------------------------
610 # Look for Boost.Wave.  For the documentation of PREFERRED-RT-OPT, see the
611 # documentation of BOOST_FIND_LIB above.
612 AC_DEFUN([BOOST_WAVE],
613 [BOOST_FIND_LIB([wave], [$1],
614                 [boost/wave.hpp],
615                 [boost::wave::token_id id; get_token_name(id);])])
618 # ----------------- #
619 # Internal helpers. #
620 # ----------------- #
623 # _BOOST_PTHREAD_FLAG()
624 # ---------------------
625 # Internal helper for BOOST_THREADS.  Based on ACX_PTHREAD:
626 # http://autoconf-archive.cryp.to/acx_pthread.html
627 AC_DEFUN([_BOOST_PTHREAD_FLAG],
628 [AC_REQUIRE([AC_PROG_CXX])dnl
629 AC_REQUIRE([AC_CANONICAL_HOST])dnl
630 AC_LANG_PUSH([C++])dnl
631 AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag],
632 [ boost_cv_pthread_flag=
633   # The ordering *is* (sometimes) important.  Some notes on the
634   # individual items follow:
635   # (none): in case threads are in libc; should be tried before -Kthread and
636   #       other compiler flags to prevent continual compiler warnings
637   # -lpthreads: AIX (must check this before -lpthread)
638   # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
639   # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
640   # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
641   # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
642   # -pthreads: Solaris/GCC
643   # -mthreads: MinGW32/GCC, Lynx/GCC
644   # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
645   #      doesn't hurt to check since this sometimes defines pthreads too;
646   #      also defines -D_REENTRANT)
647   #      ... -mt is also the pthreads flag for HP/aCC
648   # -lpthread: GNU Linux, etc.
649   # --thread-safe: KAI C++
650   case $host_os in #(
651     *solaris*)
652       # On Solaris (at least, for some versions), libc contains stubbed
653       # (non-functional) versions of the pthreads routines, so link-based
654       # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
655       # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
656       # a function called by this macro, so we could check for that, but
657       # who knows whether they'll stub that too in a future libc.)  So,
658       # we'll just look for -pthreads and -lpthread first:
659       boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #(
660     *)
661       boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \
662                            -pthreads -mthreads -lpthread --thread-safe -mt";;
663   esac
664   # Generate the test file.
665   AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <pthread.h>],
666     [pthread_t th; pthread_join(th, 0);
667     pthread_attr_init(0); pthread_cleanup_push(0, 0);
668     pthread_create(0,0,0,0); pthread_cleanup_pop(0);])])
669   for boost_pthread_flag in '' $boost_pthread_flags; do
670     boost_pthread_ok=false
671 dnl Re-use the test file already generated.
672     boost_pthreads__save_LIBS=$LIBS
673     LIBS="$LIBS $boost_pthread_flag"
674     AC_LINK_IFELSE([],
675       [if grep ".*$boost_pthread_flag" conftest.err; then
676          echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD
677        else
678          boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag
679        fi])
680     LIBS=$boost_pthreads__save_LIBS
681     $boost_pthread_ok && break
682   done
684 AC_LANG_POP([C++])dnl
685 ])# _BOOST_PTHREAD_FLAG
688 # _BOOST_gcc_test(MAJOR, MINOR)
689 # -----------------------------
690 # Internal helper for _BOOST_FIND_COMPILER_TAG.
691 m4_define([_BOOST_gcc_test],
692 ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl
695 # _BOOST_FIND_COMPILER_TAG()
696 # --------------------------
697 # Internal.  When Boost is installed without --layout=system, each library
698 # filename will hold a suffix that encodes the compiler used during the
699 # build.  The Boost build system seems to call this a `tag'.
700 AC_DEFUN([_BOOST_FIND_COMPILER_TAG],
701 [AC_REQUIRE([AC_PROG_CXX])dnl
702 AC_CACHE_CHECK([for the toolset name used by Boost for $CXX], [boost_cv_lib_tag],
703 [AC_LANG_PUSH([C++])dnl
704   boost_cv_lib_tag=unknown
705   # The following tests are mostly inspired by boost/config/auto_link.hpp
706   # The list is sorted to most recent/common to oldest compiler (in order
707   # to increase the likelihood of finding the right compiler with the
708   # least number of compilation attempt).
709   # Beware that some tests are sensible to the order (for instance, we must
710   # look for MinGW before looking for GCC3).
711   # I used one compilation test per compiler with a #error to recognize
712   # each compiler so that it works even when cross-compiling (let me know
713   # if you know a better approach).
714   # Known missing tags (known from Boost's tools/build/v2/tools/common.jam):
715   #   como, edg, kcc, bck, mp, sw, tru, xlc
716   # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines
717   # the same defines as GCC's).
718   # TODO: Move the test on GCC 4.3 up once it's released.
719   for i in \
720     _BOOST_gcc_test(4, 2) \
721     _BOOST_gcc_test(4, 1) \
722     _BOOST_gcc_test(4, 0) \
723     "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \
724      && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
725          || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \
726     _BOOST_gcc_test(3, 4) \
727     _BOOST_gcc_test(3, 3) \
728     "defined _MSC_VER && _MSC_VER >= 1400 @ vc80" \
729     _BOOST_gcc_test(3, 2) \
730     "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \
731     _BOOST_gcc_test(3, 1) \
732     _BOOST_gcc_test(3, 0) \
733     "defined __BORLANDC__ @ bcb" \
734     "defined __ICC && (defined __unix || defined __unix__) @ il" \
735     "defined __ICL @ iw" \
736     "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \
737     _BOOST_gcc_test(4, 3) \
738     _BOOST_gcc_test(2, 95) \
739     "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \
740     "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \
741     "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \
742     "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8"
743   do
744     boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '`
745     boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'`
746     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
747 #if $boost_tag_test
748 /* OK */
749 #else
750 # error $boost_tag_test
751 #endif
752 ]])], [boost_cv_lib_tag=$boost_tag; break], [])
753   done
754 AC_LANG_POP([C++])dnl
756   case $boost_cv_lib_tag in #(
757     # Some newer (>= 1.35?) versions of Boost seem to only use "gcc" as opposed
758     # to "gcc41" for instance.
759     gcc*)
760       # We can specify multiple tags in this variable because it's used by
761       # BOOST_FIND_LIB that does a `for tag in -$boost_cv_lib_tag' ...
762       boost_cv_lib_tag="$boost_cv_lib_tag -gcc"
763       ;; #(
764     unknown)
765       AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]])
766       boost_cv_lib_tag=
767       ;;
768   esac
769 ])# _BOOST_FIND_COMPILER_TAG
772 # _BOOST_GUESS_WHETHER_TO_USE_MT()
773 # --------------------------------
774 # Compile a small test to try to guess whether we should favor MT (Multi
775 # Thread) flavors of Boost.  Sets boost_guess_use_mt accordingly.
776 AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT],
777 [# Check whether we do better use `mt' even though we weren't ask to.
778 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
779 #if defined _REENTRANT || defined _MT || defined __MT__
780 /* use -mt */
781 #else
782 # error MT not needed
783 #endif
784 ]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false])
787 # _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
788 # -------------------------------------------------------------------
789 # Fork of _AC_LINK_IFELSE that preserves conftest.o across calls.  Fragile,
790 # will break when Autoconf changes its internals.  Requires that you manually
791 # rm -f conftest.$ac_objext in between to really different tests, otherwise
792 # you will try to link a conftest.o left behind by a previous test.
793 # Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this
794 # macro)
795 m4_define([_BOOST_AC_LINK_IFELSE],
796 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
797 rm -f conftest$ac_exeext
798 boost_ac_ext_save=$ac_ext
799 boost_use_source=:
800 # If we already have a .o, re-use it.  We change $ac_ext so that $ac_link
801 # tries to link the existing object file instead of compiling from source.
802 test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false &&
803   _AS_ECHO_LOG([re-using the existing conftest.$ac_objext])
804 AS_IF([_AC_DO_STDERR($ac_link) && {
805          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
806          test ! -s conftest.err
807        } && test -s conftest$ac_exeext && {
808          test "$cross_compiling" = yes ||
809          $as_executable_p conftest$ac_exeext
810 dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough.
811        }],
812       [$2],
813       [if $boost_use_source; then
814          _AC_MSG_LOG_CONFTEST
815        fi
816        $3])
817 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
818 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
819 dnl as it would interfere with the next link command.
820 rm -f core conftest.err conftest_ipa8_conftest.oo \
821       conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl
822 ])# _BOOST_AC_LINK_IFELSE