preload: cleanup disabled messages and simplify flow.
[LibreOffice.git] / m4 / ax_boost_base.m4
blob94909a52fe49192cc4ee2aa178329ca60009b653
1 # ===========================================================================
2 #       http://www.gnu.org/software/autoconf-archive/ax_boost_base.html
3 # ===========================================================================
5 # SYNOPSIS
7 #   AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
9 # DESCRIPTION
11 #   Test for the Boost C++ libraries of a particular version (or newer)
13 #   If no path to the installed boost library is given the macro searches
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>.
18 #   This macro calls:
20 #     AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
22 #   And sets:
24 #     HAVE_BOOST
26 # LICENSE
28 #   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
29 #   Copyright (c) 2009 Peter Adolphs
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.
36 #serial 20
38 AC_DEFUN([AX_BOOST_BASE],
40 AC_ARG_WITH([boost],
41   [AS_HELP_STRING([--with-boost@<:@=ARG@:>@],
42     [use Boost library from a standard location (ARG=yes),
43      from the specified location (ARG=<path>),
44      or disable it (ARG=no)
45      @<:@ARG=yes@:>@ ])],
46     [
47     if test "$withval" = "no"; then
48         want_boost="no"
49     elif test "$withval" = "yes"; then
50         want_boost="yes"
51         ac_boost_path=""
52     else
53         want_boost="yes"
54         ac_boost_path="$withval"
55     fi
56     ],
57     [want_boost="yes"])
60 AC_ARG_WITH([boost-libdir],
61         AS_HELP_STRING([--with-boost-libdir=LIB_DIR],
62         [Force given directory for boost libraries. Note that this will override library path detection, so use this parameter only if default library detection fails and you know exactly where your boost libraries are located.]),
63         [
64         if test -d "$withval"
65         then
66                 ac_boost_lib_path="$withval"
67         else
68                 AC_MSG_ERROR(--with-boost-libdir expected directory name)
69         fi
70         ],
71         [ac_boost_lib_path=""]
74 if test "x$want_boost" = "xyes"; then
75     boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
76     boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
77     boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
78     boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
79     boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
80     if test "x$boost_lib_version_req_sub_minor" = "x" ; then
81         boost_lib_version_req_sub_minor="0"
82         fi
83     WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+  $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
84     AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
85     succeeded=no
87     dnl On 64-bit systems check for system libraries in both lib64 and lib.
88     dnl The former is specified by FHS, but e.g. Debian does not adhere to
89     dnl this (as it rises problems for generic multi-arch support).
90     dnl The last entry in the list is chosen by default when no libraries
91     dnl are found, e.g. when only header-only libraries are installed!
92     libsubdirs="lib"
93     ax_arch=`uname -m`
94     if test $ax_arch = x86_64 -o $ax_arch = ppc64 -o $ax_arch = ppc64le -o $ax_arch = s390x -o $ax_arch = sparc64 -o $ax_arch = aarch64; then
95         libsubdirs="lib64 lib lib64"
96     fi
98     dnl first we check the system location for boost libraries
99     dnl this location is chosen if boost libraries are installed with the --layout=system option
100     dnl or if you install boost with RPM
101     if test "$ac_boost_path" != ""; then
102         BOOST_CPPFLAGS="-I$ac_boost_path/include"
103         for ac_boost_path_tmp in $libsubdirs; do
104                 if test -d "$ac_boost_path"/"$ac_boost_path_tmp" ; then
105                         BOOST_LDFLAGS="-L$ac_boost_path/$ac_boost_path_tmp"
106                         break
107                 fi
108         done
109     else
110         if test "$cross_compiling" != yes; then
111             ac_boost_paths='/usr /usr/local /opt /opt/local'
112         else
113             ac_boost_paths="/usr/$host/sys-root/mingw"
114         fi
115         for ac_boost_path_tmp in $ac_boost_paths ; do
116             if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
117                 for libsubdir in $libsubdirs ; do
118                     if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
119                 done
120                 BOOST_LDFLAGS="-L$ac_boost_path_tmp/$libsubdir"
121                 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
122                 break;
123             fi
124         done
125     fi
127     dnl overwrite ld flags if we have required special directory with
128     dnl --with-boost-libdir parameter
129     if test "$ac_boost_lib_path" != ""; then
130        BOOST_LDFLAGS="-L$ac_boost_lib_path"
131     fi
133     CPPFLAGS_SAVED="$CPPFLAGS"
134     CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
135     export CPPFLAGS
137     LDFLAGS_SAVED="$LDFLAGS"
138     LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
139     export LDFLAGS
141     AC_REQUIRE([AC_PROG_CXX])
142     AC_LANG_PUSH(C++)
143         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
144     @%:@include <boost/version.hpp>
145     ]], [[
146     #if BOOST_VERSION >= $WANT_BOOST_VERSION
147     // Everything is okay
148     #else
149     #  error Boost version is too old
150     #endif
151     ]])],[
152         AC_MSG_RESULT(yes)
153     succeeded=yes
154     found_system=yes
155         ],[
156         ])
157     AC_LANG_POP([C++])
161     dnl if we found no boost with system layout we search for boost libraries
162     dnl built and installed without the --layout=system option or for a staged(not installed) version
163     if test "x$succeeded" != "xyes"; then
164         _version=0
165         if test "$ac_boost_path" != ""; then
166             if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
167                 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
168                     _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
169                     V_CHECK=`expr $_version_tmp \> $_version`
170                     if test "$V_CHECK" = "1" ; then
171                         _version=$_version_tmp
172                     fi
173                     VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
174                     BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
175                 done
176             fi
177         else
178             if test "$cross_compiling" != yes; then
179                 ac_boost_paths='/usr /usr/local /opt /opt/local'
180             else
181                 ac_boost_paths="/usr/$host/sys-root/mingw"
182             fi
183             for ac_boost_path in $ac_boost_paths ; do
184                 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
185                     for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
186                         _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
187                         V_CHECK=`expr $_version_tmp \> $_version`
188                         if test "$V_CHECK" = "1" ; then
189                             _version=$_version_tmp
190                             best_path=$ac_boost_path
191                         fi
192                     done
193                 fi
194             done
196             VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
197             BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
198             if test "$ac_boost_lib_path" = ""; then
199                 for libsubdir in $libsubdirs ; do
200                     if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
201                 done
202                 BOOST_LDFLAGS="-L$best_path/$libsubdir"
203             fi
205             if test "x$BOOST_ROOT" != "x"; then
206                 for libsubdir in $libsubdirs ; do
207                     if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
208                 done
209                 if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then
210                     version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
211                     stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
212                         stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
213                     V_CHECK=`expr $stage_version_shorten \>\= $_version`
214                     if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then
215                         AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
216                         BOOST_CPPFLAGS="-I$BOOST_ROOT"
217                         BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
218                     fi
219                 fi
220             fi
221         fi
223         CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
224         export CPPFLAGS
225         LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
226         export LDFLAGS
228         AC_LANG_PUSH(C++)
229             AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
230         @%:@include <boost/version.hpp>
231         ]], [[
232         #if BOOST_VERSION >= $WANT_BOOST_VERSION
233         // Everything is okay
234         #else
235         #  error Boost version is too old
236         #endif
237         ]])],[
238             AC_MSG_RESULT(yes)
239         succeeded=yes
240         found_system=yes
241             ],[
242             ])
243         AC_LANG_POP([C++])
244     fi
246     if test "$succeeded" != "yes" ; then
247         if test "$_version" = "0" ; then
248             AC_MSG_NOTICE([[We could not detect the boost libraries (version $boost_lib_version_req_shorten 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.]])
249         else
250             AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
251         fi
252         # execute ACTION-IF-NOT-FOUND (if present):
253         ifelse([$3], , :, [$3])
254     else
255         AC_SUBST(BOOST_CPPFLAGS)
256         AC_SUBST(BOOST_LDFLAGS)
257         AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
258         # execute ACTION-IF-FOUND (if present):
259         ifelse([$2], , :, [$2])
260     fi
262     CPPFLAGS="$CPPFLAGS_SAVED"
263     LDFLAGS="$LDFLAGS_SAVED"