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 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Original sources can be found at http://repo.or.cz/w/boost.m4.git
19 # You can fetch the latest version of the script by doing:
20 # wget 'http://repo.or.cz/w/boost.m4.git?a=blob_plain;f=build-aux/boost.m4;hb=HEAD' -O boost.m4
26 # This file provides several macros to use the various Boost libraries.
27 # The first macro is BOOST_REQUIRE. It will simply check if it's possible to
28 # find the Boost headers of a given (optional) minimum version and it will
29 # define BOOST_CPPFLAGS accordingly. It will add an option --with-boost to
30 # your configure so that users can specify non standard locations.
31 # For more README and documentation, go to http://repo.or.cz/w/boost.m4.git
32 # Note: THESE MACRO ASSUME THAT YOU USE LIBTOOL. If you don't, don't worry,
33 # simply read the README, it will show you what to do step by step.
35 m4_pattern_forbid([^_?BOOST_])
37 # BOOST_REQUIRE([VERSION])
38 # ------------------------
39 # Look for Boost. If version is given, it must either be a literal of the form
40 # "X.Y.Z" where X, Y and Z are integers (the ".Z" part being optional) or a
42 # Defines the value BOOST_CPPFLAGS. This macro only checks for headers with
43 # the required version, it does not check for any of the Boost libraries.
44 # FIXME: Add a 2nd optional argument so that it's not fatal if Boost isn't found
45 # and add an AC_DEFINE to tell whether HAVE_BOOST.
46 AC_DEFUN([BOOST_REQUIRE],
47 [dnl First find out what kind of argument we have.
48 dnl If we have an empty argument, there is no constraint on the version of
49 dnl Boost to use. If it's a literal version number, we can split it in M4 (so
50 dnl the resulting configure script will be smaller/faster). Otherwise we do
51 dnl the splitting at runtime.
53 [^ *$], [m4_pushdef([BOOST_VERSION_REQ], [])dnl
56 boost_version_subminor=0
58 [^[0-9]+\([-._][0-9]+\)*$],
59 [m4_pushdef([BOOST_VERSION_REQ], [ version >= $1])dnl
60 boost_version_major=m4_bregexp([$1], [^\([0-9]+\)], [\1])
61 boost_version_minor=m4_bregexp([$1], [^[0-9]+[-._]\([0-9]+\)], [\1])
62 boost_version_subminor=m4_bregexp([$1], [^[0-9]+[-._][0-9]+[-._]\([0-9]+\)], [\1])
65 [m4_pushdef([BOOST_VERSION_REQ], [])dnl
66 boost_version_major=`expr "X$1" : 'X\([[^-._]]*\)'`
67 boost_version_minor=`expr "X$1" : 'X[[0-9]]*[[-._]]\([[^-._]]*\)'`
68 boost_version_subminor=`expr "X$1" : 'X[[0-9]]*[[-._]][[0-9]]*[[-._]]\([[0-9]]*\)'`
69 case $boost_version_major:$boost_version_minor in #(
70 *: | :* | *[[^0-9]]*:* | *:*[[^0-9]]*)
71 AC_MSG_ERROR([[Invalid argument for REQUIRE_BOOST: `$1']])
75 [m4_fatal(Invalid argument: `$1')]
78 [AS_HELP_STRING([--with-boost=DIR],
79 [prefix of Boost]BOOST_VERSION_REQ[ @<:@guess@:>@])])dnl
80 AC_SUBST([DISTCHECK_CONFIGURE_FLAGS],
81 ["$DISTCHECK_CONFIGURE_FLAGS '--with-boost=$with_boost'"])
82 AC_CACHE_CHECK([for Boost headers[]BOOST_VERSION_REQ],
85 AC_LANG_PUSH([C++])dnl
87 test x"$boost_version_subminor" != x \
88 && boost_subminor_chk="|| (B_V_MAJ == $boost_version_major \
89 && B_V_MIN == $boost_version_minor \
90 && B_V_SUB < $boost_version_subminor)"
91 for boost_inc in "$with_boost/include" '' \
92 /opt/local/include /usr/local/include /opt/include /usr/include \
93 "$with_boost" C:/Boost/include
95 test -e "$boost_inc" || continue
96 # Ensure that version.hpp exists: we're going to read it. Moreover,
97 # Boost could be reachable thanks to the default include path so we can
98 # mistakenly accept a wrong include path without this check.
99 test -e "$boost_inc/boost/version.hpp" || continue
100 boost_save_CPPFLAGS=$CPPFLAGS
101 test x"$boost_inc" != x && CPPFLAGS="$CPPFLAGS -I$boost_inc"
102 m4_pattern_allow([^BOOST_VERSION$])dnl
103 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <boost/version.hpp>
104 #ifndef BOOST_VERSION
105 # error BOOST_VERSION is not defined
107 #define B_V_MAJ (BOOST_VERSION / 100000)
108 #define B_V_MIN (BOOST_VERSION / 100 % 1000)
109 #define B_V_SUB (BOOST_VERSION % 100)
110 #if (B_V_MAJ < $boost_version_major) \
111 || (B_V_MAJ == $boost_version_major \
112 && B_V_MIN < $boost_version_minor) $boost_subminor_chk
113 # error Boost headers version < $1
115 ]])], [boost_cv_inc_path=yes], [boost_cv_version=no])
116 CPPFLAGS=$boost_save_CPPFLAGS
117 if test x"$boost_cv_inc_path" = xyes; then
118 if test x"$boost_inc" != x; then
119 boost_cv_inc_path=$boost_inc
124 AC_LANG_POP([C++])dnl
126 case $boost_cv_inc_path in #(
128 AC_MSG_ERROR([Could not find Boost headers[]BOOST_VERSION_REQ])
134 BOOST_CPPFLAGS="-I$boost_cv_inc_path"
137 AC_SUBST([BOOST_CPPFLAGS])dnl
138 AC_CACHE_CHECK([for Boost's header version],
139 [boost_cv_lib_version],
140 [m4_pattern_allow([^BOOST_LIB_VERSION$])dnl
141 boost_cv_lib_version=unknown
142 boost_sed_version='/^.*BOOST_LIB_VERSION.*"\([[^"]]*\)".*$/!d;s//\1/'
143 boost_version_hpp="$boost_inc/boost/version.hpp"
144 test -e "$boost_version_hpp" \
145 && boost_cv_lib_version=`sed "$boost_sed_version" "$boost_version_hpp"`
147 m4_popdef([BOOST_VERSION_REQ])dnl
151 # BOOST_FIND_HEADER([HEADER-NAME], [ACTION-IF-NOT-FOUND], [ACTION-IF-FOUND])
152 # --------------------------------------------------------------------------
153 # Wrapper around AC_CHECK_HEADER for Boost headers. Useful to check for
154 # some parts of the Boost library which are only made of headers and don't
155 # require linking (such as Boost.Foreach).
157 # Default ACTION-IF-NOT-FOUND: Fail with a fatal error.
159 # Default ACTION-IF-FOUND: define the preprocessor symbol HAVE_<HEADER-NAME> in
160 # case of success # (where HEADER-NAME is written LIKE_THIS, e.g.,
161 # HAVE_BOOST_FOREACH_HPP).
162 AC_DEFUN([BOOST_FIND_HEADER],
163 [AC_REQUIRE([BOOST_REQUIRE])dnl
164 AC_LANG_PUSH([C++])dnl
165 boost_save_CPPFLAGS=$CPPFLAGS
166 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
167 AC_CHECK_HEADER([$1],
168 [m4_default([$3], [AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1],
169 [Define to 1 if you have <$1>])])],
170 [m4_default([$2], [AC_MSG_ERROR([cannot find $1])])])
171 CPPFLAGS=$boost_save_CPPFLAGS
172 AC_LANG_POP([C++])dnl
173 ])# BOOST_FIND_HEADER
176 # BOOST_FIND_LIB([LIB-NAME], [PREFERRED-RT-OPT], [HEADER-NAME], [CXX-TEST])
177 # -------------------------------------------------------------------------
178 # Look for the Boost library LIB-NAME (e.g., LIB-NAME = `thread', for
179 # libboost_thread). Check that HEADER-NAME works and check that
180 # libboost_LIB-NAME can link with the code CXX-TEST.
182 # Invokes BOOST_FIND_HEADER([HEADER-NAME]) (see above).
184 # Boost libraries typically come compiled with several flavors (with different
185 # runtime options) so PREFERRED-RT-OPT is the preferred suffix. A suffix is one
186 # or more of the following letters: sgdpn (in that order). s = static
187 # runtime, d = debug build, g = debug/diagnostic runtime, p = STLPort build,
188 # n = (unsure) STLPort build without iostreams from STLPort (it looks like `n'
189 # must always be used along with `p'). Additionally, PREFERRED-RT-OPT can
190 # start with `mt-' to indicate that there is a preference for multi-thread
191 # builds. Some sample values for PREFERRED-RT-OPT: (nothing), mt, d, mt-d, gdp
192 # ... If you want to make sure you have a specific version of Boost
193 # (eg, >= 1.33) you *must* invoke BOOST_REQUIRE before this macro.
194 AC_DEFUN([BOOST_FIND_LIB],
195 [AC_REQUIRE([_BOOST_FIND_COMPILER_TAG])dnl
196 AC_REQUIRE([BOOST_REQUIRE])dnl
197 AC_REQUIRE([_BOOST_GUESS_WHETHER_TO_USE_MT])dnl
198 AC_LANG_PUSH([C++])dnl
199 AS_VAR_PUSHDEF([Boost_lib], [boost_cv_lib_$1])dnl
200 AS_VAR_PUSHDEF([Boost_lib_LDFLAGS], [boost_cv_lib_$1_LDFLAGS])dnl
201 AS_VAR_PUSHDEF([Boost_lib_LIBS], [boost_cv_lib_$1_LIBS])dnl
202 BOOST_FIND_HEADER([$3])
203 boost_save_CPPFLAGS=$CPPFLAGS
204 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
205 # Now let's try to find the library. The algorithm is as follows: first look
206 # for a given library name according to the user's PREFERRED-RT-OPT. For each
207 # library name, we prefer to use the ones that carry the tag (toolset name).
208 # Each library is searched through the various standard paths were Boost is
209 # usually installed. If we can't find the standard variants, we try to
210 # enforce -mt (for instance on MacOSX, libboost_threads.dylib doesn't exist
211 # but there's -obviously- libboost_threads-mt.dylib).
212 AC_CACHE_CHECK([for the Boost $1 library], [Boost_lib],
215 mt | mt-) boost_mt=-mt; boost_rtopt=;; #(
216 mt* | mt-*) boost_mt=-mt; boost_rtopt=`expr "X$2" : 'Xmt-*\(.*\)'`;; #(
217 *) boost_mt=; boost_rtopt=$2;;
219 # If the PREFERRED-RT-OPT are not empty, prepend a `-'.
220 case $boost_rtopt in #(
221 *[[a-z0-9A-Z]]*) boost_rtopt="-$boost_rtopt";;
223 $boost_guess_use_mt && boost_mt=-mt
224 # Look for the abs path the static archive.
225 # $libext is computed by Libtool but let's make sure it's non empty.
227 AC_MSG_ERROR([the libext variable is empty, did you invoke Libtool?])
228 boost_save_ac_objext=$ac_objext
229 # Generate the test file.
230 AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <$3>], [$4])])
231 dnl Optimization hacks: compiling C++ is slow, especially with Boost. What
232 dnl we're trying to do here is guess the right combination of link flags
233 dnl (LIBS / LDFLAGS) to use a given library. This can take several
234 dnl iterations before it succeeds and is thus *very* slow. So what we do
235 dnl instead is that we compile the code first (and thus get an object file,
236 dnl typically conftest.o). Then we try various combinations of link flags
237 dnl until we succeed to link conftest.o in an executable. The problem is
238 dnl that the various TRY_LINK / COMPILE_IFELSE macros of Autoconf always
239 dnl remove all the temporary files including conftest.o. So the trick here
240 dnl is to temporarily change the value of ac_objext so that conftest.o is
241 dnl preserved accross tests. This is obviously fragile and I will burn in
242 dnl hell for not respecting Autoconf's documented interfaces, but in the
243 dnl mean time, it optimizes the macro by a factor of 5 to 30.
244 dnl Another small optimization: the first argument of AC_COMPILE_IFELSE left
245 dnl empty because the test file is generated only once above (before we
246 dnl start the for loops).
247 AC_COMPILE_IFELSE([],
248 [ac_objext=do_not_rm_me_plz],
249 [AC_MSG_ERROR([Cannot compile a test that uses Boost $1])])
250 ac_objext=$boost_save_ac_objext
252 # Don't bother to ident the 6 nested for loops, only the 2 innermost ones
254 for boost_tag_ in -$boost_cv_lib_tag ''; do
255 for boost_ver_ in -$boost_cv_lib_version ''; do
256 for boost_mt_ in $boost_mt -mt ''; do
257 for boost_rtopt_ in $boost_rtopt '' -d; do
259 boost_$1$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ \
260 boost_$1$boost_tag_$boost_mt_$boost_ver_ \
261 boost_$1$boost_tag_$boost_rtopt_$boost_ver_ \
262 boost_$1$boost_tag_$boost_mt_ \
263 boost_$1$boost_tag_$boost_ver_
265 # Avoid testing twice the same lib
266 case $boost_failed_libs in #(
267 *@$boost_lib@*) continue;;
269 # If with_boost is empty, we'll search in /lib first, which is not quite
270 # right so instead we'll try to a location based on where the headers are.
271 boost_tmp_lib=$with_boost
272 test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include}
273 for boost_ldpath in "$boost_tmp_lib/lib" '' \
274 /opt/local/lib /usr/local/lib /opt/lib /usr/lib \
275 "$with_boost" C:/Boost/lib /lib /usr/lib64 /lib64
277 test -e "$boost_ldpath" || continue
278 boost_save_LDFLAGS=$LDFLAGS
279 # Are we looking for a static library?
280 case $boost_ldpath:$boost_rtopt_ in #(
281 *?*:*s*) # Yes (Non empty boost_ldpath + s in rt opt)
282 Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext";; #(
283 *) # No: use -lboost_foo to find the shared library.
284 Boost_lib_LIBS="-l$boost_lib";;
286 boost_save_LIBS=$LIBS
287 LIBS="$Boost_lib_LIBS $LIBS"
288 test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"
289 dnl First argument of AC_LINK_IFELSE left empty because the test file is
290 dnl generated only once above (before we start the for loops).
291 _BOOST_AC_LINK_IFELSE([],
292 [Boost_lib=yes], [Boost_lib=no])
293 ac_objext=$boost_save_ac_objext
294 LDFLAGS=$boost_save_LDFLAGS
295 LIBS=$boost_save_LIBS
296 if test x"$Boost_lib" = xyes; then
297 Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath"
300 boost_failed_libs="$boost_failed_libs@$boost_lib@"
308 rm -f conftest.$ac_objext
310 case $Boost_lib in #(
311 no) AC_MSG_ERROR([Could not find the flags to link with Boost $1])
314 AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS])
315 AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS])
316 CPPFLAGS=$boost_save_CPPFLAGS
317 AS_VAR_POPDEF([Boost_lib])dnl
318 AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl
319 AS_VAR_POPDEF([Boost_lib_LIBS])dnl
320 AC_LANG_POP([C++])dnl
324 # --------------------------------------- #
325 # Checks for the various Boost libraries. #
326 # --------------------------------------- #
328 # List of boost libraries: http://www.boost.org/libs/libraries.htm
329 # The page http://beta.boost.org/doc/libs is useful: it gives the first release
330 # version of each library (among other things).
335 # Look for Boost.Bind
336 AC_DEFUN([BOOST_BIND],
337 [BOOST_FIND_HEADER([boost/bind.hpp])])
342 # Look for Boost.Conversion (cast / lexical_cast)
343 AC_DEFUN([BOOST_CONVERSION],
344 [BOOST_FIND_HEADER([boost/cast.hpp])
345 BOOST_FIND_HEADER([boost/lexical_cast.hpp])
349 # BOOST_DATE_TIME([PREFERRED-RT-OPT])
350 # -----------------------------------
351 # Look for Boost.Date_Time. For the documentation of PREFERRED-RT-OPT, see the
352 # documentation of BOOST_FIND_LIB above.
353 AC_DEFUN([BOOST_DATE_TIME],
354 [BOOST_FIND_LIB([date_time], [$1],
355 [boost/date_time/posix_time/posix_time.hpp],
356 [boost::posix_time::ptime t;])
360 # BOOST_FILESYSTEM([PREFERRED-RT-OPT])
361 # ------------------------------------
362 # Look for Boost.Filesystem. For the documentation of PREFERRED-RT-OPT, see the
363 # documentation of BOOST_FIND_LIB above.
364 # Do not check for boost/filesystem.hpp because this file was introduced in 1.34.
365 AC_DEFUN([BOOST_FILESYSTEM],
366 [BOOST_FIND_LIB([filesystem], [$1],
367 [boost/filesystem/path.hpp], [boost::filesystem::path p;])
373 # Look for Boost.Foreach
374 AC_DEFUN([BOOST_FOREACH],
375 [BOOST_FIND_HEADER([boost/foreach.hpp])])
380 # Look for Boost.Format
381 # Note: we can't check for boost/format/format_fwd.hpp because the header isn't
382 # standalone. It can't be compiled because it triggers the following error:
383 # boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std'
384 # does not name a type
385 AC_DEFUN([BOOST_FORMAT],
386 [BOOST_FIND_HEADER([boost/format.hpp])])
391 # Look for Boost.Function
392 AC_DEFUN([BOOST_FUNCTION],
393 [BOOST_FIND_HEADER([boost/function.hpp])])
396 # BOOST_GRAPH([PREFERRED-RT-OPT])
397 # -------------------------------
398 # Look for Boost.Graphs. For the documentation of PREFERRED-RT-OPT, see the
399 # documentation of BOOST_FIND_LIB above.
400 AC_DEFUN([BOOST_GRAPH],
401 [BOOST_FIND_LIB([graph], [$1],
402 [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;])
406 # BOOST_IOSTREAMS([PREFERRED-RT-OPT])
407 # -------------------------------
408 # Look for Boost.IOStreams. For the documentation of PREFERRED-RT-OPT, see the
409 # documentation of BOOST_FIND_LIB above.
410 AC_DEFUN([BOOST_IOSTREAMS],
411 [BOOST_FIND_LIB([iostreams], [$1],
412 [boost/iostreams/device/file_descriptor.hpp],
413 [boost::iostreams::file_descriptor fd(0); fd.close();])
419 # Look for Boost.Functional/Hash
420 AC_DEFUN([BOOST_HASH],
421 [BOOST_FIND_HEADER([boost/functional/hash.hpp])])
424 # BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT])
425 # -----------------------------------------
426 # Look for Boost.Program_options. For the documentation of PREFERRED-RT-OPT, see
427 # the documentation of BOOST_FIND_LIB above.
428 AC_DEFUN([BOOST_PROGRAM_OPTIONS],
429 [BOOST_FIND_LIB([program_options], [$1],
430 [boost/program_options.hpp],
431 [boost::program_options::options_description d("test");])
432 ])# BOOST_PROGRAM_OPTIONS
438 AC_DEFUN([BOOST_REF],
439 [BOOST_FIND_HEADER([boost/ref.hpp])])
442 # BOOST_REGEX([PREFERRED-RT-OPT])
443 # -------------------------------
444 # Look for Boost.Regex. For the documentation of PREFERRED-RT-OPT, see the
445 # documentation of BOOST_FIND_LIB above.
446 AC_DEFUN([BOOST_REGEX],
447 [BOOST_FIND_LIB([regex], [$1],
449 [boost::regex exp("*"); boost::regex_match("foo", exp);])
453 # BOOST_SIGNALS([PREFERRED-RT-OPT])
454 # ---------------------------------
455 # Look for Boost.Signals. For the documentation of PREFERRED-RT-OPT, see the
456 # documentation of BOOST_FIND_LIB above.
457 AC_DEFUN([BOOST_SIGNALS],
458 [BOOST_FIND_LIB([signals], [$1],
460 [boost::signal<void ()> s;])
466 # Look for Boost.SmartPtr
467 AC_DEFUN([BOOST_SMART_PTR],
468 [BOOST_FIND_HEADER([boost/scoped_ptr.hpp])
469 BOOST_FIND_HEADER([boost/shared_ptr.hpp])
473 # BOOST_STRING_ALGO()
474 # -------------------
475 # Look for Boost.StringAlgo
476 AC_DEFUN([BOOST_STRING_ALGO],
477 [BOOST_FIND_HEADER([boost/algorithm/string.hpp])
481 # BOOST_TEST([PREFERRED-RT-OPT])
482 # ------------------------------
483 # Look for Boost.Test. For the documentation of PREFERRED-RT-OPT, see the
484 # documentation of BOOST_FIND_LIB above.
485 AC_DEFUN([BOOST_TEST],
486 [m4_pattern_allow([^BOOST_CHECK$])dnl
487 BOOST_FIND_LIB([unit_test_framework], [$1],
488 [boost/test/unit_test.hpp], [BOOST_CHECK(2==2);])
492 # BOOST_THREADS([PREFERRED-RT-OPT])
493 # ---------------------------------
494 # Look for Boost.Thread. For the documentation of PREFERRED-RT-OPT, see the
495 # documentation of BOOST_FIND_LIB above.
496 # FIXME: Provide an alias "BOOST_THREAD".
497 AC_DEFUN([BOOST_THREADS],
498 [dnl Having the pthread flag is required at least on GCC3 where
499 dnl boost/thread.hpp would complain if we try to compile without
500 dnl -pthread on GNU/Linux.
501 AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
502 boost_threads_save_LIBS=$LIBS
503 boost_threads_save_CPPFLAGS=$CPPFLAGS
504 LIBS="$LIBS $boost_cv_pthread_flag"
505 # Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
506 # boost/thread.hpp will trigger a #error if -pthread isn't used:
507 # boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
508 # is not turned on. Please set the correct command line options for
509 # threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
510 CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag"
511 BOOST_FIND_LIB([thread], [$1],
512 [boost/thread.hpp], [boost::thread t; boost::mutex m;])
513 BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $boost_cv_pthread_flag"
514 BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag"
515 LIBS=$boost_threads_save_LIBS
516 CPPFLAGS=$boost_threads_save_CPPFLAGS
522 # Look for Boost.Tokenizer
523 AC_DEFUN([BOOST_TOKENIZER],
524 [BOOST_FIND_HEADER([boost/tokenizer.hpp])])
529 # Look for Boost.Tribool
530 AC_DEFUN([BOOST_TRIBOOL],
531 [BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp])
532 BOOST_FIND_HEADER([boost/logic/tribool.hpp])
538 # Look for Boost.Tuple
539 AC_DEFUN([BOOST_TUPLE],
540 [BOOST_FIND_HEADER([boost/tuple/tuple.hpp])])
545 # Look for Boost.Utility (noncopyable, result_of, base-from-member idiom,
547 AC_DEFUN([BOOST_UTILITY],
548 [BOOST_FIND_HEADER([boost/utility.hpp])])
553 # Look for Boost.Variant.
554 AC_DEFUN([BOOST_VARIANT],
555 [BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp])
556 BOOST_FIND_HEADER([boost/variant.hpp])])
559 # BOOST_WAVE([PREFERRED-RT-OPT])
560 # ------------------------------
561 # Look for Boost.Wave. For the documentation of PREFERRED-RT-OPT, see the
562 # documentation of BOOST_FIND_LIB above.
563 AC_DEFUN([BOOST_WAVE],
564 [BOOST_FIND_LIB([wave], [$1],
566 [boost::wave::token_id id; get_token_name(id);])])
569 # ----------------- #
570 # Internal helpers. #
571 # ----------------- #
574 # _BOOST_PTHREAD_FLAG()
575 # ---------------------
576 # Internal helper for BOOST_THREADS. Based on ACX_PTHREAD:
577 # http://autoconf-archive.cryp.to/acx_pthread.html
578 AC_DEFUN([_BOOST_PTHREAD_FLAG],
579 [AC_REQUIRE([AC_PROG_CXX])dnl
580 AC_REQUIRE([AC_CANONICAL_HOST])dnl
581 AC_LANG_PUSH([C++])dnl
582 AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag],
583 [ boost_cv_pthread_flag=
584 # The ordering *is* (sometimes) important. Some notes on the
585 # individual items follow:
586 # (none): in case threads are in libc; should be tried before -Kthread and
587 # other compiler flags to prevent continual compiler warnings
588 # -lpthreads: AIX (must check this before -lpthread)
589 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
590 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
591 # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
592 # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
593 # -pthreads: Solaris/GCC
594 # -mthreads: MinGW32/GCC, Lynx/GCC
595 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
596 # doesn't hurt to check since this sometimes defines pthreads too;
597 # also defines -D_REENTRANT)
598 # ... -mt is also the pthreads flag for HP/aCC
599 # -lpthread: GNU Linux, etc.
600 # --thread-safe: KAI C++
603 # On Solaris (at least, for some versions), libc contains stubbed
604 # (non-functional) versions of the pthreads routines, so link-based
605 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
606 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
607 # a function called by this macro, so we could check for that, but
608 # who knows whether they'll stub that too in a future libc.) So,
609 # we'll just look for -pthreads and -lpthread first:
610 boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #(
612 boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \
613 -pthreads -mthreads -lpthread --thread-safe -mt";;
615 # Generate the test file.
616 AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <pthread.h>],
617 [pthread_t th; pthread_join(th, 0);
618 pthread_attr_init(0); pthread_cleanup_push(0, 0);
619 pthread_create(0,0,0,0); pthread_cleanup_pop(0);])])
620 for boost_pthread_flag in '' $boost_pthread_flags; do
621 boost_pthread_ok=false
622 dnl Re-use the test file already generated.
623 boost_pthreads__save_LIBS=$LIBS
624 LIBS="$LIBS $boost_pthread_flag"
626 [if grep ".*$boost_pthread_flag" conftest.err; then
627 echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD
629 boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag
631 LIBS=$boost_pthreads__save_LIBS
632 $boost_pthread_ok && break
635 AC_LANG_POP([C++])dnl
636 ])# _BOOST_PTHREAD_FLAG
639 # _BOOST_gcc_test(MAJOR, MINOR)
640 # -----------------------------
641 # Internal helper for _BOOST_FIND_COMPILER_TAG.
642 m4_define([_BOOST_gcc_test],
643 ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl
646 # _BOOST_FIND_COMPILER_TAG()
647 # --------------------------
648 # Internal. When Boost is installed without --layout=system, each library
649 # filename will hold a suffix that encodes the compiler used during the
650 # build. The Boost build system seems to call this a `tag'.
651 AC_DEFUN([_BOOST_FIND_COMPILER_TAG],
652 [AC_REQUIRE([AC_PROG_CXX])dnl
653 AC_CACHE_CHECK([for the toolset name used by Boost for $CXX], [boost_cv_lib_tag],
654 [AC_LANG_PUSH([C++])dnl
655 boost_cv_lib_tag=unknown
656 # The following tests are mostly inspired by boost/config/auto_link.hpp
657 # The list is sorted to most recent/common to oldest compiler (in order
658 # to increase the likelihood of finding the right compiler with the
659 # least number of compilation attempt).
660 # Beware that some tests are sensible to the order (for instance, we must
661 # look for MinGW before looking for GCC3).
662 # I used one compilation test per compiler with a #error to recognize
663 # each compiler so that it works even when cross-compiling (let me know
664 # if you know a better approach).
665 # Known missing tags (known from Boost's tools/build/v2/tools/common.jam):
666 # como, edg, kcc, bck, mp, sw, tru, xlc
667 # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines
668 # the same defines as GCC's).
669 # TODO: Move the test on GCC 4.3 up once it's released.
671 _BOOST_gcc_test(4, 2) \
672 _BOOST_gcc_test(4, 1) \
673 _BOOST_gcc_test(4, 0) \
674 "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \
675 && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
676 || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \
677 _BOOST_gcc_test(3, 4) \
678 _BOOST_gcc_test(3, 3) \
679 "defined _MSC_VER && _MSC_VER >= 1400 @ vc80" \
680 _BOOST_gcc_test(3, 2) \
681 "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \
682 _BOOST_gcc_test(3, 1) \
683 _BOOST_gcc_test(3, 0) \
684 "defined __BORLANDC__ @ bcb" \
685 "defined __ICC && (defined __unix || defined __unix__) @ il" \
686 "defined __ICL @ iw" \
687 "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \
688 _BOOST_gcc_test(4, 3) \
689 _BOOST_gcc_test(2, 95) \
690 "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \
691 "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \
692 "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \
693 "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8"
695 boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '`
696 boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'`
697 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
701 # error $boost_tag_test
703 ]])], [boost_cv_lib_tag=$boost_tag; break], [])
705 AC_LANG_POP([C++])dnl
707 if test x"$boost_cv_lib_tag" = xunknown; then
708 AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]])
711 ])# _BOOST_FIND_COMPILER_TAG
714 # _BOOST_GUESS_WHETHER_TO_USE_MT()
715 # --------------------------------
716 # Compile a small test to try to guess whether we should favor MT (Multi
717 # Thread) flavors of Boost. Sets boost_guess_use_mt accordingly.
718 AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT],
719 [# Check whether we do better use `mt' even though we weren't ask to.
720 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
721 #if defined _REENTRANT || defined _MT || defined __MT__
724 # error MT not needed
726 ]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false])
729 # _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
730 # -------------------------------------------------------------------
731 # Fork of _AC_LINK_IFELSE that preserves conftest.o across calls. Fragile,
732 # will break when Autoconf changes its internals. Requires that you manually
733 # rm -f conftest.$ac_objext in between to really different tests, otherwise
734 # you will try to link a conftest.o left behind by a previous test.
735 # Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this
737 m4_define([_BOOST_AC_LINK_IFELSE],
738 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
739 rm -f conftest$ac_exeext
740 boost_ac_ext_save=$ac_ext
742 # If we already have a .o, re-use it. We change $ac_ext so that $ac_link
743 # tries to link the existing object file instead of compiling from source.
744 test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false &&
745 _AS_ECHO_LOG([re-using the existing conftest.$ac_objext])
746 AS_IF([_AC_DO_STDERR($ac_link) && {
747 test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
748 test ! -s conftest.err
749 } && test -s conftest$ac_exeext && {
750 test "$cross_compiling" = yes ||
751 $as_executable_p conftest$ac_exeext
752 dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough.
755 [if $boost_use_source; then
759 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
760 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
761 dnl as it would interfere with the next link command.
762 rm -f core conftest.err conftest_ipa8_conftest.oo \
763 conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl
764 ])# _BOOST_AC_LINK_IFELSE