|
| 1 | +class Sdformat16 < Formula |
| 2 | + desc "Simulation Description Format" |
| 3 | + homepage "http://sdformat.org" |
| 4 | + url "https://github.com/gazebosim/sdformat.git", branch: "main" |
| 5 | + version "15.999.999-0-20250428" |
| 6 | + license "Apache-2.0" |
| 7 | + |
| 8 | + head "https://github.com/gazebosim/sdformat.git", branch: "sdf16" |
| 9 | + |
| 10 | + depends_on "cmake" => [:build, :test] |
| 11 | + depends_on "pkgconf" => [:build, :test] |
| 12 | + depends_on "pybind11" => :build |
| 13 | + depends_on "[email protected]" => [:build, :test] |
| 14 | + depends_on "[email protected]" => [:build, :test] |
| 15 | + |
| 16 | + depends_on "doxygen" |
| 17 | + depends_on "gz-cmake5" |
| 18 | + depends_on "gz-math9" |
| 19 | + depends_on "gz-tools2" |
| 20 | + depends_on "gz-utils4" |
| 21 | + depends_on macos: :mojave # c++17 |
| 22 | + depends_on "tinyxml2" |
| 23 | + depends_on "urdfdom" |
| 24 | + |
| 25 | + def pythons |
| 26 | + deps.map(&:to_formula) |
| 27 | + .select { |f| f.name.match?(/^python@3\.\d+$/) } |
| 28 | + end |
| 29 | + |
| 30 | + def python_cmake_arg(python = Formula["[email protected]"]) |
| 31 | + "-DPython3_EXECUTABLE=#{python.opt_libexec}/bin/python" |
| 32 | + end |
| 33 | + |
| 34 | + def install |
| 35 | + cmake_args = std_cmake_args |
| 36 | + cmake_args << "-DBUILD_TESTING=Off" |
| 37 | + cmake_args << "-DCMAKE_INSTALL_RPATH=#{rpath}" |
| 38 | + |
| 39 | + # first build without python bindings |
| 40 | + mkdir "build" do |
| 41 | + system "cmake", "..", *cmake_args, "-DSKIP_PYBIND11=ON" |
| 42 | + system "make", "install" |
| 43 | + end |
| 44 | + |
| 45 | + # now build only the python bindings |
| 46 | + pythons.each do |python| |
| 47 | + # remove @ from formula name |
| 48 | + python_name = python.name.tr("@", "") |
| 49 | + mkdir "build_#{python_name}" do |
| 50 | + system "cmake", "../python", *cmake_args, python_cmake_arg(python) |
| 51 | + system "make", "install" |
| 52 | + (lib/"#{python_name}/site-packages").install Dir[lib/"python/*"] |
| 53 | + rmdir prefix/"lib/python" |
| 54 | + end |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + test do |
| 59 | + (testpath/"test.cpp").write <<-EOS |
| 60 | + #include <iostream> |
| 61 | + #include "sdf/sdf.hh" |
| 62 | + const std::string sdfString( |
| 63 | + "<sdf version='1.5'>" |
| 64 | + " <model name='example'>" |
| 65 | + " <link name='link'>" |
| 66 | + " <sensor type='gps' name='mysensor' />" |
| 67 | + " </link>" |
| 68 | + " </model>" |
| 69 | + "</sdf>"); |
| 70 | + int main() { |
| 71 | + sdf::SDF modelSDF; |
| 72 | + modelSDF.SetFromString(sdfString); |
| 73 | + std::cout << modelSDF.ToString() << std::endl; |
| 74 | + } |
| 75 | + EOS |
| 76 | + (testpath/"CMakeLists.txt").write <<-EOS |
| 77 | + cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) |
| 78 | + find_package(sdformat QUIET REQUIRED) |
| 79 | + add_executable(test_cmake test.cpp) |
| 80 | + target_link_libraries(test_cmake ${SDFormat_LIBRARIES}) |
| 81 | + EOS |
| 82 | + system "pkg-config", "sdformat" |
| 83 | + cflags = `pkg-config --cflags sdformat`.split |
| 84 | + system ENV.cc, "test.cpp", |
| 85 | + *cflags, |
| 86 | + "-L#{lib}", |
| 87 | + "-lsdformat", |
| 88 | + "-lc++", |
| 89 | + "-o", "test" |
| 90 | + system "./test" |
| 91 | + # test building with cmake |
| 92 | + mkdir "build" do |
| 93 | + system "cmake", ".." |
| 94 | + system "make" |
| 95 | + system "./test_cmake" |
| 96 | + end |
| 97 | + # check for Xcode frameworks in bottle |
| 98 | + cmd_not_grep_xcode = "! grep -rnI 'Applications[/]Xcode' #{prefix}" |
| 99 | + system cmd_not_grep_xcode |
| 100 | + # check python import |
| 101 | + pythons.each do |python| |
| 102 | + system python.opt_libexec/"bin/python", "-c", "import sdformat" |
| 103 | + end |
| 104 | + end |
| 105 | +end |
0 commit comments