Skip to content

Commit bfa1c3e

Browse files
committed
Imporving initial build process on Linux
Removing unused module Have CMake pull the submodules Added Linux CMake installer Removing unused code Partially working auto installer.
1 parent 7f2e041 commit bfa1c3e

10 files changed

Lines changed: 219 additions & 45 deletions

File tree

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[submodule "OpenVR-SpaceCalibrator/gl3w"]
22
path = OpenVR-SpaceCalibrator/gl3w
33
url = https://github.com/skaslev/gl3w.git
4-
[submodule "modules/gl3w"]
5-
path = modules/gl3w
6-
url = https://github.com/skaslev/gl3w.git
74
[submodule "modules/imgui"]
85
path = modules/imgui
96
url = https://github.com/ocornut/imgui.git
7+
[submodule "modules/openvr"]
8+
path = modules/openvr
9+
url = https://github.com/ValveSoftware/openvr.git

CMakeLists.txt

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ cmake_minimum_required(VERSION 3.10)
33
project (OpenVR-SpaceCalibrator VERSION 1.0)
44
add_definitions(-D__linux__)
55

6+
set(CMAKE_BUILD_TYPE Debug)
7+
set(DRIVER_LOG_FILE "/tmp/spaceCalDriverLog.txt" CACHE PATH "Driver Log Path" )
8+
69
add_library(imgui
710
lib/imgui/imgui.cpp
811
lib/imgui/imgui_demo.cpp
@@ -13,17 +16,16 @@ add_library(imgui
1316
)
1417

1518
find_library(glfw libglfw.so)
16-
find_library(GL libgl.so)
17-
find_library(openvr_api openvr_api.so)
19+
find_library(GL libGL.so)
20+
find_library( openvr_api libopenvr_api.so PATHS ./modules/openvr/bin/linux64/libopenvr_api.so )
1821

1922
include_directories(OpenVR-SpaceCalibratorDriver)
2023
include_directories(/usr/include/eigen3)
21-
include_directories(/usr/include/openvr)
2224
include_directories(lib/gl3w/include)
2325
include_directories(lib)
2426
include_directories(modules/openvr/headers)
2527

26-
add_library(gl3w lib/gl3w/src/gl3w.c)
28+
add_library( gl3w lib/gl3w/src/gl3w.c )
2729

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

@@ -62,5 +64,56 @@ set_target_properties(driver_01spacecalibrator PROPERTIES
6264
PREFIX ""
6365
)
6466

65-
configure_file( ./OpenVR-SpaceCalibrator/manifest.vrmanifest manifest.vrmanifest )
66-
configure_file( ./OpenVR-SpaceCalibratorDriver/01spacecalibrator/driver.vrdrivermanifest driver.vrdrivermanifest )
67+
#######################################################################################
68+
set( APP_MANIFEST_PATH ${CMAKE_INSTALL_PREFIX}/share/openvr-spacecalibrator/manifest.vrmanifest )
69+
set( DRIVER_INSTALLER_PATH ${CMAKE_INSTALL_PREFIX}/share/openvr-spacecalibrator )
70+
set( DRIVER_MANIFEST_PATH ${CMAKE_INSTALL_PREFIX}/lib/steamvr/OpenVR-SpaceCalibrator/01spacecalibrator )
71+
configure_file( StaticConfig.h.in StaticConfig.h )
72+
73+
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
74+
75+
configure_file( ./OpenVR-SpaceCalibrator/manifest.vrmanifest ${CMAKE_CURRENT_BINARY_DIR}/manifest.vrmanifest )
76+
configure_file( ./OpenVR-SpaceCalibratorDriver/01spacecalibrator/driver.vrdrivermanifest ${CMAKE_CURRENT_BINARY_DIR}/driver.vrdrivermanifest )
77+
configure_file( ./driverInstall.py ${CMAKE_CURRENT_BINARY_DIR}/driverInstall.py )
78+
79+
80+
#######################################################################################
81+
install(
82+
FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.vrmanifest
83+
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/openvr-spacecalibrator
84+
)
85+
86+
install(
87+
FILES ${CMAKE_CURRENT_BINARY_DIR}/driver.vrdrivermanifest
88+
DESTINATION lib/steamvr/OpenVR-SpaceCalibrator/01spacecalibrator
89+
)
90+
91+
install(
92+
TARGETS OpenVR-SpaceCalibrator
93+
)
94+
install(
95+
TARGETS driver_01spacecalibrator
96+
DESTINATION lib/steamvr/OpenVR-SpaceCalibrator/01spacecalibrator/bin/linux64/
97+
)
98+
99+
install(
100+
FILES driverInstall.py
101+
DESTINATION "${DRIVER_INSTALLER_PATH}"
102+
)
103+
104+
find_package(Git QUIET)
105+
106+
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
107+
# Update submodules as needed
108+
option(GIT_SUBMODULE "Check submodules during build" ON)
109+
if(GIT_SUBMODULE)
110+
message(STATUS "Submodule update")
111+
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
112+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
113+
RESULT_VARIABLE GIT_SUBMOD_RESULT)
114+
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
115+
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
116+
endif()
117+
endif()
118+
endif()
119+

OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <string>
88
#include <codecvt>
99
#include <locale>
10-
#include <GL/gl3w.h>
10+
#include "GL/gl3w.h"
1111

1212
#ifdef __linux__
1313
#include <unistd.h>
@@ -24,7 +24,7 @@
2424
#include <openvr.h>
2525

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

4242
#ifdef __linux__
43-
#define MANIFEST_END_PATH "/manifest.vrmanifest"
43+
#define MANIFEST_PATH(CWD) (APP_MANIFEST_PATH)
4444
#else
45-
#define MANIFEST_END_PATH "\\manifest.vrmanifest"
45+
#define MANIFEST_PATH(CWD) (CWD + "\\manifest.vrmanifest")
4646
#endif
4747

4848

@@ -474,6 +474,10 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
474474
std::cout << "-installmanifest install the application vrmanifest" << std::endl;
475475
std::cout << "-removemanifest remove the application vrmanifest" << std::endl;
476476
std::cout << "-activatemultipledrivers enable multiple drivers in steamvr" << std::endl;
477+
#ifdef __linux__
478+
std::cout << "-installdriver install the steam vr driver." << std::endl;
479+
std::cout << "-uninstalldriver uninstall the steam vr driver." << std::endl;
480+
#endif
477481
std::cout << "-help -h print this message" << std::endl;
478482
exit(0);
479483
}
@@ -513,13 +517,14 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
513517
else
514518
{
515519
std::string manifestPath = oldWd;
516-
manifestPath += MANIFEST_END_PATH;
520+
manifestPath = MANIFEST_PATH(manifestPath);
517521
std::cout << "Removing old manifest path: " << manifestPath << std::endl;
518522
vr::VRApplications()->RemoveApplicationManifest(manifestPath.c_str());
519523
}
520524
}
521525
std::string manifestPath = cwd;
522-
manifestPath += MANIFEST_END_PATH;
526+
manifestPath = MANIFEST_PATH(manifestPath);
527+
523528
std::cout << "Adding manifest path: " << manifestPath << std::endl;
524529
auto vrAppErr = vr::VRApplications()->AddApplicationManifest(manifestPath.c_str());
525530
if (vrAppErr != vr::VRApplicationError_None)
@@ -545,8 +550,9 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
545550
{
546551
if (vr::VRApplications()->IsApplicationInstalled(OPENVR_APPLICATION_KEY))
547552
{
548-
std::string manifestPath = cwd;
549-
manifestPath += MANIFEST_END_PATH;
553+
std::string manifestPath = cwd;
554+
manifestPath = MANIFEST_PATH(manifestPath);
555+
550556
std::cout << "Removing manifest path: " << manifestPath << std::endl;
551557
vr::VRApplications()->RemoveApplicationManifest(manifestPath.c_str());
552558
}
@@ -581,4 +587,56 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
581587
vr::VR_Shutdown();
582588
exit(ret);
583589
}
590+
#ifdef __linux__
591+
else if (StringMatch(lpCmdLine, L"-installdriver"))
592+
{
593+
auto vrErr = vr::VRInitError_None;
594+
vr::VR_Init(&vrErr, vr::VRApplication_Utility);
595+
if (vrErr != vr::VRInitError_None)
596+
{
597+
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
598+
vr::VR_Shutdown();
599+
exit(-2);
600+
}
601+
602+
char cruntimePath[MAX_PATH] = { 0 };
603+
unsigned int pathLen;
604+
vr::VR_GetRuntimePath(cruntimePath, MAX_PATH, &pathLen);
605+
606+
const int cmdLength = 8196;
607+
char cmd[cmdLength];
608+
609+
snprintf(cmd, cmdLength, "python " DRIVER_INSTALLER_PATH "/driverInstall.py --toInstall " DRIVER_MANIFEST_PATH " --vrpathreg %s/bin/vrpathreg.sh", cruntimePath);
610+
printf("cmd: %s\n", cmd);
611+
system(cmd);
612+
613+
vr::VR_Shutdown();
614+
exit(0);
615+
}
616+
else if (StringMatch(lpCmdLine, L"-uninstalldriver"))
617+
{
618+
auto vrErr = vr::VRInitError_None;
619+
vr::VR_Init(&vrErr, vr::VRApplication_Utility);
620+
if (vrErr != vr::VRInitError_None)
621+
{
622+
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
623+
vr::VR_Shutdown();
624+
exit(-2);
625+
}
626+
627+
char cruntimePath[MAX_PATH] = { 0 };
628+
unsigned int pathLen;
629+
vr::VR_GetRuntimePath(cruntimePath, MAX_PATH, &pathLen);
630+
631+
const int cmdLength = 8196;
632+
char cmd[cmdLength];
633+
634+
snprintf(cmd, cmdLength, "\"%s/bin/vrpathreg.sh\" removedriverwithname 01spacecalibrator", cruntimePath);
635+
printf("cmd: %s\n", cmd);
636+
637+
vr::VR_Shutdown();
638+
exit(0);
639+
}
640+
#endif
641+
584642
}

OpenVR-SpaceCalibratorDriver/Comms.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class UDPServerSocket{
3333
//TODO verify that 0 is valid for UDP.
3434
sock = socket(AF_INET, SOCK_DGRAM, 0);
3535
if(sock == -1){
36-
LOG("%s", "Failed to create socket");
36+
LOG("Failed to create socket: %s", strerror(errno));
3737
return false;
3838
}
3939

4040
int err = bind(sock, (sockaddr*)&my_addr, sizeof(my_addr));
4141
if(err){
42-
LOG("%s", "Failed to bind socket");
42+
LOG("Failed to bind socket: %s", strerror(errno));
4343
return false;
4444
}
4545
return true;

OpenVR-SpaceCalibratorDriver/Logging.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
#include <chrono>
44
#include <ctime>
55

6+
#ifdef __linux__
7+
#include "StaticConfig.h"
8+
#else
9+
#define DRIVER_LOG_FILE "space_calibrator_driver.log"
10+
#endif
11+
12+
613
FILE *LogFile;
714

815
void OpenLogFile()
916
{
10-
LogFile = fopen("/tmp/space_calibrator_driver.log", "w");
17+
LogFile = fopen(DRIVER_LOG_FILE, "w");
1118
if (LogFile == nullptr)
1219
{
1320
LogFile = stderr;

OpenVR-SpaceCalibratorDriver/build.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

StaticConfig.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#cmakedefine DRIVER_LOG_FILE "@DRIVER_LOG_FILE@"
2+
#cmakedefine APP_MANIFEST_PATH "@APP_MANIFEST_PATH@"
3+
#cmakedefine DRIVER_MANIFEST_PATH "@DRIVER_MANIFEST_PATH@"
4+
#cmakedefine DRIVER_INSTALLER_PATH "@DRIVER_INSTALLER_PATH@"

driverInstall.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
import os, sys
3+
import subprocess
4+
import re
5+
import argparse
6+
7+
#vrpathreg = "/home/zack/.local/share/Steam/steamapps/common/SteamVR/bin/vrpathreg.sh"
8+
9+
def GetDrivers(vrpathreg):
10+
proc = subprocess.Popen([vrpathreg], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8')
11+
(stdout, _) = proc.communicate()
12+
13+
lineno = 0
14+
externalReg = re.compile('.*External Drivers:.*')
15+
lines = stdout.split('\n')
16+
for line in lines:
17+
lineno += 1
18+
if externalReg.match(line):
19+
break
20+
21+
lines = [ x.strip().split(':')[1].strip() for x in lines[lineno:] if len(x) > 0]
22+
return lines
23+
24+
def RemoveDriver(vrpathreg, driver):
25+
cmd = [vrpathreg, 'removedriver', driver]
26+
print(cmd)
27+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8')
28+
(stdout, _) = proc.communicate()
29+
30+
def AddDriver(vrpathreg, driver):
31+
cmd = [vrpathreg, 'adddriver', driver]
32+
print(cmd)
33+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8')
34+
(stdout, _) = proc.communicate()
35+
36+
def main():
37+
parser = argparse.ArgumentParser()
38+
39+
parser.add_argument('--toInstall', help="Driver to install (folder path)", required=True)
40+
parser.add_argument('--vrpathreg', help="Path to vrpathreg.sh", required=True)
41+
42+
args = parser.parse_args()
43+
44+
fail = False
45+
if not os.path.exists(args.toInstall):
46+
print("Driver path [{args.toInstall}] does not exist")
47+
fail = True
48+
49+
if not os.path.exists(args.vrpathreg):
50+
print("Path to vrpathreg.sh [{args.toInstall}] does not exist")
51+
fail = True
52+
53+
if fail:
54+
return
55+
56+
drivers = GetDrivers(args.vrpathreg)
57+
58+
spaceCalReg = re.compile('.*01spacecalibrator.*')
59+
60+
for driver in drivers:
61+
RemoveDriver(args.vrpathreg, driver)
62+
63+
AddDriver(args.vrpathreg, args.toInstall)
64+
65+
for driver in drivers[::-1]:
66+
if spaceCalReg.match(driver):
67+
continue
68+
69+
AddDriver(args.vrpathreg, driver)
70+
71+
pass
72+
73+
74+
if __name__ == "__main__":
75+
main()
76+

modules/gl3w

Lines changed: 0 additions & 1 deletion
This file was deleted.

modules/openvr

Submodule openvr added at 08de382

0 commit comments

Comments
 (0)