TJez
TJez

Reputation: 2029

Building Sqlite ICU with xcode

How do I compile sqlite with ICU (International Components for Unicode) as a project in my iPhone app's workspace?

I've compiled the sqlite amalgamation before, however I'm not sure what files I should download, and what scripts need to be added to xcode - surely I'm not the first to need this.

Ideally I'm looking for step-by-step instructions.

Upvotes: 1

Views: 1580

Answers (2)

Qiulang
Qiulang

Reputation: 12405

This is a rather old question but b/c I spent quite some time in building an ICU version myself I would like to share my experience. Basically I raised the question and get the help from sqlite mail list here https://www.mail-archive.com/[email protected]/msg112029.html

So first using brew to install icu4c, but with a catch, b/c brew refuses to link icu4c. So I need to add icu4c in my path

qiulangs-MacBook-Pro:fts qiulang$ brew info icu4c
icu4c: stable 62.1 (bottled) [keg-only]
C/C++ and Java libraries for Unicode and globalization
http://site.icu-project.org/
/usr/local/Cellar/icu4c/62.1 (250 files, 67.3MB)
  Poured from bottle on 2018-07-05 at 15:12:09
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/icu4c.rb
==> Caveats
icu4c is keg-only, which means it was not symlinked into /usr/local,
because macOS provides libicucore.dylib (but nothing else).

If you need to have icu4c first in your PATH run:
  echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile

For compilers to find icu4c you may need to set:
  export LDFLAGS="-L/usr/local/opt/icu4c/lib"
  export CPPFLAGS="-I/usr/local/opt/icu4c/include"

Second, download the sqlite-autoconf tar from https://www.sqlite.org/download.html Then just run configure like this, (if the first line of your configure output is bash: icu-config: command not found then check why icu4c wasn't in your path.)

./configure CFLAGS="-DSQLITE_ENABLE_ICU `icu-config --cppflags`" LDFLAGS="`icu-config --ldflags`"

I didn't set LDFLAGS & CPPFLAGS as brew suggests and I still run configure successfully with output creating Makefile , then run make to build an ICU version. I believe after that you would like to double check it works. This is the sample codes I used:

sqlite> CREATE VIRTUAL TABLE zh_text USING fts4(text, tokenize=icu zh_CN);
sqlite> INSERT INTO zh_text values('为什么不支持中文 Can icu support Chinese');
sqlite> CREATE VIRTUAL TABLE zh_terms USING fts4aux(zh_text);
sqlite> SELECT term, col, documents FROM zh_terms;
can|*|1
can|0|1
chinese|*|1
chinese|0|1
icu|*|1
icu|0|1
support|*|1
support|0|1
不|*|1
不|0|1
中文|*|1
中文|0|1
为什么|*|1
为什么|0|1
支持|*|1
支持|0|1
sqlite> CREATE VIRTUAL TABLE icu_zh_cn USING fts3tokenize(icu, zh_CN);
sqlite> SELECT token, start, end, position FROM icu_zh_cn WHERE INPUT='为什么不支持中文 fts5 does not seem to work for chinese';
为什么|0|9|0
不|9|12|1
支持|12|18|2
中文|18|24|3
fts5|25|29|4
does|30|34|5
not|35|38|6
seem|39|43|7
to|44|46|8
work|47|51|9
for|52|55|10
chinese|56|63|11

fts5 seems not support ICU tokenizer yet so I can only fts3 or fts4.

sqlite> CREATE VIRTUAL TABLE zh_text5 USING fts5(text, tokenize=icu zh_CN);
Error: parse error in "tokenize=icu zh_CN"

Upvotes: 3

Marc Bernier
Marc Bernier

Reputation: 2996

I've done this with 5.2.1 on Linux (GCC compiler) using the ICU source code from here: http://site.icu-project.org/download/52. All of the cpp and c files were added to the project. SQLite 3.8.4.1 amalgamated was also in the project. The trick is the defines:

ICU needs: U_COMMON_IMPLEMENTATION U_STATIC_IMPLEMENTATION U_I18N_IMPLEMENTATION HAVE_CONFIG_H HAVE_INTTYPES_H

SQLite needs: SQLITE_OMIT_LOAD_EXTENSION

It's not the easiest thing, but a lot easier than older versions of ICU.

Granted, Linux is not the iPhone, but this may help a little.

Upvotes: -1

Related Questions