Skip to content

Commit

Permalink
Update CMake to specify FXC.EXE to use (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn authored Sep 3, 2024
1 parent fb0a22e commit 2895334
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ elseif(WINDOWS_STORE)
endif()

include(GNUInstallDirs)
include(build/CompilerAndLinker.cmake)

#--- Library
set(LIBRARY_HEADERS
Expand Down Expand Up @@ -224,12 +225,19 @@ else()
endif()

if(NOT USE_PREBUILT_SHADERS)
if(BUILD_XBOXONE_SHADERS)
else()
find_program(DIRECTX_FXC_TOOL FXC.EXE
HINTS "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_SYSTEM_VERSION}/${DIRECTX_HOST_ARCH}"
"C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/${DIRECTX_HOST_ARCH}")
message(STATUS "Using LegacyShaderCompiler found in ${DIRECTX_FXC_TOOL}")
endif()
add_custom_command(
OUTPUT "${COMPILED_SHADERS}/SpriteEffect_SpriteVertexShader.inc"
MAIN_DEPENDENCY "${PROJECT_SOURCE_DIR}/Src/Shaders/CompileShaders.cmd"
DEPENDS ${SHADER_SOURCES}
COMMENT "Generating HLSL shaders..."
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" CompileShaders.cmd ARGS ${ShaderOpts} > "${COMPILED_SHADERS}/compileshaders.log"
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" $<$<BOOL:${DIRECTX_FXC_TOOL}>:LegacyShaderCompiler=${DIRECTX_FXC_TOOL}> CompileShaders.cmd ARGS ${ShaderOpts} > "${COMPILED_SHADERS}/compileshaders.log"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/Src/Shaders"
USES_TERMINAL)
endif()
Expand Down Expand Up @@ -387,8 +395,6 @@ if(MSVC)
endif()
endif()

include(build/CompilerAndLinker.cmake)

foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_definitions(${t} PRIVATE ${COMPILER_DEFINES})
target_compile_options(${t} PRIVATE ${COMPILER_SWITCHES})
Expand Down
12 changes: 12 additions & 0 deletions Src/Shaders/CompileShaders.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ goto continue

:continuepc

if defined LegacyShaderCompiler goto fxcviaenv
set PCFXC="%WindowsSdkVerBinPath%%FXCARCH%\fxc.exe"
if exist %PCFXC% goto continue
set PCFXC="%WindowsSdkBinPath%%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
Expand All @@ -40,6 +41,12 @@ set PCFXC="%WindowsSdkDir%bin\%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
if exist %PCFXC% goto continue

set PCFXC=fxc.exe
goto continue

:fxcviaenv
set PCFXC="%LegacyShaderCompiler%"
if not exist %PCFXC% goto needfxc
goto continue

:continue
if not defined CompileShadersOutput set CompileShadersOutput=Compiled
Expand Down Expand Up @@ -329,6 +336,11 @@ echo %fxc%
%fxc% || set error=1
exit /b

:needfxc
echo ERROR: CompileShaders requires FXC.EXE
exit /b 1

:needxdk
echo ERROR: CompileShaders xbox requires the Microsoft Xbox One XDK
echo (try re-running from the XDK Command Prompt)
exit /b 1
7 changes: 7 additions & 0 deletions build/CompilerAndLinker.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Aa][Rr][Mm]64EC$")
set(DIRECTX_ARCH arm64ec)
endif()

#--- Determines host architecture
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "[Aa][Rr][Mm]64|aarch64|arm64")
set(DIRECTX_HOST_ARCH arm64)
else()
set(DIRECTX_HOST_ARCH x64)
endif()

#--- Build with Unicode Win32 APIs per "UTF-8 Everywhere"
if(WIN32)
list(APPEND COMPILER_DEFINES _UNICODE UNICODE)
Expand Down
1 change: 1 addition & 0 deletions build/DirectXTK-GitHub-Dev17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pr:
paths:
include:
- build/DirectXTK-GitHub-Dev17.yml
- Src/Shaders/CompileShaders.cmd

resources:
repositories:
Expand Down
1 change: 1 addition & 0 deletions build/DirectXTK-GitHub-GDK-Dev17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pr:
- build/*.in
- build/*.cmake
- build/SetupBWOI.*
- Src/Shaders/CompileShaders.cmd

resources:
repositories:
Expand Down
1 change: 1 addition & 0 deletions build/DirectXTK-GitHub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pr:
paths:
include:
- build/DirectXTK-GitHub.yml
- Src/Shaders/CompileShaders.cmd

resources:
repositories:
Expand Down

0 comments on commit 2895334

Please sign in to comment.