summaryrefslogtreecommitdiff
path: root/m4/sqlite-threadsafe.m4
blob: 75bdfbfa895c0c32528078288133c3879de0d94c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# sqlite-threadsafe.m4 serial 2

dnl Copyright (C) 2010 Aleksander Morgado <aleksander@gnu.org>
dnl This file is free software; unlimited permission to copy and/or distribute
dnl  it is given, with or without modifications, as long as this notice is
dnl  preserved.

dnl This program will execute the sqlite3_threadsafe() method to check
dnl  whether the sqlite3 library was compiled in threadsafe mode or not,
dnl  and will fill the ax_cv_sqlite_threadsafe cached variable accordingly.
dnl See http://sqlite.org/c3ref/threadsafe.html for more information.

dnl Once this m4 macro has been evaluated, you can for example issue an error
dnl  when sqlite3 was not compiled thread-safe:
dnl
dnl  AX_SQLITE_THREADSAFE
dnl  if test "x$ax_cv_sqlite_threadsafe" != "xyes"; then
dnl    AC_MSG_ERROR([sqlite3 is not compiled in a thread-safe mode])
dnl  fi


AC_DEFUN([AX_SQLITE_THREADSAFE],
[
  AC_REQUIRE([AC_PROG_CC])

  save_LIBS="$LIBS"

  AC_CHECK_HEADERS([sqlite3.h])
  AC_CHECK_LIB([sqlite3],[sqlite3_threadsafe])

  AC_CACHE_CHECK([whether sqlite was compiled thread-safe],
                 [ax_cv_sqlite_threadsafe],
  [
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <sqlite3.h>
int main ()
{
  /* sqlite3_threadsafe() returns the value of the SQLITE_THREADSAFE
   * preprocessor macro used when compiling. If this is 0, sqlite3
   * library was NOT compiled in a thread-safe mode */

  return sqlite3_threadsafe () == 0 ? -1 : 0;
}

  ]])],
       [ax_cv_sqlite_threadsafe=yes],
       [ax_cv_sqlite_threadsafe=no],
       [ax_cv_sqlite_threadsafe=no])])

  LIBS="$save_LIBS"
])