package An official xmake package repository https://xrepo.xmake.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.4 KiB

4 years ago
package("jsoncpp")
4 years ago
set_homepage("https://github.com/open-source-parsers/jsoncpp/wiki")
set_description("A C++ library for interacting with JSON.")
4 years ago
4 years ago
set_urls("https://github.com/open-source-parsers/jsoncpp/archive/$(version).zip")
4 years ago
4 years ago
add_versions("1.9.4", "6da6cdc026fe042599d9fce7b06ff2c128e8dd6b8b751fca91eb022bce310880")
4 years ago
4 years ago
add_deps("cmake")
4 years ago
4 years ago
on_install("linux", "macosx", "android", "iphoneos", "windows", "mingw", "cross", function(package)
local configs = {"-DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF", "-DJSONCPP_WITH_TESTS=OFF", "-DJSONCPP_WITH_EXAMPLE=OFF", "-DBUILD_OBJECT_LIBS=OFF"}
4 years ago
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DBUILD_STATIC_LIBS=" .. (package:config("shared") and "OFF" or "ON"))
4 years ago
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
if package:config("pic") ~= false then
table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
end
4 years ago
import("package.tools.cmake").install(package, configs)
end)
4 years ago
4 years ago
on_test(function(package)
assert(package:check_cxxsnippets({
test = [[
#include <iostream>
#include <assert.h>
static void test() {
const std::string rawJson = R"({"Age": 20, "Name": "colin"})";
const auto rawJsonLength = static_cast<int>(rawJson.length());
constexpr bool shouldUseOldWay = false;
JSONCPP_STRING err;
Json::Value root;
if (shouldUseOldWay) {
Json::Reader reader;
reader.parse(rawJson, root);
} else {
Json::CharReaderBuilder builder;
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
if (!reader->parse(rawJson.c_str(), rawJson.c_str() + rawJsonLength, &root,
&err)) ;
}
const std::string name = root["Name"].asString();
const int age = root["Age"].asInt();
assert(name == "colin");
assert(age == 20);
4 years ago
}
4 years ago
]]
}, {configs = {languages = "c++11"}, includes = "json/json.h"}))
end)