1 diff --git a/CMakeLists.txt b/CMakeLists.txt
2 index eea180c0..efb39178 100644
5 @@ -93,7 +93,7 @@ add_subdirectory(src/render)
6 add_subdirectory(src/thread)
7 add_subdirectory(src/ui)
9 -target_compile_definitions(mujoco PRIVATE _GNU_SOURCE CCD_STATIC_DEFINE MUJOCO_DLL_EXPORTS -DMC_IMPLEM_ENABLE)
10 +target_compile_definitions(mujoco PRIVATE _GNU_SOURCE MUJOCO_DLL_EXPORTS -DMC_IMPLEM_ENABLE)
11 if(MUJOCO_ENABLE_AVX_INTRINSICS)
12 target_compile_definitions(mujoco PUBLIC mjUSEPLATFORMSIMD)
14 @@ -118,7 +118,7 @@ target_link_libraries(
22 set_target_properties(
23 diff --git a/cmake/MujocoDependencies.cmake b/cmake/MujocoDependencies.cmake
24 index 44962272..656beeb8 100644
25 --- a/cmake/MujocoDependencies.cmake
26 +++ b/cmake/MujocoDependencies.cmake
27 @@ -93,28 +93,36 @@ set(BUILD_SHARED_LIBS
28 if(NOT TARGET lodepng)
31 - GIT_REPOSITORY https://github.com/lvandeve/lodepng.git
32 - GIT_TAG ${MUJOCO_DEP_VERSION_lodepng}
36 - FetchContent_GetProperties(lodepng)
37 - if(NOT lodepng_POPULATED)
38 - FetchContent_Populate(lodepng)
39 - # This is not a CMake project.
40 - set(LODEPNG_SRCS ${lodepng_SOURCE_DIR}/lodepng.cpp)
41 - set(LODEPNG_HEADERS ${lodepng_SOURCE_DIR}/lodepng.h)
42 - add_library(lodepng STATIC ${LODEPNG_HEADERS} ${LODEPNG_SRCS})
43 - target_compile_options(lodepng PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
44 - target_link_options(lodepng PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
45 - target_include_directories(lodepng PUBLIC ${lodepng_SOURCE_DIR})
46 +if(NOT TARGET lodepng)
47 + if(NOT MUJOCO_USE_SYSTEM_lodepng)
48 + fetchcontent_declare(
50 + GIT_REPOSITORY https://github.com/lvandeve/lodepng.git
51 + GIT_TAG ${MUJOCO_DEP_VERSION_lodepng}
54 + FetchContent_GetProperties(lodepng)
55 + if(NOT lodepng_POPULATED)
56 + FetchContent_Populate(lodepng)
57 + # This is not a CMake project.
58 + set(LODEPNG_SRCS ${lodepng_SOURCE_DIR}/lodepng.cpp)
59 + set(LODEPNG_HEADERS ${lodepng_SOURCE_DIR}/lodepng.h)
60 + add_library(lodepng STATIC ${LODEPNG_HEADERS} ${LODEPNG_SRCS})
61 + target_compile_options(lodepng PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
62 + target_link_options(lodepng PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
63 + target_include_directories(lodepng PUBLIC ${lodepng_SOURCE_DIR})
66 + find_package(lodepng REQUIRED)
70 if(NOT TARGET marchingcubecpp)
73 - GIT_REPOSITORY https://github.com/aparis69/MarchingCubeCpp.git
74 - GIT_TAG ${MUJOCO_DEP_VERSION_MarchingCubeCpp}
77 FetchContent_GetProperties(marchingcubecpp)
78 @@ -124,119 +132,158 @@ if(NOT TARGET marchingcubecpp)
82 +option(MUJOCO_USE_SYSTEM_qhull "Use installed qhull version." OFF)
83 +mark_as_advanced(MUJOCO_USE_SYSTEM_qhull)
85 set(QHULL_ENABLE_TESTING OFF)
90 + ${MUJOCO_USE_SYSTEM_qhull}
97 - https://github.com/qhull/qhull.git
99 - ${MUJOCO_DEP_VERSION_qhull}
104 -# MuJoCo includes a file from libqhull_r which is not exported by the qhull include directories.
105 -# Add it to the target.
106 -target_include_directories(
107 - qhullstatic_r INTERFACE $<BUILD_INTERFACE:${qhull_SOURCE_DIR}/src/libqhull_r>
109 -target_compile_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
110 -target_link_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
111 +if(NOT MUJOCO_USE_SYSTEM_qhull)
112 + # MuJoCo includes a file from libqhull_r which is not exported by the qhull include directories.
113 + # Add it to the target.
114 + target_include_directories(
115 + qhullstatic_r INTERFACE $<BUILD_INTERFACE:${qhull_SOURCE_DIR}/src/libqhull_r>
117 + target_compile_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
118 + target_link_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
120 + if(NOT TARGET qhullstatic_r)
121 + add_library(qhullstatic_r INTERFACE)
122 + set_target_properties(qhullstatic_r PROPERTIES INTERFACE_LINK_LIBRARIES Qhull::qhull_r)
124 + # Workaround as headers are installed in <prefix>/include/libqhull_r/something.h
125 + # but mujoco include them as #include <something.h>
126 + get_property(qhull_include_dirs TARGET Qhull::qhull_r PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
127 + foreach(qhull_include_dir IN LISTS qhull_include_dirs)
128 + target_include_directories(qhullstatic_r INTERFACE ${qhull_include_dirs}/libqhull_r)
130 + target_include_directories(qhullstatic_r INTERFACE )
134 +option(MUJOCO_USE_SYSTEM_tinyxml2 "Use installed tinyxml2 version." OFF)
135 +mark_as_advanced(MUJOCO_USE_SYSTEM_tinyxml2)
137 set(tinyxml2_BUILD_TESTING OFF)
141 + ${MUJOCO_USE_SYSTEM_tinyxml2}
147 - https://github.com/leethomason/tinyxml2.git
149 - ${MUJOCO_DEP_VERSION_tinyxml2}
155 -target_compile_options(tinyxml2 PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
156 -target_link_options(tinyxml2 PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
157 +if(NOT MUJOCO_USE_SYSTEM_tinyxml2)
158 + target_compile_options(tinyxml2 PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
159 + target_link_options(tinyxml2 PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
162 +option(MUJOCO_USE_SYSTEM_tinyobjloader "Use installed tinyobjloader version." OFF)
163 +mark_as_advanced(MUJOCO_USE_SYSTEM_tinyobjloader)
168 + ${MUJOCO_USE_SYSTEM_tinyobjloader}
174 - https://github.com/tinyobjloader/tinyobjloader.git
176 - ${MUJOCO_DEP_VERSION_tinyobjloader}
182 +if(MUJOCO_USE_SYSTEM_tinyobjloader)
183 + # As of tinyobjloader v2.0.0rc10, the tinyobjloader target is named tinyobjloader in the build,
184 + # but tinyobjloader::tinyobjloader when it is installed. To deal with this, if tinyobjloader is
185 + # found in the system, we create an ALIAS
186 + # The following is equivalent to add_library(tinyobjloader ALIAS tinyobjloader::tinyobjloader),
187 + # but compatible with CMake 3.16 . Once the minimum CMake is bumped to CMake 3.18, we can use
188 + # the simpler version
189 + add_library(tinyobjloader INTERFACE IMPORTED)
190 + set_target_properties(tinyobjloader PROPERTIES INTERFACE_LINK_LIBRARIES tinyobjloader::tinyobjloader)
193 +option(MUJOCO_USE_SYSTEM_sdflib "Use installed sdflib version." OFF)
194 +mark_as_advanced(MUJOCO_USE_SYSTEM_sdflib)
196 option(SDFLIB_USE_ASSIMP OFF)
197 option(SDFLIB_USE_OPENMP OFF)
198 option(SDFLIB_USE_ENOKI OFF)
203 + ${MUJOCO_USE_SYSTEM_sdflib}
210 - https://github.com/UPC-ViRVIG/SdfLib.git
212 - ${MUJOCO_DEP_VERSION_sdflib}
218 -target_compile_options(SdfLib PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
219 -target_link_options(SdfLib PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
221 +if(NOT MUJOCO_USE_SYSTEM_sdflib)
222 + target_compile_options(SdfLib PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
223 + target_link_options(SdfLib PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
226 +option(MUJOCO_USE_SYSTEM_ccd "Use installed ccd version." OFF)
227 +mark_as_advanced(MUJOCO_USE_SYSTEM_ccd)
229 set(ENABLE_DOUBLE_PRECISION ON)
230 set(CCD_HIDE_ALL_SYMBOLS ON)
234 + ${MUJOCO_USE_SYSTEM_ccd}
240 - https://github.com/danfis/libccd.git
242 - ${MUJOCO_DEP_VERSION_ccd}
247 -target_compile_options(ccd PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
248 -target_link_options(ccd PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
250 -# libCCD has an unconditional `#define _CRT_SECURE_NO_WARNINGS` on Windows.
251 -# TODO(stunya): Remove this after https://github.com/danfis/libccd/pull/77 is merged.
254 - # C4005 is the MSVC equivalent of -Wmacro-redefined.
255 - target_compile_options(ccd PRIVATE /wd4005)
257 - target_compile_options(ccd PRIVATE -Wno-macro-redefined)
259 +if(NOT MUJOCO_USE_SYSTEM_ccd)
260 + target_compile_options(ccd PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
261 + target_link_options(ccd PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
262 + # This is necessary to ensure that the any library that consumes the ccd
263 + # compiled internally by MuJoCo (as static library) has CCD_EXPORT correctly
264 + # defined as an empty string. For ccd itself, this is ensured by the variable
265 + # CCD_HIDE_ALL_SYMBOLS set to ON before the call to findorfetch
266 + # See https://github.com/danfis/libccd/pull/79
267 + target_compile_definitions(ccd INTERFACE CCD_STATIC_DEFINE)
269 + # libCCD has an unconditional `#define _CRT_SECURE_NO_WARNINGS` on Windows.
270 + # TODO(stunya): Remove this after https://github.com/danfis/libccd/pull/77 is merged.
273 + # C4005 is the MSVC equivalent of -Wmacro-redefined.
274 + target_compile_options(ccd PRIVATE /wd4005)
276 + target_compile_options(ccd PRIVATE -Wno-macro-redefined)
281 if(MUJOCO_BUILD_TESTS)
282 + option(MUJOCO_USE_SYSTEM_abseil "Use installed abseil version." OFF)
283 + mark_as_advanced(MUJOCO_USE_SYSTEM_abseil)
285 set(ABSL_PROPAGATE_CXX_STD ON)
287 # This specific version of Abseil does not have the following variable. We need to work with BUILD_TESTING
288 @@ -249,15 +296,11 @@ if(MUJOCO_BUILD_TESTS)
289 set(ABSL_BUILD_TESTING OFF)
293 + ${MUJOCO_USE_SYSTEM_abseil}
299 - https://github.com/abseil/abseil-cpp.git
301 - ${MUJOCO_DEP_VERSION_abseil}
305 @@ -268,6 +311,9 @@ if(MUJOCO_BUILD_TESTS)
306 CACHE BOOL "Build tests." FORCE
309 + option(MUJOCO_USE_SYSTEM_gtest "Use installed gtest version." OFF)
310 + mark_as_advanced(MUJOCO_USE_SYSTEM_gtest)
312 # Avoid linking errors on Windows by dynamically linking to the C runtime.
313 set(gtest_force_shared_crt
315 @@ -276,22 +322,20 @@ if(MUJOCO_BUILD_TESTS)
320 + ${MUJOCO_USE_SYSTEM_gtest}
326 - https://github.com/google/googletest.git
328 - ${MUJOCO_DEP_VERSION_gtest}
338 + option(MUJOCO_USE_SYSTEM_benchmark "Use installed benchmark version." OFF)
339 + mark_as_advanced(MUJOCO_USE_SYSTEM_benchmark)
341 set(BENCHMARK_EXTRA_FETCH_ARGS "")
342 if(WIN32 AND NOT MSVC)
343 set(BENCHMARK_EXTRA_FETCH_ARGS
344 @@ -310,15 +354,11 @@ if(MUJOCO_BUILD_TESTS)
349 + ${MUJOCO_USE_SYSTEM_benchmark}
355 - https://github.com/google/benchmark.git
357 - ${MUJOCO_DEP_VERSION_benchmark}
360 benchmark::benchmark_main
361 @@ -328,15 +368,18 @@ if(MUJOCO_BUILD_TESTS)
364 if(MUJOCO_TEST_PYTHON_UTIL)
365 + option(MUJOCO_USE_SYSTEM_Eigen3 "Use installed Eigen3 version." OFF)
366 + mark_as_advanced(MUJOCO_USE_SYSTEM_Eigen3)
368 add_compile_definitions(EIGEN_MPL2_ONLY)
369 - if(NOT TARGET eigen)
370 - # Support new IN_LIST if() operator.
371 - set(CMAKE_POLICY_DEFAULT_CMP0057 NEW)
372 + if(NOT TARGET Eigen3::Eigen)
373 + if(NOT MUJOCO_USE_SYSTEM_Eigen3)
374 + # Support new IN_LIST if() operator.
375 + set(CMAKE_POLICY_DEFAULT_CMP0057 NEW)
378 FetchContent_Declare(
380 - GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
381 - GIT_TAG ${MUJOCO_DEP_VERSION_Eigen3}
384 FetchContent_GetProperties(Eigen3)
385 @@ -348,6 +391,19 @@ if(MUJOCO_TEST_PYTHON_UTIL)
386 set_target_properties(
387 Eigen3::Eigen PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${eigen3_SOURCE_DIR}"
390 + fetchcontent_getproperties(Eigen3)
391 + # if(NOT Eigen3_POPULATED)
392 + # fetchcontent_populate(Eigen3)
394 + # # Mark the library as IMPORTED as a workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/15415
395 + # add_library(Eigen3::Eigen INTERFACE IMPORTED)
396 + # set_target_properties(
397 + # Eigen3::Eigen PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${eigen3_SOURCE_DIR}"
401 + find_package(Eigen3 REQUIRED)
405 diff --git a/plugin/sdf/CMakeLists.txt b/plugin/sdf/CMakeLists.txt
406 index 3e216fc4..e7e3a1eb 100644
407 --- a/plugin/sdf/CMakeLists.txt
408 +++ b/plugin/sdf/CMakeLists.txt
409 @@ -37,7 +37,7 @@ set(MUJOCO_SDF_SRCS
410 add_library(sdf SHARED)
411 target_sources(sdf PRIVATE ${MUJOCO_SDF_SRCS})
412 target_include_directories(sdf PRIVATE ${MUJOCO_SDF_INCLUDE})
413 -target_link_libraries(sdf PRIVATE mujoco SdfLib)
414 +target_link_libraries(sdf PRIVATE mujoco SdfLib::SdfLib)
415 target_compile_options(
417 PRIVATE ${AVX_COMPILE_OPTIONS}
418 diff --git a/python/mujoco/util/CMakeLists.txt b/python/mujoco/util/CMakeLists.txt
419 index 666a3725..d89bb499 100644
420 --- a/python/mujoco/util/CMakeLists.txt
421 +++ b/python/mujoco/util/CMakeLists.txt
422 @@ -63,8 +63,8 @@ if(BUILD_TESTING)
423 target_link_libraries(
431 gtest_add_tests(TARGET array_traits_test SOURCES array_traits_test.cc)
433 @@ -72,8 +72,8 @@ if(BUILD_TESTING)
434 target_link_libraries(
442 gtest_add_tests(TARGET func_traits_test SOURCES func_traits_test.cc)
444 @@ -81,8 +81,8 @@ if(BUILD_TESTING)
445 target_link_libraries(
453 gtest_add_tests(TARGET func_wrap_test SOURCES func_wrap_test.cc)
455 @@ -90,8 +90,8 @@ if(BUILD_TESTING)
456 target_link_libraries(
464 gtest_add_tests(TARGET tuple_tools_test SOURCES tuple_tools_test.cc)
466 diff --git a/simulate/cmake/SimulateDependencies.cmake b/simulate/cmake/SimulateDependencies.cmake
467 index 5141406c..75ff7884 100644
468 --- a/simulate/cmake/SimulateDependencies.cmake
469 +++ b/simulate/cmake/SimulateDependencies.cmake
470 @@ -81,10 +81,6 @@ findorfetch(
475 - https://github.com/glfw/glfw.git
477 - ${MUJOCO_DEP_VERSION_glfw3}
481 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
482 index 122760a9..ddd90819 100644
483 --- a/test/CMakeLists.txt
484 +++ b/test/CMakeLists.txt
485 @@ -30,7 +30,7 @@ macro(mujoco_test name)
488 add_executable(${name} ${name}.cc)
489 - target_link_libraries(${name} gtest_main mujoco)
490 + target_link_libraries(${name} GTest::gtest_main mujoco)
491 target_include_directories(${name} PRIVATE ${MUJOCO_TEST_INCLUDE})
492 set_target_properties(${name} PROPERTIES BUILD_RPATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
493 # gtest_discover_tests is recommended over gtest_add_tests, but has some issues in Windows.
494 @@ -60,20 +60,20 @@ target_link_libraries(
495 absl::synchronization
504 target_include_directories(fixture PRIVATE ${mujoco_SOURCE_DIR}/include gmock)
506 mujoco_test(fixture_test)
507 -target_link_libraries(fixture_test fixture gmock)
508 +target_link_libraries(fixture_test fixture GTest::gmock)
510 mujoco_test(header_test)
511 -target_link_libraries(header_test fixture gmock)
512 +target_link_libraries(fixture_test fixture GTest::gmock)
514 mujoco_test(pipeline_test)
515 -target_link_libraries(pipeline_test fixture gmock)
516 +target_link_libraries(fixture_test fixture GTest::gmock)
518 add_subdirectory(benchmark)
519 add_subdirectory(engine)