Skip to content

Commit 635d3a3

Browse files
CMake: improved d3dcompiler.dll, dxcompiler.dll and dxil.dll detection (close #467)
1 parent dc40a95 commit 635d3a3

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed

BuildTools/CMake/BuildUtils.cmake

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,16 @@ if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS)
3232

3333
# Copy D3Dcompiler_47.dll, dxcompiler.dll, and dxil.dll
3434
if(MSVC)
35-
if ((D3D11_SUPPORTED OR D3D12_SUPPORTED) AND VS_D3D_COMPILER_PATH)
36-
# Note that VS_D3D_COMPILER_PATH can only be used in a Visual Studio command
37-
# and is not a valid path during CMake configuration
38-
list(APPEND SHADER_COMPILER_DLLS ${VS_D3D_COMPILER_PATH})
35+
if ((D3D11_SUPPORTED OR D3D12_SUPPORTED) AND D3D_COMPILER_PATH)
36+
list(APPEND SHADER_COMPILER_DLLS "${D3D_COMPILER_PATH}")
3937
endif()
4038

41-
if(D3D12_SUPPORTED AND VS_DXC_COMPILER_PATH AND VS_DXIL_SIGNER_PATH)
39+
if(D3D12_SUPPORTED AND DXC_COMPILER_PATH AND DXIL_SIGNER_PATH)
4240
# For the compiler to sign the bytecode, you have to have a copy of dxil.dll in
4341
# the same folder as the dxcompiler.dll at runtime.
4442

45-
# Note that VS_DXC_COMPILER_PATH and VS_DXIL_SIGNER_PATH can only be used in a Visual Studio command
46-
# and are not valid paths during CMake configuration
47-
list(APPEND SHADER_COMPILER_DLLS ${VS_DXC_COMPILER_PATH})
48-
list(APPEND SHADER_COMPILER_DLLS ${VS_DXIL_SIGNER_PATH})
43+
list(APPEND SHADER_COMPILER_DLLS "${DXC_COMPILER_PATH}")
44+
list(APPEND SHADER_COMPILER_DLLS "${DXIL_SIGNER_PATH}")
4945
endif()
5046

5147
foreach(DLL ${SHADER_COMPILER_DLLS})
@@ -77,18 +73,16 @@ if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS)
7773
endfunction()
7874

7975
function(package_required_dlls TARGET_NAME)
80-
if(D3D12_SUPPORTED AND VS_DXC_COMPILER_PATH AND VS_DXIL_SIGNER_PATH)
76+
if(D3D12_SUPPORTED AND DXC_COMPILER_PATH AND DXIL_SIGNER_PATH)
8177
# Copy the dlls to the project's CMake binary dir
8278

83-
# Note that VS_DXC_COMPILER_PATH and VS_DXIL_SIGNER_PATH can only be used in a Visual Studio command
84-
# and are not valid paths during CMake configuration
8579
add_custom_command(TARGET ${TARGET_NAME} PRE_BUILD
8680
COMMAND ${CMAKE_COMMAND} -E copy_if_different
87-
${VS_DXC_COMPILER_PATH}
88-
"\"${CMAKE_CURRENT_BINARY_DIR}/dxcompiler.dll\""
81+
"${DXC_COMPILER_PATH}"
82+
"${CMAKE_CURRENT_BINARY_DIR}/dxcompiler.dll"
8983
COMMAND ${CMAKE_COMMAND} -E copy_if_different
90-
${VS_DXIL_SIGNER_PATH}
91-
"\"${CMAKE_CURRENT_BINARY_DIR}/dxil.dll\"")
84+
"${DXIL_SIGNER_PATH}"
85+
"${CMAKE_CURRENT_BINARY_DIR}/dxil.dll")
9286
set(DLLS "${CMAKE_CURRENT_BINARY_DIR}/dxcompiler.dll" "${CMAKE_CURRENT_BINARY_DIR}/dxil.dll")
9387

9488
# Add the dlls to the target project as source files

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ if(WIN32)
124124
if (NOT WINDOWS_KITS_ROOT)
125125
message(WARNING "Unable to read Windows SDK root directory from registry")
126126
elseif(NOT EXISTS "${WINDOWS_KITS_ROOT}")
127-
message(WARNING "Windows SDK root directory does not exist: " ${WINDOWS_KITS_ROOT})
127+
message(WARNING "Windows SDK root directory does not exist: ${WINDOWS_KITS_ROOT}")
128128
unset(WINDOWS_KITS_ROOT)
129129
endif()
130130

@@ -148,7 +148,7 @@ if(WIN32)
148148
if (EXISTS "${WINDOWS_SDK_BIN_DIR}")
149149
set(WINDOWS_SDK_BIN_DIR "${WINDOWS_SDK_BIN_DIR}" CACHE INTERNAL "Windows SDK bin directory")
150150
else()
151-
message(WARNING "Windows SDK bin directory does not exist: " ${WINDOWS_SDK_BIN_DIR})
151+
message(WARNING "Windows SDK bin directory does not exist: ${WINDOWS_SDK_BIN_DIR}")
152152
unset(WINDOWS_SDK_BIN_DIR)
153153
endif()
154154
endif()

Graphics/GraphicsEngineD3DBase/CMakeLists.txt

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,52 @@ endif()
7373

7474
# Set paths to D3Dcompiler_47.dll, dxcompiler.dll, and dxil.dll
7575
if(MSVC)
76-
if (${CMAKE_SIZEOF_VOID_P} EQUAL 8)
77-
set(ARCH_SUFFIX "x64")
78-
else()
79-
set(ARCH_SUFFIX "x86")
80-
endif()
81-
82-
# Note that CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION is stated to be defined when targeting Windows 10
83-
# and above, however it is also defined when targeting 8.1 and Visual Studio 2019 (but not VS2017)
8476
if("${WINDOWS_SDK_VERSION}" VERSION_GREATER_EQUAL "10.0" AND WINDOWS_SDK_BIN_DIR)
85-
set(VS_D3D_COMPILER_PATH "\"${WINDOWS_SDK_BIN_DIR}\\D3Dcompiler_47.dll\"" CACHE INTERNAL "D3Dcompiler_47.dll path")
77+
set(D3D_COMPILER_PATH "${WINDOWS_SDK_BIN_DIR}/D3Dcompiler_47.dll")
8678

8779
# DXC is only present in Windows SDK starting with version 10.0.17763.0
8880
if("${WINDOWS_SDK_VERSION}" VERSION_GREATER_EQUAL "10.0.17763.0")
89-
set(VS_DXC_COMPILER_PATH "\"${WINDOWS_SDK_BIN_DIR}\\dxcompiler.dll\"" CACHE INTERNAL "dxcompiler.dll path")
90-
set(VS_DXIL_SIGNER_PATH "\"${WINDOWS_SDK_BIN_DIR}\\dxil.dll\"" CACHE INTERNAL "dxil.dll path")
81+
set(DXC_COMPILER_PATH "${WINDOWS_SDK_BIN_DIR}/dxcompiler.dll")
82+
set(DXIL_SIGNER_PATH "${WINDOWS_SDK_BIN_DIR}/dxil.dll")
9183
endif()
9284
elseif("${WINDOWS_SDK_VERSION}" VERSION_EQUAL "8.1")
9385
# D3Dcompiler_47.dll from Win8.1 SDK is ancient (from 2013) and fails to
9486
# compile a number of test shaders. Use the compiler from Visual Studio
9587
# executable path instead
96-
set(VS_D3D_COMPILER_PATH "\"$(VC_ExecutablePath_x64_${ARCH_SUFFIX})\\D3Dcompiler_47.dll\"" CACHE INTERNAL "D3Dcompiler_47.dll path")
88+
if(CMAKE_AR AND IS_ABSOLUTE "${CMAKE_AR}")
89+
get_filename_component(CMAKE_AR_DIR "${CMAKE_AR}" DIRECTORY)
90+
set(D3D_COMPILER_PATH "${CMAKE_AR_DIR}/D3Dcompiler_47.dll")
91+
endif()
92+
endif()
93+
94+
if(D3D_COMPILER_PATH)
95+
if(EXISTS "${D3D_COMPILER_PATH}")
96+
message(STATUS "Found D3Dcompiler_47.dll: ${D3D_COMPILER_PATH}")
97+
set(D3D_COMPILER_PATH "${D3D_COMPILER_PATH}" CACHE INTERNAL "D3Dcompiler_47.dll path")
98+
else()
99+
message(WARNING "Cannot find D3Dcompiler_47.dll. File does not exist: ${D3D_COMPILER_PATH}")
100+
unset(D3D_COMPILER_PATH CACHE)
101+
endif()
102+
endif()
103+
104+
if (DXC_COMPILER_PATH)
105+
if (EXISTS "${DXC_COMPILER_PATH}")
106+
message(STATUS "Found dxcompiler.dll: ${DXC_COMPILER_PATH}")
107+
set(DXC_COMPILER_PATH "${DXC_COMPILER_PATH}" CACHE INTERNAL "dxcompiler.dll path")
108+
else()
109+
message(WARNING "Cannot find dxcompiler.dll. File does not exist: ${DXC_COMPILER_PATH}")
110+
unset(DXC_COMPILER_PATH CACHE)
111+
endif()
112+
endif()
113+
114+
if (DXIL_SIGNER_PATH)
115+
if (EXISTS "${DXIL_SIGNER_PATH}")
116+
message(STATUS "Found dxil.dll: ${DXIL_SIGNER_PATH}")
117+
set(DXIL_SIGNER_PATH "${DXIL_SIGNER_PATH}" CACHE INTERNAL "dxil.dll path")
118+
else()
119+
message(WARNING "Cannot find dxil.dll. File does not exist: ${DXIL_SIGNER_PATH}")
120+
unset(DXIL_SIGNER_PATH CACHE)
121+
endif()
97122
endif()
98123
endif()
99124

0 commit comments

Comments
 (0)