CPPXT-102 - BOOST autoconf macros break with gcc5
[shibboleth/cpp-xmltooling.git] / m4 / boost.m4
1 # boost.m4: Locate Boost headers and libraries for autoconf-based projects.
2 # Copyright (C) 2007-2011, 2014  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 m4_define([_BOOST_SERIAL], [m4_translit([
25 # serial 24
26 ], [#
27 ], [])])
28
29 # Original sources can be found at http://github.com/tsuna/boost.m4
30 # You can fetch the latest version of the script by doing:
31 #   wget http://github.com/tsuna/boost.m4/raw/master/build-aux/boost.m4
32
33 # ------ #
34 # README #
35 # ------ #
36
37 # This file provides several macros to use the various Boost libraries.
38 # The first macro is BOOST_REQUIRE.  It will simply check if it's possible to
39 # find the Boost headers of a given (optional) minimum version and it will
40 # define BOOST_CPPFLAGS accordingly.  It will add an option --with-boost to
41 # your configure so that users can specify non standard locations.
42 # If the user's environment contains BOOST_ROOT and --with-boost was not
43 # specified, --with-boost=$BOOST_ROOT is implicitly used.
44 # For more README and documentation, go to http://github.com/tsuna/boost.m4
45 # Note: THESE MACROS ASSUME THAT YOU USE LIBTOOL.  If you don't, don't worry,
46 # simply read the README, it will show you what to do step by step.
47
48 m4_pattern_forbid([^_?(BOOST|Boost)_])
49
50
51 # _BOOST_SED_CPP(SED-PROGRAM, PROGRAM,
52 #                [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
53 # --------------------------------------------------------
54 # Same as AC_EGREP_CPP, but leave the result in conftest.i.
55 #
56 # SED-PROGRAM is *not* overquoted, as in AC_EGREP_CPP.  It is expanded
57 # in double-quotes, so escape your double quotes.
58 #
59 # It could be useful to turn this into a macro which extracts the
60 # value of any macro.
61 m4_define([_BOOST_SED_CPP],
62 [AC_LANG_PUSH([C++])dnl
63 AC_LANG_PREPROC_REQUIRE()dnl
64 AC_REQUIRE([AC_PROG_SED])dnl
65 AC_LANG_CONFTEST([AC_LANG_SOURCE([[$2]])])
66 AS_IF([dnl eval is necessary to expand ac_cpp.
67 dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
68 dnl Beware of Windows end-of-lines, for instance if we are running
69 dnl some Windows programs under Wine.  In that case, boost/version.hpp
70 dnl is certainly using "\r\n", but the regular Unix shell will only
71 dnl strip `\n' with backquotes, not the `\r'.  This results in
72 dnl boost_cv_lib_version='1_37\r' for instance, which breaks
73 dnl everything else.
74 dnl Cannot use 'dnl' after [$4] because a trailing dnl may break AC_CACHE_CHECK
75 dnl
76 dnl Beware that GCC 5, when expanding macros, may embed # line directives
77 dnl a within single line:
78 dnl
79 dnl # 1 "conftest.cc"
80 dnl # 1 "<built-in>"
81 dnl # 1 "<command-line>"
82 dnl # 1 "conftest.cc"
83 dnl # 1 "/opt/local/include/boost/version.hpp" 1 3
84 dnl # 2 "conftest.cc" 2
85 dnl boost-lib-version =
86 dnl # 2 "conftest.cc" 3
87 dnl                    "1_56"
88 dnl
89 dnl So get rid of the # lines, and glue the remaining ones together.
90 (eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
91   grep -v '#' |
92   tr -d '\r' |
93   tr -s '\n' ' ' |
94   $SED -n -e "$1" >conftest.i 2>&1],
95   [$3],
96   [$4])
97 rm -rf conftest*
98 AC_LANG_POP([C++])dnl
99 ])# _BOOST_SED_CPP
100
101
102
103 # BOOST_REQUIRE([VERSION], [ACTION-IF-NOT-FOUND])
104 # -----------------------------------------------
105 # Look for Boost.  If version is given, it must either be a literal of the form
106 # "X.Y.Z" where X, Y and Z are integers (the ".Z" part being optional) or a
107 # variable "$var".
108 # Defines the value BOOST_CPPFLAGS.  This macro only checks for headers with
109 # the required version, it does not check for any of the Boost libraries.
110 # On # success, defines HAVE_BOOST.  On failure, calls the optional
111 # ACTION-IF-NOT-FOUND action if one was supplied.
112 # Otherwise aborts with an error message.
113 AC_DEFUN([BOOST_REQUIRE],
114 [AC_REQUIRE([AC_PROG_CXX])dnl
115 AC_REQUIRE([AC_PROG_GREP])dnl
116 echo "$as_me: this is boost.m4[]_BOOST_SERIAL" >&AS_MESSAGE_LOG_FD
117 boost_save_IFS=$IFS
118 boost_version_req=$1
119 IFS=.
120 set x $boost_version_req 0 0 0
121 IFS=$boost_save_IFS
122 shift
123 boost_version_req=`expr "$[1]" '*' 100000 + "$[2]" '*' 100 + "$[3]"`
124 boost_version_req_string=$[1].$[2].$[3]
125 AC_ARG_WITH([boost],
126    [AS_HELP_STRING([--with-boost=DIR],
127                    [prefix of Boost $1 @<:@guess@:>@])])dnl
128 AC_ARG_VAR([BOOST_ROOT],[Location of Boost installation])dnl
129 # If BOOST_ROOT is set and the user has not provided a value to
130 # --with-boost, then treat BOOST_ROOT as if it the user supplied it.
131 if test x"$BOOST_ROOT" != x; then
132   if test x"$with_boost" = x; then
133     AC_MSG_NOTICE([Detected BOOST_ROOT; continuing with --with-boost=$BOOST_ROOT])
134     with_boost=$BOOST_ROOT
135   else
136     AC_MSG_NOTICE([Detected BOOST_ROOT=$BOOST_ROOT, but overridden by --with-boost=$with_boost])
137   fi
138 fi
139 AC_SUBST([DISTCHECK_CONFIGURE_FLAGS],
140          ["$DISTCHECK_CONFIGURE_FLAGS '--with-boost=$with_boost'"])dnl
141 boost_save_CPPFLAGS=$CPPFLAGS
142   AC_CACHE_CHECK([for Boost headers version >= $boost_version_req_string],
143     [boost_cv_inc_path],
144     [boost_cv_inc_path=no
145 AC_LANG_PUSH([C++])dnl
146 m4_pattern_allow([^BOOST_VERSION$])dnl
147     AC_LANG_CONFTEST([AC_LANG_PROGRAM([[#include <boost/version.hpp>
148 #if !defined BOOST_VERSION
149 # error BOOST_VERSION is not defined
150 #elif BOOST_VERSION < $boost_version_req
151 # error Boost headers version < $boost_version_req
152 #endif
153 ]])])
154     # If the user provided a value to --with-boost, use it and only it.
155     case $with_boost in #(
156       ''|yes) set x '' /opt/local/include /usr/local/include /opt/include \
157                  /usr/include C:/Boost/include;; #(
158       *)      set x "$with_boost/include" "$with_boost";;
159     esac
160     shift
161     for boost_dir
162     do
163     # Without --layout=system, Boost (or at least some versions) installs
164     # itself in <prefix>/include/boost-<version>.  This inner loop helps to
165     # find headers in such directories.
166     #
167     # Any ${boost_dir}/boost-x_xx directories are searched in reverse version
168     # order followed by ${boost_dir}.  The final '.' is a sentinel for
169     # searching $boost_dir" itself.  Entries are whitespace separated.
170     #
171     # I didn't indent this loop on purpose (to avoid over-indented code)
172     boost_layout_system_search_list=`cd "$boost_dir" 2>/dev/null \
173         && ls -1 | "${GREP}" '^boost-' | sort -rn -t- -k2 \
174         && echo .`
175     for boost_inc in $boost_layout_system_search_list
176     do
177       if test x"$boost_inc" != x.; then
178         boost_inc="$boost_dir/$boost_inc"
179       else
180         boost_inc="$boost_dir" # Uses sentinel in boost_layout_system_search_list
181       fi
182       if test x"$boost_inc" != x; then
183         # We are going to check whether the version of Boost installed
184         # in $boost_inc is usable by running a compilation that
185         # #includes it.  But if we pass a -I/some/path in which Boost
186         # is not installed, the compiler will just skip this -I and
187         # use other locations (either from CPPFLAGS, or from its list
188         # of system include directories).  As a result we would use
189         # header installed on the machine instead of the /some/path
190         # specified by the user.  So in that precise case (trying
191         # $boost_inc), make sure the version.hpp exists.
192         #
193         # Use test -e as there can be symlinks.
194         test -e "$boost_inc/boost/version.hpp" || continue
195         CPPFLAGS="$CPPFLAGS -I$boost_inc"
196       fi
197       AC_COMPILE_IFELSE([], [boost_cv_inc_path=yes], [boost_cv_version=no])
198       if test x"$boost_cv_inc_path" = xyes; then
199         if test x"$boost_inc" != x; then
200           boost_cv_inc_path=$boost_inc
201         fi
202         break 2
203       fi
204     done
205     done
206 AC_LANG_POP([C++])dnl
207     ])
208     case $boost_cv_inc_path in #(
209       no)
210         boost_errmsg="cannot find Boost headers version >= $boost_version_req_string"
211         m4_if([$2], [],  [AC_MSG_ERROR([$boost_errmsg])],
212                         [AC_MSG_NOTICE([$boost_errmsg])])
213         $2
214         ;;#(
215       yes)
216         BOOST_CPPFLAGS=
217         ;;#(
218       *)
219         AC_SUBST([BOOST_CPPFLAGS], ["-I$boost_cv_inc_path"])dnl
220         ;;
221     esac
222   if test x"$boost_cv_inc_path" != xno; then
223   AC_DEFINE([HAVE_BOOST], [1],
224             [Defined if the requested minimum BOOST version is satisfied])
225   AC_CACHE_CHECK([for Boost's header version],
226     [boost_cv_lib_version],
227     [m4_pattern_allow([^BOOST_LIB_VERSION$])dnl
228      _BOOST_SED_CPP([[/^boost-lib-version = /{s///;s/[\" ]//g;p;q;}]],
229                     [#include <boost/version.hpp>
230 boost-lib-version = BOOST_LIB_VERSION],
231     [boost_cv_lib_version=`cat conftest.i`])])
232     # e.g. "134" for 1_34_1 or "135" for 1_35
233     boost_major_version=`echo "$boost_cv_lib_version" | sed 's/_//;s/_.*//'`
234     case $boost_major_version in #(
235       '' | *[[!0-9]]*)
236         AC_MSG_ERROR([invalid value: boost_major_version='$boost_major_version'])
237         ;;
238     esac
239 fi
240 CPPFLAGS=$boost_save_CPPFLAGS
241 ])# BOOST_REQUIRE
242
243
244 # BOOST_STATIC()
245 # --------------
246 # Add the "--enable-static-boost" configure argument. If this argument is given
247 # on the command line, static versions of the libraries will be looked up.
248 AC_DEFUN([BOOST_STATIC],
249   [AC_ARG_ENABLE([static-boost],
250      [AS_HELP_STRING([--enable-static-boost],
251                [Prefer the static boost libraries over the shared ones [no]])],
252      [enable_static_boost=yes],
253      [enable_static_boost=no])])# BOOST_STATIC
254
255
256 # BOOST_FIND_HEADER([HEADER-NAME], [ACTION-IF-NOT-FOUND], [ACTION-IF-FOUND])
257 # --------------------------------------------------------------------------
258 # Wrapper around AC_CHECK_HEADER for Boost headers.  Useful to check for
259 # some parts of the Boost library which are only made of headers and don't
260 # require linking (such as Boost.Foreach).
261 #
262 # Default ACTION-IF-NOT-FOUND: Fail with a fatal error unless Boost couldn't be
263 # found in the first place, in which case by default a notice is issued to the
264 # user.  Presumably if we haven't died already it's because it's OK to not have
265 # Boost, which is why only a notice is issued instead of a hard error.
266 #
267 # Default ACTION-IF-FOUND: define the preprocessor symbol HAVE_<HEADER-NAME> in
268 # case of success # (where HEADER-NAME is written LIKE_THIS, e.g.,
269 # HAVE_BOOST_FOREACH_HPP).
270 AC_DEFUN([BOOST_FIND_HEADER],
271 [AC_REQUIRE([BOOST_REQUIRE])dnl
272 if test x"$boost_cv_inc_path" = xno; then
273   m4_default([$2], [AC_MSG_NOTICE([Boost not available, not searching for $1])])
274 else
275 AC_LANG_PUSH([C++])dnl
276 boost_save_CPPFLAGS=$CPPFLAGS
277 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
278 AC_CHECK_HEADER([$1],
279   [m4_default([$3], [AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1],
280                                [Define to 1 if you have <$1>])])],
281   [m4_default([$2], [AC_MSG_ERROR([cannot find $1])])])
282 CPPFLAGS=$boost_save_CPPFLAGS
283 AC_LANG_POP([C++])dnl
284 fi
285 ])# BOOST_FIND_HEADER
286
287
288 # BOOST_FIND_LIBS([COMPONENT-NAME], [CANDIDATE-LIB-NAMES],
289 #                 [PREFERRED-RT-OPT], [HEADER-NAME], [CXX-TEST],
290 #                 [CXX-PROLOGUE])
291 # --------------------------------------------------------------
292 # Look for the Boost library COMPONENT-NAME (e.g., `thread', for
293 # libboost_thread) under the possible CANDIDATE-LIB-NAMES (e.g.,
294 # "thread_win32 thread").  Check that HEADER-NAME works and check that
295 # libboost_LIB-NAME can link with the code CXX-TEST.  The optional
296 # argument CXX-PROLOGUE can be used to include some C++ code before
297 # the `main' function.
298 #
299 # Invokes BOOST_FIND_HEADER([HEADER-NAME]) (see above).
300 #
301 # Boost libraries typically come compiled with several flavors (with different
302 # runtime options) so PREFERRED-RT-OPT is the preferred suffix.  A suffix is one
303 # or more of the following letters: sgdpn (in that order).  s = static
304 # runtime, d = debug build, g = debug/diagnostic runtime, p = STLPort build,
305 # n = (unsure) STLPort build without iostreams from STLPort (it looks like `n'
306 # must always be used along with `p').  Additionally, PREFERRED-RT-OPT can
307 # start with `mt-' to indicate that there is a preference for multi-thread
308 # builds.  Some sample values for PREFERRED-RT-OPT: (nothing), mt, d, mt-d, gdp
309 # ...  If you want to make sure you have a specific version of Boost
310 # (eg, >= 1.33) you *must* invoke BOOST_REQUIRE before this macro.
311 AC_DEFUN([BOOST_FIND_LIBS],
312 [AC_REQUIRE([BOOST_REQUIRE])dnl
313 AC_REQUIRE([_BOOST_FIND_COMPILER_TAG])dnl
314 AC_REQUIRE([BOOST_STATIC])dnl
315 AC_REQUIRE([_BOOST_GUESS_WHETHER_TO_USE_MT])dnl
316 if test x"$boost_cv_inc_path" = xno; then
317   AC_MSG_NOTICE([Boost not available, not searching for the Boost $1 library])
318 else
319 dnl The else branch is huge and wasn't intended on purpose.
320 AC_LANG_PUSH([C++])dnl
321 AS_VAR_PUSHDEF([Boost_lib], [boost_cv_lib_$1])dnl
322 AS_VAR_PUSHDEF([Boost_lib_LDFLAGS], [boost_cv_lib_$1_LDFLAGS])dnl
323 AS_VAR_PUSHDEF([Boost_lib_LDPATH], [boost_cv_lib_$1_LDPATH])dnl
324 AS_VAR_PUSHDEF([Boost_lib_LIBS], [boost_cv_lib_$1_LIBS])dnl
325 BOOST_FIND_HEADER([$4])
326 boost_save_CPPFLAGS=$CPPFLAGS
327 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
328 AC_CACHE_CHECK([for the Boost $1 library], [Boost_lib],
329                [_BOOST_FIND_LIBS($@)])
330 case $Boost_lib in #(
331   (no) _AC_MSG_LOG_CONFTEST
332     AC_MSG_ERROR([cannot find the flags to link with Boost $1])
333     ;;
334 esac
335 AC_SUBST(AS_TR_CPP([BOOST_$1_LDFLAGS]), [$Boost_lib_LDFLAGS])dnl
336 AC_SUBST(AS_TR_CPP([BOOST_$1_LDPATH]), [$Boost_lib_LDPATH])dnl
337 AC_SUBST([BOOST_LDPATH], [$Boost_lib_LDPATH])dnl
338 AC_SUBST(AS_TR_CPP([BOOST_$1_LIBS]), [$Boost_lib_LIBS])dnl
339 CPPFLAGS=$boost_save_CPPFLAGS
340 AS_VAR_POPDEF([Boost_lib])dnl
341 AS_VAR_POPDEF([Boost_lib_LDFLAGS])dnl
342 AS_VAR_POPDEF([Boost_lib_LDPATH])dnl
343 AS_VAR_POPDEF([Boost_lib_LIBS])dnl
344 AC_LANG_POP([C++])dnl
345 fi
346 ])
347
348
349 # BOOST_FIND_LIB([LIB-NAME],
350 #                [PREFERRED-RT-OPT], [HEADER-NAME], [CXX-TEST],
351 #                [CXX-PROLOGUE])
352 # --------------------------------------------------------------
353 # Backward compatibility wrapper for BOOST_FIND_LIBS.
354 AC_DEFUN([BOOST_FIND_LIB],
355 [BOOST_FIND_LIBS([$1], $@)])
356
357
358 # _BOOST_FIND_LIBS([LIB-NAME], [CANDIDATE-LIB-NAMES],
359 #                 [PREFERRED-RT-OPT], [HEADER-NAME], [CXX-TEST],
360 #                 [CXX-PROLOGUE])
361 # --------------------------------------------------------------
362 # Real implementation of BOOST_FIND_LIBS: rely on these local macros:
363 # Boost_lib, Boost_lib_LDFLAGS, Boost_lib_LDPATH, Boost_lib_LIBS
364 #
365 # The algorithm is as follows: first look for a given library name
366 # according to the user's PREFERRED-RT-OPT.  For each library name, we
367 # prefer to use the ones that carry the tag (toolset name).  Each
368 # library is searched through the various standard paths were Boost is
369 # usually installed.  If we can't find the standard variants, we try
370 # to enforce -mt (for instance on MacOSX, libboost_thread.dylib
371 # doesn't exist but there's -obviously- libboost_thread-mt.dylib).
372 AC_DEFUN([_BOOST_FIND_LIBS],
373 [Boost_lib=no
374   case "$3" in #(
375     (mt | mt-) boost_mt=-mt; boost_rtopt=;; #(
376     (mt* | mt-*) boost_mt=-mt; boost_rtopt=`expr "X$3" : 'Xmt-*\(.*\)'`;; #(
377     (*) boost_mt=; boost_rtopt=$3;;
378   esac
379   if test $enable_static_boost = yes; then
380     boost_rtopt="s$boost_rtopt"
381   fi
382   # Find the proper debug variant depending on what we've been asked to find.
383   case $boost_rtopt in #(
384     (*d*) boost_rt_d=$boost_rtopt;; #(
385     (*[[sgpn]]*) # Insert the `d' at the right place (in between `sg' and `pn')
386       boost_rt_d=`echo "$boost_rtopt" | sed 's/\(s*g*\)\(p*n*\)/\1\2/'`;; #(
387     (*) boost_rt_d='-d';;
388   esac
389   # If the PREFERRED-RT-OPT are not empty, prepend a `-'.
390   test -n "$boost_rtopt" && boost_rtopt="-$boost_rtopt"
391   $boost_guess_use_mt && boost_mt=-mt
392   # Look for the abs path the static archive.
393   # $libext is computed by Libtool but let's make sure it's non empty.
394   test -z "$libext" &&
395     AC_MSG_ERROR([the libext variable is empty, did you invoke Libtool?])
396   boost_save_ac_objext=$ac_objext
397   # Generate the test file.
398   AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <$4>
399 $6], [$5])])
400 dnl Optimization hacks: compiling C++ is slow, especially with Boost.  What
401 dnl we're trying to do here is guess the right combination of link flags
402 dnl (LIBS / LDFLAGS) to use a given library.  This can take several
403 dnl iterations before it succeeds and is thus *very* slow.  So what we do
404 dnl instead is that we compile the code first (and thus get an object file,
405 dnl typically conftest.o).  Then we try various combinations of link flags
406 dnl until we succeed to link conftest.o in an executable.  The problem is
407 dnl that the various TRY_LINK / COMPILE_IFELSE macros of Autoconf always
408 dnl remove all the temporary files including conftest.o.  So the trick here
409 dnl is to temporarily change the value of ac_objext so that conftest.o is
410 dnl preserved accross tests.  This is obviously fragile and I will burn in
411 dnl hell for not respecting Autoconf's documented interfaces, but in the
412 dnl mean time, it optimizes the macro by a factor of 5 to 30.
413 dnl Another small optimization: the first argument of AC_COMPILE_IFELSE left
414 dnl empty because the test file is generated only once above (before we
415 dnl start the for loops).
416   AC_COMPILE_IFELSE([],
417     [ac_objext=do_not_rm_me_plz],
418     [AC_MSG_ERROR([cannot compile a test that uses Boost $1])])
419   ac_objext=$boost_save_ac_objext
420   boost_failed_libs=
421 # Don't bother to ident the following nested for loops, only the 2
422 # innermost ones matter.
423 for boost_lib_ in $2; do
424 for boost_tag_ in -$boost_cv_lib_tag ''; do
425 for boost_ver_ in -$boost_cv_lib_version ''; do
426 for boost_mt_ in $boost_mt -mt ''; do
427 for boost_rtopt_ in $boost_rtopt '' -d; do
428   for boost_lib in \
429     boost_$boost_lib_$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ \
430     boost_$boost_lib_$boost_tag_$boost_rtopt_$boost_ver_ \
431     boost_$boost_lib_$boost_tag_$boost_mt_$boost_ver_ \
432     boost_$boost_lib_$boost_tag_$boost_ver_
433   do
434     # Avoid testing twice the same lib
435     case $boost_failed_libs in #(
436       (*@$boost_lib@*) continue;;
437     esac
438     # If with_boost is empty, we'll search in /lib first, which is not quite
439     # right so instead we'll try to a location based on where the headers are.
440     boost_tmp_lib=$with_boost
441     test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include}
442     for boost_ldpath in "$boost_tmp_lib/lib" '' \
443              /opt/local/lib* /usr/local/lib* /opt/lib* /usr/lib* \
444              "$with_boost" C:/Boost/lib /lib*
445     do
446       # Don't waste time with directories that don't exist.
447       if test x"$boost_ldpath" != x && test ! -e "$boost_ldpath"; then
448         continue
449       fi
450       boost_save_LDFLAGS=$LDFLAGS
451       # Are we looking for a static library?
452       case $boost_ldpath:$boost_rtopt_ in #(
453         (*?*:*s*) # Yes (Non empty boost_ldpath + s in rt opt)
454           Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext"
455           test -e "$Boost_lib_LIBS" || continue;; #(
456         (*) # No: use -lboost_foo to find the shared library.
457           Boost_lib_LIBS="-l$boost_lib";;
458       esac
459       boost_save_LIBS=$LIBS
460       LIBS="$Boost_lib_LIBS $LIBS"
461       test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"
462 dnl First argument of AC_LINK_IFELSE left empty because the test file is
463 dnl generated only once above (before we start the for loops).
464       _BOOST_AC_LINK_IFELSE([],
465                             [Boost_lib=yes], [Boost_lib=no])
466       ac_objext=$boost_save_ac_objext
467       LDFLAGS=$boost_save_LDFLAGS
468       LIBS=$boost_save_LIBS
469       if test x"$Boost_lib" = xyes; then
470         # Check or used cached result of whether or not using -R or
471         # -rpath makes sense.  Some implementations of ld, such as for
472         # Mac OSX, require -rpath but -R is the flag known to work on
473         # other systems.  https://github.com/tsuna/boost.m4/issues/19
474         AC_CACHE_VAL([boost_cv_rpath_link_ldflag],
475           [case $boost_ldpath in
476            '') # Nothing to do.
477              boost_cv_rpath_link_ldflag=
478              boost_rpath_link_ldflag_found=yes;;
479            *)
480             for boost_cv_rpath_link_ldflag in -Wl,-R, -Wl,-rpath,; do
481               LDFLAGS="$boost_save_LDFLAGS -L$boost_ldpath $boost_cv_rpath_link_ldflag$boost_ldpath"
482               LIBS="$boost_save_LIBS $Boost_lib_LIBS"
483               _BOOST_AC_LINK_IFELSE([],
484                 [boost_rpath_link_ldflag_found=yes
485                 break],
486                 [boost_rpath_link_ldflag_found=no])
487             done
488             ;;
489           esac
490           AS_IF([test "x$boost_rpath_link_ldflag_found" != "xyes"],
491             [AC_MSG_ERROR([Unable to determine whether to use -R or -rpath])])
492           LDFLAGS=$boost_save_LDFLAGS
493           LIBS=$boost_save_LIBS
494           ])
495         test x"$boost_ldpath" != x &&
496           Boost_lib_LDFLAGS="-L$boost_ldpath $boost_cv_rpath_link_ldflag$boost_ldpath"
497         Boost_lib_LDPATH="$boost_ldpath"
498         break 7
499       else
500         boost_failed_libs="$boost_failed_libs@$boost_lib@"
501       fi
502     done
503   done
504 done
505 done
506 done
507 done
508 done # boost_lib_
509 rm -f conftest.$ac_objext
510 ])
511
512
513
514 # --------------------------------------- #
515 # Checks for the various Boost libraries. #
516 # --------------------------------------- #
517
518 # List of boost libraries: http://www.boost.org/libs/libraries.htm
519 # The page http://beta.boost.org/doc/libs is useful: it gives the first release
520 # version of each library (among other things).
521
522 # BOOST_DEFUN(LIBRARY, CODE)
523 # --------------------------
524 # Define BOOST_<LIBRARY-UPPERCASE> as a macro that runs CODE.
525 #
526 # Use indir to avoid the warning on underquoted macro name given to AC_DEFUN.
527 m4_define([BOOST_DEFUN],
528 [m4_indir([AC_DEFUN],
529           m4_toupper([BOOST_$1]),
530 [m4_pushdef([BOOST_Library], [$1])dnl
531 $2
532 m4_popdef([BOOST_Library])dnl
533 ])
534 ])
535
536 # BOOST_ARRAY()
537 # -------------
538 # Look for Boost.Array
539 BOOST_DEFUN([Array],
540 [BOOST_FIND_HEADER([boost/array.hpp])])
541
542
543 # BOOST_ASIO()
544 # ------------
545 # Look for Boost.Asio (new in Boost 1.35).
546 BOOST_DEFUN([Asio],
547 [AC_REQUIRE([BOOST_SYSTEM])dnl
548 BOOST_FIND_HEADER([boost/asio.hpp])])
549
550
551 # BOOST_BIND()
552 # ------------
553 # Look for Boost.Bind.
554 BOOST_DEFUN([Bind],
555 [BOOST_FIND_HEADER([boost/bind.hpp])])
556
557
558 # BOOST_CHRONO()
559 # --------------
560 # Look for Boost.Chrono.
561 BOOST_DEFUN([Chrono],
562 [# Do we have to check for Boost.System?  This link-time dependency was
563 # added as of 1.35.0.  If we have a version <1.35, we must not attempt to
564 # find Boost.System as it didn't exist by then.
565 if test $boost_major_version -ge 135; then
566   BOOST_SYSTEM([$1])
567 fi # end of the Boost.System check.
568 boost_filesystem_save_LIBS=$LIBS
569 boost_filesystem_save_LDFLAGS=$LDFLAGS
570 m4_pattern_allow([^BOOST_SYSTEM_(LIBS|LDFLAGS)$])dnl
571 LIBS="$LIBS $BOOST_SYSTEM_LIBS"
572 LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS"
573 BOOST_FIND_LIB([chrono], [$1],
574                 [boost/chrono.hpp],
575                 [boost::chrono::thread_clock d;])
576 if test $enable_static_boost = yes && test $boost_major_version -ge 135; then
577   BOOST_CHRONO_LIBS="$BOOST_CHRONO_LIBS $BOOST_SYSTEM_LIBS"
578 fi
579 LIBS=$boost_filesystem_save_LIBS
580 LDFLAGS=$boost_filesystem_save_LDFLAGS
581 ])# BOOST_CHRONO
582
583
584 # BOOST_CONTEXT([PREFERRED-RT-OPT])
585 # -----------------------------------
586 # Look for Boost.Context.  For the documentation of PREFERRED-RT-OPT, see the
587 # documentation of BOOST_FIND_LIB above.  This library was introduced in Boost
588 # 1.51.0
589 BOOST_DEFUN([Context],
590 [BOOST_FIND_LIB([context], [$1],
591                 [boost/context/all.hpp],[[
592 // creates a stack
593 void * stack_pointer = new void*[4096];
594 std::size_t const size = sizeof(void*[4096]);
595
596 // context fc uses f() as context function
597 // fcontext_t is placed on top of context stack
598 // a pointer to fcontext_t is returned
599 fc = ctx::make_fcontext(stack_pointer, size, f);
600 return ctx::jump_fcontext(&fcm, fc, 3) == 6;]],[dnl
601 namespace ctx = boost::context;
602 // context
603 static ctx::fcontext_t fcm, *fc;
604 // context-function
605 static void f(intptr_t i) {
606     ctx::jump_fcontext(fc, &fcm, i * 2);
607 }])
608 ])# BOOST_CONTEXT
609
610
611 # BOOST_CONVERSION()
612 # ------------------
613 # Look for Boost.Conversion (cast / lexical_cast)
614 BOOST_DEFUN([Conversion],
615 [BOOST_FIND_HEADER([boost/cast.hpp])
616 BOOST_FIND_HEADER([boost/lexical_cast.hpp])
617 ])# BOOST_CONVERSION
618
619
620 # BOOST_COROUTINE([PREFERRED-RT-OPT])
621 # -----------------------------------
622 # Look for Boost.Coroutine.  For the documentation of PREFERRED-RT-OPT, see the
623 # documentation of BOOST_FIND_LIB above.  This library was introduced in Boost
624 # 1.53.0
625 BOOST_DEFUN([Coroutine],
626 [
627 boost_coroutine_save_LIBS=$LIBS
628 boost_coroutine_save_LDFLAGS=$LDFLAGS
629 # Link-time dependency from coroutine to context
630 BOOST_CONTEXT([$1])
631 # Starting from Boost 1.55 a dependency on Boost.System is added
632 if test $boost_major_version -ge 155; then
633   BOOST_SYSTEM([$1])
634 fi
635 m4_pattern_allow([^BOOST_(CONTEXT|SYSTEM)_(LIBS|LDFLAGS)])
636 LIBS="$LIBS $BOOST_CONTEXT_LIBS $BOOST_SYSTEM_LIBS"
637 LDFLAGS="$LDFLAGS $BOOST_CONTEXT_LDFLAGS"
638
639 BOOST_FIND_LIB([coroutine], [$1],
640                 [boost/coroutine/coroutine.hpp],
641                 [boost::coroutines::coroutine< int(int) > coro; coro.empty();])
642
643 # Link-time dependency from coroutine to context, existed only in 1.53, in 1.54
644 # coroutine doesn't use context from its headers but from its library.
645 if test $boost_major_version -eq 153 || test $enable_static_boost = yes && test $boost_major_version -ge 154; then
646   BOOST_COROUTINE_LIBS="$BOOST_COROUTINE_LIBS $BOOST_CONTEXT_LIBS"
647   BOOST_COROUTINE_LDFLAGS="$BOOST_COROUTINE_LDFLAGS $BOOST_CONTEXT_LDFLAGS"
648 fi
649 if test $enable_static_boost = yes && test $boost_major_version -ge 155; then
650   BOOST_COROUTINE_LIBS="$BOOST_COROUTINE_LIBS $BOOST_SYSTEM_LIBS"
651   BOOST_COROUTINE_LDFLAGS="$BOOST_COROUTINE_LDFLAGS $BOOST_SYSTEM_LDFLAGS"
652 fi
653 LIBS=$boost_coroutine_save_LIBS
654 LDFLAGS=$boost_coroutine_save_LDFLAGS
655 ])# BOOST_COROUTINE
656
657
658 # BOOST_CRC()
659 # -----------
660 # Look for Boost.CRC
661 BOOST_DEFUN([CRC],
662 [BOOST_FIND_HEADER([boost/crc.hpp])
663 ])# BOOST_CRC
664
665
666 # BOOST_DATE_TIME([PREFERRED-RT-OPT])
667 # -----------------------------------
668 # Look for Boost.Date_Time.  For the documentation of PREFERRED-RT-OPT, see the
669 # documentation of BOOST_FIND_LIB above.
670 BOOST_DEFUN([Date_Time],
671 [BOOST_FIND_LIB([date_time], [$1],
672                 [boost/date_time/posix_time/posix_time.hpp],
673                 [boost::posix_time::ptime t;])
674 ])# BOOST_DATE_TIME
675
676
677 # BOOST_FILESYSTEM([PREFERRED-RT-OPT])
678 # ------------------------------------
679 # Look for Boost.Filesystem.  For the documentation of PREFERRED-RT-OPT, see
680 # the documentation of BOOST_FIND_LIB above.
681 # Do not check for boost/filesystem.hpp because this file was introduced in
682 # 1.34.
683 BOOST_DEFUN([Filesystem],
684 [# Do we have to check for Boost.System?  This link-time dependency was
685 # added as of 1.35.0.  If we have a version <1.35, we must not attempt to
686 # find Boost.System as it didn't exist by then.
687 if test $boost_major_version -ge 135; then
688   BOOST_SYSTEM([$1])
689 fi # end of the Boost.System check.
690 boost_filesystem_save_LIBS=$LIBS
691 boost_filesystem_save_LDFLAGS=$LDFLAGS
692 m4_pattern_allow([^BOOST_SYSTEM_(LIBS|LDFLAGS)$])dnl
693 LIBS="$LIBS $BOOST_SYSTEM_LIBS"
694 LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS"
695 BOOST_FIND_LIB([filesystem], [$1],
696                 [boost/filesystem/path.hpp], [boost::filesystem::path p;])
697 if test $enable_static_boost = yes && test $boost_major_version -ge 135; then
698   BOOST_FILESYSTEM_LIBS="$BOOST_FILESYSTEM_LIBS $BOOST_SYSTEM_LIBS"
699 fi
700 LIBS=$boost_filesystem_save_LIBS
701 LDFLAGS=$boost_filesystem_save_LDFLAGS
702 ])# BOOST_FILESYSTEM
703
704
705 # BOOST_FLYWEIGHT()
706 # -----------------
707 # Look for Boost.Flyweight.
708 BOOST_DEFUN([Flyweight],
709 [dnl There's a hidden dependency on pthreads.
710 AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
711 BOOST_FIND_HEADER([boost/flyweight.hpp])
712 AC_SUBST([BOOST_FLYWEIGHT_LIBS], [$boost_cv_pthread_flag])
713 ])
714
715
716 # BOOST_FOREACH()
717 # ---------------
718 # Look for Boost.Foreach.
719 BOOST_DEFUN([Foreach],
720 [BOOST_FIND_HEADER([boost/foreach.hpp])])
721
722
723 # BOOST_FORMAT()
724 # --------------
725 # Look for Boost.Format.
726 # Note: we can't check for boost/format/format_fwd.hpp because the header isn't
727 # standalone.  It can't be compiled because it triggers the following error:
728 # boost/format/detail/config_macros.hpp:88: error: 'locale' in namespace 'std'
729 #                                                  does not name a type
730 BOOST_DEFUN([Format],
731 [BOOST_FIND_HEADER([boost/format.hpp])])
732
733
734 # BOOST_FUNCTION()
735 # ----------------
736 # Look for Boost.Function
737 BOOST_DEFUN([Function],
738 [BOOST_FIND_HEADER([boost/function.hpp])])
739
740
741 # BOOST_GEOMETRY()
742 # ----------------
743 # Look for Boost.Geometry (new since 1.47.0).
744 BOOST_DEFUN([Geometry],
745 [BOOST_FIND_HEADER([boost/geometry.hpp])
746 ])# BOOST_GEOMETRY
747
748
749 # BOOST_GRAPH([PREFERRED-RT-OPT])
750 # -------------------------------
751 # Look for Boost.Graphs.  For the documentation of PREFERRED-RT-OPT, see the
752 # documentation of BOOST_FIND_LIB above.
753 BOOST_DEFUN([Graph],
754 [BOOST_FIND_LIB([graph], [$1],
755                 [boost/graph/adjacency_list.hpp], [boost::adjacency_list<> g;])
756 ])# BOOST_GRAPH
757
758
759 # BOOST_IOSTREAMS([PREFERRED-RT-OPT])
760 # -----------------------------------
761 # Look for Boost.IOStreams.  For the documentation of PREFERRED-RT-OPT, see the
762 # documentation of BOOST_FIND_LIB above.
763 BOOST_DEFUN([IOStreams],
764 [BOOST_FIND_LIB([iostreams], [$1],
765                 [boost/iostreams/device/file_descriptor.hpp],
766                 [boost::iostreams::file_descriptor fd; fd.close();])
767 ])# BOOST_IOSTREAMS
768
769
770 # BOOST_HASH()
771 # ------------
772 # Look for Boost.Functional/Hash
773 BOOST_DEFUN([Hash],
774 [BOOST_FIND_HEADER([boost/functional/hash.hpp])])
775
776
777 # BOOST_LAMBDA()
778 # --------------
779 # Look for Boost.Lambda
780 BOOST_DEFUN([Lambda],
781 [BOOST_FIND_HEADER([boost/lambda/lambda.hpp])])
782
783
784 # BOOST_LOCALE()
785 # --------------
786 # Look for Boost.Locale
787 BOOST_DEFUN([Locale],
788 [BOOST_FIND_LIB([locale], [$1],
789     [boost/locale.hpp],
790     [[boost::locale::generator gen; std::locale::global(gen(""));]])
791 ])# BOOST_LOCALE
792
793 # BOOST_LOG([PREFERRED-RT-OPT])
794 # -----------------------------
795 # Look for Boost.Log.  For the documentation of PREFERRED-RT-OPT, see the
796 # documentation of BOOST_FIND_LIB above.
797 BOOST_DEFUN([Log],
798 [BOOST_FIND_LIB([log], [$1],
799     [boost/log/core/core.hpp],
800     [boost::log::attribute a; a.get_value();])
801 ])# BOOST_LOG
802
803
804 # BOOST_LOG_SETUP([PREFERRED-RT-OPT])
805 # -----------------------------------
806 # Look for Boost.Log.  For the documentation of PREFERRED-RT-OPT, see the
807 # documentation of BOOST_FIND_LIB above.
808 BOOST_DEFUN([Log_Setup],
809 [AC_REQUIRE([BOOST_LOG])dnl
810 BOOST_FIND_LIB([log_setup], [$1],
811     [boost/log/utility/setup/from_settings.hpp],
812     [boost::log::basic_settings<char> bs; bs.empty();])
813 ])# BOOST_LOG_SETUP
814
815
816 # BOOST_MATH()
817 # ------------
818 # Look for Boost.Math
819 # TODO: This library isn't header-only but it comes in multiple different
820 # flavors that don't play well with BOOST_FIND_LIB (e.g, libboost_math_c99,
821 # libboost_math_c99f, libboost_math_c99l, libboost_math_tr1,
822 # libboost_math_tr1f, libboost_math_tr1l).  This macro must be fixed to do the
823 # right thing anyway.
824 BOOST_DEFUN([Math],
825 [BOOST_FIND_HEADER([boost/math/special_functions.hpp])])
826
827
828 # BOOST_MPI([PREFERRED-RT-OPT])
829 # -------------------------------
830 # Look for Boost MPI.  For the documentation of PREFERRED-RT-OPT, see the
831 # documentation of BOOST_FIND_LIB above.  Uses MPICXX variable if it is
832 # set, otherwise tries CXX
833 #
834 BOOST_DEFUN([MPI],
835 [boost_save_CXX=${CXX}
836 boost_save_CXXCPP=${CXXCPP}
837 if test x"${MPICXX}" != x; then
838   CXX=${MPICXX}
839   CXXCPP="${MPICXX} -E"
840 fi
841 BOOST_FIND_LIB([mpi], [$1],
842                [boost/mpi.hpp],
843                [int argc = 0;
844                 char **argv = 0;
845                 boost::mpi::environment env(argc,argv);])
846 CXX=${boost_save_CXX}
847 CXXCPP=${boost_save_CXXCPP}
848 ])# BOOST_MPI
849
850
851 # BOOST_MULTIARRAY()
852 # ------------------
853 # Look for Boost.MultiArray
854 BOOST_DEFUN([MultiArray],
855 [BOOST_FIND_HEADER([boost/multi_array.hpp])])
856
857
858 # BOOST_NUMERIC_UBLAS()
859 # --------------------------
860 # Look for Boost.NumericUblas (Basic Linear Algebra)
861 BOOST_DEFUN([Numeric_Ublas],
862 [BOOST_FIND_HEADER([boost/numeric/ublas/vector.hpp])
863 ])# BOOST_NUMERIC_UBLAS
864
865
866 # BOOST_NUMERIC_CONVERSION()
867 # --------------------------
868 # Look for Boost.NumericConversion (policy-based numeric conversion)
869 BOOST_DEFUN([Numeric_Conversion],
870 [BOOST_FIND_HEADER([boost/numeric/conversion/converter.hpp])
871 ])# BOOST_NUMERIC_CONVERSION
872
873
874 # BOOST_OPTIONAL()
875 # ----------------
876 # Look for Boost.Optional
877 BOOST_DEFUN([Optional],
878 [BOOST_FIND_HEADER([boost/optional.hpp])])
879
880
881 # BOOST_PREPROCESSOR()
882 # --------------------
883 # Look for Boost.Preprocessor
884 BOOST_DEFUN([Preprocessor],
885 [BOOST_FIND_HEADER([boost/preprocessor/repeat.hpp])])
886
887
888 # BOOST_RANGE()
889 # --------------------
890 # Look for Boost.Range
891 BOOST_DEFUN([Range],
892 [BOOST_FIND_HEADER([boost/range/adaptors.hpp])])
893
894 # BOOST_UNORDERED()
895 # -----------------
896 # Look for Boost.Unordered
897 BOOST_DEFUN([Unordered],
898 [BOOST_FIND_HEADER([boost/unordered_map.hpp])])
899
900
901 # BOOST_UUID()
902 # ------------
903 # Look for Boost.Uuid
904 BOOST_DEFUN([Uuid],
905 [BOOST_FIND_HEADER([boost/uuid/uuid.hpp])])
906
907
908 # BOOST_PROGRAM_OPTIONS([PREFERRED-RT-OPT])
909 # -----------------------------------------
910 # Look for Boost.Program_options.  For the documentation of PREFERRED-RT-OPT,
911 # see the documentation of BOOST_FIND_LIB above.
912 BOOST_DEFUN([Program_Options],
913 [BOOST_FIND_LIB([program_options], [$1],
914                 [boost/program_options.hpp],
915                 [boost::program_options::options_description d("test");])
916 ])# BOOST_PROGRAM_OPTIONS
917
918
919
920 # _BOOST_PYTHON_CONFIG(VARIABLE, FLAG)
921 # ------------------------------------
922 # Save VARIABLE, and define it via `python-config --FLAG`.
923 # Substitute BOOST_PYTHON_VARIABLE.
924 m4_define([_BOOST_PYTHON_CONFIG],
925 [AC_SUBST([BOOST_PYTHON_$1],
926           [`python-config --$2 2>/dev/null`])dnl
927 boost_python_save_$1=$$1
928 $1="$$1 $BOOST_PYTHON_$1"])
929
930
931 # BOOST_PYTHON([PREFERRED-RT-OPT])
932 # --------------------------------
933 # Look for Boost.Python.  For the documentation of PREFERRED-RT-OPT,
934 # see the documentation of BOOST_FIND_LIB above.
935 BOOST_DEFUN([Python],
936 [_BOOST_PYTHON_CONFIG([CPPFLAGS], [includes])
937 _BOOST_PYTHON_CONFIG([LDFLAGS],   [ldflags])
938 _BOOST_PYTHON_CONFIG([LIBS],      [libs])
939 m4_pattern_allow([^BOOST_PYTHON_MODULE$])dnl
940 BOOST_FIND_LIBS([python], [python python3], [$1],
941                 [boost/python.hpp],
942                 [], [BOOST_PYTHON_MODULE(empty) {}])
943 CPPFLAGS=$boost_python_save_CPPFLAGS
944 LDFLAGS=$boost_python_save_LDFLAGS
945 LIBS=$boost_python_save_LIBS
946 ])# BOOST_PYTHON
947
948
949 # BOOST_REF()
950 # -----------
951 # Look for Boost.Ref
952 BOOST_DEFUN([Ref],
953 [BOOST_FIND_HEADER([boost/ref.hpp])])
954
955
956 # BOOST_REGEX([PREFERRED-RT-OPT])
957 # -------------------------------
958 # Look for Boost.Regex.  For the documentation of PREFERRED-RT-OPT, see the
959 # documentation of BOOST_FIND_LIB above.
960 BOOST_DEFUN([Regex],
961 [BOOST_FIND_LIB([regex], [$1],
962                 [boost/regex.hpp],
963                 [boost::regex exp("*"); boost::regex_match("foo", exp);])
964 ])# BOOST_REGEX
965
966
967 # BOOST_SERIALIZATION([PREFERRED-RT-OPT])
968 # ---------------------------------------
969 # Look for Boost.Serialization.  For the documentation of PREFERRED-RT-OPT, see
970 # the documentation of BOOST_FIND_LIB above.
971 BOOST_DEFUN([Serialization],
972 [BOOST_FIND_LIB([serialization], [$1],
973                 [boost/archive/text_oarchive.hpp],
974                 [std::ostream* o = 0; // Cheap way to get an ostream...
975                 boost::archive::text_oarchive t(*o);])
976 ])# BOOST_SERIALIZATION
977
978
979 # BOOST_SIGNALS([PREFERRED-RT-OPT])
980 # ---------------------------------
981 # Look for Boost.Signals.  For the documentation of PREFERRED-RT-OPT, see the
982 # documentation of BOOST_FIND_LIB above.
983 BOOST_DEFUN([Signals],
984 [BOOST_FIND_LIB([signals], [$1],
985                 [boost/signal.hpp],
986                 [boost::signal<void ()> s;])
987 ])# BOOST_SIGNALS
988
989
990 # BOOST_SIGNALS2()
991 # ----------------
992 # Look for Boost.Signals2 (new since 1.39.0).
993 BOOST_DEFUN([Signals2],
994 [BOOST_FIND_HEADER([boost/signals2.hpp])
995 ])# BOOST_SIGNALS2
996
997
998 # BOOST_SMART_PTR()
999 # -----------------
1000 # Look for Boost.SmartPtr
1001 BOOST_DEFUN([Smart_Ptr],
1002 [BOOST_FIND_HEADER([boost/scoped_ptr.hpp])
1003 BOOST_FIND_HEADER([boost/shared_ptr.hpp])
1004 ])
1005
1006
1007 # BOOST_STATICASSERT()
1008 # --------------------
1009 # Look for Boost.StaticAssert
1010 BOOST_DEFUN([StaticAssert],
1011 [BOOST_FIND_HEADER([boost/static_assert.hpp])])
1012
1013
1014 # BOOST_STRING_ALGO()
1015 # -------------------
1016 # Look for Boost.StringAlgo
1017 BOOST_DEFUN([String_Algo],
1018 [BOOST_FIND_HEADER([boost/algorithm/string.hpp])
1019 ])
1020
1021
1022 # BOOST_SYSTEM([PREFERRED-RT-OPT])
1023 # --------------------------------
1024 # Look for Boost.System.  For the documentation of PREFERRED-RT-OPT, see the
1025 # documentation of BOOST_FIND_LIB above.  This library was introduced in Boost
1026 # 1.35.0.
1027 BOOST_DEFUN([System],
1028 [BOOST_FIND_LIB([system], [$1],
1029                 [boost/system/error_code.hpp],
1030                 [boost::system::error_code e; e.clear();])
1031 ])# BOOST_SYSTEM
1032
1033
1034 # BOOST_TEST([PREFERRED-RT-OPT])
1035 # ------------------------------
1036 # Look for Boost.Test.  For the documentation of PREFERRED-RT-OPT, see the
1037 # documentation of BOOST_FIND_LIB above.
1038 BOOST_DEFUN([Test],
1039 [m4_pattern_allow([^BOOST_CHECK$])dnl
1040 BOOST_FIND_LIB([unit_test_framework], [$1],
1041                [boost/test/unit_test.hpp], [BOOST_CHECK(2 == 2);],
1042                [using boost::unit_test::test_suite;
1043                test_suite* init_unit_test_suite(int argc, char ** argv)
1044                { return NULL; }])
1045 ])# BOOST_TEST
1046
1047
1048 # BOOST_THREAD([PREFERRED-RT-OPT])
1049 # ---------------------------------
1050 # Look for Boost.Thread.  For the documentation of PREFERRED-RT-OPT, see the
1051 # documentation of BOOST_FIND_LIB above.
1052 BOOST_DEFUN([Thread],
1053 [dnl Having the pthread flag is required at least on GCC3 where
1054 dnl boost/thread.hpp would complain if we try to compile without
1055 dnl -pthread on GNU/Linux.
1056 AC_REQUIRE([_BOOST_PTHREAD_FLAG])dnl
1057 boost_thread_save_LIBS=$LIBS
1058 boost_thread_save_LDFLAGS=$LDFLAGS
1059 boost_thread_save_CPPFLAGS=$CPPFLAGS
1060 # Link-time dependency from thread to system was added as of 1.49.0.
1061 if test $boost_major_version -ge 149; then
1062 BOOST_SYSTEM([$1])
1063 fi # end of the Boost.System check.
1064 m4_pattern_allow([^BOOST_SYSTEM_(LIBS|LDFLAGS)$])dnl
1065 LIBS="$LIBS $BOOST_SYSTEM_LIBS $boost_cv_pthread_flag"
1066 LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS"
1067 CPPFLAGS="$CPPFLAGS $boost_cv_pthread_flag"
1068
1069 # When compiling for the Windows platform, the threads library is named
1070 # differently.
1071 case $host_os in
1072   (*mingw*) boost_thread_lib_ext=_win32;;
1073 esac
1074 BOOST_FIND_LIBS([thread], [thread$boost_thread_lib_ext],
1075                 [$1],
1076                 [boost/thread.hpp], [boost::thread t; boost::mutex m;])
1077
1078 BOOST_THREAD_LIBS="$BOOST_THREAD_LIBS $BOOST_SYSTEM_LIBS $boost_cv_pthread_flag"
1079 BOOST_THREAD_LDFLAGS="$BOOST_SYSTEM_LDFLAGS"
1080 BOOST_CPPFLAGS="$BOOST_CPPFLAGS $boost_cv_pthread_flag"
1081 LIBS=$boost_thread_save_LIBS
1082 LDFLAGS=$boost_thread_save_LDFLAGS
1083 CPPFLAGS=$boost_thread_save_CPPFLAGS
1084 ])# BOOST_THREAD
1085
1086 AU_ALIAS([BOOST_THREADS], [BOOST_THREAD])
1087
1088
1089 # BOOST_TOKENIZER()
1090 # -----------------
1091 # Look for Boost.Tokenizer
1092 BOOST_DEFUN([Tokenizer],
1093 [BOOST_FIND_HEADER([boost/tokenizer.hpp])])
1094
1095
1096 # BOOST_TRIBOOL()
1097 # ---------------
1098 # Look for Boost.Tribool
1099 BOOST_DEFUN([Tribool],
1100 [BOOST_FIND_HEADER([boost/logic/tribool_fwd.hpp])
1101 BOOST_FIND_HEADER([boost/logic/tribool.hpp])
1102 ])
1103
1104
1105 # BOOST_TUPLE()
1106 # -------------
1107 # Look for Boost.Tuple
1108 BOOST_DEFUN([Tuple],
1109 [BOOST_FIND_HEADER([boost/tuple/tuple.hpp])])
1110
1111
1112 # BOOST_TYPETRAITS()
1113 # --------------------
1114 # Look for Boost.TypeTraits
1115 BOOST_DEFUN([TypeTraits],
1116 [BOOST_FIND_HEADER([boost/type_traits.hpp])])
1117
1118
1119 # BOOST_UTILITY()
1120 # ---------------
1121 # Look for Boost.Utility (noncopyable, result_of, base-from-member idiom,
1122 # etc.)
1123 BOOST_DEFUN([Utility],
1124 [BOOST_FIND_HEADER([boost/utility.hpp])])
1125
1126
1127 # BOOST_VARIANT()
1128 # ---------------
1129 # Look for Boost.Variant.
1130 BOOST_DEFUN([Variant],
1131 [BOOST_FIND_HEADER([boost/variant/variant_fwd.hpp])
1132 BOOST_FIND_HEADER([boost/variant.hpp])])
1133
1134
1135 # BOOST_POINTER_CONTAINER()
1136 # ------------------------
1137 # Look for Boost.PointerContainer
1138 BOOST_DEFUN([Pointer_Container],
1139 [BOOST_FIND_HEADER([boost/ptr_container/ptr_deque.hpp])
1140 BOOST_FIND_HEADER([boost/ptr_container/ptr_list.hpp])
1141 BOOST_FIND_HEADER([boost/ptr_container/ptr_vector.hpp])
1142 BOOST_FIND_HEADER([boost/ptr_container/ptr_array.hpp])
1143 BOOST_FIND_HEADER([boost/ptr_container/ptr_set.hpp])
1144 BOOST_FIND_HEADER([boost/ptr_container/ptr_map.hpp])
1145 ])# BOOST_POINTER_CONTAINER
1146
1147
1148 # BOOST_WAVE([PREFERRED-RT-OPT])
1149 # ------------------------------
1150 # NOTE: If you intend to use Wave/Spirit with thread support, make sure you
1151 # call BOOST_THREAD first.
1152 # Look for Boost.Wave.  For the documentation of PREFERRED-RT-OPT, see the
1153 # documentation of BOOST_FIND_LIB above.
1154 BOOST_DEFUN([Wave],
1155 [AC_REQUIRE([BOOST_FILESYSTEM])dnl
1156 AC_REQUIRE([BOOST_DATE_TIME])dnl
1157 boost_wave_save_LIBS=$LIBS
1158 boost_wave_save_LDFLAGS=$LDFLAGS
1159 m4_pattern_allow([^BOOST_((FILE)?SYSTEM|DATE_TIME|THREAD)_(LIBS|LDFLAGS)$])dnl
1160 LIBS="$LIBS $BOOST_SYSTEM_LIBS $BOOST_FILESYSTEM_LIBS $BOOST_DATE_TIME_LIBS \
1161 $BOOST_THREAD_LIBS"
1162 LDFLAGS="$LDFLAGS $BOOST_SYSTEM_LDFLAGS $BOOST_FILESYSTEM_LDFLAGS \
1163 $BOOST_DATE_TIME_LDFLAGS $BOOST_THREAD_LDFLAGS"
1164 BOOST_FIND_LIB([wave], [$1],
1165                 [boost/wave.hpp],
1166                 [boost::wave::token_id id; get_token_name(id);])
1167 LIBS=$boost_wave_save_LIBS
1168 LDFLAGS=$boost_wave_save_LDFLAGS
1169 ])# BOOST_WAVE
1170
1171
1172 # BOOST_XPRESSIVE()
1173 # -----------------
1174 # Look for Boost.Xpressive (new since 1.36.0).
1175 BOOST_DEFUN([Xpressive],
1176 [BOOST_FIND_HEADER([boost/xpressive/xpressive.hpp])])
1177
1178
1179 # ----------------- #
1180 # Internal helpers. #
1181 # ----------------- #
1182
1183
1184 # _BOOST_PTHREAD_FLAG()
1185 # ---------------------
1186 # Internal helper for BOOST_THREAD.  Computes boost_cv_pthread_flag
1187 # which must be used in CPPFLAGS and LIBS.
1188 #
1189 # Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3,
1190 # boost/thread.hpp will trigger a #error if -pthread isn't used:
1191 #   boost/config/requires_threads.hpp:47:5: #error "Compiler threading support
1192 #   is not turned on. Please set the correct command line options for
1193 #   threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
1194 #
1195 # Based on ACX_PTHREAD: http://autoconf-archive.cryp.to/acx_pthread.html
1196 AC_DEFUN([_BOOST_PTHREAD_FLAG],
1197 [AC_REQUIRE([AC_PROG_CXX])dnl
1198 AC_REQUIRE([AC_CANONICAL_HOST])dnl
1199 AC_LANG_PUSH([C++])dnl
1200 AC_CACHE_CHECK([for the flags needed to use pthreads], [boost_cv_pthread_flag],
1201 [ boost_cv_pthread_flag=
1202   # The ordering *is* (sometimes) important.  Some notes on the
1203   # individual items follow:
1204   # (none): in case threads are in libc; should be tried before -Kthread and
1205   #       other compiler flags to prevent continual compiler warnings
1206   # -lpthreads: AIX (must check this before -lpthread)
1207   # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
1208   # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
1209   # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
1210   # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads)
1211   # -pthreads: Solaris/GCC
1212   # -mthreads: MinGW32/GCC, Lynx/GCC
1213   # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
1214   #      doesn't hurt to check since this sometimes defines pthreads too;
1215   #      also defines -D_REENTRANT)
1216   #      ... -mt is also the pthreads flag for HP/aCC
1217   # -lpthread: GNU Linux, etc.
1218   # --thread-safe: KAI C++
1219   case $host_os in #(
1220     *solaris*)
1221       # On Solaris (at least, for some versions), libc contains stubbed
1222       # (non-functional) versions of the pthreads routines, so link-based
1223       # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
1224       # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
1225       # a function called by this macro, so we could check for that, but
1226       # who knows whether they'll stub that too in a future libc.)  So,
1227       # we'll just look for -pthreads and -lpthread first:
1228       boost_pthread_flags="-pthreads -lpthread -mt -pthread";; #(
1229     *)
1230       boost_pthread_flags="-lpthreads -Kthread -kthread -llthread -pthread \
1231                            -pthreads -mthreads -lpthread --thread-safe -mt";;
1232   esac
1233   # Generate the test file.
1234   AC_LANG_CONFTEST([AC_LANG_PROGRAM([#include <pthread.h>],
1235     [pthread_t th; pthread_join(th, 0);
1236     pthread_attr_init(0); pthread_cleanup_push(0, 0);
1237     pthread_create(0,0,0,0); pthread_cleanup_pop(0);])])
1238   for boost_pthread_flag in '' $boost_pthread_flags; do
1239     boost_pthread_ok=false
1240 dnl Re-use the test file already generated.
1241     boost_pthreads__save_LIBS=$LIBS
1242     LIBS="$LIBS $boost_pthread_flag"
1243     AC_LINK_IFELSE([],
1244       [if grep ".*$boost_pthread_flag" conftest.err; then
1245          echo "This flag seems to have triggered warnings" >&AS_MESSAGE_LOG_FD
1246        else
1247          boost_pthread_ok=:; boost_cv_pthread_flag=$boost_pthread_flag
1248        fi])
1249     LIBS=$boost_pthreads__save_LIBS
1250     $boost_pthread_ok && break
1251   done
1252 ])
1253 AC_LANG_POP([C++])dnl
1254 ])# _BOOST_PTHREAD_FLAG
1255
1256
1257 # _BOOST_gcc_test(MAJOR, MINOR)
1258 # -----------------------------
1259 # Internal helper for _BOOST_FIND_COMPILER_TAG.
1260 m4_define([_BOOST_gcc_test],
1261 ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC @ gcc$1$2"])dnl
1262
1263 # _BOOST_mingw_test(MAJOR, MINOR)
1264 # -----------------------------
1265 # Internal helper for _BOOST_FIND_COMPILER_TAG.
1266 m4_define([_BOOST_mingw_test],
1267 ["defined __GNUC__ && __GNUC__ == $1 && __GNUC_MINOR__ == $2 && !defined __ICC && \
1268   (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
1269          || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw$1$2"])dnl
1270
1271
1272 # _BOOST_FIND_COMPILER_TAG()
1273 # --------------------------
1274 # Internal.  When Boost is installed without --layout=system, each library
1275 # filename will hold a suffix that encodes the compiler used during the
1276 # build.  The Boost build system seems to call this a `tag'.
1277 AC_DEFUN([_BOOST_FIND_COMPILER_TAG],
1278 [AC_REQUIRE([AC_PROG_CXX])dnl
1279 AC_REQUIRE([AC_CANONICAL_HOST])dnl
1280 AC_CACHE_CHECK([for the toolset name used by Boost for $CXX],
1281                [boost_cv_lib_tag],
1282 [boost_cv_lib_tag=unknown
1283 if test x$boost_cv_inc_path != xno; then
1284   AC_LANG_PUSH([C++])dnl
1285   # The following tests are mostly inspired by boost/config/auto_link.hpp
1286   # The list is sorted to most recent/common to oldest compiler (in order
1287   # to increase the likelihood of finding the right compiler with the
1288   # least number of compilation attempt).
1289   # Beware that some tests are sensible to the order (for instance, we must
1290   # look for MinGW before looking for GCC3).
1291   # I used one compilation test per compiler with a #error to recognize
1292   # each compiler so that it works even when cross-compiling (let me know
1293   # if you know a better approach).
1294   # Known missing tags (known from Boost's tools/build/v2/tools/common.jam):
1295   #   como, edg, kcc, bck, mp, sw, tru, xlc
1296   # I'm not sure about my test for `il' (be careful: Intel's ICC pre-defines
1297   # the same defines as GCC's).
1298   for i in \
1299     _BOOST_mingw_test(5, 0) \
1300     _BOOST_gcc_test(5, 0) \
1301     _BOOST_mingw_test(4, 10) \
1302     _BOOST_gcc_test(4, 10) \
1303     _BOOST_mingw_test(4, 9) \
1304     _BOOST_gcc_test(4, 9) \
1305     _BOOST_mingw_test(4, 8) \
1306     _BOOST_gcc_test(4, 8) \
1307     _BOOST_mingw_test(4, 7) \
1308     _BOOST_gcc_test(4, 7) \
1309     _BOOST_mingw_test(4, 6) \
1310     _BOOST_gcc_test(4, 6) \
1311     _BOOST_mingw_test(4, 5) \
1312     _BOOST_gcc_test(4, 5) \
1313     _BOOST_mingw_test(4, 4) \
1314     _BOOST_gcc_test(4, 4) \
1315     _BOOST_mingw_test(4, 3) \
1316     _BOOST_gcc_test(4, 3) \
1317     _BOOST_mingw_test(4, 2) \
1318     _BOOST_gcc_test(4, 2) \
1319     _BOOST_mingw_test(4, 1) \
1320     _BOOST_gcc_test(4, 1) \
1321     _BOOST_mingw_test(4, 0) \
1322     _BOOST_gcc_test(4, 0) \
1323     "defined __GNUC__ && __GNUC__ == 3 && !defined __ICC \
1324      && (defined WIN32 || defined WINNT || defined _WIN32 || defined __WIN32 \
1325          || defined __WIN32__ || defined __WINNT || defined __WINNT__) @ mgw" \
1326     _BOOST_gcc_test(3, 4) \
1327     _BOOST_gcc_test(3, 3) \
1328     "defined _MSC_VER && _MSC_VER >= 1500 @ vc90" \
1329     "defined _MSC_VER && _MSC_VER == 1400 @ vc80" \
1330     _BOOST_gcc_test(3, 2) \
1331     "defined _MSC_VER && _MSC_VER == 1310 @ vc71" \
1332     _BOOST_gcc_test(3, 1) \
1333     _BOOST_gcc_test(3, 0) \
1334     "defined __BORLANDC__ @ bcb" \
1335     "defined __ICC && (defined __unix || defined __unix__) @ il" \
1336     "defined __ICL @ iw" \
1337     "defined _MSC_VER && _MSC_VER == 1300 @ vc7" \
1338     _BOOST_gcc_test(2, 95) \
1339     "defined __MWERKS__ && __MWERKS__ <= 0x32FF @ cw9" \
1340     "defined _MSC_VER && _MSC_VER < 1300 && !defined UNDER_CE @ vc6" \
1341     "defined _MSC_VER && _MSC_VER < 1300 && defined UNDER_CE @ evc4" \
1342     "defined __MWERKS__ && __MWERKS__ <= 0x31FF @ cw8"
1343   do
1344     boost_tag_test=`expr "X$i" : 'X\([[^@]]*\) @ '`
1345     boost_tag=`expr "X$i" : 'X[[^@]]* @ \(.*\)'`
1346     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1347 #if $boost_tag_test
1348 /* OK */
1349 #else
1350 # error $boost_tag_test
1351 #endif
1352 ]])], [boost_cv_lib_tag=$boost_tag; break], [])
1353   done
1354 AC_LANG_POP([C++])dnl
1355   case $boost_cv_lib_tag in #(
1356     # Some newer (>= 1.35?) versions of Boost seem to only use "gcc" as opposed
1357     # to "gcc41" for instance.
1358     *-gcc | *'-gcc ') :;; #(  Don't re-add -gcc: it's already in there.
1359     gcc*)
1360       boost_tag_x=
1361       case $host_os in #(
1362         darwin*)
1363           if test $boost_major_version -ge 136; then
1364             # The `x' added in r46793 of Boost.
1365             boost_tag_x=x
1366           fi;;
1367       esac
1368       # We can specify multiple tags in this variable because it's used by
1369       # BOOST_FIND_LIB that does a `for tag in -$boost_cv_lib_tag' ...
1370       boost_cv_lib_tag="$boost_tag_x$boost_cv_lib_tag -${boost_tag_x}gcc"
1371       ;; #(
1372     unknown)
1373       AC_MSG_WARN([[could not figure out which toolset name to use for $CXX]])
1374       boost_cv_lib_tag=
1375       ;;
1376   esac
1377 fi])dnl end of AC_CACHE_CHECK
1378 ])# _BOOST_FIND_COMPILER_TAG
1379
1380
1381 # _BOOST_GUESS_WHETHER_TO_USE_MT()
1382 # --------------------------------
1383 # Compile a small test to try to guess whether we should favor MT (Multi
1384 # Thread) flavors of Boost.  Sets boost_guess_use_mt accordingly.
1385 AC_DEFUN([_BOOST_GUESS_WHETHER_TO_USE_MT],
1386 [# Check whether we do better use `mt' even though we weren't ask to.
1387 AC_LANG_PUSH([C++])dnl
1388 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1389 #if defined _REENTRANT || defined _MT || defined __MT__
1390 /* use -mt */
1391 #else
1392 # error MT not needed
1393 #endif
1394 ]])], [boost_guess_use_mt=:], [boost_guess_use_mt=false])
1395 AC_LANG_POP([C++])dnl
1396 ])
1397
1398 # _BOOST_AC_LINK_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
1399 # -------------------------------------------------------------------
1400 # Fork of _AC_LINK_IFELSE that preserves conftest.o across calls.  Fragile,
1401 # will break when Autoconf changes its internals.  Requires that you manually
1402 # rm -f conftest.$ac_objext in between to really different tests, otherwise
1403 # you will try to link a conftest.o left behind by a previous test.
1404 # Used to aggressively optimize BOOST_FIND_LIB (see the big comment in this
1405 # macro).
1406 #
1407 # Don't use "break" in the actions, as it would short-circuit some code
1408 # this macro runs after the actions.
1409 m4_define([_BOOST_AC_LINK_IFELSE],
1410 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
1411 rm -f conftest$ac_exeext
1412 boost_save_ac_ext=$ac_ext
1413 boost_use_source=:
1414 # If we already have a .o, re-use it.  We change $ac_ext so that $ac_link
1415 # tries to link the existing object file instead of compiling from source.
1416 test -f conftest.$ac_objext && ac_ext=$ac_objext && boost_use_source=false &&
1417   _AS_ECHO_LOG([re-using the existing conftest.$ac_objext])
1418 AS_IF([_AC_DO_STDERR($ac_link) && {
1419          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
1420          test ! -s conftest.err
1421        } && test -s conftest$ac_exeext && {
1422          test "$cross_compiling" = yes ||
1423          $as_executable_p conftest$ac_exeext
1424 dnl FIXME: use AS_TEST_X instead when 2.61 is widespread enough.
1425        }],
1426       [$2],
1427       [if $boost_use_source; then
1428          _AC_MSG_LOG_CONFTEST
1429        fi
1430        $3])
1431 ac_objext=$boost_save_ac_objext
1432 ac_ext=$boost_save_ac_ext
1433 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
1434 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
1435 dnl as it would interfere with the next link command.
1436 rm -f core conftest.err conftest_ipa8_conftest.oo \
1437       conftest$ac_exeext m4_ifval([$1], [conftest.$ac_ext])[]dnl
1438 ])# _BOOST_AC_LINK_IFELSE
1439
1440 # Local Variables:
1441 # mode: autoconf
1442 # End: