Skip to content

Commit

Permalink
Refactor command-line tools to use shared header (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn authored Sep 17, 2024
1 parent 1deadd3 commit 73aa2f3
Show file tree
Hide file tree
Showing 67 changed files with 1,133 additions and 1,604 deletions.
41 changes: 21 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ elseif((BUILD_XBOX_EXTS_XBOXONE OR BUILD_XBOX_EXTS_SCARLETT) AND WIN32)
Auxiliary/DirectXTexXboxTile.cpp)
endif()


if(BUILD_DX11 AND WIN32 AND (NOT (XBOX_CONSOLE_TARGET STREQUAL "durango")))
set(SHADER_SOURCES
DirectXTex/Shaders/BC6HEncode.hlsl
Expand All @@ -160,7 +159,7 @@ if(BUILD_DX12)
list(APPEND LIBRARY_SOURCES DirectXTex/DirectXTexD3D12.cpp)

if(NOT (DEFINED XBOX_CONSOLE_TARGET))
list(APPEND LIBRARY_SOURCES DirectXTex/d3dx12.h)
list(APPEND LIBRARY_SOURCES Common/d3dx12.h)
endif()
endif()

Expand Down Expand Up @@ -404,7 +403,8 @@ if(BUILD_TOOLS AND WIN32)
add_executable(texassemble
Texassemble/texassemble.cpp
Texassemble/texassemble.rc
Texassemble/settings.manifest
Common/CmdLineHelpers.h
Common/settings.manifest
Texassemble/AnimatedGif.cpp)
target_compile_features(texassemble PRIVATE cxx_std_17)
target_link_libraries(texassemble PRIVATE ${PROJECT_NAME} ole32.lib version.lib)
Expand All @@ -416,7 +416,8 @@ if(BUILD_TOOLS AND BUILD_DX11 AND WIN32)
add_executable(texconv
Texconv/texconv.cpp
Texconv/texconv.rc
Texconv/settings.manifest
Common/CmdLineHelpers.h
Common/settings.manifest
Texconv/ExtendedBMP.cpp
Texconv/PortablePixMap.cpp)
target_compile_features(texconv PRIVATE cxx_std_17)
Expand All @@ -429,13 +430,18 @@ if(BUILD_TOOLS AND WIN32)
add_executable(texdiag
Texdiag/texdiag.cpp
Texdiag/texdiag.rc
Texdiag/settings.manifest)
Common/CmdLineHelpers.h
Common/settings.manifest)
target_compile_features(texdiag PRIVATE cxx_std_17)
target_link_libraries(texdiag PRIVATE ${PROJECT_NAME} ole32.lib version.lib)
source_group(texdiag REGULAR_EXPRESSION Texdiag/*.*)
list(APPEND TOOL_EXES texdiag)
endif()

foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_include_directories(${t} PRIVATE Common)
endforeach()

if(BUILD_TOOLS AND WIN32)
if(ENABLE_OPENEXR_SUPPORT)
foreach(t IN LISTS TOOL_EXES)
Expand Down Expand Up @@ -477,32 +483,22 @@ endif()
if(BUILD_SAMPLE AND BUILD_DX11 AND WIN32)
list(APPEND TOOL_EXES ddsview)

if(NOT COMPILED_DDSVIEW_SHADERS)
if(USE_PREBUILT_SHADERS)
message(FATAL_ERROR "ERROR: Using prebuilt shaders requires the COMPILED_DDSVIEW_SHADERS variable is set")
endif()
set(COMPILED_DDSVIEW_SHADERS ${CMAKE_CURRENT_BINARY_DIR}/Shaders/Compiled)
file(MAKE_DIRECTORY ${COMPILED_DDSVIEW_SHADERS})
else()
file(TO_CMAKE_PATH ${COMPILED_DDSVIEW_SHADERS} COMPILED_DDSVIEW_SHADERS)
endif()

add_executable(ddsview WIN32
DDSView/ddsview.cpp
DDSView/ddsview.rc
${COMPILED_DDSVIEW_SHADERS}/ddsview_ps1D.inc)
${COMPILED_SHADERS}/ddsview_ps1D.inc)
target_link_libraries(ddsview PRIVATE ${PROJECT_NAME} d3d11.lib ole32.lib)
source_group(ddsview REGULAR_EXPRESSION DDSView/*.*)

target_include_directories(ddsview PRIVATE ${COMPILED_DDSVIEW_SHADERS})
target_include_directories(ddsview PRIVATE ${COMPILED_SHADERS})

if(NOT USE_PREBUILT_SHADERS)
add_custom_command(
OUTPUT "${COMPILED_DDSVIEW_SHADERS}/ddsview_ps1D.inc"
OUTPUT "${COMPILED_SHADERS}/ddsview_ps1D.inc"
MAIN_DEPENDENCY "${PROJECT_SOURCE_DIR}/DDSView/hlsl.cmd"
DEPENDS "${PROJECT_SOURCE_DIR}/DDSView/ddsview.fx"
DEPENDS "DDSView/ddsview.hlsl"
COMMENT "Generating HLSL shaders for DDSView..."
COMMAND COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_DDSVIEW_SHADERS}" hlsl.cmd > "${COMPILED_DDSVIEW_SHADERS}/hlsl.log"
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" $<$<BOOL:${DIRECTX_FXC_TOOL}>:LegacyShaderCompiler=${DIRECTX_FXC_TOOL}> hlsl.cmd > "${COMPILED_SHADERS}/hlsl_ddsview.log"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/DDSView"
USES_TERMINAL)
endif()
Expand All @@ -514,6 +510,10 @@ if(directxmath_FOUND)
endforeach()
endif()

if(TOOL_EXES)
message(STATUS "Building tools: ${TOOL_EXES}")
endif()

if(MSVC)
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Wall /GR-)
Expand Down Expand Up @@ -574,6 +574,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
endif()

if(ENABLE_CODE_ANALYSIS)
message(STATUS "Building with Code Analysis (PREFIX)")
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /analyze /WX)
endforeach()
Expand Down
3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@
{ "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug) with DX12", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] },
{ "name": "x64-Release-ICX" , "description": "Intel oneAPI Compiler (Release) with DX12", "inherits": [ "base", "x64", "Release", "IntelLLVM" ] },

{ "name": "x64-Fuzzing" , "description": "MSVC for x64 (Release) with ASan", "inherits": [ "base", "x64", "Release", "MSVC", "Fuzzing" ] }
{ "name": "x64-Fuzzing" , "description": "MSVC for x64 (Release) with ASan", "inherits": [ "base", "x64", "Release", "MSVC", "Fuzzing" ] },
{ "name": "x64-Analyze" , "description": "MSVC for x64 (Debug) with DX12 using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC" ], "cacheVariables": { "ENABLE_CODE_ANALYSIS": true } }
],
"testPresets": [
{ "name": "x64-Debug" , "configurePreset": "x64-Debug" },
Expand Down
Loading

0 comments on commit 73aa2f3

Please sign in to comment.