Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ AlignEscapedNewlines: Right
AlignOperands: DontAlign
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
OverEmptyLines: 2
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
steps:
- uses: actions/checkout@v6
with:
submodules: true
submodules: recursive

- if: matrix.os == 'ubuntu-latest'
name: Install GCC 16
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/Microsoft/vcpkg.git
[submodule "libraries/solarxr-protocol"]
path = libraries/solarxr-protocol
url = https://github.com/SlimeVR/SolarXR-Protocol.git
104 changes: 51 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
cmake_minimum_required(VERSION 3.8.0)

#if (NOT DEFINED VCPKG_TARGET_TRIPLET)
if(WIN32)
set(VCPKG_TARGET_TRIPLET "x64-windows-static-md")
endif()
if(WIN32)
set(VCPKG_TARGET_TRIPLET "x64-windows-static-md")
endif()
#endif()

set (CMAKE_CXX_STANDARD 20)

# If the toolchain is already defined, do not attempt to find it
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
# If the VCPKG_ROOT environment variable is not defined, try to automatically define it from AppData/home
if(NOT DEFINED ENV{VCPKG_ROOT})
if(WIN32)
file(READ "$ENV{LOCALAPPDATA}/vcpkg/vcpkg.path.txt" VCPKG_ROOT)
elseif(UNIX)
file(READ "$ENV{HOME}/.vcpkg/vcpkg.path.txt" VCPKG_ROOT)
endif()

set(VCPKG_PATH "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
else()
set(VCPKG_PATH "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
endif()

if(EXISTS "${VCPKG_PATH}")
message("vcpkg CMake toolchain was found at \"${VCPKG_PATH}\"")
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_PATH}")
else()
message(FATAL_ERROR "vcpkg could not be found")
# If the VCPKG_ROOT environment variable is not defined, try to automatically define it from AppData/home
if(NOT DEFINED ENV{VCPKG_ROOT})
if(WIN32)
file(READ "$ENV{LOCALAPPDATA}/vcpkg/vcpkg.path.txt" VCPKG_ROOT)
elseif(UNIX)
file(READ "$ENV{HOME}/.vcpkg/vcpkg.path.txt" VCPKG_ROOT)
endif()

set(VCPKG_PATH "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
else()
set(VCPKG_PATH "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
endif()

if(EXISTS "${VCPKG_PATH}")
message("vcpkg CMake toolchain was found at \"${VCPKG_PATH}\"")
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_PATH}")
else()
message(FATAL_ERROR "vcpkg could not be found")
endif()
endif()

project(SlimeVR-OpenVR-Driver VERSION 0.2.0)
Expand All @@ -38,30 +38,26 @@ set(DRIVER_NAME "slimevr")
include(CTest)
enable_testing()

# OpenVR
set(OPENVR_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/openvr/headers")

set(SOLARXR_PROTOCOL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/libraries/solarxr-protocol")
set(FLATBUFFERS_GENERATED_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/libraries/solarxr-protocol/protocol/cpp")

set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PROCESSOR_ARCH "64")
set(PROCESSOR_ARCH "64")
else()
set(PROCESSOR_ARCH "32")
set(PROCESSOR_ARCH "32")
endif()

if(WIN32)
set(PLATFORM_NAME "win")
set(PLATFORM_NAME "win")
elseif(UNIX AND NOT APPLE)
set(PLATFORM_NAME "linux")
set(PLATFORM_NAME "linux")
elseif(APPLE)
set(PLATFORM_NAME "osx")
set(PLATFORM_NAME "osx")
endif()

# Please refer to this readme to install protobuf in your system: https://github.com/protocolbuffers/protobuf/blob/master/src/README.md
set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "")
find_package(Protobuf CONFIG REQUIRED)
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/bridge/ProtobufMessages.proto")
set_source_files_properties(${PROTO_SRC} ${PROTO_HEADER} PROPERTIES GENERATED TRUE)

find_package(simdjson CONFIG REQUIRED)

find_package(uvw CONFIG REQUIRED)
Expand All @@ -71,20 +67,20 @@ find_package(Catch2 3 REQUIRED)
find_package(Git)

if (NOT GIT_DESC)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always
OUTPUT_VARIABLE GIT_DESC
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
string(STRIP "${GIT_DESC}" GIT_DESC)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always
OUTPUT_VARIABLE GIT_DESC
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
string(STRIP "${GIT_DESC}" GIT_DESC)
else()
message(STATUS "Using GIT_DESC ${GIT_DESC} from explicit build flag")
message(STATUS "Using GIT_DESC ${GIT_DESC} from explicit build flag")
endif()

if (GIT_DESC)
message(STATUS "GIT_DESC: ${GIT_DESC}")
message(STATUS "GIT_DESC: ${GIT_DESC}")
else()
message(FATAL_ERROR "Could not set GIT_DESC")
message(FATAL_ERROR "Could not set GIT_DESC")
endif()

# Project
Expand All @@ -94,9 +90,6 @@ set(DEPS_INCLUDES
"${CMAKE_CURRENT_SOURCE_DIR}/src/"
)
set(DEPS_LIBS
protobuf::libprotoc
protobuf::libprotobuf
protobuf::libprotobuf-lite
simdjson::simdjson
uvw::uvw
)
Expand All @@ -109,10 +102,15 @@ file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp")
add_library("${PROJECT_NAME}_static" STATIC ${SOURCES} ${PROTO_HEADER} ${PROTO_SRC})
target_link_libraries("${PROJECT_NAME}_static" PUBLIC ${DEPS_LIBS})
set_property(TARGET "${PROJECT_NAME}_static" PROPERTY CXX_STANDARD 23)
include_directories("${PROJECT_NAME}_static" PUBLIC ${DEPS_INCLUDES} ${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/src")
target_include_directories("${PROJECT_NAME}_static" BEFORE PUBLIC "${SOLARXR_PROTOCOL_ROOT}/lib/flatbuffers/include" "${SOLARXR_PROTOCOL_ROOT}/lib/flatbuffers/" "${FLATBUFFERS_GENERATED_ROOT}/include")
target_include_directories("${PROJECT_NAME}_static" PUBLIC ${DEPS_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/src")
if(UNIX)
target_compile_options("${PROJECT_NAME}_static" PRIVATE "-fPIC")
target_link_libraries("${PROJECT_NAME}_static" PUBLIC atomic)
target_compile_options("${PROJECT_NAME}_static" PRIVATE "-fPIC")
target_link_libraries("${PROJECT_NAME}_static" PUBLIC atomic)
endif()
# Enable unwind on MSVC
if(MSVC)
target_compile_options("${PROJECT_NAME}_static" PUBLIC "/EHsc")
endif()

# compile driver
Expand Down Expand Up @@ -145,17 +143,17 @@ include(CPack)
# Copy driver assets to output folder
add_custom_command(
TARGET ${PROJECT_NAME}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/driver/
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/driver/
$<TARGET_FILE_DIR:${PROJECT_NAME}>/driver
)

# Copy dll to output folder
add_custom_command(
TARGET ${PROJECT_NAME}
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:${PROJECT_NAME}>
$<TARGET_FILE_DIR:${PROJECT_NAME}>/driver/${DRIVER_NAME}/bin/${PLATFORM_NAME}${PROCESSOR_ARCH}/driver_${DRIVER_NAME}$<TARGET_FILE_SUFFIX:${PROJECT_NAME}>
)
1 change: 1 addition & 0 deletions libraries/solarxr-protocol
Submodule solarxr-protocol added at 15aee0
27 changes: 10 additions & 17 deletions src/IVRDevice.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#pragma once

#include "ProtobufMessages.pb.h"
#include <DeviceType.hpp>
#include <openvr_driver.h>
#include <solarxr_protocol/generated/all_generated.h>

#include "DeviceType.hpp"

namespace SlimeVRDriver {

class IVRDevice : public vr::ITrackedDeviceServerDriver {
public:
virtual solarxr_protocol::datatypes::BodyPart GetBodyPart() = 0;

/**
* Returns the serial string for this device.
*
Expand Down Expand Up @@ -62,29 +65,19 @@ class IVRDevice : public vr::ITrackedDeviceServerDriver {
}

/**
* Returns the device id.
*/
virtual int GetDeviceId() = 0;

/**
* Sets the device id.
*/
virtual void SetDeviceId(int device_id) = 0;

/**
* Updates device position from a received message.
* Updates device pose from a received message.
*/
virtual void PositionMessage(messages::Position& position) = 0;
virtual void UpdatePose(const solarxr_protocol::datatypes::math::Quat* rot, const solarxr_protocol::datatypes::math::Vec3f* pos, solarxr_protocol::datatypes::TrackerStatus status) = 0;

/**
* Updates device status from a received message.
*/
virtual void StatusMessage(messages::TrackerStatus& status) = 0;
virtual void UpdateStatus(solarxr_protocol::datatypes::TrackerStatus status) = 0;

/**
* Updates battery indicator from a received message.
*/
virtual void BatteryMessage(messages::Battery& battery) = 0;
virtual void UpdateBattery(float battery_percentage, bool charging) = 0;

// Inherited via ITrackedDeviceServerDriver
virtual vr::EVRInitError Activate(uint32_t unObjectId) = 0;
Expand All @@ -97,4 +90,4 @@ class IVRDevice : public vr::ITrackedDeviceServerDriver {
~IVRDevice() = default;
};

} // namespace SlimeVRDriver
} // namespace SlimeVRDriver
Loading
Loading