-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathgz-math7.rb
99 lines (90 loc) · 3.12 KB
/
gz-math7.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class GzMath7 < Formula
desc "Math API for robotic applications"
homepage "https://gazebosim.org"
url "https://osrf-distributions.s3.amazonaws.com/gz-math/releases/gz-math-7.5.2.tar.bz2"
sha256 "2451435f601f1adc8fdb3580e3b55bba951822dd85dcddcc8bae4fe132587803"
license "Apache-2.0"
head "https://github.com/gazebosim/gz-math.git", branch: "gz-math7"
bottle do
root_url "https://osrf-distributions.s3.amazonaws.com/bottles-simulation"
sha256 cellar: :any, sonoma: "0fa6e82a5357dc759b6a04f945ef33131cc1362570fc852d3de50292dac50877"
sha256 cellar: :any, ventura: "627e2fd4005571a016896ad36953613006b8f00c96bb16254e97a0123c9f88bc"
end
depends_on "cmake" => :build
depends_on "doxygen" => :build
depends_on "pybind11" => :build
depends_on "[email protected]" => [:build, :test]
depends_on "[email protected]" => [:build, :test]
depends_on "pkgconf" => :test
depends_on "eigen"
depends_on "gz-cmake3"
depends_on "gz-utils2"
depends_on "ruby"
def pythons
deps.map(&:to_formula)
.select { |f| f.name.match?(/^python@3\.\d+$/) }
end
def python_cmake_arg(python = Formula["[email protected]"])
"-DPython3_EXECUTABLE=#{python.opt_libexec}/bin/python"
end
def install
cmake_args = std_cmake_args
cmake_args << "-DBUILD_TESTING=OFF"
cmake_args << "-DCMAKE_INSTALL_RPATH=#{rpath}"
# first build without python bindings
mkdir "build" do
system "cmake", "..", *cmake_args, "-DSKIP_PYBIND11=ON"
system "make", "install"
end
# now build only the python bindings
pythons.each do |python|
# remove @ from formula name
python_name = python.name.tr("@", "")
mkdir "build_#{python_name}" do
system "cmake", "../src/python_pybind11", *cmake_args, python_cmake_arg(python)
system "make", "install"
(lib/"#{python_name}/site-packages").install Dir[lib/"python/*"]
rmdir prefix/"lib/python"
end
end
end
test do
(testpath/"test.cpp").write <<-EOS
#include "gz/math/SignalStats.hh"
int main() {
gz::math::SignalMean mean;
mean.InsertData(1.0);
mean.InsertData(-1.0);
return static_cast<int>(mean.Value());
}
EOS
(testpath/"CMakeLists.txt").write <<-EOS
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
find_package(gz-math7 QUIET REQUIRED)
add_executable(test_cmake test.cpp)
target_link_libraries(test_cmake gz-math7::gz-math7)
EOS
system "pkg-config", "gz-math7"
cflags = `pkg-config --cflags gz-math7`.split
ldflags = `pkg-config --libs gz-math7`.split
system ENV.cc, "test.cpp",
*cflags,
*ldflags,
"-lc++",
"-o", "test"
system "./test"
# test building with cmake
mkdir "build" do
system "cmake", ".."
system "make"
system "./test_cmake"
end
# check for Xcode frameworks in bottle
cmd_not_grep_xcode = "! grep -rnI 'Applications[/]Xcode' #{prefix}"
system cmd_not_grep_xcode
# check python import
pythons.each do |python|
system python.opt_libexec/"bin/python", "-c", "import gz.math7"
end
end
end