homebrew-core/Formula/nlohmann-json.rb

50 lines
1.3 KiB
Ruby

class NlohmannJson < Formula
desc "JSON for modern C++"
homepage "https://github.com/nlohmann/json"
url "https://github.com/nlohmann/json/archive/v3.11.2.tar.gz"
sha256 "d69f9deb6a75e2580465c6c4c5111b89c4dc2fa94e3a85fcd2ffcd9a143d9273"
license "MIT"
head "https://github.com/nlohmann/json.git", branch: "develop"
bottle do
sha256 cellar: :any_skip_relocation, all: "9ca4704d40b8e80ae9405d98e64c89922ace4de66ededabe63b65d73d14d8bc8"
end
depends_on "cmake" => :build
def install
mkdir "build" do
system "cmake", "..", "-DJSON_BuildTests=OFF", "-DJSON_MultipleHeaders=ON", *std_cmake_args
system "make", "install"
end
end
test do
(testpath/"test.cc").write <<~EOS
#include <iostream>
#include <nlohmann/json.hpp>
using nlohmann::json;
int main() {
json j = {
{"pi", 3.141},
{"name", "Niels"},
{"list", {1, 0, 2}},
{"object", {
{"happy", true},
{"nothing", nullptr}
}}
};
std::cout << j << std::endl;
}
EOS
system ENV.cxx, "test.cc", "-I#{include}", "-std=c++11", "-o", "test"
std_output = <<~EOS
{"list":[1,0,2],"name":"Niels","object":{"happy":true,"nothing":null},"pi":3.141}
EOS
assert_match std_output, shell_output("./test")
end
end