IreneKnapp / direct-sqlite

MIT License
35 stars 54 forks source link

ICU extension flag #96

Open moll opened 2 years ago

moll commented 2 years ago

Hey,

I wanted to use SQLite with ICU enabled, so here's a patch to enable it. Perhaps useful to add to Direct-SQLite-proper, too.

diff --git a/direct-sqlite.cabal b/direct-sqlite.cabal
index deb5d30..67bcc4e 100644
--- a/direct-sqlite.cabal
+++ b/direct-sqlite.cabal
@@ -48,6 +48,10 @@ flag json1
   description: Enable json1 extension.
   default: True

+flag icu
+  description: Enable the ICU extension.
+  default: False
+
 Library
   exposed-modules:
     Database.SQLite3
@@ -86,6 +90,11 @@ Library
     if flag(json1) {
       cc-options: -DSQLITE_ENABLE_JSON1
     }
+
+    if flag(icu) {
+      cc-options: -DSQLITE_ENABLE_ICU
+      extra-libraries: icui18n icuuc icudata
+    }
   }

   include-dirs: .
jchia commented 2 years ago

I'm not sure if this way of building works on all platforms that we care about, especially the part about extra-libraries. Do those libraries always have the same names?

moll commented 2 years ago

To be honest, I don't know. That happens to be the list that pkg-config --libs icu-i18n prints out. I suppose if Cabal can take a pkg-config directive somehow, that'd may be slightly more portable.

jchia commented 2 years ago

I wonder if this approach works: https://stackoverflow.com/a/4961304/679688 A PR that uses pkg-config is welcome.