1 /*
2 ** Copyright (c) 2019 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeBSD License".)
7 **
8 ** This program is distributed in the hope that it will be useful,
9 ** but without any warranty; without even the implied warranty of
10 ** merchantability or fitness for a particular purpose.
11 **
12 ** Author contact information:
13 ** drh@hwaci.com
14 ** http://www.hwaci.com/drh/
15 **
16 *******************************************************************************
17 **
18 ** This file is NOT part of the Fossil executable. It is called from
19 ** auto.def in the autosetup system.
20 **
21 ** This file contains a test program used by ../configure with the
22 ** the --disable-internal-sqlite option to determine whether or
23 ** not the system SQLite library is sufficient to support Fossil.
24 **
25 ** This must be compiled with -D MINIMUM_SQLITE_VERSION set in auto.def.
26 **
27 ** It is preferred to statically link Fossil with the sqlite3.c source
28 ** file that is part of the source tree and not use any SQLite shared
29 ** library that is included with the system. But some packagers do not
30 ** like to do this. Hence, we provide the option to link Fossil against
31 ** the system SQLite shared library. But Fossil is very particular about
32 ** the version and build options for SQLite. Unless a recent version of
33 ** SQLite is available, and unless that SQLite is built using some
34 ** non-default features, the system library won't meet the needs of
35 ** Fossil. This program attempts to determine if the system library
36 ** SQLite is sufficient for Fossil.
37 **
38 ** Compile this program, linking it against the system SQLite library,
39 ** and run it. If it returns with a zero exit code, then all is well.
40 ** But if it returns a non-zero exit code, then the system SQLite library
41 ** lacks some capability that Fossil uses. A message on stdout describes
42 ** the missing feature.
43 */
44 #include "sqlite3.h"
45 #include <stdio.h>
46 #include <string.h>
47
main(int argc,char ** argv)48 int main(int argc, char **argv){
49
50 #if !defined(MINIMUM_SQLITE_VERSION)
51 #error "Must set -DMINIMUM_SQLITE_VERSION=nn.nn.nn in auto.def"
52 #endif
53
54 #define QUOTE(VAL) #VAL
55 #define STR(MACRO_VAL) QUOTE(MACRO_VAL)
56
57 char zMinimumVersionNumber[8]="nn.nn.nn";
58 strncpy((char *)&zMinimumVersionNumber,STR(MINIMUM_SQLITE_VERSION),sizeof(zMinimumVersionNumber));
59
60 long major, minor, release, version;
61 sscanf(zMinimumVersionNumber, "%li.%li.%li", &major, &minor, &release);
62 version=(major*1000000)+(minor*1000)+release;
63
64 int i;
65 static const char *zRequiredOpts[] = {
66 "ENABLE_FTS4", /* Required for repository search */
67 "ENABLE_JSON1", /* Required for the check-in locking protocol */
68 "ENABLE_DBSTAT_VTAB", /* Required by /repo-tabsize page */
69 };
70
71 /* Check minimum SQLite version number */
72 if( sqlite3_libversion_number()<version ){
73 printf("found system SQLite version %s but need %s or later, consider removing --disable-internal-sqlite\n",
74 sqlite3_libversion(),STR(MINIMUM_SQLITE_VERSION));
75 return 1;
76 }
77
78 for(i=0; i<sizeof(zRequiredOpts)/sizeof(zRequiredOpts[0]); i++){
79 if( !sqlite3_compileoption_used(zRequiredOpts[i]) ){
80 printf("system SQLite library omits required build option -DSQLITE_%s\n",
81 zRequiredOpts[i]);
82 return 1;
83 }
84 }
85
86 /* Success! */
87 return 0;
88 }
89