blob: 5894d0cabb6597058cca2eac816f6393acc99fab [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"
Christian Lavoie4f42ef72010-11-04 18:51:42 +000073 BOOST_ROOT_PATH="$ac_boost_path"
Marc Slemko6f038a72006-08-03 18:58:09 +000074 else
David Reiss2d2aa142008-03-26 07:22:26 +000075 for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
Marc Slemko6f038a72006-08-03 18:58:09 +000076 if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
77 BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
78 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
Christian Lavoie4f42ef72010-11-04 18:51:42 +000079 BOOST_ROOT_PATH="$ac_boost_path_tmp"
Marc Slemko6f038a72006-08-03 18:58:09 +000080 break;
81 fi
82 done
83 fi
84
85 CPPFLAGS_SAVED="$CPPFLAGS"
86 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
87 export CPPFLAGS
88
89 LDFLAGS_SAVED="$LDFLAGS"
90 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
91 export LDFLAGS
92
Christian Lavoie4f42ef72010-11-04 18:51:42 +000093 export BOOST_ROOT_PATH
94
Marc Slemko6f038a72006-08-03 18:58:09 +000095 AC_LANG_PUSH(C++)
96 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
97 @%:@include <boost/version.hpp>
98 ]], [[
99 #if BOOST_VERSION >= $WANT_BOOST_VERSION
100 // Everything is okay
101 #else
102 # error Boost version is too old
103 #endif
104 ]])],[
105 AC_MSG_RESULT(yes)
106 succeeded=yes
107 found_system=yes
108 ],[
109 ])
110 AC_LANG_POP([C++])
111
112
113
114 dnl if we found no boost with system layout we search for boost libraries
115 dnl built and installed without the --layout=system option or for a staged(not installed) version
116 if test "x$succeeded" != "xyes"; then
117 _version=0
118 if test "$ac_boost_path" != ""; then
119 BOOST_LDFLAGS="-L$ac_boost_path/lib"
120 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
121 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
122 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
123 V_CHECK=`expr $_version_tmp \> $_version`
124 if test "$V_CHECK" = "1" ; then
125 _version=$_version_tmp
126 fi
127 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
128 BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
129 done
130 fi
131 else
David Reiss2d2aa142008-03-26 07:22:26 +0000132 for ac_boost_path in /usr /usr/local /opt /opt/local ; do
Marc Slemko6f038a72006-08-03 18:58:09 +0000133 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
134 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
135 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
136 V_CHECK=`expr $_version_tmp \> $_version`
137 if test "$V_CHECK" = "1" ; then
138 _version=$_version_tmp
139 best_path=$ac_boost_path
140 fi
141 done
142 fi
143 done
144
145 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
146 BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
147 BOOST_LDFLAGS="-L$best_path/lib"
Christian Lavoie4f42ef72010-11-04 18:51:42 +0000148 BOOST_ROOT_PATH="$best_path"
Marc Slemko6f038a72006-08-03 18:58:09 +0000149
150 if test "x$BOOST_ROOT" != "x"; then
151 if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then
152 version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
153 stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
154 stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
155 V_CHECK=`expr $stage_version_shorten \>\= $_version`
156 if test "$V_CHECK" = "1" ; then
157 AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
158 BOOST_CPPFLAGS="-I$BOOST_ROOT"
159 BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib"
Christian Lavoie4f42ef72010-11-04 18:51:42 +0000160 BOOST_ROOT_PATH="$BOOST_ROOT"
Marc Slemko6f038a72006-08-03 18:58:09 +0000161 fi
162 fi
163 fi
164 fi
165
166 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
167 export CPPFLAGS
168 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
169 export LDFLAGS
Christian Lavoie4f42ef72010-11-04 18:51:42 +0000170 export BOOST_ROOT_PATH
Marc Slemko6f038a72006-08-03 18:58:09 +0000171
172 AC_LANG_PUSH(C++)
173 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
174 @%:@include <boost/version.hpp>
175 ]], [[
176 #if BOOST_VERSION >= $WANT_BOOST_VERSION
177 // Everything is okay
178 #else
179 # error Boost version is too old
180 #endif
181 ]])],[
182 AC_MSG_RESULT(yes)
183 succeeded=yes
184 found_system=yes
185 ],[
186 ])
187 AC_LANG_POP([C++])
188 fi
189
190 if test "$succeeded" != "yes" ; then
191 if test "$_version" = "0" ; then
David Reissef5e81b2010-08-31 16:51:28 +0000192 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 +0000193 else
David Reissef5e81b2010-08-31 16:51:28 +0000194 AC_MSG_WARN([Your boost libraries seems to old (version $_version).])
Marc Slemko6f038a72006-08-03 18:58:09 +0000195 fi
196 else
197 AC_SUBST(BOOST_CPPFLAGS)
198 AC_SUBST(BOOST_LDFLAGS)
Christian Lavoie4f42ef72010-11-04 18:51:42 +0000199 AC_SUBST(BOOST_ROOT_PATH)
Marc Slemko6f038a72006-08-03 18:58:09 +0000200 AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
201 fi
202
203 CPPFLAGS="$CPPFLAGS_SAVED"
204 LDFLAGS="$LDFLAGS_SAVED"
205fi
206
207])