xmake.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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_license("BSD-3-Clause")
  5. set_urls("https://github.com/sqlcipher/sqlcipher/archive/refs/tags/v$(version).tar.gz")
  6. add_versions("4.13.0", "7ca5c11f70e460d6537844185621d5b3d683a001e6bad223d15bdf8eff322efa")
  7. add_versions("4.12.0", "151a1c618c7ae175dfd0f862a8d52e8abd4c5808d548072290e8656032bb0f12")
  8. add_versions("4.6.0", "879fb030c36bc5138029af6aa3ae3f36c28c58e920af05ac7ca78a5915b2fa3c")
  9. add_versions("4.5.3", "5c9d672eba6be4d05a9a8170f70170e537ae735a09c3de444a8ad629b595d5e2")
  10. if not is_plat("windows") then
  11. -- only for GCC 15
  12. add_patches(">=4.12.0", path.join(os.scriptdir(), "patches", "4.12.0", "stdint.patch"), "608ea7c41855b26029f114ac5b0c9abf35656dec559b86939909813da6bb78ae")
  13. end
  14. add_configs("encrypt", { description = "enable encrypt", default = true, type = "boolean"})
  15. add_configs("temp_store", { description = "use an in-ram database for temporary tables", default = "2", values = {"0", "1", "2" , "3"}})
  16. add_configs("threadsafe", { description = "sqltie thread safe mode", default = "1", values = {"0", "1", "2"}})
  17. if is_plat("iphoneos") then
  18. add_frameworks("Security")
  19. else
  20. add_deps("openssl3")
  21. end
  22. if is_host("linux", "macosx") then
  23. add_deps("tclsh")
  24. end
  25. if is_plat("macosx", "linux", "cross") then
  26. add_syslinks("pthread", "dl", "m")
  27. elseif is_plat("android") then
  28. add_syslinks("dl", "m", "z")
  29. end
  30. if on_check then
  31. on_check("windows|arm64", function (package)
  32. raise("package(sqlcipher): does not support windows-arm64")
  33. end)
  34. end
  35. on_load(function (package)
  36. if package:is_plat("windows") and package:config("shared") then
  37. package:add("defines", "SQLITE_API=__declspec(dllimport)")
  38. end
  39. if package:config("encrypt") then
  40. package:add("defines", "SQLITE_HAS_CODEC=1")
  41. end
  42. end)
  43. on_install("windows", function (package)
  44. local openssl = package:dep("openssl3"):fetch()
  45. assert(openssl, "Failed fetch openssl3 library!")
  46. local rtcc_include = ""
  47. for _, dir in ipairs(openssl.sysincludedirs or openssl.includedirs) do
  48. rtcc_include = rtcc_include .. " -I" .. dir
  49. end
  50. local libpaths = ""
  51. for _, dir in ipairs(openssl.linkdirs) do
  52. libpaths = libpaths .. " /LIBPATH:" .. dir
  53. end
  54. local temp_store = " -DSQLITE_TEMP_STORE=" .. package:config("temp_store")
  55. local thread_safe = " -DSQLITE_THREADSAFE=" .. package:config("threadsafe")
  56. io.replace("Makefile.msc", "TCC = $(TCC) -DSQLITE_TEMP_STORE=1", "TCC = $(TCC) -DSQLITE_HAS_CODEC" .. rtcc_include .. temp_store, {plain = true})
  57. io.replace("Makefile.msc", "TCC = $(TCC) -DSQLITE_THREADSAFE=1", "TCC = $(TCC)" .. thread_safe, {plain = true})
  58. io.replace("Makefile.msc", "RCC = $(RCC) -DSQLITE_TEMP_STORE=1", "RCC = $(RCC) -DSQLITE_HAS_CODEC" .. rtcc_include .. temp_store, {plain = true})
  59. io.replace("Makefile.msc", "RCC = $(RCC) -DSQLITE_THREADSAFE=1", "RCC = $(RCC)" .. thread_safe, {plain = true})
  60. import("package.tools.nmake")
  61. local envs = nmake.buildenvs(package)
  62. envs.NO_TCL = 1
  63. envs.SESSION = 0
  64. envs.SQLITE3DLL = "sqlcipher.dll"
  65. envs.SQLITE3LIB = "sqlcipher.lib"
  66. envs.SQLITE3EXE = "sqlcipher.exe"
  67. envs.SQLITE3EXEPDB = "/pdb:sqlcipher.pdb"
  68. envs.LTLIBS = "advapi32.lib user32.lib ws2_32.lib crypt32.lib wsock32.lib libcrypto.lib libssl.lib"
  69. envs.LTLIBPATHS = libpaths
  70. envs.PLATFORM = package:arch()
  71. nmake.build(package, {"-f", "Makefile.msc"}, {envs = envs})
  72. os.cp("sqlcipher.dll", package:installdir("bin"))
  73. os.cp("sqlcipher.pdb", package:installdir("bin"))
  74. os.cp("sqlcipher.exe", package:installdir("bin"))
  75. os.cp("sqlcipher.lib", package:installdir("lib"))
  76. os.cp("sqlite3.h", package:installdir("include"))
  77. os.cp("sqlite3ext.h", package:installdir("include"))
  78. end)
  79. on_install("linux", "macosx", "iphoneos", "cross", function (package)
  80. local make_args = {}
  81. local packagedeps = {}
  82. if package:version():ge("4.7.0") then
  83. if package:config("temp_store") ~= "0" then
  84. table.insert(make_args, "--with-tempstore=yes")
  85. end
  86. if package:config("threadsafe") == "0" then
  87. table.insert(make_args, "--disable-threadsafe")
  88. end
  89. if package:config("encrypt") then
  90. if is_plat("iphoneos") then
  91. table.insert(make_args, [[CFLAGS="-DSQLITE_HAS_CODEC -DSQLITE_EXTRA_INIT=sqlcipher_extra_init -DSQLITE_EXTRA_SHUTDOWN=sqlcipher_extra_shutdown -DSQLCIPHER_CRYPTO_CC"]])
  92. else
  93. table.insert(make_args, [[CFLAGS="-DSQLITE_HAS_CODEC -DSQLITE_EXTRA_INIT=sqlcipher_extra_init -DSQLITE_EXTRA_SHUTDOWN=sqlcipher_extra_shutdown -DSQLCIPHER_CRYPTO_OPENSSL"]])
  94. table.insert(packagedeps, "openssl3")
  95. end
  96. end
  97. else
  98. table.insert(make_args, "--with-crypto-lib=none")
  99. end
  100. os.vrunv("./configure", make_args)
  101. import("package.tools.make").build(package, {"sqlite3.c"}, {packagedeps = packagedeps})
  102. local configs = {}
  103. if package:config("shared") then
  104. configs.kind = "shared"
  105. end
  106. configs.encrypt = package:config("encrypt")
  107. configs.threadsafe = threadsafe
  108. configs.temp_store = temp_store
  109. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  110. import("package.tools.xmake").install(package, configs)
  111. end)
  112. on_test(function (package)
  113. assert(package:has_cfuncs("sqlite3_open_v2", {includes = "sqlite3.h"}))
  114. end)