xmake.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package("jsoncpp")
  2. set_homepage("https://github.com/open-source-parsers/jsoncpp/wiki")
  3. set_description("A C++ library for interacting with JSON.")
  4. set_urls("https://github.com/open-source-parsers/jsoncpp/archive/$(version).zip")
  5. add_versions("1.9.4", "6da6cdc026fe042599d9fce7b06ff2c128e8dd6b8b751fca91eb022bce310880")
  6. add_includedirs("include")
  7. add_deps("cmake")
  8. on_install("linux", "macosx", "iphoneos", "android", function(package)
  9. local configs = {}
  10. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  11. table.insert(configs, "-DDBUILD_STATIC_LIBS=" .. (package:config("static") and "ON" or "OFF"))
  12. table.insert(configs, "-DDCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  13. import("package.tools.cmake").install(package, configs)
  14. end)
  15. on_test(function(package)
  16. assert(package:check_cxxsnippets({
  17. test = [[
  18. #include <iostream>
  19. #include <assert.h>
  20. static void test() {
  21. const std::string rawJson = R"({"Age": 20, "Name": "colin"})";
  22. const auto rawJsonLength = static_cast<int>(rawJson.length());
  23. constexpr bool shouldUseOldWay = false;
  24. JSONCPP_STRING err;
  25. Json::Value root;
  26. if (shouldUseOldWay) {
  27. Json::Reader reader;
  28. reader.parse(rawJson, root);
  29. } else {
  30. Json::CharReaderBuilder builder;
  31. const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
  32. if (!reader->parse(rawJson.c_str(), rawJson.c_str() + rawJsonLength, &root,
  33. &err)) ;
  34. }
  35. const std::string name = root["Name"].asString();
  36. const int age = root["Age"].asInt();
  37. assert(name == "colin");
  38. assert(age == 20);
  39. }
  40. ]]
  41. }, {
  42. configs = {
  43. languages = "c++11"
  44. },
  45. includes = "json/json.h"
  46. }))
  47. end)