xmake.lua 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package("soci")
  2. set_homepage("http://soci.sourceforge.net/")
  3. set_description("Official repository of the SOCI - The C++ Database Access Library")
  4. set_license("BSL-1.0")
  5. add_urls("https://github.com/SOCI/soci/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/SOCI/soci.git")
  7. add_versions("v4.0.3", "4b1ff9c8545c5d802fbe06ee6cd2886630e5c03bf740e269bb625b45cf934928")
  8. add_patches("v4.0.3", path.join(os.scriptdir(), "patches", "v4.0.3", "cmake_policy_fix.patch"), "6d8746c3ae39edf1b750d47dcfde97dedbe4211c2563481e877d36a9dccc556a")
  9. local backends = {
  10. "empty",
  11. "sqlite3",
  12. "db2",
  13. "odbc",
  14. "oracle",
  15. "firebird",
  16. "mysql",
  17. "postgresql",
  18. }
  19. for _, backend in ipairs(backends) do
  20. add_configs(backend, {description = "Build " .. backend .. " backend", default = false, type = "boolean"})
  21. end
  22. add_configs("boost", {description = "Enable boost integration", default = false, type = "boolean"})
  23. add_configs("visibility", {description = "Enable hiding private symbol using ELF visibility if supported by the platform", default = true, type = "boolean"})
  24. add_deps("cmake")
  25. on_load(function (package)
  26. for _, pkg in ipairs({"sqlite3", "mysql", "postgresql"}) do
  27. if package:config(pkg) then
  28. package:add("deps", pkg)
  29. end
  30. end
  31. if package:config("boost") then
  32. package:add("deps", "boost")
  33. end
  34. end)
  35. on_install(function (package)
  36. local configs = {"-DSOCI_TESTS=OFF", "-DSOCI_CXX11=ON"}
  37. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  38. table.insert(configs, "-DSOCI_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  39. table.insert(configs, "-DSOCI_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  40. table.insert(configs, "-DSOCI_LTO=" .. (package:config("lto") and "ON" or "OFF"))
  41. table.insert(configs, "-DSOCI_ASAN=" .. (package:config("asan") and "ON" or "OFF"))
  42. table.insert(configs, "-DSOCI_VISIBILITY=" .. (package:config("visibility") and "ON" or "OFF"))
  43. table.insert(configs, "-DSOCI_EMPTY=" .. (package:config("empty") and "ON" or "OFF"))
  44. for name, enabled in pairs(package:configs()) do
  45. if (not package:extraconf("configs", name, "builtin")) and (name ~= "empty") then
  46. table.insert(configs, "-DWITH_" .. name:upper() .. "=" .. (package:config(name) and "ON" or "OFF"))
  47. end
  48. end
  49. import("package.tools.cmake").install(package, configs)
  50. end)
  51. on_test(function (package)
  52. local includes = {"soci/soci.h"}
  53. for _, pkg in ipairs(backends) do
  54. if package:config(pkg) then
  55. table.insert(includes, "soci/" .. pkg .. "/soci-" .. pkg .. ".h")
  56. end
  57. end
  58. assert(package:check_cxxsnippets({test = [[
  59. void test() {
  60. soci::session sql("connectString");
  61. }
  62. ]]}, {configs = {languages = "c++14", defines = package:config("boost") and "SOCI_USE_BOOST" or {}}, includes = includes}))
  63. end)