From 846bdf8bc8fd710fa10d0fdb486088d67bc189db Mon Sep 17 00:00:00 2001 From: Ortisa Poci Date: Tue, 4 Nov 2025 14:30:38 +0100 Subject: [PATCH 1/9] integration of mujoco_vendor --- CMakeLists.txt | 65 +++++++------------------------------------------- package.xml | 1 + 2 files changed, 10 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 461a9b6..a17a0ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,65 +17,18 @@ find_package(rclcpp REQUIRED) find_package(rclcpp_lifecycle REQUIRED) find_package(Threads REQUIRED) -set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +# Import MuJoCo via vendor package (already installed) +find_package(mujoco REQUIRED) +set(MUJOCO_LIB mujoco::mujoco) +get_target_property(MUJOCO_INCLUDE_DIR mujoco::mujoco INTERFACE_INCLUDE_DIRECTORIES) +set(MUJOCO_SIMULATE_DIR ${MUJOCO_INCLUDE_DIR}/../simulate) -# 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") - set(MUJOCO_LIB mujoco::mujoco) - set(MUJOCO_INCLUDE_DIR ${MUJOCO_INCLUDE_DIR}) - set(MUJOCO_SIMULATE_DIR ${MUJOCO_INCLUDE_DIR}/../simulate) -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}) - find_library(MUJOCO_LIB mujoco HINTS $ENV{MUJOCO_DIR}/lib) - if(NOT MUJOCO_LIB) - message(FATAL_ERROR "Failed to find binary in $ENV{MUJOCO_DIR}") - endif() - set(MUJOCO_INCLUDE_DIR $ENV{MUJOCO_DIR}/include) - set(MUJOCO_SIMULATE_DIR $ENV{MUJOCO_DIR}/simulate) -else() - include(FetchContent) +message(STATUS "Using MuJoCo from vendor package") +message(STATUS " MUJOCO_INCLUDE_DIR: ${MUJOCO_INCLUDE_DIR}") +message(STATUS " MUJOCO_SIMULATE_DIR: ${MUJOCO_SIMULATE_DIR}") - # Detect architecture - set(MUJOCO_VERSION "3.3.4") - if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") - set(CPU_ARCH "x86_64") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64") - set(CPU_ARCH "aarch64") - else() - message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") - endif() - message(STATUS "No MuJoCo installation found. Downloading MuJoCo ${MUJOCO_VERSION} for ${CPU_ARCH}.") - - # Download the archive and put it next to the source directory - set(MUJOCO_DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/mujoco) - set(MUJOCO_EXTRACT_DIR ${MUJOCO_DOWNLOAD_DIR}/mujoco-${MUJOCO_VERSION}) - set(FETCHCONTENT_UPDATES_DISCONNECTED ON) - FetchContent_Declare( - mujoco_download - URL https://github.com/google-deepmind/mujoco/releases/download/${MUJOCO_VERSION}/mujoco-${MUJOCO_VERSION}-linux-${CPU_ARCH}.tar.gz - SOURCE_DIR ${MUJOCO_EXTRACT_DIR} - DOWNLOAD_EXTRACT_TIMESTAMP True - ) - FetchContent_MakeAvailable(mujoco_download) - - set(MUJOCO_DIR ${MUJOCO_EXTRACT_DIR}) - message(STATUS "MuJoCo downloaded to: ${MUJOCO_DIR}") - - # Find the library in the downloaded location - find_library(MUJOCO_LIB mujoco HINTS ${MUJOCO_DIR}/lib NO_DEFAULT_PATH) - if(NOT MUJOCO_LIB) - message(FATAL_ERROR "Failed to find MuJoCo library in ${MUJOCO_DIR}/lib") - endif() - - set(MUJOCO_INCLUDE_DIR ${MUJOCO_DIR}/include) - set(MUJOCO_SIMULATE_DIR ${MUJOCO_DIR}/simulate) - message(STATUS "MuJoCo library found: ${MUJOCO_LIB}") -endif() +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # Fetch lodepng dependency. if(NOT TARGET lodepng) diff --git a/package.xml b/package.xml index 6ad03ab..e6b7fcb 100644 --- a/package.xml +++ b/package.xml @@ -10,6 +10,7 @@ ament_cmake + mujoco_vendor controller_manager hardware_interface libglfw3-dev From 457b839f6117738f409fded79d4ea53007b4d8f8 Mon Sep 17 00:00:00 2001 From: Ortisa Poci Date: Tue, 4 Nov 2025 14:35:31 +0100 Subject: [PATCH 2/9] removed message print from CMakeLists --- CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a17a0ac..44ea792 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,11 +23,6 @@ set(MUJOCO_LIB mujoco::mujoco) get_target_property(MUJOCO_INCLUDE_DIR mujoco::mujoco INTERFACE_INCLUDE_DIRECTORIES) set(MUJOCO_SIMULATE_DIR ${MUJOCO_INCLUDE_DIR}/../simulate) -message(STATUS "Using MuJoCo from vendor package") -message(STATUS " MUJOCO_INCLUDE_DIR: ${MUJOCO_INCLUDE_DIR}") -message(STATUS " MUJOCO_SIMULATE_DIR: ${MUJOCO_SIMULATE_DIR}") - - set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # Fetch lodepng dependency. From b0972c42fbdadb13f7d543edcffc9eae2321120d Mon Sep 17 00:00:00 2001 From: Ortisa Poci Date: Tue, 4 Nov 2025 15:32:44 +0100 Subject: [PATCH 3/9] fixed CMakeLists --- CMakeLists.txt | 59 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44ea792..cf97f79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,10 +18,61 @@ find_package(rclcpp_lifecycle REQUIRED) find_package(Threads REQUIRED) # Import MuJoCo via vendor package (already installed) -find_package(mujoco REQUIRED) -set(MUJOCO_LIB mujoco::mujoco) -get_target_property(MUJOCO_INCLUDE_DIR mujoco::mujoco INTERFACE_INCLUDE_DIRECTORIES) -set(MUJOCO_SIMULATE_DIR ${MUJOCO_INCLUDE_DIR}/../simulate) +find_package(mujoco_vendor REQUIRED) +if(mujoco_vendor_FOUND) + set(MUJOCO_LIB mujoco::mujoco) + set(MUJOCO_INCLUDE_DIR ${mujoco_vendor_INCLUDE_DIRS}) + set(MUJOCO_SIMULATE_DIR ${MUJOCO_INCLUDE_DIR}/../simulate) + +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}) + find_library(MUJOCO_LIB mujoco HINTS $ENV{MUJOCO_DIR}/lib) + if(NOT MUJOCO_LIB) + message(FATAL_ERROR "Failed to find binary in $ENV{MUJOCO_DIR}") + endif() + set(MUJOCO_INCLUDE_DIR $ENV{MUJOCO_DIR}/include) + set(MUJOCO_SIMULATE_DIR $ENV{MUJOCO_DIR}/simulate) +else() + include(FetchContent) + # Detect architecture + set(MUJOCO_VERSION "3.3.4") + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") + set(CPU_ARCH "x86_64") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64") + set(CPU_ARCH "aarch64") + else() + message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") + endif() + + message(STATUS "No MuJoCo installation found. Downloading MuJoCo ${MUJOCO_VERSION} for ${CPU_ARCH}.") + + # Download the archive and put it next to the source directory + set(MUJOCO_DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/mujoco) + set(MUJOCO_EXTRACT_DIR ${MUJOCO_DOWNLOAD_DIR}/mujoco-${MUJOCO_VERSION}) + set(FETCHCONTENT_UPDATES_DISCONNECTED ON) + FetchContent_Declare( + mujoco_download + URL https://github.com/google-deepmind/mujoco/releases/download/${MUJOCO_VERSION}/mujoco-${MUJOCO_VERSION}-linux-${CPU_ARCH}.tar.gz + SOURCE_DIR ${MUJOCO_EXTRACT_DIR} + DOWNLOAD_EXTRACT_TIMESTAMP True + ) + FetchContent_MakeAvailable(mujoco_download) + + set(MUJOCO_DIR ${MUJOCO_EXTRACT_DIR}) + message(STATUS "MuJoCo downloaded to: ${MUJOCO_DIR}") + + # Find the library in the downloaded location + find_library(MUJOCO_LIB mujoco HINTS ${MUJOCO_DIR}/lib NO_DEFAULT_PATH) + if(NOT MUJOCO_LIB) + message(FATAL_ERROR "Failed to find MuJoCo library in ${MUJOCO_DIR}/lib") + endif() + + set(MUJOCO_INCLUDE_DIR ${MUJOCO_DIR}/include) + set(MUJOCO_SIMULATE_DIR ${MUJOCO_DIR}/simulate) + message(STATUS "MuJoCo library found: ${MUJOCO_LIB}") +endif() + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) From 5c24edf78ef33e1c52a089876492e036033679b9 Mon Sep 17 00:00:00 2001 From: Ortisa Poci Date: Tue, 4 Nov 2025 15:54:37 +0100 Subject: [PATCH 4/9] updated README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 151a1b0..e860d7f 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 package if it is installed in your workspace. +If mujoco_vendor 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. From 945092f7662e5a5d186061f0c8fbda000f657736 Mon Sep 17 00:00:00 2001 From: Ortisa Poci Date: Tue, 4 Nov 2025 15:57:29 +0100 Subject: [PATCH 5/9] Added link to mujoco_vendor --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e860d7f..059f7f6 100644 --- a/README.md +++ b/README.md @@ -14,8 +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 first attempt to use the mujoco_vendor package if it is installed in your workspace. -If mujoco_vendor is not found, 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 [mujoco_vendor] 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 From 86721b6ecd1de156a3b288004ab28d5b18c49016 Mon Sep 17 00:00:00 2001 From: Ortisa Poci Date: Tue, 4 Nov 2025 15:58:51 +0100 Subject: [PATCH 6/9] clean up README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 059f7f6..5f5b44e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ It should also be compatible with kilted and rolling, but we do not actively mai We assume all required ROS dependencies have been installed either manually or with `rosdep`. 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 [mujoco_vendor] is not found, a local install of MuJoCo can be used to build the application by setting the following environment variables, +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 From b16cf4417f3884f4a80eb7b1d096fdb6126e7386 Mon Sep 17 00:00:00 2001 From: Ortisa Poci Date: Wed, 5 Nov 2025 15:51:55 +0100 Subject: [PATCH 7/9] removed vendor dependence --- package.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/package.xml b/package.xml index e6b7fcb..6ad03ab 100644 --- a/package.xml +++ b/package.xml @@ -10,7 +10,6 @@ ament_cmake - mujoco_vendor controller_manager hardware_interface libglfw3-dev From 26ebdb04446995dbcbbea01eb831a61f4a2fc92c Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Mon, 10 Nov 2025 17:50:11 +0100 Subject: [PATCH 8/9] Add mujoco_vendor dependency --- package.xml | 1 + 1 file changed, 1 insertion(+) 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 From f0ee00149afdc0adb9affd94db2a86b452013b26 Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Tue, 11 Nov 2025 05:21:29 +0100 Subject: [PATCH 9/9] Apply suggestions from code review for CMakeLists.txt Co-authored-by: Erik Holum --- CMakeLists.txt | 9 +++++---- README.md | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf97f79..1aa4d0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,13 +17,13 @@ find_package(rclcpp REQUIRED) find_package(rclcpp_lifecycle REQUIRED) find_package(Threads REQUIRED) -# Import MuJoCo via vendor package (already installed) -find_package(mujoco_vendor REQUIRED) +# 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_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}) @@ -33,9 +33,10 @@ 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 + # Detect architecture set(MUJOCO_VERSION "3.3.4") if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") set(CPU_ARCH "x86_64") diff --git a/README.md b/README.md index 5f5b44e..b70a0dd 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ 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 first attempt to use the [mujoco_vendor](https://github.com/pal-robotics/mujoco_vendor) package if it is installed in your workspace. +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