xmake.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package("sqlcipher")
  2. set_homepage("https://www.zetetic.net/sqlcipher/")
  3. set_description("SQLCipher is a standalone fork of the SQLite database library that adds 256 bit AES encryption of database files and other security features")
  4. set_urls("https://github.com/sqlcipher/sqlcipher/archive/refs/tags/v$(version).tar.gz")
  5. add_versions("4.5.3", "5c9d672eba6be4d05a9a8170f70170e537ae735a09c3de444a8ad629b595d5e2")
  6. add_configs("encrypt", { description = "enable encrypt", default = true, type = "boolean"})
  7. add_configs("temp_store", { description = "use an in-ram database for temporary tables", default = "2", values = {"0", "1", "2" , "3"}})
  8. add_configs("threadsafe", { description = "sqltie thread safe mode", default = "1", values = {"0", "1", "2"}})
  9. if is_plat("iphoneos") then
  10. add_frameworks("Security")
  11. else
  12. add_deps("openssl")
  13. end
  14. if is_host("linux", "macosx") then
  15. add_deps("tclsh")
  16. end
  17. if is_plat("macosx", "linux", "cross") then
  18. add_syslinks("pthread", "dl", "m")
  19. elseif is_plat("android") then
  20. add_syslinks("dl", "m", "z")
  21. end
  22. on_load(function (package)
  23. if package:is_plat("windows") and package:config("shared") then
  24. package:add("defines", "SQLITE_API=__declspec(dllimport)")
  25. end
  26. if package:config("encrypt") then
  27. package:add("defines", "SQLITE_HAS_CODEC=1")
  28. end
  29. end)
  30. on_install("windows", function (package)
  31. local openssl = package:dep("openssl"):fetch()
  32. assert(openssl, "Failed fetch openssl library!")
  33. local rtcc_include = ""
  34. for _, dir in ipairs(openssl.sysincludedirs or openssl.includedirs) do
  35. rtcc_include = rtcc_include .. " -I" .. dir
  36. end
  37. local libpaths = ""
  38. for _, dir in ipairs(openssl.linkdirs) do
  39. libpaths = libpaths .. " /LIBPATH:" .. dir
  40. end
  41. local temp_store = " -DSQLITE_TEMP_STORE=" .. package:config("temp_store")
  42. local thread_safe = " -DSQLITE_THREADSAFE=" .. package:config("threadsafe")
  43. io.replace("Makefile.msc", "TCC = $(TCC) -DSQLITE_TEMP_STORE=1", "TCC = $(TCC) -DSQLITE_HAS_CODEC" .. rtcc_include .. temp_store, {plain = true})
  44. io.replace("Makefile.msc", "TCC = $(TCC) -DSQLITE_THREADSAFE=1", "TCC = $(TCC)" .. thread_safe, {plain = true})
  45. io.replace("Makefile.msc", "RCC = $(RCC) -DSQLITE_TEMP_STORE=1", "RCC = $(RCC) -DSQLITE_HAS_CODEC" .. rtcc_include .. temp_store, {plain = true})
  46. io.replace("Makefile.msc", "RCC = $(RCC) -DSQLITE_THREADSAFE=1", "RCC = $(RCC)" .. thread_safe, {plain = true})
  47. import("package.tools.nmake")
  48. local envs = nmake.buildenvs(package)
  49. envs.NO_TCL = 1
  50. envs.SESSION = 0
  51. envs.SQLITE3DLL = "sqlcipher.dll"
  52. envs.SQLITE3LIB = "sqlcipher.lib"
  53. envs.SQLITE3EXE = "sqlcipher.exe"
  54. envs.SQLITE3EXEPDB = "/pdb:sqlcipher.pdb"
  55. envs.LTLIBS = "advapi32.lib user32.lib ws2_32.lib crypt32.lib wsock32.lib libcrypto.lib libssl.lib"
  56. envs.LTLIBPATHS = libpaths
  57. envs.PLATFORM = package:arch()
  58. nmake.build(package, {"-f", "Makefile.msc"}, {envs = envs})
  59. os.cp("sqlcipher.dll", package:installdir("bin"))
  60. os.cp("sqlcipher.pdb", package:installdir("bin"))
  61. os.cp("sqlcipher.exe", package:installdir("bin"))
  62. os.cp("sqlcipher.lib", package:installdir("lib"))
  63. os.cp("sqlite3.h", package:installdir("include"))
  64. os.cp("sqlite3ext.h", package:installdir("include"))
  65. end)
  66. on_install("linux", "macosx", "android", "iphoneos", "cross", function (package)
  67. os.vrunv("./configure", {"--with-crypto-lib=none"})
  68. import("package.tools.make").build(package, {"sqlite3.c"})
  69. local configs = {}
  70. if package:config("shared") then
  71. configs.kind = "shared"
  72. end
  73. configs.encrypt = package:config("encrypt")
  74. configs.threadsafe = threadsafe
  75. configs.temp_store = temp_store
  76. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  77. import("package.tools.xmake").install(package, configs)
  78. end)
  79. on_test(function (package)
  80. assert(package:has_cfuncs("sqlite3_open_v2", {includes = "sqlite3.h"}))
  81. end)