|
| 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 | + |
| 16 | +# Plugin target name (used for library and plugInfo.json) |
| 17 | +set(MJCF_PLUGIN_TARGET_NAME usdMjcf) |
| 18 | + |
| 19 | +add_library(${MJCF_PLUGIN_TARGET_NAME} SHARED |
| 20 | + mjcf/mjcf_file_format.cc |
| 21 | + mjcf/mjcf_file_format.h |
| 22 | + mjcf/mujoco_to_usd.cc |
| 23 | + mjcf/mujoco_to_usd.h |
| 24 | + mjcf/utils.cc |
| 25 | + mjcf/utils.h |
| 26 | +) |
| 27 | + |
| 28 | +# We need to set the visibility to default until core type symbol visibility |
| 29 | +# is resolved in OpenUSD https://github.com/PixarAnimationStudios/OpenUSD/issues/1475 |
| 30 | +# Otherwise we will run into issues during composition on MacOS due to std::type_info |
| 31 | +# comparisons failing for pxr::TfTokenVector and the like that we place in SdfAbstractData. |
| 32 | +set_target_properties(${MJCF_PLUGIN_TARGET_NAME} PROPERTIES |
| 33 | + OUTPUT_NAME ${MJCF_PLUGIN_TARGET_NAME} |
| 34 | + CXX_VISIBILITY_PRESET default |
| 35 | +) |
| 36 | + |
| 37 | +target_include_directories(${MJCF_PLUGIN_TARGET_NAME} PRIVATE |
| 38 | + "${CMAKE_CURRENT_SOURCE_DIR}" |
| 39 | +) |
| 40 | + |
| 41 | +if (MUJOCO_USD_TARGET STREQUAL "USD") |
| 42 | + find_package(pxr REQUIRED) |
| 43 | + |
| 44 | + # --- Link Dependencies --- |
| 45 | + # Link against the necessary OpenUSD components |
| 46 | + target_link_libraries(${MJCF_PLUGIN_TARGET_NAME} PRIVATE |
| 47 | + usd |
| 48 | + ar |
| 49 | + kind |
| 50 | + tf |
| 51 | + gf |
| 52 | + vt |
| 53 | + usdShade |
| 54 | + usdLux |
| 55 | + usdGeom |
| 56 | + usdImaging |
| 57 | + usdPhysics |
| 58 | + mujoco |
| 59 | + tinyxml2 |
| 60 | + ) |
| 61 | +elseif (MUJOCO_USD_TARGET STREQUAL "Houdini") |
| 62 | + |
| 63 | + if (NOT DEFINED ENV{HFS}) |
| 64 | + message(FATAL_ERROR "Environment variable 'HFS' is not defined: $ENV{HFS}. Please run houdini_setup.") |
| 65 | + endif() |
| 66 | + |
| 67 | + # In Houdini, the Houdini package we would typically use via find_package |
| 68 | + # does not have all the USD dependencies that we need (namely UsdPhysics) |
| 69 | + # so we need to manually link all the required libraries. |
| 70 | + |
| 71 | + set(HFS_ENV "$ENV{HFS}") |
| 72 | + set(HOUDINI_LIBS "${HFS_ENV}/../Libraries") |
| 73 | + get_filename_component(HOUDINI_LIBS "${HOUDINI_LIBS}" ABSOLUTE) # Normalize the path |
| 74 | + target_link_directories(${MJCF_PLUGIN_TARGET_NAME} PRIVATE ${HOUDINI_LIBS}) |
| 75 | + |
| 76 | + target_include_directories(${MJCF_PLUGIN_TARGET_NAME} PRIVATE |
| 77 | + "${HFS_ENV}/toolkit/include" |
| 78 | + "${HFS_ENV}/toolkit/include/python3.11" |
| 79 | + ) |
| 80 | + |
| 81 | + # Assume everyone using Houdini on 3.11 for now. |
| 82 | + set(USD_MJCF_PYTHON_LIB python3.11) |
| 83 | + set(USD_MJCF_PYTHON_LIB_NUMBER python311) |
| 84 | + set(PYTHON_LIB "${HFS_ENV}/Frameworks/Python.framework/Versions/3.11/Python") |
| 85 | + set(PXR_LIB_PREFIX "pxr_") |
| 86 | + |
| 87 | + # --- Link Dependencies --- |
| 88 | + # Link against the necessary OpenUSD components |
| 89 | + target_link_libraries(${MJCF_PLUGIN_TARGET_NAME} PRIVATE |
| 90 | + ${PXR_LIB_PREFIX}usd |
| 91 | + ${PXR_LIB_PREFIX}ar |
| 92 | + ${PXR_LIB_PREFIX}kind |
| 93 | + ${PXR_LIB_PREFIX}tf |
| 94 | + ${PXR_LIB_PREFIX}gf |
| 95 | + ${PXR_LIB_PREFIX}vt |
| 96 | + ${PXR_LIB_PREFIX}sdf |
| 97 | + ${PXR_LIB_PREFIX}usdShade |
| 98 | + ${PXR_LIB_PREFIX}usdLux |
| 99 | + ${PXR_LIB_PREFIX}usdGeom |
| 100 | + ${PXR_LIB_PREFIX}usdImaging |
| 101 | + ${PXR_LIB_PREFIX}usdPhysics |
| 102 | + tbb |
| 103 | + hboost_${USD_MJCF_PYTHON_LIB_NUMBER} |
| 104 | + ${PYTHON_LIB} |
| 105 | + mujoco |
| 106 | + tinyxml2 |
| 107 | + ) |
| 108 | +endif() |
| 109 | + |
| 110 | + |
| 111 | +# --- Generate plugInfo.json --- |
| 112 | +if(CMAKE_SHARED_LIBRARY_PREFIX) |
| 113 | + set(LIB_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX}) # Usually "lib" on Unix |
| 114 | +else() |
| 115 | + set(LIB_PREFIX "") |
| 116 | +endif() |
| 117 | +set(PLUG_INFO_LIBRARY_PATH "${LIB_PREFIX}${MJCF_PLUGIN_TARGET_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}") |
| 118 | + |
| 119 | +# --- Installation --- |
| 120 | + |
| 121 | +set(USD_PLUGIN_INSTALL_DIR_LIB ${CMAKE_INSTALL_LIBDIR}/usdMjcf) |
| 122 | + |
| 123 | +message(STATUS "Copying plugInfo.json to ${CMAKE_BINARY_DIR}/${USD_PLUGIN_INSTALL_DIR_LIB}/plugInfo.json") |
| 124 | +configure_file( |
| 125 | + mjcf/plugInfo.json |
| 126 | + ${CMAKE_BINARY_DIR}/${USD_PLUGIN_INSTALL_DIR_LIB}/plugInfo.json |
| 127 | +) |
| 128 | + |
| 129 | +install(FILES ${CMAKE_BINARY_DIR}/${USD_PLUGIN_INSTALL_DIR_LIB}/plugInfo.json DESTINATION ${USD_PLUGIN_INSTALL_DIR_LIB}) |
| 130 | + |
| 131 | +# Install shared lib and plugInfo to same location for simplicity. |
| 132 | +install(TARGETS ${MJCF_PLUGIN_TARGET_NAME} |
| 133 | + LIBRARY DESTINATION ${USD_PLUGIN_INSTALL_DIR_LIB} |
| 134 | +) |
| 135 | + |
| 136 | +message(STATUS "USD MJCF Plugin will be installed to: ${CMAKE_INSTALL_PREFIX}/${USD_PLUGIN_INSTALL_DIR_LIB}") |
| 137 | +message(STATUS "Make sure PXR_PLUGINPATH_NAME includes: ${CMAKE_INSTALL_PREFIX}/${USD_PLUGIN_INSTALL_DIR_LIB}") |
0 commit comments