ax_lib_sqlite3.m4 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_lib_sqlite3.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_LIB_SQLITE3([MINIMUM-VERSION])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Test for the SQLite 3 library of a particular version (or newer)
  12. #
  13. # This macro takes only one optional argument, required version of SQLite
  14. # 3 library. If required version is not passed, 3.0.0 is used in the test
  15. # of existance of SQLite 3.
  16. #
  17. # If no intallation prefix to the installed SQLite library is given the
  18. # macro searches under /usr, /usr/local, and /opt.
  19. #
  20. # This macro calls:
  21. #
  22. # AC_SUBST(SQLITE3_CFLAGS)
  23. # AC_SUBST(SQLITE3_LDFLAGS)
  24. # AC_SUBST(SQLITE3_VERSION)
  25. #
  26. # And sets:
  27. #
  28. # HAVE_SQLITE3
  29. #
  30. # LICENSE
  31. #
  32. # Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
  33. #
  34. # Copying and distribution of this file, with or without modification, are
  35. # permitted in any medium without royalty provided the copyright notice
  36. # and this notice are preserved. This file is offered as-is, without any
  37. # warranty.
  38. #serial 14
  39. AC_DEFUN([AX_LIB_SQLITE3],
  40. [
  41. AC_ARG_WITH([sqlite3],
  42. AS_HELP_STRING(
  43. [--with-sqlite3=@<:@ARG@:>@],
  44. [use SQLite 3 library @<:@default=yes@:>@, optionally specify the prefix for sqlite3 library]
  45. ),
  46. [
  47. if test "$withval" = "no"; then
  48. WANT_SQLITE3="no"
  49. elif test "$withval" = "yes"; then
  50. WANT_SQLITE3="yes"
  51. ac_sqlite3_path=""
  52. else
  53. WANT_SQLITE3="yes"
  54. ac_sqlite3_path="$withval"
  55. fi
  56. ],
  57. [WANT_SQLITE3="yes"]
  58. )
  59. SQLITE3_CFLAGS=""
  60. SQLITE3_LDFLAGS=""
  61. SQLITE3_VERSION=""
  62. if test "x$WANT_SQLITE3" = "xyes"; then
  63. ac_sqlite3_header="sqlite3.h"
  64. sqlite3_version_req=ifelse([$1], [], [3.0.0], [$1])
  65. sqlite3_version_req_shorten=`expr $sqlite3_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
  66. sqlite3_version_req_major=`expr $sqlite3_version_req : '\([[0-9]]*\)'`
  67. sqlite3_version_req_minor=`expr $sqlite3_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
  68. sqlite3_version_req_micro=`expr $sqlite3_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  69. if test "x$sqlite3_version_req_micro" = "x" ; then
  70. sqlite3_version_req_micro="0"
  71. fi
  72. sqlite3_version_req_number=`expr $sqlite3_version_req_major \* 1000000 \
  73. \+ $sqlite3_version_req_minor \* 1000 \
  74. \+ $sqlite3_version_req_micro`
  75. AC_MSG_CHECKING([for SQLite3 library >= $sqlite3_version_req])
  76. if test "$ac_sqlite3_path" != ""; then
  77. ac_sqlite3_ldflags="-L$ac_sqlite3_path/lib"
  78. ac_sqlite3_cppflags="-I$ac_sqlite3_path/include"
  79. else
  80. for ac_sqlite3_path_tmp in /usr /usr/local /opt ; do
  81. if test -f "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header" \
  82. && test -r "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header"; then
  83. ac_sqlite3_path=$ac_sqlite3_path_tmp
  84. ac_sqlite3_cppflags="-I$ac_sqlite3_path_tmp/include"
  85. ac_sqlite3_ldflags="-L$ac_sqlite3_path_tmp/lib"
  86. break;
  87. fi
  88. done
  89. fi
  90. ac_sqlite3_ldflags="$ac_sqlite3_ldflags -lsqlite3"
  91. saved_CPPFLAGS="$CPPFLAGS"
  92. CPPFLAGS="$CPPFLAGS $ac_sqlite3_cppflags"
  93. AC_LANG_PUSH(C)
  94. AC_COMPILE_IFELSE(
  95. [
  96. AC_LANG_PROGRAM([[@%:@include <sqlite3.h>]],
  97. [[
  98. #if (SQLITE_VERSION_NUMBER >= $sqlite3_version_req_number)
  99. // Everything is okay
  100. #else
  101. # error SQLite version is too old
  102. #endif
  103. ]]
  104. )
  105. ],
  106. [
  107. AC_MSG_RESULT([yes])
  108. success="yes"
  109. ],
  110. [
  111. AC_MSG_RESULT([not found])
  112. success="no"
  113. WANT_SQLITE3="no"
  114. ]
  115. )
  116. AC_LANG_POP(C)
  117. CPPFLAGS="$saved_CPPFLAGS"
  118. if test "$success" = "yes"; then
  119. SQLITE3_CFLAGS="$ac_sqlite3_cppflags"
  120. SQLITE3_LDFLAGS="$ac_sqlite3_ldflags"
  121. ac_sqlite3_header_path="$ac_sqlite3_path/include/$ac_sqlite3_header"
  122. dnl Retrieve SQLite release version
  123. if test "x$ac_sqlite3_header_path" != "x"; then
  124. ac_sqlite3_version=`cat $ac_sqlite3_header_path \
  125. | grep '#define.*SQLITE_VERSION.*\"' | sed -e 's/.* "//' \
  126. | sed -e 's/"//'`
  127. if test $ac_sqlite3_version != ""; then
  128. SQLITE3_VERSION=$ac_sqlite3_version
  129. else
  130. AC_MSG_WARN([Cannot find SQLITE_VERSION macro in sqlite3.h header to retrieve SQLite version!])
  131. fi
  132. fi
  133. AC_SUBST(SQLITE3_CFLAGS)
  134. AC_SUBST(SQLITE3_LDFLAGS)
  135. AC_SUBST(SQLITE3_VERSION)
  136. AC_DEFINE([HAVE_SQLITE3], [], [Have the SQLITE3 library])
  137. fi
  138. fi
  139. ])