1 # boost.m4: Locate Boost headers and libraries for autoconf-based projects.
2 # Copyright (C) 2007, 2008, 2009 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/>.
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
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 # If the user's environment contains BOOST_ROOT and --with-boost was not
39 # specified, --with-boost=$BOOST_ROOT is implicitly used.
40 # For more README and documentation, go to http://repo.or.cz/w/boost.m4.git
41 # Note: THESE MACROS ASSUME THAT YOU USE LIBTOOL. If you don't, don't worry,
42 # simply read the README, it will show you what to do step by step.
44 m4_pattern_forbid([^_?BOOST_])
47 # _BOOST_SED_CPP(SED-PROGRAM, PROGRAM,
48 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
49 # --------------------------------------------------------
50 # Same as AC_EGREP_CPP, but leave the result in conftest.i.
51 # PATTERN is *not* overquoted, as in AC_EGREP_CPP. It could be useful
52 # to turn this into a macro which extracts the value of any macro.
53 m4_define([_BOOST_SED_CPP],
54 [AC_LANG_PREPROC_REQUIRE()dnl
55 AC_REQUIRE([AC_PROG_SED])dnl
56 AC_LANG_CONFTEST([AC_LANG_SOURCE([[$2]])])
57 AS_IF([dnl eval is necessary to expand ac_cpp.
58 dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
59 (eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
60 $SED -n -e "$1" >conftest.i 2>&1],
68 # BOOST_REQUIRE([VERSION])
69 # ------------------------
70 # Look for Boost. If version is given, it must either be a literal of the form
71 # "X.Y.Z" where X, Y and Z are integers (the ".Z" part being optional) or a
73 # Defines the value BOOST_CPPFLAGS. This macro only checks for headers with
74 # the required version, it does not check for any of the Boost libraries.
75 # FIXME: Add a 2nd optional argument so that it's not fatal if Boost isn't found
76 # and add an AC_DEFINE to tell whether HAVE_BOOST.
77 AC_DEFUN([BOOST_REQUIRE],
79 boost_version_req="$1"
81 set x $boost_version_req 0 0 0
84 boost_version_req=`expr "$[1]" '*' 100000 + "$[2]" '*' 100 + "$[3]"`
86 [AS_HELP_STRING([--with-boost=DIR],
87 [prefix of Boost $1 @<:@guess@:>@])])dnl
88 AC_ARG_VAR([BOOST_ROOT],[Location of Boost installation])dnl
89 # If BOOST_ROOT is set and the user has not provided a value to
90 # --with-boost, then treat BOOST_ROOT as if it the user supplied it.
91 if test x"$BOOST_ROOT" != x; then
92 if test x"$with_boost" = x; then
93 AC_MSG_NOTICE([Detected BOOST_ROOT; continuing with --with-boost=$BOOST_ROOT])
94 with_boost=$BOOST_ROOT
96 AC_MSG_NOTICE([Detected BOOST_ROOT=$BOOST_ROOT, but overridden by --with-boost=$with_boost])
99 AC_SUBST([DISTCHECK_CONFIGURE_FLAGS],
100 ["$DISTCHECK_CONFIGURE_FLAGS '--with-boost=$with_boost'"])
101 boost_save_CPPFLAGS=$CPPFLAGS
102 AC_CACHE_CHECK([for Boost headers version >= $boost_version_req],
104 [boost_cv_inc_path=no
105 AC_LANG_PUSH([C++])dnl
106 m4_pattern_allow([^BOOST_VERSION$])dnl
107 AC_LANG_CONFTEST([AC_LANG_PROGRAM([[#include <boost/version.hpp>
108 #if !defined BOOST_VERSION
109 # error BOOST_VERSION is not defined
110 #elif BOOST_VERSION < $boost_version_req
111 # error Boost headers version < $boost_version_req
114 # If the user provided a value to --with-boost, use it and only it.
115 case $with_boost in #(
116 ''|yes) set x '' /opt/local/include /usr/local/include /opt/include \
117 /usr/include C:/Boost/include;; #(
118 *) set x "$with_boost/include" "$with_boost";;
123 # Without --layout=system, Boost (or at least some versions) installs
124 # itself in <prefix>/include/boost-<version>. This inner loop helps to
125 # find headers in such directories.
126 # I didn't indent this loop on purpose (to avoid over-indented code)
127 for boost_inc in "$boost_dir" "$boost_dir"/boost-*
129 test x"$boost_inc" != x && CPPFLAGS="$CPPFLAGS -I$boost_inc"
130 AC_COMPILE_IFELSE([], [boost_cv_inc_path=yes], [boost_cv_version=no])
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
139 AC_LANG_POP([C++])dnl
141 case $boost_cv_inc_path in #(
142 no) AC_MSG_ERROR([cannot find Boost headers version >= $boost_version_req]);;#(
143 yes) BOOST_CPPFLAGS=;;#(
144 *) AC_SUBST([BOOST_CPPFLAGS], ["-I$boost_cv_inc_path"]);;
146 AC_CACHE_CHECK([for Boost's header version],
147 [boost_cv_lib_version],
148 [m4_pattern_allow([^BOOST_LIB_VERSION$])dnl
149 _BOOST_SED_CPP([/^boost-lib-version = /{s///;s/\"//g;p;g;}],
150 [#include <boost/version.hpp>
151 boost-lib-version = BOOST_LIB_VERSION],
152 [boost_cv_lib_version=`cat conftest.i`])])
153 # e.g. "134" for 1_34_1 or "135" for 1_35
154 boost_major_version=`echo "$boost_cv_lib_version" | sed 's/_//;s/_.*//'`
155 case $boost_major_version in #(
157 AC_MSG_ERROR([Invalid value: boost_major_version=$boost_major_version])
160 CPPFLAGS=$boost_save_CPPFLAGS
165 # Add the "--enable-static-boost" configure argument. If this argument is given
166 # on the command line, static versions of the libraries will be looked up.
167 AC_DEFUN([BOOST_STATIC],
168 [AC_ARG_ENABLE([static-boost],
169 [AC_HELP_STRING([--enable-static-boost],
170 [Prefer the static boost libraries over the shared ones [no]])],
171 [enable_static_boost=yes],
172 [enable_static_boost=no])])# BOOST_STATIC
174 # BOOST_FIND_HEADER([HEADER-NAME], [ACTION-IF-NOT-FOUND], [ACTION-IF-FOUND])
175 # --------------------------------------------------------------------------
176 # Wrapper around AC_CHECK_HEADER for Boost headers. Useful to check for
177 # some parts of the Boost library which are only made of headers and don't
178 # require linking (such as Boost.Foreach).
180 # Default ACTION-IF-NOT-FOUND: Fail with a fatal error.
182 # Default ACTION-IF-FOUND: define the preprocessor symbol HAVE_<HEADER-NAME> in
183 # case of success # (where HEADER-NAME is written LIKE_THIS, e.g.,
184 # HAVE_BOOST_FOREACH_HPP).
185 AC_DEFUN([BOOST_FIND_HEADER],
186 [AC_REQUIRE([BOOST_REQUIRE])dnl
187 AC_LANG_PUSH([C++])dnl
188 boost_save_CPPFLAGS=$CPPFLAGS
189 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
190 AC_CHECK_HEADER([$1],
191 [m4_default([$3], [AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1],
192 [Define to 1 if you have <$1>])])],
193 [m4_default([$2], [AC_MSG_ERROR([cannot find $1])])])
194 CPPFLAGS=$boost_save_CPPFLAGS
195 AC_LANG_POP([C++])dnl
196 ])# BOOST_FIND_HEADER
199 # BOOST_FIND_LIB([LIB-NAME], [PREFERRED-RT-OPT], [HEADER-NAME], [CXX-TEST],
201 # -------------------------------------------------------------------------
202 # Look for the Boost library LIB-NAME (e.g., LIB-NAME = `thread', for
203 # libboost_thread). Check that HEADER-NAME works and check that
204 # libboost_LIB-NAME can link with the code CXX-TEST. The optional argument
205 # CXX-PROLOGUE can be used to include some C++ code before the `main'
208 # Invokes BOOST_FIND_HEADER([HEADER-NAME]) (see above).
210 # Boost libraries typically come compiled with several flavors (with different
211 # runtime options) so PREFERRED-RT-OPT is the preferred suffix. A suffix is one
212 # or more of the following letters: sgdpn (in that order). s = static
213 # runtime, d = debug build, g = debug/diagnostic runtime, p = STLPort build,
214 # n = (unsure) STLPort build without iostreams from STLPort (it looks like `n'
215 # must always be used along with `p'). Additionally, PREFERRED-RT-OPT can
216 # start with `mt-' to indicate that there is a preference for multi-thread
217 # builds. Some sample values for PREFERRED-RT-OPT: (nothing), mt, d, mt-d, gdp
218 # ... If you want to make sure you have a specific version of Boost
219 # (eg, >= 1.33) you *must* invoke BOOST_REQUIRE before this macro.
220 AC_DEFUN([BOOST_FIND_LIB],
221 [AC_REQUIRE([_BOOST_FIND_COMPILER_TAG])dnl
222 AC_REQUIRE([BOOST_REQUIRE])dnl
223 AC_REQUIRE([BOOST_STATIC])dnl
224 AC_REQUIRE([_BOOST_GUESS_WHETHER_TO_USE_MT])dnl
225 AC_LANG_PUSH([C++])dnl
226 AS_VAR_PUSHDEF([Boost_lib], [boost_cv_lib_$1])dnl
227 AS_VAR_PUSHDEF([Boost_lib_LDFLAGS], [boost_cv_lib_$1_LDFLAGS])dnl
228 AS_VAR_PUSHDEF([Boost_lib_LIBS], [boost_cv_lib_$1_LIBS])dnl
229 BOOST_FIND_HEADER([$3])
230 boost_save_CPPFLAGS=$CPPFLAGS
231 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
232 # Now let's try to find the library. The algorithm is as follows: first look
233 # for a given library name according to the user's PREFERRED-RT-OPT. For each
234 # library name, we prefer to use the ones that carry the tag (toolset name).
235 # Each library is searched through the various standard paths were Boost is
236 # usually installed. If we can't find the standard variants, we try to
237 # enforce -mt (for instance on MacOSX, libboost_threads.dylib doesn't exist
238 # but there's -obviously- libboost_threads-mt.dylib).
239 AC_CACHE_CHECK([for the Boost $1 library], [Boost_lib],
242 mt | mt-) boost_mt=-mt; boost_rtopt=;; #(
243 mt* | mt-*) boost_mt=-mt; boost_rtopt=`expr "X$2" : 'Xmt-*\(.*\)'`;; #(
244 *) boost_mt=; boost_rtopt=$2;;
246 if test $enable_static_boost = yes; then
247 boost_rtopt="s$boost_rtopt"
249 # Find the proper debug variant depending on what we've been asked to find.
250 case $boost_rtopt in #(
251 *d*) boost_rt_d=$boost_rtopt;; #(
252 *[[sgpn]]*) # Insert the `d' at the right place (in between `sg' and `pn')
253 boost_rt_d=`echo "$boost_rtopt" | sed 's/\(s*g*\)\(p*n*\)/\1\2/'`;; #(
256 # If the PREFERRED-RT-OPT are not empty, prepend a `-'.
257 test -n "$boost_rtopt" && boost_rtopt="-$boost_rtopt"
258 $boost_guess_use_mt && boost_mt=-mt
259 # Look for the abs path the static archive.
260 # $libext is computed by Libtool but let's make sure it's non empty.
262 AC_MSG_ERROR([the libext variable is empty, did you invoke Libtool?])
263 boost_save_ac_objext=$ac_objext
264 # Generate the test file.
265 AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <$3>
267 dnl Optimization hacks: compiling C++ is slow, especially with Boost. What
268 dnl we're trying to do here is guess the right combination of link flags
269 dnl (LIBS / LDFLAGS) to use a given library. This can take several
270 dnl iterations before it succeeds and is thus *very* slow. So what we do
271 dnl instead is that we compile the code first (and thus get an object file,
272 dnl typically conftest.o). Then we try various combinations of link flags
273 dnl until we succeed to link conftest.o in an executable. The problem is
274 dnl that the various TRY_LINK / COMPILE_IFELSE macros of Autoconf always
275 dnl remove all the temporary files including conftest.o. So the trick here
276 dnl is to temporarily change the value of ac_objext so that conftest.o is
277 dnl preserved accross tests. This is obviously fragile and I will burn in
278 dnl hell for not respecting Autoconf's documented interfaces, but in the
279 dnl mean time, it optimizes the macro by a factor of 5 to 30.
280 dnl Another small optimization: the first argument of AC_COMPILE_IFELSE left
281 dnl empty because the test file is generated only once above (before we
282 dnl start the for loops).
283 AC_COMPILE_IFELSE([],
284 [ac_objext=do_not_rm_me_plz],
285 [AC_MSG_ERROR([Cannot compile a test that uses Boost $1])])
286 ac_objext=$boost_save_ac_objext
288 # Don't bother to ident the 6 nested for loops, only the 2 innermost ones
290 for boost_tag_ in -$boost_cv_lib_tag ''; do
291 for boost_ver_ in -$boost_cv_lib_version ''; do
292 for boost_mt_ in $boost_mt -mt ''; do
293 for boost_rtopt_ in $boost_rtopt '' -d; do
295 boost_$1$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ \
296 boost_$1$boost_tag_$boost_rtopt_$boost_ver_ \
297 boost_$1$boost_tag_$boost_mt_$boost_ver_ \
298 boost_$1$boost_tag_$boost_ver_
300 # Avoid testing twice the same lib
301 case $boost_failed_libs in #(
302 *@$boost_lib@*) continue;;
304 # If with_boost is empty, we'll search in /lib first, which is not quite
305 # right so instead we'll try to a location based on where the headers are.
306 boost_tmp_lib=$with_boost
307 test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include}
308 for boost_ldpath in "$boost_tmp_lib/lib" '' \
309 /opt/local/lib /usr/local/lib /opt/lib /usr/lib \
310 "$with_boost" C:/Boost/lib /lib /usr/lib64 /lib64
312 test -e "$boost_ldpath" || continue
313 boost_save_LDFLAGS=$LDFLAGS
314 # Are we looking for a static library?
315 case $boost_ldpath:$boost_rtopt_ in #(
316 *?*:*s*) # Yes (Non empty boost_ldpath + s in rt opt)
317 Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext"
318 test -e "$Boost_lib_LIBS" || continue;; #(
319 *) # No: use -lboost_foo to find the shared library.
320 Boost_lib_LIBS="-l$boost_lib";;
322 boost_save_LIBS=$LIBS
323 LIBS="$Boost_lib_LIBS $LIBS"
324 test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"
325 dnl First argument of AC_LINK_IFELSE left empty because the test file is
326 dnl generated only once above (before we start the for loops).
327 _BOOST_AC_LINK_IFELSE([],
328 [Boost_lib=yes], [Boost_lib=no])
329 ac_objext=$boost_save_ac_objext
330 LDFLAGS=$boost_save_LDFLAGS
331 LIBS=$boost_save_LIBS
332 if test x"$Boost_lib" = xyes; then
333 Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath"
336 boost_failed_libs="$boost_failed_libs@$boost_lib@"
344 rm -f conftest.$ac_objext
346 case $Boost_lib in #(
347 no) AC_MSG_ERROR([Could not find the flags to link with Boost $1])
350 AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS])
351 AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS])
352 CPPFLAGS=$boost_save_CPPFLAGS
353 AS_VAR_POPDEF([Boost_lib])dnl
354 AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl
355 AS_VAR_POPDEF([Boost_lib_LIBS])dnl
356 AC_LANG_POP([C++])dnl
360 # --------------------------------------- #
361 # Checks for the various Boost libraries. #
362 # --------------------------------------- #
364 # List of boost libraries: http://www.boost.org/libs/libraries.htm
365 # The page http://beta.boost.org/doc/libs is useful: it gives the first release
366 # version of each library (among other things).
371 # Look for Boost.Asio (new in Boost 1.35).
372 AC_DEFUN([BOOST_ASIO],
373 [AC_REQUIRE([BOOST_SYSTEM])dnl
374 BOOST_FIND_HEADER([boost/asio.hpp])])
379 # Look for Boost.Bind
380 AC_DEFUN([BOOST_BIND],
381 [BOOST_FIND_HEADER([boost/bind.hpp])])
386 # Look for Boost.Conversion (cast / lexical_cast)
387 AC_DEFUN([BOOST_CONVERSION],
388 [BOOST_FIND_HEADER([boost/cast.hpp])
389 BOOST_FIND_HEADER([boost/lexical_cast.hpp])
393 # BOOST_DATE_TIME([PREFERRED-RT-OPT])
394 # -----------------------------------
395 # Look for Boost.Date_Time. For the documentation of PREFERRED-RT-OPT, see the
396 # documentation of BOOST_FIND_LIB above.
397 AC_DEFUN([BOOST_DATE_TIME],
398 [BOOST_FIND_LIB([date_time], [$1],
399 [boost/date_time/posix_time/posix_time.hpp],
400 [boost::posix_time::ptime t;])
404 # BOOST_FILESYSTEM([PREFERRED-RT-OPT])
405 # ------------------------------------
406 # Look for Boost.Filesystem. For the documentation of PREFERRED-RT-OPT, see
407 # the documentation of BOOST_FIND_LIB above.
408 # Do not check for boost/filesystem.hpp because this file was introduced in
410 AC_DEFUN([BOOST_FILESYSTEM],
411 [# Do we have to check for Boost.System? This link-time dependency was
412 # added as of 1.35.0. If we have a version <1.35, we must not attempt to
413 # find Boost.System as it didn't exist by then.
414 if test $boost_major_version -ge 135; then
416 fi # end of the Boost.System check.
417 boost_filesystem_save_LIBS=$LIBS
418 boost_filesystem_save_LDFLAGS=$LDFLAGS
419 m4_pattern_allow([^BOOST_SYSTEM_(LIBS|LDFLAGS)$])dnl
420 LIBS="$LIBS $BOOST_SYSTEM_LIBS"
421 LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS"
422 BOOST_FIND_LIB([filesystem], [$1],
423 [boost/filesystem/path.hpp], [boost::filesystem::path p;])
424 LIBS=$boost_filesystem_save_LIBS
425 LDFLAGS=$boost_filesystem_save_LDFLAGS
431 # Look for Boost.Foreach
432 AC_DEFUN([BOOST_FOREACH],
433 [BOOST_FIND_HEADER([boost/foreach.hpp])])
438 # Look for Boost.Format
439 # Note: we can't check for boost/format/format_fwd.hpp because the header isn't
440 # standalone. It can't be compiled because it triggers the following error:
441 # boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std'
442 # does not name a type
443 AC_DEFUN([BOOST_FORMAT],
444 [BOOST_FIND_HEADER([boost/format.hpp])])
449 # Look for Boost.Function
450 AC_DEFUN([BOOST_FUNCTION],
451 [BOOST_FIND_HEADER([boost/function.hpp])])
454 # BOOST_GRAPH([PREFERRED-RT-OPT])
455 # -------------------------------
456 # Look for Boost.Graphs. For the documentation of PREFERRED-RT-OPT, see the
457 # documentation of BOOST_FIND_LIB above.
458 AC_DEFUN([BOOST_GRAPH],
459 [BOOST_FIND_LIB([graph], [$1],
460 [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;])
464 # BOOST_IOSTREAMS([PREFERRED-RT-OPT])
465 # -------------------------------
466 # Look for Boost.IOStreams. For the documentation of PREFERRED-RT-OPT, see the
467 # documentation of BOOST_FIND_LIB above.
468 AC_DEFUN([BOOST_IOSTREAMS],
469 [BOOST_FIND_LIB([iostreams], [$1],
470 [boost/iostreams/device/file_descriptor.hpp],
471 [boost::iostreams::file_descriptor fd(0); fd.close();])
477 # Look for Boost.Functional/Hash
478 AC_DEFUN([BOOST_HASH],
479 [BOOST_FIND_HEADER([boost/functional/hash.hpp])])
484 # Look for Boost.Lambda
485 AC_DEFUN([BOOST_LAMBDA],
486 [BOOST_FIND_HEADER([boost/lambda/lambda.hpp])])
491 # Look for Boost.Optional
492 AC_DEFUN([BOOST_OPTIONAL],
493 [BOOST_FIND_HEADER([boost/optional.hpp])])
496 # BOOST_PREPROCESSOR()
497 # --------------------
498 # Look for Boost.Preprocessor
499 AC_DEFUN([BOOST_PREPROCESSOR],
500 [BOOST_FIND_HEADER([boost/preprocessor/repeat.hpp])])
503 # BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT])
504 # -----------------------------------------
505 # Look for Boost.Program_options. For the documentation of PREFERRED-RT-OPT, see
506 # the documentation of BOOST_FIND_LIB above.
507 AC_DEFUN([BOOST_PROGRAM_OPTIONS],
508 [BOOST_FIND_LIB([program_options], [$1],
509 [boost/program_options.hpp],
510 [boost::program_options::options_description d("test");])
511 ])# BOOST_PROGRAM_OPTIONS
517 AC_DEFUN([BOOST_REF],
518 [BOOST_FIND_HEADER([boost/ref.hpp])])
521 # BOOST_REGEX([PREFERRED-RT-OPT])
522 # -------------------------------
523 # Look for Boost.Regex. For the documentation of PREFERRED-RT-OPT, see the
524 # documentation of BOOST_FIND_LIB above.
525 AC_DEFUN([BOOST_REGEX],
526 [BOOST_FIND_LIB([regex], [$1],
528 [boost::regex exp("*"); boost::regex_match("foo", exp);])
532 # BOOST_SERIALIZATION([PREFERRED-RT-OPT])
533 # ---------------------------------------
534 # Look for Boost.Serialization. For the documentation of PREFERRED-RT-OPT, see
535 # the documentation of BOOST_FIND_LIB above.
536 AC_DEFUN([BOOST_SERIALIZATION],
537 [BOOST_FIND_LIB([serialization], [$1],
538 [boost/archive/text_oarchive.hpp],
539 [std::ostream* o = 0; // Cheap way to get an ostream...
540 boost::archive::text_oarchive t(*o);])
544 # BOOST_SIGNALS([PREFERRED-RT-OPT])
545 # ---------------------------------
546 # Look for Boost.Signals. For the documentation of PREFERRED-RT-OPT, see the
547 # documentation of BOOST_FIND_LIB above.
548 AC_DEFUN([BOOST_SIGNALS],
549 [BOOST_FIND_LIB([signals], [$1],
551 [boost::signal<void ()> s;])
557 # Look for Boost.SmartPtr
558 AC_DEFUN([BOOST_SMART_PTR],
559 [BOOST_FIND_HEADER([boost/scoped_ptr.hpp])
560 BOOST_FIND_HEADER([boost/shared_ptr.hpp])
564 # BOOST_STRING_ALGO()
565 # -------------------
566 # Look for Boost.StringAlgo
567 AC_DEFUN([BOOST_STRING_ALGO],
568 [BOOST_FIND_HEADER([boost/algorithm/string.hpp])
572 # BOOST_SYSTEM([PREFERRED-RT-OPT])
573 # --------------------------------
574 # Look for Boost.System. For the documentation of PREFERRED-RT-OPT, see the
575 # documentation of BOOST_FIND_LIB above. This library was introduced in Boost
577 AC_DEFUN([BOOST_SYSTEM],
578 [BOOST_FIND_LIB([system], [$1],
579 [boost/system/error_code.hpp],
580 [boost::system::error_code e; e.clear();])
584 # BOOST_TEST([PREFERRED-RT-OPT])
585 # ------------------------------
586 # Look for Boost.Test. For the documentation of PREFERRED-RT-OPT, see the
587 # documentation of BOOST_FIND_LIB above.
588 AC_DEFUN([BOOST_TEST],
589 [m4_pattern_allow([^BOOST_CHECK$])dnl
590 BOOST_FIND_LIB([unit_test_framework], [$1],
591 [boost/test/unit_test.hpp], [BOOST_CHECK(2 == 2);],
592 [using boost::unit_test::test_suite;
593 test_suite* init_unit_test_suite(int argc, char ** argv)
598 # BOOST_THREADS([PREFERRED-RT-OPT])
599 # ---------------------------------
600 # Look for Boost.Thread. For the documentation of PREFERRED-RT-OPT, see the
601 # documentation of BOOST_FIND_LIB above.
602 # FIXME: Provide an alias "BOOST_THREAD".
603 AC_DEFUN([BOOST_THREADS],
604 [dnl Having the pthread flag is required at least on GCC3 where
605 dnl boost/thread.hpp would complain if we try to compile without
606 dnl -pthread on GNU/Linux.
607 AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
608 boost_threads_save_LIBS=$LIBS
609 boost_threads_save_CPPFLAGS=$CPPFLAGS
610 LIBS="$LIBS $boost_cv_pthread_flag"
611 # Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
612 # boost/thread.hpp will trigger a #error if -pthread isn't used:
613 # boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
614 # is not turned on. Please set the correct command line options for
615 # threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
616 CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag"
617 BOOST_FIND_LIB([thread], [$1],
618 [boost/thread.hpp], [boost::thread t; boost::mutex m;])
619 BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $boost_cv_pthread_flag"
620 BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag"
621 LIBS=$boost_threads_save_LIBS
622 CPPFLAGS=$boost_threads_save_CPPFLAGS
628 # Look for Boost.Tokenizer
629 AC_DEFUN([BOOST_TOKENIZER],
630 [BOOST_FIND_HEADER([boost/tokenizer.hpp])])
635 # Look for Boost.Tribool
636 AC_DEFUN([BOOST_TRIBOOL],
637 [BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp])
638 BOOST_FIND_HEADER([boost/logic/tribool.hpp])
644 # Look for Boost.Tuple
645 AC_DEFUN([BOOST_TUPLE],
646 [BOOST_FIND_HEADER([boost/tuple/tuple.hpp])])
651 # Look for Boost.Utility (noncopyable, result_of, base-from-member idiom,
653 AC_DEFUN([BOOST_UTILITY],
654 [BOOST_FIND_HEADER([boost/utility.hpp])])
659 # Look for Boost.Variant.
660 AC_DEFUN([BOOST_VARIANT],
661 [BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp])
662 BOOST_FIND_HEADER([boost/variant.hpp])])
665 # BOOST_WAVE([PREFERRED-RT-OPT])
666 # ------------------------------
667 # NOTE: If you intend to use Wave/Spirit with thread support, make sure you
668 # call BOOST_THREADS first.
669 # Look for Boost.Wave. For the documentation of PREFERRED-RT-OPT, see the
670 # documentation of BOOST_FIND_LIB above.
671 AC_DEFUN([BOOST_WAVE],
672 [AC_REQUIRE([BOOST_FILESYSTEM])dnl
673 AC_REQUIRE([BOOST_DATE_TIME])dnl
674 boost_wave_save_LIBS=$LIBS
675 boost_wave_save_LDFLAGS=$LDFLAGS
676 m4_pattern_allow([^BOOST_((FILE)?SYSTEM|DATE_TIME|THREAD)_(LIBS|LDFLAGS)$])dnl
677 LIBS="$LIBS $BOOST_SYSTEM_LIBS $BOOST_FILESYSTEM_LIBS $BOOST_DATE_TIME_LIBS\
679 LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS $BOOST_FILESYSTEM_LDFLAGS\
680 $BOOST_DATE_TIME_LDFLAGS $BOOST_THREAD_LDFLAGS"
681 BOOST_FIND_LIB([wave], [$1],
683 [boost::wave::token_id id; get_token_name(id);])
684 LIBS=$boost_wave_save_LIBS
685 LDFLAGS=$boost_wave_save_LDFLAGS
691 # Look for Boost.Xpressive (new since 1.36.0).
692 AC_DEFUN([BOOST_XPRESSIVE],
693 [BOOST_FIND_HEADER([boost/xpressive/xpressive.hpp])])
696 # ----------------- #
697 # Internal helpers. #
698 # ----------------- #
701 # _BOOST_PTHREAD_FLAG()
702 # ---------------------
703 # Internal helper for BOOST_THREADS. Based on ACX_PTHREAD:
704 # http://autoconf-archive.cryp.to/acx_pthread.html
705 AC_DEFUN([_BOOST_PTHREAD_FLAG],
706 [AC_REQUIRE([AC_PROG_CXX])dnl
707 AC_REQUIRE([AC_CANONICAL_HOST])dnl
708 AC_LANG_PUSH([C++])dnl
709 AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag],
710 [ boost_cv_pthread_flag=
711 # The ordering *is* (sometimes) important. Some notes on the
712 # individual items follow:
713 # (none): in case threads are in libc; should be tried before -Kthread and
714 # other compiler flags to prevent continual compiler warnings
715 # -lpthreads: AIX (must check this before -lpthread)
716 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
717 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
718 # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
719 # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
720 # -pthreads: Solaris/GCC
721 # -mthreads: MinGW32/GCC, Lynx/GCC
722 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
723 # doesn't hurt to check since this sometimes defines pthreads too;
724 # also defines -D_REENTRANT)
725 # ... -mt is also the pthreads flag for HP/aCC
726 # -lpthread: GNU Linux, etc.
727 # --thread-safe: KAI C++
730 # On Solaris (at least, for some versions), libc contains stubbed
731 # (non-functional) versions of the pthreads routines, so link-based
732 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
733 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
734 # a function called by this macro, so we could check for that, but
735 # who knows whether they'll stub that too in a future libc.) So,
736 # we'll just look for -pthreads and -lpthread first:
737 boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #(
739 boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \
740 -pthreads -mthreads -lpthread --thread-safe -mt";;
742 # Generate the test file.
743 AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <pthread.h>],
744 [pthread_t th; pthread_join(th, 0);
745 pthread_attr_init(0); pthread_cleanup_push(0, 0);
746 pthread_create(0,0,0,0); pthread_cleanup_pop(0);])])
747 for boost_pthread_flag in '' $boost_pthread_flags; do
748 boost_pthread_ok=false
749 dnl Re-use the test file already generated.
750 boost_pthreads__save_LIBS=$LIBS
751 LIBS="$LIBS $boost_pthread_flag"
753 [if grep ".*$boost_pthread_flag" conftest.err; then
754 echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD
756 boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag
758 LIBS=$boost_pthreads__save_LIBS
759 $boost_pthread_ok && break
762 AC_LANG_POP([C++])dnl
763 ])# _BOOST_PTHREAD_FLAG
766 # _BOOST_gcc_test(MAJOR, MINOR)
767 # -----------------------------
768 # Internal helper for _BOOST_FIND_COMPILER_TAG.
769 m4_define([_BOOST_gcc_test],
770 ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl
773 # _BOOST_FIND_COMPILER_TAG()
774 # --------------------------
775 # Internal. When Boost is installed without --layout=system, each library
776 # filename will hold a suffix that encodes the compiler used during the
777 # build. The Boost build system seems to call this a `tag'.
778 AC_DEFUN([_BOOST_FIND_COMPILER_TAG],
779 [AC_REQUIRE([AC_PROG_CXX])dnl
780 AC_CACHE_CHECK([for the toolset name used by Boost for $CXX], [boost_cv_lib_tag],
781 [AC_LANG_PUSH([C++])dnl
782 boost_cv_lib_tag=unknown
783 # The following tests are mostly inspired by boost/config/auto_link.hpp
784 # The list is sorted to most recent/common to oldest compiler (in order
785 # to increase the likelihood of finding the right compiler with the
786 # least number of compilation attempt).
787 # Beware that some tests are sensible to the order (for instance, we must
788 # look for MinGW before looking for GCC3).
789 # I used one compilation test per compiler with a #error to recognize
790 # each compiler so that it works even when cross-compiling (let me know
791 # if you know a better approach).
792 # Known missing tags (known from Boost's tools/build/v2/tools/common.jam):
793 # como, edg, kcc, bck, mp, sw, tru, xlc
794 # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines
795 # the same defines as GCC's).
796 # TODO: Move the test on GCC 4.4 up once it's released.
798 _BOOST_gcc_test(4, 3) \
799 _BOOST_gcc_test(4, 2) \
800 _BOOST_gcc_test(4, 1) \
801 _BOOST_gcc_test(4, 0) \
802 "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \
803 && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
804 || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \
805 _BOOST_gcc_test(3, 4) \
806 _BOOST_gcc_test(3, 3) \
807 "defined _MSC_VER && _MSC_VER >= 1400 @ vc80" \
808 _BOOST_gcc_test(3, 2) \
809 "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \
810 _BOOST_gcc_test(3, 1) \
811 _BOOST_gcc_test(3, 0) \
812 "defined __BORLANDC__ @ bcb" \
813 "defined __ICC && (defined __unix || defined __unix__) @ il" \
814 "defined __ICL @ iw" \
815 "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \
816 _BOOST_gcc_test(4, 4) \
817 _BOOST_gcc_test(2, 95) \
818 "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \
819 "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \
820 "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \
821 "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8"
823 boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '`
824 boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'`
825 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
829 # error $boost_tag_test
831 ]])], [boost_cv_lib_tag=$boost_tag; break], [])
833 AC_LANG_POP([C++])dnl
834 case $boost_cv_lib_tag in #(
835 # Some newer (>= 1.35?) versions of Boost seem to only use "gcc" as opposed
836 # to "gcc41" for instance.
837 *-gcc | *'-gcc ') :;; #( Don't re-add -gcc: it's already in there.
839 # We can specify multiple tags in this variable because it's used by
840 # BOOST_FIND_LIB that does a `for tag in -$boost_cv_lib_tag' ...
841 boost_cv_lib_tag="$boost_cv_lib_tag -gcc"
844 AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]])
848 ])dnl end of AC_CACHE_CHECK
849 ])# _BOOST_FIND_COMPILER_TAG
852 # _BOOST_GUESS_WHETHER_TO_USE_MT()
853 # --------------------------------
854 # Compile a small test to try to guess whether we should favor MT (Multi
855 # Thread) flavors of Boost. Sets boost_guess_use_mt accordingly.
856 AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT],
857 [# Check whether we do better use `mt' even though we weren't ask to.
858 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
859 #if defined _REENTRANT || defined _MT || defined __MT__
862 # error MT not needed
864 ]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false])
867 # _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
868 # -------------------------------------------------------------------
869 # Fork of _AC_LINK_IFELSE that preserves conftest.o across calls. Fragile,
870 # will break when Autoconf changes its internals. Requires that you manually
871 # rm -f conftest.$ac_objext in between to really different tests, otherwise
872 # you will try to link a conftest.o left behind by a previous test.
873 # Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this
875 m4_define([_BOOST_AC_LINK_IFELSE],
876 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
877 rm -f conftest$ac_exeext
878 boost_ac_ext_save=$ac_ext
880 # If we already have a .o, re-use it. We change $ac_ext so that $ac_link
881 # tries to link the existing object file instead of compiling from source.
882 test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false &&
883 _AS_ECHO_LOG([re-using the existing conftest.$ac_objext])
884 AS_IF([_AC_DO_STDERR($ac_link) && {
885 test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
886 test ! -s conftest.err
887 } && test -s conftest$ac_exeext && {
888 test "$cross_compiling" = yes ||
889 $as_executable_p conftest$ac_exeext
890 dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough.
893 [if $boost_use_source; then
897 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
898 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
899 dnl as it would interfere with the next link command.
900 rm -f core conftest.err conftest_ipa8_conftest.oo \
901 conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl
902 ])# _BOOST_AC_LINK_IFELSE