Skip to content

Initial release #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
121 changes: 121 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
### C ###
# Object files
*.o
*.ko
*.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Debug files
*.dSYM/
*.su


### OSX ###
*.DS_Store
.AppleDouble
.LSOverride


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output


### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 swiftlyfalling
Copyright (c) 2016 swiftlyfalling (https://github.com/swiftlyfalling)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
153 changes: 152 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,153 @@
# SQLiteLib
SQLiteLib
==========

Easily build a custom SQLite static library for use in OSX and iOS frameworks and apps.

If you need a specific version of SQLite, or specific SQLite compilation options/features, read on.


---

**May 29, 2016: SQLiteLib updated for SQLite 3.13.0** ([changelog](CHANGELOG.md)).

**Requirements**: iOS 8.0+ / OSX 10.9+, Xcode 7.3+

**SQLite Included:** 3.13.0


### Installation

#### Manual Installation (ex. into a Framework)

1. Download a copy of SQLiteLib.
2. Embed the `SQLiteLib.xcodeproj` project in your own project.
3. Add the SQLiteLib.`sqlitecustom` target in the **Target Dependencies** section of the **Build Phases** tab of your application target.
4. Add `libsqlitecustom.a` to the **Linked Frameworks and Libraries** section of the **General** tab of your target.

That's it! (You'll probably also want to `#include "sqlite3.h"` somewhere. SQLiteLib copies this generated file to its project directory.)

#### Using in Swift

You probably shouldn't be using the raw SQLite C API in Swift. There are a bunch of great libraries available that wrap it.

For example: ([GRDB.swift](https://github.com/groue/GRDB.swift)).


### Customization

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).

#### Specifying Additional SQLite Compilation Options

> 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*.
> You only need to follow the steps below if you wish to customize the options.

To specify additional options:

1. Open `SQLiteLib-Custom.xcconfig`
2. Modify `CUSTOM_SQLLIBRARY_CFLAGS` to specify the additional options.

For example, to specify SQLITE\_ENABLE\_PREUPDATE\_HOOK, you would modify it like this:
```ini
CUSTOM\_SQLLIBRARY\_CFLAGS = -DSQLITE\_ENABLE\_PREUPDATE\_HOOK
```

That's it.
There is no need to modify any other files.


#### Compiling a Specific Version of SQLite

SQLiteLib currently ships with the source for SQLite 3.13.0.

If you'd like to compile a newer (or older) version, the process is simple:

1. Download a snapshot of the complete (raw) source tree for SQLite for the version you'd like.
2. Replace the contents of SQLiteLib's "sqlite" subdirectory with the contents of the SQLite raw source tree snapshot.

> **IMPORTANT**:
> You **must** use the complete raw SQLite source. The amalgamation source will *NOT* work properly.
>
> SQLiteLib internally builds the amalgamation source using the steps specified in ([How To Compile SQLite](https://www.sqlite.org/howtocompile.html#amal)).
>
> Setting compilation options using the SQLite amalgamation is not guaranteed to work:
> > 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**.

**Quick Guide to Using the Latest version of SQLite**:
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**.
You'll want the file named "sqlite-src-*version*.zip".
> Do **NOT** use the file beginning with "sqlite-preprocessed" - it will not work properly.


### Additional Details

#### Default Compilation Options

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):

> Fetched using `PRAGMA compile_options;`

- MacOSX (10.11.5)
- ENABLE_API_ARMOR
- ENABLE_FTS3
- ENABLE_FTS3_PARENTHESIS
- ENABLE_LOCKING_STYLE=1
- ENABLE_RTREE
- ENABLE_UPDATE_DELETE_LIMIT
- OMIT_AUTORESET
- OMIT_BUILTIN_TEST
- OMIT_LOAD_EXTENSION
- SYSTEM_MALLOC
- THREADSAFE=2

- iPhoneOS (9.3.2)
- ENABLE_API_ARMOR
- ENABLE_FTS3
- ENABLE_FTS3_PARENTHESIS
- ENABLE_LOCKING_STYLE=1
- ENABLE_RTREE
- ENABLE_UPDATE_DELETE_LIMIT
- MAX_MMAP_SIZE=0
- OMIT_AUTORESET
- OMIT_BUILTIN_TEST
- OMIT_LOAD_EXTENSION
- SYSTEM_MALLOC
- THREADSAFE=2

SQLiteLib uses these settings with one exception - on iOS:

The SQLite code (verified in: 3.13.0) uses a deprecated function (`gethostuuid()`).

D. Richard Hipp (SQLite architect), suggests working around this on iOS using `-DSQLITE_ENABLE_LOCKING_STYLE=0`:
> "The SQLITE_ENABLE_LOCKING_STYLE thing is an apple-only extension that
> boosts performance when SQLite is used on a network filesystem. This
> is important on MacOS because some users think it is a good idea to
> put their home directory on a network filesystem.
>
> I'm guessing this is not really a factor on iOS."

Thus, SQLiteLib uses SQLITE_ENABLE_LOCKING_STYLE=1 on OSX,
**but on iOS, SQLiteLib compiles with ENABLE_LOCKING_STYLE=0**.

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).
To prevent this warning, SQLiteLib separately specifies `-Wno-#warnings` when building for iOS.

All of these base settings are configured in the SQLiteLib.xcconfig file.
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)

#### Build Locations

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).

The generated SQLite amalgamation files are copied to:
"${BUILT_PRODUCTS_DIR}/sqlite3.c"
"${PROJECT_DIR}/sqlite3.h"

#### Notes

##### "sqlite3.c" shows as red/missing in Xcode

Xcode (verified in Version 7.3.1 (7D1014)) will always show "sqlite3.c" as red/missing, even after a build.
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.


11 changes: 11 additions & 0 deletions SQLiteLib-Custom.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

// Custom additions to the SQLite compilation options
// These are merged with the default options (for OSX / iOS)
//
// As an example, SQLITE_ENABLE_PREUPDATE_HOOK is set below.
// (On SQLite 3.13.0+, this enables pre-update hook functionality.)
//
// For more information on the options, see: https://www.sqlite.org/compile.html

// Added to OTHER_CFLAGS in all cases
CUSTOM_SQLLIBRARY_CFLAGS = -DSQLITE_ENABLE_PREUPDATE_HOOK
95 changes: 95 additions & 0 deletions SQLiteLib.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// NOTE: DO NOT EDIT THIS FILE!
// To specify additional custom SQLite compilation options, edit "SQLiteLib-Custom.xcconfig"
//

#include "SQLiteLib-Custom.xcconfig"

// SQLiteLib targets OS X 10.9
MACOSX_DEPLOYMENT_TARGET = 10.9

// SQLiteLib targets iOS 8.0
IPHONEOS_DEPLOYMENT_TARGET = 8.0

// Supported platforms
SUPPORTED_PLATFORMS = iphonesimulator macosx iphoneos appletvsimulator appletvos watchsimulator watchos

// Compilation options used by stock sqlite3 shipped with Apple operating systems
//
// Mac OSX 10.11.5:
// ENABLE_API_ARMOR
// ENABLE_FTS3
// ENABLE_FTS3_PARENTHESIS
// ENABLE_LOCKING_STYLE=1
// ENABLE_RTREE
// ENABLE_UPDATE_DELETE_LIMIT
// OMIT_AUTORESET
// OMIT_BUILTIN_TEST
// OMIT_LOAD_EXTENSION
// SYSTEM_MALLOC
// THREADSAFE=2

// iOS 9.3.2:
// ENABLE_API_ARMOR
// ENABLE_FTS3
// ENABLE_FTS3_PARENTHESIS
// ENABLE_LOCKING_STYLE=1
// ENABLE_RTREE
// ENABLE_UPDATE_DELETE_LIMIT
// MAX_MMAP_SIZE=0
// OMIT_AUTORESET
// OMIT_BUILTIN_TEST
// OMIT_LOAD_EXTENSION
// SYSTEM_MALLOC
// THREADSAFE=2

// IMPORTANT:
// The system SQLite library is compiled with SQLITE_ENABLE_LOCKING_STYLE=1 on both OSX 10.11 & iOS 9.0.
// However, the SQLite code (verified in: 3.13.0) uses a deprecated function on iOS (gethostuuid()).
//
// D. Richard Hipp (SQLite architect), suggests working around this on iOS using -DSQLITE_ENABLE_LOCKING_STYLE=0
// "The SQLITE_ENABLE_LOCKING_STYLE thing is an apple-only extension that
// boosts performance when SQLite is used on a network filesystem. This
// is important on MacOS because some users think it is a good idea to
// put their home directory on a network filesystem.
//
// I'm guessing this is not really a factor on iOS."
// Source: https://groups.google.com/forum/#!topic/sqlite-dev/7yjGulq3LmY
// Via: https://github.com/clemensg/sqlite3pod/issues/1
//
// Thus, SQLITE_ENABLE_LOCKING_STYLE=1 is used on OSX,
// and SQLITE_ENABLE_LOCKING_STYLE=0 on iOS/tvOS/watchOS.
//
// (Note: This doesn't get rid of the warning that "gethostuuid() is disabled" (as of 3.13.0). Uncomment the lines below to do so.)
//
// ↓ UNCOMMENT THE LINES BELOW to remove "gethostuuid() is disabled" warning on iOS/tvOS/watchOS.
WARNING_CFLAGS[sdk=iphoneos*] = -Wno-#warnings
WARNING_CFLAGS[sdk=iphonesimulator*] = -Wno-#warnings
WARNING_CFLAGS[sdk=appletvos*] = -Wno-#warnings
WARNING_CFLAGS[sdk=appletvsimulator*] = -Wno-#warnings
WARNING_CFLAGS[sdk=watchos*] = -Wno-#warnings
WARNING_CFLAGS[sdk=watchsimulator*] = -Wno-#warnings
// ↑ UNCOMMENT THE LINES ABOVE to remove "gethostuuid() is disabled" warning on iOS/tvOS/watchOS.

// The common set of compilation options (on OSX and iOS).
// NOTE: To add more compilation options, see SQLiteLibCustom.xcconfig.
SQLLIBRARY_BASE_CFLAGS = -DSQLITE_ENABLE_API_ARMOR -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -DSQLITE_OMIT_AUTORESET -DSQLITE_OMIT_BUILTIN_TEST -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_SYSTEM_MALLOC -DSQLITE_THREADSAFE=2 -DSQLITE_OS_UNIX=1 $(CUSTOM_SQLLIBRARY_CFLAGS)

SQLLIBRARY_OSX_ADDITIONAL_CFLAGS = -DSQLITE_ENABLE_LOCKING_STYLE=1
SQLLIBRARY_IOS_ADDITIONAL_CFLAGS = -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_MAX_MMAP_SIZE=0
SQLLIBRARY_RELEASE_CFLAGS = -DNDEBUG
SQLLIBRARY_ARMV6_CFLAGS = -mno-thumb

SQLLIBRARY_CFLAGS = $(SQLLIBRARY_BASE_CFLAGS)
SQLLIBRARY_CFLAGS[sdk=iphoneos*] = $(SQLLIBRARY_BASE_CFLAGS) $(SQLLIBRARY_IOS_ADDITIONAL_CFLAGS)
SQLLIBRARY_CFLAGS[sdk=iphonesimulator*] = $(SQLLIBRARY_BASE_CFLAGS) $(SQLLIBRARY_IOS_ADDITIONAL_CFLAGS)
SQLLIBRARY_CFLAGS[sdk=appletvos*] = $(SQLLIBRARY_BASE_CFLAGS) $(SQLLIBRARY_IOS_ADDITIONAL_CFLAGS)
SQLLIBRARY_CFLAGS[sdk=appletvsimulator*] = $(SQLLIBRARY_BASE_CFLAGS) $(SQLLIBRARY_IOS_ADDITIONAL_CFLAGS)
SQLLIBRARY_CFLAGS[sdk=watchos*] = $(SQLLIBRARY_BASE_CFLAGS) $(SQLLIBRARY_IOS_ADDITIONAL_CFLAGS)
SQLLIBRARY_CFLAGS[sdk=watchsimulator*] = $(SQLLIBRARY_BASE_CFLAGS) $(SQLLIBRARY_IOS_ADDITIONAL_CFLAGS)
SQLLIBRARY_CFLAGS[sdk=macosx*] = $(SQLLIBRARY_BASE_CFLAGS) $(SQLLIBRARY_OSX_ADDITIONAL_CFLAGS)

OTHER_CFLAGS = $(SQLLIBRARY_CFLAGS)
OTHER_CFLAGS[arch=armv6] = $(SQLLIBRARY_ARMV6_CFLAGS) $(SQLLIBRARY_CFLAGS)
OTHER_CFLAGS[config=Release] = $(SQLLIBRARY_CFLAGS) $(SQLLIBRARY_RELEASE_CFLAGS)
OTHER_CFLAGS[config=Release][arch=armv6] = $(SQLLIBRARY_ARMV6_CFLAGS) $(SQLLIBRARY_CFLAGS) $(SQLLIBRARY_RELEASE_CFLAGS)
Loading