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/>.
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 # 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
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.
60 [^ *$], [m4_pushdef([BOOST_VERSION_REQ], [])dnl
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])
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']])
82 [m4_fatal(Invalid argument: `$1')]
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],
92 AC_LANG_PUSH([C++])dnl
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
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-*
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
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
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
139 AC_LANG_POP([C++])dnl
141 case $boost_cv_inc_path in #(
143 AC_MSG_ERROR([Could not find Boost headers[]BOOST_VERSION_REQ])
149 BOOST_CPPFLAGS="-I$boost_cv_inc_path"
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"`
162 m4_popdef([BOOST_VERSION_REQ])dnl
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],
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'
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],
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;;
237 # Find the proper debug variant depending on what we've been asked to find.
238 case $boost_rtopt in #(
239 *d*) boost_rt_d=$boost_rtopt;; #(
240 *[[sgpn]]*) # Insert the `d' at the right place (in between `sg' and `pn')
241 boost_rt_d=`echo "$boost_rtopt" | sed 's/\(s*g*\)\(p*n*\)/\1\2/'`;; #(
244 # If the PREFERRED-RT-OPT are not empty, prepend a `-'.
245 test -n "$boost_rtopt" && boost_rtopt="-$boost_rtopt"
246 $boost_guess_use_mt && boost_mt=-mt
247 # Look for the abs path the static archive.
248 # $libext is computed by Libtool but let's make sure it's non empty.
250 AC_MSG_ERROR([the libext variable is empty, did you invoke Libtool?])
251 boost_save_ac_objext=$ac_objext
252 # Generate the test file.
253 AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <$3>
255 dnl Optimization hacks: compiling C++ is slow, especially with Boost. What
256 dnl we're trying to do here is guess the right combination of link flags
257 dnl (LIBS / LDFLAGS) to use a given library. This can take several
258 dnl iterations before it succeeds and is thus *very* slow. So what we do
259 dnl instead is that we compile the code first (and thus get an object file,
260 dnl typically conftest.o). Then we try various combinations of link flags
261 dnl until we succeed to link conftest.o in an executable. The problem is
262 dnl that the various TRY_LINK / COMPILE_IFELSE macros of Autoconf always
263 dnl remove all the temporary files including conftest.o. So the trick here
264 dnl is to temporarily change the value of ac_objext so that conftest.o is
265 dnl preserved accross tests. This is obviously fragile and I will burn in
266 dnl hell for not respecting Autoconf's documented interfaces, but in the
267 dnl mean time, it optimizes the macro by a factor of 5 to 30.
268 dnl Another small optimization: the first argument of AC_COMPILE_IFELSE left
269 dnl empty because the test file is generated only once above (before we
270 dnl start the for loops).
271 AC_COMPILE_IFELSE([],
272 [ac_objext=do_not_rm_me_plz],
273 [AC_MSG_ERROR([Cannot compile a test that uses Boost $1])])
274 ac_objext=$boost_save_ac_objext
276 # Don't bother to ident the 6 nested for loops, only the 2 innermost ones
278 for boost_tag_ in -$boost_cv_lib_tag ''; do
279 for boost_ver_ in -$boost_cv_lib_version ''; do
280 for boost_mt_ in $boost_mt -mt ''; do
281 for boost_rtopt_ in $boost_rtopt '' -d; do
283 boost_$1$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ \
284 boost_$1$boost_tag_$boost_rtopt_$boost_ver_ \
285 boost_$1$boost_tag_$boost_mt_$boost_ver_ \
286 boost_$1$boost_tag_$boost_ver_
288 # Avoid testing twice the same lib
289 case $boost_failed_libs in #(
290 *@$boost_lib@*) continue;;
292 # If with_boost is empty, we'll search in /lib first, which is not quite
293 # right so instead we'll try to a location based on where the headers are.
294 boost_tmp_lib=$with_boost
295 test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include}
296 for boost_ldpath in "$boost_tmp_lib/lib" '' \
297 /opt/local/lib /usr/local/lib /opt/lib /usr/lib \
298 "$with_boost" C:/Boost/lib /lib /usr/lib64 /lib64
300 test -e "$boost_ldpath" || continue
301 boost_save_LDFLAGS=$LDFLAGS
302 # Are we looking for a static library?
303 case $boost_ldpath:$boost_rtopt_ in #(
304 *?*:*s*) # Yes (Non empty boost_ldpath + s in rt opt)
305 Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext"
306 test -e "$Boost_lib_LIBS" || continue;; #(
307 *) # No: use -lboost_foo to find the shared library.
308 Boost_lib_LIBS="-l$boost_lib";;
310 boost_save_LIBS=$LIBS
311 LIBS="$Boost_lib_LIBS $LIBS"
312 test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"
313 dnl First argument of AC_LINK_IFELSE left empty because the test file is
314 dnl generated only once above (before we start the for loops).
315 _BOOST_AC_LINK_IFELSE([],
316 [Boost_lib=yes], [Boost_lib=no])
317 ac_objext=$boost_save_ac_objext
318 LDFLAGS=$boost_save_LDFLAGS
319 LIBS=$boost_save_LIBS
320 if test x"$Boost_lib" = xyes; then
321 Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath"
324 boost_failed_libs="$boost_failed_libs@$boost_lib@"
332 rm -f conftest.$ac_objext
334 case $Boost_lib in #(
335 no) AC_MSG_ERROR([Could not find the flags to link with Boost $1])
338 AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS])
339 AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS])
340 CPPFLAGS=$boost_save_CPPFLAGS
341 AS_VAR_POPDEF([Boost_lib])dnl
342 AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl
343 AS_VAR_POPDEF([Boost_lib_LIBS])dnl
344 AC_LANG_POP([C++])dnl
348 # --------------------------------------- #
349 # Checks for the various Boost libraries. #
350 # --------------------------------------- #
352 # List of boost libraries: http://www.boost.org/libs/libraries.htm
353 # The page http://beta.boost.org/doc/libs is useful: it gives the first release
354 # version of each library (among other things).
359 # Look for Boost.Bind
360 AC_DEFUN([BOOST_BIND],
361 [BOOST_FIND_HEADER([boost/bind.hpp])])
366 # Look for Boost.Conversion (cast / lexical_cast)
367 AC_DEFUN([BOOST_CONVERSION],
368 [BOOST_FIND_HEADER([boost/cast.hpp])
369 BOOST_FIND_HEADER([boost/lexical_cast.hpp])
373 # BOOST_DATE_TIME([PREFERRED-RT-OPT])
374 # -----------------------------------
375 # Look for Boost.Date_Time. For the documentation of PREFERRED-RT-OPT, see the
376 # documentation of BOOST_FIND_LIB above.
377 AC_DEFUN([BOOST_DATE_TIME],
378 [BOOST_FIND_LIB([date_time], [$1],
379 [boost/date_time/posix_time/posix_time.hpp],
380 [boost::posix_time::ptime t;])
384 # BOOST_FILESYSTEM([PREFERRED-RT-OPT])
385 # ------------------------------------
386 # Look for Boost.Filesystem. For the documentation of PREFERRED-RT-OPT, see the
387 # documentation of BOOST_FIND_LIB above.
388 # Do not check for boost/filesystem.hpp because this file was introduced in 1.34.
389 AC_DEFUN([BOOST_FILESYSTEM],
390 [BOOST_FIND_LIB([filesystem], [$1],
391 [boost/filesystem/path.hpp], [boost::filesystem::path p;])
397 # Look for Boost.Foreach
398 AC_DEFUN([BOOST_FOREACH],
399 [BOOST_FIND_HEADER([boost/foreach.hpp])])
404 # Look for Boost.Format
405 # Note: we can't check for boost/format/format_fwd.hpp because the header isn't
406 # standalone. It can't be compiled because it triggers the following error:
407 # boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std'
408 # does not name a type
409 AC_DEFUN([BOOST_FORMAT],
410 [BOOST_FIND_HEADER([boost/format.hpp])])
415 # Look for Boost.Function
416 AC_DEFUN([BOOST_FUNCTION],
417 [BOOST_FIND_HEADER([boost/function.hpp])])
420 # BOOST_GRAPH([PREFERRED-RT-OPT])
421 # -------------------------------
422 # Look for Boost.Graphs. For the documentation of PREFERRED-RT-OPT, see the
423 # documentation of BOOST_FIND_LIB above.
424 AC_DEFUN([BOOST_GRAPH],
425 [BOOST_FIND_LIB([graph], [$1],
426 [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;])
430 # BOOST_IOSTREAMS([PREFERRED-RT-OPT])
431 # -------------------------------
432 # Look for Boost.IOStreams. For the documentation of PREFERRED-RT-OPT, see the
433 # documentation of BOOST_FIND_LIB above.
434 AC_DEFUN([BOOST_IOSTREAMS],
435 [BOOST_FIND_LIB([iostreams], [$1],
436 [boost/iostreams/device/file_descriptor.hpp],
437 [boost::iostreams::file_descriptor fd(0); fd.close();])
443 # Look for Boost.Functional/Hash
444 AC_DEFUN([BOOST_HASH],
445 [BOOST_FIND_HEADER([boost/functional/hash.hpp])])
450 # Look for Boost.Lambda
451 AC_DEFUN([BOOST_LAMBDA],
452 [BOOST_FIND_HEADER([boost/lambda/lambda.hpp])])
455 # BOOST_PREPROCESSOR()
456 # --------------------
457 # Look for Boost.Preprocessor
458 AC_DEFUN([BOOST_PREPROCESSOR],
459 [BOOST_FIND_HEADER([boost/preprocessor/repeat.hpp])])
462 # BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT])
463 # -----------------------------------------
464 # Look for Boost.Program_options. For the documentation of PREFERRED-RT-OPT, see
465 # the documentation of BOOST_FIND_LIB above.
466 AC_DEFUN([BOOST_PROGRAM_OPTIONS],
467 [BOOST_FIND_LIB([program_options], [$1],
468 [boost/program_options.hpp],
469 [boost::program_options::options_description d("test");])
470 ])# BOOST_PROGRAM_OPTIONS
476 AC_DEFUN([BOOST_REF],
477 [BOOST_FIND_HEADER([boost/ref.hpp])])
480 # BOOST_REGEX([PREFERRED-RT-OPT])
481 # -------------------------------
482 # Look for Boost.Regex. For the documentation of PREFERRED-RT-OPT, see the
483 # documentation of BOOST_FIND_LIB above.
484 AC_DEFUN([BOOST_REGEX],
485 [BOOST_FIND_LIB([regex], [$1],
487 [boost::regex exp("*"); boost::regex_match("foo", exp);])
491 # BOOST_SERIALIZATION([PREFERRED-RT-OPT])
492 # ---------------------------------------
493 # Look for Boost.Serialization. For the documentation of PREFERRED-RT-OPT, see
494 # the documentation of BOOST_FIND_LIB above.
495 AC_DEFUN([BOOST_SERIALIZATION],
496 [BOOST_FIND_LIB([serialization], [$1],
497 [boost/archive/text_oarchive.hpp],
498 [std::ostream* o = 0; // Cheap way to get an ostream...
499 boost::archive::text_oarchive t(*o);])
503 # BOOST_SIGNALS([PREFERRED-RT-OPT])
504 # ---------------------------------
505 # Look for Boost.Signals. For the documentation of PREFERRED-RT-OPT, see the
506 # documentation of BOOST_FIND_LIB above.
507 AC_DEFUN([BOOST_SIGNALS],
508 [BOOST_FIND_LIB([signals], [$1],
510 [boost::signal<void ()> s;])
516 # Look for Boost.SmartPtr
517 AC_DEFUN([BOOST_SMART_PTR],
518 [BOOST_FIND_HEADER([boost/scoped_ptr.hpp])
519 BOOST_FIND_HEADER([boost/shared_ptr.hpp])
523 # BOOST_STRING_ALGO()
524 # -------------------
525 # Look for Boost.StringAlgo
526 AC_DEFUN([BOOST_STRING_ALGO],
527 [BOOST_FIND_HEADER([boost/algorithm/string.hpp])
531 # BOOST_TEST([PREFERRED-RT-OPT])
532 # ------------------------------
533 # Look for Boost.Test. For the documentation of PREFERRED-RT-OPT, see the
534 # documentation of BOOST_FIND_LIB above.
535 AC_DEFUN([BOOST_TEST],
536 [m4_pattern_allow([^BOOST_CHECK$])dnl
537 BOOST_FIND_LIB([unit_test_framework], [$1],
538 [boost/test/unit_test.hpp], [BOOST_CHECK(2 == 2);],
539 [using boost::unit_test::test_suite;
540 test_suite* init_unit_test_suite(int argc, char ** argv)
545 # BOOST_THREADS([PREFERRED-RT-OPT])
546 # ---------------------------------
547 # Look for Boost.Thread. For the documentation of PREFERRED-RT-OPT, see the
548 # documentation of BOOST_FIND_LIB above.
549 # FIXME: Provide an alias "BOOST_THREAD".
550 AC_DEFUN([BOOST_THREADS],
551 [dnl Having the pthread flag is required at least on GCC3 where
552 dnl boost/thread.hpp would complain if we try to compile without
553 dnl -pthread on GNU/Linux.
554 AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
555 boost_threads_save_LIBS=$LIBS
556 boost_threads_save_CPPFLAGS=$CPPFLAGS
557 LIBS="$LIBS $boost_cv_pthread_flag"
558 # Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
559 # boost/thread.hpp will trigger a #error if -pthread isn't used:
560 # boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
561 # is not turned on. Please set the correct command line options for
562 # threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
563 CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag"
564 BOOST_FIND_LIB([thread], [$1],
565 [boost/thread.hpp], [boost::thread t; boost::mutex m;])
566 BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $boost_cv_pthread_flag"
567 BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag"
568 LIBS=$boost_threads_save_LIBS
569 CPPFLAGS=$boost_threads_save_CPPFLAGS
575 # Look for Boost.Tokenizer
576 AC_DEFUN([BOOST_TOKENIZER],
577 [BOOST_FIND_HEADER([boost/tokenizer.hpp])])
582 # Look for Boost.Tribool
583 AC_DEFUN([BOOST_TRIBOOL],
584 [BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp])
585 BOOST_FIND_HEADER([boost/logic/tribool.hpp])
591 # Look for Boost.Tuple
592 AC_DEFUN([BOOST_TUPLE],
593 [BOOST_FIND_HEADER([boost/tuple/tuple.hpp])])
598 # Look for Boost.Utility (noncopyable, result_of, base-from-member idiom,
600 AC_DEFUN([BOOST_UTILITY],
601 [BOOST_FIND_HEADER([boost/utility.hpp])])
606 # Look for Boost.Variant.
607 AC_DEFUN([BOOST_VARIANT],
608 [BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp])
609 BOOST_FIND_HEADER([boost/variant.hpp])])
612 # BOOST_WAVE([PREFERRED-RT-OPT])
613 # ------------------------------
614 # Look for Boost.Wave. For the documentation of PREFERRED-RT-OPT, see the
615 # documentation of BOOST_FIND_LIB above.
616 AC_DEFUN([BOOST_WAVE],
617 [BOOST_FIND_LIB([wave], [$1],
619 [boost::wave::token_id id; get_token_name(id);])])
622 # ----------------- #
623 # Internal helpers. #
624 # ----------------- #
627 # _BOOST_PTHREAD_FLAG()
628 # ---------------------
629 # Internal helper for BOOST_THREADS. Based on ACX_PTHREAD:
630 # http://autoconf-archive.cryp.to/acx_pthread.html
631 AC_DEFUN([_BOOST_PTHREAD_FLAG],
632 [AC_REQUIRE([AC_PROG_CXX])dnl
633 AC_REQUIRE([AC_CANONICAL_HOST])dnl
634 AC_LANG_PUSH([C++])dnl
635 AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag],
636 [ boost_cv_pthread_flag=
637 # The ordering *is* (sometimes) important. Some notes on the
638 # individual items follow:
639 # (none): in case threads are in libc; should be tried before -Kthread and
640 # other compiler flags to prevent continual compiler warnings
641 # -lpthreads: AIX (must check this before -lpthread)
642 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
643 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
644 # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
645 # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
646 # -pthreads: Solaris/GCC
647 # -mthreads: MinGW32/GCC, Lynx/GCC
648 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
649 # doesn't hurt to check since this sometimes defines pthreads too;
650 # also defines -D_REENTRANT)
651 # ... -mt is also the pthreads flag for HP/aCC
652 # -lpthread: GNU Linux, etc.
653 # --thread-safe: KAI C++
656 # On Solaris (at least, for some versions), libc contains stubbed
657 # (non-functional) versions of the pthreads routines, so link-based
658 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
659 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
660 # a function called by this macro, so we could check for that, but
661 # who knows whether they'll stub that too in a future libc.) So,
662 # we'll just look for -pthreads and -lpthread first:
663 boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #(
665 boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \
666 -pthreads -mthreads -lpthread --thread-safe -mt";;
668 # Generate the test file.
669 AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <pthread.h>],
670 [pthread_t th; pthread_join(th, 0);
671 pthread_attr_init(0); pthread_cleanup_push(0, 0);
672 pthread_create(0,0,0,0); pthread_cleanup_pop(0);])])
673 for boost_pthread_flag in '' $boost_pthread_flags; do
674 boost_pthread_ok=false
675 dnl Re-use the test file already generated.
676 boost_pthreads__save_LIBS=$LIBS
677 LIBS="$LIBS $boost_pthread_flag"
679 [if grep ".*$boost_pthread_flag" conftest.err; then
680 echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD
682 boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag
684 LIBS=$boost_pthreads__save_LIBS
685 $boost_pthread_ok && break
688 AC_LANG_POP([C++])dnl
689 ])# _BOOST_PTHREAD_FLAG
692 # _BOOST_gcc_test(MAJOR, MINOR)
693 # -----------------------------
694 # Internal helper for _BOOST_FIND_COMPILER_TAG.
695 m4_define([_BOOST_gcc_test],
696 ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl
699 # _BOOST_FIND_COMPILER_TAG()
700 # --------------------------
701 # Internal. When Boost is installed without --layout=system, each library
702 # filename will hold a suffix that encodes the compiler used during the
703 # build. The Boost build system seems to call this a `tag'.
704 AC_DEFUN([_BOOST_FIND_COMPILER_TAG],
705 [AC_REQUIRE([AC_PROG_CXX])dnl
706 AC_CACHE_CHECK([for the toolset name used by Boost for $CXX], [boost_cv_lib_tag],
707 [AC_LANG_PUSH([C++])dnl
708 boost_cv_lib_tag=unknown
709 # The following tests are mostly inspired by boost/config/auto_link.hpp
710 # The list is sorted to most recent/common to oldest compiler (in order
711 # to increase the likelihood of finding the right compiler with the
712 # least number of compilation attempt).
713 # Beware that some tests are sensible to the order (for instance, we must
714 # look for MinGW before looking for GCC3).
715 # I used one compilation test per compiler with a #error to recognize
716 # each compiler so that it works even when cross-compiling (let me know
717 # if you know a better approach).
718 # Known missing tags (known from Boost's tools/build/v2/tools/common.jam):
719 # como, edg, kcc, bck, mp, sw, tru, xlc
720 # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines
721 # the same defines as GCC's).
722 # TODO: Move the test on GCC 4.3 up once it's released.
724 _BOOST_gcc_test(4, 2) \
725 _BOOST_gcc_test(4, 1) \
726 _BOOST_gcc_test(4, 0) \
727 "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \
728 && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
729 || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \
730 _BOOST_gcc_test(3, 4) \
731 _BOOST_gcc_test(3, 3) \
732 "defined _MSC_VER && _MSC_VER >= 1400 @ vc80" \
733 _BOOST_gcc_test(3, 2) \
734 "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \
735 _BOOST_gcc_test(3, 1) \
736 _BOOST_gcc_test(3, 0) \
737 "defined __BORLANDC__ @ bcb" \
738 "defined __ICC && (defined __unix || defined __unix__) @ il" \
739 "defined __ICL @ iw" \
740 "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \
741 _BOOST_gcc_test(4, 3) \
742 _BOOST_gcc_test(2, 95) \
743 "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \
744 "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \
745 "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \
746 "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8"
748 boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '`
749 boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'`
750 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
754 # error $boost_tag_test
756 ]])], [boost_cv_lib_tag=$boost_tag; break], [])
758 AC_LANG_POP([C++])dnl
760 case $boost_cv_lib_tag in #(
761 # Some newer (>= 1.35?) versions of Boost seem to only use "gcc" as opposed
762 # to "gcc41" for instance.
764 # We can specify multiple tags in this variable because it's used by
765 # BOOST_FIND_LIB that does a `for tag in -$boost_cv_lib_tag' ...
766 boost_cv_lib_tag="$boost_cv_lib_tag -gcc"
769 AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]])
773 ])# _BOOST_FIND_COMPILER_TAG
776 # _BOOST_GUESS_WHETHER_TO_USE_MT()
777 # --------------------------------
778 # Compile a small test to try to guess whether we should favor MT (Multi
779 # Thread) flavors of Boost. Sets boost_guess_use_mt accordingly.
780 AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT],
781 [# Check whether we do better use `mt' even though we weren't ask to.
782 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
783 #if defined _REENTRANT || defined _MT || defined __MT__
786 # error MT not needed
788 ]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false])
791 # _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
792 # -------------------------------------------------------------------
793 # Fork of _AC_LINK_IFELSE that preserves conftest.o across calls. Fragile,
794 # will break when Autoconf changes its internals. Requires that you manually
795 # rm -f conftest.$ac_objext in between to really different tests, otherwise
796 # you will try to link a conftest.o left behind by a previous test.
797 # Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this
799 m4_define([_BOOST_AC_LINK_IFELSE],
800 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
801 rm -f conftest$ac_exeext
802 boost_ac_ext_save=$ac_ext
804 # If we already have a .o, re-use it. We change $ac_ext so that $ac_link
805 # tries to link the existing object file instead of compiling from source.
806 test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false &&
807 _AS_ECHO_LOG([re-using the existing conftest.$ac_objext])
808 AS_IF([_AC_DO_STDERR($ac_link) && {
809 test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
810 test ! -s conftest.err
811 } && test -s conftest$ac_exeext && {
812 test "$cross_compiling" = yes ||
813 $as_executable_p conftest$ac_exeext
814 dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough.
817 [if $boost_use_source; then
821 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
822 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
823 dnl as it would interfere with the next link command.
824 rm -f core conftest.err conftest_ipa8_conftest.oo \
825 conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl
826 ])# _BOOST_AC_LINK_IFELSE