blob: c96d1b662c442f277c56d927895fe1b75300b52a [file] [log] [blame]
David Reiss2d2aa142008-03-26 07:22:26 +00001##### http://autoconf-archive.cryp.to/ax_boost_base.html
2#
3# SYNOPSIS
4#
5# AX_BOOST_BASE([MINIMUM-VERSION])
6#
7# DESCRIPTION
8#
9# Test for the Boost C++ libraries of a particular version (or newer)
10#
11# If no path to the installed boost library is given the macro
12# searchs under /usr, /usr/local, /opt and /opt/local and evaluates
13# the $BOOST_ROOT environment variable. Further documentation is
14# available at <http://randspringer.de/boost/index.html>.
15#
16# This macro calls:
17#
18# AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
19#
20# And sets:
21#
22# HAVE_BOOST
23#
24# LAST MODIFICATION
25#
26# 2007-07-28
David Reissef5e81b2010-08-31 16:51:28 +000027# Modified for use in Thrift
David Reiss2d2aa142008-03-26 07:22:26 +000028#
29# COPYLEFT
30#
31# Copyright (c) 2007 Thomas Porschberg <thomas@randspringer.de>
32#
33# Copying and distribution of this file, with or without
34# modification, are permitted in any medium without royalty provided
35# the copyright notice and this notice are preserved.
Marc Slemko6f038a72006-08-03 18:58:09 +000036
37AC_DEFUN([AX_BOOST_BASE],
38[
39AC_ARG_WITH([boost],
David Reiss2d2aa142008-03-26 07:22:26 +000040 AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is yes) - it is possible to specify the root directory for boost (optional)]),
Marc Slemko6f038a72006-08-03 18:58:09 +000041 [
42 if test "$withval" = "no"; then
43 want_boost="no"
44 elif test "$withval" = "yes"; then
45 want_boost="yes"
46 ac_boost_path=""
47 else
David Reiss2d2aa142008-03-26 07:22:26 +000048 want_boost="yes"
Marc Slemko6f038a72006-08-03 18:58:09 +000049 ac_boost_path="$withval"
50 fi
51 ],
Marc Slemko75c2f702007-01-17 07:59:38 +000052 [want_boost="yes"])
Marc Slemko6f038a72006-08-03 18:58:09 +000053
54if test "x$want_boost" = "xyes"; then
55 boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
56 boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
57 boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
58 boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
59 boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
60 if test "x$boost_lib_version_req_sub_minor" = "x" ; then
61 boost_lib_version_req_sub_minor="0"
62 fi
63 WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
64 AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
65 succeeded=no
66
67 dnl first we check the system location for boost libraries
68 dnl this location ist chosen if boost libraries are installed with the --layout=system option
69 dnl or if you install boost with RPM
70 if test "$ac_boost_path" != ""; then
71 BOOST_LDFLAGS="-L$ac_boost_path/lib"
72 BOOST_CPPFLAGS="-I$ac_boost_path/include"
73 else
David Reiss2d2aa142008-03-26 07:22:26 +000074 for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
Marc Slemko6f038a72006-08-03 18:58:09 +000075 if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
76 BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
77 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
78 break;
79 fi
80 done
81 fi
82
83 CPPFLAGS_SAVED="$CPPFLAGS"
84 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
85 export CPPFLAGS
86
87 LDFLAGS_SAVED="$LDFLAGS"
88 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
89 export LDFLAGS
90
91 AC_LANG_PUSH(C++)
92 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
93 @%:@include <boost/version.hpp>
94 ]], [[
95 #if BOOST_VERSION >= $WANT_BOOST_VERSION
96 // Everything is okay
97 #else
98 # error Boost version is too old
99 #endif
100 ]])],[
101 AC_MSG_RESULT(yes)
102 succeeded=yes
103 found_system=yes
104 ],[
105 ])
106 AC_LANG_POP([C++])
107
108
109
110 dnl if we found no boost with system layout we search for boost libraries
111 dnl built and installed without the --layout=system option or for a staged(not installed) version
112 if test "x$succeeded" != "xyes"; then
113 _version=0
114 if test "$ac_boost_path" != ""; then
115 BOOST_LDFLAGS="-L$ac_boost_path/lib"
116 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
117 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
118 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
119 V_CHECK=`expr $_version_tmp \> $_version`
120 if test "$V_CHECK" = "1" ; then
121 _version=$_version_tmp
122 fi
123 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
124 BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
125 done
126 fi
127 else
David Reiss2d2aa142008-03-26 07:22:26 +0000128 for ac_boost_path in /usr /usr/local /opt /opt/local ; do
Marc Slemko6f038a72006-08-03 18:58:09 +0000129 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
130 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
131 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
132 V_CHECK=`expr $_version_tmp \> $_version`
133 if test "$V_CHECK" = "1" ; then
134 _version=$_version_tmp
135 best_path=$ac_boost_path
136 fi
137 done
138 fi
139 done
140
141 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
142 BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
143 BOOST_LDFLAGS="-L$best_path/lib"
144
145 if test "x$BOOST_ROOT" != "x"; then
146 if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then
147 version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
148 stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
149 stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
150 V_CHECK=`expr $stage_version_shorten \>\= $_version`
151 if test "$V_CHECK" = "1" ; then
152 AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
153 BOOST_CPPFLAGS="-I$BOOST_ROOT"
154 BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib"
155 fi
156 fi
157 fi
158 fi
159
160 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
161 export CPPFLAGS
162 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
163 export LDFLAGS
164
165 AC_LANG_PUSH(C++)
166 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
167 @%:@include <boost/version.hpp>
168 ]], [[
169 #if BOOST_VERSION >= $WANT_BOOST_VERSION
170 // Everything is okay
171 #else
172 # error Boost version is too old
173 #endif
174 ]])],[
175 AC_MSG_RESULT(yes)
176 succeeded=yes
177 found_system=yes
178 ],[
179 ])
180 AC_LANG_POP([C++])
181 fi
182
183 if test "$succeeded" != "yes" ; then
184 if test "$_version" = "0" ; then
David Reissef5e81b2010-08-31 16:51:28 +0000185 AC_MSG_WARN([[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.]])
Marc Slemko6f038a72006-08-03 18:58:09 +0000186 else
David Reissef5e81b2010-08-31 16:51:28 +0000187 AC_MSG_WARN([Your boost libraries seems to old (version $_version).])
Marc Slemko6f038a72006-08-03 18:58:09 +0000188 fi
189 else
190 AC_SUBST(BOOST_CPPFLAGS)
191 AC_SUBST(BOOST_LDFLAGS)
192 AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
193 fi
194
195 CPPFLAGS="$CPPFLAGS_SAVED"
196 LDFLAGS="$LDFLAGS_SAVED"
197fi
198
199])