diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a80a5d9..81dccb9c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -203,8 +203,26 @@ function(compile_glsl run_target_name) endfunction() if(WIN32) - add_definitions(-DXR_USE_GRAPHICS_API_D3D11) - add_definitions(-DXR_USE_GRAPHICS_API_D3D12) + # This is too simple of detection to be worth separating into a find module + find_library(D3D_DXGI_LIBRARY dxgi) + find_library(D3D_COMPILER_LIBRARY d3dcompiler) + find_path(D3D_D3D11_INCLUDE_DIR d3d11.h) + find_library(D3D_D3D11_LIBRARY d3d11) + if(D3D_D3D11_INCLUDE_DIR AND D3D_D3D11_LIBRARY AND D3D_DXGI_LIBRARY AND D3D_COMPILER_LIBRARY) + set(D3D_D3D11_FOUND ON) + set(D3D_D3D11_LIBRARIES ${D3D_D3D11_LIBRARY} ${D3D_DXGI_LIBRARY} ${D3D_COMPILER_LIBRARY}) + add_definitions(-DXR_USE_GRAPHICS_API_D3D11) + endif() + + find_path(D3D_D3D12_INCLUDE_DIR d3d12.h) + find_library(D3D_D3D12_LIBRARY d3d12) + if(D3D_D3D12_INCLUDE_DIR AND D3D_D3D12_LIBRARY AND D3D_DXGI_LIBRARY) + set(D3D_D3D12_FOUND ON) + set(D3D_D3D12_LIBRARIES ${D3D_D3D12_LIBRARY} ${D3D_DXGI_LIBRARY} ${D3D_COMPILER_LIBRARY}) + add_definitions(-DXR_USE_GRAPHICS_API_D3D12) + endif() + + find_path(D3D_DIRECTXCOLORS_INCLUDE_DIR DirectXColors.h) endif() # Check for the existence of the secure_getenv or __secure_getenv commands diff --git a/src/tests/hello_xr/CMakeLists.txt b/src/tests/hello_xr/CMakeLists.txt index 4f119f05..bff9fea7 100644 --- a/src/tests/hello_xr/CMakeLists.txt +++ b/src/tests/hello_xr/CMakeLists.txt @@ -69,7 +69,21 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") target_compile_definitions(hello_xr PRIVATE _CRT_SECURE_NO_WARNINGS) target_compile_options(hello_xr PRIVATE /Zc:wchar_t /Zc:forScope /W4 /WX) endif() - target_link_libraries(hello_xr d3d11 d3d12 d3dcompiler dxgi ole32 ${OPENGL_gl_LIBRARY}) + target_link_libraries(hello_xr ole32) + if(D3D_D3D11_FOUND AND D3D_DIRECTXCOLORS_INCLUDE_DIR) + target_link_libraries(hello_xr ${D3D_D3D11_LIBRARIES}) + target_include_directories(hello_xr PRIVATE ${D3D_D3D11_INCLUDE_DIR} ${D3D_DIRECTXCOLORS_INCLUDE_DIR}) + endif() + if(D3D_D3D12_FOUND AND D3D_DIRECTXCOLORS_INCLUDE_DIR) + target_link_libraries(hello_xr ${D3D_D3D12_LIBRARIES}) + target_include_directories(hello_xr PRIVATE ${D3D_D3D12_INCLUDE_DIR} ${D3D_DIRECTXCOLORS_INCLUDE_DIR}) + endif() + if(NOT D3D_DIRECTXCOLORS_INCLUDE_DIR) + target_compile_definitions(hello_xr PRIVATE -DMISSING_DIRECTX_COLORS) + endif() + if(OPENGL_FOUND) + target_link_libraries(hello_xr ${OPENGL_gl_LIBRARY}) + endif() elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") target_compile_options(hello_xr PRIVATE -Wall) target_link_libraries(hello_xr m pthread) diff --git a/src/tests/hello_xr/d3d_common.cpp b/src/tests/hello_xr/d3d_common.cpp index 440c97e7..2e92ced0 100644 --- a/src/tests/hello_xr/d3d_common.cpp +++ b/src/tests/hello_xr/d3d_common.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "common.h" -#if defined(XR_USE_GRAPHICS_API_D3D11) || defined(XR_USE_GRAPHICS_API_D3D12) +#if (defined(XR_USE_GRAPHICS_API_D3D11) || defined(XR_USE_GRAPHICS_API_D3D12)) && !defined(MISSING_DIRECTX_COLORS) #include #include diff --git a/src/tests/hello_xr/graphicsplugin_d3d11.cpp b/src/tests/hello_xr/graphicsplugin_d3d11.cpp index e5a05858..ae66866e 100644 --- a/src/tests/hello_xr/graphicsplugin_d3d11.cpp +++ b/src/tests/hello_xr/graphicsplugin_d3d11.cpp @@ -3,7 +3,7 @@ #include "geometry.h" #include "graphicsplugin.h" -#if defined(XR_USE_GRAPHICS_API_D3D11) && !defined(__MINGW32__) +#if defined(XR_USE_GRAPHICS_API_D3D12) && !defined(MISSING_DIRECTX_COLORS) #include #include diff --git a/src/tests/hello_xr/graphicsplugin_d3d12.cpp b/src/tests/hello_xr/graphicsplugin_d3d12.cpp index 95683c6c..5b144831 100644 --- a/src/tests/hello_xr/graphicsplugin_d3d12.cpp +++ b/src/tests/hello_xr/graphicsplugin_d3d12.cpp @@ -3,7 +3,7 @@ #include "geometry.h" #include "graphicsplugin.h" -#ifdef XR_USE_GRAPHICS_API_D3D12 +#if defined(XR_USE_GRAPHICS_API_D3D12) && !defined(MISSING_DIRECTX_COLORS) #include #include diff --git a/src/tests/hello_xr/graphicsplugin_factory.cpp b/src/tests/hello_xr/graphicsplugin_factory.cpp index 18d3964c..c7781b03 100644 --- a/src/tests/hello_xr/graphicsplugin_factory.cpp +++ b/src/tests/hello_xr/graphicsplugin_factory.cpp @@ -19,11 +19,11 @@ std::shared_ptr CreateGraphicsPlugin_OpenGL(const std::shared_p std::shared_ptr CreateGraphicsPlugin_Vulkan(const std::shared_ptr& options, std::shared_ptr platformPlugin); #endif -#if defined(XR_USE_GRAPHICS_API_D3D11) && !defined(__MINGW32__) +#if defined(XR_USE_GRAPHICS_API_D3D11) && !defined(MISSING_DIRECTX_COLORS) std::shared_ptr CreateGraphicsPlugin_D3D11(const std::shared_ptr& options, std::shared_ptr platformPlugin); #endif -#ifdef XR_USE_GRAPHICS_API_D3D12 +#if defined(XR_USE_GRAPHICS_API_D3D12) && !defined(MISSING_DIRECTX_COLORS) std::shared_ptr CreateGraphicsPlugin_D3D12(const std::shared_ptr& options, std::shared_ptr platformPlugin); #endif @@ -51,13 +51,13 @@ std::map graphicsPlugi return CreateGraphicsPlugin_Vulkan(options, std::move(platformPlugin)); }}, #endif -#if defined(XR_USE_GRAPHICS_API_D3D11) && !defined(__MINGW32__) +#if defined(XR_USE_GRAPHICS_API_D3D11) && !defined(MISSING_DIRECTX_COLORS) {"D3D11", [](const std::shared_ptr& options, std::shared_ptr platformPlugin) { return CreateGraphicsPlugin_D3D11(options, std::move(platformPlugin)); }}, #endif -#ifdef XR_USE_GRAPHICS_API_D3D12 +#if defined(XR_USE_GRAPHICS_API_D3D12) && !defined(MISSING_DIRECTX_COLORS) {"D3D12", [](const std::shared_ptr& options, std::shared_ptr platformPlugin) { return CreateGraphicsPlugin_D3D12(options, std::move(platformPlugin)); diff --git a/src/tests/loader_test/CMakeLists.txt b/src/tests/loader_test/CMakeLists.txt index 5b6808ef..fa46b449 100644 --- a/src/tests/loader_test/CMakeLists.txt +++ b/src/tests/loader_test/CMakeLists.txt @@ -50,7 +50,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") target_compile_definitions(loader_test PRIVATE _CRT_SECURE_NO_WARNINGS) target_compile_options(loader_test PRIVATE /Zc:wchar_t /Zc:forScope /W4 /WX) endif() - target_link_libraries(loader_test openxr_loader opengl32 d3d11) + target_link_libraries(loader_test openxr_loader) + if(OPENGL_FOUND) + target_link_libraries(loader_test opengl32) + endif() + if(D3D_D3D11_FOUND) + target_link_libraries(loader_test d3d11) + endif() + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") target_compile_options( loader_test PRIVATE -Wall -Wno-unused-function -Wno-format-truncation