Skip to content

Commit 2895334

Browse files
authored
Update CMake to specify FXC.EXE to use (#470)
1 parent fb0a22e commit 2895334

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ elseif(WINDOWS_STORE)
6161
endif()
6262

6363
include(GNUInstallDirs)
64+
include(build/CompilerAndLinker.cmake)
6465

6566
#--- Library
6667
set(LIBRARY_HEADERS
@@ -224,12 +225,19 @@ else()
224225
endif()
225226

226227
if(NOT USE_PREBUILT_SHADERS)
228+
if(BUILD_XBOXONE_SHADERS)
229+
else()
230+
find_program(DIRECTX_FXC_TOOL FXC.EXE
231+
HINTS "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_SYSTEM_VERSION}/${DIRECTX_HOST_ARCH}"
232+
"C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/${DIRECTX_HOST_ARCH}")
233+
message(STATUS "Using LegacyShaderCompiler found in ${DIRECTX_FXC_TOOL}")
234+
endif()
227235
add_custom_command(
228236
OUTPUT "${COMPILED_SHADERS}/SpriteEffect_SpriteVertexShader.inc"
229237
MAIN_DEPENDENCY "${PROJECT_SOURCE_DIR}/Src/Shaders/CompileShaders.cmd"
230238
DEPENDS ${SHADER_SOURCES}
231239
COMMENT "Generating HLSL shaders..."
232-
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" CompileShaders.cmd ARGS ${ShaderOpts} > "${COMPILED_SHADERS}/compileshaders.log"
240+
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" $<$<BOOL:${DIRECTX_FXC_TOOL}>:LegacyShaderCompiler=${DIRECTX_FXC_TOOL}> CompileShaders.cmd ARGS ${ShaderOpts} > "${COMPILED_SHADERS}/compileshaders.log"
233241
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/Src/Shaders"
234242
USES_TERMINAL)
235243
endif()
@@ -387,8 +395,6 @@ if(MSVC)
387395
endif()
388396
endif()
389397

390-
include(build/CompilerAndLinker.cmake)
391-
392398
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
393399
target_compile_definitions(${t} PRIVATE ${COMPILER_DEFINES})
394400
target_compile_options(${t} PRIVATE ${COMPILER_SWITCHES})

Src/Shaders/CompileShaders.cmd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ goto continue
3232

3333
:continuepc
3434

35+
if defined LegacyShaderCompiler goto fxcviaenv
3536
set PCFXC="%WindowsSdkVerBinPath%%FXCARCH%\fxc.exe"
3637
if exist %PCFXC% goto continue
3738
set PCFXC="%WindowsSdkBinPath%%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
@@ -40,6 +41,12 @@ set PCFXC="%WindowsSdkDir%bin\%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
4041
if exist %PCFXC% goto continue
4142

4243
set PCFXC=fxc.exe
44+
goto continue
45+
46+
:fxcviaenv
47+
set PCFXC="%LegacyShaderCompiler%"
48+
if not exist %PCFXC% goto needfxc
49+
goto continue
4350

4451
:continue
4552
if not defined CompileShadersOutput set CompileShadersOutput=Compiled
@@ -329,6 +336,11 @@ echo %fxc%
329336
%fxc% || set error=1
330337
exit /b
331338

339+
:needfxc
340+
echo ERROR: CompileShaders requires FXC.EXE
341+
exit /b 1
342+
332343
:needxdk
333344
echo ERROR: CompileShaders xbox requires the Microsoft Xbox One XDK
334345
echo (try re-running from the XDK Command Prompt)
346+
exit /b 1

build/CompilerAndLinker.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Aa][Rr][Mm]64EC$")
3232
set(DIRECTX_ARCH arm64ec)
3333
endif()
3434

35+
#--- Determines host architecture
36+
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "[Aa][Rr][Mm]64|aarch64|arm64")
37+
set(DIRECTX_HOST_ARCH arm64)
38+
else()
39+
set(DIRECTX_HOST_ARCH x64)
40+
endif()
41+
3542
#--- Build with Unicode Win32 APIs per "UTF-8 Everywhere"
3643
if(WIN32)
3744
list(APPEND COMPILER_DEFINES _UNICODE UNICODE)

build/DirectXTK-GitHub-Dev17.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pr:
2121
paths:
2222
include:
2323
- build/DirectXTK-GitHub-Dev17.yml
24+
- Src/Shaders/CompileShaders.cmd
2425

2526
resources:
2627
repositories:

build/DirectXTK-GitHub-GDK-Dev17.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pr:
2525
- build/*.in
2626
- build/*.cmake
2727
- build/SetupBWOI.*
28+
- Src/Shaders/CompileShaders.cmd
2829

2930
resources:
3031
repositories:

build/DirectXTK-GitHub.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pr:
2121
paths:
2222
include:
2323
- build/DirectXTK-GitHub.yml
24+
- Src/Shaders/CompileShaders.cmd
2425

2526
resources:
2627
repositories:

0 commit comments

Comments
 (0)