Initial open sourcing of MuJoCo.

PiperOrigin-RevId: 450374687
Change-Id: Ie3225a46ce095fc28ae8e63c326a640261f562bb
This commit is contained in:
Saran Tunyasuvunakool
2022-05-23 01:08:10 -07:00
committed by Copybara-Service
parent 0e5d062302
commit 1913a02b40
275 changed files with 99607 additions and 935 deletions
+177
View File
@@ -0,0 +1,177 @@
# Copyright 2022 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#.rst:
# duplicate_target
# ----------------------
#
# Duplicates the specified target.
#
# duplicate_target(TARGET target NEW_TARGET_NAME new_target_name)
#
# Duplicates the specified target by creating a new target with the name
# specified by ``NEW_TARGET_NAME`` and copying all properties defined by
# ``TARGET``.
# The command has the following parameters:
#
# Arguments:
# - ``TARGET`` Target to be duplicated.
# - ``NEW_TARGET_NAME`` name of the new target.
#
if(COMMAND duplicate_target)
return()
endif()
macro(duplicate_target)
# Parse arguments.
set(options)
set(one_value_args TARGET NEW_TARGET_NAME)
set(multi_value_args)
cmake_parse_arguments(
_ARGS
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN}
)
# Check required variables are defined.
if(NOT _ARGS_TARGET)
message(FATAL_ERROR "duplicate_target: TARGET must be specified.")
endif()
if(NOT _ARGS_NEW_TARGET_NAME)
message(FATAL_ERROR "duplicate_target: NEW_TARGET_NAME must be specified.")
endif()
# Check for the target to exist.
if(NOT TARGET ${_ARGS_TARGET})
message(FATAL_ERROR "duplicate_target: TARGET ${_ARGS_TARGET} not found.")
endif()
# Non-exausitve list.
set(PROPERTIES_TO_SKIP)
get_target_property(TARGET_TYPE ${_ARGS_TARGET} TYPE)
if(${TARGET_TYPE} STREQUAL "STATIC_LIBRARY")
add_library(${_ARGS_NEW_TARGET_NAME} STATIC)
list(APPEND PROPERTIES_TO_SKIP "IMPORTED_GLOBAL")
elseif(${TARGET_TYPE} STREQUAL "SHARED_LIBRARY")
add_library(${_ARGS_NEW_TARGET_NAME} SHARED)
list(APPEND PROPERTIES_TO_SKIP "IMPORTED_GLOBAL")
elseif(${TARGET_TYPE} STREQUAL "OBJECT_LIBRARY")
add_library(${_ARGS_NEW_TARGET_NAME} OBJECT)
list(APPEND PROPERTIES_TO_SKIP "IMPORTED_GLOBAL")
elseif(${TARGET_TYPE} STREQUAL "INTERFACE_LIBRARY")
add_library(${_ARGS_NEW_TARGET_NAME} INTERFACE)
elseif(${TARGET_TYPE} STREQUAL "EXECUTABLE")
add_executable(${_ARGS_NEW_TARGET_NAME})
list(APPEND PROPERTIES_TO_SKIP "IMPORTED_GLOBAL")
endif()
set(IGNORED_PROPERTIES "HEADER_SETS;INTERFACE_HEADER_SETS;NAME;TYPE")
# Get all CMake target properties.
if(NOT CMAKE_ALL_PROPERTY_LIST)
execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE ALL_PROPERTIES)
# Convert command output into a CMake list
string(
REGEX
REPLACE ";"
"\\\\;"
ALL_PROPERTIES
"${ALL_PROPERTIES}"
)
string(
REGEX
REPLACE "\n"
";"
ALL_PROPERTIES
"${ALL_PROPERTIES}"
)
# Post process the properties. We:
# - Remove all properties listed in ``IGNORED_PROPERTIES``.
# - Remove LOCATION as it should not be accessed, See https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i
# - Substitute <CONFIG> with all the possible build types. This is needed for multi-config generators as they can change the type of build without invoking again CMake.
set(CMAKE_ALL_PROPERTY_LIST "")
foreach(PROPERTY ${ALL_PROPERTIES})
# Skip reading the LOCAION property as they should not be read.
# See https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i
if(PROPERTY STREQUAL "LOCATION"
OR PROPERTY MATCHES "^LOCATION_"
OR PROPERTY MATCHES "_LOCATION$"
)
continue()
endif()
set(_ignore OFF)
foreach(_pro ${IGNORED_PROPERTIES})
if(PROPERTY STREQUAL ${_pro})
set(_ignore ON)
break()
endif()
endforeach()
if(_ignore)
continue()
endif()
string(FIND ${PROPERTY} "<CONFIG>" FOUND)
if(${FOUND} EQUAL -1)
# Simply append the property.
list(APPEND CMAKE_ALL_PROPERTY_LIST ${PROPERTY})
else()
# Iterate on the build types to add the correct property.
foreach(BUILD_TYPE ${BUILD_TYPES})
string(
REPLACE "<CONFIG>"
"${BUILD_TYPE}"
CONFIG_PROPERTY
${PROPERTY}
)
list(APPEND CMAKE_ALL_PROPERTY_LIST ${CONFIG_PROPERTY})
endforeach()
endif()
endforeach()
endif()
foreach(PROPERTY ${CMAKE_ALL_PROPERTY_LIST})
# Search if we should skip this property.
list(
FIND
PROPERTIES_TO_SKIP
${PROPERTY}
SHOULD_SKIP
)
if(${SHOULD_SKIP} GREATER_EQUAL 0)
continue()
endif()
# First check if the property was set on the target
get_property(
PROPERTY_FOUND
TARGET ${_ARGS_TARGET}
PROPERTY ${PROPERTY}
SET
)
if(PROPERTY_FOUND)
get_target_property(PROPERTY_VALUE ${_ARGS_TARGET} ${PROPERTY})
set_target_properties(${_ARGS_NEW_TARGET_NAME} PROPERTIES ${PROPERTY} "${PROPERTY_VALUE}")
endif()
endforeach()
endmacro()
+25 -14
View File
@@ -31,8 +31,9 @@
#
# Arguments:
# - ``USE_SYSTEM_PACKAGE`` one-value argument on whether to search for the
# package in the system (ON) or whether to fetch the library from a git
# repository (OFF).
# package in the system (ON) or whether to fetch the library using
# FetchContent from the specified Git repository (OFF). Note that
# FetchContent variables will override this behaviour.
# - ``PACKAGE_NAME`` name of the system-package. Ignored if
# ``USE_SYSTEM_PACKAGE`` is ``OFF``.
# - ``LIBRARY_NAME`` name of the library. Ignored if
@@ -41,9 +42,19 @@
# ``USE_SYSTEM_PACKAGE`` is ``ON``.
# - ``GIT_TAG`` tag reference when fetching the library from the git
# repository. Ignored if ``USE_SYSTEM_PACKAGE`` is ``ON``.
# - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an
# update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add
# for details on the parameter.
# - ``TARGETS`` list of targets to be satisfied. If any of these targets are
# not currently defined, this macro will attempt to either find or fetch the
# package.
# - ``EXCLUDE_FROM_ALL`` if specified, the targets are not added to the ``all``
# metatarget.
#
# Note: if ``USE_SYSTEM_PACKAGE`` is ``OFF``, FetchContent will be used to
# retrieve the specified targets. It is possible to specify any variable in
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variables to
# override this macro behaviour.
if(COMMAND FindOrFetch)
return()
@@ -76,10 +87,14 @@ macro(FindOrFetch)
if(NOT _ARGS_TARGETS)
message(FATAL_ERROR "mujoco::FindOrFetch: TARGETS must be specified.")
endif()
set(targets_found TRUE)
message(CHECK_START
"mujoco::FindOrFetch: checking for targets in package `${_ARGS_PACKAGE_NAME}`"
)
foreach(target ${_ARGS_TARGETS})
if(NOT TARGET ${target})
message(STATUS "mujoco::FindOrFetch: target `${target}` not defined.")
message(CHECK_FAIL "target `${target}` not defined.")
set(targets_found FALSE)
break()
endif()
@@ -88,16 +103,14 @@ macro(FindOrFetch)
# If targets are not found, use `find_package` or `FetchContent...` to get it.
if(NOT targets_found)
if(${_ARGS_USE_SYSTEM_PACKAGE})
message(
STATUS
"mujoco::FindOrFetch: Attempting to find `${_ARGS_PACKAGE_NAME}` in system packages..."
message(CHECK_START
"mujoco::FindOrFetch: finding `${_ARGS_PACKAGE_NAME}` in system packages..."
)
find_package(${_ARGS_PACKAGE_NAME} REQUIRED)
message(STATUS "mujoco::FindOrFetch: Found `${_ARGS_PACKAGE_NAME}` in system packages.")
message(CHECK_PASS "found")
else()
message(
STATUS
"mujoco::FindOrFetch: Attempting to fetch `${_ARGS_LIBRARY_NAME}` from `${_ARGS_GIT_REPO}`..."
message(CHECK_START
"mujoco::FindOrFetch: Using FetchContent to retrieve `${_ARGS_LIBRARY_NAME}`"
)
FetchContent_Declare(
${_ARGS_LIBRARY_NAME}
@@ -118,11 +131,9 @@ macro(FindOrFetch)
else()
FetchContent_MakeAvailable(${_ARGS_LIBRARY_NAME})
endif()
message(
STATUS "mujoco::FindOrFetch: Fetched `${_ARGS_LIBRARY_NAME}` from `${_ARGS_GIT_REPO}`."
)
message(CHECK_PASS "Done")
endif()
else()
message(STATUS "mujoco::FindOrFetch: `${_ARGS_PACKAGE_NAME}` targets found.")
message(CHECK_PASS "found")
endif()
endmacro()
+327
View File
@@ -0,0 +1,327 @@
# Copyright 2021 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Build configuration for third party libraries used in MuJoCo.
# Override the BUILD_SHARED_LIBS setting, just for building third party libs (since we always want
# static libraries). The ccd CMakeLists.txt doesn't expose an option to build a static ccd library,
# unless BUILD_SHARED_LIBS is set.
set(MUJOCO_DEP_VERSION_lodepng
48e5364ef48ec2408f44c727657ac1b6703185f8
CACHE STRING "Version of `lodepng` to be fetched."
)
set(MUJOCO_DEP_VERSION_tinyxml2
1dee28e51f9175a31955b9791c74c430fe13dc82 # 9.0.0
CACHE STRING "Version of `tinyxml2` to be fetched."
)
set(MUJOCO_DEP_VERSION_tinyobjloader
1421a10d6ed9742f5b2c1766d22faa6cfbc56248
CACHE STRING "Version of `tinyobjloader` to be fetched."
)
set(MUJOCO_DEP_VERSION_ccd
7931e764a19ef6b21b443376c699bbc9c6d4fba8 # v2.1
CACHE STRING "Version of `ccd` to be fetched."
)
set(MUJOCO_DEP_VERSION_qhull
3df027b91202cf179f3fba3c46eebe65bbac3790
CACHE STRING "Version of `qhull` to be fetched."
)
set(MUJOCO_DEP_VERSION_Eigen3
b02c384ef4e8eba7b8bdef16f9dc6f8f4d6a6b2b
CACHE STRING "Version of `Eigen3` to be fetched."
)
set(MUJOCO_DEP_VERSION_abseil
78f9680225b9792c26dfdd99d0bd26c96de53dd4 # Fixes universal builds for macOS
CACHE STRING "Version of `abseil` to be fetched."
)
set(MUJOCO_DEP_VERSION_gtest
e2239ee6043f73722e7aa812a459f54a28552929 # release-1.11.0
CACHE STRING "Version of `gtest` to be fetched."
)
set(MUJOCO_DEP_VERSION_benchmark
0d98dba29d66e93259db7daa53a9327df767a415 # v1.6.1
CACHE STRING "Version of `benchmark` to be fetched."
)
mark_as_advanced(MUJOCO_DEP_VERSION_lodepng)
mark_as_advanced(MUJOCO_DEP_VERSION_tinyxml2)
mark_as_advanced(MUJOCO_DEP_VERSION_tinyobjloader)
mark_as_advanced(MUJOCO_DEP_VERSION_ccd)
mark_as_advanced(MUJOCO_DEP_VERSION_qhull)
mark_as_advanced(MUJOCO_DEP_VERSION_Eigen3)
mark_as_advanced(MUJOCO_DEP_VERSION_abseil)
mark_as_advanced(MUJOCO_DEP_VERSION_gtest)
mark_as_advanced(MUJOCO_DEP_VERSION_benchmark)
include(FetchContent)
include(FindOrFetch)
# We force all the dependencies to be compiled as static libraries.
# TODO(fraromano) Revisit this choice when adding support for install.
set(BUILD_SHARED_LIBS_OLD ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS
OFF
CACHE INTERNAL "Build SHARED libraries"
)
if(NOT TARGET lodepng)
FetchContent_Declare(
lodepng
GIT_REPOSITORY https://github.com/lvandeve/lodepng.git
GIT_TAG ${MUJOCO_DEP_VERSION_lodepng}
)
FetchContent_GetProperties(lodepng)
if(NOT lodepng_POPULATED)
FetchContent_Populate(lodepng)
# This is not a CMake project.
set(LODEPNG_SRCS ${lodepng_SOURCE_DIR}/lodepng.cpp)
set(LODEPNG_HEADERS ${lodepng_SOURCE_DIR}/lodepng.h)
add_library(lodepng STATIC ${LODEPNG_HEADERS} ${LODEPNG_SRCS})
target_compile_options(lodepng PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
target_link_options(lodepng PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
target_include_directories(lodepng PUBLIC ${lodepng_SOURCE_DIR})
endif()
endif()
# TODO(fraromano) We fetch qhull before the other libraries as it needs to go before until https://github.com/qhull/qhull/pull/111 is merged.
set(QHULL_ENABLE_TESTING OFF)
# We need Git to apply the patch using git apply.
find_package(Git REQUIRED)
findorfetch(
USE_SYSTEM_PACKAGE
OFF
PACKAGE_NAME
qhull
LIBRARY_NAME
qhull
GIT_REPO
https://github.com/qhull/qhull.git
GIT_TAG
${MUJOCO_DEP_VERSION_qhull}
TARGETS
qhull
# TODO(fraromano) Remove when https://github.com/qhull/qhull/pull/112 is merged.
# Do not fail if patch fails. This will happen the second time we run CMake as the sources will be already patched.
PATCH_COMMAND
"${GIT_EXECUTABLE}"
"apply"
"-q"
"${PROJECT_SOURCE_DIR}/cmake/qhull_fix_testing.patch"
"||"
"${CMAKE_COMMAND}"
"-E"
"true"
EXCLUDE_FROM_ALL
)
# MuJoCo includes a file from libqhull_r which is not exported by the qhull include directories.
# Add it to the target.
target_include_directories(
qhullstatic_r INTERFACE $<BUILD_INTERFACE:${qhull_SOURCE_DIR}/src/libqhull_r>
)
target_compile_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
target_link_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
set(tinyxml2_BUILD_TESTING OFF)
findorfetch(
USE_SYSTEM_PACKAGE
OFF
PACKAGE_NAME
tinyxml2
LIBRARY_NAME
tinyxml2
GIT_REPO
https://github.com/leethomason/tinyxml2.git
GIT_TAG
${MUJOCO_DEP_VERSION_tinyxml2}
TARGETS
tinyxml2
EXCLUDE_FROM_ALL
)
target_compile_options(tinyxml2 PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
target_link_options(tinyxml2 PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
findorfetch(
USE_SYSTEM_PACKAGE
OFF
PACKAGE_NAME
tinyobjloader
LIBRARY_NAME
tinyobjloader
GIT_REPO
https://github.com/tinyobjloader/tinyobjloader.git
GIT_TAG
${MUJOCO_DEP_VERSION_tinyobjloader}
TARGETS
tinyobjloader
EXCLUDE_FROM_ALL
)
set(ENABLE_DOUBLE_PRECISION ON)
set(CCD_HIDE_ALL_SYMBOLS ON)
findorfetch(
USE_SYSTEM_PACKAGE
OFF
PACKAGE_NAME
ccd
LIBRARY_NAME
ccd
GIT_REPO
https://github.com/danfis/libccd.git
GIT_TAG
${MUJOCO_DEP_VERSION_ccd}
TARGETS
ccd
EXCLUDE_FROM_ALL
)
target_compile_options(ccd PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
target_link_options(ccd PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
# libCCD has an unconditional `#define _CRT_SECURE_NO_WARNINGS` on Windows.
# TODO(stunya): Remove this after https://github.com/danfis/libccd/pull/77 is merged.
if(WIN32)
if(MSVC)
# C4005 is the MSVC equivalent of -Wmacro-redefined.
target_compile_options(ccd PRIVATE /wd4005)
else()
target_compile_options(ccd PRIVATE -Wno-macro-redefined)
endif()
endif()
if(MUJOCO_BUILD_TESTS)
set(ABSL_PROPAGATE_CXX_STD ON)
# This specific version of Abseil does not have the following variable. We need to work with BUILD_TESTING
set(BUILD_TESTING_OLD ${BUILD_TESTING})
set(BUILD_TESTING
OFF
CACHE INTERNAL "Build tests."
)
set(ABSL_BUILD_TESTING OFF)
findorfetch(
USE_SYSTEM_PACKAGE
OFF
PACKAGE_NAME
absl
LIBRARY_NAME
abseil-cpp
GIT_REPO
https://github.com/abseil/abseil-cpp.git
GIT_TAG
${MUJOCO_DEP_VERSION_abseil}
TARGETS
absl::core_headers
EXCLUDE_FROM_ALL
)
set(BUILD_TESTING
${BUILD_TESTING_OLD}
CACHE BOOL "Build tests." FORCE
)
# Avoid linking errors on Windows by dynamically linking to the C runtime.
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE
)
findorfetch(
USE_SYSTEM_PACKAGE
OFF
PACKAGE_NAME
GTest
LIBRARY_NAME
googletest
GIT_REPO
https://github.com/google/googletest.git
GIT_TAG
${MUJOCO_DEP_VERSION_gtest}
TARGETS
gtest
gmock
gtest_main
EXCLUDE_FROM_ALL
)
set(BENCHMARK_EXTRA_FETCH_ARGS "")
if(WIN32 AND NOT MSVC)
set(BENCHMARK_EXTRA_FETCH_ARGS
PATCH_COMMAND
"sed"
"-i"
"-e"
"s/-std=c++11/-std=c++14/g"
"-e"
"s/HAVE_CXX_FLAG_STD_CXX11/HAVE_CXX_FLAG_STD_CXX14/g"
"${CMAKE_BINARY_DIR}/_deps/benchmark-src/CMakeLists.txt"
)
endif()
set(BENCHMARK_ENABLE_TESTING OFF)
findorfetch(
USE_SYSTEM_PACKAGE
OFF
PACKAGE_NAME
benchmark
LIBRARY_NAME
benchmark
GIT_REPO
https://github.com/google/benchmark.git
GIT_TAG
${MUJOCO_DEP_VERSION_benchmark}
TARGETS
benchmark::benchmark
benchmark::benchmark_main
${BENCHMARK_EXTRA_FETCH_ARGS}
EXCLUDE_FROM_ALL
)
endif()
if(MUJOCO_TEST_PYTHON_UTIL)
add_compile_definitions(EIGEN_MPL2_ONLY)
if(NOT TARGET eigen)
# Support new IN_LIST if() operator.
set(CMAKE_POLICY_DEFAULT_CMP0057 NEW)
FetchContent_Declare(
Eigen3
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG ${MUJOCO_DEP_VERSION_Eigen3}
)
FetchContent_GetProperties(Eigen3)
if(NOT Eigen3_POPULATED)
FetchContent_Populate(Eigen3)
# Mark the library as IMPORTED as a workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/15415
add_library(Eigen3::Eigen INTERFACE IMPORTED)
set_target_properties(
Eigen3::Eigen PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${eigen3_SOURCE_DIR}"
)
endif()
endif()
endif()
# Reset BUILD_SHARED_LIBS to its previous value
set(BUILD_SHARED_LIBS
${BUILD_SHARED_LIBS_OLD}
CACHE BOOL "Build MuJoCo as a shared library" FORCE
)
+35
View File
@@ -0,0 +1,35 @@
# Copyright 2022 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
option(MUJOCO_HARDEN "Enable build hardening for MuJoCo." OFF)
if(MUJOCO_HARDEN
AND NOT
CMAKE_CXX_COMPILER_ID
MATCHES
".*Clang.*"
)
message(FATAL_ERROR "MUJOCO_HARDEN is only supported when building with Clang")
endif()
if(MUJOCO_HARDEN)
set(MUJOCO_HARDEN_COMPILE_OPTIONS -D_FORTIFY_SOURCE=2 -fstack-protector)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MUJOCO_HARDEN_LINK_OPTIONS -Wl,-bind_at_load)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(MUJOCO_HARDEN_LINK_OPTIONS -Wl,-z,relro -Wl,-z,now)
endif()
else()
set(MUJOCO_HARDEN_COMPILE_OPTIONS "")
set(MUJOCO_HARDEN_LINK_OPTIONS "")
endif()
+38
View File
@@ -0,0 +1,38 @@
# Copyright 2022 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if(APPLE)
# 10.12 is the oldest version of macOS that supports C++17, launched 2016.
set(MUJOCO_MACOSX_VERSION_MIN 10.12)
# We are setting the -mmacosx-version-min compiler flag directly rather than using the
# CMAKE_OSX_DEPLOYMENT_TARGET variable since we do not want to affect choice of SDK,
# and also we only want to apply the version restriction locally.
set(MUJOCO_MACOS_COMPILE_OPTIONS -mmacosx-version-min=${MUJOCO_MACOSX_VERSION_MIN}
-Werror=partial-availability -Werror=unguarded-availability
)
set(MUJOCO_MACOS_LINK_OPTIONS -mmacosx-version-min=${MUJOCO_MACOSX_VERSION_MIN}
-Wl,-no_weak_imports
)
else()
set(MUJOCO_MACOS_COMPILE_OPTIONS "")
set(MUJOCO_MACOS_LINK_OPTIONS "")
endif()
function(enforce_mujoco_macosx_min_version)
if(APPLE)
add_compile_options(${MUJOCO_MACOS_COMPILE_OPTIONS})
add_link_options(${MUJOCO_MACOS_LINK_OPTIONS})
endif()
endfunction()
+106
View File
@@ -0,0 +1,106 @@
# Copyright 2021 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Global compilation settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # For LLVM tooling
if(NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Choose the type of build, recommanded options are: Debug or Release" FORCE
)
endif()
set(BUILD_TYPES
"Debug"
"Release"
"MinSizeRel"
"RelWithDebInfo"
)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${BUILD_TYPES})
endif()
include(GNUInstallDirs)
# Change the default output directory in the build structure. This is not stricly needed, but helps
# running in Windows, such that all built executables have DLLs in the same folder as the .exe
# files.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
set(OpenGL_GL_PREFERENCE GLVND)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
if(MSVC)
add_compile_options(/Gy /Gw /Oi)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-fdata-sections -ffunction-sections)
endif()
# We default to shared library.
set(BUILD_SHARED_LIBS
ON
CACHE BOOL "Build Mujoco as shared library."
)
option(MUJOCO_ENABLE_AVX "Build binaries that require AVX instructions, if possible." ON)
option(MUJOCO_ENABLE_AVX_INTRINSICS "Make use of hand-written AVX intrinsics, if possible." ON)
option(MUJOCO_ENABLE_RPATH "Enable RPath support when installing Mujoco." ON)
mark_as_advanced(MUJOCO_ENABLE_RPATH)
if(MUJOCO_ENABLE_AVX)
include(CheckAvxSupport)
get_avx_compile_options(AVX_COMPILE_OPTIONS)
else()
set(AVX_COMPILE_OPTIONS)
endif()
option(MUJOCO_BUILD_MACOS_FRAMEWORKS "Build libraries as macOS Frameworks" OFF)
# Get some extra link options.
include(MujocoLinkOptions)
get_mujoco_extra_link_options(EXTRA_LINK_OPTIONS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT MSVC))
set(EXTRA_COMPILE_OPTIONS -Wall -Werror)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(EXTRA_COMPILE_OPTIONS
-Wno-int-in-bool-context
-Wno-maybe-uninitialized
-Wno-sign-compare
-Wno-stringop-overflow
-Wno-stringop-truncation
)
endif()
endif()
if(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()
include(MujocoHarden)
set(EXTRA_COMPILE_OPTIONS ${EXTRA_COMPILE_OPTIONS} ${MUJOCO_HARDEN_COMPILE_OPTIONS})
set(EXTRA_LINK_OPTIONS ${EXTRA_LINK_OPTIONS} ${MUJOCO_HARDEN_LINK_OPTIONS})
+188
View File
@@ -0,0 +1,188 @@
# Copyright 2022 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#[=======================================================================[.rst:
TargetAddRpath
----------------------
Add support to RPATH for the specified targets
.. command:: target_add_rpath
Add support to RPATH for the specified targets::
.. code-block:: cmake
target_add_rpath(target1 target2 ...
INSTALL_DIRECTORY install_directory
LIB_DIRS dir1 dir2 ...
[INSTALL_NAME_DIR [dir]]
[DEPENDS condition [condition]]
[USE_LINK_PATH])
This function setups the RPATH paths for the specified targets. The use of
RPATH allows to avoid using the (dangerous) environment variable
``LD_LIBRARY_PATH`` (or equivalent on macOS) when installing without absolute
paths.
By using RPATH the installation can be relocated as the linker will look for
(some of) the dependencies at run time.
The function has the following parameters:
Options:
- ``USE_LINK_PATH``: if defined, the function will set
``INSTALL_RPATH_USE_LINK_PATH`` on all the specified targets, i.e. CMake
will automatically adds to the RPATH the path to all the dependent
libraries defined outside this project.
Arguments:
- ``INSTALL_DIRECTORY`` The directory where the specified targets will be
installed.
- ``LIB_DIRS`` list of directories to be added a search path to the RPATH.
Note that the relative path between ``INSTALL_DIRECTORY`` and these
directories will be added to the RPATH.
- ``INSTALL_NAME_DIR`` directory where the libraries will be installed.
This variable will be used only if ``CMAKE_SKIP_RPATH`` or
``CMAKE_SKIP_INSTALL_RPATH`` is set to ``TRUE`` as it will set the
``INSTALL_NAME_DIR`` on all targets.
- ``DEPENDS`` list of conditions that should be ``TRUE`` to enable
RPATH, for example ``FOO; NOT BAR``.
Note: see https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
and https://gitlab.kitware.com/cmake/cmake/issues/16589 for further details.
#]=======================================================================]
if(COMMAND target_add_rpath)
return()
endif()
function(_get_system_dirs _output_var)
set(${_output_var}
${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}
PARENT_SCOPE
)
endfunction()
function(
_get_rpath_relative_path
_output_var
_bin_dir
_lib_dir
)
file(
RELATIVE_PATH
_rel_path
${_bin_dir}
${_lib_dir}
)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(${_output_var}
"@loader_path/${_rel_path}"
PARENT_SCOPE
)
else()
set(${_output_var}
"\$ORIGIN/${_rel_path}"
PARENT_SCOPE
)
endif()
endfunction()
function(target_add_rpath)
set(_options USE_LINK_PATH)
set(_oneValueArgs INSTALL_NAME_DIR INSTALL_DIRECTORY)
set(_multiValueArgs TARGETS LIB_DIRS DEPENDS)
cmake_parse_arguments(
_ARGS
"${_options}"
"${_oneValueArgs}"
"${_multiValueArgs}"
"${ARGN}"
)
# Handle Apple-specific installation directory. Note that this disable proper RPATH.
if(CMAKE_SKIP_RPATH OR CMAKE_SKIP_INSTALL_RPATH)
if(DEFINED _ARGS_INSTALL_NAME_DIR)
set_target_properties(${_ARGS_TARGETS} PROPERTIES INSTALL_NAME_DIR ${_ARGS_INSTALL_NAME_DIR})
endif()
endif()
# If RPATH is disabled, do nothing and return.
if(CMAKE_SKIP_RPATH OR (CMAKE_SKIP_INSTALL_RPATH AND CMAKE_SKIP_BUILD_RPATH))
return()
endif()
# Check if the user requested RPATH for the specified targets.
set(_enable_rpath ON)
if(DEFINED _ARGS_DEPENDS)
foreach(_cond ${_ARGS_DEPENDS})
string(
REGEX
REPLACE " +"
";"
_cond
"${_cond}"
)
if(NOT (${_cond}))
set(_enable_rpath OFF)
endif()
endforeach()
endif()
if(NOT _enable_rpath)
return()
endif()
# Now enable RPATH for the specified targets.
_get_system_dirs(_system_dirs)
# We do this per target to preserve the original rpath setting.
foreach(_target ${_ARGS_TARGETS})
get_target_property(_install_rpath ${_target} INSTALL_RPATH)
foreach(_lib_dir ${_ARGS_LIB_DIRS})
# Check if the specified library path is a system directory. These are always searched so we do
# not need to include them in the RPATH.
list(
FIND
_system_dirs
"${_lib_dir}"
is_system_dir
)
if("${is_system_dir}" STREQUAL "-1")
_get_rpath_relative_path(_bin_lib_rel_path ${_ARGS_INSTALL_DIRECTORY} ${_lib_dir})
list(APPEND _install_rpath ${_bin_lib_rel_path})
endif()
endforeach()
if(NOT
"${_install_rpath}"
STREQUAL
""
)
list(REMOVE_DUPLICATES _install_rpath)
endif()
set_target_properties(
${_target}
PROPERTIES INSTALL_RPATH ${_install_rpath}
INSTALL_RPATH_USE_LINK_PATH ${_ARGS_USE_LINK_PATH}
MACOSX_RPATH ON # This is ON by default.
)
endforeach()
endfunction()
+21
View File
@@ -0,0 +1,21 @@
#!/bin/bash
# Copyright 2021 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ -z "$1" ]; then
echo "Expecting an output directory. Got none." 1>&2
exit 1
fi
rm -rf "$1"
+24
View File
@@ -0,0 +1,24 @@
# Copyright 2021 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(OpenGL)
if(NOT TARGET mujoco AND NOT @PROJECT_NAME@_BINARY_DIR)
include("${CMAKE_CURRENT_LIST_DIR}/mujocoTargets.cmake")
endif()
check_required_components(mujoco)
+92
View File
@@ -0,0 +1,92 @@
From 2bf2d1f5151d0d36cd17dea03129bd9a825384c5 Mon Sep 17 00:00:00 2001
From: Francesco Romano <francesco.romano.1987@gmail.com>
Date: Fri, 6 May 2022 11:30:44 +0100
Subject: [PATCH] Add option to disable testing
---
CMakeLists.txt | 55 ++++++++++++++++++++++++++------------------------
1 file changed, 29 insertions(+), 26 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cd95ad0..6ff1c98 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -113,6 +113,7 @@ cmake_dependent_option(LINK_APPS_SHARED "Use shared library for linking applicat
"BUILD_SHARED_LIBS;BUILD_STATIC_LIBS"
${BUILD_SHARED_LIBS}
)
+option(QHULL_ENABLE_TESTING "Build and run tests" ON)
if(INCLUDE_INSTALL_DIR)
else()
@@ -147,6 +148,7 @@ message(STATUS "Build Type (CMAKE_BUILD_TYPE): ${CMAKE_BUILD_TYPE}")
message(STATUS "Build static libraries: ${BUILD_STATIC_LIBS}")
message(STATUS "Build shared library: ${BUILD_SHARED_LIBS}")
message(STATUS "Use shared library for linking apps: ${LINK_APPS_SHARED}")
+message(STATUS "Build tests: ${QHULL_ENABLE_TESTING}")
message(STATUS "To override these options, add -D{OPTION_NAME}=... to the cmake command")
message(STATUS " Build the debug targets -DCMAKE_BUILD_TYPE=Debug")
message(STATUS)
@@ -636,32 +638,33 @@ set_target_properties(user_egp PROPERTIES
# ---------------------------------------
# Define test
# ---------------------------------------
-
-enable_testing()
-add_test(NAME testqset
- COMMAND ./testqset 10000)
-add_test(NAME testqset_r
- COMMAND ./testqset_r 10000)
-add_test(NAME smoketest
- COMMAND sh -c "./rbox D4 | ./qhull Tv")
-add_test(NAME rbox-10-qhull
- COMMAND sh -c "./rbox 10 | ./qhull Tv")
-add_test(NAME rbox-10-qconvex
- COMMAND sh -c "./rbox 10 | ./qconvex Tv")
-add_test(NAME rbox-10-qdelaunay
- COMMAND sh -c "./rbox 10 | ./qdelaunay Tv")
-add_test(NAME rbox-10-qhalf
- COMMAND sh -c "./rbox 10 | ./qconvex FQ FV n Tv | ./qhalf Tv")
-add_test(NAME rbox-10-qvoronoi
- COMMAND sh -c "./rbox 10 | ./qvoronoi Tv")
-add_test(NAME user_eg
- COMMAND sh -c "./user_eg")
-add_test(NAME user_eg2
- COMMAND sh -c "./user_eg2")
-
-if(${BUILD_STATIC_LIBS})
- add_test(NAME user_eg3
- COMMAND sh -c "./user_eg3 rbox '10 D2' '2 D2' qhull 's p' facets")
+if (QHULL_ENABLE_TESTING)
+ enable_testing()
+ add_test(NAME testqset
+ COMMAND ./testqset 10000)
+ add_test(NAME testqset_r
+ COMMAND ./testqset_r 10000)
+ add_test(NAME smoketest
+ COMMAND sh -c "./rbox D4 | ./qhull Tv")
+ add_test(NAME rbox-10-qhull
+ COMMAND sh -c "./rbox 10 | ./qhull Tv")
+ add_test(NAME rbox-10-qconvex
+ COMMAND sh -c "./rbox 10 | ./qconvex Tv")
+ add_test(NAME rbox-10-qdelaunay
+ COMMAND sh -c "./rbox 10 | ./qdelaunay Tv")
+ add_test(NAME rbox-10-qhalf
+ COMMAND sh -c "./rbox 10 | ./qconvex FQ FV n Tv | ./qhalf Tv")
+ add_test(NAME rbox-10-qvoronoi
+ COMMAND sh -c "./rbox 10 | ./qvoronoi Tv")
+ add_test(NAME user_eg
+ COMMAND sh -c "./user_eg")
+ add_test(NAME user_eg2
+ COMMAND sh -c "./user_eg2")
+
+ if(${BUILD_STATIC_LIBS})
+ add_test(NAME user_eg3
+ COMMAND sh -c "./user_eg3 rbox '10 D2' '2 D2' qhull 's p' facets")
+ endif()
endif()
# ---------------------------------------
--
2.36.0.512.ge40c2bad7a-goog
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
# Copyright 2021 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ -z "$1" ]; then
echo "Expecting an output directory. Got none." 1>&2
exit 1
fi
mkdir -p "$1"
rm -rf "$1/*"