mujoco icon indicating copy to clipboard operation
mujoco copied to clipboard

MujocoDependencies: Add CMake options to use system versions of dependencies

Open traversaro opened this issue 2 years ago • 5 comments

This PR adds options for using the system versions of MuJoCo dependencies. This options are OFF by default, but they can be useful for anyone packaging MuJoCo as part of a software distribution.

For each MuJoCo dependencies <dep>, an advanced option (by default OFF) called MUJOCO_USE_SYSTEM_<dep> is created.

To ensure that the MUJOCO_USE_SYSTEM_<dep> option work as intended, the following additional changes were done:

  • Use tinyxml2::tinyxml2 target to link tinyxml2 : the tinyxml2::tinyxml2 target works well both when tinyxml2 is found via find_package or via add_subdirectory/FetchContent, as opposed to the tinyxml2 target that only works if tinyxml2 is added with add_subdirectory/FetchContent.
  • Use GTest::gtest, GTest::gtest_main and GTest::gmock imported targets instead of gtest, gtest_main and gmock. As n the case of tinyxml2, the target gtest, gtest_main and gmock ar defined only when gtest is included via add_subdirectory.
  • Instead, for tinyobjloader and qhull the targets available when the libraries is found via find_package is different from the targets available if the library is included via add_subdirectory, so in this case appropriate alias targets are introduced.
  • For CCD, it is necessary to ensure that CCD_STATIC_DEFINE is defined only if the consumed ccd is static, not it if is dynamic (otherwise this will result in Windows linking errors such as https://github.com/conda-forge/libccd-feedstock/issues/8)

traversaro avatar Jun 19 '23 21:06 traversaro

This changes are tested extensively in https://github.com/traversaro/mujoco-conda-forge-ci/pull/2, a CI job in which all dependencies are installed via conda-forge, and not managed by CMake's FetchContent.

traversaro avatar Jun 19 '23 21:06 traversaro

This patch would be useful in NixOS where packages are built in isolated environments (offline with explicit dependencies). The current approach depends on big patches and some messy preConfigure scripts.

tmplt avatar Nov 07 '23 17:11 tmplt