Mention the Libtool dependency in the M4 file.
[boost.m4.git] / build-aux / boost.m4
blobb53c5c5ceac0f9b60f56c86acb0b79ff9d9e0757
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 3
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   boost_save_ac_objext=$ac_objext
225   # Generate the test file.
226   AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <$3>], [$4])])
227 dnl Optimization hacks: compiling C++ is slow, especially with Boost.  What
228 dnl we're trying to do here is guess the right combination of link flags
229 dnl (LIBS / LDFLAGS) to use a given library.  This can take several
230 dnl iterations before it succeeds and is thus *very* slow.  So what we do
231 dnl instead is that we compile the code first (and thus get an object file,
232 dnl typically conftest.o).  Then we try various combinations of link flags
233 dnl until we succeed to link conftest.o in an executable.  The problem is
234 dnl that the various TRY_LINK / COMPILE_IFELSE macros of Autoconf always
235 dnl remove all the temporary files including conftest.o.  So the trick here
236 dnl is to temporarily change the value of ac_objext so that conftest.o is
237 dnl preserved accross tests.  This is obviously fragile and I will burn in
238 dnl hell for not respecting Autoconf's documented interfaces, but in the
239 dnl mean time, it optimizes the macro by a factor of 5 to 30.
240 dnl Another small optimization: the first argument of AC_COMPILE_IFELSE left
241 dnl empty because the test file is generated only once above (before we
242 dnl start the for loops).
243   AC_COMPILE_IFELSE([],
244     [ac_objext=do_not_rm_me_plz],
245     [AC_MSG_ERROR([Cannot compile a test that uses Boost $1])])
246   ac_objext=$boost_save_ac_objext
247   boost_failed_libs=
248 # Don't bother to ident the 6 nested for loops, only the 2 innermost ones
249 # matter.
250 for boost_tag_ in -$boost_cv_lib_tag ''; do
251 for boost_ver_ in -$boost_cv_lib_version ''; do
252 for boost_mt_ in $boost_mt -mt ''; do
253 for boost_rtopt_ in $boost_rtopt '' -d; do
254   for boost_lib in \
255     boost_$1$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ \
256     boost_$1$boost_tag_$boost_mt_$boost_ver_ \
257     boost_$1$boost_tag_$boost_rtopt_$boost_ver_ \
258     boost_$1$boost_tag_$boost_mt_ \
259     boost_$1$boost_tag_$boost_ver_
260   do
261     # Avoid testing twice the same lib
262     case $boost_failed_libs in #(
263       *@$boost_lib@*) continue;;
264     esac
265     boost_save_LIBS=$LIBS
266     LIBS="-l$boost_lib $LIBS"
267     # If with_boost is empty, we'll search in /lib first, which is not quite
268     # right so instead we'll try to a location based on where the headers are.
269     boost_tmp_lib=$with_boost
270     test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include}
271     for boost_ldpath in "$boost_tmp_lib/lib" '' \
272              /opt/local/lib /usr/local/lib /opt/lib /usr/lib \
273              "$with_boost" C:/Boost/lib /lib /usr/lib64 /lib64
274     do
275       test -e "$boost_ldpath" || continue
276       boost_save_LDFLAGS=$LDFLAGS
277       test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"
278 dnl First argument of AC_LINK_IFELSE left empty because the test file is
279 dnl generated only once above (before we start the for loops).
280       _BOOST_AC_LINK_IFELSE([],
281                             [Boost_lib=yes], [Boost_lib=no])
282       ac_objext=$boost_save_ac_objext
283       LDFLAGS=$boost_save_LDFLAGS
284       if test x"$Boost_lib" = xyes; then
285         Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath"
286         Boost_lib_LIBS="-l$boost_lib"
287         LIBS=$boost_save_LIBS
288         break 6
289       else
290         boost_failed_libs="$boost_failed_libs@$boost_lib@"
291       fi
292     done
293     LIBS=$boost_save_LIBS
294   done
295 done
296 done
297 done
298 done
299 rm -f conftest.$ac_objext
301 AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS])
302 AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS])
303 CPPFLAGS=$boost_save_CPPFLAGS
304 AS_VAR_POPDEF([Boost_lib])dnl
305 AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl
306 AS_VAR_POPDEF([Boost_lib_LIBS])dnl
307 AC_LANG_POP([C++])dnl
308 ])# BOOST_FIND_LIB
311 # --------------------------------------- #
312 # Checks for the various Boost libraries. #
313 # --------------------------------------- #
315 # List of boost libraries: http://www.boost.org/libs/libraries.htm
316 # The page http://beta.boost.org/doc/libs is useful: it gives the first release
317 # version of each library (among other things).
320 # BOOST_BIND()
321 # ------------
322 # Look for Boost.Bind
323 AC_DEFUN([BOOST_BIND],
324 [BOOST_FIND_HEADER([boost/bind.hpp])])
327 # BOOST_CONVERSION()
328 # ------------------
329 # Look for Boost.Conversion (cast / lexical_cast)
330 AC_DEFUN([BOOST_CONVERSION],
331 [BOOST_FIND_HEADER([boost/cast.hpp])
332 BOOST_FIND_HEADER([boost/lexical_cast.hpp])
333 ])# BOOST_CONVERSION
336 # BOOST_DATE_TIME([PREFERRED-RT-OPT])
337 # -----------------------------------
338 # Look for Boost.Date_Time.  For the documentation of PREFERRED-RT-OPT, see the
339 # documentation of BOOST_FIND_LIB above.
340 AC_DEFUN([BOOST_DATE_TIME],
341 [BOOST_FIND_LIB([date_time], [$1],
342                 [boost/date_time/posix_time/posix_time.hpp],
343                 [boost::posix_time::ptime t;])
344 ])# BOOST_DATE_TIME
347 # BOOST_FILESYSTEM([PREFERRED-RT-OPT])
348 # ------------------------------------
349 # Look for Boost.Filesystem.  For the documentation of PREFERRED-RT-OPT, see the
350 # documentation of BOOST_FIND_LIB above.
351 # Do not check for boost/filesystem.hpp because this file was introduced in 1.34.
352 AC_DEFUN([BOOST_FILESYSTEM],
353 [BOOST_FIND_LIB([filesystem], [$1],
354                 [boost/filesystem/path.hpp], [boost::filesystem::path p;])
355 ])# BOOST_FILESYSTEM
358 # BOOST_FOREACH()
359 # ---------------
360 # Look for Boost.Foreach
361 AC_DEFUN([BOOST_FOREACH],
362 [BOOST_FIND_HEADER([boost/foreach.hpp])])
365 # BOOST_FORMAT()
366 # --------------
367 # Look for Boost.Format
368 # Note: we can't check for boost/format/format_fwd.hpp because the header isn't
369 # standalone.  It can't be compiled because it triggers the following error:
370 # boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std'
371 #                                                  does not name a type
372 AC_DEFUN([BOOST_FORMAT],
373 [BOOST_FIND_HEADER([boost/format.hpp])])
376 # BOOST_FUNCTION()
377 # ----------------
378 # Look for Boost.Function
379 AC_DEFUN([BOOST_FUNCTION],
380 [BOOST_FIND_HEADER([boost/function.hpp])])
383 # BOOST_GRAPH([PREFERRED-RT-OPT])
384 # -------------------------------
385 # Look for Boost.Graphs.  For the documentation of PREFERRED-RT-OPT, see the
386 # documentation of BOOST_FIND_LIB above.
387 AC_DEFUN([BOOST_GRAPH],
388 [BOOST_FIND_LIB([graph], [$1],
389                 [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;])
390 ])# BOOST_GRAPH
393 # BOOST_IOSTREAMS([PREFERRED-RT-OPT])
394 # -------------------------------
395 # Look for Boost.IOStreams.  For the documentation of PREFERRED-RT-OPT, see the
396 # documentation of BOOST_FIND_LIB above.
397 AC_DEFUN([BOOST_IOSTREAMS],
398 [BOOST_FIND_LIB([iostreams], [$1],
399                 [boost/iostreams/device/file_descriptor.hpp],
400                 [boost::iostreams::file_descriptor fd(0); fd.close();])
401 ])# BOOST_IOSTREAMS
404 # BOOST_HASH()
405 # ------------
406 # Look for Boost.Functional/Hash
407 AC_DEFUN([BOOST_HASH],
408 [BOOST_FIND_HEADER([boost/functional/hash.hpp])])
411 # BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT])
412 # -----------------------------------------
413 # Look for Boost.Program_options.  For the documentation of PREFERRED-RT-OPT, see
414 # the documentation of BOOST_FIND_LIB above.
415 AC_DEFUN([BOOST_PROGRAM_OPTIONS],
416 [BOOST_FIND_LIB([program_options], [$1],
417                 [boost/program_options.hpp],
418                 [boost::program_options::options_description d("test");])
419 ])# BOOST_PROGRAM_OPTIONS
422 # BOOST_REF()
423 # -----------
424 # Look for Boost.Ref
425 AC_DEFUN([BOOST_REF],
426 [BOOST_FIND_HEADER([boost/ref.hpp])])
429 # BOOST_REGEX([PREFERRED-RT-OPT])
430 # -------------------------------
431 # Look for Boost.Regex.  For the documentation of PREFERRED-RT-OPT, see the
432 # documentation of BOOST_FIND_LIB above.
433 AC_DEFUN([BOOST_REGEX],
434 [BOOST_FIND_LIB([regex], [$1],
435                 [boost/regex.hpp],
436                 [boost::regex exp("*"); boost::regex_match("foo", exp);])
437 ])# BOOST_REGEX
440 # BOOST_SIGNALS([PREFERRED-RT-OPT])
441 # ---------------------------------
442 # Look for Boost.Signals.  For the documentation of PREFERRED-RT-OPT, see the
443 # documentation of BOOST_FIND_LIB above.
444 AC_DEFUN([BOOST_SIGNALS],
445 [BOOST_FIND_LIB([signals], [$1],
446                 [boost/signal.hpp],
447                 [boost::signal<void ()> s;])
448 ])# BOOST_SIGNALS
451 # BOOST_SMART_PTR()
452 # -----------------
453 # Look for Boost.SmartPtr
454 AC_DEFUN([BOOST_SMART_PTR],
455 [BOOST_FIND_HEADER([boost/scoped_ptr.hpp])
456 BOOST_FIND_HEADER([boost/shared_ptr.hpp])
460 # BOOST_STRING_ALGO()
461 # -------------------
462 # Look for Boost.StringAlgo
463 AC_DEFUN([BOOST_STRING_ALGO],
464 [BOOST_FIND_HEADER([boost/algorithm/string.hpp])
468 # BOOST_TEST([PREFERRED-RT-OPT])
469 # ------------------------------
470 # Look for Boost.Test.  For the documentation of PREFERRED-RT-OPT, see the
471 # documentation of BOOST_FIND_LIB above.
472 AC_DEFUN([BOOST_TEST],
473 [m4_pattern_allow([^BOOST_CHECK$])dnl
474 BOOST_FIND_LIB([unit_test_framework], [$1],
475                [boost/test/unit_test.hpp], [BOOST_CHECK(2==2);])
476 ])# BOOST_TEST
479 # BOOST_TRIBOOL()
480 # ---------------
481 # Look for Boost.Tribool
482 AC_DEFUN([BOOST_TRIBOOL],
483 [BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp])
484 BOOST_FIND_HEADER([boost/logic/tribool.hpp])
488 # BOOST_THREADS([PREFERRED-RT-OPT])
489 # ---------------------------------
490 # Look for Boost.Thread.  For the documentation of PREFERRED-RT-OPT, see the
491 # documentation of BOOST_FIND_LIB above.
492 # FIXME: Provide an alias "BOOST_THREAD".
493 AC_DEFUN([BOOST_THREADS],
494 [dnl Having the pthread flag is required at least on GCC3 where
495 dnl boost/thread.hpp would complain if we try to compile without
496 dnl -pthread on GNU/Linux.
497 AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
498 boost_threads_save_LIBS=$LIBS
499 boost_threads_save_CPPFLAGS=$CPPFLAGS
500 LIBS="$LIBS $boost_cv_pthread_flag"
501 # Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
502 # boost/thread.hpp will trigger a #error if -pthread isn't used:
503 #   boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
504 #   is not turned on. Please set the correct command line options for
505 #   threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
506 CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag"
507 BOOST_FIND_LIB([thread], [$1],
508                 [boost/thread.hpp], [boost::thread t; boost::mutex m;])
509 BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $boost_cv_pthread_flag"
510 BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag"
511 LIBS=$boost_threads_save_LIBS
512 CPPFLAGS=$boost_threads_save_CPPFLAGS
513 ])# BOOST_THREADS
516 # BOOST_TUPLE()
517 # -------------
518 # Look for Boost.Tuple
519 AC_DEFUN([BOOST_TUPLE],
520 [BOOST_FIND_HEADER([boost/tuple/tuple.hpp])])
523 # BOOST_UTILITY()
524 # ---------------
525 # Look for Boost.Utility (noncopyable, result_of, base-from-member idiom,
526 # etc.)
527 AC_DEFUN([BOOST_UTILITY],
528 [BOOST_FIND_HEADER([boost/utility.hpp])])
531 # BOOST_VARIANT()
532 # ---------------
533 # Look for Boost.Variant.
534 AC_DEFUN([BOOST_VARIANT],
535 [BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp])
536 BOOST_FIND_HEADER([boost/variant.hpp])])
539 # BOOST_WAVE([PREFERRED-RT-OPT])
540 # ------------------------------
541 # Look for Boost.Wave.  For the documentation of PREFERRED-RT-OPT, see the
542 # documentation of BOOST_FIND_LIB above.
543 AC_DEFUN([BOOST_WAVE],
544 [BOOST_FIND_LIB([wave], [$1],
545                 [boost/wave.hpp],
546                 [boost::wave::token_id id; get_token_name(id);])])
549 # ----------------- #
550 # Internal helpers. #
551 # ----------------- #
554 # _BOOST_PTHREAD_FLAG()
555 # ---------------------
556 # Internal helper for BOOST_THREADS.  Based on ACX_PTHREAD:
557 # http://autoconf-archive.cryp.to/acx_pthread.html
558 AC_DEFUN([_BOOST_PTHREAD_FLAG],
559 [AC_REQUIRE([AC_PROG_CXX])dnl
560 AC_REQUIRE([AC_CANONICAL_HOST])dnl
561 AC_LANG_PUSH([C++])dnl
562 AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag],
563 [ boost_cv_pthread_flag=
564   # The ordering *is* (sometimes) important.  Some notes on the
565   # individual items follow:
566   # (none): in case threads are in libc; should be tried before -Kthread and
567   #       other compiler flags to prevent continual compiler warnings
568   # -lpthreads: AIX (must check this before -lpthread)
569   # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
570   # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
571   # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
572   # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
573   # -pthreads: Solaris/GCC
574   # -mthreads: MinGW32/GCC, Lynx/GCC
575   # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
576   #      doesn't hurt to check since this sometimes defines pthreads too;
577   #      also defines -D_REENTRANT)
578   #      ... -mt is also the pthreads flag for HP/aCC
579   # -lpthread: GNU Linux, etc.
580   # --thread-safe: KAI C++
581   case $host_os in #(
582     *solaris*)
583       # On Solaris (at least, for some versions), libc contains stubbed
584       # (non-functional) versions of the pthreads routines, so link-based
585       # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
586       # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
587       # a function called by this macro, so we could check for that, but
588       # who knows whether they'll stub that too in a future libc.)  So,
589       # we'll just look for -pthreads and -lpthread first:
590       boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #(
591     *)
592       boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \
593                            -pthreads -mthreads -lpthread --thread-safe -mt";;
594   esac
595   # Generate the test file.
596   AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <pthread.h>],
597     [pthread_t th; pthread_join(th, 0);
598     pthread_attr_init(0); pthread_cleanup_push(0, 0);
599     pthread_create(0,0,0,0); pthread_cleanup_pop(0);])])
600   for boost_pthread_flag in '' $boost_pthread_flags; do
601     boost_pthread_ok=false
602 dnl Re-use the test file already generated.
603     boost_pthreads__save_LIBS=$LIBS
604     LIBS="$LIBS $boost_pthread_flag"
605     AC_LINK_IFELSE([],
606       [if grep ".*$boost_pthread_flag" conftest.err; then
607          echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD
608        else
609          boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag
610        fi])
611     LIBS=$boost_pthreads__save_LIBS
612     $boost_pthread_ok && break
613   done
615 AC_LANG_POP([C++])dnl
616 ])# _BOOST_PTHREAD_FLAG
619 # _BOOST_gcc_test(MAJOR, MINOR)
620 # -----------------------------
621 # Internal helper for _BOOST_FIND_COMPILER_TAG.
622 m4_define([_BOOST_gcc_test],
623 ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl
626 # _BOOST_FIND_COMPILER_TAG()
627 # --------------------------
628 # Internal.  When Boost is installed without --layout=system, each library
629 # filename will hold a suffix that encodes the compiler used during the
630 # build.  The Boost build system seems to call this a `tag'.
631 AC_DEFUN([_BOOST_FIND_COMPILER_TAG],
632 [AC_REQUIRE([AC_PROG_CXX])dnl
633 AC_CACHE_CHECK([for the toolset name used by Boost for $CXX], [boost_cv_lib_tag],
634 [AC_LANG_PUSH([C++])dnl
635   boost_cv_lib_tag=unknown
636   # The following tests are mostly inspired by boost/config/auto_link.hpp
637   # The list is sorted to most recent/common to oldest compiler (in order
638   # to increase the likelihood of finding the right compiler with the
639   # least number of compilation attempt).
640   # Beware that some tests are sensible to the order (for instance, we must
641   # look for MinGW before looking for GCC3).
642   # I used one compilation test per compiler with a #error to recognize
643   # each compiler so that it works even when cross-compiling (let me know
644   # if you know a better approach).
645   # Known missing tags (known from Boost's tools/build/v2/tools/common.jam):
646   #   como, edg, kcc, bck, mp, sw, tru, xlc
647   # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines
648   # the same defines as GCC's).
649   # TODO: Move the test on GCC 4.3 up once it's released.
650   for i in \
651     _BOOST_gcc_test(4, 2) \
652     _BOOST_gcc_test(4, 1) \
653     _BOOST_gcc_test(4, 0) \
654     "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \
655      && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
656          || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \
657     _BOOST_gcc_test(3, 4) \
658     _BOOST_gcc_test(3, 3) \
659     "defined _MSC_VER && _MSC_VER >= 1400 @ vc80" \
660     _BOOST_gcc_test(3, 2) \
661     "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \
662     _BOOST_gcc_test(3, 1) \
663     _BOOST_gcc_test(3, 0) \
664     "defined __BORLANDC__ @ bcb" \
665     "defined __ICC && (defined __unix || defined __unix__) @ il" \
666     "defined __ICL @ iw" \
667     "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \
668     _BOOST_gcc_test(4, 3) \
669     _BOOST_gcc_test(2, 95) \
670     "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \
671     "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \
672     "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \
673     "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8"
674   do
675     boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '`
676     boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'`
677     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
678 #if $boost_tag_test
679 /* OK */
680 #else
681 # error $boost_tag_test
682 #endif
683 ]])], [boost_cv_lib_tag=$boost_tag; break], [])
684   done
685 AC_LANG_POP([C++])dnl
687   if test x"$boost_cv_lib_tag" = xunknown; then
688     AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]])
689     boost_cv_lib_tag=
690   fi
691 ])# _BOOST_FIND_COMPILER_TAG
694 # _BOOST_GUESS_WHETHER_TO_USE_MT()
695 # --------------------------------
696 # Compile a small test to try to guess whether we should favor MT (Multi
697 # Thread) flavors of Boost.  Sets boost_guess_use_mt accordingly.
698 AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT],
699 [# Check whether we do better use `mt' even though we weren't ask to.
700 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
701 #if defined _REENTRANT || defined _MT || defined __MT__
702 /* use -mt */
703 #else
704 # error MT not needed
705 #endif
706 ]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false])
709 # _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
710 # -------------------------------------------------------------------
711 # Fork of _AC_LINK_IFELSE that preserves conftest.o across calls.  Fragile,
712 # will break when Autoconf changes its internals.  Requires that you manually
713 # rm -f conftest.$ac_objext in between to really different tests, otherwise
714 # you will try to link a conftest.o left behind by a previous test.
715 # Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this
716 # macro)
717 m4_define([_BOOST_AC_LINK_IFELSE],
718 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
719 rm -f conftest$ac_exeext
720 boost_ac_ext_save=$ac_ext
721 boost_use_source=:
722 # If we already have a .o, re-use it.  We change $ac_ext so that $ac_link
723 # tries to link the existing object file instead of compiling from source.
724 test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false &&
725   _AS_ECHO_LOG([re-using the existing conftest.$ac_objext])
726 AS_IF([_AC_DO_STDERR($ac_link) && {
727          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
728          test ! -s conftest.err
729        } && test -s conftest$ac_exeext && {
730          test "$cross_compiling" = yes ||
731          $as_executable_p conftest$ac_exeext
732 dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough.
733        }],
734       [$2],
735       [if $boost_use_source; then
736          _AC_MSG_LOG_CONFTEST
737        fi
738        $3])
739 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
740 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
741 dnl as it would interfere with the next link command.
742 rm -f core conftest.err conftest_ipa8_conftest.oo \
743       conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl
744 ])# _BOOST_AC_LINK_IFELSE