Skip to content

Add FSO_BUILD_WITH_OPENXR cmake option #6477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ OPTION(FSO_BUILD_WITH_OPENGL_DEBUG "Enables debug option for OpenGL" OFF)

OPTION(FSO_BUILD_WITH_VULKAN "Enable compilation of the Vulkan renderer" OFF)

IF(NOT APPLE)
SET(OPENXR_BUILD_DEFAULT ON)
ELSE()
SET(OPENXR_BUILD_DEFAULT OFF)
ENDIF()
OPTION(FSO_BUILD_WITH_OPENXR "Build with OpenXR support" ${OPENXR_BUILD_DEFAULT})
IF(FSO_BUILD_WITH_OPENXR AND APPLE)
MESSAGE(WARNING "FSO_BUILD_WITH_OPENXR is ON. Not supported on macOS - setting to OFF.")
SET(FSO_BUILD_WITH_OPENXR OFF CACHE BOOL "" FORCE)
ENDIF()

OPTION(FSO_BUILD_WITH_OPENXR_DEBUG "Enables debug option for OpenXR" OFF)

OPTION(FSO_USE_LTO "Build using LTO (only for release builds)" ON)
Expand All @@ -144,6 +155,7 @@ mark_as_advanced(FORCE FSO_BUILD_WITH_FFMPEG)
mark_as_advanced(FORCE FSO_BUILD_WITH_OPENGL)
mark_as_advanced(FORCE FSO_BUILD_WITH_OPENGL_DEBUG)
mark_as_advanced(FORCE FSO_BUILD_WITH_VULKAN)
mark_as_advanced(FORCE FSO_BUILD_WITH_OPENXR)
mark_as_advanced(FORCE FSO_BUILD_WITH_OPENXR_DEBUG)

# Include cotire file from https://github.com/sakra/cotire/
Expand Down Expand Up @@ -233,3 +245,4 @@ message(STATUS "Release logging: ${FSO_RELEASE_LOGGING}")
message(STATUS "With FFmpeg: ${FSO_BUILD_WITH_FFMPEG}")
message(STATUS "With OpenGL: ${FSO_BUILD_WITH_OPENGL}")
message(STATUS "With Vulkan: ${FSO_BUILD_WITH_VULKAN}")
message(STATUS "With OpenXR: ${FSO_BUILD_WITH_OPENXR}")
10 changes: 7 additions & 3 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ if (FSO_BUILD_WITH_OPENGL)
endif()
endif()

if(FSO_BUILD_WITH_OPENXR_DEBUG)
if(FSO_BUILD_WITH_OPENXR)
add_definitions(-DFS_OPENXR)
endif()

if(FSO_BUILD_WITH_OPENXR_DEBUG AND FSO_BUILD_WITH_OPENXR)
add_definitions(-DFS_OPENXR_DEBUG)
endif()

Expand Down Expand Up @@ -79,7 +83,7 @@ target_link_libraries(code PUBLIC hidapi::hidapi)

target_link_libraries(code PUBLIC imgui)

IF(NOT APPLE)
IF(FSO_BUILD_WITH_OPENXR)
target_link_libraries(code PUBLIC OpenXR::openxr_loader)
target_include_directories(code PUBLIC OpenXR::Headers)
ENDIF()
Expand Down Expand Up @@ -139,4 +143,4 @@ set_target_properties(code PROPERTIES XCODE_ATTRIBUTE_STRIP_INSTALLED_PRODUCT[va
set_target_properties(code PROPERTIES XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN[variant=Debug] "NO")

# Prevent GCC warnings in third-party BitOp... see GitHub #4366
suppress_file_warnings(scripting/lua/bitop/bit.c)
suppress_file_warnings(scripting/lua/bitop/bit.c)
6 changes: 3 additions & 3 deletions code/graphics/opengl/gropenglopenxr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "graphics/opengl/ShaderProgram.h"
#include "osapi/osapi.h"

#if defined __APPLE_CC__
#ifndef FS_OPENXR

//Not supported

Expand All @@ -38,7 +38,7 @@

#include <SDL_syswm.h>

#ifndef __APPLE_CC__
#ifdef FS_OPENXR

//SETUP FUNCTIONS OGL
SCP_vector<const char*> gr_opengl_openxr_get_extensions() {
Expand Down Expand Up @@ -473,4 +473,4 @@ bool gr_opengl_openxr_acquire_swapchain_buffers() { return false; }

bool gr_opengl_openxr_flip() { return false; }

#endif
#endif
9 changes: 5 additions & 4 deletions code/graphics/openxr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

std::unique_ptr<star[]> Stars_XRBuffer;

#ifndef __APPLE_CC__
#ifdef FS_OPENXR

#define XR_MAKE_VERSION_SHORT(major, minor, patch) \
((((major) & 0x3ffU) << 20) | (((minor) & 0x3ffU) << 10) | ((patch) & 0x3ffU))
Expand Down Expand Up @@ -522,12 +522,13 @@ void openxr_start_frame() {
}

#else
//Stubs for Mac, as linking with OpenXR causes issues there.
// Stubs for when building without OpenXR support.
// NOTE: macOS has issues linking with OpenXR.

void openxr_prepare(float hudscale) {}

float openxr_preinit(float req_ar, float scale) {
mprintf(("Cannot create OpenXR session on macOS.\n"));
mprintf(("Cannot create OpenXR session. Not built with OpenXR support.\n"));
return 0.0f;
}

Expand All @@ -545,4 +546,4 @@ bool openxr_requested() { return false; }

OpenXRTrackingInfo openxr_start_stereo_frame() { return OpenXRTrackingInfo{}; }

#endif
#endif
4 changes: 2 additions & 2 deletions code/graphics/openxr_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <type_traits>
#include <tl/optional.hpp>

#ifndef __APPLE_CC__
#ifdef FS_OPENXR

#include <openxr/openxr.h>
#include <openxr/openxr_platform.h>
Expand Down Expand Up @@ -51,4 +51,4 @@ tl::optional<std::invoke_result_t<openxr_fnc,arg_t...>> openxr_callExtensionFunc
return func(std::forward<arg_t>(args)...);
}

#endif
#endif
4 changes: 2 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ add_subdirectory(hidapi)

ADD_SUBDIRECTORY(imgui)

if(NOT APPLE)
if(FSO_BUILD_WITH_OPENXR)
add_subdirectory(openxr)
endif()
endif()
Loading