MujocoDependencies: Add CMake options to use system versions of dependencies
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::tinyxml2target to link tinyxml2 : thetinyxml2::tinyxml2target works well both when tinyxml2 is found via find_package or via add_subdirectory/FetchContent, as opposed to thetinyxml2target that only works iftinyxml2is added with add_subdirectory/FetchContent. - Use
GTest::gtest,GTest::gtest_mainandGTest::gmockimported targets instead ofgtest,gtest_mainandgmock. As n the case oftinyxml2, the targetgtest,gtest_mainandgmockar defined only when gtest is included viaadd_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 thatCCD_STATIC_DEFINEis 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)
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.
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.