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.1/msgpack-cxx-4.1.1.tar.gz"
sha256 "8115c5edcf20bc1408c798a6bdaec16c1e52b1c34859d4982a0fb03300438f0b"
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: "1092abf2f7f9541c0f2ae7d2189985daf5234132f6e9a1c530a0396d7f69bc5b"
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