# Provides the imported target OpenVR::OpenVR. # # Either point OPENVR_ROOT at an OpenVR SDK checkout (needs headers/ and bin//), # or leave it empty and the required files of OPENVR_VERSION are downloaded once into # third_party/openvr-/ (header + Linux libraries only, not the whole SDK). set(OPENVR_ROOT "" CACHE PATH "Path to an OpenVR SDK (leave empty to auto-download)") if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|ARM64)$") set(_openvr_platform linuxarm64) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|amd64)$") set(_openvr_platform linux64) else() message(FATAL_ERROR "Unsupported target processor for OpenVR: ${CMAKE_SYSTEM_PROCESSOR}") endif() if(NOT OPENVR_ROOT) set(OPENVR_ROOT ${CMAKE_SOURCE_DIR}/third_party/openvr-${OPENVR_VERSION}) set(_base "https://raw.githubusercontent.com/ValveSoftware/openvr/v${OPENVR_VERSION}") foreach(_file headers/openvr.h LICENSE bin/${_openvr_platform}/libopenvr_api.so) if(NOT EXISTS ${OPENVR_ROOT}/${_file}) message(STATUS "Downloading OpenVR ${OPENVR_VERSION}: ${_file}") file(DOWNLOAD ${_base}/${_file} ${OPENVR_ROOT}/${_file}.part STATUS _status TLS_VERIFY ON) list(GET _status 0 _code) if(NOT _code EQUAL 0) file(REMOVE ${OPENVR_ROOT}/${_file}.part) message(FATAL_ERROR "Download of ${_base}/${_file} failed: ${_status}\n" "Set OPENVR_ROOT to a local OpenVR SDK to build offline.") endif() file(RENAME ${OPENVR_ROOT}/${_file}.part ${OPENVR_ROOT}/${_file}) endif() endforeach() endif() set(_openvr_lib ${OPENVR_ROOT}/bin/${_openvr_platform}/libopenvr_api.so) if(NOT EXISTS ${OPENVR_ROOT}/headers/openvr.h OR NOT EXISTS ${_openvr_lib}) message(FATAL_ERROR "OPENVR_ROOT=${OPENVR_ROOT} lacks headers/openvr.h or ${_openvr_lib}") endif() add_library(OpenVR::OpenVR SHARED IMPORTED GLOBAL) set_target_properties(OpenVR::OpenVR PROPERTIES IMPORTED_LOCATION ${_openvr_lib} IMPORTED_NO_SONAME TRUE INTERFACE_INCLUDE_DIRECTORIES ${OPENVR_ROOT}/headers) set(OPENVR_LIBRARY ${_openvr_lib}) set(OPENVR_LICENSE ${OPENVR_ROOT}/LICENSE) message(STATUS "OpenVR: ${OPENVR_ROOT} (${_openvr_platform})")