Skip to content

Commit 9e150fe

Browse files
havesscopybara-github
authored andcommitted
Add separate build step for OpenUSD to third_party_deps.
This will fetch and call the build_usd.py build helper for OpenUSD and build within the MuJoCo _deps folder. Simplifying the build process for MuJoCo with USD. Users can still provide their own USD build, but must now do so via pxr_DIR. PiperOrigin-RevId: 846735578 Change-Id: I0da7eb2da6465e2d518084340e762bf370adb6d5
1 parent 76e0a78 commit 9e150fe

File tree

6 files changed

+178
-109
lines changed

6 files changed

+178
-109
lines changed

CMakeLists.txt

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,6 @@ if(EMSCRIPTEN)
5454
option(MUJOCO_BUILD_TESTS_WASM "Build tests for WASM bindings" ON)
5555
endif()
5656

57-
# Option to provide a path to an existing USD build directory or to Houdini HFS directory.
58-
set(USD_DIR "" CACHE PATH "Path to an existing USD build directory.")
59-
set(HOUDINI_HFS_DIR "" CACHE PATH "Path to Houdini HFS directory to build USD plugins against.")
60-
if(USD_DIR)
61-
if(EXISTS "${USD_DIR}")
62-
# If the path is provided, set MUJOCO_WITH_USD to ON and add the path to CMAKE_PREFIX_PATH.
63-
set(MUJOCO_WITH_USD ON CACHE BOOL "Build with OpenUSD" FORCE)
64-
list(PREPEND CMAKE_PREFIX_PATH "${USD_DIR}")
65-
message(STATUS "Using custom USD build directory: ${USD_DIR}")
66-
else()
67-
message(WARNING "Invalid path provided for USD_DIR: ${USD_DIR}")
68-
endif()
69-
elseif(HOUDINI_HFS_DIR)
70-
if(EXISTS "${HOUDINI_HFS_DIR}")
71-
set(MUJOCO_WITH_USD ON CACHE BOOL "Build with OpenUSD" FORCE)
72-
message(STATUS "Building Mujoco USD against Houdini HFS: ${HOUDINI_HFS_DIR}")
73-
endif()
74-
endif()
75-
7657
if(APPLE AND (MUJOCO_BUILD_EXAMPLES OR MUJOCO_BUILD_SIMULATE))
7758
enable_language(OBJC)
7859
enable_language(OBJCXX)
@@ -243,7 +224,24 @@ if(MUJOCO_BUILD_EXAMPLES)
243224
endif()
244225

245226
if(MUJOCO_WITH_USD)
246-
target_compile_definitions(mujoco PUBLIC mjUSEUSD)
227+
include(third_party_deps/openusd)
228+
229+
get_filename_component(USD_INSTALL_ROOT "${pxr_DIR}/lib" ABSOLUTE)
230+
install(
231+
DIRECTORY ${USD_INSTALL_ROOT}/
232+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
233+
)
234+
235+
if(APPLE)
236+
set_target_properties(mujoco PROPERTIES
237+
BUILD_RPATH "${USD_INSTALL_ROOT}"
238+
INSTALL_RPATH "@loader_path")
239+
elseif(UNIX)
240+
set_target_properties(mujoco PROPERTIES
241+
BUILD_RPATH "${USD_INSTALL_ROOT}"
242+
INSTALL_RPATH "$ORIGIN")
243+
endif()
244+
247245
add_subdirectory(src/experimental/usd)
248246
endif()
249247

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2025 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Find OpenUSD package. The user can either provide pxr_DIR to use their own
16+
# OpenUSD installation or they can build external_dependencies.
17+
#
18+
# We use QUIET here to provide a better error message when pxr is not found.
19+
find_package(pxr
20+
QUIET
21+
HINTS "${CMAKE_BINARY_DIR}/_deps/openusd-build"
22+
)
23+
24+
if(NOT pxr_FOUND)
25+
message(FATAL_ERROR
26+
"-----------------------------------------------------------\n"
27+
"USD Configuration Error:\n${pxr_NOT_FOUND_MESSAGE}\n"
28+
"If you have built USD yourself, provide -Dpxr_DIR=your_pxr_install_dir' \n"
29+
"Otherwise you can build cmake/third_party_deps/openusd:\n"
30+
"cd ~/mujoco\n"
31+
"cmake -Bcmake/third_party_deps/openusd/build cmake/third_party_deps/openusd -DBUILD_USD=True\n"
32+
"cmake --build cmake/third_party_deps/openusd/build\n"
33+
"cmake -Bbuild -S. -DMUJOCO_WITH_USD=True\n"
34+
"cmake --build build\n"
35+
"cmake --install build"
36+
"-----------------------------------------------------------"
37+
)
38+
endif()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2025 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
cmake_minimum_required(VERSION "3.16")
15+
16+
option(BUILD_USD OFF "Build OpenUSD")
17+
project(openusd-dependency)
18+
19+
if (BUILD_USD)
20+
include(ExternalProject)
21+
22+
set(DEPS_DIR ${CMAKE_BINARY_DIR}/../../../../build/_deps)
23+
24+
ExternalProject_Add(openusd
25+
GIT_REPOSITORY https://github.com/PixarAnimationStudios/USD.git
26+
GIT_TAG v25.11
27+
PREFIX openusd
28+
BUILD_IN_SOURCE 0
29+
UPDATE_COMMAND ""
30+
CONFIGURE_COMMAND ""
31+
INSTALL_COMMAND ""
32+
SOURCE_DIR ${DEPS_DIR}/openusd-src
33+
BINARY_DIR ${DEPS_DIR}/openusd-build
34+
INSTALL_DIR ${DEPS_DIR}/openusd-build
35+
BUILD_COMMAND python3 ${DEPS_DIR}/openusd-src/build_scripts/build_usd.py
36+
--build-shared
37+
--no-examples
38+
--no-tools
39+
--no-ptex
40+
--no-prman
41+
--no-openimageio
42+
--no-opencolorio
43+
--no-alembic
44+
--no-draco
45+
--no-materialx
46+
--no-tutorials
47+
--no-tests
48+
--no-docs
49+
--no-imaging
50+
--no-python
51+
--no-usdValidation
52+
<INSTALL_DIR>
53+
)
54+
endif()

simulate/CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ if(SIMULATE_BUILD_EXECUTABLE)
185185
target_link_libraries(simulate "-framework CoreVideo")
186186
endif()
187187

188-
if (MUJOCO_WITH_USD)
188+
if (BUILD_WITH_USD)
189189
# pxr/usd/tf/hashset.h might include deprecated headers so disable this check
190190
# when compiling with USD enabled.
191191
target_compile_options(
@@ -265,8 +265,13 @@ if(SIMULATE_BUILD_EXECUTABLE)
265265
MUJOCO_ENABLE_RPATH
266266
)
267267

268-
if (MUJOCO_WITH_USD)
269-
target_compile_definitions(simulate PUBLIC mjUSEUSD)
268+
if (BUILD_WITH_USD)
269+
# pxr/usd/tf/hashset.h might include deprecated headers so disable this check
270+
# when compiling with USD enabled.
271+
target_compile_options(
272+
simulate
273+
PRIVATE -Wno-deprecated
274+
)
270275

271276
# Add support to RPATH for the samples.
272277
target_add_rpath(
@@ -275,10 +280,13 @@ if(SIMULATE_BUILD_EXECUTABLE)
275280
INSTALL_DIRECTORY
276281
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}"
277282
LIB_DIRS
278-
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/mujocoUsd ${USD_DIR}/lib
279283
DEPENDS
280284
MUJOCO_ENABLE_RPATH
281285
)
286+
287+
# Do we need this?
288+
#target_link_options(simulate PRIVATE -rpath=${pxr_DIR}/lib)
289+
282290
endif()
283291

284292
if(NOT MUJOCO_SIMULATE_USE_SYSTEM_GLFW)

0 commit comments

Comments
 (0)