Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catboostmodel-cpp: Add with-static option #119

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions Formula/catboostmodel-cpp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class CatboostmodelCpp < Formula
sha256 cellar: :any_skip_relocation, x86_64_linux: "b7a291af06644fb0c3243484fa2dfab06b433387473ef45c2f7e475f8c877b03"
end

option "with-static", "Also install the static library"

depends_on "cmake" => :build
depends_on "conan@1" => :build
depends_on "ninja" => :build
Expand All @@ -51,16 +53,21 @@ def install

args = [
"-DCATBOOST_COMPONENTS=libs",
"-DHAVE_CUDA=NO",
"-DHAVE_CUDA=no",
"-DCMAKE_POSITION_INDEPENDENT_CODE=On",
"-DCMAKE_TOOLCHAIN_FILE=#{buildpath}/build/toolchains/clang.toolchain",
]

targets = ["catboostmodel"]
targets << "catboostmodel_static" if build.with?("static")

cmakepath = buildpath/"cmake-build"
system "cmake", "-S", ".", "-B", cmakepath, "-G", "Ninja", *args, *std_cmake_args
system "ninja", "-C", cmakepath, "catboostmodel"
system "ninja", "-C", cmakepath, *targets

lib.install cmakepath/"catboost/libs/model_interface/libcatboostmodel.#{OS.mac? ? "dylib" : "so"}"
lib.install Dir[cmakepath/"catboost/libs/model_interface/static/*.a"] if build.with?("static")

%w[c_api.h wrapped_calcer.h].each do |header|
(include/"catboost/model_interface").install Dir[buildpath/"catboost/libs/model_interface/#{header}"]
end
Expand All @@ -81,5 +88,17 @@ def install
EOS
system ENV.cxx, testpath/"test.cpp", "-std=c++1y", "-L#{lib}", "-lcatboostmodel", "-o", testpath/"test"
resource("model.cbm").stage { system testpath/"test" }

if build.with?("static")
libs = [
lib/"libcatboostmodel_static.global.a",
lib/"libcatboostmodel_static.a",
]

libs += %w[-lpthread -ldl] if OS.linux?

system ENV.cxx, testpath/"test.cpp", "-std=c++1y", *libs, "-o", testpath/"test_static"
resource("model.cbm").stage { system testpath/"test_static" }
end
end
end