From 34de252300719b7afe05ef5de6414f0748759ff8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 30 Mar 2011 13:09:41 +0200 Subject: Autotools support for SQLite --- configure.ac | 4 +++ m4/database.m4 | 7 ++++- m4/libodb-sqlite.m4 | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ m4/mysql.m4 | 2 +- m4/sqlite.m4 | 61 ++++++++++++++++++++++++++++++++++++++ mapping/makefile | 2 +- template/Makefile.am | 8 ++++- 7 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 m4/libodb-sqlite.m4 create mode 100644 m4/sqlite.m4 diff --git a/configure.ac b/configure.ac index b2c9a19..9c38a3d 100644 --- a/configure.ac +++ b/configure.ac @@ -62,6 +62,10 @@ case $database in LIBODB_MYSQL([], [AC_MSG_ERROR([libodb-mysql is not found; consider using --with-libodb-mysql=DIR])]) MYSQL ;; + sqlite) + LIBODB_SQLITE([], [AC_MSG_ERROR([libodb-sqlite is not found; consider using --with-libodb-sqlite=DIR])]) + SQLITE + ;; esac # Check for the ODB compiler. diff --git a/m4/database.m4 b/m4/database.m4 index 6f75e27..9478016 100644 --- a/m4/database.m4 +++ b/m4/database.m4 @@ -13,7 +13,7 @@ AC_MSG_CHECKING([for database to use]) AC_ARG_WITH( [database], [AC_HELP_STRING([--with-database=db], - [database to use for tests; valid values are: 'mysql'])], + [database to use for tests; valid values are: 'mysql', 'sqlite'])], [case $withval in no | yes) AC_MSG_RESULT([]) @@ -23,6 +23,10 @@ AC_ARG_WITH( database=mysql AC_DEFINE([DATABASE_MYSQL], [1], [Using MySQL.]) ;; + sqlite) + database=sqlite + AC_DEFINE([DATABASE_SQLITE], [1], [Using SQLite.]) + ;; *) AC_MSG_RESULT([]) AC_MSG_ERROR([unknown database $withval]) @@ -37,5 +41,6 @@ AC_MSG_RESULT([$database]) AC_SUBST([database]) AM_CONDITIONAL([DATABASE_MYSQL], [test x$database = xmysql]) +AM_CONDITIONAL([DATABASE_SQLITE], [test x$database = xsqlite]) ])dnl diff --git a/m4/libodb-sqlite.m4 b/m4/libodb-sqlite.m4 new file mode 100644 index 0000000..b85614f --- /dev/null +++ b/m4/libodb-sqlite.m4 @@ -0,0 +1,84 @@ +dnl file : m4/libodb-sqlite.m4 +dnl author : Boris Kolpackov +dnl copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +dnl license : GNU GPL v2; see accompanying LICENSE file +dnl +dnl LIBODB_SQLITE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +dnl +dnl +AC_DEFUN([LIBODB_SQLITE], [ +libodb_sqlite_found=no + +AC_ARG_WITH( + [libodb-sqlite], + [AC_HELP_STRING([--with-libodb-sqlite=DIR],[location of libodb-sqlite build directory])], + [libodb_sqlite_dir=${withval}], + [libodb_sqlite_dir=]) + +AC_MSG_CHECKING([for libodb-sqlite]) + +# If libodb_sqlite_dir was given, add the necessary preprocessor and +# linker flags. +# +if test x"$libodb_sqlite_dir" != x; then + save_CPPFLAGS="$CPPFLAGS" + save_LDFLAGS="$LDFLAGS" + + AS_SET_CATFILE([abs_libodb_sqlite_dir], [$ac_pwd], [$libodb_sqlite_dir]) + + CPPFLAGS="$CPPFLAGS -I$abs_libodb_sqlite_dir" + LDFLAGS="$LDFLAGS -L$abs_libodb_sqlite_dir/odb/sqlite" +fi + +save_LIBS="$LIBS" +LIBS="-lodb-sqlite $LIBS" + +CXX_LIBTOOL_LINK_IFELSE( +AC_LANG_SOURCE([[ +#include + +void +f () +{ +} + +const char* +g () +{ + try + { + f (); + } + catch (const odb::sqlite::database_exception& e) + { + return e.what (); + } + return 0; +} + +int +main () +{ + const char* m (g ()); + return m != 0; +} +]]), +[libodb_sqlite_found=yes]) + +if test x"$libodb_sqlite_found" = xno; then + LIBS="$save_LIBS" + + if test x"$libodb_sqlite_dir" != x; then + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + fi +fi + +if test x"$libodb_sqlite_found" = xyes; then + AC_MSG_RESULT([yes]) + $1 +else + AC_MSG_RESULT([no]) + $2 +fi +])dnl diff --git a/m4/mysql.m4 b/m4/mysql.m4 index 5f35c91..102f150 100644 --- a/m4/mysql.m4 +++ b/m4/mysql.m4 @@ -202,7 +202,7 @@ fi # Create options file. # -AC_CONFIG_COMMANDS([db.options], +AC_CONFIG_COMMANDS([mysql.options], [ rm -f db.options echo '#! /bin/sh' >db-driver diff --git a/m4/sqlite.m4 b/m4/sqlite.m4 new file mode 100644 index 0000000..de5503e --- /dev/null +++ b/m4/sqlite.m4 @@ -0,0 +1,61 @@ +dnl file : m4/sqlite.m4 +dnl author : Boris Kolpackov +dnl copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +dnl license : GNU GPL v2; see accompanying LICENSE file +dnl +dnl SQLITE +dnl +AC_DEFUN([SQLITE], [ + +# Database file. +# +AC_MSG_CHECKING([for sqlite database file]) +AC_ARG_WITH( + [sqlite-db], + [AC_HELP_STRING([--with-sqlite-db=file], [SQLite database file (odb_test.db by default). Note that all data in this database WILL BE LOST!])], + [case $withval in + yes) + sqlite_db=odb_test.db + sqlite_db_set=yes + ;; + no) + sqlite_db_set=no + ;; + *) + sqlite_db=$withval + sqlite_db_set=yes + ;; + esac], + [sqlite_db=odb_test.db + sqlite_db_set=yes]) + +if test x$sqlite_db_set = xyes; then + + # Make it an absolute path unless it is one of the special values. + # + if test x$sqlite_db != x -a x$sqlite_db != x:memory:; then + AS_SET_CATFILE([abs_sqlite_db], [$ac_pwd], [$sqlite_db]) + sqlite_db=$abs_sqlite_db + fi + + AC_MSG_RESULT(['$sqlite_db']) +else + AC_MSG_RESULT([none]) +fi + +# Create options file. +# +AC_CONFIG_COMMANDS([sqlite.options], + [ + rm -f db.options + + if test x$sqlite_db_set = xyes; then + echo "--database '$sqlite_db'" >>db.options + fi + ], + [ + sqlite_db="$sqlite_db" + sqlite_db_set="$sqlite_db_set" + ]) + +])dnl diff --git a/mapping/makefile b/mapping/makefile index 8e7ff14..1b50fe2 100644 --- a/mapping/makefile +++ b/mapping/makefile @@ -65,7 +65,7 @@ $(dist): db_id := @database@ $(dist): sources := $(cxx_tun) $(dist): headers := $(odb_hdr) $(dist): export name := $(name) -$(dist): export extra_headers := traits.hxx +$(dist): export extra_headers := traits.hxx $(databases:%=traits-%.hxx) $(dist): export odb_header_stem := $(basename $(odb_hdr)) $(dist): export extra_dist := README $(call vc9projs,$(name)) \ $(call vc10projs,$(name)) diff --git a/template/Makefile.am b/template/Makefile.am index 2bd31ff..7bebe38 100644 --- a/template/Makefile.am +++ b/template/Makefile.am @@ -7,8 +7,14 @@ EXTRA_DIST = __file__(extra_dist) noinst_PROGRAMS = driver driver_SOURCES = driver.cxx database.hxx __path__(extra_sources) __path__(extra_headers) +AM_CPPFLAGS = -I'$(builddir)' -I'$(srcdir)' + if DATABASE_MYSQL -AM_CPPFLAGS = -DDATABASE_MYSQL +AM_CPPFLAGS += -DDATABASE_MYSQL +endif + +if DATABASE_SQLITE +AM_CPPFLAGS += -DDATABASE_SQLITE endif TESTS=$(top_builddir)/tester -- cgit v1.1