Create list_dependencies sample to list all dependencies for an MCJF file.

PiperOrigin-RevId: 814816067
Change-Id: Idc6232e5d1ef1ff0318aeacd0e3d4b4a5a303485
This commit is contained in:
Sam Haves
2025-10-03 13:46:20 -07:00
committed by Copybara-Service
parent 6ae9cc8061
commit e4704cd28b
8 changed files with 97 additions and 29 deletions
+10
View File
@@ -76,12 +76,19 @@ target_compile_options(compile PUBLIC ${MUJOCO_SAMPLE_COMPILE_OPTIONS})
target_link_libraries(compile Threads::Threads)
target_link_options(compile PRIVATE ${MUJOCO_SAMPLE_LINK_OPTIONS})
# Build sample binaries
add_executable(dependencies dependencies.cc)
target_compile_options(dependencies PUBLIC ${MUJOCO_SAMPLE_COMPILE_OPTIONS})
target_link_libraries(dependencies Threads::Threads)
target_link_options(dependencies PRIVATE ${MUJOCO_SAMPLE_LINK_OPTIONS})
add_executable(testspeed testspeed.cc)
target_compile_options(testspeed PUBLIC ${MUJOCO_SAMPLE_COMPILE_OPTIONS})
target_link_libraries(testspeed Threads::Threads)
target_link_options(testspeed PRIVATE ${MUJOCO_SAMPLE_LINK_OPTIONS})
target_link_libraries(compile mujoco::mujoco)
target_link_libraries(dependencies mujoco::mujoco)
target_link_libraries(testspeed mujoco::mujoco)
# Build samples that require GLFW.
@@ -109,6 +116,7 @@ target_link_options(record PRIVATE ${MUJOCO_SAMPLE_LINK_OPTIONS})
if(APPLE AND MUJOCO_BUILD_MACOS_FRAMEWORKS)
embed_in_bundle(basic simulate)
embed_in_bundle(compile simulate)
embed_in_bundle(dependencies simulate)
embed_in_bundle(record simulate)
embed_in_bundle(testspeed simulate)
endif()
@@ -127,6 +135,7 @@ if(_INSTALL_SAMPLES)
TARGETS
basic
compile
dependencies
record
testspeed
INSTALL_DIRECTORY
@@ -140,6 +149,7 @@ if(_INSTALL_SAMPLES)
install(
TARGETS basic
compile
dependencies
record
testspeed
EXPORT ${PROJECT_NAME}
+45
View File
@@ -0,0 +1,45 @@
// Copyright 2025 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <mujoco/mujoco.h>
// help
static constexpr char helpstring[] =
"\n Usage: list_dependencies infile\n"
" infile must be in MJCF\n"
" Example: list_dependencies model.xml\n";
// main function
int main(int argc, char** argv) {
// print help if arguments are missing
if (argc!=3 && argc!=2) {
std::cout << helpstring << std::endl;
return EXIT_SUCCESS;
}
mjStringVec dependencies;
mju_getXMLDependencies(argv[1], &dependencies);
std::sort(dependencies.begin(), dependencies.end());
std::cout << "Dependencies:" << std::endl;
for (int i = 0; i < dependencies.size(); ++i) {
std::cout << "\t " << dependencies[i] << std::endl;
}
return EXIT_SUCCESS;
}