[tracker/wip/fts4: 19/21] Detect at configure time whether FTS needs compiling



commit ba7e4878fc3718e3fe6c94d048d017958bbf8cb7
Author: Carlos Garnacho <carlos lanedo com>
Date:   Fri Jan 25 18:46:01 2013 +0100

    Detect at configure time whether FTS needs compiling
    
    Recent sqlites (>3.7.9) with FTS support compiled have all
    what Tracker requires to handle FTS, so only compile it
    optionally if no FTS support was detected in the sqlite library.

 configure.ac                     |   33 +++++++++++++++++++++++++++++++--
 src/libtracker-fts/Makefile.am   |    7 ++++++-
 src/libtracker-fts/tracker-fts.c |   11 ++++++++++-
 3 files changed, 47 insertions(+), 4 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a39a3e0..7b8117e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -203,7 +203,8 @@ GUPNP_DLNA_REQUIRED=0.7
 # 3.6.16 to fix test failures
 # 3.6.17 for shared cache mode with virtual tables
 # 3.7.0 for WAL
-SQLITE_REQUIRED=3.7.0
+# 3.7.9 for FTS4 content= support
+SQLITE_REQUIRED=3.7.9
 
 # Needed to generate .gir files,
 # see http://live.gnome.org/GnomeGoals/AddGObjectIntrospectionSupport
@@ -715,10 +716,38 @@ fi
 
 if test "x$have_tracker_fts" = "xyes"; then
    AC_DEFINE(HAVE_TRACKER_FTS, [1], [Define to 1 if tracker FTS is compiled])
+
+   OLD_CFLAGS="$CFLAGS"
+   OLD_LIBS="$LIBS"
+   CFLAGS="$SQLITE3_CFLAGS"
+   LIBS="$SQLITE3_LIBS"
+
+   AC_MSG_CHECKING(whether SQLite3 has required FTS features)
+   AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <sqlite3.h>]],
+                                  [[sqlite3 *db;
+                                    int rc;
+                                    rc = sqlite3_open(":memory:", &db);
+                                    if (rc!=SQLITE_OK) return -1;
+                                    rc = sqlite3_exec(db, "create table a(text)", 0, 0, 0);
+                                    if (rc!=SQLITE_OK) return -1;
+                                    rc = sqlite3_exec(db, "create virtual table t using fts4(content='a',text)", 0, 0, 0);
+                                    if (rc!=SQLITE_OK) return -1;]])],
+                     [have_builtin_fts4=yes],
+                     [have_builtin_fts4=no])
+   AC_MSG_RESULT($have_builtin_fts4)
+
+   CFLAGS="$OLD_CFLAGS"
+   LIBS="$OLD_LIBS"
+
+   if test "x$have_builtin_fts4" = "xyes" ; then
+      AC_DEFINE(HAVE_BUILTIN_FTS, [], [Defined if Sqlite has FTS4 compiled in])
+   fi
 else
    AC_DEFINE(HAVE_TRACKER_FTS, [0], [Define to 0 if tracker FTS is not compiled])
+   $have_builtin_fts4="disabled"
 fi
 
+AM_CONDITIONAL(HAVE_BUILTIN_FTS, test "$have_builtin_fts4" = "yes")
 AM_CONDITIONAL(HAVE_TRACKER_FTS, test "$have_tracker_fts" = "yes")
 
 ####################################################################
@@ -2451,7 +2480,7 @@ Build Configuration:
 Applications:
 
 	Build with Journal support:             $have_tracker_journal
-	Build with SQLite FTS support:          $have_tracker_fts
+	Build with SQLite FTS support:          $have_tracker_fts (built-in FTS: $have_builtin_fts4)
 
 	Build tracker-preferences:              $have_tracker_preferences
 	Build tracker-explorer:                 $have_tracker_explorer
diff --git a/src/libtracker-fts/Makefile.am b/src/libtracker-fts/Makefile.am
index 6e4b7f0..e99ea72 100644
--- a/src/libtracker-fts/Makefile.am
+++ b/src/libtracker-fts/Makefile.am
@@ -28,7 +28,6 @@ fts4_sources =                                         \
 	fts3_write.c
 
 libtracker_fts_la_SOURCES =                            \
-	$(fts4_sources)                                \
 	tracker-fts.c                                  \
 	tracker-fts.h                                  \
 	tracker-fts-config.c                           \
@@ -39,6 +38,10 @@ libtracker_fts_la_SOURCES =                            \
 	tracker-parser-utils.h                         \
 	tracker-parser.h
 
+if !HAVE_BUILTIN_FTS
+  libtracker_fts_la_SOURCES += $(fts4_sources)
+endif
+
 if BUILD_LIBUNISTRING_PARSER
   libtracker_fts_la_SOURCES += tracker-parser-libunistring.c
 endif
@@ -51,3 +54,5 @@ libtracker_fts_la_LIBADD =                             \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
 	$(BUILD_LIBS)                                  \
 	$(LIBTRACKER_FTS_LIBS)
+
+EXTRA_DIST = $(fts4_sources)
diff --git a/src/libtracker-fts/tracker-fts.c b/src/libtracker-fts/tracker-fts.c
index ac96155..1050cf4 100644
--- a/src/libtracker-fts/tracker-fts.c
+++ b/src/libtracker-fts/tracker-fts.c
@@ -19,13 +19,21 @@
  * 02110-1301  USA
  */
 
+#include "config.h"
 #include <sqlite3.h>
 #include "tracker-fts-tokenizer.h"
 #include "tracker-fts.h"
-#include "fts3.h"
+
+#ifndef HAVE_BUILTIN_FTS
+#  include "fts3.h"
+#endif
 
 gboolean
 tracker_fts_init (void) {
+#ifdef HAVE_BUILTIN_FTS
+	/* SQLite has all needed FTS4 features compiled in */
+	return TRUE;
+#else
 	static gsize module_initialized = 0;
 	int rc = SQLITE_OK;
 
@@ -35,6 +43,7 @@ tracker_fts_init (void) {
 	}
 
 	return (module_initialized != 0);
+#endif
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]