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 MACROS 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_dir in "$with_boost/include" '' \
92 /opt/local/include /usr/local/include /opt/include /usr/include \
93 "$with_boost" C:/Boost/include
95 # Without --layout=system, Boost (or at least some versions) installs
96 # itself in <prefix>/include/boost-<version>. This inner loop helps to
97 # find headers in such directories.
98 # I didn't indent this loop on purpose (to avoid over-indented code)
99 for boost_inc in "$boost_dir" "$boost_dir"/boost-*
101 # $boost_inc can often be a symlink, so keep -e here.
102 test -e "$boost_inc" || continue
103 # Ensure that version.hpp exists: we're going to read it. Moreover,
104 # Boost could be reachable thanks to the default include path so we can
105 # mistakenly accept a wrong include path without this check.
106 test -e "$boost_inc/boost/version.hpp" || continue
107 boost_save_CPPFLAGS=$CPPFLAGS
108 test x"$boost_inc" != x && CPPFLAGS="$CPPFLAGS -I$boost_inc"
109 m4_pattern_allow([^BOOST_VERSION$])dnl
110 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <boost/version.hpp>
111 #ifndef BOOST_VERSION
112 # error BOOST_VERSION is not defined
114 #define B_V_MAJ (BOOST_VERSION / 100000)
115 #define B_V_MIN (BOOST_VERSION / 100 % 1000)
116 #define B_V_SUB (BOOST_VERSION % 100)
117 #if (B_V_MAJ < $boost_version_major) \
118 || (B_V_MAJ == $boost_version_major \
119 && B_V_MIN < $boost_version_minor) $boost_subminor_chk
120 # error Boost headers version < $1
122 ]])], [boost_cv_inc_path=yes], [boost_cv_version=no])
123 CPPFLAGS=$boost_save_CPPFLAGS
124 if test x"$boost_cv_inc_path" = xyes; then
125 if test x"$boost_inc" != x; then
126 boost_cv_inc_path=$boost_inc
132 AC_LANG_POP([C++])dnl
134 case $boost_cv_inc_path in #(
136 AC_MSG_ERROR([Could not find Boost headers[]BOOST_VERSION_REQ])
142 BOOST_CPPFLAGS="-I$boost_cv_inc_path"
145 AC_SUBST([BOOST_CPPFLAGS])dnl
146 AC_CACHE_CHECK([for Boost's header version],
147 [boost_cv_lib_version],
148 [m4_pattern_allow([^BOOST_LIB_VERSION$])dnl
149 boost_cv_lib_version=unknown
150 boost_sed_version='/^.*BOOST_LIB_VERSION.*"\([[^"]]*\)".*$/!d;s//\1/'
151 boost_version_hpp="$boost_inc/boost/version.hpp"
152 test -e "$boost_version_hpp" \
153 && boost_cv_lib_version=`sed "$boost_sed_version" "$boost_version_hpp"`
155 m4_popdef([BOOST_VERSION_REQ])dnl
159 # BOOST_FIND_HEADER([HEADER-NAME], [ACTION-IF-NOT-FOUND], [ACTION-IF-FOUND])
160 # --------------------------------------------------------------------------
161 # Wrapper around AC_CHECK_HEADER for Boost headers. Useful to check for
162 # some parts of the Boost library which are only made of headers and don't
163 # require linking (such as Boost.Foreach).
165 # Default ACTION-IF-NOT-FOUND: Fail with a fatal error.
167 # Default ACTION-IF-FOUND: define the preprocessor symbol HAVE_<HEADER-NAME> in
168 # case of success # (where HEADER-NAME is written LIKE_THIS, e.g.,
169 # HAVE_BOOST_FOREACH_HPP).
170 AC_DEFUN([BOOST_FIND_HEADER],
171 [AC_REQUIRE([BOOST_REQUIRE])dnl
172 AC_LANG_PUSH([C++])dnl
173 boost_save_CPPFLAGS=$CPPFLAGS
174 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
175 AC_CHECK_HEADER([$1],
176 [m4_default([$3], [AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1],
177 [Define to 1 if you have <$1>])])],
178 [m4_default([$2], [AC_MSG_ERROR([cannot find $1])])])
179 CPPFLAGS=$boost_save_CPPFLAGS
180 AC_LANG_POP([C++])dnl
181 ])# BOOST_FIND_HEADER
184 # BOOST_FIND_LIB([LIB-NAME], [PREFERRED-RT-OPT], [HEADER-NAME], [CXX-TEST],
186 # -------------------------------------------------------------------------
187 # Look for the Boost library LIB-NAME (e.g., LIB-NAME = `thread', for
188 # libboost_thread). Check that HEADER-NAME works and check that
189 # libboost_LIB-NAME can link with the code CXX-TEST. The optional argument
190 # CXX-PROLOGUE can be used to include some C++ code before the `main'
193 # Invokes BOOST_FIND_HEADER([HEADER-NAME]) (see above).
195 # Boost libraries typically come compiled with several flavors (with different
196 # runtime options) so PREFERRED-RT-OPT is the preferred suffix. A suffix is one
197 # or more of the following letters: sgdpn (in that order). s = static
198 # runtime, d = debug build, g = debug/diagnostic runtime, p = STLPort build,
199 # n = (unsure) STLPort build without iostreams from STLPort (it looks like `n'
200 # must always be used along with `p'). Additionally, PREFERRED-RT-OPT can
201 # start with `mt-' to indicate that there is a preference for multi-thread
202 # builds. Some sample values for PREFERRED-RT-OPT: (nothing), mt, d, mt-d, gdp
203 # ... If you want to make sure you have a specific version of Boost
204 # (eg, >= 1.33) you *must* invoke BOOST_REQUIRE before this macro.
205 AC_DEFUN([BOOST_FIND_LIB],
206 [AC_REQUIRE([_BOOST_FIND_COMPILER_TAG])dnl
207 AC_REQUIRE([BOOST_REQUIRE])dnl
208 AC_REQUIRE([_BOOST_GUESS_WHETHER_TO_USE_MT])dnl
209 AC_LANG_PUSH([C++])dnl
210 AS_VAR_PUSHDEF([Boost_lib], [boost_cv_lib_$1])dnl
211 AS_VAR_PUSHDEF([Boost_lib_LDFLAGS], [boost_cv_lib_$1_LDFLAGS])dnl
212 AS_VAR_PUSHDEF([Boost_lib_LIBS], [boost_cv_lib_$1_LIBS])dnl
213 BOOST_FIND_HEADER([$3])
214 boost_save_CPPFLAGS=$CPPFLAGS
215 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
216 # Now let's try to find the library. The algorithm is as follows: first look
217 # for a given library name according to the user's PREFERRED-RT-OPT. For each
218 # library name, we prefer to use the ones that carry the tag (toolset name).
219 # Each library is searched through the various standard paths were Boost is
220 # usually installed. If we can't find the standard variants, we try to
221 # enforce -mt (for instance on MacOSX, libboost_threads.dylib doesn't exist
222 # but there's -obviously- libboost_threads-mt.dylib).
223 AC_CACHE_CHECK([for the Boost $1 library], [Boost_lib],
226 mt | mt-) boost_mt=-mt; boost_rtopt=;; #(
227 mt* | mt-*) boost_mt=-mt; boost_rtopt=`expr "X$2" : 'Xmt-*\(.*\)'`;; #(
228 *) boost_mt=; boost_rtopt=$2;;
230 # If the PREFERRED-RT-OPT are not empty, prepend a `-'.
231 case $boost_rtopt in #(
232 *[[a-z0-9A-Z]]*) boost_rtopt="-$boost_rtopt";;
234 $boost_guess_use_mt && boost_mt=-mt
235 # Look for the abs path the static archive.
236 # $libext is computed by Libtool but let's make sure it's non empty.
238 AC_MSG_ERROR([the libext variable is empty, did you invoke Libtool?])
239 boost_save_ac_objext=$ac_objext
240 # Generate the test file.
241 AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <$3>
243 dnl Optimization hacks: compiling C++ is slow, especially with Boost. What
244 dnl we're trying to do here is guess the right combination of link flags
245 dnl (LIBS / LDFLAGS) to use a given library. This can take several
246 dnl iterations before it succeeds and is thus *very* slow. So what we do
247 dnl instead is that we compile the code first (and thus get an object file,
248 dnl typically conftest.o). Then we try various combinations of link flags
249 dnl until we succeed to link conftest.o in an executable. The problem is
250 dnl that the various TRY_LINK / COMPILE_IFELSE macros of Autoconf always
251 dnl remove all the temporary files including conftest.o. So the trick here
252 dnl is to temporarily change the value of ac_objext so that conftest.o is
253 dnl preserved accross tests. This is obviously fragile and I will burn in
254 dnl hell for not respecting Autoconf's documented interfaces, but in the
255 dnl mean time, it optimizes the macro by a factor of 5 to 30.
256 dnl Another small optimization: the first argument of AC_COMPILE_IFELSE left
257 dnl empty because the test file is generated only once above (before we
258 dnl start the for loops).
259 AC_COMPILE_IFELSE([],
260 [ac_objext=do_not_rm_me_plz],
261 [AC_MSG_ERROR([Cannot compile a test that uses Boost $1])])
262 ac_objext=$boost_save_ac_objext
264 # Don't bother to ident the 6 nested for loops, only the 2 innermost ones
266 for boost_tag_ in -$boost_cv_lib_tag ''; do
267 for boost_ver_ in -$boost_cv_lib_version ''; do
268 for boost_mt_ in $boost_mt -mt ''; do
269 for boost_rtopt_ in $boost_rtopt '' -d; do
271 boost_$1$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ \
272 boost_$1$boost_tag_$boost_mt_$boost_ver_ \
273 boost_$1$boost_tag_$boost_rtopt_$boost_ver_ \
274 boost_$1$boost_tag_$boost_mt_ \
275 boost_$1$boost_tag_$boost_ver_
277 # Avoid testing twice the same lib
278 case $boost_failed_libs in #(
279 *@$boost_lib@*) continue;;
281 # If with_boost is empty, we'll search in /lib first, which is not quite
282 # right so instead we'll try to a location based on where the headers are.
283 boost_tmp_lib=$with_boost
284 test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include}
285 for boost_ldpath in "$boost_tmp_lib/lib" '' \
286 /opt/local/lib /usr/local/lib /opt/lib /usr/lib \
287 "$with_boost" C:/Boost/lib /lib /usr/lib64 /lib64
289 test -e "$boost_ldpath" || continue
290 boost_save_LDFLAGS=$LDFLAGS
291 # Are we looking for a static library?
292 case $boost_ldpath:$boost_rtopt_ in #(
293 *?*:*s*) # Yes (Non empty boost_ldpath + s in rt opt)
294 Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext"
295 test -e "$Boost_lib_LIBS" || continue;; #(
296 *) # No: use -lboost_foo to find the shared library.
297 Boost_lib_LIBS="-l$boost_lib";;
299 boost_save_LIBS=$LIBS
300 LIBS="$Boost_lib_LIBS $LIBS"
301 test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"
302 dnl First argument of AC_LINK_IFELSE left empty because the test file is
303 dnl generated only once above (before we start the for loops).
304 _BOOST_AC_LINK_IFELSE([],
305 [Boost_lib=yes], [Boost_lib=no])
306 ac_objext=$boost_save_ac_objext
307 LDFLAGS=$boost_save_LDFLAGS
308 LIBS=$boost_save_LIBS
309 if test x"$Boost_lib" = xyes; then
310 Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath"
313 boost_failed_libs="$boost_failed_libs@$boost_lib@"
321 rm -f conftest.$ac_objext
323 case $Boost_lib in #(
324 no) AC_MSG_ERROR([Could not find the flags to link with Boost $1])
327 AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS])
328 AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS])
329 CPPFLAGS=$boost_save_CPPFLAGS
330 AS_VAR_POPDEF([Boost_lib])dnl
331 AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl
332 AS_VAR_POPDEF([Boost_lib_LIBS])dnl
333 AC_LANG_POP([C++])dnl
337 # --------------------------------------- #
338 # Checks for the various Boost libraries. #
339 # --------------------------------------- #
341 # List of boost libraries: http://www.boost.org/libs/libraries.htm
342 # The page http://beta.boost.org/doc/libs is useful: it gives the first release
343 # version of each library (among other things).
348 # Look for Boost.Bind
349 AC_DEFUN([BOOST_BIND],
350 [BOOST_FIND_HEADER([boost/bind.hpp])])
355 # Look for Boost.Conversion (cast / lexical_cast)
356 AC_DEFUN([BOOST_CONVERSION],
357 [BOOST_FIND_HEADER([boost/cast.hpp])
358 BOOST_FIND_HEADER([boost/lexical_cast.hpp])
362 # BOOST_DATE_TIME([PREFERRED-RT-OPT])
363 # -----------------------------------
364 # Look for Boost.Date_Time. For the documentation of PREFERRED-RT-OPT, see the
365 # documentation of BOOST_FIND_LIB above.
366 AC_DEFUN([BOOST_DATE_TIME],
367 [BOOST_FIND_LIB([date_time], [$1],
368 [boost/date_time/posix_time/posix_time.hpp],
369 [boost::posix_time::ptime t;])
373 # BOOST_FILESYSTEM([PREFERRED-RT-OPT])
374 # ------------------------------------
375 # Look for Boost.Filesystem. For the documentation of PREFERRED-RT-OPT, see the
376 # documentation of BOOST_FIND_LIB above.
377 # Do not check for boost/filesystem.hpp because this file was introduced in 1.34.
378 AC_DEFUN([BOOST_FILESYSTEM],
379 [BOOST_FIND_LIB([filesystem], [$1],
380 [boost/filesystem/path.hpp], [boost::filesystem::path p;])
386 # Look for Boost.Foreach
387 AC_DEFUN([BOOST_FOREACH],
388 [BOOST_FIND_HEADER([boost/foreach.hpp])])
393 # Look for Boost.Format
394 # Note: we can't check for boost/format/format_fwd.hpp because the header isn't
395 # standalone. It can't be compiled because it triggers the following error:
396 # boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std'
397 # does not name a type
398 AC_DEFUN([BOOST_FORMAT],
399 [BOOST_FIND_HEADER([boost/format.hpp])])
404 # Look for Boost.Function
405 AC_DEFUN([BOOST_FUNCTION],
406 [BOOST_FIND_HEADER([boost/function.hpp])])
409 # BOOST_GRAPH([PREFERRED-RT-OPT])
410 # -------------------------------
411 # Look for Boost.Graphs. For the documentation of PREFERRED-RT-OPT, see the
412 # documentation of BOOST_FIND_LIB above.
413 AC_DEFUN([BOOST_GRAPH],
414 [BOOST_FIND_LIB([graph], [$1],
415 [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;])
419 # BOOST_IOSTREAMS([PREFERRED-RT-OPT])
420 # -------------------------------
421 # Look for Boost.IOStreams. For the documentation of PREFERRED-RT-OPT, see the
422 # documentation of BOOST_FIND_LIB above.
423 AC_DEFUN([BOOST_IOSTREAMS],
424 [BOOST_FIND_LIB([iostreams], [$1],
425 [boost/iostreams/device/file_descriptor.hpp],
426 [boost::iostreams::file_descriptor fd(0); fd.close();])
432 # Look for Boost.Functional/Hash
433 AC_DEFUN([BOOST_HASH],
434 [BOOST_FIND_HEADER([boost/functional/hash.hpp])])
437 # BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT])
438 # -----------------------------------------
439 # Look for Boost.Program_options. For the documentation of PREFERRED-RT-OPT, see
440 # the documentation of BOOST_FIND_LIB above.
441 AC_DEFUN([BOOST_PROGRAM_OPTIONS],
442 [BOOST_FIND_LIB([program_options], [$1],
443 [boost/program_options.hpp],
444 [boost::program_options::options_description d("test");])
445 ])# BOOST_PROGRAM_OPTIONS
451 AC_DEFUN([BOOST_REF],
452 [BOOST_FIND_HEADER([boost/ref.hpp])])
455 # BOOST_REGEX([PREFERRED-RT-OPT])
456 # -------------------------------
457 # Look for Boost.Regex. For the documentation of PREFERRED-RT-OPT, see the
458 # documentation of BOOST_FIND_LIB above.
459 AC_DEFUN([BOOST_REGEX],
460 [BOOST_FIND_LIB([regex], [$1],
462 [boost::regex exp("*"); boost::regex_match("foo", exp);])
466 # BOOST_SERIALIZATION([PREFERRED-RT-OPT])
467 # ---------------------------------------
468 # Look for Boost.Serialization. For the documentation of PREFERRED-RT-OPT, see
469 # the documentation of BOOST_FIND_LIB above.
470 AC_DEFUN([BOOST_SERIALIZATION],
471 [BOOST_FIND_LIB([serialization], [$1],
472 [boost/archive/text_oarchive.hpp],
473 [std::ostream* o = 0; // Cheap way to get an ostream...
474 boost::archive::text_oarchive t(*o);])
478 # BOOST_SIGNALS([PREFERRED-RT-OPT])
479 # ---------------------------------
480 # Look for Boost.Signals. For the documentation of PREFERRED-RT-OPT, see the
481 # documentation of BOOST_FIND_LIB above.
482 AC_DEFUN([BOOST_SIGNALS],
483 [BOOST_FIND_LIB([signals], [$1],
485 [boost::signal<void ()> s;])
491 # Look for Boost.SmartPtr
492 AC_DEFUN([BOOST_SMART_PTR],
493 [BOOST_FIND_HEADER([boost/scoped_ptr.hpp])
494 BOOST_FIND_HEADER([boost/shared_ptr.hpp])
498 # BOOST_STRING_ALGO()
499 # -------------------
500 # Look for Boost.StringAlgo
501 AC_DEFUN([BOOST_STRING_ALGO],
502 [BOOST_FIND_HEADER([boost/algorithm/string.hpp])
506 # BOOST_TEST([PREFERRED-RT-OPT])
507 # ------------------------------
508 # Look for Boost.Test. For the documentation of PREFERRED-RT-OPT, see the
509 # documentation of BOOST_FIND_LIB above.
510 AC_DEFUN([BOOST_TEST],
511 [m4_pattern_allow([^BOOST_CHECK$])dnl
512 BOOST_FIND_LIB([unit_test_framework], [$1],
513 [boost/test/unit_test.hpp], [BOOST_CHECK(2 == 2);],
514 [using boost::unit_test::test_suite;
515 test_suite* init_unit_test_suite(int argc, char ** argv)
520 # BOOST_THREADS([PREFERRED-RT-OPT])
521 # ---------------------------------
522 # Look for Boost.Thread. For the documentation of PREFERRED-RT-OPT, see the
523 # documentation of BOOST_FIND_LIB above.
524 # FIXME: Provide an alias "BOOST_THREAD".
525 AC_DEFUN([BOOST_THREADS],
526 [dnl Having the pthread flag is required at least on GCC3 where
527 dnl boost/thread.hpp would complain if we try to compile without
528 dnl -pthread on GNU/Linux.
529 AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
530 boost_threads_save_LIBS=$LIBS
531 boost_threads_save_CPPFLAGS=$CPPFLAGS
532 LIBS="$LIBS $boost_cv_pthread_flag"
533 # Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
534 # boost/thread.hpp will trigger a #error if -pthread isn't used:
535 # boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
536 # is not turned on. Please set the correct command line options for
537 # threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
538 CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag"
539 BOOST_FIND_LIB([thread], [$1],
540 [boost/thread.hpp], [boost::thread t; boost::mutex m;])
541 BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $boost_cv_pthread_flag"
542 BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag"
543 LIBS=$boost_threads_save_LIBS
544 CPPFLAGS=$boost_threads_save_CPPFLAGS
550 # Look for Boost.Tokenizer
551 AC_DEFUN([BOOST_TOKENIZER],
552 [BOOST_FIND_HEADER([boost/tokenizer.hpp])])
557 # Look for Boost.Tribool
558 AC_DEFUN([BOOST_TRIBOOL],
559 [BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp])
560 BOOST_FIND_HEADER([boost/logic/tribool.hpp])
566 # Look for Boost.Tuple
567 AC_DEFUN([BOOST_TUPLE],
568 [BOOST_FIND_HEADER([boost/tuple/tuple.hpp])])
573 # Look for Boost.Utility (noncopyable, result_of, base-from-member idiom,
575 AC_DEFUN([BOOST_UTILITY],
576 [BOOST_FIND_HEADER([boost/utility.hpp])])
581 # Look for Boost.Variant.
582 AC_DEFUN([BOOST_VARIANT],
583 [BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp])
584 BOOST_FIND_HEADER([boost/variant.hpp])])
587 # BOOST_WAVE([PREFERRED-RT-OPT])
588 # ------------------------------
589 # Look for Boost.Wave. For the documentation of PREFERRED-RT-OPT, see the
590 # documentation of BOOST_FIND_LIB above.
591 AC_DEFUN([BOOST_WAVE],
592 [BOOST_FIND_LIB([wave], [$1],
594 [boost::wave::token_id id; get_token_name(id);])])
597 # ----------------- #
598 # Internal helpers. #
599 # ----------------- #
602 # _BOOST_PTHREAD_FLAG()
603 # ---------------------
604 # Internal helper for BOOST_THREADS. Based on ACX_PTHREAD:
605 # http://autoconf-archive.cryp.to/acx_pthread.html
606 AC_DEFUN([_BOOST_PTHREAD_FLAG],
607 [AC_REQUIRE([AC_PROG_CXX])dnl
608 AC_REQUIRE([AC_CANONICAL_HOST])dnl
609 AC_LANG_PUSH([C++])dnl
610 AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag],
611 [ boost_cv_pthread_flag=
612 # The ordering *is* (sometimes) important. Some notes on the
613 # individual items follow:
614 # (none): in case threads are in libc; should be tried before -Kthread and
615 # other compiler flags to prevent continual compiler warnings
616 # -lpthreads: AIX (must check this before -lpthread)
617 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
618 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
619 # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
620 # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
621 # -pthreads: Solaris/GCC
622 # -mthreads: MinGW32/GCC, Lynx/GCC
623 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
624 # doesn't hurt to check since this sometimes defines pthreads too;
625 # also defines -D_REENTRANT)
626 # ... -mt is also the pthreads flag for HP/aCC
627 # -lpthread: GNU Linux, etc.
628 # --thread-safe: KAI C++
631 # On Solaris (at least, for some versions), libc contains stubbed
632 # (non-functional) versions of the pthreads routines, so link-based
633 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
634 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
635 # a function called by this macro, so we could check for that, but
636 # who knows whether they'll stub that too in a future libc.) So,
637 # we'll just look for -pthreads and -lpthread first:
638 boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #(
640 boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \
641 -pthreads -mthreads -lpthread --thread-safe -mt";;
643 # Generate the test file.
644 AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <pthread.h>],
645 [pthread_t th; pthread_join(th, 0);
646 pthread_attr_init(0); pthread_cleanup_push(0, 0);
647 pthread_create(0,0,0,0); pthread_cleanup_pop(0);])])
648 for boost_pthread_flag in '' $boost_pthread_flags; do
649 boost_pthread_ok=false
650 dnl Re-use the test file already generated.
651 boost_pthreads__save_LIBS=$LIBS
652 LIBS="$LIBS $boost_pthread_flag"
654 [if grep ".*$boost_pthread_flag" conftest.err; then
655 echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD
657 boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag
659 LIBS=$boost_pthreads__save_LIBS
660 $boost_pthread_ok && break
663 AC_LANG_POP([C++])dnl
664 ])# _BOOST_PTHREAD_FLAG
667 # _BOOST_gcc_test(MAJOR, MINOR)
668 # -----------------------------
669 # Internal helper for _BOOST_FIND_COMPILER_TAG.
670 m4_define([_BOOST_gcc_test],
671 ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl
674 # _BOOST_FIND_COMPILER_TAG()
675 # --------------------------
676 # Internal. When Boost is installed without --layout=system, each library
677 # filename will hold a suffix that encodes the compiler used during the
678 # build. The Boost build system seems to call this a `tag'.
679 AC_DEFUN([_BOOST_FIND_COMPILER_TAG],
680 [AC_REQUIRE([AC_PROG_CXX])dnl
681 AC_CACHE_CHECK([for the toolset name used by Boost for $CXX], [boost_cv_lib_tag],
682 [AC_LANG_PUSH([C++])dnl
683 boost_cv_lib_tag=unknown
684 # The following tests are mostly inspired by boost/config/auto_link.hpp
685 # The list is sorted to most recent/common to oldest compiler (in order
686 # to increase the likelihood of finding the right compiler with the
687 # least number of compilation attempt).
688 # Beware that some tests are sensible to the order (for instance, we must
689 # look for MinGW before looking for GCC3).
690 # I used one compilation test per compiler with a #error to recognize
691 # each compiler so that it works even when cross-compiling (let me know
692 # if you know a better approach).
693 # Known missing tags (known from Boost's tools/build/v2/tools/common.jam):
694 # como, edg, kcc, bck, mp, sw, tru, xlc
695 # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines
696 # the same defines as GCC's).
697 # TODO: Move the test on GCC 4.3 up once it's released.
699 _BOOST_gcc_test(4, 2) \
700 _BOOST_gcc_test(4, 1) \
701 _BOOST_gcc_test(4, 0) \
702 "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \
703 && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
704 || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \
705 _BOOST_gcc_test(3, 4) \
706 _BOOST_gcc_test(3, 3) \
707 "defined _MSC_VER && _MSC_VER >= 1400 @ vc80" \
708 _BOOST_gcc_test(3, 2) \
709 "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \
710 _BOOST_gcc_test(3, 1) \
711 _BOOST_gcc_test(3, 0) \
712 "defined __BORLANDC__ @ bcb" \
713 "defined __ICC && (defined __unix || defined __unix__) @ il" \
714 "defined __ICL @ iw" \
715 "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \
716 _BOOST_gcc_test(4, 3) \
717 _BOOST_gcc_test(2, 95) \
718 "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \
719 "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \
720 "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \
721 "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8"
723 boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '`
724 boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'`
725 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
729 # error $boost_tag_test
731 ]])], [boost_cv_lib_tag=$boost_tag; break], [])
733 AC_LANG_POP([C++])dnl
735 if test x"$boost_cv_lib_tag" = xunknown; then
736 AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]])
739 ])# _BOOST_FIND_COMPILER_TAG
742 # _BOOST_GUESS_WHETHER_TO_USE_MT()
743 # --------------------------------
744 # Compile a small test to try to guess whether we should favor MT (Multi
745 # Thread) flavors of Boost. Sets boost_guess_use_mt accordingly.
746 AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT],
747 [# Check whether we do better use `mt' even though we weren't ask to.
748 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
749 #if defined _REENTRANT || defined _MT || defined __MT__
752 # error MT not needed
754 ]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false])
757 # _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
758 # -------------------------------------------------------------------
759 # Fork of _AC_LINK_IFELSE that preserves conftest.o across calls. Fragile,
760 # will break when Autoconf changes its internals. Requires that you manually
761 # rm -f conftest.$ac_objext in between to really different tests, otherwise
762 # you will try to link a conftest.o left behind by a previous test.
763 # Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this
765 m4_define([_BOOST_AC_LINK_IFELSE],
766 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
767 rm -f conftest$ac_exeext
768 boost_ac_ext_save=$ac_ext
770 # If we already have a .o, re-use it. We change $ac_ext so that $ac_link
771 # tries to link the existing object file instead of compiling from source.
772 test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false &&
773 _AS_ECHO_LOG([re-using the existing conftest.$ac_objext])
774 AS_IF([_AC_DO_STDERR($ac_link) && {
775 test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
776 test ! -s conftest.err
777 } && test -s conftest$ac_exeext && {
778 test "$cross_compiling" = yes ||
779 $as_executable_p conftest$ac_exeext
780 dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough.
783 [if $boost_use_source; then
787 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
788 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
789 dnl as it would interfere with the next link command.
790 rm -f core conftest.err conftest_ipa8_conftest.oo \
791 conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl
792 ])# _BOOST_AC_LINK_IFELSE