Skip to content

Commit

Permalink
build: Be more precise in actually searching for D3D11/12
Browse files Browse the repository at this point in the history
Fixes build of hello_xr on MinGW
  • Loading branch information
rpavlik committed May 6, 2020
1 parent 03adb8d commit d5882cd
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 deletions.
22 changes: 20 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion src/tests/hello_xr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/hello_xr/d3d_common.cpp
Original file line number Diff line number Diff line change
@@ -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 <common/xr_linear.h>
#include <DirectXColors.h>
Expand Down
2 changes: 1 addition & 1 deletion src/tests/hello_xr/graphicsplugin_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <common/xr_linear.h>
#include <DirectXColors.h>
Expand Down
2 changes: 1 addition & 1 deletion src/tests/hello_xr/graphicsplugin_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <common/xr_linear.h>
#include <DirectXColors.h>
Expand Down
8 changes: 4 additions & 4 deletions src/tests/hello_xr/graphicsplugin_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_OpenGL(const std::shared_p
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_Vulkan(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> 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<IGraphicsPlugin> CreateGraphicsPlugin_D3D11(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin);
#endif
#ifdef XR_USE_GRAPHICS_API_D3D12
#if defined(XR_USE_GRAPHICS_API_D3D12) && !defined(MISSING_DIRECTX_COLORS)
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_D3D12(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin);
#endif
Expand Down Expand Up @@ -51,13 +51,13 @@ std::map<std::string, GraphicsPluginFactory, IgnoreCaseStringLess> 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>& options, std::shared_ptr<IPlatformPlugin> 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>& options, std::shared_ptr<IPlatformPlugin> platformPlugin) {
return CreateGraphicsPlugin_D3D12(options, std::move(platformPlugin));
Expand Down
9 changes: 8 additions & 1 deletion src/tests/loader_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d5882cd

Please sign in to comment.