homebrew-core/Formula/msgpack-cxx.rb

62 lines
1.8 KiB
Ruby

class MsgpackCxx < Formula
desc "MessagePack implementation for C++ / msgpack.org[C++]"
homepage "https://msgpack.org/"
url "https://github.com/msgpack/msgpack-c/releases/download/cpp-4.1.2/msgpack-cxx-4.1.2.tar.gz"
sha256 "eeddd7faeacbc12e10052bd1e3ec78bd26c69bfbbea9f9264c7ffce9b1ede7b1"
license "BSL-1.0"
head "https://github.com/msgpack/msgpack-c.git", branch: "cpp_master"
livecheck do
url :stable
regex(/^cpp[._-]v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any_skip_relocation, all: "d6ac98d8b1eb0b0f06c997d2c34ebabe2b04eceb099ab3fe6e7d977f01189671"
end
depends_on "cmake" => :build
depends_on "boost"
def install
system "cmake", ".", *std_cmake_args
system "make", "install"
end
test do
# Reference: https://github.com/msgpack/msgpack-c/blob/cpp_master/QUICKSTART-CPP.md
(testpath/"test.cpp").write <<~EOS
#include <msgpack.hpp>
#include <vector>
#include <string>
#include <iostream>
int main(void) {
// serializes this object.
std::vector<std::string> vec;
vec.push_back("Hello");
vec.push_back("MessagePack");
// serialize it into simple buffer.
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, vec);
// deserialize it.
msgpack::object_handle oh =
msgpack::unpack(sbuf.data(), sbuf.size());
// print the deserialized object.
msgpack::object obj = oh.get();
std::cout << obj << std::endl; //=> ["Hello", "MessagePack"]
// convert it into statically typed object.
std::vector<std::string> rvec;
obj.convert(rvec);
}
EOS
system ENV.cxx, "-o", "test", "test.cpp", "-I#{include}"
assert_equal "[\"Hello\",\"MessagePack\"]\n", `./test`
end
end