homebrew-core/Formula/clickhouse-cpp.rb

97 lines
3.4 KiB
Ruby

class ClickhouseCpp < Formula
desc "C++ client library for ClickHouse"
homepage "https://github.com/ClickHouse/clickhouse-cpp#readme"
url "https://github.com/ClickHouse/clickhouse-cpp/archive/refs/tags/v2.1.0.tar.gz"
sha256 "d724df55f9d4e13b3028355141c6af08fc7f2cd184d8b531e57f0d4f4a376db9"
license "Apache-2.0"
head "https://github.com/ClickHouse/clickhouse-cpp.git", branch: "master"
bottle do
sha256 cellar: :any, arm64_monterey: "472399e540b1eeefca43801ebb2512ce972b0e70795a697658a0aa58c36134df"
sha256 cellar: :any, arm64_big_sur: "2324d8e0318eb0e64c3bca66865fb2e71e6a0db8432e87bb46c26b9b5d04655f"
sha256 cellar: :any, monterey: "6a99a0ea829244bfcff82932a1ad99613593f7fa38fc77488a5ae0dd7329bd63"
sha256 cellar: :any, big_sur: "e1e9aa84d8828813fd7162d66cab5b44d3c1c88ed5b1836f948be52a54a7c022"
sha256 cellar: :any, catalina: "5f7c0eba509be90e77fa801b0da2fcc4b1ec4b7f6c45048702cfeb41a1e24b70"
sha256 cellar: :any_skip_relocation, x86_64_linux: "a72a1585ce0b441de3cc58db9a12e2695aaabcb915b9dc34dc0473133cc83e86"
end
depends_on "cmake" => [:build, :test]
depends_on "abseil"
depends_on "openssl@1.1"
on_linux do
depends_on "gcc"
end
fails_with gcc: "5"
fails_with gcc: "6"
def install
system "cmake", "-S", ".", "-B", "build",
"-DWITH_OPENSSL=ON", "-DOPENSSL_ROOT_DIR=#{Formula["openssl@1.1"].opt_prefix}", *std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
end
test do
(testpath/"main.cpp").write <<~EOS
#include <clickhouse/client.h>
#include <exception>
#include <cstdio>
#include <cstdlib>
int main(int argc, char* argv[])
{
int exit_code = EXIT_SUCCESS;
try
{
// Expecting a typical "failed to connect" error.
clickhouse::Client client(
clickhouse::ClientOptions()
.SetHost("example.com")
.SetSendRetries(1)
.SetRetryTimeout(std::chrono::seconds(1))
.SetTcpKeepAliveCount(1)
.SetTcpKeepAliveInterval(std::chrono::seconds(1))
);
}
catch (const std::exception& ex)
{
std::fprintf(stdout, "Exception: %s\\n", ex.what());
exit_code = EXIT_FAILURE;
}
catch (...)
{
std::fprintf(stdout, "Exception: unknown\\n");
exit_code = EXIT_FAILURE;
}
return exit_code;
}
EOS
(testpath/"CMakeLists.txt").write <<~EOS
project (clickhouse-cpp-test-client LANGUAGES CXX)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CLICKHOUSE_CPP_INCLUDE "#{include}")
find_library (CLICKHOUSE_CPP_LIB NAMES clickhouse-cpp-lib PATHS "#{lib}" REQUIRED NO_DEFAULT_PATH)
add_executable (test-client main.cpp)
target_include_directories (test-client PRIVATE ${CLICKHOUSE_CPP_INCLUDE})
target_link_libraries (test-client PRIVATE ${CLICKHOUSE_CPP_LIB})
target_compile_definitions (test-client PUBLIC WITH_OPENSSL)
EOS
system "cmake", "-S", testpath, "-B", (testpath/"build"), *std_cmake_args
system "cmake", "--build", (testpath/"build")
assert_match "Exception: fail to connect: ", shell_output(testpath/"build"/"test-client", 1)
end
end