xmake.lua 4.4 KB

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