xmake.lua 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package("jsoncons")
  2. set_kind("library", {headeronly = true})
  3. set_homepage("https://danielaparker.github.io/jsoncons/")
  4. set_description("A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON")
  5. set_license("BSL-1.0")
  6. set_urls("https://github.com/danielaparker/jsoncons/archive/$(version).zip",
  7. "https://github.com/danielaparker/jsoncons.git")
  8. add_versions("v0.176.0", "71a618219b62a2bbcc46efac98696574581e343cd98ef33e5e1bd8db182005d9")
  9. add_versions("v0.170.2", "81ac768eecb8cf2613a09a9d081294895d7afd294b841166b4e1378f0acfdd6e")
  10. add_versions("v0.158.0", "7ad7cc0e9c74df495dd16b818758ec2e2a5b7fef8f1852841087fd5e8bb6a6cb")
  11. on_install(function (package)
  12. os.cp("include", package:installdir())
  13. end)
  14. on_test(function (package)
  15. assert(package:check_cxxsnippets({test = [[
  16. #include <iostream>
  17. #include <string>
  18. using namespace jsoncons;
  19. std::string data = R"(
  20. {
  21. "application": "hiking",
  22. "reputons":
  23. [
  24. {
  25. "rater": "HikingAsylum",
  26. "assertion": "advanced",
  27. "rated": "Marilyn C",
  28. "rating": 0.90,
  29. "generated": 1514862245
  30. }
  31. ]
  32. }
  33. )";
  34. void test() {
  35. json j = json::parse(data);
  36. std::cout << "(1) " << std::boolalpha << j.contains("reputons") << "\n\n";
  37. const json &v = j["reputons"];
  38. for (const auto &item : v.array_range()) {
  39. // Access rated as string and rating as double
  40. std::cout << item["rated"].as<std::string>() << ", "
  41. << item["rating"].as<double>() << "\n";
  42. }
  43. std::cout << "\n";
  44. std::cout << "(3)\n";
  45. json result = jsonpath::json_query(j, "$..rated");
  46. std::cout << pretty_print(result) << "\n\n";
  47. std::cout << "(4)\n" << pretty_print(j) << "\n\n";
  48. }
  49. ]]}, {configs = {languages = "c++11"}, includes = {"jsoncons/json.hpp", "jsoncons_ext/jsonpath/jsonpath.hpp"}}))
  50. end)