source: m4/boost.m4@ 7535

Last change on this file since 7535 was 7535, checked in by Christoph Mayer, 14 years ago

-missing doxygen in interface

File size: 33.6 KB
Line 
1# boost.m4: Locate Boost headers and libraries for autoconf-based projects.
2# Copyright (C) 2007 Benoit Sigoure <tsuna@lrde.epita.fr>
3#
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.
8#
9# Additional permission under section 7 of the GNU General Public
10# License, version 3 ("GPLv3"):
11#
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.
15#
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.
20#
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/>.
23
24# serial 8
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
28
29# ------ #
30# README #
31# ------ #
32
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.
41
42m4_pattern_forbid([^_?BOOST_])
43
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
48# variable "$var".
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.
53AC_DEFUN([BOOST_REQUIRE],
54[dnl First find out what kind of argument we have.
55dnl If we have an empty argument, there is no constraint on the version of
56dnl Boost to use. If it's a literal version number, we can split it in M4 (so
57dnl the resulting configure script will be smaller/faster). Otherwise we do
58dnl the splitting at runtime.
59m4_bmatch([$1],
60 [^ *$], [m4_pushdef([BOOST_VERSION_REQ], [])dnl
61 boost_version_major=0
62 boost_version_minor=0
63 boost_version_subminor=0
64],
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])
70],
71 [^\$[a-zA-Z_]+$],
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']])
79 ;;
80 esac
81],
82 [m4_fatal(Invalid argument: `$1')]
83)dnl
84AC_ARG_WITH([boost],
85 [AS_HELP_STRING([--with-boost=DIR],
86 [prefix of Boost]BOOST_VERSION_REQ[ @<:@guess@:>@])])dnl
87AC_SUBST([DISTCHECK_CONFIGURE_FLAGS],
88 ["$DISTCHECK_CONFIGURE_FLAGS '--with-boost=$with_boost'"])
89 AC_CACHE_CHECK([for Boost headers[]BOOST_VERSION_REQ],
90 [boost_cv_inc_path],
91 [boost_cv_inc_path=no
92AC_LANG_PUSH([C++])dnl
93 boost_subminor_chk=
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
101 do
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-*
107 do
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"
116m4_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
120#endif
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
128#endif
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
134 fi
135 break 2
136 fi
137 done
138 done
139AC_LANG_POP([C++])dnl
140 ])
141 case $boost_cv_inc_path in #(
142 no)
143 AC_MSG_ERROR([Could not find Boost headers[]BOOST_VERSION_REQ])
144 ;;#(
145 yes)
146 BOOST_CPPFLAGS=
147 ;;#(
148 *)
149 BOOST_CPPFLAGS="-I$boost_cv_inc_path"
150 ;;
151 esac
152AC_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"`
161 ])
162 # e.g. "134" for 1_34_1 or "135" for 1_35
163 boost_major_version=`echo "$boost_cv_lib_version" | sed 's/_//;s/_.*//'`
164 case $boost_major_version in
165 '' | *[[^0-9]]*)
166 AC_MSG_ERROR([Invalid value: boost_major_version=$boost_major_version])
167 ;;
168 esac
169m4_popdef([BOOST_VERSION_REQ])dnl
170])# BOOST_REQUIRE
171
172
173# BOOST_FIND_HEADER([HEADER-NAME], [ACTION-IF-NOT-FOUND], [ACTION-IF-FOUND])
174# --------------------------------------------------------------------------
175# Wrapper around AC_CHECK_HEADER for Boost headers. Useful to check for
176# some parts of the Boost library which are only made of headers and don't
177# require linking (such as Boost.Foreach).
178#
179# Default ACTION-IF-NOT-FOUND: Fail with a fatal error.
180#
181# Default ACTION-IF-FOUND: define the preprocessor symbol HAVE_<HEADER-NAME> in
182# case of success # (where HEADER-NAME is written LIKE_THIS, e.g.,
183# HAVE_BOOST_FOREACH_HPP).
184AC_DEFUN([BOOST_FIND_HEADER],
185[AC_REQUIRE([BOOST_REQUIRE])dnl
186AC_LANG_PUSH([C++])dnl
187boost_save_CPPFLAGS=$CPPFLAGS
188CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
189AC_CHECK_HEADER([$1],
190 [m4_default([$3], [AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1],
191 [Define to 1 if you have <$1>])])],
192 [m4_default([$2], [AC_MSG_ERROR([cannot find $1])])])
193CPPFLAGS=$boost_save_CPPFLAGS
194AC_LANG_POP([C++])dnl
195])# BOOST_FIND_HEADER
196
197
198# BOOST_FIND_LIB([LIB-NAME], [PREFERRED-RT-OPT], [HEADER-NAME], [CXX-TEST],
199# [CXX-PROLOGUE])
200# -------------------------------------------------------------------------
201# Look for the Boost library LIB-NAME (e.g., LIB-NAME = `thread', for
202# libboost_thread). Check that HEADER-NAME works and check that
203# libboost_LIB-NAME can link with the code CXX-TEST. The optional argument
204# CXX-PROLOGUE can be used to include some C++ code before the `main'
205# function.
206#
207# Invokes BOOST_FIND_HEADER([HEADER-NAME]) (see above).
208#
209# Boost libraries typically come compiled with several flavors (with different
210# runtime options) so PREFERRED-RT-OPT is the preferred suffix. A suffix is one
211# or more of the following letters: sgdpn (in that order). s = static
212# runtime, d = debug build, g = debug/diagnostic runtime, p = STLPort build,
213# n = (unsure) STLPort build without iostreams from STLPort (it looks like `n'
214# must always be used along with `p'). Additionally, PREFERRED-RT-OPT can
215# start with `mt-' to indicate that there is a preference for multi-thread
216# builds. Some sample values for PREFERRED-RT-OPT: (nothing), mt, d, mt-d, gdp
217# ... If you want to make sure you have a specific version of Boost
218# (eg, >= 1.33) you *must* invoke BOOST_REQUIRE before this macro.
219AC_DEFUN([BOOST_FIND_LIB],
220[AC_REQUIRE([_BOOST_FIND_COMPILER_TAG])dnl
221AC_REQUIRE([BOOST_REQUIRE])dnl
222AC_REQUIRE([_BOOST_GUESS_WHETHER_TO_USE_MT])dnl
223AC_LANG_PUSH([C++])dnl
224AS_VAR_PUSHDEF([Boost_lib], [boost_cv_lib_$1])dnl
225AS_VAR_PUSHDEF([Boost_lib_LDFLAGS], [boost_cv_lib_$1_LDFLAGS])dnl
226AS_VAR_PUSHDEF([Boost_lib_LIBS], [boost_cv_lib_$1_LIBS])dnl
227BOOST_FIND_HEADER([$3])
228boost_save_CPPFLAGS=$CPPFLAGS
229CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
230# Now let's try to find the library. The algorithm is as follows: first look
231# for a given library name according to the user's PREFERRED-RT-OPT. For each
232# library name, we prefer to use the ones that carry the tag (toolset name).
233# Each library is searched through the various standard paths were Boost is
234# usually installed. If we can't find the standard variants, we try to
235# enforce -mt (for instance on MacOSX, libboost_threads.dylib doesn't exist
236# but there's -obviously- libboost_threads-mt.dylib).
237AC_CACHE_CHECK([for the Boost $1 library], [Boost_lib],
238 [Boost_lib=no
239 case "$2" in #(
240 mt | mt-) boost_mt=-mt; boost_rtopt=;; #(
241 mt* | mt-*) boost_mt=-mt; boost_rtopt=`expr "X$2" : 'Xmt-*\(.*\)'`;; #(
242 *) boost_mt=; boost_rtopt=$2;;
243 esac
244 # Find the proper debug variant depending on what we've been asked to find.
245 case $boost_rtopt in #(
246 *d*) boost_rt_d=$boost_rtopt;; #(
247 *[[sgpn]]*) # Insert the `d' at the right place (in between `sg' and `pn')
248 boost_rt_d=`echo "$boost_rtopt" | sed 's/\(s*g*\)\(p*n*\)/\1\2/'`;; #(
249 *) boost_rt_d='-d';;
250 esac
251 # If the PREFERRED-RT-OPT are not empty, prepend a `-'.
252 test -n "$boost_rtopt" && boost_rtopt="-$boost_rtopt"
253 $boost_guess_use_mt && boost_mt=-mt
254 # Look for the abs path the static archive.
255 # $libext is computed by Libtool but let's make sure it's non empty.
256 test -z "$libext" &&
257 AC_MSG_ERROR([the libext variable is empty, did you invoke Libtool?])
258 boost_save_ac_objext=$ac_objext
259 # Generate the test file.
260 AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <$3>
261$5], [$4])])
262dnl Optimization hacks: compiling C++ is slow, especially with Boost. What
263dnl we're trying to do here is guess the right combination of link flags
264dnl (LIBS / LDFLAGS) to use a given library. This can take several
265dnl iterations before it succeeds and is thus *very* slow. So what we do
266dnl instead is that we compile the code first (and thus get an object file,
267dnl typically conftest.o). Then we try various combinations of link flags
268dnl until we succeed to link conftest.o in an executable. The problem is
269dnl that the various TRY_LINK / COMPILE_IFELSE macros of Autoconf always
270dnl remove all the temporary files including conftest.o. So the trick here
271dnl is to temporarily change the value of ac_objext so that conftest.o is
272dnl preserved accross tests. This is obviously fragile and I will burn in
273dnl hell for not respecting Autoconf's documented interfaces, but in the
274dnl mean time, it optimizes the macro by a factor of 5 to 30.
275dnl Another small optimization: the first argument of AC_COMPILE_IFELSE left
276dnl empty because the test file is generated only once above (before we
277dnl start the for loops).
278 AC_COMPILE_IFELSE([],
279 [ac_objext=do_not_rm_me_plz],
280 [AC_MSG_ERROR([Cannot compile a test that uses Boost $1])])
281 ac_objext=$boost_save_ac_objext
282 boost_failed_libs=
283# Don't bother to ident the 6 nested for loops, only the 2 innermost ones
284# matter.
285for boost_tag_ in -$boost_cv_lib_tag ''; do
286for boost_ver_ in -$boost_cv_lib_version ''; do
287for boost_mt_ in $boost_mt -mt ''; do
288for boost_rtopt_ in $boost_rtopt '' -d; do
289 for boost_lib in \
290 boost_$1$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ \
291 boost_$1$boost_tag_$boost_rtopt_$boost_ver_ \
292 boost_$1$boost_tag_$boost_mt_$boost_ver_ \
293 boost_$1$boost_tag_$boost_ver_
294 do
295 # Avoid testing twice the same lib
296 case $boost_failed_libs in #(
297 *@$boost_lib@*) continue;;
298 esac
299 # If with_boost is empty, we'll search in /lib first, which is not quite
300 # right so instead we'll try to a location based on where the headers are.
301 boost_tmp_lib=$with_boost
302 test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include}
303 for boost_ldpath in "$boost_tmp_lib/lib" '' \
304 /opt/local/lib /usr/local/lib /opt/lib /usr/lib \
305 "$with_boost" C:/Boost/lib /lib /usr/lib64 /lib64
306 do
307 test -e "$boost_ldpath" || continue
308 boost_save_LDFLAGS=$LDFLAGS
309 # Are we looking for a static library?
310 case $boost_ldpath:$boost_rtopt_ in #(
311 *?*:*s*) # Yes (Non empty boost_ldpath + s in rt opt)
312 Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext"
313 test -e "$Boost_lib_LIBS" || continue;; #(
314 *) # No: use -lboost_foo to find the shared library.
315 Boost_lib_LIBS="-l$boost_lib";;
316 esac
317 boost_save_LIBS=$LIBS
318 LIBS="$Boost_lib_LIBS $LIBS"
319 test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"
320dnl First argument of AC_LINK_IFELSE left empty because the test file is
321dnl generated only once above (before we start the for loops).
322 _BOOST_AC_LINK_IFELSE([],
323 [Boost_lib=yes], [Boost_lib=no])
324 ac_objext=$boost_save_ac_objext
325 LDFLAGS=$boost_save_LDFLAGS
326 LIBS=$boost_save_LIBS
327 if test x"$Boost_lib" = xyes; then
328 Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath"
329 break 6
330 else
331 boost_failed_libs="$boost_failed_libs@$boost_lib@"
332 fi
333 done
334 done
335done
336done
337done
338done
339rm -f conftest.$ac_objext
340])
341case $Boost_lib in #(
342 no) AC_MSG_ERROR([Could not find the flags to link with Boost $1])
343 ;;
344esac
345AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS])
346AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS])
347CPPFLAGS=$boost_save_CPPFLAGS
348AS_VAR_POPDEF([Boost_lib])dnl
349AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl
350AS_VAR_POPDEF([Boost_lib_LIBS])dnl
351AC_LANG_POP([C++])dnl
352])# BOOST_FIND_LIB
353
354
355# --------------------------------------- #
356# Checks for the various Boost libraries. #
357# --------------------------------------- #
358
359# List of boost libraries: http://www.boost.org/libs/libraries.htm
360# The page http://beta.boost.org/doc/libs is useful: it gives the first release
361# version of each library (among other things).
362
363
364# BOOST_ASIO()
365# ------------
366# Look for Boost.Asio (new in Boost 1.35).
367AC_DEFUN([BOOST_ASIO],
368[AC_REQUIRE([BOOST_SYSTEM])dnl
369BOOST_FIND_HEADER([boost/asio.hpp])])
370
371
372# BOOST_BIND()
373# ------------
374# Look for Boost.Bind
375AC_DEFUN([BOOST_BIND],
376[BOOST_FIND_HEADER([boost/bind.hpp])])
377
378
379# BOOST_CONVERSION()
380# ------------------
381# Look for Boost.Conversion (cast / lexical_cast)
382AC_DEFUN([BOOST_CONVERSION],
383[BOOST_FIND_HEADER([boost/cast.hpp])
384BOOST_FIND_HEADER([boost/lexical_cast.hpp])
385])# BOOST_CONVERSION
386
387
388# BOOST_DATE_TIME([PREFERRED-RT-OPT])
389# -----------------------------------
390# Look for Boost.Date_Time. For the documentation of PREFERRED-RT-OPT, see the
391# documentation of BOOST_FIND_LIB above.
392AC_DEFUN([BOOST_DATE_TIME],
393[BOOST_FIND_LIB([date_time], [$1],
394 [boost/date_time/posix_time/posix_time.hpp],
395 [boost::posix_time::ptime t;])
396])# BOOST_DATE_TIME
397
398
399# BOOST_FILESYSTEM([PREFERRED-RT-OPT])
400# ------------------------------------
401# Look for Boost.Filesystem. For the documentation of PREFERRED-RT-OPT, see
402# the documentation of BOOST_FIND_LIB above.
403# Do not check for boost/filesystem.hpp because this file was introduced in
404# 1.34.
405AC_DEFUN([BOOST_FILESYSTEM],
406[# Do we have to check for Boost.System? This link-time dependency was
407# added as of 1.35.0. If we have a version <1.35, we must not attempt to
408# find Boost.System as it didn't exist by then.
409if test $boost_major_version -ge 135; then
410BOOST_SYSTEM([$1])
411fi # end of the Boost.System check.
412boost_filesystem_save_LIBS=$LIBS
413boost_filesystem_save_LDFLAGS=$LDFLAGS
414m4_pattern_allow([^BOOST_SYSTEM_(LIBS|LDFLAGS)$])dnl
415LIBS="$LIBS $BOOST_SYSTEM_LIBS"
416LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS"
417BOOST_FIND_LIB([filesystem], [$1],
418 [boost/filesystem/path.hpp], [boost::filesystem::path p;])
419LIBS=$boost_filesystem_save_LIBS
420LDFLAGS=$boost_filesystem_save_LDFLAGS
421])# BOOST_FILESYSTEM
422
423
424# BOOST_FOREACH()
425# ---------------
426# Look for Boost.Foreach
427AC_DEFUN([BOOST_FOREACH],
428[BOOST_FIND_HEADER([boost/foreach.hpp])])
429
430
431# BOOST_FORMAT()
432# --------------
433# Look for Boost.Format
434# Note: we can't check for boost/format/format_fwd.hpp because the header isn't
435# standalone. It can't be compiled because it triggers the following error:
436# boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std'
437# does not name a type
438AC_DEFUN([BOOST_FORMAT],
439[BOOST_FIND_HEADER([boost/format.hpp])])
440
441
442# BOOST_FUNCTION()
443# ----------------
444# Look for Boost.Function
445AC_DEFUN([BOOST_FUNCTION],
446[BOOST_FIND_HEADER([boost/function.hpp])])
447
448
449# BOOST_GRAPH([PREFERRED-RT-OPT])
450# -------------------------------
451# Look for Boost.Graphs. For the documentation of PREFERRED-RT-OPT, see the
452# documentation of BOOST_FIND_LIB above.
453AC_DEFUN([BOOST_GRAPH],
454[BOOST_FIND_LIB([graph], [$1],
455 [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;])
456])# BOOST_GRAPH
457
458
459# BOOST_IOSTREAMS([PREFERRED-RT-OPT])
460# -------------------------------
461# Look for Boost.IOStreams. For the documentation of PREFERRED-RT-OPT, see the
462# documentation of BOOST_FIND_LIB above.
463AC_DEFUN([BOOST_IOSTREAMS],
464[BOOST_FIND_LIB([iostreams], [$1],
465 [boost/iostreams/device/file_descriptor.hpp],
466 [boost::iostreams::file_descriptor fd(0); fd.close();])
467])# BOOST_IOSTREAMS
468
469
470# BOOST_HASH()
471# ------------
472# Look for Boost.Functional/Hash
473AC_DEFUN([BOOST_HASH],
474[BOOST_FIND_HEADER([boost/functional/hash.hpp])])
475
476
477# BOOST_LAMBDA()
478# --------------
479# Look for Boost.Lambda
480AC_DEFUN([BOOST_LAMBDA],
481[BOOST_FIND_HEADER([boost/lambda/lambda.hpp])])
482
483
484# BOOST_PREPROCESSOR()
485# --------------------
486# Look for Boost.Preprocessor
487AC_DEFUN([BOOST_PREPROCESSOR],
488[BOOST_FIND_HEADER([boost/preprocessor/repeat.hpp])])
489
490
491# BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT])
492# -----------------------------------------
493# Look for Boost.Program_options. For the documentation of PREFERRED-RT-OPT, see
494# the documentation of BOOST_FIND_LIB above.
495AC_DEFUN([BOOST_PROGRAM_OPTIONS],
496[BOOST_FIND_LIB([program_options], [$1],
497 [boost/program_options.hpp],
498 [boost::program_options::options_description d("test");])
499])# BOOST_PROGRAM_OPTIONS
500
501
502# BOOST_REF()
503# -----------
504# Look for Boost.Ref
505AC_DEFUN([BOOST_REF],
506[BOOST_FIND_HEADER([boost/ref.hpp])])
507
508
509# BOOST_REGEX([PREFERRED-RT-OPT])
510# -------------------------------
511# Look for Boost.Regex. For the documentation of PREFERRED-RT-OPT, see the
512# documentation of BOOST_FIND_LIB above.
513AC_DEFUN([BOOST_REGEX],
514[BOOST_FIND_LIB([regex], [$1],
515 [boost/regex.hpp],
516 [boost::regex exp("*"); boost::regex_match("foo", exp);])
517])# BOOST_REGEX
518
519
520# BOOST_SERIALIZATION([PREFERRED-RT-OPT])
521# ---------------------------------------
522# Look for Boost.Serialization. For the documentation of PREFERRED-RT-OPT, see
523# the documentation of BOOST_FIND_LIB above.
524AC_DEFUN([BOOST_SERIALIZATION],
525[BOOST_FIND_LIB([serialization], [$1],
526 [boost/archive/text_oarchive.hpp],
527 [std::ostream* o = 0; // Cheap way to get an ostream...
528 boost::archive::text_oarchive t(*o);])
529])# BOOST_SIGNALS
530
531
532# BOOST_SIGNALS([PREFERRED-RT-OPT])
533# ---------------------------------
534# Look for Boost.Signals. For the documentation of PREFERRED-RT-OPT, see the
535# documentation of BOOST_FIND_LIB above.
536AC_DEFUN([BOOST_SIGNALS],
537[BOOST_FIND_LIB([signals], [$1],
538 [boost/signal.hpp],
539 [boost::signal<void ()> s;])
540])# BOOST_SIGNALS
541
542
543# BOOST_SMART_PTR()
544# -----------------
545# Look for Boost.SmartPtr
546AC_DEFUN([BOOST_SMART_PTR],
547[BOOST_FIND_HEADER([boost/scoped_ptr.hpp])
548BOOST_FIND_HEADER([boost/shared_ptr.hpp])
549])
550
551
552# BOOST_STRING_ALGO()
553# -------------------
554# Look for Boost.StringAlgo
555AC_DEFUN([BOOST_STRING_ALGO],
556[BOOST_FIND_HEADER([boost/algorithm/string.hpp])
557])
558
559
560# BOOST_SYSTEM([PREFERRED-RT-OPT])
561# --------------------------------
562# Look for Boost.System. For the documentation of PREFERRED-RT-OPT, see the
563# documentation of BOOST_FIND_LIB above. This library was introduced in Boost
564# 1.35.0.
565AC_DEFUN([BOOST_SYSTEM],
566[BOOST_FIND_LIB([system], [$1],
567 [boost/system/error_code.hpp],
568 [boost::system::error_code e; e.clear();])
569])# BOOST_SYSTEM
570
571
572# BOOST_TEST([PREFERRED-RT-OPT])
573# ------------------------------
574# Look for Boost.Test. For the documentation of PREFERRED-RT-OPT, see the
575# documentation of BOOST_FIND_LIB above.
576AC_DEFUN([BOOST_TEST],
577[m4_pattern_allow([^BOOST_CHECK$])dnl
578BOOST_FIND_LIB([unit_test_framework], [$1],
579 [boost/test/unit_test.hpp], [BOOST_CHECK(2 == 2);],
580 [using boost::unit_test::test_suite;
581 test_suite* init_unit_test_suite(int argc, char ** argv)
582 { return NULL; }])
583])# BOOST_TEST
584
585
586# BOOST_THREADS([PREFERRED-RT-OPT])
587# ---------------------------------
588# Look for Boost.Thread. For the documentation of PREFERRED-RT-OPT, see the
589# documentation of BOOST_FIND_LIB above.
590# FIXME: Provide an alias "BOOST_THREAD".
591AC_DEFUN([BOOST_THREADS],
592[dnl Having the pthread flag is required at least on GCC3 where
593dnl boost/thread.hpp would complain if we try to compile without
594dnl -pthread on GNU/Linux.
595AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
596boost_threads_save_LIBS=$LIBS
597boost_threads_save_CPPFLAGS=$CPPFLAGS
598LIBS="$LIBS $boost_cv_pthread_flag"
599# Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
600# boost/thread.hpp will trigger a #error if -pthread isn't used:
601# boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
602# is not turned on. Please set the correct command line options for
603# threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
604CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag"
605BOOST_FIND_LIB([thread], [$1],
606 [boost/thread.hpp], [boost::thread t; boost::mutex m;])
607BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $boost_cv_pthread_flag"
608BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag"
609LIBS=$boost_threads_save_LIBS
610CPPFLAGS=$boost_threads_save_CPPFLAGS
611])# BOOST_THREADS
612
613
614# BOOST_TOKENIZER()
615# -----------------
616# Look for Boost.Tokenizer
617AC_DEFUN([BOOST_TOKENIZER],
618[BOOST_FIND_HEADER([boost/tokenizer.hpp])])
619
620
621# BOOST_TRIBOOL()
622# ---------------
623# Look for Boost.Tribool
624AC_DEFUN([BOOST_TRIBOOL],
625[BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp])
626BOOST_FIND_HEADER([boost/logic/tribool.hpp])
627])
628
629
630# BOOST_TUPLE()
631# -------------
632# Look for Boost.Tuple
633AC_DEFUN([BOOST_TUPLE],
634[BOOST_FIND_HEADER([boost/tuple/tuple.hpp])])
635
636
637# BOOST_UTILITY()
638# ---------------
639# Look for Boost.Utility (noncopyable, result_of, base-from-member idiom,
640# etc.)
641AC_DEFUN([BOOST_UTILITY],
642[BOOST_FIND_HEADER([boost/utility.hpp])])
643
644
645# BOOST_VARIANT()
646# ---------------
647# Look for Boost.Variant.
648AC_DEFUN([BOOST_VARIANT],
649[BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp])
650BOOST_FIND_HEADER([boost/variant.hpp])])
651
652
653# BOOST_WAVE([PREFERRED-RT-OPT])
654# ------------------------------
655# NOTE: If you intend to use Wave/Spirit with thread support, make sure you
656# call BOOST_THREADS first.
657# Look for Boost.Wave. For the documentation of PREFERRED-RT-OPT, see the
658# documentation of BOOST_FIND_LIB above.
659AC_DEFUN([BOOST_WAVE],
660[AC_REQUIRE([BOOST_FILESYSTEM])dnl
661AC_REQUIRE([BOOST_DATE_TIME])dnl
662boost_wave_save_LIBS=$LIBS
663boost_wave_save_LDFLAGS=$LDFLAGS
664m4_pattern_allow([^BOOST_((FILE)?SYSTEM|DATE_TIME|THREAD)_(LIBS|LDFLAGS)$])dnl
665LIBS="$LIBS $BOOST_SYSTEM_LIBS $BOOST_FILESYSTEM_LIBS $BOOST_DATE_TIME_LIBS\
666$BOOST_THREAD_LIBS"
667LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS $BOOST_FILESYSTEM_LDFLAGS\
668$BOOST_DATE_TIME_LDFLAGS $BOOST_THREAD_LDFLAGS"
669BOOST_FIND_LIB([wave], [$1],
670 [boost/wave.hpp],
671 [boost::wave::token_id id; get_token_name(id);])
672LIBS=$boost_wave_save_LIBS
673LDFLAGS=$boost_wave_save_LDFLAGS
674])# BOOST_WAVE
675
676
677# BOOST_XPRESSIVE()
678# -----------------
679# Look for Boost.Xpressive (new since 1.36.0).
680AC_DEFUN([BOOST_XPRESSIVE],
681[BOOST_FIND_HEADER([boost/xpressive/xpressive.hpp])])
682
683
684# ----------------- #
685# Internal helpers. #
686# ----------------- #
687
688
689# _BOOST_PTHREAD_FLAG()
690# ---------------------
691# Internal helper for BOOST_THREADS. Based on ACX_PTHREAD:
692# http://autoconf-archive.cryp.to/acx_pthread.html
693AC_DEFUN([_BOOST_PTHREAD_FLAG],
694[AC_REQUIRE([AC_PROG_CXX])dnl
695AC_REQUIRE([AC_CANONICAL_HOST])dnl
696AC_LANG_PUSH([C++])dnl
697AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag],
698[ boost_cv_pthread_flag=
699 # The ordering *is* (sometimes) important. Some notes on the
700 # individual items follow:
701 # (none): in case threads are in libc; should be tried before -Kthread and
702 # other compiler flags to prevent continual compiler warnings
703 # -lpthreads: AIX (must check this before -lpthread)
704 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
705 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
706 # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
707 # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
708 # -pthreads: Solaris/GCC
709 # -mthreads: MinGW32/GCC, Lynx/GCC
710 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
711 # doesn't hurt to check since this sometimes defines pthreads too;
712 # also defines -D_REENTRANT)
713 # ... -mt is also the pthreads flag for HP/aCC
714 # -lpthread: GNU Linux, etc.
715 # --thread-safe: KAI C++
716 case $host_os in #(
717 *solaris*)
718 # On Solaris (at least, for some versions), libc contains stubbed
719 # (non-functional) versions of the pthreads routines, so link-based
720 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
721 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
722 # a function called by this macro, so we could check for that, but
723 # who knows whether they'll stub that too in a future libc.) So,
724 # we'll just look for -pthreads and -lpthread first:
725 boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #(
726 *)
727 boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \
728 -pthreads -mthreads -lpthread --thread-safe -mt";;
729 esac
730 # Generate the test file.
731 AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <pthread.h>],
732 [pthread_t th; pthread_join(th, 0);
733 pthread_attr_init(0); pthread_cleanup_push(0, 0);
734 pthread_create(0,0,0,0); pthread_cleanup_pop(0);])])
735 for boost_pthread_flag in '' $boost_pthread_flags; do
736 boost_pthread_ok=false
737dnl Re-use the test file already generated.
738 boost_pthreads__save_LIBS=$LIBS
739 LIBS="$LIBS $boost_pthread_flag"
740 AC_LINK_IFELSE([],
741 [if grep ".*$boost_pthread_flag" conftest.err; then
742 echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD
743 else
744 boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag
745 fi])
746 LIBS=$boost_pthreads__save_LIBS
747 $boost_pthread_ok && break
748 done
749])
750AC_LANG_POP([C++])dnl
751])# _BOOST_PTHREAD_FLAG
752
753
754# _BOOST_gcc_test(MAJOR, MINOR)
755# -----------------------------
756# Internal helper for _BOOST_FIND_COMPILER_TAG.
757m4_define([_BOOST_gcc_test],
758["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl
759
760
761# _BOOST_FIND_COMPILER_TAG()
762# --------------------------
763# Internal. When Boost is installed without --layout=system, each library
764# filename will hold a suffix that encodes the compiler used during the
765# build. The Boost build system seems to call this a `tag'.
766AC_DEFUN([_BOOST_FIND_COMPILER_TAG],
767[AC_REQUIRE([AC_PROG_CXX])dnl
768AC_CACHE_CHECK([for the toolset name used by Boost for $CXX], [boost_cv_lib_tag],
769[AC_LANG_PUSH([C++])dnl
770 boost_cv_lib_tag=unknown
771 # The following tests are mostly inspired by boost/config/auto_link.hpp
772 # The list is sorted to most recent/common to oldest compiler (in order
773 # to increase the likelihood of finding the right compiler with the
774 # least number of compilation attempt).
775 # Beware that some tests are sensible to the order (for instance, we must
776 # look for MinGW before looking for GCC3).
777 # I used one compilation test per compiler with a #error to recognize
778 # each compiler so that it works even when cross-compiling (let me know
779 # if you know a better approach).
780 # Known missing tags (known from Boost's tools/build/v2/tools/common.jam):
781 # como, edg, kcc, bck, mp, sw, tru, xlc
782 # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines
783 # the same defines as GCC's).
784 # TODO: Move the test on GCC 4.4 up once it's released.
785 for i in \
786 _BOOST_gcc_test(4, 3) \
787 _BOOST_gcc_test(4, 2) \
788 _BOOST_gcc_test(4, 1) \
789 _BOOST_gcc_test(4, 0) \
790 "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \
791 && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
792 || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \
793 _BOOST_gcc_test(3, 4) \
794 _BOOST_gcc_test(3, 3) \
795 "defined _MSC_VER && _MSC_VER >= 1400 @ vc80" \
796 _BOOST_gcc_test(3, 2) \
797 "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \
798 _BOOST_gcc_test(3, 1) \
799 _BOOST_gcc_test(3, 0) \
800 "defined __BORLANDC__ @ bcb" \
801 "defined __ICC && (defined __unix || defined __unix__) @ il" \
802 "defined __ICL @ iw" \
803 "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \
804 _BOOST_gcc_test(4, 4) \
805 _BOOST_gcc_test(2, 95) \
806 "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \
807 "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \
808 "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \
809 "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8"
810 do
811 boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '`
812 boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'`
813 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
814#if $boost_tag_test
815/* OK */
816#else
817# error $boost_tag_test
818#endif
819]])], [boost_cv_lib_tag=$boost_tag; break], [])
820 done
821AC_LANG_POP([C++])dnl
822])
823 case $boost_cv_lib_tag in #(
824 # Some newer (>= 1.35?) versions of Boost seem to only use "gcc" as opposed
825 # to "gcc41" for instance.
826 gcc*)
827 # We can specify multiple tags in this variable because it's used by
828 # BOOST_FIND_LIB that does a `for tag in -$boost_cv_lib_tag' ...
829 boost_cv_lib_tag="$boost_cv_lib_tag -gcc"
830 ;; #(
831 unknown)
832 AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]])
833 boost_cv_lib_tag=
834 ;;
835 esac
836])# _BOOST_FIND_COMPILER_TAG
837
838
839# _BOOST_GUESS_WHETHER_TO_USE_MT()
840# --------------------------------
841# Compile a small test to try to guess whether we should favor MT (Multi
842# Thread) flavors of Boost. Sets boost_guess_use_mt accordingly.
843AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT],
844[# Check whether we do better use `mt' even though we weren't ask to.
845AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
846#if defined _REENTRANT || defined _MT || defined __MT__
847/* use -mt */
848#else
849# error MT not needed
850#endif
851]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false])
852])
853
854# _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
855# -------------------------------------------------------------------
856# Fork of _AC_LINK_IFELSE that preserves conftest.o across calls. Fragile,
857# will break when Autoconf changes its internals. Requires that you manually
858# rm -f conftest.$ac_objext in between to really different tests, otherwise
859# you will try to link a conftest.o left behind by a previous test.
860# Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this
861# macro)
862m4_define([_BOOST_AC_LINK_IFELSE],
863[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
864rm -f conftest$ac_exeext
865boost_ac_ext_save=$ac_ext
866boost_use_source=:
867# If we already have a .o, re-use it. We change $ac_ext so that $ac_link
868# tries to link the existing object file instead of compiling from source.
869test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false &&
870 _AS_ECHO_LOG([re-using the existing conftest.$ac_objext])
871AS_IF([_AC_DO_STDERR($ac_link) && {
872 test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
873 test ! -s conftest.err
874 } && test -s conftest$ac_exeext && {
875 test "$cross_compiling" = yes ||
876 $as_executable_p conftest$ac_exeext
877dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough.
878 }],
879 [$2],
880 [if $boost_use_source; then
881 _AC_MSG_LOG_CONFTEST
882 fi
883 $3])
884dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
885dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
886dnl as it would interfere with the next link command.
887rm -f core conftest.err conftest_ipa8_conftest.oo \
888 conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl
889])# _BOOST_AC_LINK_IFELSE
Note: See TracBrowser for help on using the repository browser.