├── .gitignore ├── Makefile ├── README.md ├── change-deployment-target ├── patches ├── gg_dxf.h.patch ├── gg_formats.h.patch ├── gg_structs.h.patch ├── spatialite.patch └── sqlite.h.patch └── update-spatialite /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | 19 | # Downloaded and built directories 20 | build 21 | include 22 | geos 23 | proj 24 | spatialite 25 | sqlite3 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | XCODE_DEVELOPER = $(shell xcode-select --print-path) 2 | IOS_PLATFORM ?= iPhoneOS 3 | 4 | # Pick latest SDK in the directory 5 | IOS_PLATFORM_DEVELOPER = ${XCODE_DEVELOPER}/Platforms/${IOS_PLATFORM}.platform/Developer 6 | IOS_SDK = ${IOS_PLATFORM_DEVELOPER}/SDKs/$(shell ls ${IOS_PLATFORM_DEVELOPER}/SDKs | sort -r | head -n1) 7 | 8 | all: lib/libspatialite.a 9 | lib/libspatialite.a: build_arches 10 | mkdir -p lib 11 | mkdir -p include 12 | 13 | # Copy includes 14 | cp -R build/arm64/include/geos include 15 | cp -R build/arm64/include/spatialite include 16 | cp -R build/arm64/include/*.h include 17 | 18 | # Make fat libraries for all architectures 19 | for file in build/arm64/lib/*.a; \ 20 | do name=`basename $$file .a`; \ 21 | lipo -create \ 22 | -arch armv7 build/armv7/lib/$$name.a \ 23 | -arch armv7s build/armv7s/lib/$$name.a \ 24 | -arch arm64 build/arm64/lib/$$name.a \ 25 | -arch i386 build/i386/lib/$$name.a \ 26 | -arch x86_64 build/x86_64/lib/$$name.a \ 27 | -output lib/$$name.a \ 28 | ; \ 29 | done; 30 | 31 | # Build separate architectures 32 | build_arches: 33 | ${MAKE} arch ARCH=armv7 IOS_PLATFORM=iPhoneOS HOST=arm-apple-darwin 34 | ${MAKE} arch ARCH=armv7s IOS_PLATFORM=iPhoneOS HOST=arm-apple-darwin 35 | ${MAKE} arch ARCH=arm64 IOS_PLATFORM=iPhoneOS HOST=arm-apple-darwin 36 | ${MAKE} arch ARCH=i386 IOS_PLATFORM=iPhoneSimulator HOST=i386-apple-darwin 37 | ${MAKE} arch ARCH=x86_64 IOS_PLATFORM=iPhoneSimulator HOST=x86_64-apple-darwin 38 | 39 | PREFIX = ${CURDIR}/build/${ARCH} 40 | LIBDIR = ${PREFIX}/lib 41 | BINDIR = ${PREFIX}/bin 42 | INCLUDEDIR = ${PREFIX}/include 43 | 44 | CXX = ${XCODE_DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ 45 | CC = ${XCODE_DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang 46 | CFLAGS = -isysroot ${IOS_SDK} -I${IOS_SDK}/usr/include -arch ${ARCH} -I${INCLUDEDIR} -miphoneos-version-min=7.0 -O3 -fembed-bitcode 47 | CXXFLAGS = -stdlib=libc++ -std=c++11 -isysroot ${IOS_SDK} -I${IOS_SDK}/usr/include -arch ${ARCH} -I${INCLUDEDIR} -miphoneos-version-min=7.0 -O3 -fembed-bitcode 48 | LDFLAGS = -stdlib=libc++ -isysroot ${IOS_SDK} -L${LIBDIR} -L${IOS_SDK}/usr/lib -arch ${ARCH} -miphoneos-version-min=7.0 49 | 50 | arch: ${LIBDIR}/libspatialite.a 51 | 52 | ${LIBDIR}/libspatialite.a: ${LIBDIR}/libproj.a ${LIBDIR}/libgeos.a ${CURDIR}/spatialite 53 | cd spatialite && env \ 54 | CXX=${CXX} \ 55 | CC=${CC} \ 56 | CFLAGS="${CFLAGS} -Wno-error=implicit-function-declaration" \ 57 | CXXFLAGS="${CXXFLAGS} -Wno-error=implicit-function-declaration" \ 58 | LDFLAGS="${LDFLAGS} -liconv -lgeos -lgeos_c -lc++" ./configure --host=${HOST} --enable-freexl=no --enable-libxml2=no --prefix=${PREFIX} --with-geosconfig=${BINDIR}/geos-config --disable-shared && make clean install-strip 59 | 60 | ${CURDIR}/spatialite: 61 | curl http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.4.0-RC1.tar.gz > spatialite.tar.gz 62 | tar -xzf spatialite.tar.gz 63 | rm spatialite.tar.gz 64 | mv libspatialite-4.4.0-RC1 spatialite 65 | ./update-spatialite 66 | ./change-deployment-target spatialite 67 | 68 | ${LIBDIR}/libproj.a: ${CURDIR}/proj 69 | cd proj && env \ 70 | CXX=${CXX} \ 71 | CC=${CC} \ 72 | CFLAGS="${CFLAGS}" \ 73 | CXXFLAGS="${CXXFLAGS}" \ 74 | LDFLAGS="${LDFLAGS}" ./configure --host=${HOST} --prefix=${PREFIX} --disable-shared && make clean install 75 | 76 | ${CURDIR}/proj: 77 | curl -L http://download.osgeo.org/proj/proj-4.9.3.tar.gz > proj.tar.gz 78 | tar -xzf proj.tar.gz 79 | rm proj.tar.gz 80 | mv proj-4.9.3 proj 81 | ./change-deployment-target proj 82 | 83 | ${LIBDIR}/libgeos.a: ${CURDIR}/geos 84 | cd geos && env \ 85 | CXX=${CXX} \ 86 | CC=${CC} \ 87 | CFLAGS="${CFLAGS}" \ 88 | CXXFLAGS="${CXXFLAGS}" \ 89 | LDFLAGS="${LDFLAGS}" ./configure --host=${HOST} --prefix=${PREFIX} --disable-shared && make clean install 90 | 91 | ${CURDIR}/geos: 92 | curl http://download.osgeo.org/geos/geos-3.6.1.tar.bz2 > geos.tar.bz2 93 | tar -xzf geos.tar.bz2 94 | rm geos.tar.bz2 95 | mv geos-3.6.1 geos 96 | ./change-deployment-target geos 97 | 98 | ${LIBDIR}/libsqlite3.a: ${CURDIR}/sqlite3 99 | cd sqlite3 && env LIBTOOL=${XCODE_DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool \ 100 | CXX=${CXX} \ 101 | CC=${CC} \ 102 | CFLAGS="${CFLAGS} -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS3_PARENTHESIS=1" \ 103 | CXXFLAGS="${CXXFLAGS} -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS3_PARENTHESIS=1" \ 104 | LDFLAGS="-Wl,-arch -Wl,${ARCH} -arch_only ${ARCH} ${LDFLAGS}" \ 105 | ./configure --host=${HOST} --prefix=${PREFIX} --disable-shared \ 106 | --enable-dynamic-extensions --enable-static && make clean install-includeHEADERS install-libLTLIBRARIES 107 | 108 | ${CURDIR}/sqlite3: 109 | curl https://www.sqlite.org/2018/sqlite-autoconf-3250200.tar.gz > sqlite3.tar.gz 110 | tar xzvf sqlite3.tar.gz 111 | rm sqlite3.tar.gz 112 | mv sqlite-autoconf-3250200 sqlite3 113 | ./change-deployment-target sqlite3 114 | touch sqlite3 115 | 116 | clean: 117 | rm -rf build geos proj spatialite include lib 118 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libspatialite-ios 2 | 3 | A Makefile for automatically downloading and compiling 4 | [libspatialite](https://www.gaia-gis.it/fossil/libspatialite/index) (including 5 | its dependencies [SQLite](http://sqlite.org/index.html), 6 | [GEOS](http://trac.osgeo.org/geos/) and [PROJ.4](https://trac.osgeo.org/proj/)) 7 | statically for iOS. 8 | 9 | The resulting library is a "fat" library suitable for multiple architectures. 10 | This includes: 11 | 12 | - armv7 (iOS) 13 | - armv7s (iOS) 14 | - arm64 (iOS) 15 | - i386 (iOS Simulator) 16 | - x86_64 (iOS Simulator) 17 | 18 | ## Requirements 19 | 20 | Xcode 12.1 with Command Line Tools installed. The following compiled 21 | dependencies can be installed with Homebrew: 22 | 23 | ```sh 24 | brew install automake autoconf libtool libxml2 pkg-config 25 | brew link libxml2 26 | ``` 27 | 28 | ## Installation 29 | 30 | Simply run 31 | 32 | ``` 33 | make 34 | ``` 35 | 36 | ## Usage 37 | 38 | - Copy the contents of `lib` and the `include` directory to your Xcode project 39 | directory. You should end up with something like the following: 40 | 41 | ``` 42 | lib/ 43 | └── libspatialite 44 | ├── include 45 | │   ├── geodesic.h 46 | │   ├── geos 47 | │   │   ├── (many more files in geos) 48 | │   ├── geos.h 49 | │   ├── geos_c.h 50 | │   ├── org_proj4_PJ.h 51 | │   ├── org_proj4_Projections.h 52 | │   ├── proj_api.h 53 | │   ├── projects.h 54 | │   ├── spatialite 55 | │   └── spatialite.h 56 | ├── libgeos.a 57 | ├── libgeos_c.a 58 | ├── libproj.a 59 | ├── libspatialite.a 60 | └── mod_spatialite.a 61 | ``` 62 | 63 | - Then, drag the contents from Finder into the project navigator to incldue them 64 | in your project. Xcode should automatically add the library files to the 65 | "Build Phases" window. If not, add them later when you add the other required 66 | libraries. 67 | 68 | - Add these to the search paths in your Xcode project's "Build Settings": 69 | 70 | - Library Search Paths: \$(PROJECT_DIR)/AppName/lib/libspatialite 71 | - Header Search Paths: \$(PROJECT_DIR)/AppName/lib/libspatialite/include 72 | 73 | - And in the "Build Phases" window, add the following to the section "Link 74 | Binary With Libraries": 75 | 76 | - libiconv 77 | - libcharset.1.0.0 78 | - libc++ 79 | - libxml2.2 80 | - libz 81 | 82 | - Lastly, if your project is written in Swift, include the headers in your 83 | bridging header: 84 | 85 | ```swift 86 | // 87 | // bridging.h 88 | // 89 | 90 | #include 91 | #include 92 | #include 93 | ``` 94 | 95 | - Now you should be able to use Spatialite: 96 | 97 | ```swift 98 | spatialite_init(0); 99 | print(spatialite_version()!) 100 | ``` 101 | 102 | ## Acknowledgements 103 | 104 | Thanks to [gstf](https://github.com/gstf) for providing the original repository 105 | this is forked from (https://github.com/gstf/libspatialite-ios), as well as 106 | [davenquinn](https://github.com/davenquinn) and 107 | [smellman](https://github.com/smellman) for their forks making it possible to 108 | build for newer versions. Thanks to [aaronpk](https://github.com/aaronpk) for 109 | the instructions on how to use this in an iOS project 110 | (https://gist.github.com/aaronpk/0252426d5161bc9650d8). This is heavily adapted 111 | from all of their work. 112 | -------------------------------------------------------------------------------- /change-deployment-target: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | repl='s/\(MACOSX_DEPLOYMENT_TARGET\)-10.0/\1-10.10/g' 4 | sed -i '' $repl "$1/ltmain.sh" 5 | sed -i '' $repl "$1/configure" 6 | 7 | -------------------------------------------------------------------------------- /patches/gg_dxf.h.patch: -------------------------------------------------------------------------------- 1 | --- spatialite/src/Headers/spatialite/gg_dxf.h 2016-04-06 21:47:50.000000000 +0100 2 | +++ ./gg_dxf.h 2016-04-07 19:16:26.000000000 +0100 3 | @@ -59,6 +59,8 @@ 4 | { 5 | #endif 6 | 7 | +#include 8 | + 9 | /* constant values for DXF */ 10 | 11 | /** import distinct layers */ 12 | -------------------------------------------------------------------------------- /patches/gg_formats.h.patch: -------------------------------------------------------------------------------- 1 | --- spatialite/src/Headers/spatialite/gg_formats.h 2016-04-06 21:47:50.000000000 +0100 2 | +++ ./gg_formats.h 2016-04-07 19:16:24.000000000 +0100 3 | @@ -60,6 +60,8 @@ 4 | { 5 | #endif 6 | 7 | +#include 8 | + 9 | /* function prototypes */ 10 | 11 | /** 12 | -------------------------------------------------------------------------------- /patches/gg_structs.h.patch: -------------------------------------------------------------------------------- 1 | --- spatialite/src/Headers/spatialite/gg_structs.h 2016-04-07 21:08:45.000000000 +0100 2 | +++ ./gg_structs.h 2016-04-07 21:10:26.000000000 +0100 3 | @@ -62,6 +62,8 @@ 4 | { 5 | #endif 6 | 7 | +#include 8 | + 9 | /** 10 | Container for OGC POINT Geometry 11 | */ 12 | -------------------------------------------------------------------------------- /patches/spatialite.patch: -------------------------------------------------------------------------------- 1 | diff -rupN spatialite/src/gaiaaux/gg_utf8.c spatialite-ios/src/gaiaaux/gg_utf8.c 2 | --- spatialite/src/gaiaaux/gg_utf8.c 2012-11-25 12:47:00.000000000 +0100 3 | +++ spatialite-ios/src/gaiaaux/gg_utf8.c 2013-02-20 16:58:56.000000000 +0100 4 | @@ -71,7 +71,7 @@ extern const char *locale_charset (void) 5 | #else /* not MINGW32 - WIN32 */ 6 | #if defined(__APPLE__) || defined(__ANDROID__) 7 | #include 8 | -#include 9 | +//#include 10 | #else /* neither Mac OsX nor Android */ 11 | #include 12 | #include 13 | diff -rupN spatialite/src/gaiageo/gg_shape.c spatialite-ios/src/gaiageo/gg_shape.c 14 | --- spatialite/src/gaiageo/gg_shape.c 2012-11-25 12:47:00.000000000 +0100 15 | +++ spatialite-ios/src/gaiageo/gg_shape.c 2013-02-20 16:59:01.000000000 +0100 16 | @@ -73,7 +73,7 @@ extern const char *locale_charset (void) 17 | #else /* not MINGW32 */ 18 | #if defined(__APPLE__) || defined(__ANDROID__) 19 | #include 20 | -#include 21 | +//#include 22 | #else /* neither Mac OsX nor Android */ 23 | #include 24 | #include 25 | -------------------------------------------------------------------------------- /patches/sqlite.h.patch: -------------------------------------------------------------------------------- 1 | --- spatialite/src/Headers/spatialite/sqlite.h 2016-04-09 11:13:12.000000000 +0100 2 | +++ ./sqlite.h 2016-04-09 11:16:30.000000000 +0100 3 | @@ -46,21 +46,9 @@ 4 | #ifndef _SPATIALITE_SQLITE_H 5 | #define _SPATIALITE_SQLITE_H 6 | 7 | -#ifdef LOADABLE_EXTENSION /* loadable-extension only */ 8 | -#ifdef SPL_AMALGAMATION /* spatialite-amalgamation */ 9 | -#include 10 | -#else 11 | -#include 12 | -#endif 13 | -/* We can't use SQLITE_EXTENSION_INIT1 as this is an intializer in recent version of sqlite */ 14 | -extern const sqlite3_api_routines *sqlite3_api; 15 | -#else /* ordinary lib */ 16 | -#ifdef SPL_AMALGAMATION /* spatialite-amalgamation */ 17 | -#include 18 | -#else 19 | + 20 | #include 21 | -#endif 22 | -#endif 23 | + 24 | 25 | #ifndef SQLITE_DETERMINISTIC 26 | /* probably SQLite < 3.8.3 - attempting to fix */ 27 | -------------------------------------------------------------------------------- /update-spatialite: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | patch -Np0 < patches/spatialite.patch 4 | patch -Np0 < patches/gg_dxf.h.patch 5 | patch -Np0 < patches/gg_formats.h.patch 6 | patch -Np0 < patches/gg_structs.h.patch 7 | patch -Np0 < patches/sqlite.h.patch 8 | 9 | for f in $(find spatialite -name Makefile.*); do 10 | sed -i '' 's/ \-DLOADABLE_EXTENSION//g' $f 11 | done 12 | --------------------------------------------------------------------------------