diff --git a/CMakeLists.txt b/CMakeLists.txt
index 461a9b6..1aa4d0b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,16 +17,13 @@ find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(Threads REQUIRED)
-set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
-
-# Attempt to find an install of mujoco, either the library itself, from the environment, or
-# as a last resort download the required tar file manually and unzip it into the workspace.
-find_package(mujoco QUIET)
-if(mujoco_FOUND)
- message(STATUS "Mujoco build from source has been found")
+# Attempt to link MuJoCo via the vendor package, if available
+find_package(mujoco_vendor QUIET)
+if(mujoco_vendor_FOUND)
set(MUJOCO_LIB mujoco::mujoco)
- set(MUJOCO_INCLUDE_DIR ${MUJOCO_INCLUDE_DIR})
+ set(MUJOCO_INCLUDE_DIR ${mujoco_vendor_INCLUDE_DIRS})
set(MUJOCO_SIMULATE_DIR ${MUJOCO_INCLUDE_DIR}/../simulate)
+# If the user has specified a MuJoCo install location use it
elseif(DEFINED ENV{MUJOCO_INSTALL_DIR})
message(STATUS "Mujoco build from source has not been found. Attempting to find the binary in $ENV{MUJOCO_INSTALL_DIR} instead.")
set(MUJOCO_DIR $ENV{MUJOCO_INSTALL_DIR})
@@ -36,9 +33,9 @@ elseif(DEFINED ENV{MUJOCO_INSTALL_DIR})
endif()
set(MUJOCO_INCLUDE_DIR $ENV{MUJOCO_DIR}/include)
set(MUJOCO_SIMULATE_DIR $ENV{MUJOCO_DIR}/simulate)
+# Otherwise we fallback and download the required tarfile and install it manually
else()
include(FetchContent)
-
# Detect architecture
set(MUJOCO_VERSION "3.3.4")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
@@ -77,6 +74,9 @@ else()
message(STATUS "MuJoCo library found: ${MUJOCO_LIB}")
endif()
+
+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+
# Fetch lodepng dependency.
if(NOT TARGET lodepng)
include(FetchContent)
diff --git a/README.md b/README.md
index 151a1b0..b70a0dd 100644
--- a/README.md
+++ b/README.md
@@ -14,10 +14,8 @@ This interface has only been tested against ROS 2 jazzy and MuJoCo `3.3.4`.
It should also be compatible with kilted and rolling, but we do not actively maintain those.
We assume all required ROS dependencies have been installed either manually or with `rosdep`.
-For configuring MuJoCo, the included [CMakeLists.txt](./CMakeLists.txt) will download and install the tarfile automatically.
-As long as users have a good network connection there should not be an issue.
-
-However, a local install of MuJoCo can be used to build the application by setting the following environment variables,
+For configuring MuJoCo, the included [CMakeLists.txt](./CMakeLists.txt) will first attempt to use the [mujoco_vendor](https://github.com/pal-robotics/mujoco_vendor) package if it is installed in your workspace.
+If it is not found, a local install of MuJoCo can be used to build the application by setting the following environment variables,
```bash
# The tested version
@@ -26,6 +24,8 @@ MUJOCO_VERSION=3.3.4
# Wherever it was installed and extracted on your machine
MUJOCO_INSTALL_DIR=/opt/mujoco/mujoco-3.3.4
```
+If neither is available, the script will automatically download and install the MuJoCo tarfile.
+As long as users have a stable network connection, this process should complete without issues.
From there the library can be compiled with `colcon build ...`, as normal.
diff --git a/package.xml b/package.xml
index 6ad03ab..8a37987 100644
--- a/package.xml
+++ b/package.xml
@@ -17,6 +17,7 @@
rclcpp
rclcpp_lifecycle
sensor_msgs
+ mujoco_vendor
joint_state_broadcaster
position_controllers