|
| 1 | +class GzPhysics9 < Formula |
| 2 | + desc "Physics library for robotics applications" |
| 3 | + homepage "https://github.com/gazebosim/gz-physics" |
| 4 | + url "https://github.com/gazebosim/gz-physics.git", branch: "main" |
| 5 | + version "8.999.999-0-20250501" |
| 6 | + license "Apache-2.0" |
| 7 | + |
| 8 | + head "https://github.com/gazebosim/gz-physics.git", branch: "gz-physics9" |
| 9 | + |
| 10 | + depends_on "cmake" => [:build, :test] |
| 11 | + |
| 12 | + depends_on "bullet" |
| 13 | + depends_on "dartsim" |
| 14 | + depends_on "google-benchmark" |
| 15 | + depends_on "gz-cmake5" |
| 16 | + depends_on "gz-common7" |
| 17 | + depends_on "gz-math9" |
| 18 | + depends_on "gz-plugin4" |
| 19 | + depends_on "gz-utils4" |
| 20 | + depends_on macos: :mojave # c++17 |
| 21 | + depends_on "pkgconf" |
| 22 | + depends_on "sdformat16" |
| 23 | + depends_on "tinyxml2" |
| 24 | + depends_on "urdfdom" |
| 25 | + |
| 26 | + def install |
| 27 | + rpaths = [ |
| 28 | + rpath, |
| 29 | + rpath(source: lib/"gz-physics-9/engine-plugins", target: lib), |
| 30 | + ] |
| 31 | + cmake_args = std_cmake_args |
| 32 | + cmake_args << "-DBUILD_TESTING=OFF" |
| 33 | + cmake_args << "-DCMAKE_INSTALL_RPATH=#{rpaths.join(";")}" |
| 34 | + |
| 35 | + # Use a build folder |
| 36 | + mkdir "build" do |
| 37 | + system "cmake", "..", *cmake_args |
| 38 | + system "make", "install" |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + test do |
| 43 | + require "system_command" |
| 44 | + extend SystemCommand::Mixin |
| 45 | + # test plugins in subfolders |
| 46 | + %w[bullet-featherstone bullet dartsim tpe].each do |engine| |
| 47 | + p = lib/"gz-physics-9/engine-plugins/libgz-physics-#{engine}-plugin.dylib" |
| 48 | + # Use gz-plugin --info command to check plugin linking |
| 49 | + cmd = Formula["gz-plugin4"].opt_libexec/"gz/plugin4/gz-plugin" |
| 50 | + args = ["--info", "--plugin"] << p |
| 51 | + # print command and check return code |
| 52 | + system cmd, *args |
| 53 | + # check that library was loaded properly |
| 54 | + _, stderr = system_command(cmd, args:) |
| 55 | + error_string = "Error while loading the library" |
| 56 | + assert stderr.exclude?(error_string), error_string |
| 57 | + end |
| 58 | + # build against API |
| 59 | + (testpath/"test.cpp").write <<-EOS |
| 60 | + #include "gz/plugin/Loader.hh" |
| 61 | + #include "gz/physics/ConstructEmpty.hh" |
| 62 | + #include "gz/physics/RequestEngine.hh" |
| 63 | + int main() |
| 64 | + { |
| 65 | + gz::plugin::Loader loader; |
| 66 | + loader.LoadLib("#{opt_lib}/libgz-physics-dartsim-plugin.dylib"); |
| 67 | + gz::plugin::PluginPtr dartsim = |
| 68 | + loader.Instantiate("gz::physics::dartsim::Plugin"); |
| 69 | + using featureList = gz::physics::FeatureList< |
| 70 | + gz::physics::ConstructEmptyWorldFeature>; |
| 71 | + auto engine = |
| 72 | + gz::physics::RequestEngine3d<featureList>::From(dartsim); |
| 73 | + return engine == nullptr; |
| 74 | + } |
| 75 | + EOS |
| 76 | + (testpath/"CMakeLists.txt").write <<-EOS |
| 77 | + cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) |
| 78 | + find_package(gz-physics REQUIRED) |
| 79 | + find_package(gz-plugin REQUIRED COMPONENTS all) |
| 80 | + add_executable(test_cmake test.cpp) |
| 81 | + target_link_libraries(test_cmake |
| 82 | + gz-physics::gz-physics |
| 83 | + gz-plugin::loader) |
| 84 | + EOS |
| 85 | + system "pkg-config", "gz-physics" |
| 86 | + cflags = `pkg-config --cflags gz-physics`.split |
| 87 | + ldflags = `pkg-config --libs gz-physics`.split |
| 88 | + system "pkg-config", "gz-plugin-loader" |
| 89 | + loader_cflags = `pkg-config --cflags gz-plugin-loader`.split |
| 90 | + loader_ldflags = `pkg-config --libs gz-plugin-loader`.split |
| 91 | + system ENV.cc, "test.cpp", |
| 92 | + *cflags, |
| 93 | + *ldflags, |
| 94 | + *loader_cflags, |
| 95 | + *loader_ldflags, |
| 96 | + "-lc++", |
| 97 | + "-o", "test" |
| 98 | + system "./test" |
| 99 | + # test building with cmake |
| 100 | + mkdir "build" do |
| 101 | + system "cmake", ".." |
| 102 | + system "make" |
| 103 | + system "./test_cmake" |
| 104 | + end |
| 105 | + # check for Xcode frameworks in bottle |
| 106 | + cmd_not_grep_xcode = "! grep -rnI 'Applications[/]Xcode' #{prefix}" |
| 107 | + system cmd_not_grep_xcode |
| 108 | + end |
| 109 | +end |
0 commit comments