xmake.lua 4.3 KB

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