Do not try to link with non existent static archives.
[boost.m4.git] / build-aux / boost.m4
blob0a454fbf8fa83bc128ccda886bc00ed7c80c30cb
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/>.
17 # serial 4
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
22 # ------ #
23 # README #
24 # ------ #
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
41 # variable "$var".
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.
52 m4_bmatch([$1],
53   [^ *$], [m4_pushdef([BOOST_VERSION_REQ], [])dnl
54            boost_version_major=0
55            boost_version_minor=0
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])
64   [^\$[a-zA-Z_]+$],
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']])
72          ;;
73      esac
75   [m4_fatal(Invalid argument: `$1')]
76 )dnl
77 AC_ARG_WITH([boost],
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],
83     [boost_cv_inc_path],
84     [boost_cv_inc_path=no
85 AC_LANG_PUSH([C++])dnl
86     boost_subminor_chk=
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
94     do
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
106 #endif
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
114 #endif
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
120         fi
121         break
122       fi
123     done
124 AC_LANG_POP([C++])dnl
125     ])
126     case $boost_cv_inc_path in #(
127       no)
128         AC_MSG_ERROR([Could not find Boost headers[]BOOST_VERSION_REQ])
129         ;;#(
130       yes)
131         BOOST_CPPFLAGS=
132         ;;#(
133       *)
134         BOOST_CPPFLAGS="-I$boost_cv_inc_path"
135         ;;
136     esac
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"`
146     ])
147 m4_popdef([BOOST_VERSION_REQ])dnl
148 ])# BOOST_REQUIRE
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],
213   [Boost_lib=no
214   case "$2" in #(
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;;
218   esac
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";;
222   esac
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.
226   test -z "$libext" &&
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
251   boost_failed_libs=
252 # Don't bother to ident the 6 nested for loops, only the 2 innermost ones
253 # matter.
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
258   for boost_lib in \
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_
264   do
265     # Avoid testing twice the same lib
266     case $boost_failed_libs in #(
267       *@$boost_lib@*) continue;;
268     esac
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
276     do
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           test -e "$Boost_lib_LIBS" || continue;; #(
284         *) # No: use -lboost_foo to find the shared library.
285           Boost_lib_LIBS="-l$boost_lib";;
286       esac
287       boost_save_LIBS=$LIBS
288       LIBS="$Boost_lib_LIBS $LIBS"
289       test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"
290 dnl First argument of AC_LINK_IFELSE left empty because the test file is
291 dnl generated only once above (before we start the for loops).
292       _BOOST_AC_LINK_IFELSE([],
293                             [Boost_lib=yes], [Boost_lib=no])
294       ac_objext=$boost_save_ac_objext
295       LDFLAGS=$boost_save_LDFLAGS
296       LIBS=$boost_save_LIBS
297       if test x"$Boost_lib" = xyes; then
298         Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath"
299         break 6
300       else
301         boost_failed_libs="$boost_failed_libs@$boost_lib@"
302       fi
303     done
304   done
305 done
306 done
307 done
308 done
309 rm -f conftest.$ac_objext
311 case $Boost_lib in #(
312   no) AC_MSG_ERROR([Could not find the flags to link with Boost $1])
313     ;;
314 esac
315 AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS])
316 AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS])
317 CPPFLAGS=$boost_save_CPPFLAGS
318 AS_VAR_POPDEF([Boost_lib])dnl
319 AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl
320 AS_VAR_POPDEF([Boost_lib_LIBS])dnl
321 AC_LANG_POP([C++])dnl
322 ])# BOOST_FIND_LIB
325 # --------------------------------------- #
326 # Checks for the various Boost libraries. #
327 # --------------------------------------- #
329 # List of boost libraries: http://www.boost.org/libs/libraries.htm
330 # The page http://beta.boost.org/doc/libs is useful: it gives the first release
331 # version of each library (among other things).
334 # BOOST_BIND()
335 # ------------
336 # Look for Boost.Bind
337 AC_DEFUN([BOOST_BIND],
338 [BOOST_FIND_HEADER([boost/bind.hpp])])
341 # BOOST_CONVERSION()
342 # ------------------
343 # Look for Boost.Conversion (cast / lexical_cast)
344 AC_DEFUN([BOOST_CONVERSION],
345 [BOOST_FIND_HEADER([boost/cast.hpp])
346 BOOST_FIND_HEADER([boost/lexical_cast.hpp])
347 ])# BOOST_CONVERSION
350 # BOOST_DATE_TIME([PREFERRED-RT-OPT])
351 # -----------------------------------
352 # Look for Boost.Date_Time.  For the documentation of PREFERRED-RT-OPT, see the
353 # documentation of BOOST_FIND_LIB above.
354 AC_DEFUN([BOOST_DATE_TIME],
355 [BOOST_FIND_LIB([date_time], [$1],
356                 [boost/date_time/posix_time/posix_time.hpp],
357                 [boost::posix_time::ptime t;])
358 ])# BOOST_DATE_TIME
361 # BOOST_FILESYSTEM([PREFERRED-RT-OPT])
362 # ------------------------------------
363 # Look for Boost.Filesystem.  For the documentation of PREFERRED-RT-OPT, see the
364 # documentation of BOOST_FIND_LIB above.
365 # Do not check for boost/filesystem.hpp because this file was introduced in 1.34.
366 AC_DEFUN([BOOST_FILESYSTEM],
367 [BOOST_FIND_LIB([filesystem], [$1],
368                 [boost/filesystem/path.hpp], [boost::filesystem::path p;])
369 ])# BOOST_FILESYSTEM
372 # BOOST_FOREACH()
373 # ---------------
374 # Look for Boost.Foreach
375 AC_DEFUN([BOOST_FOREACH],
376 [BOOST_FIND_HEADER([boost/foreach.hpp])])
379 # BOOST_FORMAT()
380 # --------------
381 # Look for Boost.Format
382 # Note: we can't check for boost/format/format_fwd.hpp because the header isn't
383 # standalone.  It can't be compiled because it triggers the following error:
384 # boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std'
385 #                                                  does not name a type
386 AC_DEFUN([BOOST_FORMAT],
387 [BOOST_FIND_HEADER([boost/format.hpp])])
390 # BOOST_FUNCTION()
391 # ----------------
392 # Look for Boost.Function
393 AC_DEFUN([BOOST_FUNCTION],
394 [BOOST_FIND_HEADER([boost/function.hpp])])
397 # BOOST_GRAPH([PREFERRED-RT-OPT])
398 # -------------------------------
399 # Look for Boost.Graphs.  For the documentation of PREFERRED-RT-OPT, see the
400 # documentation of BOOST_FIND_LIB above.
401 AC_DEFUN([BOOST_GRAPH],
402 [BOOST_FIND_LIB([graph], [$1],
403                 [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;])
404 ])# BOOST_GRAPH
407 # BOOST_IOSTREAMS([PREFERRED-RT-OPT])
408 # -------------------------------
409 # Look for Boost.IOStreams.  For the documentation of PREFERRED-RT-OPT, see the
410 # documentation of BOOST_FIND_LIB above.
411 AC_DEFUN([BOOST_IOSTREAMS],
412 [BOOST_FIND_LIB([iostreams], [$1],
413                 [boost/iostreams/device/file_descriptor.hpp],
414                 [boost::iostreams::file_descriptor fd(0); fd.close();])
415 ])# BOOST_IOSTREAMS
418 # BOOST_HASH()
419 # ------------
420 # Look for Boost.Functional/Hash
421 AC_DEFUN([BOOST_HASH],
422 [BOOST_FIND_HEADER([boost/functional/hash.hpp])])
425 # BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT])
426 # -----------------------------------------
427 # Look for Boost.Program_options.  For the documentation of PREFERRED-RT-OPT, see
428 # the documentation of BOOST_FIND_LIB above.
429 AC_DEFUN([BOOST_PROGRAM_OPTIONS],
430 [BOOST_FIND_LIB([program_options], [$1],
431                 [boost/program_options.hpp],
432                 [boost::program_options::options_description d("test");])
433 ])# BOOST_PROGRAM_OPTIONS
436 # BOOST_REF()
437 # -----------
438 # Look for Boost.Ref
439 AC_DEFUN([BOOST_REF],
440 [BOOST_FIND_HEADER([boost/ref.hpp])])
443 # BOOST_REGEX([PREFERRED-RT-OPT])
444 # -------------------------------
445 # Look for Boost.Regex.  For the documentation of PREFERRED-RT-OPT, see the
446 # documentation of BOOST_FIND_LIB above.
447 AC_DEFUN([BOOST_REGEX],
448 [BOOST_FIND_LIB([regex], [$1],
449                 [boost/regex.hpp],
450                 [boost::regex exp("*"); boost::regex_match("foo", exp);])
451 ])# BOOST_REGEX
454 # BOOST_SIGNALS([PREFERRED-RT-OPT])
455 # ---------------------------------
456 # Look for Boost.Signals.  For the documentation of PREFERRED-RT-OPT, see the
457 # documentation of BOOST_FIND_LIB above.
458 AC_DEFUN([BOOST_SIGNALS],
459 [BOOST_FIND_LIB([signals], [$1],
460                 [boost/signal.hpp],
461                 [boost::signal<void ()> s;])
462 ])# BOOST_SIGNALS
465 # BOOST_SMART_PTR()
466 # -----------------
467 # Look for Boost.SmartPtr
468 AC_DEFUN([BOOST_SMART_PTR],
469 [BOOST_FIND_HEADER([boost/scoped_ptr.hpp])
470 BOOST_FIND_HEADER([boost/shared_ptr.hpp])
474 # BOOST_STRING_ALGO()
475 # -------------------
476 # Look for Boost.StringAlgo
477 AC_DEFUN([BOOST_STRING_ALGO],
478 [BOOST_FIND_HEADER([boost/algorithm/string.hpp])
482 # BOOST_TEST([PREFERRED-RT-OPT])
483 # ------------------------------
484 # Look for Boost.Test.  For the documentation of PREFERRED-RT-OPT, see the
485 # documentation of BOOST_FIND_LIB above.
486 AC_DEFUN([BOOST_TEST],
487 [m4_pattern_allow([^BOOST_CHECK$])dnl
488 BOOST_FIND_LIB([unit_test_framework], [$1],
489                [boost/test/unit_test.hpp], [BOOST_CHECK(2==2);])
490 ])# BOOST_TEST
493 # BOOST_THREADS([PREFERRED-RT-OPT])
494 # ---------------------------------
495 # Look for Boost.Thread.  For the documentation of PREFERRED-RT-OPT, see the
496 # documentation of BOOST_FIND_LIB above.
497 # FIXME: Provide an alias "BOOST_THREAD".
498 AC_DEFUN([BOOST_THREADS],
499 [dnl Having the pthread flag is required at least on GCC3 where
500 dnl boost/thread.hpp would complain if we try to compile without
501 dnl -pthread on GNU/Linux.
502 AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
503 boost_threads_save_LIBS=$LIBS
504 boost_threads_save_CPPFLAGS=$CPPFLAGS
505 LIBS="$LIBS $boost_cv_pthread_flag"
506 # Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
507 # boost/thread.hpp will trigger a #error if -pthread isn't used:
508 #   boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
509 #   is not turned on. Please set the correct command line options for
510 #   threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
511 CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag"
512 BOOST_FIND_LIB([thread], [$1],
513                 [boost/thread.hpp], [boost::thread t; boost::mutex m;])
514 BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $boost_cv_pthread_flag"
515 BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag"
516 LIBS=$boost_threads_save_LIBS
517 CPPFLAGS=$boost_threads_save_CPPFLAGS
518 ])# BOOST_THREADS
521 # BOOST_TOKENIZER()
522 # -----------------
523 # Look for Boost.Tokenizer
524 AC_DEFUN([BOOST_TOKENIZER],
525 [BOOST_FIND_HEADER([boost/tokenizer.hpp])])
528 # BOOST_TRIBOOL()
529 # ---------------
530 # Look for Boost.Tribool
531 AC_DEFUN([BOOST_TRIBOOL],
532 [BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp])
533 BOOST_FIND_HEADER([boost/logic/tribool.hpp])
537 # BOOST_TUPLE()
538 # -------------
539 # Look for Boost.Tuple
540 AC_DEFUN([BOOST_TUPLE],
541 [BOOST_FIND_HEADER([boost/tuple/tuple.hpp])])
544 # BOOST_UTILITY()
545 # ---------------
546 # Look for Boost.Utility (noncopyable, result_of, base-from-member idiom,
547 # etc.)
548 AC_DEFUN([BOOST_UTILITY],
549 [BOOST_FIND_HEADER([boost/utility.hpp])])
552 # BOOST_VARIANT()
553 # ---------------
554 # Look for Boost.Variant.
555 AC_DEFUN([BOOST_VARIANT],
556 [BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp])
557 BOOST_FIND_HEADER([boost/variant.hpp])])
560 # BOOST_WAVE([PREFERRED-RT-OPT])
561 # ------------------------------
562 # Look for Boost.Wave.  For the documentation of PREFERRED-RT-OPT, see the
563 # documentation of BOOST_FIND_LIB above.
564 AC_DEFUN([BOOST_WAVE],
565 [BOOST_FIND_LIB([wave], [$1],
566                 [boost/wave.hpp],
567                 [boost::wave::token_id id; get_token_name(id);])])
570 # ----------------- #
571 # Internal helpers. #
572 # ----------------- #
575 # _BOOST_PTHREAD_FLAG()
576 # ---------------------
577 # Internal helper for BOOST_THREADS.  Based on ACX_PTHREAD:
578 # http://autoconf-archive.cryp.to/acx_pthread.html
579 AC_DEFUN([_BOOST_PTHREAD_FLAG],
580 [AC_REQUIRE([AC_PROG_CXX])dnl
581 AC_REQUIRE([AC_CANONICAL_HOST])dnl
582 AC_LANG_PUSH([C++])dnl
583 AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag],
584 [ boost_cv_pthread_flag=
585   # The ordering *is* (sometimes) important.  Some notes on the
586   # individual items follow:
587   # (none): in case threads are in libc; should be tried before -Kthread and
588   #       other compiler flags to prevent continual compiler warnings
589   # -lpthreads: AIX (must check this before -lpthread)
590   # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
591   # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
592   # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
593   # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
594   # -pthreads: Solaris/GCC
595   # -mthreads: MinGW32/GCC, Lynx/GCC
596   # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
597   #      doesn't hurt to check since this sometimes defines pthreads too;
598   #      also defines -D_REENTRANT)
599   #      ... -mt is also the pthreads flag for HP/aCC
600   # -lpthread: GNU Linux, etc.
601   # --thread-safe: KAI C++
602   case $host_os in #(
603     *solaris*)
604       # On Solaris (at least, for some versions), libc contains stubbed
605       # (non-functional) versions of the pthreads routines, so link-based
606       # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
607       # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
608       # a function called by this macro, so we could check for that, but
609       # who knows whether they'll stub that too in a future libc.)  So,
610       # we'll just look for -pthreads and -lpthread first:
611       boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #(
612     *)
613       boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \
614                            -pthreads -mthreads -lpthread --thread-safe -mt";;
615   esac
616   # Generate the test file.
617   AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <pthread.h>],
618     [pthread_t th; pthread_join(th, 0);
619     pthread_attr_init(0); pthread_cleanup_push(0, 0);
620     pthread_create(0,0,0,0); pthread_cleanup_pop(0);])])
621   for boost_pthread_flag in '' $boost_pthread_flags; do
622     boost_pthread_ok=false
623 dnl Re-use the test file already generated.
624     boost_pthreads__save_LIBS=$LIBS
625     LIBS="$LIBS $boost_pthread_flag"
626     AC_LINK_IFELSE([],
627       [if grep ".*$boost_pthread_flag" conftest.err; then
628          echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD
629        else
630          boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag
631        fi])
632     LIBS=$boost_pthreads__save_LIBS
633     $boost_pthread_ok && break
634   done
636 AC_LANG_POP([C++])dnl
637 ])# _BOOST_PTHREAD_FLAG
640 # _BOOST_gcc_test(MAJOR, MINOR)
641 # -----------------------------
642 # Internal helper for _BOOST_FIND_COMPILER_TAG.
643 m4_define([_BOOST_gcc_test],
644 ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl
647 # _BOOST_FIND_COMPILER_TAG()
648 # --------------------------
649 # Internal.  When Boost is installed without --layout=system, each library
650 # filename will hold a suffix that encodes the compiler used during the
651 # build.  The Boost build system seems to call this a `tag'.
652 AC_DEFUN([_BOOST_FIND_COMPILER_TAG],
653 [AC_REQUIRE([AC_PROG_CXX])dnl
654 AC_CACHE_CHECK([for the toolset name used by Boost for $CXX], [boost_cv_lib_tag],
655 [AC_LANG_PUSH([C++])dnl
656   boost_cv_lib_tag=unknown
657   # The following tests are mostly inspired by boost/config/auto_link.hpp
658   # The list is sorted to most recent/common to oldest compiler (in order
659   # to increase the likelihood of finding the right compiler with the
660   # least number of compilation attempt).
661   # Beware that some tests are sensible to the order (for instance, we must
662   # look for MinGW before looking for GCC3).
663   # I used one compilation test per compiler with a #error to recognize
664   # each compiler so that it works even when cross-compiling (let me know
665   # if you know a better approach).
666   # Known missing tags (known from Boost's tools/build/v2/tools/common.jam):
667   #   como, edg, kcc, bck, mp, sw, tru, xlc
668   # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines
669   # the same defines as GCC's).
670   # TODO: Move the test on GCC 4.3 up once it's released.
671   for i in \
672     _BOOST_gcc_test(4, 2) \
673     _BOOST_gcc_test(4, 1) \
674     _BOOST_gcc_test(4, 0) \
675     "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \
676      && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
677          || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \
678     _BOOST_gcc_test(3, 4) \
679     _BOOST_gcc_test(3, 3) \
680     "defined _MSC_VER && _MSC_VER >= 1400 @ vc80" \
681     _BOOST_gcc_test(3, 2) \
682     "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \
683     _BOOST_gcc_test(3, 1) \
684     _BOOST_gcc_test(3, 0) \
685     "defined __BORLANDC__ @ bcb" \
686     "defined __ICC && (defined __unix || defined __unix__) @ il" \
687     "defined __ICL @ iw" \
688     "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \
689     _BOOST_gcc_test(4, 3) \
690     _BOOST_gcc_test(2, 95) \
691     "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \
692     "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \
693     "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \
694     "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8"
695   do
696     boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '`
697     boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'`
698     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
699 #if $boost_tag_test
700 /* OK */
701 #else
702 # error $boost_tag_test
703 #endif
704 ]])], [boost_cv_lib_tag=$boost_tag; break], [])
705   done
706 AC_LANG_POP([C++])dnl
708   if test x"$boost_cv_lib_tag" = xunknown; then
709     AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]])
710     boost_cv_lib_tag=
711   fi
712 ])# _BOOST_FIND_COMPILER_TAG
715 # _BOOST_GUESS_WHETHER_TO_USE_MT()
716 # --------------------------------
717 # Compile a small test to try to guess whether we should favor MT (Multi
718 # Thread) flavors of Boost.  Sets boost_guess_use_mt accordingly.
719 AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT],
720 [# Check whether we do better use `mt' even though we weren't ask to.
721 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
722 #if defined _REENTRANT || defined _MT || defined __MT__
723 /* use -mt */
724 #else
725 # error MT not needed
726 #endif
727 ]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false])
730 # _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
731 # -------------------------------------------------------------------
732 # Fork of _AC_LINK_IFELSE that preserves conftest.o across calls.  Fragile,
733 # will break when Autoconf changes its internals.  Requires that you manually
734 # rm -f conftest.$ac_objext in between to really different tests, otherwise
735 # you will try to link a conftest.o left behind by a previous test.
736 # Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this
737 # macro)
738 m4_define([_BOOST_AC_LINK_IFELSE],
739 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
740 rm -f conftest$ac_exeext
741 boost_ac_ext_save=$ac_ext
742 boost_use_source=:
743 # If we already have a .o, re-use it.  We change $ac_ext so that $ac_link
744 # tries to link the existing object file instead of compiling from source.
745 test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false &&
746   _AS_ECHO_LOG([re-using the existing conftest.$ac_objext])
747 AS_IF([_AC_DO_STDERR($ac_link) && {
748          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
749          test ! -s conftest.err
750        } && test -s conftest$ac_exeext && {
751          test "$cross_compiling" = yes ||
752          $as_executable_p conftest$ac_exeext
753 dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough.
754        }],
755       [$2],
756       [if $boost_use_source; then
757          _AC_MSG_LOG_CONFTEST
758        fi
759        $3])
760 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
761 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
762 dnl as it would interfere with the next link command.
763 rm -f core conftest.err conftest_ipa8_conftest.oo \
764       conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl
765 ])# _BOOST_AC_LINK_IFELSE