1 dnl Find the compiler and linker flags for SQLite.
3 dnl Finds the compiler and linker flags for linking with the SQLite library.
4 dnl Provides the --with-sqlite, --with-sqlite-lib, and --with-sqlite-include
5 dnl configure options to specify non-standard paths to the SQLite libraries or
6 dnl header files. Currently, only SQLite 3 is considered sufficient.
8 dnl Provides the macros RRA_LIB_SQLITE and RRA_LIB_SQLITE_OPTIONAL and sets
9 dnl the substitution variables SQLITE_CPPFLAGS, SQLITE_LDFLAGS, and
10 dnl SQLITE_LIBS. Also provides RRA_LIB_SQLITE_SWITCH to set CPPFLAGS,
11 dnl LDFLAGS, and LIBS to include the SQLite libraries, saving the current
12 dnl values first, and RRA_LIB_SQLITE_RESTORE to restore those settings to
13 dnl before the last RRA_LIB_SQLITE_SWITCH. Defines HAVE_SQLITE and sets
14 dnl rra_use_SQLITE to true if libevent is found. If it isn't found, the
15 dnl substitution variables will be empty.
17 dnl Depends on the lib-helper.m4 framework.
19 dnl The canonical version of this file is maintained in the rra-c-util
20 dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
22 dnl Written by Russ Allbery <eagle@eyrie.org>
24 dnl The Board of Trustees of the Leland Stanford Junior University
26 dnl This file is free software; the authors give unlimited permission to copy
27 dnl and/or distribute it, with or without modifications, as long as this
28 dnl notice is preserved.
30 dnl SPDX-License-Identifier: FSFULLR
32 dnl Save the current CPPFLAGS, LDFLAGS, and LIBS settings and switch to
33 dnl versions that include the libevent flags. Used as a wrapper, with
34 dnl RRA_LIB_SQLITE_RESTORE, around tests.
35 AC_DEFUN([RRA_LIB_SQLITE_SWITCH], [RRA_LIB_HELPER_SWITCH([SQLITE])])
37 dnl Restore CPPFLAGS, LDFLAGS, and LIBS to their previous values before
38 dnl RRA_LIB_SQLITE_SWITCH was called.
39 AC_DEFUN([RRA_LIB_SQLITE_RESTORE], [RRA_LIB_HELPER_RESTORE([SQLITE])])
41 dnl Checks if SQLite is present. The single argument, if "true", says to fail
42 dnl if the SQLite library could not be found. Prefer probing with pkg-config
43 dnl if available and the --with flags were not given.
44 AC_DEFUN([_RRA_LIB_SQLITE_INTERNAL],
45 [RRA_LIB_HELPER_PATHS([SQLITE])
46 AS_IF([test x"$SQLITE_CPPFLAGS" = x && test x"$SQLITE_LDFLAGS" = x],
47 [PKG_CHECK_EXISTS([sqlite3],
48 [PKG_CHECK_MODULES([SQLITE], [sqlite3])
49 SQLITE_CPPFLAGS="$SQLITE_CFLAGS"])])
50 AS_IF([test x"$SQLITE_LIBS" = x],
51 [RRA_LIB_SQLITE_SWITCH
53 AC_SEARCH_LIBS([sqlite3_open_v2], [sqlite3],
54 [SQLITE_LIBS="$LIBS"],
55 [AS_IF([test x"$1" = xtrue],
56 [AC_MSG_ERROR([cannot find usable SQLite library])])])
57 RRA_LIB_SQLITE_RESTORE])
59 AC_CHECK_HEADERS([sqlite3.h])
60 RRA_LIB_SQLITE_RESTORE])
62 dnl The main macro for packages with mandatory SQLite 3 support.
63 AC_DEFUN([RRA_LIB_SQLITE],
64 [RRA_LIB_HELPER_VAR_INIT([SQLITE])
65 RRA_LIB_HELPER_WITH([sqlite], [SQLite], [SQLITE])
66 _RRA_LIB_SQLITE_INTERNAL([true])
68 AC_DEFINE([HAVE_SQLITE], 1, [Define if SQLite is available.])])
70 dnl The main macro for packages with optional SQLite support.
71 AC_DEFUN([RRA_LIB_SQLITE_OPTIONAL],
72 [RRA_LIB_HELPER_VAR_INIT([SQLITE])
73 RRA_LIB_HELPER_WITH_OPTIONAL([sqlite], [SQLite], [SQLITE])
74 AS_IF([test x"$rra_use_SQLITE" != xfalse],
75 [AS_IF([test x"$rra_use_SQLITE" = xtrue],
76 [_RRA_LIB_SQLITE_INTERNAL([true])],
77 [_RRA_LIB_SQLITE_INTERNAL([false])])])
78 AS_IF([test x"$SQLITE_LIBS" != x],
80 AC_DEFINE([HAVE_SQLITE], 1, [Define if SQLite is available.])])])