Skip to content

Commit e413320

Browse files
Add initial README
1 parent a8d5767 commit e413320

File tree

1 file changed

+152
-1
lines changed

1 file changed

+152
-1
lines changed

README.md

100644100755
Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,153 @@
1-
# SQLiteLib
1+
SQLiteLib
2+
==========
3+
24
Easily build a custom SQLite static library for use in OSX and iOS frameworks and apps.
5+
6+
If you need a specific version of SQLite, or specific SQLite compilation options/features, read on.
7+
8+
9+
---
10+
11+
**May 29, 2016: SQLiteLib updated for SQLite 3.13.0** ([changelog](CHANGELOG.md)).
12+
13+
**Requirements**: iOS 8.0+ / OSX 10.9+, Xcode 7.3+
14+
15+
**SQLite Included:** 3.13.0
16+
17+
18+
### Installation
19+
20+
#### Manual Installation (ex. into a Framework)
21+
22+
1. Download a copy of SQLiteLib.
23+
2. Embed the `SQLiteLib.xcodeproj` project in your own project.
24+
3. Add the SQLiteLib.`sqlitecustom` target in the **Target Dependencies** section of the **Build Phases** tab of your application target.
25+
4. Add `libsqlitecustom.a` to the **Linked Frameworks and Libraries** section of the **General** tab of your target.
26+
27+
That's it! (You'll probably also want to `#include "sqlite3.h"` somewhere. SQLiteLib copies this generated file to its project directory.)
28+
29+
#### Using in Swift
30+
31+
You probably shouldn't be using the raw SQLite C API in Swift. There are a bunch of great libraries available that wrap it.
32+
33+
For example: ([GRDB.swift](https://github.com/groue/GRDB.swift)).
34+
35+
36+
### Customization
37+
38+
By default, SQLiteLib builds SQLite with options that match the built-in system version of SQLite on OSX and iOS (as of OSX 10.11.5, iOS 9.3.2), [with one exception*](#additional-details).
39+
40+
#### Specifying Additional SQLite Compilation Options
41+
42+
> By default, SQLiteLib compiles SQLite with options that match the built-in OSX/iOS version of SQLite (as of OSX 10.11, iOS 9.3.2), with one exception*.
43+
> You only need to follow the steps below if you wish to customize the options.
44+
45+
To specify additional options:
46+
47+
1. Open `SQLiteLib-Custom.xcconfig`
48+
2. Modify `CUSTOM_SQLLIBRARY_CFLAGS` to specify the additional options.
49+
50+
For example, to specify SQLITE\_ENABLE\_PREUPDATE\_HOOK, you would modify it like this:
51+
```ini
52+
CUSTOM\_SQLLIBRARY\_CFLAGS = -DSQLITE\_ENABLE\_PREUPDATE\_HOOK
53+
```
54+
55+
That's it.
56+
There is no need to modify any other files.
57+
58+
59+
#### Compiling a Specific Version of SQLite
60+
61+
SQLiteLib currently ships with the source for SQLite 3.13.0.
62+
63+
If you'd like to compile a newer (or older) version, the process is simple:
64+
65+
1. Download a snapshot of the complete (raw) source tree for SQLite for the version you'd like.
66+
2. Replace the contents of SQLiteLib's "sqlite" subdirectory with the contents of the SQLite raw source tree snapshot.
67+
68+
> **IMPORTANT**:
69+
> You **must** use the complete raw SQLite source. The amalgamation source will *NOT* work properly.
70+
>
71+
> SQLiteLib internally builds the amalgamation source using the steps specified in ([How To Compile SQLite](https://www.sqlite.org/howtocompile.html#amal)).
72+
>
73+
> Setting compilation options using the SQLite amalgamation is not guaranteed to work:
74+
> > The versions of the SQLite amalgamation that are supplied on the download page are normally adequate for most users. However, some projects may want or need to build their own amalgamations. A common reason for building a custom amalgamation is in order to use certain compile-time options to customize the SQLite library. Recall that the SQLite amalgamation contains a lot of C-code that is generated by auxiliary programs and scripts. Many of the compile-time options effect this generated code and **must be supplied to the code generators before the amalgamation is assembled**.
75+
76+
**Quick Guide to Using the Latest version of SQLite**:
77+
The snapshop of the complete (raw) source tree for the *current* version of SQLite is available on the ([SQLite Download Page](https://www.sqlite.org/download.html#old)) under: **Alternative Source Code Formats**.
78+
You'll want the file named "sqlite-src-*version*.zip".
79+
> Do **NOT** use the file beginning with "sqlite-preprocessed" - it will not work properly.
80+
81+
82+
### Additional Details
83+
84+
#### Default Compilation Options
85+
86+
The built-in OSX/iOS version of SQLite were built with the following compilation options (as of OSX 10.11.5, iOS 9.3.2):
87+
88+
> Fetched using `PRAGMA compile_options;`
89+
90+
- MacOSX (10.11.5)
91+
- ENABLE_API_ARMOR
92+
- ENABLE_FTS3
93+
- ENABLE_FTS3_PARENTHESIS
94+
- ENABLE_LOCKING_STYLE=1
95+
- ENABLE_RTREE
96+
- ENABLE_UPDATE_DELETE_LIMIT
97+
- OMIT_AUTORESET
98+
- OMIT_BUILTIN_TEST
99+
- OMIT_LOAD_EXTENSION
100+
- SYSTEM_MALLOC
101+
- THREADSAFE=2
102+
103+
- iPhoneOS (9.3.2)
104+
- ENABLE_API_ARMOR
105+
- ENABLE_FTS3
106+
- ENABLE_FTS3_PARENTHESIS
107+
- ENABLE_LOCKING_STYLE=1
108+
- ENABLE_RTREE
109+
- ENABLE_UPDATE_DELETE_LIMIT
110+
- MAX_MMAP_SIZE=0
111+
- OMIT_AUTORESET
112+
- OMIT_BUILTIN_TEST
113+
- OMIT_LOAD_EXTENSION
114+
- SYSTEM_MALLOC
115+
- THREADSAFE=2
116+
117+
SQLiteLib uses these settings with one exception - on iOS:
118+
119+
The SQLite code (verified in: 3.13.0) uses a deprecated function (`gethostuuid()`).
120+
121+
D. Richard Hipp (SQLite architect), suggests working around this on iOS using `-DSQLITE_ENABLE_LOCKING_STYLE=0`:
122+
> "The SQLITE_ENABLE_LOCKING_STYLE thing is an apple-only extension that
123+
> boosts performance when SQLite is used on a network filesystem. This
124+
> is important on MacOS because some users think it is a good idea to
125+
> put their home directory on a network filesystem.
126+
>
127+
> I'm guessing this is not really a factor on iOS."
128+
129+
Thus, SQLiteLib uses SQLITE_ENABLE_LOCKING_STYLE=1 on OSX,
130+
**but on iOS, SQLiteLib compiles with ENABLE_LOCKING_STYLE=0**.
131+
132+
This removes the code that uses the deprecated function, but doesn't get rid of the warning that "`gethostuuid() is disabled`" (as of 3.13.0).
133+
To prevent this warning, SQLiteLib separately specifies `-Wno-#warnings` when building for iOS.
134+
135+
All of these base settings are configured in the SQLiteLib.xcconfig file.
136+
It is strongly recommended that you do not edit this file. If you'd like to specify additional compilation options, see [the instructions above](#specifying-additional-sqlite-compilation-options)
137+
138+
#### Build Locations
139+
140+
SQLiteLib generates intermediate files in [${DERIVED_SOURCES_DIR}](https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW43).
141+
142+
The generated SQLite amalgamation files are copied to:
143+
"${BUILT_PRODUCTS_DIR}/sqlite3.c"
144+
"${PROJECT_DIR}/sqlite3.h"
145+
146+
#### Notes
147+
148+
##### "sqlite3.c" shows as red/missing in Xcode
149+
150+
Xcode (verified in Version 7.3.1 (7D1014)) will always show "sqlite3.c" as red/missing, even after a build.
151+
This is a UI issue in Xcode - the path is properly set in the project.pbxproj file to be "Relative to Build Products", and the build should succeed.
152+
153+

0 commit comments

Comments
 (0)