jackett 0.22.1382
[Homebrew/homebrew-core.git] / Formula / c / cereal.rb
blobcd27a778754e1fd4e09b1698bca75823b72a4681
1 class Cereal < Formula
2   desc "C++11 library for serialization"
3   homepage "https://uscilab.github.io/cereal/"
4   url "https://github.com/USCiLab/cereal/archive/refs/tags/v1.3.2.tar.gz"
5   sha256 "16a7ad9b31ba5880dac55d62b5d6f243c3ebc8d46a3514149e56b5e7ea81f85f"
6   license "BSD-3-Clause"
7   head "https://github.com/USCiLab/cereal.git", branch: "develop"
9   bottle do
10     rebuild 1
11     sha256 cellar: :any_skip_relocation, all: "dd568ffbaa2689d64040eea49404b91b65a33657ea8a6567255fb738185c1199"
12   end
14   depends_on "cmake" => :build
16   def install
17     system "cmake", "-S", ".", "-B", "build", "-DJUST_INSTALL_CEREAL=ON", *std_cmake_args
18     system "cmake", "--build", "build"
19     system "cmake", "--install", "build"
20   end
22   test do
23     (testpath/"test.cpp").write <<~CPP
24       #include <cereal/types/unordered_map.hpp>
25       #include <cereal/types/memory.hpp>
26       #include <cereal/archives/binary.hpp>
27       #include <fstream>
29       struct MyRecord
30       {
31         uint8_t x, y;
32         float z;
34         template <class Archive>
35         void serialize( Archive & ar )
36         {
37           ar( x, y, z );
38         }
39       };
41       struct SomeData
42       {
43         int32_t id;
44         std::shared_ptr<std::unordered_map<uint32_t, MyRecord>> data;
46         template <class Archive>
47         void save( Archive & ar ) const
48         {
49           ar( data );
50         }
52         template <class Archive>
53         void load( Archive & ar )
54         {
55           static int32_t idGen = 0;
56           id = idGen++;
57           ar( data );
58         }
59       };
61       int main()
62       {
63         std::ofstream os("out.cereal", std::ios::binary);
64         cereal::BinaryOutputArchive archive( os );
66         SomeData myData;
67         archive( myData );
69         return 0;
70       }
71     CPP
72     system ENV.cxx, "test.cpp", "-std=c++11", "-I#{include}", "-o", "test"
73     system "./test"
74     assert_predicate testpath/"out.cereal", :exist?
75   end
76 end