Skip to content

Commit d5882cd

Browse files
committed
build: Be more precise in actually searching for D3D11/12
Fixes build of hello_xr on MinGW
1 parent 03adb8d commit d5882cd

7 files changed

+50
-11
lines changed

Diff for: src/CMakeLists.txt

+20-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,26 @@ function(compile_glsl run_target_name)
203203
endfunction()
204204

205205
if(WIN32)
206-
add_definitions(-DXR_USE_GRAPHICS_API_D3D11)
207-
add_definitions(-DXR_USE_GRAPHICS_API_D3D12)
206+
# This is too simple of detection to be worth separating into a find module
207+
find_library(D3D_DXGI_LIBRARY dxgi)
208+
find_library(D3D_COMPILER_LIBRARY d3dcompiler)
209+
find_path(D3D_D3D11_INCLUDE_DIR d3d11.h)
210+
find_library(D3D_D3D11_LIBRARY d3d11)
211+
if(D3D_D3D11_INCLUDE_DIR AND D3D_D3D11_LIBRARY AND D3D_DXGI_LIBRARY AND D3D_COMPILER_LIBRARY)
212+
set(D3D_D3D11_FOUND ON)
213+
set(D3D_D3D11_LIBRARIES ${D3D_D3D11_LIBRARY} ${D3D_DXGI_LIBRARY} ${D3D_COMPILER_LIBRARY})
214+
add_definitions(-DXR_USE_GRAPHICS_API_D3D11)
215+
endif()
216+
217+
find_path(D3D_D3D12_INCLUDE_DIR d3d12.h)
218+
find_library(D3D_D3D12_LIBRARY d3d12)
219+
if(D3D_D3D12_INCLUDE_DIR AND D3D_D3D12_LIBRARY AND D3D_DXGI_LIBRARY)
220+
set(D3D_D3D12_FOUND ON)
221+
set(D3D_D3D12_LIBRARIES ${D3D_D3D12_LIBRARY} ${D3D_DXGI_LIBRARY} ${D3D_COMPILER_LIBRARY})
222+
add_definitions(-DXR_USE_GRAPHICS_API_D3D12)
223+
endif()
224+
225+
find_path(D3D_DIRECTXCOLORS_INCLUDE_DIR DirectXColors.h)
208226
endif()
209227

210228
# Check for the existence of the secure_getenv or __secure_getenv commands

Diff for: src/tests/hello_xr/CMakeLists.txt

+15-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,21 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
6969
target_compile_definitions(hello_xr PRIVATE _CRT_SECURE_NO_WARNINGS)
7070
target_compile_options(hello_xr PRIVATE /Zc:wchar_t /Zc:forScope /W4 /WX)
7171
endif()
72-
target_link_libraries(hello_xr d3d11 d3d12 d3dcompiler dxgi ole32 ${OPENGL_gl_LIBRARY})
72+
target_link_libraries(hello_xr ole32)
73+
if(D3D_D3D11_FOUND AND D3D_DIRECTXCOLORS_INCLUDE_DIR)
74+
target_link_libraries(hello_xr ${D3D_D3D11_LIBRARIES})
75+
target_include_directories(hello_xr PRIVATE ${D3D_D3D11_INCLUDE_DIR} ${D3D_DIRECTXCOLORS_INCLUDE_DIR})
76+
endif()
77+
if(D3D_D3D12_FOUND AND D3D_DIRECTXCOLORS_INCLUDE_DIR)
78+
target_link_libraries(hello_xr ${D3D_D3D12_LIBRARIES})
79+
target_include_directories(hello_xr PRIVATE ${D3D_D3D12_INCLUDE_DIR} ${D3D_DIRECTXCOLORS_INCLUDE_DIR})
80+
endif()
81+
if(NOT D3D_DIRECTXCOLORS_INCLUDE_DIR)
82+
target_compile_definitions(hello_xr PRIVATE -DMISSING_DIRECTX_COLORS)
83+
endif()
84+
if(OPENGL_FOUND)
85+
target_link_libraries(hello_xr ${OPENGL_gl_LIBRARY})
86+
endif()
7387
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
7488
target_compile_options(hello_xr PRIVATE -Wall)
7589
target_link_libraries(hello_xr m pthread)

Diff for: src/tests/hello_xr/d3d_common.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "pch.h"
22
#include "common.h"
33

4-
#if defined(XR_USE_GRAPHICS_API_D3D11) || defined(XR_USE_GRAPHICS_API_D3D12)
4+
#if (defined(XR_USE_GRAPHICS_API_D3D11) || defined(XR_USE_GRAPHICS_API_D3D12)) && !defined(MISSING_DIRECTX_COLORS)
55

66
#include <common/xr_linear.h>
77
#include <DirectXColors.h>

Diff for: src/tests/hello_xr/graphicsplugin_d3d11.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "geometry.h"
44
#include "graphicsplugin.h"
55

6-
#if defined(XR_USE_GRAPHICS_API_D3D11) && !defined(__MINGW32__)
6+
#if defined(XR_USE_GRAPHICS_API_D3D12) && !defined(MISSING_DIRECTX_COLORS)
77

88
#include <common/xr_linear.h>
99
#include <DirectXColors.h>

Diff for: src/tests/hello_xr/graphicsplugin_d3d12.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "geometry.h"
44
#include "graphicsplugin.h"
55

6-
#ifdef XR_USE_GRAPHICS_API_D3D12
6+
#if defined(XR_USE_GRAPHICS_API_D3D12) && !defined(MISSING_DIRECTX_COLORS)
77

88
#include <common/xr_linear.h>
99
#include <DirectXColors.h>

Diff for: src/tests/hello_xr/graphicsplugin_factory.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_OpenGL(const std::shared_p
1919
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_Vulkan(const std::shared_ptr<Options>& options,
2020
std::shared_ptr<IPlatformPlugin> platformPlugin);
2121
#endif
22-
#if defined(XR_USE_GRAPHICS_API_D3D11) && !defined(__MINGW32__)
22+
#if defined(XR_USE_GRAPHICS_API_D3D11) && !defined(MISSING_DIRECTX_COLORS)
2323
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_D3D11(const std::shared_ptr<Options>& options,
2424
std::shared_ptr<IPlatformPlugin> platformPlugin);
2525
#endif
26-
#ifdef XR_USE_GRAPHICS_API_D3D12
26+
#if defined(XR_USE_GRAPHICS_API_D3D12) && !defined(MISSING_DIRECTX_COLORS)
2727
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_D3D12(const std::shared_ptr<Options>& options,
2828
std::shared_ptr<IPlatformPlugin> platformPlugin);
2929
#endif
@@ -51,13 +51,13 @@ std::map<std::string, GraphicsPluginFactory, IgnoreCaseStringLess> graphicsPlugi
5151
return CreateGraphicsPlugin_Vulkan(options, std::move(platformPlugin));
5252
}},
5353
#endif
54-
#if defined(XR_USE_GRAPHICS_API_D3D11) && !defined(__MINGW32__)
54+
#if defined(XR_USE_GRAPHICS_API_D3D11) && !defined(MISSING_DIRECTX_COLORS)
5555
{"D3D11",
5656
[](const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> platformPlugin) {
5757
return CreateGraphicsPlugin_D3D11(options, std::move(platformPlugin));
5858
}},
5959
#endif
60-
#ifdef XR_USE_GRAPHICS_API_D3D12
60+
#if defined(XR_USE_GRAPHICS_API_D3D12) && !defined(MISSING_DIRECTX_COLORS)
6161
{"D3D12",
6262
[](const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> platformPlugin) {
6363
return CreateGraphicsPlugin_D3D12(options, std::move(platformPlugin));

Diff for: src/tests/loader_test/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
5050
target_compile_definitions(loader_test PRIVATE _CRT_SECURE_NO_WARNINGS)
5151
target_compile_options(loader_test PRIVATE /Zc:wchar_t /Zc:forScope /W4 /WX)
5252
endif()
53-
target_link_libraries(loader_test openxr_loader opengl32 d3d11)
53+
target_link_libraries(loader_test openxr_loader)
54+
if(OPENGL_FOUND)
55+
target_link_libraries(loader_test opengl32)
56+
endif()
57+
if(D3D_D3D11_FOUND)
58+
target_link_libraries(loader_test d3d11)
59+
endif()
60+
5461
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
5562
target_compile_options(
5663
loader_test PRIVATE -Wall -Wno-unused-function -Wno-format-truncation

0 commit comments

Comments
 (0)