11if (PLATFORM_WIN32)
22
3- # Copies required dlls to the target's output directory
4- #
5- # The following dlls are copied:
6- # - Engine dlls (GraphicsEngine*.dll)
7- # - Archiver dll (Archiver*.dll)
8- # - D3Dcompiler_47.dll
9- # - Optional DXC dlls (dxcompiler.dll, dxil.dll, spv_dxcompiler.dll)
10- #
11- # Arguments:
12- # TARGET_NAME - name of the target to copy dlls for
13- # DXC_REQUIRED - Indicates that the target requires DXC compiler dlls
14- # (dxcompiler.dll, dxil.dll and spv_dxcompiler.dll)
15- #
16- # Example:
17- # copy_required_dlls(MyTarget DXC_REQUIRED YES)
18- #
19- function (copy_required_dlls TARGET_NAME)
20- set (options )
21- set (oneValueArgs DXC_REQUIRED)
22- set (multiValueArgs)
23- cmake_parse_arguments (PARSE_ARGV 1 arg "${options} " "${oneValueArgs} " "${multiValueArgs} " )
24-
3+ # Copies engine dlls to the target's output directory
4+ function (copy_engine_dlls TARGET_NAME)
5+ set (ENGINE_DLLS)
256 if (D3D11_SUPPORTED)
267 list (APPEND ENGINE_DLLS Diligent-GraphicsEngineD3D11-shared)
278 endif ()
@@ -47,18 +28,36 @@ if(PLATFORM_WIN32)
4728 foreach (DLL ${ENGINE_DLLS} )
4829 add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
4930 COMMAND ${CMAKE_COMMAND} -E copy_if_different
50- "\" $<TARGET_FILE:${DLL} >\" "
51- "\" $<TARGET_FILE_DIR:${TARGET_NAME} >\" " )
31+ "$<TARGET_FILE:${DLL} >"
32+ "$<TARGET_FILE_DIR:${TARGET_NAME} >" )
5233 endforeach (DLL)
34+ endfunction ()
5335
54- # Copy D3Dcompiler_47.dll, dxcompiler.dll, and dxil.dll
55- if ((D3D11_SUPPORTED OR D3D12_SUPPORTED) AND D3D_COMPILER_PATH)
36+ # Copies shader compiler dlls to the target's output directory
37+ #
38+ # Arguments:
39+ # TARGET_NAME - Name of the target to copy dlls for
40+ # D3D_COMPILER - Indicates that D3Dcompiler_47.dll is required
41+ # DXCOMPILER - Indicates that dxcompiler.dll and dxil.dll are required
42+ # DXCOMPILER_FOR_SPIRV - Indicates that spv_dxcompiler.dll is required
43+ #
44+ # Example:
45+ # copy_shader_compiler_dlls(MyTarget D3D_COMPILER YES DXCOMPILER YES)
46+ function (copy_shader_compiler_dlls TARGET_NAME)
47+ set (options )
48+ set (oneValueArgs D3D_COMPILER DXCOMPILER DXCOMPILER_FOR_SPIRV)
49+ set (multiValueArgs)
50+ cmake_parse_arguments (PARSE_ARGV 1 arg "${options} " "${oneValueArgs} " "${multiValueArgs} " )
51+
52+ set (SHADER_COMPILER_DLLS)
53+
54+ # D3Dcompiler_47.dll
55+ if (arg_D3D_COMPILER AND D3D_COMPILER_PATH)
5656 list (APPEND SHADER_COMPILER_DLLS "${D3D_COMPILER_PATH} " )
5757 endif ()
5858
59- # Dawn uses DXC, so we need to copy the DXC dlls even if DXC_REQUIRED is not set
60- # to get consistent shader compilation results
61- if (((arg_DXC_REQUIRED AND D3D12_SUPPORTED) OR WEBGPU_SUPPORTED) AND DXC_COMPILER_PATH AND DXIL_SIGNER_PATH)
59+ # dxcompiler.dll and dxil.dll
60+ if (arg_DXCOMPILER AND DXC_COMPILER_PATH AND DXIL_SIGNER_PATH)
6261 # For the compiler to sign the bytecode, you have to have a copy of dxil.dll in
6362 # the same folder as the dxcompiler.dll at runtime.
6463
@@ -69,22 +68,73 @@ if(PLATFORM_WIN32)
6968 foreach (DLL ${SHADER_COMPILER_DLLS} )
7069 add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
7170 COMMAND ${CMAKE_COMMAND} -E copy_if_different
72- ${DLL}
73- "\" $<TARGET_FILE_DIR:${TARGET_NAME} >\" " )
71+ " ${DLL} "
72+ "$<TARGET_FILE_DIR:${TARGET_NAME} >" )
7473 endforeach (DLL)
7574
76- if (D3D12_SUPPORTED AND EXISTS "${DILIGENT_PIX_EVENT_RUNTIME_DLL_PATH} " )
75+ # spv_dxcompiler.dll
76+ if (arg_DXCOMPILER_FOR_SPIRV AND EXISTS "${DILIGENT_DXCOMPILER_FOR_SPIRV_PATH} " )
7777 add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
7878 COMMAND ${CMAKE_COMMAND} -E copy_if_different
79- "${DILIGENT_PIX_EVENT_RUNTIME_DLL_PATH } "
80- "\" $<TARGET_FILE_DIR:${TARGET_NAME} >\" " )
79+ "${DILIGENT_DXCOMPILER_FOR_SPIRV_PATH } "
80+ "$<TARGET_FILE_DIR:${TARGET_NAME} >/spv_dxcompiler.dll " )
8181 endif ()
82+ endfunction ()
8283
83- if (arg_DXC_REQUIRED AND VULKAN_SUPPORTED AND EXISTS "${DILIGENT_DXCOMPILER_FOR_SPIRV_PATH} " )
84+ # Copies required dlls to the target's output directory
85+ #
86+ # The following dlls are copied:
87+ # - Engine dlls (GraphicsEngine*.dll)
88+ # - Archiver dll (Archiver*.dll)
89+ # - D3Dcompiler_47.dll
90+ # - Optional DXC dlls (dxcompiler.dll, dxil.dll, spv_dxcompiler.dll)
91+ #
92+ # Arguments:
93+ # TARGET_NAME - Name of the target to copy dlls for
94+ # DXC_REQUIRED - Indicates that the target requires DXC compiler dlls
95+ # (dxcompiler.dll, dxil.dll and spv_dxcompiler.dll)
96+ #
97+ # Example:
98+ # copy_required_dlls(MyTarget DXC_REQUIRED YES)
99+ #
100+ function (copy_required_dlls TARGET_NAME)
101+ set (options )
102+ set (oneValueArgs DXC_REQUIRED)
103+ set (multiValueArgs)
104+ cmake_parse_arguments (PARSE_ARGV 1 arg "${options} " "${oneValueArgs} " "${multiValueArgs} " )
105+
106+ copy_engine_dlls(${TARGET_NAME} )
107+
108+ # Copy D3Dcompiler_47.dll, dxcompiler.dll, and dxil.dll
109+ set (D3D_COMPILER_REQUIRED NO )
110+ set (DXCOMPILER_REQUIRED NO )
111+ set (DXCOMPILER_FOR_SPIRV_REQUIRED NO )
112+
113+ if (D3D11_SUPPORTED OR D3D12_SUPPORTED)
114+ set (D3D_COMPILER_REQUIRED YES )
115+ endif ()
116+
117+ # Dawn uses DXC, so we need to copy the DXC dlls even if DXC_REQUIRED is not set
118+ # to get consistent shader compilation results
119+ if ((arg_DXC_REQUIRED AND D3D12_SUPPORTED) OR WEBGPU_SUPPORTED)
120+ set (DXCOMPILER_REQUIRED YES )
121+ endif ()
122+
123+ if (arg_DXC_REQUIRED AND VULKAN_SUPPORTED)
124+ set (DXCOMPILER_FOR_SPIRV_REQUIRED YES )
125+ endif ()
126+
127+ copy_shader_compiler_dlls(${TARGET_NAME}
128+ D3D_COMPILER ${D3D_COMPILER_REQUIRED}
129+ DXCOMPILER ${DXCOMPILER_REQUIRED}
130+ DXCOMPILER_FOR_SPIRV ${DXCOMPILER_FOR_SPIRV_REQUIRED}
131+ )
132+
133+ if (D3D12_SUPPORTED AND EXISTS "${DILIGENT_PIX_EVENT_RUNTIME_DLL_PATH} " )
84134 add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
85135 COMMAND ${CMAKE_COMMAND} -E copy_if_different
86- "${DILIGENT_DXCOMPILER_FOR_SPIRV_PATH } "
87- "\" $<TARGET_FILE_DIR:${TARGET_NAME} >/spv_dxcompiler.dll \" " )
136+ "${DILIGENT_PIX_EVENT_RUNTIME_DLL_PATH } "
137+ "$<TARGET_FILE_DIR:${TARGET_NAME} >" )
88138 endif ()
89139 endfunction ()
90140
0 commit comments