homebrew-core/Formula/spdlog.rb

66 lines
2.1 KiB
Ruby

class Spdlog < Formula
desc "Super fast C++ logging library"
homepage "https://github.com/gabime/spdlog"
url "https://github.com/gabime/spdlog/archive/v1.8.1.tar.gz"
sha256 "5197b3147cfcfaa67dd564db7b878e4a4b3d9f3443801722b3915cdeced656cb"
license "MIT"
head "https://github.com/gabime/spdlog.git", branch: "v1.x"
bottle do
cellar :any
sha256 "96c1aa7617928a308908b830a8b79f1d3e7d5aa8f5b41aebe94ebf7f1c09d4cd" => :big_sur
sha256 "3599f833d5d9d0c6542c7782deffa7d2788e14ddf68abf55c1fc39eb80254b18" => :catalina
sha256 "f8382a1e47f1d92ff14311b0c0706b8684aafbbe0794c6d51dec6fedc12364eb" => :mojave
sha256 "ac0a305a6b391825ab51324b9dab2bc3acb6135ec3604bc01f561b403c742042" => :high_sierra
end
depends_on "cmake" => :build
depends_on "fmt"
def install
ENV.cxx11
inreplace "include/spdlog/tweakme.h", "// #define SPDLOG_FMT_EXTERNAL", "#define SPDLOG_FMT_EXTERNAL"
mkdir "spdlog-build" do
args = std_cmake_args + %W[
-Dpkg_config_libdir=#{lib}
-DSPDLOG_BUILD_BENCH=OFF
-DSPDLOG_BUILD_TESTS=OFF
-DSPDLOG_FMT_EXTERNAL=ON
]
system "cmake", "..", "-DSPDLOG_BUILD_SHARED=ON", *args
system "make", "install"
system "make", "clean"
system "cmake", "..", "-DSPDLOG_BUILD_SHARED=OFF", *args
system "make"
lib.install "libspdlog.a"
end
end
test do
(testpath/"test.cpp").write <<~EOS
#include "spdlog/sinks/basic_file_sink.h"
#include <iostream>
#include <memory>
int main()
{
try {
auto console = spdlog::basic_logger_mt("basic_logger", "#{testpath}/basic-log.txt");
console->info("Test");
}
catch (const spdlog::spdlog_ex &ex)
{
std::cout << "Log init failed: " << ex.what() << std::endl;
return 1;
}
}
EOS
system ENV.cxx, "-std=c++11", "test.cpp", "-I#{include}", "-L#{Formula["fmt"].opt_lib}", "-lfmt", "-o", "test"
system "./test"
assert_predicate testpath/"basic-log.txt", :exist?
assert_match "Test", (testpath/"basic-log.txt").read
end
end