Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
286 lines (250 loc) · 10 KB
/
Copy pathCMakeLists.txt
File metadata and controls
286 lines (250 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
cmake_minimum_required(VERSION 3.16)
project(xrDriver VERSION 2.11.9 LANGUAGES C)
# Emit compile_commands.json for IDEs (VS Code IntelliSense)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
configure_file(include/version.h.in version.h)
include_directories(${PROJECT_BINARY_DIR})
# Build type: default to RelWithDebInfo for useful backtraces unless caller overrides
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel)
set(CMAKE_C_STANDARD 17)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(PkgConfig REQUIRED)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
set (py_cmd "${CMAKE_SOURCE_DIR}/bin/build_custom_banner_config.py")
set (custom_banner_header_file "${CMAKE_SOURCE_DIR}/include/custom_banner_config.h")
set (custom_banner_yaml_file "${CMAKE_SOURCE_DIR}/custom_banner_config.yml")
add_custom_target(run_python_script ALL
COMMAND ${Python3_EXECUTABLE} ${py_cmd} ${custom_banner_yaml_file} ${custom_banner_header_file}
)
if(DEFINED ENV{UA_API_SECRET})
set(UA_API_SECRET $ENV{UA_API_SECRET})
message(STATUS "Using UA_API_SECRET from environment")
add_definitions(-DUA_API_SECRET="${UA_API_SECRET}")
else()
set(UA_API_SECRET "")
message(STATUS "!!! UA_API_SECRET is NOT set")
endif()
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/license_public_key.pem DEVICE_LICENSE_PUBLIC_KEY_RAW)
string(REPLACE "\n" "\\n" DEVICE_LICENSE_PUBLIC_KEY_ESCAPED ${DEVICE_LICENSE_PUBLIC_KEY_RAW})
add_definitions(-DDEVICE_LICENSE_PUBLIC_KEY="${DEVICE_LICENSE_PUBLIC_KEY_ESCAPED}")
find_package(Threads REQUIRED)
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
pkg_check_modules(LIBEVDEV REQUIRED libevdev)
pkg_check_modules(OPENSSL REQUIRED openssl)
pkg_check_modules(JSONC REQUIRED json-c)
pkg_check_modules(CURL REQUIRED libcurl)
pkg_check_modules(LIBWAYLAND_CLIENT REQUIRED wayland-client)
execute_process(COMMAND git submodule update --init
modules/xrealInterfaceLibrary
modules/xrDeviceKit
modules/xrealAirDeviceKit
modules/xrealOneDeviceKit
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
execute_process(COMMAND git submodule update --init interface_lib/modules/hidapi
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/modules/xrealInterfaceLibrary)
execute_process(COMMAND git submodule update --init modules/Fusion
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/modules/xrDeviceKit)
execute_process(COMMAND git submodule update --init modules/xreal_one_driver
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/modules/xrealOneDeviceKit)
set(XRDEVICEKIT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/modules/xrDeviceKit")
set(XREAL_AIR_DRIVER_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/modules/xrealInterfaceLibrary")
# Link the vendored submodules (notably hidapi) statically
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build vendored submodules as static libraries" FORCE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(modules/xrealAirDeviceKit)
add_subdirectory(modules/xrealOneDeviceKit)
# Set the library directory based on architecture
set(LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/${CMAKE_SYSTEM_PROCESSOR})
set(VITURE_LIB_DIR ${LIB_DIR}/viture)
message(STATUS "LIB_DIR: ${LIB_DIR}")
if(EXISTS ${VITURE_LIB_DIR})
message(STATUS "VITURE_LIB_DIR: ${VITURE_LIB_DIR}")
endif()
# Find all .a files in the library directory
file(GLOB STATIC_LIBS ${LIB_DIR}/*.a)
if(EXISTS ${VITURE_LIB_DIR})
file(GLOB VITURE_STATIC_LIBS ${VITURE_LIB_DIR}/*.a)
list(APPEND STATIC_LIBS ${VITURE_STATIC_LIBS})
endif()
message(STATUS "STATIC_LIBS: ${STATIC_LIBS}")
# Add all static libraries
foreach(LIB ${STATIC_LIBS})
get_filename_component(LIB_NAME ${LIB} NAME_WE)
string(REPLACE "lib" "" LIB_NAME ${LIB_NAME})
add_library(${LIB_NAME} STATIC IMPORTED)
set_target_properties(${LIB_NAME} PROPERTIES
IMPORTED_LOCATION ${LIB}
)
endforeach()
# Find all .so files in the library directory
file(GLOB SHARED_LIBS ${LIB_DIR}/*.so)
if(EXISTS ${VITURE_LIB_DIR})
file(GLOB VITURE_SHARED_LIBS ${VITURE_LIB_DIR}/*.so)
list(APPEND SHARED_LIBS ${VITURE_SHARED_LIBS})
endif()
# The RayNeo SDK re-exports ~100 libusb_* symbols, which would interpose the real libusb for every
# other library in the process (see include/sdks/rayneo.h). Keep it out of the link entirely; it's
# dlopen'd with RTLD_LOCAL|RTLD_DEEPBIND when a RayNeo device shows up.
set(RAYNEO_LIB ${LIB_DIR}/libRayNeoXRMiniSDK.so)
list(REMOVE_ITEM SHARED_LIBS ${RAYNEO_LIB})
message(STATUS "SHARED_LIBS: ${SHARED_LIBS}")
# Add all shared libraries
foreach(LIB ${SHARED_LIBS})
get_filename_component(LIB_NAME ${LIB} NAME_WE)
string(REPLACE "lib" "" LIB_NAME ${LIB_NAME})
add_library(${LIB_NAME} SHARED IMPORTED)
set_target_properties(${LIB_NAME} PROPERTIES
IMPORTED_LOCATION ${LIB}
IMPORTED_SONAME ${LIB_NAME}.so
)
endforeach()
# Define the mapping of binary names to source files
set(DEVICE_MAPPINGS
"libGlassSDK.so:src/devices/rokid.c"
)
set(SOURCES
src/buffer.c
src/config.c
src/connection_pool.c
src/curl.c
src/devices/xreal.c
src/devices.c
src/driver.c
src/epoch.c
src/features/breezy_desktop.c
src/features/smooth_follow.c
src/features/sbs.c
src/files.c
src/logging.c
src/imu.c
src/imu_rate.c
src/ipc.c
src/multitap.c
src/outputs.c
src/plugins.c
src/plugins/breezy_desktop.c
src/plugins/custom_banner.c
src/plugins/device_license.c
src/plugins/gamescope_reshade_wayland.c
src/plugins/metrics.c
src/plugins/sideview.c
src/plugins/smooth_follow.c
src/plugins/virtual_display.c
src/plugins/neck_saver.c
src/plugins/opentrack_source.c
src/plugins/opentrack_listener.c
src/runtime_context.c
src/state.c
src/strings.c
src/system.c
src/wl_client/gamescope_reshade.c
)
# Function to get the source file from a mapping
function(get_source_file BINARY_NAME RESULT_VAR)
foreach(MAPPING ${DEVICE_MAPPINGS})
string(REPLACE ":" ";" MAPPING_LIST ${MAPPING})
list(GET MAPPING_LIST 0 MAPPED_BINARY)
list(GET MAPPING_LIST 1 MAPPED_SOURCE)
if(${BINARY_NAME} STREQUAL ${MAPPED_BINARY})
set(${RESULT_VAR} ${MAPPED_SOURCE} PARENT_SCOPE)
return()
endif()
endforeach()
set(${RESULT_VAR} "" PARENT_SCOPE)
endfunction()
# Get all targets in the current directory
get_property(ALL_TARGETS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY IMPORTED_TARGETS)
# Iterate over all targets
foreach(TARGET ${ALL_TARGETS})
get_target_property(LIB_TYPE ${TARGET} TYPE)
if(LIB_TYPE STREQUAL "STATIC_LIBRARY" OR LIB_TYPE STREQUAL "SHARED_LIBRARY")
get_target_property(LIB_LOCATION ${TARGET} IMPORTED_LOCATION)
if(LIB_LOCATION)
get_filename_component(LIB_NAME ${LIB_LOCATION} NAME)
get_source_file(${LIB_NAME} SOURCE_FILE)
if(SOURCE_FILE)
list(APPEND SOURCES ${SOURCE_FILE})
string(TOUPPER ${TARGET} TARGET_UPPER)
add_definitions(-D${TARGET_UPPER}_SUPPORTED)
message(STATUS "${TARGET} support enabled, added ${SOURCE_FILE}")
endif()
endif()
endif()
endforeach()
if(EXISTS ${VITURE_LIB_DIR})
list(APPEND SOURCES src/devices/viture.c)
add_definitions(-DVITURE_SUPPORTED)
message(STATUS "VITURE support enabled, added src/devices/viture.c")
endif()
# RayNeo is dlopen'd rather than linked, so it has no imported target to drive DEVICE_MAPPINGS
if(EXISTS ${RAYNEO_LIB})
list(APPEND SOURCES src/devices/rayneo.c)
add_definitions(-DRAYNEOXRMINISDK_SUPPORTED)
message(STATUS "RayNeo support enabled, added src/devices/rayneo.c")
endif()
add_executable(xrDriver ${SOURCES})
# Improve crash backtraces and line number resolution
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
# Per-config compile options
target_compile_options(xrDriver PRIVATE
$<$<CONFIG:Debug>:-g3>
$<$<CONFIG:Debug>:-O0>
$<$<CONFIG:Debug>:-fno-omit-frame-pointer>
$<$<CONFIG:RelWithDebInfo>:-g>
$<$<CONFIG:RelWithDebInfo>:-fno-omit-frame-pointer>
)
# Export symbol table for better backtrace_symbols() resolution
target_link_options(xrDriver PRIVATE
$<$<CONFIG:Debug>:-rdynamic>
$<$<CONFIG:RelWithDebInfo>:-rdynamic>
)
endif()
# Optional: AddressSanitizer for clearer reports on memory errors
option(ENABLE_ASAN "Build with AddressSanitizer" OFF)
if(ENABLE_ASAN AND CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(xrDriver PRIVATE -fsanitize=address -fno-omit-frame-pointer -g)
target_link_options(xrDriver PRIVATE -fsanitize=address)
endif()
target_include_directories(xrDriver
SYSTEM BEFORE PRIVATE
${LIBEVDEV_INCLUDE_DIRS}
${JSONC_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/modules/rayneoSDKHeaders
${XREALAIRDEVICEKIT_INCLUDE_DIR}
${XREALONEDEVICEKIT_INCLUDE_DIR}
${LIBUSB_INCLUDE_DIRS}
${LIBCURL_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIRS}
${LIBWAYLAND_CLIENT_INCLUDE_DIRS}
)
set(ALL_IMPORTED_LIBS)
get_property(ALL_TARGETS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY IMPORTED_TARGETS)
foreach(TARGET ${ALL_TARGETS})
get_target_property(LIB_TYPE ${TARGET} TYPE)
if(LIB_TYPE STREQUAL "STATIC_LIBRARY" OR LIB_TYPE STREQUAL "SHARED_LIBRARY")
list(APPEND ALL_IMPORTED_LIBS ${TARGET})
endif()
endforeach()
target_link_libraries(xrDriver
PRIVATE
${LIBEVDEV_LIBRARIES}
${JSONC_LIBRARIES}
xrealAirDeviceKit
xrealOneDeviceKit
Threads::Threads
m
${CURL_LIBRARIES}
${OPENSSL_LIBRARIES}
${ALL_IMPORTED_LIBS}
${LIBUSB_LIBRARIES}
${LIBWAYLAND_CLIENT_LIBRARIES}
${CMAKE_DL_LIBS}
)
# dlopen("libRayNeoXRMiniSDK.so") consults the executable's RUNPATH, so keep LIB_DIR on it even
# though nothing in LIB_DIR is linked directly any more
set_target_properties(xrDriver PROPERTIES BUILD_RPATH "${LIB_DIR}")
add_dependencies(xrDriver run_python_script)