source: trunk/m4/ax_boost_base.m4

Last change on this file was 4042, checked in by Peter, 4 months ago

upgrade to autoconf-archive-2021.02.19

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 13.5 KB
Line 
1# ===========================================================================
2#      https://www.gnu.org/software/autoconf-archive/ax_boost_base.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
8#
9# DESCRIPTION
10#
11#   Test for the Boost C++ libraries of a particular version (or newer)
12#
13#   If no path to the installed boost library is given the macro searchs
14#   under /usr, /usr/local, /opt and /opt/local and evaluates the
15#   $BOOST_ROOT environment variable. Further documentation is available at
16#   <http://randspringer.de/boost/index.html>.
17#
18#   This macro calls:
19#
20#     AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
21#
22#   And sets:
23#
24#     HAVE_BOOST
25#
26# LICENSE
27#
28#   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
29#   Copyright (c) 2009 Peter Adolphs
30#
31#   Copying and distribution of this file, with or without modification, are
32#   permitted in any medium without royalty provided the copyright notice
33#   and this notice are preserved. This file is offered as-is, without any
34#   warranty.
35
36#serial 49
37
38# example boost program (need to pass version)
39m4_define([_AX_BOOST_BASE_PROGRAM],
40          [AC_LANG_PROGRAM([[
41#include <boost/version.hpp>
42]],[[
43(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));
44]])])
45
46AC_DEFUN([AX_BOOST_BASE],
47[
48AC_ARG_WITH([boost],
49  [AS_HELP_STRING([--with-boost@<:@=ARG@:>@],
50    [use Boost library from a standard location (ARG=yes),
51     from the specified location (ARG=<path>),
52     or disable it (ARG=no)
53     @<:@ARG=yes@:>@ ])],
54    [
55     AS_CASE([$withval],
56       [no],[want_boost="no";_AX_BOOST_BASE_boost_path=""],
57       [yes],[want_boost="yes";_AX_BOOST_BASE_boost_path=""],
58       [want_boost="yes";_AX_BOOST_BASE_boost_path="$withval"])
59    ],
60    [want_boost="yes"])
61
62
63AC_ARG_WITH([boost-libdir],
64  [AS_HELP_STRING([--with-boost-libdir=LIB_DIR],
65    [Force given directory for boost libraries.
66     Note that this will override library path detection,
67     so use this parameter only if default library detection fails
68     and you know exactly where your boost libraries are located.])],
69  [
70   AS_IF([test -d "$withval"],
71         [_AX_BOOST_BASE_boost_lib_path="$withval"],
72    [AC_MSG_ERROR([--with-boost-libdir expected directory name])])
73  ],
74  [_AX_BOOST_BASE_boost_lib_path=""])
75
76BOOST_LDFLAGS=""
77BOOST_CPPFLAGS=""
78AS_IF([test "x$want_boost" = "xyes"],
79      [_AX_BOOST_BASE_RUNDETECT([$1],[$2],[$3])])
80AC_SUBST(BOOST_CPPFLAGS)
81AC_SUBST(BOOST_LDFLAGS)
82])
83
84
85# convert a version string in $2 to numeric and affect to polymorphic var $1
86AC_DEFUN([_AX_BOOST_BASE_TONUMERICVERSION],[
87  AS_IF([test "x$2" = "x"],[_AX_BOOST_BASE_TONUMERICVERSION_req="1.20.0"],[_AX_BOOST_BASE_TONUMERICVERSION_req="$2"])
88  _AX_BOOST_BASE_TONUMERICVERSION_req_shorten=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([[0-9]]*\.[[0-9]]*\)'`
89  _AX_BOOST_BASE_TONUMERICVERSION_req_major=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([[0-9]]*\)'`
90  AS_IF([test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_major" = "x"],
91        [AC_MSG_ERROR([You should at least specify libboost major version])])
92  _AX_BOOST_BASE_TONUMERICVERSION_req_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[[0-9]]*\.\([[0-9]]*\)'`
93  AS_IF([test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_minor" = "x"],
94        [_AX_BOOST_BASE_TONUMERICVERSION_req_minor="0"])
95  _AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
96  AS_IF([test "X$_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor" = "X"],
97        [_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor="0"])
98  _AX_BOOST_BASE_TONUMERICVERSION_RET=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req_major \* 100000 \+  $_AX_BOOST_BASE_TONUMERICVERSION_req_minor \* 100 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor`
99  AS_VAR_SET($1,$_AX_BOOST_BASE_TONUMERICVERSION_RET)
100])
101
102dnl Run the detection of boost should be run only if $want_boost
103AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[
104    _AX_BOOST_BASE_TONUMERICVERSION(WANT_BOOST_VERSION,[$1])
105    succeeded=no
106
107
108    AC_REQUIRE([AC_CANONICAL_HOST])
109    dnl On 64-bit systems check for system libraries in both lib64 and lib.
110    dnl The former is specified by FHS, but e.g. Debian does not adhere to
111    dnl this (as it rises problems for generic multi-arch support).
112    dnl The last entry in the list is chosen by default when no libraries
113    dnl are found, e.g. when only header-only libraries are installed!
114    AS_CASE([${host_cpu}],
115      [x86_64],[libsubdirs="lib64 libx32 lib lib64"],
116      [mips*64*],[libsubdirs="lib64 lib32 lib lib64"],
117      [ppc64|powerpc64|s390x|sparc64|aarch64|ppc64le|powerpc64le|riscv64|e2k],[libsubdirs="lib64 lib lib64"],
118      [libsubdirs="lib"]
119    )
120
121    dnl allow for real multi-arch paths e.g. /usr/lib/x86_64-linux-gnu. Give
122    dnl them priority over the other paths since, if libs are found there, they
123    dnl are almost assuredly the ones desired.
124    AS_CASE([${host_cpu}],
125      [i?86],[multiarch_libsubdir="lib/i386-${host_os}"],
126      [armv7l],[multiarch_libsubdir="lib/arm-${host_os}"],
127      [multiarch_libsubdir="lib/${host_cpu}-${host_os}"]
128    )
129
130    dnl first we check the system location for boost libraries
131    dnl this location ist chosen if boost libraries are installed with the --layout=system option
132    dnl or if you install boost with RPM
133    AS_IF([test "x$_AX_BOOST_BASE_boost_path" != "x"],[
134        AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) includes in "$_AX_BOOST_BASE_boost_path/include"])
135         AS_IF([test -d "$_AX_BOOST_BASE_boost_path/include" && test -r "$_AX_BOOST_BASE_boost_path/include"],[
136           AC_MSG_RESULT([yes])
137           BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include"
138           for _AX_BOOST_BASE_boost_path_tmp in $multiarch_libsubdir $libsubdirs; do
139                AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) lib path in "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp"])
140                AS_IF([test -d "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" && test -r "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" ],[
141                        AC_MSG_RESULT([yes])
142                        BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp";
143                        break;
144                ],
145      [AC_MSG_RESULT([no])])
146           done],[
147      AC_MSG_RESULT([no])])
148    ],[
149        if test X"$cross_compiling" = Xyes; then
150            search_libsubdirs=$multiarch_libsubdir
151        else
152            search_libsubdirs="$multiarch_libsubdir $libsubdirs"
153        fi
154        for _AX_BOOST_BASE_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
155            if test -d "$_AX_BOOST_BASE_boost_path_tmp/include/boost" && test -r "$_AX_BOOST_BASE_boost_path_tmp/include/boost" ; then
156                for libsubdir in $search_libsubdirs ; do
157                    if ls "$_AX_BOOST_BASE_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
158                done
159                BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path_tmp/$libsubdir"
160                BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path_tmp/include"
161                break;
162            fi
163        done
164    ])
165
166    dnl overwrite ld flags if we have required special directory with
167    dnl --with-boost-libdir parameter
168    AS_IF([test "x$_AX_BOOST_BASE_boost_lib_path" != "x"],
169          [BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_lib_path"])
170
171    AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION)])
172    CPPFLAGS_SAVED="$CPPFLAGS"
173    CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
174    export CPPFLAGS
175
176    LDFLAGS_SAVED="$LDFLAGS"
177    LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
178    export LDFLAGS
179
180    AC_REQUIRE([AC_PROG_CXX])
181    AC_LANG_PUSH(C++)
182        AC_COMPILE_IFELSE([_AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)],[
183        AC_MSG_RESULT(yes)
184    succeeded=yes
185    found_system=yes
186        ],[
187        ])
188    AC_LANG_POP([C++])
189
190
191
192    dnl if we found no boost with system layout we search for boost libraries
193    dnl built and installed without the --layout=system option or for a staged(not installed) version
194    if test "x$succeeded" != "xyes" ; then
195        CPPFLAGS="$CPPFLAGS_SAVED"
196        LDFLAGS="$LDFLAGS_SAVED"
197        BOOST_CPPFLAGS=
198        if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
199            BOOST_LDFLAGS=
200        fi
201        _version=0
202        if test -n "$_AX_BOOST_BASE_boost_path" ; then
203            if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path"; then
204                for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do
205                    _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
206                    V_CHECK=`expr $_version_tmp \> $_version`
207                    if test "x$V_CHECK" = "x1" ; then
208                        _version=$_version_tmp
209                    fi
210                    VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
211                    BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include/boost-$VERSION_UNDERSCORE"
212                done
213                dnl if nothing found search for layout used in Windows distributions
214                if test -z "$BOOST_CPPFLAGS"; then
215                    if test -d "$_AX_BOOST_BASE_boost_path/boost" && test -r "$_AX_BOOST_BASE_boost_path/boost"; then
216                        BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path"
217                    fi
218                fi
219                dnl if we found something and BOOST_LDFLAGS was unset before
220                dnl (because "$_AX_BOOST_BASE_boost_lib_path" = ""), set it here.
221                if test -n "$BOOST_CPPFLAGS" && test -z "$BOOST_LDFLAGS"; then
222                    for libsubdir in $libsubdirs ; do
223                        if ls "$_AX_BOOST_BASE_boost_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
224                    done
225                    BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$libsubdir"
226                fi
227            fi
228        else
229            if test "x$cross_compiling" != "xyes" ; then
230                for _AX_BOOST_BASE_boost_path in /usr /usr/local /opt /opt/local ; do
231                    if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path" ; then
232                        for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do
233                            _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
234                            V_CHECK=`expr $_version_tmp \> $_version`
235                            if test "x$V_CHECK" = "x1" ; then
236                                _version=$_version_tmp
237                                best_path=$_AX_BOOST_BASE_boost_path
238                            fi
239                        done
240                    fi
241                done
242
243                VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
244                BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
245                if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
246                    for libsubdir in $libsubdirs ; do
247                        if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
248                    done
249                    BOOST_LDFLAGS="-L$best_path/$libsubdir"
250                fi
251            fi
252
253            if test -n "$BOOST_ROOT" ; then
254                for libsubdir in $libsubdirs ; do
255                    if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
256                done
257                if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then
258                    version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
259                    stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
260                        stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
261                    V_CHECK=`expr $stage_version_shorten \>\= $_version`
262                    if test "x$V_CHECK" = "x1" && test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
263                        AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
264                        BOOST_CPPFLAGS="-I$BOOST_ROOT"
265                        BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
266                    fi
267                fi
268            fi
269        fi
270
271        CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
272        export CPPFLAGS
273        LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
274        export LDFLAGS
275
276        AC_LANG_PUSH(C++)
277            AC_COMPILE_IFELSE([_AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)],[
278            AC_MSG_RESULT(yes)
279        succeeded=yes
280        found_system=yes
281            ],[
282            ])
283        AC_LANG_POP([C++])
284    fi
285
286    if test "x$succeeded" != "xyes" ; then
287        if test "x$_version" = "x0" ; then
288            AC_MSG_NOTICE([[We could not detect the boost libraries (version $1 or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option.  If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.]])
289        else
290            AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
291        fi
292        # execute ACTION-IF-NOT-FOUND (if present):
293        ifelse([$3], , :, [$3])
294    else
295        AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
296        # execute ACTION-IF-FOUND (if present):
297        ifelse([$2], , :, [$2])
298    fi
299
300    CPPFLAGS="$CPPFLAGS_SAVED"
301    LDFLAGS="$LDFLAGS_SAVED"
302
303])
Note: See TracBrowser for help on using the repository browser.