xmake.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package("reflect-cpp")
  2. set_homepage("https://github.com/getml/reflect-cpp")
  3. set_description("A C++20 library for fast serialization, deserialization and validation using reflection. Supports JSON, BSON, CBOR, flexbuffers, msgpack, TOML, XML, YAML / msgpack.org[C++20]")
  4. set_license("MIT")
  5. add_urls("https://github.com/getml/reflect-cpp/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/getml/reflect-cpp.git", {submodules = false})
  7. add_versions("v0.16.0", "a84d94dbd353d788926d6e54507b44c046863f7bc4ecb35afe0338374a68a77d")
  8. add_versions("v0.14.1", "639aec9d33025703a58d32c231ab1ab474c0cc4fb0ff90eadcaffb49271c41cd")
  9. add_versions("v0.14.0", "ea92a2460a71184b7d4fa4e9baad9910efad092df78b114459a7d6b0ee558d3c")
  10. add_versions("v0.13.0", "a7a31832fe8bbaa7f7299da46dfd4ccc8b99a13242e16a1d93f8669de1fca9c6")
  11. add_versions("v0.12.0", "13d448dd5eaee13ecb7ab5cb61cb263c7111ba75230503adc823a888f68e1eaa")
  12. add_versions("v0.11.1", "e45f112fb3f14507a4aa53b99ae2d4ab6a4e7b2d5f04dd06fec00bf7faa7bbdc")
  13. add_versions("v0.10.0", "d2c8876d993ddc8c57c5804e767786bdb46a2bdf1a6cd81f4b14f57b1552dfd7")
  14. add_patches("0.16.0", "patches/0.16.0/cmake.patch", "1b2a6e0ed81dd0bd373bd1daaf52010de965f3829e5e19406c53e8ebf0a5b9fc")
  15. add_patches("0.11.1", "patches/0.11.1/cmake.patch", "a43ae2c6de455054ab860adfb309da7bd376c31c493c8bab0ebe07aae0805205")
  16. add_patches("0.10.0", "patches/0.10.0/cmake.patch", "b8929c0a13bd4045cbdeea0127e08a784e2dc8c43209ca9f056fff4a3ab5c4d3")
  17. add_configs("bson", {description = "Enable Bson Support.", default = false, type = "boolean", readonly = true})
  18. add_configs("yyjson", {description = "Enable yyjson Support.", default = true, type = "boolean"})
  19. add_configs("cbor", {description = "Enable Cbor Support.", default = false, type = "boolean"})
  20. add_configs("flatbuffers", {description = "Enable Flexbuffers Support.", default = false, type = "boolean"})
  21. add_configs("msgpack", {description = "Enable Msgpack Support.", default = false, type = "boolean"})
  22. add_configs("xml", {description = "Enable Xml Support.", default = false, type = "boolean"})
  23. add_configs("toml", {description = "Enable Toml Support.", default = false, type = "boolean"})
  24. add_configs("yaml", {description = "Enable Yaml Support.", default = false, type = "boolean"})
  25. add_configs("ubjson", {description = "Enable UBJSON Support.", default = false, type = "boolean"})
  26. if is_plat("windows") then
  27. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  28. end
  29. on_check(function (package)
  30. if package:is_plat("windows") then
  31. local vs = package:toolchain("msvc"):config("vs")
  32. assert(vs and tonumber(vs) >= 2022, "package(reflect-cpp): need vs >= 2022")
  33. else
  34. assert(package:check_cxxsnippets({test = [[
  35. #include <ranges>
  36. #include <source_location>
  37. #include <iostream>
  38. void test() {
  39. constexpr std::string_view message = "Hello, C++20!";
  40. for (char c : std::views::filter(message, [](char c) { return std::islower(c); }))
  41. std::cout << std::source_location::current().line() << ": " << c << '\n';
  42. }
  43. ]]}, {configs = {languages = "c++20"}}), "package(reflect-cpp) Require at least C++20.")
  44. end
  45. end)
  46. on_load(function (package)
  47. if package:config("yyjson") then
  48. package:add("deps", "yyjson")
  49. end
  50. if package:config("cbor") then
  51. package:add("deps", "tinycbor")
  52. end
  53. if package:config("flatbuffers") then
  54. package:add("deps", "flatbuffers")
  55. end
  56. if package:config("msgpack") then
  57. package:add("deps", "msgpack-c")
  58. end
  59. if package:config("xml") then
  60. package:add("deps", "pugixml")
  61. end
  62. if package:config("toml") then
  63. package:add("deps", "toml++")
  64. end
  65. if package:config("yaml") then
  66. package:add("deps", "yaml-cpp")
  67. end
  68. if package:config("ubjson") then
  69. package:add("deps", "jsoncons")
  70. end
  71. local version = package:version()
  72. if version then
  73. if version:lt("0.13.0") then
  74. package:set("kind", "library", {headeronly = true})
  75. end
  76. if version:ge("0.11.1") then
  77. package:add("deps", "ctre", {configs = {cmake = true}})
  78. if version:eq("0.11.1") then
  79. package:add("defines", "REFLECTCPP_NO_BUNDLED_DEPENDENCIES")
  80. end
  81. end
  82. end
  83. if package:gitref() or version:lt("0.11.1") or version:ge("0.13.0") then
  84. package:add("deps", "cmake")
  85. end
  86. end)
  87. on_install(function (package)
  88. local version = package:version()
  89. if package:gitref() or version:lt("0.11.1") or version:ge("0.13.0") then
  90. local configs = {
  91. "-DREFLECTCPP_USE_BUNDLED_DEPENDENCIES=OFF",
  92. "-DREFLECTCPP_USE_VCPKG=OFF",
  93. }
  94. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  95. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  96. table.insert(configs, "-DREFLECTCPP_BSON=" .. (package:config("bson") and "ON" or "OFF"))
  97. table.insert(configs, "-DREFLECTCPP_CBOR=" .. (package:config("cbor") and "ON" or "OFF"))
  98. table.insert(configs, "-DREFLECTCPP_FLEXBUFFERS=" .. (package:config("flatbuffers") and "ON" or "OFF"))
  99. table.insert(configs, "-DREFLECTCPP_MSGPACK=" .. (package:config("msgpack") and "ON" or "OFF"))
  100. table.insert(configs, "-DREFLECTCPP_XML=" .. (package:config("xml") and "ON" or "OFF"))
  101. table.insert(configs, "-DREFLECTCPP_TOML=" .. (package:config("toml") and "ON" or "OFF"))
  102. table.insert(configs, "-DREFLECTCPP_UBJSON=" .. (package:config("ubjson") and "ON" or "OFF"))
  103. table.insert(configs, "-DREFLECTCPP_YAML=" .. (package:config("yaml") and "ON" or "OFF"))
  104. import("package.tools.cmake").install(package, configs)
  105. else
  106. os.rm("include/thirdparty")
  107. os.cp("include", package:installdir())
  108. end
  109. end)
  110. on_test(function (package)
  111. assert(package:check_cxxsnippets({test = [[
  112. #include <rfl/json.hpp>
  113. #include <rfl.hpp>
  114. struct Person {
  115. std::string first_name;
  116. std::string last_name;
  117. int age;
  118. };
  119. const auto homer = Person{.first_name = "Homer",
  120. .last_name = "Simpson",
  121. .age = 45};
  122. void test() {
  123. const std::string json_string = rfl::json::write(homer);
  124. auto homer2 = rfl::json::read<Person>(json_string).value();
  125. }
  126. ]]}, {configs = {languages = "c++20"}}))
  127. if package:config("msgpack") then
  128. assert(package:check_cxxsnippets({test = [[
  129. #include <rfl/msgpack.hpp>
  130. #include <rfl.hpp>
  131. struct Person {
  132. std::string first_name;
  133. std::string last_name;
  134. int age;
  135. };
  136. const auto homer = Person{.first_name = "Homer",
  137. .last_name = "Simpson",
  138. .age = 45};
  139. void test() {
  140. std::vector<char> msgpack_str_vec = rfl::msgpack::write(homer);
  141. auto homer2 = rfl::msgpack::read<Person>(msgpack_str_vec).value();
  142. }
  143. ]]}, {configs = {languages = "c++20"}}))
  144. end
  145. end)