xmake.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package("sqlgen")
  2. set_homepage("https://github.com/getml/sqlgen")
  3. set_description("sqlgen is an ORM and SQL query generator for C++-20, similar to Python's SQLAlchemy/SQLModel or Rust's Diesel.")
  4. set_license("MIT")
  5. add_urls("https://github.com/getml/sqlgen/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/getml/sqlgen.git")
  7. add_versions("v0.2.0", "c093036ebdf2aaf1003b2d1623713b97106ed43b1d39dc3d4f38e381f371799e")
  8. add_patches("0.2.0", "patches/0.2.0/cmake.patch", "e9819b9a8a2c8f8a5b6c553eac3bb10fc65856aa9af451f83e2dbf55ca6c66c0")
  9. add_deps("cmake", "reflect-cpp")
  10. add_configs("mysql", {description = "Enable MySQL Support", default = false, type = "boolean", readonly = true})
  11. add_configs("postgres", {description = "Enable PostgreSQL Support", default = true})
  12. add_configs("sqlite", {description = "Enable SQLite Support", default = true})
  13. if is_plat("windows") then
  14. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  15. end
  16. on_load(function (package)
  17. if package:config("mysql") then
  18. package:add("deps", "mariadb-connector-c")
  19. end
  20. if package:config("postgres") then
  21. package:add("deps", "libpq")
  22. end
  23. if package:config("sqlite") then
  24. package:add("deps", "sqlite3")
  25. end
  26. end)
  27. on_check(function (package)
  28. if package:config("postgres") then
  29. assert(not package:is_arch("arm64"), "package(%s) does not support arm64", package:name())
  30. end
  31. end)
  32. on_install("windows", "macosx", "linux", "bsd", function (package)
  33. local configs = {
  34. "-DSQLGEN_USE_VCPKG=OFF",
  35. }
  36. table.insert(configs, "-DSQLGEN_MYSQL=" .. (package:config("mysql") and "ON" or "OFF"))
  37. table.insert(configs, "-DSQLGEN_POSTGRES=" .. (package:config("postgres") and "ON" or "OFF"))
  38. table.insert(configs, "-DSQLGEN_SQLITE3=" .. (package:config("sqlite") and "ON" or "OFF"))
  39. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  40. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  41. import("package.tools.cmake").install(package, configs)
  42. end)
  43. on_test(function (package)
  44. if package:config("postgres") then
  45. assert(package:check_cxxsnippets({test = [[
  46. #include <sqlgen/postgres.hpp>
  47. const auto credentials = sqlgen::postgres::Credentials{
  48. .user = "username",
  49. .password = "password",
  50. .host = "localhost",
  51. .dbname = "mydb",
  52. .port = 5432
  53. };
  54. const auto conn = sqlgen::postgres::connect(credentials);
  55. ]]}, {configs = {languages = "c++20"}}))
  56. end
  57. if package:config("sqlite") then
  58. assert(package:check_cxxsnippets({test = [[
  59. #include <sqlgen/sqlite.hpp>
  60. struct User {
  61. std::string name;
  62. int age;
  63. };
  64. void test() {
  65. const auto conn = sqlgen::sqlite::connect("test.db");
  66. const auto user = User{.name = "John", .age = 30};
  67. sqlgen::write(conn, user);
  68. }
  69. ]]}, {configs = {languages = "c++20"}}))
  70. end
  71. if package:config("mysql") then
  72. assert(package:check_cxxsnippets({test = [[
  73. #include <sqlgen/mysql.hpp>
  74. const auto creds = sqlgen::mysql::Credentials{
  75. .host = "localhost",
  76. .user = "myuser",
  77. .password = "mypassword",
  78. .dbname = "mydatabase"
  79. };
  80. const auto conn = sqlgen::mysql::connect(creds);
  81. ]]}, {configs = {languages = "c++20"}}))
  82. end
  83. end)