| 1 |
# Dependencies |
| 2 |
find_package(OpenGL REQUIRED) |
| 3 |
find_package(OpenSceneGraph REQUIRED COMPONENTS osgViewer osgUtil) |
| 4 |
find_package(OpenXR REQUIRED) |
| 5 |
|
| 6 |
# Old OpenXR SDK versions don't find Threads but Threads::Threads is an |
| 7 |
# INTERFACE link library of openxr_loader, so do so explicitly |
| 8 |
if(OpenXR_VERSION VERSION_LESS 1.0.14) |
| 9 |
find_package(Threads REQUIRED) |
| 10 |
endif() |
| 11 |
|
| 12 |
# Public header files |
| 13 |
set(osgXR_HEADERS |
| 14 |
include/osgXR/Action |
| 15 |
include/osgXR/ActionSet |
| 16 |
include/osgXR/CompositionLayer |
| 17 |
include/osgXR/CompositionLayerQuad |
| 18 |
include/osgXR/Export |
| 19 |
include/osgXR/InteractionProfile |
| 20 |
include/osgXR/Manager |
| 21 |
include/osgXR/Mirror |
| 22 |
include/osgXR/MirrorSettings |
| 23 |
include/osgXR/OpenXRDisplay |
| 24 |
include/osgXR/Settings |
| 25 |
include/osgXR/SubImage |
| 26 |
include/osgXR/Subaction |
| 27 |
include/osgXR/Swapchain |
| 28 |
include/osgXR/View |
| 29 |
include/osgXR/osgXR |
| 30 |
) |
| 31 |
|
| 32 |
# Source files |
| 33 |
set(osgXR_SRCS |
| 34 |
OpenXR/Action.cpp |
| 35 |
OpenXR/ActionSet.cpp |
| 36 |
OpenXR/Compositor.cpp |
| 37 |
OpenXR/DebugUtilsMessenger.cpp |
| 38 |
OpenXR/EventHandler.cpp |
| 39 |
OpenXR/GraphicsBinding.cpp |
| 40 |
OpenXR/Instance.cpp |
| 41 |
OpenXR/InteractionProfile.cpp |
| 42 |
OpenXR/Path.cpp |
| 43 |
OpenXR/Quirks.cpp |
| 44 |
OpenXR/Session.cpp |
| 45 |
OpenXR/Space.cpp |
| 46 |
OpenXR/Swapchain.cpp |
| 47 |
OpenXR/SwapchainGroup.cpp |
| 48 |
OpenXR/System.cpp |
| 49 |
XRFramebuffer.cpp |
| 50 |
XRState.cpp |
| 51 |
XRRealizeOperation.cpp |
| 52 |
XRUpdateOperation.cpp |
| 53 |
Action.cpp |
| 54 |
ActionSet.cpp |
| 55 |
CompositionLayer.cpp |
| 56 |
CompositionLayerQuad.cpp |
| 57 |
DebugCallbackOsg.cpp |
| 58 |
FrameStore.cpp |
| 59 |
InteractionProfile.cpp |
| 60 |
Manager.cpp |
| 61 |
Mirror.cpp |
| 62 |
MirrorSettings.cpp |
| 63 |
OpenXRDisplay.cpp |
| 64 |
Settings.cpp |
| 65 |
Subaction.cpp |
| 66 |
Swapchain.cpp |
| 67 |
View.cpp |
| 68 |
osgXR.cpp |
| 69 |
projection.cpp |
| 70 |
) |
| 71 |
|
| 72 |
# Win32 graphics binding |
| 73 |
if(WIN32) |
| 74 |
list(APPEND osgXR_SRCS |
| 75 |
OpenXR/GraphicsBindingWin32.cpp |
| 76 |
) |
| 77 |
add_compile_definitions(OSGXR_USE_WIN32) |
| 78 |
endif() |
| 79 |
|
| 80 |
# X11 graphics binding |
| 81 |
find_package(X11) |
| 82 |
if(X11_FOUND) |
| 83 |
list(APPEND osgXR_SRCS |
| 84 |
OpenXR/GraphicsBindingX11.cpp |
| 85 |
) |
| 86 |
add_compile_definitions(OSGXR_USE_X11) |
| 87 |
endif() |
| 88 |
|
| 89 |
|
| 90 |
# Build osgXR as a library |
| 91 |
add_library(osgXR ${osgXR_LIBRARY_TYPE} ${osgXR_SRCS}) |
| 92 |
|
| 93 |
get_target_property(osgXR_TYPE osgXR TYPE) |
| 94 |
if(osgXR_TYPE STREQUAL STATIC_LIBRARY) |
| 95 |
# Needed to switch OSGXR_EXPORT off on Windows |
| 96 |
set(OSGXR_STATIC_LIBRARY 1) |
| 97 |
endif() |
| 98 |
# Needed to switch OSGXR_EXPORT to dllexport on Windows |
| 99 |
add_compile_definitions(OSGXR_LIBRARY) |
| 100 |
|
| 101 |
# Generate a "generated/Version.h" header |
| 102 |
set(osgXR_VERSION_HEADER "${PROJECT_BINARY_DIR}/include/generated/Version.h") |
| 103 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Version.h.in" |
| 104 |
"${osgXR_VERSION_HEADER}") |
| 105 |
|
| 106 |
# Generate "osgXR/Config" header |
| 107 |
set(osgXR_CONFIG_HEADER "${PROJECT_BINARY_DIR}/include/osgXR/Config") |
| 108 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Config.in" |
| 109 |
"${osgXR_CONFIG_HEADER}") |
| 110 |
list(APPEND osgXR_HEADERS "${osgXR_CONFIG_HEADER}") |
| 111 |
|
| 112 |
# Ensure required C++ standards are available |
| 113 |
target_compile_features(osgXR |
| 114 |
# smart pointers |
| 115 |
PUBLIC cxx_std_11 |
| 116 |
# std::optional |
| 117 |
PRIVATE cxx_std_17 |
| 118 |
) |
| 119 |
|
| 120 |
# Enable compiler warnings |
| 121 |
if(OSGXR_WARNINGS) |
| 122 |
target_compile_options(osgXR PRIVATE |
| 123 |
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: |
| 124 |
-Wall -pedantic |
| 125 |
-Wextra -Wno-missing-field-initializers |
| 126 |
-Wno-unused-parameter> |
| 127 |
$<$<CXX_COMPILER_ID:MSVC>: |
| 128 |
/W4> |
| 129 |
) |
| 130 |
endif() |
| 131 |
|
| 132 |
target_include_directories(osgXR |
| 133 |
PRIVATE |
| 134 |
${PROJECT_BINARY_DIR}/include |
| 135 |
${PROJECT_SOURCE_DIR}/include |
| 136 |
${OPENGL_INCLUDE_DIR} |
| 137 |
${OPENSCENEGRAPH_INCLUDE_DIRS} |
| 138 |
${OpenXR_INCLUDE_DIR} |
| 139 |
PUBLIC |
| 140 |
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>" |
| 141 |
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>" |
| 142 |
) |
| 143 |
|
| 144 |
target_link_libraries(osgXR |
| 145 |
PRIVATE |
| 146 |
${OPENGL_LIBRARIES} |
| 147 |
PUBLIC |
| 148 |
${OPENSCENEGRAPH_LIBRARIES} |
| 149 |
OpenXR::openxr_loader |
| 150 |
) |
| 151 |
|
| 152 |
set_target_properties(osgXR |
| 153 |
PROPERTIES |
| 154 |
VERSION ${PROJECT_VERSION} |
| 155 |
SOVERSION ${osgXR_SOVERSION} |
| 156 |
PUBLIC_HEADER "${osgXR_HEADERS}" |
| 157 |
INTERFACE_osgXR_MAJOR_VERSION ${osgXR_MAJOR_VERSION} |
| 158 |
INTERFACE_osgXR_MINOR_VERSION ${osgXR_MINOR_VERSION} |
| 159 |
) |
| 160 |
set_property(TARGET osgXR APPEND PROPERTY |
| 161 |
COMPATIBLE_INTERFACE_STRING osgXR_MAJOR_VERSION osgXR_MINOR_VERSION |
| 162 |
) |