homebrew-core/Formula/cereal.rb

75 lines
1.8 KiB
Ruby

class Cereal < Formula
desc "C++11 library for serialization"
homepage "https://uscilab.github.io/cereal/"
url "https://github.com/USCiLab/cereal/archive/v1.3.2.tar.gz"
sha256 "16a7ad9b31ba5880dac55d62b5d6f243c3ebc8d46a3514149e56b5e7ea81f85f"
license "BSD-3-Clause"
head "https://github.com/USCiLab/cereal.git", branch: "develop"
bottle do
sha256 cellar: :any_skip_relocation, all: "13b3cb91e465c3857b307912e79bc1531167deccf9a2823d1c6e69abb8833792"
end
depends_on "cmake" => :build
def install
system "cmake", ".", "-DJUST_INSTALL_CEREAL=ON", *std_cmake_args
system "make", "install"
end
test do
(testpath/"test.cpp").write <<~EOS
#include <cereal/types/unordered_map.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/archives/binary.hpp>
#include <fstream>
struct MyRecord
{
uint8_t x, y;
float z;
template <class Archive>
void serialize( Archive & ar )
{
ar( x, y, z );
}
};
struct SomeData
{
int32_t id;
std::shared_ptr<std::unordered_map<uint32_t, MyRecord>> data;
template <class Archive>
void save( Archive & ar ) const
{
ar( data );
}
template <class Archive>
void load( Archive & ar )
{
static int32_t idGen = 0;
id = idGen++;
ar( data );
}
};
int main()
{
std::ofstream os("out.cereal", std::ios::binary);
cereal::BinaryOutputArchive archive( os );
SomeData myData;
archive( myData );
return 0;
}
EOS
system ENV.cxx, "test.cpp", "-std=c++11", "-I#{include}", "-o", "test"
system "./test"
assert_predicate testpath/"out.cereal", :exist?
end
end