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.10.5.tar.gz"
sha256 "5daca6ca216495edf89d167f808d1d03c4a4d929cef7da5e10f135ae1540c7e4"
license "MIT"
head "https://github.com/nlohmann/json.git", branch: "develop"
bottle do
sha256 cellar: :any_skip_relocation, all: "6c7473b0acc64f87a1697bea4df7c439ee2c90ccec4343d7c95024cfec17a5e6"
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