Skip to content

Commit

Permalink
CMake: reworked D3D11/D3D12 support and Windows SDK version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 20, 2023
1 parent 813864e commit 8c50b10
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions BuildTools/CMake/CheckATL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <atlbase.h>

int main()
{
return 0;
}
6 changes: 6 additions & 0 deletions BuildTools/CMake/CheckD3D11.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <d3d11.h>

int main()
{
return 0;
}
6 changes: 6 additions & 0 deletions BuildTools/CMake/CheckD3D12.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <d3d12.h>

int main()
{
return 0;
}
47 changes: 30 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,24 @@ endif()
message("CMake generator: " ${CMAKE_GENERATOR})

if(WIN32)
if (CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
set(WINDOWS_SDK_VERSION ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} CACHE INTERNAL "Windows SDK version")
elseif(DEFINED ENV{WindowsSDKVersion})
set(WINDOWS_SDK_VERSION $ENV{WindowsSDKVersion})
# For unbeknown reason, the environment variable ends with a backslash, so we need to remove it
string(REPLACE "\\" "" WINDOWS_SDK_VERSION ${WINDOWS_SDK_VERSION})
set(WINDOWS_SDK_VERSION ${WINDOWS_SDK_VERSION} CACHE INTERNAL "Windows SDK version")
else()
set(WINDOWS_SDK_VERSION "0.0" CACHE INTERNAL "Windows SDK version")
message(WARNING "Unable to determine Windows SDK version: niether CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION CMake variable nor WindowsSDKVersion environment variable is set")

Check failure on line 111 in CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Linux -> Pre-checks

niether ==> neither
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
set(PLATFORM_UNIVERSAL_WINDOWS TRUE CACHE INTERNAL "Target platform: Windows Store")
message("Target platform: Universal Windows " ${ARCH} ". SDK Version: " ${CMAKE_SYSTEM_VERSION})
message("Target platform: Universal Windows " ${ARCH} ". Windows SDK Version: " ${WINDOWS_SDK_VERSION})
else()
set(PLATFORM_WIN32 TRUE CACHE INTERNAL "Target platform: Win32") #WIN32 is a variable, so we cannot use string "WIN32"
message("Target platform: Win32 " ${ARCH} ". SDK Version: " ${CMAKE_SYSTEM_VERSION})
message("Target platform: Win32 " ${ARCH} ". Windows SDK Version: " ${WINDOWS_SDK_VERSION})
endif()
else()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
Expand Down Expand Up @@ -141,28 +153,29 @@ endif()

add_library(Diligent-PublicBuildSettings INTERFACE)

if(PLATFORM_WIN32)
if(MSVC)
set(D3D11_SUPPORTED TRUE CACHE INTERNAL "D3D11 is supported on Win32 platform")
if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "10.0")
set(D3D12_SUPPORTED TRUE CACHE INTERNAL "D3D12 is supported on Win32 platform")
endif()
if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS)
try_compile(HAS_D3D11 "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/BuildTools/CMake/CheckD3D11.cpp")
try_compile(HAS_D3D12 "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/BuildTools/CMake/CheckD3D12.cpp")
try_compile(HAS_ATL "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/BuildTools/CMake/CheckATL.cpp")

if (HAS_D3D11 AND HAS_ATL)
set(D3D11_SUPPORTED TRUE CACHE INTERNAL "D3D11 is supported")
else()
message("Building with MinGW")
set(MINGW_BUILD TRUE CACHE INTERNAL "Building with MinGW")
set(D3D11_SUPPORTED FALSE CACHE INTERNAL "D3D11 requires compiling with MSVC")
set(D3D12_SUPPORTED FALSE CACHE INTERNAL "D3D12 requires compiling with MSVC")
set(D3D11_SUPPORTED FALSE CACHE INTERNAL "D3D11 is not supported")
endif()
if (HAS_D3D12 AND HAS_ATL)
set(D3D12_SUPPORTED TRUE CACHE INTERNAL "D3D12 is supported")
else()
set(D3D12_SUPPORTED FALSE CACHE INTERNAL "D3D12 is not supported")
endif()
endif()

if(PLATFORM_WIN32)
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on Win32 platform")
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is supported on Win32 platform")
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Win32 platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_WIN32=1)
elseif(PLATFORM_UNIVERSAL_WINDOWS)
set(D3D11_SUPPORTED TRUE CACHE INTERNAL "D3D11 is supported on Universal Windows platform")
if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "10.0")
set(D3D12_SUPPORTED TRUE CACHE INTERNAL "D3D12 is supported on Universal Windows platform")
endif()
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Universal Windows platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_UNIVERSAL_WINDOWS=1)
elseif(PLATFORM_ANDROID)
Expand Down Expand Up @@ -496,7 +509,7 @@ elseif (NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX})
message("Transformed CMAKE_INSTALL_PREFIX into absolute path: " ${CMAKE_INSTALL_PREFIX})
endif()

include(BuildUtils.cmake)
include(BuildTools/CMake/BuildUtils.cmake)

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
# Find available .NET SDKs
Expand Down
4 changes: 2 additions & 2 deletions Graphics/GraphicsEngineD3DBase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ if(MSVC)

# Note that CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION is stated to be defined when targeting Windows 10
# and above, however it is also defined when targeting 8.1 and Visual Studio 2019 (but not VS2017)
if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "10.0")
if("${WINDOWS_SDK_VERSION}" VERSION_GREATER_EQUAL "10.0")
if (DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
# Note that VS_WINDOWS_SDK_BIN_DIR as well as all derived paths can only be used in Visual Studio
# commands and are not valid paths during CMake configuration
Expand All @@ -94,7 +94,7 @@ if(MSVC)
set(VS_DXIL_SIGNER_PATH "\"${VS_WINDOWS_SDK_BIN_DIR}\\dxil.dll\"" CACHE INTERNAL "dxil.dll path")
endif()
endif()
elseif(CMAKE_SYSTEM_VERSION VERSION_EQUAL "8.1")
elseif("${WINDOWS_SDK_VERSION}" VERSION_EQUAL "8.1")
# D3Dcompiler_47.dll from Win8.1 SDK is ancient (from 2013) and fails to
# compile a number of test shaders. Use the compiler from Visual Studio
# executable path instead
Expand Down

0 comments on commit 8c50b10

Please sign in to comment.