Initial open sourcing of MuJoCo.
PiperOrigin-RevId: 450374687 Change-Id: Ie3225a46ce095fc28ae8e63c326a640261f562bb
This commit is contained in:
committed by
Copybara-Service
parent
0e5d062302
commit
1913a02b40
@@ -40,32 +40,60 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
|
||||
separate_arguments(CMDLINE_LINK_OPTIONS UNIX_COMMAND ${CMAKE_SHARED_LINKER_FLAGS})
|
||||
add_link_options(${CMDLINE_LINK_OPTIONS})
|
||||
|
||||
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()
|
||||
|
||||
include(MujocoLinkOptions)
|
||||
get_mujoco_extra_link_options(EXTRA_LINK_OPTIONS)
|
||||
add_link_options(${EXTRA_LINK_OPTIONS})
|
||||
|
||||
if(APPLE)
|
||||
add_compile_options(-Werror=partial-availability -Werror=unguarded-availability)
|
||||
add_link_options(-Wl,-no_weak_imports)
|
||||
include(MujocoMacOS)
|
||||
enforce_mujoco_macosx_min_version()
|
||||
|
||||
if(WIN32)
|
||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
include(MujocoHarden)
|
||||
add_compile_options("${MUJOCO_HARDEN_COMPILE_OPTIONS}")
|
||||
add_link_options("${MUJOCO_HARDEN_LINK_OPTIONS}")
|
||||
|
||||
find_package(Python3 COMPONENTS Interpreter Development)
|
||||
|
||||
include(FindOrFetch)
|
||||
|
||||
# ==================== MUJOCO LIBRARY ==========================================
|
||||
if(NOT TARGET mujoco)
|
||||
find_library(MUJOCO_LIBRARY mujoco mujoco.2.1.5 HINTS ${MUJOCO_LIBRARY_DIR} REQUIRED)
|
||||
find_path(MUJOCO_INCLUDE mujoco.h HINTS ${MUJOCO_INCLUDE_DIR} REQUIRED)
|
||||
message("MuJoCo is at ${MUJOCO_LIBRARY}")
|
||||
message("MuJoCo headers are at ${MUJOCO_INCLUDE}")
|
||||
add_library(mujoco SHARED IMPORTED)
|
||||
if(APPLE)
|
||||
# On macOS, check if we are using mujoco.framework first.
|
||||
# Framework headers are searched differently from normal headers.
|
||||
# We need to use -F instead of the usual target_include_directories.
|
||||
find_path(MUJOCO_FRAMEWORK mujoco.Framework HINTS ${MUJOCO_FRAMEWORK_DIR})
|
||||
if(MUJOCO_FRAMEWORK)
|
||||
message("MuJoCo framework is at ${MUJOCO_FRAMEWORK}/mujoco.framework")
|
||||
set(MUJOCO_LIBRARY ${MUJOCO_FRAMEWORK}/mujoco.framework/Versions/A/libmujoco.2.2.0.dylib)
|
||||
target_compile_options(mujoco INTERFACE -F${MUJOCO_FRAMEWORK})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT MUJOCO_FRAMEWORK)
|
||||
find_library(MUJOCO_LIBRARY mujoco mujoco.2.2.0 HINTS ${MUJOCO_LIBRARY_DIR} REQUIRED)
|
||||
find_path(MUJOCO_INCLUDE mujoco/mujoco.h HINTS ${MUJOCO_INCLUDE_DIR} REQUIRED)
|
||||
message("MuJoCo is at ${MUJOCO_LIBRARY}")
|
||||
message("MuJoCo headers are at ${MUJOCO_INCLUDE}")
|
||||
target_include_directories(mujoco INTERFACE "${MUJOCO_INCLUDE}")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
set_target_properties(mujoco PROPERTIES IMPORTED_IMPLIB "${MUJOCO_LIBRARY}")
|
||||
else()
|
||||
set_target_properties(mujoco PROPERTIES IMPORTED_LOCATION "${MUJOCO_LIBRARY}")
|
||||
endif()
|
||||
target_include_directories(mujoco INTERFACE "${MUJOCO_INCLUDE}")
|
||||
|
||||
if(APPLE)
|
||||
execute_process(
|
||||
COMMAND otool -XD ${MUJOCO_LIBRARY}
|
||||
@@ -88,18 +116,7 @@ if(NOT TARGET mujoco)
|
||||
endif()
|
||||
|
||||
# ==================== ABSEIL ==================================================
|
||||
if(APPLE)
|
||||
set(ABSL_EXTRA_FETCH_ARGS
|
||||
PATCH_COMMAND
|
||||
"sed"
|
||||
"-i"
|
||||
" "
|
||||
"s/-march=armv8-a+crypto/-mcpu=apple-m1+crypto/g"
|
||||
"${CMAKE_BINARY_DIR}/_deps/abseil-cpp-src/absl/copts/GENERATED_AbseilCopts.cmake"
|
||||
)
|
||||
else()
|
||||
set(ABSL_EXTRA_FETCH_ARGS "")
|
||||
endif()
|
||||
set(MUJOCO_PYTHON_ABSL_TARGETS absl::core_headers absl::flat_hash_map absl::span)
|
||||
findorfetch(
|
||||
USE_SYSTEM_PACKAGE
|
||||
OFF
|
||||
@@ -110,14 +127,26 @@ findorfetch(
|
||||
GIT_REPO
|
||||
https://github.com/abseil/abseil-cpp
|
||||
GIT_TAG
|
||||
215105818dfde3174fe799600bb0f3cae233d0bf # 20211102.0
|
||||
78f9680225b9792c26dfdd99d0bd26c96de53dd4 # # Fixes universal builds for macOS
|
||||
TARGETS
|
||||
absl::core_headers
|
||||
absl::flat_hash_map
|
||||
absl::span
|
||||
${ABSL_EXTRA_FETCH_ARGS}
|
||||
${MUJOCO_PYTHON_ABSL_TARGETS}
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
foreach(absl_target IN ITEMS ${MUJOCO_PYTHON_ABSL_TARGETS})
|
||||
get_target_property(absl_target_aliased ${absl_target} ALIASED_TARGET)
|
||||
if(absl_target_aliased)
|
||||
set(absl_target ${absl_target_aliased})
|
||||
endif()
|
||||
get_target_property(absl_target_type ${absl_target} TYPE)
|
||||
if(NOT
|
||||
${absl_target_type}
|
||||
STREQUAL
|
||||
"INTERFACE_LIBRARY"
|
||||
)
|
||||
target_compile_options(${absl_target} PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
|
||||
target_link_options(${absl_target} PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# ==================== EIGEN ===================================================
|
||||
add_compile_definitions(EIGEN_MPL2_ONLY)
|
||||
@@ -138,26 +167,21 @@ findorfetch(
|
||||
)
|
||||
|
||||
# ==================== PYBIND11 ================================================
|
||||
if(MUJOCO_PYBIND11_DIR)
|
||||
FetchContent_Declare(pybind11 SOURCE_DIR ${MUJOCO_PYBIND11_DIR} EXCLUDE_FROM_ALL)
|
||||
FetchContent_MakeAvailable(pybind11)
|
||||
else()
|
||||
findorfetch(
|
||||
USE_SYSTEM_PACKAGE
|
||||
OFF
|
||||
PACKAGE_NAME
|
||||
pybind11
|
||||
LIBRARY_NAME
|
||||
pybind11
|
||||
GIT_REPO
|
||||
https://github.com/pybind/pybind11
|
||||
GIT_TAG
|
||||
a8f1a5567608f346bdba293b3d062a288ee16cd4
|
||||
TARGETS
|
||||
pybind11::pybind11_headers
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
endif()
|
||||
findorfetch(
|
||||
USE_SYSTEM_PACKAGE
|
||||
OFF
|
||||
PACKAGE_NAME
|
||||
pybind11
|
||||
LIBRARY_NAME
|
||||
pybind11
|
||||
GIT_REPO
|
||||
https://github.com/pybind/pybind11
|
||||
GIT_TAG
|
||||
a8f1a5567608f346bdba293b3d062a288ee16cd4
|
||||
TARGETS
|
||||
pybind11::pybind11_headers
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
||||
# ==================== MUJOCO PYTHON BINDINGS ==================================
|
||||
|
||||
@@ -222,6 +246,7 @@ target_link_libraries(
|
||||
structs_header
|
||||
INTERFACE absl::flat_hash_map
|
||||
absl::span
|
||||
crossplatform
|
||||
mujoco
|
||||
raw
|
||||
)
|
||||
@@ -246,6 +271,19 @@ get_avx_compile_options(AVX_COMPILE_OPTIONS)
|
||||
macro(mujoco_pybind11_module name)
|
||||
pybind11_add_module(${name} ${ARGN})
|
||||
target_compile_options(${name} PRIVATE ${AVX_COMPILE_OPTIONS})
|
||||
if(NOT MSVC)
|
||||
target_compile_options(${name} PRIVATE -Wall -Werror)
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL GNU)
|
||||
target_compile_options(
|
||||
${name}
|
||||
PRIVATE -Wno-int-in-bool-context
|
||||
-Wno-maybe-uninitialized
|
||||
-Wno-sign-compare
|
||||
-Wno-stringop-overflow
|
||||
-Wno-stringop-truncation
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
if(APPLE)
|
||||
add_custom_command(
|
||||
@@ -323,6 +361,7 @@ mujoco_pybind11_module(
|
||||
target_link_libraries(
|
||||
_structs
|
||||
PRIVATE absl::flat_hash_map
|
||||
crossplatform
|
||||
mujoco
|
||||
raw
|
||||
errors_header
|
||||
|
||||
Reference in New Issue
Block a user