MujocoDependencies.cmake 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. # Copyright 2021 DeepMind Technologies Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # https://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Build configuration for third party libraries used in MuJoCo.
  15. set(MUJOCO_DEP_VERSION_lodepng
  16. b4ed2cd7ecf61d29076169b49199371456d4f90b
  17. CACHE STRING "Version of `lodepng` to be fetched."
  18. )
  19. set(MUJOCO_DEP_VERSION_tinyxml2
  20. 9a89766acc42ddfa9e7133c7d81a5bda108a0ade
  21. CACHE STRING "Version of `tinyxml2` to be fetched."
  22. )
  23. set(MUJOCO_DEP_VERSION_tinyobjloader
  24. 1421a10d6ed9742f5b2c1766d22faa6cfbc56248
  25. CACHE STRING "Version of `tinyobjloader` to be fetched."
  26. )
  27. set(MUJOCO_DEP_VERSION_MarchingCubeCpp
  28. f03a1b3ec29b1d7d865691ca8aea4f1eb2c2873d
  29. CACHE STRING "Version of `MarchingCubeCpp` to be fetched."
  30. )
  31. set(MUJOCO_DEP_VERSION_ccd
  32. 7931e764a19ef6b21b443376c699bbc9c6d4fba8 # v2.1
  33. CACHE STRING "Version of `ccd` to be fetched."
  34. )
  35. set(MUJOCO_DEP_VERSION_qhull
  36. 0c8fc90d2037588024d9964515c1e684f6007ecc
  37. CACHE STRING "Version of `qhull` to be fetched."
  38. )
  39. set(MUJOCO_DEP_VERSION_Eigen3
  40. b396a6fbb2e173f52edb3360485dedf3389ef830
  41. CACHE STRING "Version of `Eigen3` to be fetched."
  42. )
  43. set(MUJOCO_DEP_VERSION_abseil
  44. 4447c7562e3bc702ade25105912dce503f0c4010 # LTS 20240722.0
  45. CACHE STRING "Version of `abseil` to be fetched."
  46. )
  47. set(MUJOCO_DEP_VERSION_gtest
  48. b514bdc898e2951020cbdca1304b75f5950d1f59 # v1.15.2
  49. CACHE STRING "Version of `gtest` to be fetched."
  50. )
  51. set(MUJOCO_DEP_VERSION_benchmark
  52. 7c8ed6b082aa3c7a3402f18e50da4480421d08fd # v1.8.4
  53. CACHE STRING "Version of `benchmark` to be fetched."
  54. )
  55. set(MUJOCO_DEP_VERSION_sdflib
  56. 1927bee6bb8225258a39c8cbf14e18a4d50409ae
  57. CACHE STRING "Version of `SdfLib` to be fetched."
  58. )
  59. mark_as_advanced(MUJOCO_DEP_VERSION_lodepng)
  60. mark_as_advanced(MUJOCO_DEP_VERSION_MarchingCubeCpp)
  61. mark_as_advanced(MUJOCO_DEP_VERSION_tinyxml2)
  62. mark_as_advanced(MUJOCO_DEP_VERSION_tinyobjloader)
  63. mark_as_advanced(MUJOCO_DEP_VERSION_ccd)
  64. mark_as_advanced(MUJOCO_DEP_VERSION_qhull)
  65. mark_as_advanced(MUJOCO_DEP_VERSION_Eigen3)
  66. mark_as_advanced(MUJOCO_DEP_VERSION_abseil)
  67. mark_as_advanced(MUJOCO_DEP_VERSION_gtest)
  68. mark_as_advanced(MUJOCO_DEP_VERSION_benchmark)
  69. mark_as_advanced(MUJOCO_DEP_VERSION_sdflib)
  70. include(FetchContent)
  71. include(FindOrFetch)
  72. # Override the BUILD_SHARED_LIBS setting, just for building third party libs (since we always want
  73. # static libraries). The ccd CMakeLists.txt doesn't expose an option to build a static ccd library,
  74. # unless BUILD_SHARED_LIBS is set.
  75. # We force all the dependencies to be compiled as static libraries.
  76. # TODO(fraromano) Revisit this choice when adding support for install.
  77. set(BUILD_SHARED_LIBS_OLD ${BUILD_SHARED_LIBS})
  78. set(BUILD_SHARED_LIBS
  79. OFF
  80. CACHE INTERNAL "Build SHARED libraries"
  81. )
  82. if(NOT TARGET lodepng)
  83. FetchContent_Declare(
  84. lodepng
  85. GIT_REPOSITORY https://github.com/lvandeve/lodepng.git
  86. GIT_TAG ${MUJOCO_DEP_VERSION_lodepng}
  87. )
  88. FetchContent_GetProperties(lodepng)
  89. if(NOT lodepng_POPULATED)
  90. FetchContent_Populate(lodepng)
  91. # This is not a CMake project.
  92. set(LODEPNG_SRCS ${lodepng_SOURCE_DIR}/lodepng.cpp)
  93. set(LODEPNG_HEADERS ${lodepng_SOURCE_DIR}/lodepng.h)
  94. add_library(lodepng STATIC ${LODEPNG_HEADERS} ${LODEPNG_SRCS})
  95. target_compile_options(lodepng PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
  96. target_link_options(lodepng PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
  97. target_include_directories(lodepng PUBLIC ${lodepng_SOURCE_DIR})
  98. endif()
  99. endif()
  100. if(NOT TARGET marchingcubecpp)
  101. FetchContent_Declare(
  102. marchingcubecpp
  103. GIT_REPOSITORY https://github.com/aparis69/MarchingCubeCpp.git
  104. GIT_TAG ${MUJOCO_DEP_VERSION_MarchingCubeCpp}
  105. )
  106. FetchContent_GetProperties(marchingcubecpp)
  107. if(NOT marchingcubecpp_POPULATED)
  108. FetchContent_Populate(marchingcubecpp)
  109. include_directories(${marchingcubecpp_SOURCE_DIR})
  110. endif()
  111. endif()
  112. set(QHULL_ENABLE_TESTING OFF)
  113. findorfetch(
  114. USE_SYSTEM_PACKAGE
  115. OFF
  116. PACKAGE_NAME
  117. qhull
  118. LIBRARY_NAME
  119. qhull
  120. GIT_REPO
  121. https://github.com/qhull/qhull.git
  122. GIT_TAG
  123. ${MUJOCO_DEP_VERSION_qhull}
  124. TARGETS
  125. qhull
  126. EXCLUDE_FROM_ALL
  127. )
  128. # MuJoCo includes a file from libqhull_r which is not exported by the qhull include directories.
  129. # Add it to the target.
  130. target_include_directories(
  131. qhullstatic_r INTERFACE $<BUILD_INTERFACE:${qhull_SOURCE_DIR}/src/libqhull_r>
  132. )
  133. target_compile_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
  134. target_link_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
  135. set(tinyxml2_BUILD_TESTING OFF)
  136. findorfetch(
  137. USE_SYSTEM_PACKAGE
  138. OFF
  139. PACKAGE_NAME
  140. tinyxml2
  141. LIBRARY_NAME
  142. tinyxml2
  143. GIT_REPO
  144. https://github.com/leethomason/tinyxml2.git
  145. GIT_TAG
  146. ${MUJOCO_DEP_VERSION_tinyxml2}
  147. TARGETS
  148. tinyxml2
  149. EXCLUDE_FROM_ALL
  150. )
  151. target_compile_options(tinyxml2 PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
  152. target_link_options(tinyxml2 PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
  153. findorfetch(
  154. USE_SYSTEM_PACKAGE
  155. OFF
  156. PACKAGE_NAME
  157. tinyobjloader
  158. LIBRARY_NAME
  159. tinyobjloader
  160. GIT_REPO
  161. https://github.com/tinyobjloader/tinyobjloader.git
  162. GIT_TAG
  163. ${MUJOCO_DEP_VERSION_tinyobjloader}
  164. TARGETS
  165. tinyobjloader
  166. EXCLUDE_FROM_ALL
  167. )
  168. option(SDFLIB_USE_ASSIMP OFF)
  169. option(SDFLIB_USE_OPENMP OFF)
  170. option(SDFLIB_USE_ENOKI OFF)
  171. findorfetch(
  172. USE_SYSTEM_PACKAGE
  173. OFF
  174. PACKAGE_NAME
  175. sdflib
  176. LIBRARY_NAME
  177. sdflib
  178. GIT_REPO
  179. https://github.com/UPC-ViRVIG/SdfLib.git
  180. GIT_TAG
  181. ${MUJOCO_DEP_VERSION_sdflib}
  182. TARGETS
  183. SdfLib
  184. EXCLUDE_FROM_ALL
  185. )
  186. target_compile_options(SdfLib PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
  187. target_link_options(SdfLib PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
  188. set(ENABLE_DOUBLE_PRECISION ON)
  189. set(CCD_HIDE_ALL_SYMBOLS ON)
  190. findorfetch(
  191. USE_SYSTEM_PACKAGE
  192. OFF
  193. PACKAGE_NAME
  194. ccd
  195. LIBRARY_NAME
  196. ccd
  197. GIT_REPO
  198. https://github.com/danfis/libccd.git
  199. GIT_TAG
  200. ${MUJOCO_DEP_VERSION_ccd}
  201. TARGETS
  202. ccd
  203. EXCLUDE_FROM_ALL
  204. )
  205. target_compile_options(ccd PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
  206. target_link_options(ccd PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
  207. # libCCD has an unconditional `#define _CRT_SECURE_NO_WARNINGS` on Windows.
  208. # TODO(stunya): Remove this after https://github.com/danfis/libccd/pull/77 is merged.
  209. if(WIN32)
  210. if(MSVC)
  211. # C4005 is the MSVC equivalent of -Wmacro-redefined.
  212. target_compile_options(ccd PRIVATE /wd4005)
  213. else()
  214. target_compile_options(ccd PRIVATE -Wno-macro-redefined)
  215. endif()
  216. endif()
  217. if(MUJOCO_BUILD_TESTS)
  218. set(ABSL_PROPAGATE_CXX_STD ON)
  219. # This specific version of Abseil does not have the following variable. We need to work with BUILD_TESTING
  220. set(BUILD_TESTING_OLD ${BUILD_TESTING})
  221. set(BUILD_TESTING
  222. OFF
  223. CACHE INTERNAL "Build tests."
  224. )
  225. set(ABSL_BUILD_TESTING OFF)
  226. findorfetch(
  227. USE_SYSTEM_PACKAGE
  228. OFF
  229. PACKAGE_NAME
  230. absl
  231. LIBRARY_NAME
  232. abseil-cpp
  233. GIT_REPO
  234. https://github.com/abseil/abseil-cpp.git
  235. GIT_TAG
  236. ${MUJOCO_DEP_VERSION_abseil}
  237. TARGETS
  238. absl::core_headers
  239. EXCLUDE_FROM_ALL
  240. )
  241. set(BUILD_TESTING
  242. ${BUILD_TESTING_OLD}
  243. CACHE BOOL "Build tests." FORCE
  244. )
  245. # Avoid linking errors on Windows by dynamically linking to the C runtime.
  246. set(gtest_force_shared_crt
  247. ON
  248. CACHE BOOL "" FORCE
  249. )
  250. findorfetch(
  251. USE_SYSTEM_PACKAGE
  252. OFF
  253. PACKAGE_NAME
  254. GTest
  255. LIBRARY_NAME
  256. googletest
  257. GIT_REPO
  258. https://github.com/google/googletest.git
  259. GIT_TAG
  260. ${MUJOCO_DEP_VERSION_gtest}
  261. TARGETS
  262. gtest
  263. gmock
  264. gtest_main
  265. EXCLUDE_FROM_ALL
  266. )
  267. set(BENCHMARK_EXTRA_FETCH_ARGS "")
  268. if(WIN32 AND NOT MSVC)
  269. set(BENCHMARK_EXTRA_FETCH_ARGS
  270. PATCH_COMMAND
  271. "sed"
  272. "-i"
  273. "-e"
  274. "s/-std=c++11/-std=c++14/g"
  275. "-e"
  276. "s/HAVE_CXX_FLAG_STD_CXX11/HAVE_CXX_FLAG_STD_CXX14/g"
  277. "${CMAKE_BINARY_DIR}/_deps/benchmark-src/CMakeLists.txt"
  278. )
  279. endif()
  280. set(BENCHMARK_ENABLE_TESTING OFF)
  281. findorfetch(
  282. USE_SYSTEM_PACKAGE
  283. OFF
  284. PACKAGE_NAME
  285. benchmark
  286. LIBRARY_NAME
  287. benchmark
  288. GIT_REPO
  289. https://github.com/google/benchmark.git
  290. GIT_TAG
  291. ${MUJOCO_DEP_VERSION_benchmark}
  292. TARGETS
  293. benchmark::benchmark
  294. benchmark::benchmark_main
  295. ${BENCHMARK_EXTRA_FETCH_ARGS}
  296. EXCLUDE_FROM_ALL
  297. )
  298. endif()
  299. if(MUJOCO_TEST_PYTHON_UTIL)
  300. add_compile_definitions(EIGEN_MPL2_ONLY)
  301. if(NOT TARGET eigen)
  302. # Support new IN_LIST if() operator.
  303. set(CMAKE_POLICY_DEFAULT_CMP0057 NEW)
  304. FetchContent_Declare(
  305. Eigen3
  306. GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
  307. GIT_TAG ${MUJOCO_DEP_VERSION_Eigen3}
  308. )
  309. FetchContent_GetProperties(Eigen3)
  310. if(NOT Eigen3_POPULATED)
  311. FetchContent_Populate(Eigen3)
  312. # Mark the library as IMPORTED as a workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/15415
  313. add_library(Eigen3::Eigen INTERFACE IMPORTED)
  314. set_target_properties(
  315. Eigen3::Eigen PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${eigen3_SOURCE_DIR}"
  316. )
  317. endif()
  318. endif()
  319. endif()
  320. # Reset BUILD_SHARED_LIBS to its previous value
  321. set(BUILD_SHARED_LIBS
  322. ${BUILD_SHARED_LIBS_OLD}
  323. CACHE BOOL "Build MuJoCo as a shared library" FORCE
  324. )