PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Tools/config/ax_boost_base.m4

#
m4 | 258 lines | 192 code | 21 blank | 45 comment | 0 complexity | ea8aabdbffa4c63cef9b1db94b2ff76d MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # ===========================================================================
  2. # http://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. #serial 20
  36. AC_DEFUN([AX_BOOST_BASE],
  37. [
  38. AC_ARG_WITH([boost],
  39. [AS_HELP_STRING([--with-boost@<:@=ARG@:>@],
  40. [use Boost library from a standard location (ARG=yes),
  41. from the specified location (ARG=<path>),
  42. or disable it (ARG=no)
  43. @<:@ARG=yes@:>@ ])],
  44. [
  45. if test "$withval" = "no"; then
  46. want_boost="no"
  47. elif test "$withval" = "yes"; then
  48. want_boost="yes"
  49. ac_boost_path=""
  50. else
  51. want_boost="yes"
  52. ac_boost_path="$withval"
  53. fi
  54. ],
  55. [want_boost="yes"])
  56. AC_ARG_WITH([boost-libdir],
  57. AS_HELP_STRING([--with-boost-libdir=LIB_DIR],
  58. [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.]),
  59. [
  60. if test -d "$withval"
  61. then
  62. ac_boost_lib_path="$withval"
  63. else
  64. AC_MSG_ERROR(--with-boost-libdir expected directory name)
  65. fi
  66. ],
  67. [ac_boost_lib_path=""]
  68. )
  69. if test "x$want_boost" = "xyes"; then
  70. boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
  71. boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
  72. boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
  73. boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
  74. boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  75. if test "x$boost_lib_version_req_sub_minor" = "x" ; then
  76. boost_lib_version_req_sub_minor="0"
  77. fi
  78. WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
  79. AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
  80. succeeded=no
  81. dnl On 64-bit systems check for system libraries in both lib64 and lib.
  82. dnl The former is specified by FHS, but e.g. Debian does not adhere to
  83. dnl this (as it rises problems for generic multi-arch support).
  84. dnl The last entry in the list is chosen by default when no libraries
  85. dnl are found, e.g. when only header-only libraries are installed!
  86. libsubdirs="lib"
  87. ax_arch=`uname -m`
  88. if test $ax_arch = x86_64 -o $ax_arch = ppc64 -o $ax_arch = s390x -o $ax_arch = sparc64; then
  89. libsubdirs="lib64 lib lib64"
  90. fi
  91. dnl first we check the system location for boost libraries
  92. dnl this location ist chosen if boost libraries are installed with the --layout=system option
  93. dnl or if you install boost with RPM
  94. if test "$ac_boost_path" != ""; then
  95. BOOST_CPPFLAGS="-I$ac_boost_path/include"
  96. for ac_boost_path_tmp in $libsubdirs; do
  97. if test -d "$ac_boost_path"/"$ac_boost_path_tmp" ; then
  98. BOOST_LDFLAGS="-L$ac_boost_path/$ac_boost_path_tmp"
  99. break
  100. fi
  101. done
  102. elif test "$cross_compiling" != yes; then
  103. for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
  104. if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
  105. for libsubdir in $libsubdirs ; do
  106. if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
  107. done
  108. BOOST_LDFLAGS="-L$ac_boost_path_tmp/$libsubdir"
  109. BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
  110. break;
  111. fi
  112. done
  113. fi
  114. dnl overwrite ld flags if we have required special directory with
  115. dnl --with-boost-libdir parameter
  116. if test "$ac_boost_lib_path" != ""; then
  117. BOOST_LDFLAGS="-L$ac_boost_lib_path"
  118. fi
  119. CPPFLAGS_SAVED="$CPPFLAGS"
  120. CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
  121. export CPPFLAGS
  122. LDFLAGS_SAVED="$LDFLAGS"
  123. LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
  124. export LDFLAGS
  125. AC_REQUIRE([AC_PROG_CXX])
  126. AC_LANG_PUSH(C++)
  127. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  128. @%:@include <boost/version.hpp>
  129. ]], [[
  130. #if BOOST_VERSION >= $WANT_BOOST_VERSION
  131. // Everything is okay
  132. #else
  133. # error Boost version is too old
  134. #endif
  135. ]])],[
  136. AC_MSG_RESULT(yes)
  137. succeeded=yes
  138. found_system=yes
  139. ],[
  140. ])
  141. AC_LANG_POP([C++])
  142. dnl if we found no boost with system layout we search for boost libraries
  143. dnl built and installed without the --layout=system option or for a staged(not installed) version
  144. if test "x$succeeded" != "xyes"; then
  145. _version=0
  146. if test "$ac_boost_path" != ""; then
  147. if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
  148. for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
  149. _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
  150. V_CHECK=`expr $_version_tmp \> $_version`
  151. if test "$V_CHECK" = "1" ; then
  152. _version=$_version_tmp
  153. fi
  154. VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
  155. BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
  156. done
  157. fi
  158. else
  159. if test "$cross_compiling" != yes; then
  160. for ac_boost_path in /usr /usr/local /opt /opt/local ; do
  161. if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
  162. for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
  163. _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
  164. V_CHECK=`expr $_version_tmp \> $_version`
  165. if test "$V_CHECK" = "1" ; then
  166. _version=$_version_tmp
  167. best_path=$ac_boost_path
  168. fi
  169. done
  170. fi
  171. done
  172. VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
  173. BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
  174. if test "$ac_boost_lib_path" = ""; then
  175. for libsubdir in $libsubdirs ; do
  176. if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
  177. done
  178. BOOST_LDFLAGS="-L$best_path/$libsubdir"
  179. fi
  180. fi
  181. if test "x$BOOST_ROOT" != "x"; then
  182. for libsubdir in $libsubdirs ; do
  183. if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
  184. done
  185. if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then
  186. version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
  187. stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
  188. stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
  189. V_CHECK=`expr $stage_version_shorten \>\= $_version`
  190. if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then
  191. AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
  192. BOOST_CPPFLAGS="-I$BOOST_ROOT"
  193. BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
  194. fi
  195. fi
  196. fi
  197. fi
  198. CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
  199. export CPPFLAGS
  200. LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
  201. export LDFLAGS
  202. AC_LANG_PUSH(C++)
  203. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  204. @%:@include <boost/version.hpp>
  205. ]], [[
  206. #if BOOST_VERSION >= $WANT_BOOST_VERSION
  207. // Everything is okay
  208. #else
  209. # error Boost version is too old
  210. #endif
  211. ]])],[
  212. AC_MSG_RESULT(yes)
  213. succeeded=yes
  214. found_system=yes
  215. ],[
  216. ])
  217. AC_LANG_POP([C++])
  218. fi
  219. if test "$succeeded" != "yes" ; then
  220. if test "$_version" = "0" ; then
  221. 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.]])
  222. else
  223. AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
  224. fi
  225. # execute ACTION-IF-NOT-FOUND (if present):
  226. ifelse([$3], , :, [$3])
  227. else
  228. AC_SUBST(BOOST_CPPFLAGS)
  229. AC_SUBST(BOOST_LDFLAGS)
  230. AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
  231. # execute ACTION-IF-FOUND (if present):
  232. ifelse([$2], , :, [$2])
  233. fi
  234. CPPFLAGS="$CPPFLAGS_SAVED"
  235. LDFLAGS="$LDFLAGS_SAVED"
  236. fi
  237. ])