Skip to content

Commit

Permalink
Imporving initial build process on Linux
Browse files Browse the repository at this point in the history
Removing unused module

Have CMake pull the submodules

Added Linux CMake  installer

Removing unused code

Partially working auto installer.
  • Loading branch information
zwparchman authored and AngriestSCV committed Sep 2, 2022
1 parent 7f2e041 commit 98e05dd
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 45 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "OpenVR-SpaceCalibrator/gl3w"]
path = OpenVR-SpaceCalibrator/gl3w
url = https://github.com/skaslev/gl3w.git
[submodule "modules/gl3w"]
path = modules/gl3w
url = https://github.com/skaslev/gl3w.git
[submodule "modules/imgui"]
path = modules/imgui
url = https://github.com/ocornut/imgui.git
[submodule "modules/openvr"]
path = modules/openvr
url = https://github.com/ValveSoftware/openvr.git
65 changes: 59 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ cmake_minimum_required(VERSION 3.10)
project (OpenVR-SpaceCalibrator VERSION 1.0)
add_definitions(-D__linux__)

set(CMAKE_BUILD_TYPE Debug)
set(DRIVER_LOG_FILE "/tmp/spaceCalDriverLog.txt" CACHE PATH "Driver Log Path" )

add_library(imgui
lib/imgui/imgui.cpp
lib/imgui/imgui_demo.cpp
Expand All @@ -13,17 +16,16 @@ add_library(imgui
)

find_library(glfw libglfw.so)
find_library(GL libgl.so)
find_library(openvr_api openvr_api.so)
find_library(GL libGL.so)
find_library( openvr_api libopenvr_api.so PATHS ./modules/openvr/bin/linux64/libopenvr_api.so )

include_directories(OpenVR-SpaceCalibratorDriver)
include_directories(/usr/include/eigen3)
include_directories(/usr/include/openvr)
include_directories(lib/gl3w/include)
include_directories(lib)
include_directories(modules/openvr/headers)

add_library(gl3w lib/gl3w/src/gl3w.c)
add_library( gl3w lib/gl3w/src/gl3w.c )

#configure_file(LinixConfig.h.in LinuxConfig.h)

Expand Down Expand Up @@ -62,5 +64,56 @@ set_target_properties(driver_01spacecalibrator PROPERTIES
PREFIX ""
)

configure_file( ./OpenVR-SpaceCalibrator/manifest.vrmanifest manifest.vrmanifest )
configure_file( ./OpenVR-SpaceCalibratorDriver/01spacecalibrator/driver.vrdrivermanifest driver.vrdrivermanifest )
#######################################################################################
set( APP_MANIFEST_PATH ${CMAKE_INSTALL_PREFIX}/share/openvr-spacecalibrator/manifest.vrmanifest )
set( DRIVER_INSTALLER_PATH ${CMAKE_INSTALL_PREFIX}/share/openvr-spacecalibrator )
set( DRIVER_MANIFEST_PATH ${CMAKE_INSTALL_PREFIX}/lib/steamvr/OpenVR-SpaceCalibrator/01spacecalibrator )
configure_file( StaticConfig.h.in StaticConfig.h )

include_directories("${CMAKE_CURRENT_BINARY_DIR}")

configure_file( ./OpenVR-SpaceCalibrator/manifest.vrmanifest ${CMAKE_CURRENT_BINARY_DIR}/manifest.vrmanifest )
configure_file( ./OpenVR-SpaceCalibratorDriver/01spacecalibrator/driver.vrdrivermanifest ${CMAKE_CURRENT_BINARY_DIR}/driver.vrdrivermanifest )
configure_file( ./driverInstall.py ${CMAKE_CURRENT_BINARY_DIR}/driverInstall.py )


#######################################################################################
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.vrmanifest
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/openvr-spacecalibrator
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/driver.vrdrivermanifest
DESTINATION lib/steamvr/OpenVR-SpaceCalibrator/01spacecalibrator
)

install(
TARGETS OpenVR-SpaceCalibrator
)
install(
TARGETS driver_01spacecalibrator
DESTINATION lib/steamvr/OpenVR-SpaceCalibrator/01spacecalibrator/bin/linux64/
)

install(
FILES driverInstall.py
DESTINATION "${DRIVER_INSTALLER_PATH}"
)

find_package(Git QUIET)

if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()

74 changes: 66 additions & 8 deletions OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string>
#include <codecvt>
#include <locale>
#include <GL/gl3w.h>
#include "GL/gl3w.h"

#ifdef __linux__
#include <unistd.h>
Expand All @@ -24,7 +24,7 @@
#include <openvr.h>

#ifdef __linux__
//NOP
#include "StaticConfig.h"
#else
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
Expand All @@ -40,9 +40,9 @@ extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x
#endif

#ifdef __linux__
#define MANIFEST_END_PATH "/manifest.vrmanifest"
#define MANIFEST_PATH(CWD) (APP_MANIFEST_PATH)
#else
#define MANIFEST_END_PATH "\\manifest.vrmanifest"
#define MANIFEST_PATH(CWD) (CWD + "\\manifest.vrmanifest")
#endif


Expand Down Expand Up @@ -474,6 +474,10 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
std::cout << "-installmanifest install the application vrmanifest" << std::endl;
std::cout << "-removemanifest remove the application vrmanifest" << std::endl;
std::cout << "-activatemultipledrivers enable multiple drivers in steamvr" << std::endl;
#ifdef __linux__
std::cout << "-installdriver install the steam vr driver." << std::endl;
std::cout << "-uninstalldriver uninstall the steam vr driver." << std::endl;
#endif
std::cout << "-help -h print this message" << std::endl;
exit(0);
}
Expand Down Expand Up @@ -513,13 +517,14 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
else
{
std::string manifestPath = oldWd;
manifestPath += MANIFEST_END_PATH;
manifestPath = MANIFEST_PATH(manifestPath);
std::cout << "Removing old manifest path: " << manifestPath << std::endl;
vr::VRApplications()->RemoveApplicationManifest(manifestPath.c_str());
}
}
std::string manifestPath = cwd;
manifestPath += MANIFEST_END_PATH;
manifestPath = MANIFEST_PATH(manifestPath);

std::cout << "Adding manifest path: " << manifestPath << std::endl;
auto vrAppErr = vr::VRApplications()->AddApplicationManifest(manifestPath.c_str());
if (vrAppErr != vr::VRApplicationError_None)
Expand All @@ -545,8 +550,9 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
{
if (vr::VRApplications()->IsApplicationInstalled(OPENVR_APPLICATION_KEY))
{
std::string manifestPath = cwd;
manifestPath += MANIFEST_END_PATH;
std::string manifestPath = cwd;
manifestPath = MANIFEST_PATH(manifestPath);

std::cout << "Removing manifest path: " << manifestPath << std::endl;
vr::VRApplications()->RemoveApplicationManifest(manifestPath.c_str());
}
Expand Down Expand Up @@ -581,4 +587,56 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
vr::VR_Shutdown();
exit(ret);
}
#ifdef __linux__
else if (StringMatch(lpCmdLine, L"-installdriver"))
{
auto vrErr = vr::VRInitError_None;
vr::VR_Init(&vrErr, vr::VRApplication_Utility);
if (vrErr != vr::VRInitError_None)
{
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
vr::VR_Shutdown();
exit(-2);
}

char cruntimePath[MAX_PATH] = { 0 };
unsigned int pathLen;
vr::VR_GetRuntimePath(cruntimePath, MAX_PATH, &pathLen);

const int cmdLength = 8196;
char cmd[cmdLength];

snprintf(cmd, cmdLength, "python " DRIVER_INSTALLER_PATH "/driverInstall.py --toInstall " DRIVER_MANIFEST_PATH " --vrpathreg %s/bin/vrpathreg.sh", cruntimePath);
printf("cmd: %s\n", cmd);
system(cmd);

vr::VR_Shutdown();
exit(0);
}
else if (StringMatch(lpCmdLine, L"-uninstalldriver"))
{
auto vrErr = vr::VRInitError_None;
vr::VR_Init(&vrErr, vr::VRApplication_Utility);
if (vrErr != vr::VRInitError_None)
{
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
vr::VR_Shutdown();
exit(-2);
}

char cruntimePath[MAX_PATH] = { 0 };
unsigned int pathLen;
vr::VR_GetRuntimePath(cruntimePath, MAX_PATH, &pathLen);

const int cmdLength = 8196;
char cmd[cmdLength];

snprintf(cmd, cmdLength, "\"%s/bin/vrpathreg.sh\" removedriverwithname 01spacecalibrator", cruntimePath);
printf("cmd: %s\n", cmd);

vr::VR_Shutdown();
exit(0);
}
#endif

}
4 changes: 2 additions & 2 deletions OpenVR-SpaceCalibratorDriver/Comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class UDPServerSocket{
//TODO verify that 0 is valid for UDP.
sock = socket(AF_INET, SOCK_DGRAM, 0);
if(sock == -1){
LOG("%s", "Failed to create socket");
LOG("Failed to create socket: %s", strerror(errno));
return false;
}

int err = bind(sock, (sockaddr*)&my_addr, sizeof(my_addr));
if(err){
LOG("%s", "Failed to bind socket");
LOG("Failed to bind socket: %s", strerror(errno));
return false;
}
return true;
Expand Down
9 changes: 8 additions & 1 deletion OpenVR-SpaceCalibratorDriver/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
#include <chrono>
#include <ctime>

#ifdef __linux__
#include "StaticConfig.h"
#else
#define DRIVER_LOG_FILE "space_calibrator_driver.log"
#endif


FILE *LogFile;

void OpenLogFile()
{
LogFile = fopen("/tmp/space_calibrator_driver.log", "w");
LogFile = fopen(DRIVER_LOG_FILE, "w");
if (LogFile == nullptr)
{
LogFile = stderr;
Expand Down
24 changes: 0 additions & 24 deletions OpenVR-SpaceCalibratorDriver/build.sh

This file was deleted.

4 changes: 4 additions & 0 deletions StaticConfig.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#cmakedefine DRIVER_LOG_FILE "@DRIVER_LOG_FILE@"
#cmakedefine APP_MANIFEST_PATH "@APP_MANIFEST_PATH@"
#cmakedefine DRIVER_MANIFEST_PATH "@DRIVER_MANIFEST_PATH@"
#cmakedefine DRIVER_INSTALLER_PATH "@DRIVER_INSTALLER_PATH@"
76 changes: 76 additions & 0 deletions driverInstall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python3
import os, sys
import subprocess
import re
import argparse

#vrpathreg = "/home/zack/.local/share/Steam/steamapps/common/SteamVR/bin/vrpathreg.sh"

def GetDrivers(vrpathreg):
proc = subprocess.Popen([vrpathreg], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8')
(stdout, _) = proc.communicate()

lineno = 0
externalReg = re.compile('.*External Drivers:.*')
lines = stdout.split('\n')
for line in lines:
lineno += 1
if externalReg.match(line):
break

lines = [ x.strip().split(':')[1].strip() for x in lines[lineno:] if len(x) > 0]
return lines

def RemoveDriver(vrpathreg, driver):
cmd = [vrpathreg, 'removedriver', driver]
print(cmd)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8')
(stdout, _) = proc.communicate()

def AddDriver(vrpathreg, driver):
cmd = [vrpathreg, 'adddriver', driver]
print(cmd)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8')
(stdout, _) = proc.communicate()

def main():
parser = argparse.ArgumentParser()

parser.add_argument('--toInstall', help="Driver to install (folder path)", required=True)
parser.add_argument('--vrpathreg', help="Path to vrpathreg.sh", required=True)

args = parser.parse_args()

fail = False
if not os.path.exists(args.toInstall):
print("Driver path [{args.toInstall}] does not exist")
fail = True

if not os.path.exists(args.vrpathreg):
print("Path to vrpathreg.sh [{args.toInstall}] does not exist")
fail = True

if fail:
return

drivers = GetDrivers(args.vrpathreg)

spaceCalReg = re.compile('.*01spacecalibrator.*')

for driver in drivers:
RemoveDriver(args.vrpathreg, driver)

AddDriver(args.vrpathreg, args.toInstall)

for driver in drivers[::-1]:
if spaceCalReg.match(driver):
continue

AddDriver(args.vrpathreg, driver)

pass


if __name__ == "__main__":
main()

1 change: 0 additions & 1 deletion modules/gl3w
Submodule gl3w deleted from 5f8d7f
1 change: 1 addition & 0 deletions modules/openvr
Submodule openvr added at 08de38

0 comments on commit 98e05dd

Please sign in to comment.