-
Notifications
You must be signed in to change notification settings - Fork 75
/
sdformat15.rb
105 lines (96 loc) · 3.11 KB
/
sdformat15.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
100
101
102
103
104
105
class Sdformat15 < Formula
desc "Simulation Description Format"
homepage "http://sdformat.org"
url "https://github.com/gazebosim/sdformat.git", branch: "scpeters/build_python_bindings_separately"
version "15.0.0~pre1"
license "Apache-2.0"
head "https://github.com/gazebosim/sdformat.git", branch: "sdf15"
depends_on "cmake" => [:build, :test]
depends_on "pkg-config" => [:build, :test]
depends_on "pybind11" => :build
depends_on "[email protected]" => [:build, :test]
depends_on "[email protected]" => [:build, :test]
depends_on "doxygen"
depends_on "gz-cmake4"
depends_on "gz-math8"
depends_on "gz-tools2"
depends_on "gz-utils3"
depends_on macos: :mojave # c++17
depends_on "tinyxml2"
depends_on "urdfdom"
def pythons
deps.map(&:to_formula)
.select { |f| f.name.match?(/^python@3\.\d+$/) }
end
def python_cmake_arg(python = "[email protected]".to_formula)
"-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", "../python", *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 <iostream>
#include "sdf/sdf.hh"
const std::string sdfString(
"<sdf version='1.5'>"
" <model name='example'>"
" <link name='link'>"
" <sensor type='gps' name='mysensor' />"
" </link>"
" </model>"
"</sdf>");
int main() {
sdf::SDF modelSDF;
modelSDF.SetFromString(sdfString);
std::cout << modelSDF.ToString() << std::endl;
}
EOS
(testpath/"CMakeLists.txt").write <<-EOS
cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR)
find_package(sdformat15 QUIET REQUIRED)
add_executable(test_cmake test.cpp)
target_link_libraries(test_cmake ${SDFormat_LIBRARIES})
EOS
system "pkg-config", "sdformat15"
cflags = `pkg-config --cflags sdformat15`.split
system ENV.cc, "test.cpp",
*cflags,
"-L#{lib}",
"-lsdformat15",
"-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 sdformat15"
end
end
end