Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MujocoDependencies: Add CMake options to use system versions of dependencies #937

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

traversaro
Copy link
Contributor

@traversaro traversaro commented Jun 19, 2023

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 Downstream projects on Windows can't link  conda-forge/libccd-feedstock#8)

@traversaro
Copy link
Contributor Author

traversaro commented Jun 19, 2023

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

@traversaro traversaro changed the title MujocoDependencies: Add options to use system versions of dependencies MujocoDependencies: Add CMake options to use system versions of dependencies Jun 20, 2023
@tmplt
Copy link
Contributor

tmplt commented Nov 7, 2023

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.

Copy link

@keszegrobert keszegrobert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok, but this is a huge PR, I would introduce the options one by one, commit by commit, it would be more digestible (interactive rebase can help)

set(ENABLE_DOUBLE_PRECISION ON)
set(CCD_HIDE_ALL_SYMBOLS ON)
findorfetch(
USE_SYSTEM_PACKAGE
OFF
${MUJOCO_USE_SYSTEM_ccd}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest capital letters when naming the options, not only here, but everywhere in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency I used exactly the style used by the MUJOCO_DEP_VERSION_<pkg> variables defined in this file. Anyhow, I think anything is ok to mujoco's mantainers is ok for me (cc @nimrod-gileadi).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was inspired by the other calls of findorfetch, for example in the SampleDependencies and SimulateDependencies, where it is made with capital letters

)
target_compile_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
target_link_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
else()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TARGETS Qhull::qhullstatic_r in the findorfetch call will simplify this change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure of the modification/simplification you are proposing here. Feel free to suggest the specific code modification, thanks!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place we use qhull is: user_mesh.cc
#include <libqhull_r/qhull_ra.h>
So I thought Qhull::qhullstatic_r should be a better target:

findorfetch(
  USE_SYSTEM_PACKAGE
  ${MUJOCO_LIB_USE_SYSTEM_QHULL}
  PACKAGE_NAME
  qhull
  LIBRARY_NAME
  qhull
  GIT_REPO
  https://github.com/qhull/qhull.git
  GIT_TAG
  ${MUJOCO_DEP_VERSION_qhull}
  TARGETS
--- qhull
+++ Qhull::qhullstatic_r
  EXCLUDE_FROM_ALL
)

But but after a little experimenting I am not sure how it will work.

@@ -59,20 +59,20 @@ target_link_libraries(
PUBLIC absl::core_headers

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PUBLIC is probably not needed in the tests, I suggest to make it PRIVATE here and everywhere in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I am missing something, that line of code is not modified by this PR. As you mentioned, this PR is already quite big, and the change you mention seems to be a bit out of scope for this PR.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, does not matter

GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG ${MUJOCO_DEP_VERSION_Eigen3}
)
FetchContent_Declare(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findorfetch can be used for eigen3 as in python/mujoco/CMakeLists.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is probably possible, but we need to make sure that it works fine with the present workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/15415 (in python/mujoco/CMakeLists.txt Eigen3::Eigen is linked to a shared library, not to a static one). I am not sure when I will be able to do (and extensively test) this modification, so feel free to propose it yourself, thanks!

@nimrod-gileadi nimrod-gileadi self-requested a review January 5, 2024 12:41
Copy link

@keszegrobert keszegrobert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't leave any TODO comments in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants