Skip to content

Commit

Permalink
More robust way of skipping shader builds
Browse files Browse the repository at this point in the history
  • Loading branch information
1runeberg committed Nov 2, 2024
1 parent 666fb68 commit 5aa18e7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/_src_android_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
-D ANDROID_NDK=$ANDROID_NDK_ROOT \
-D ANDROID_USE_LEGACY_TOOLCHAIN_FILE=NO \
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-D BUILD_SHADERS=OFF \
-D BUILD_AS_STATIC=OFF \
-D ENABLE_XRVK=${{ matrix.enable_xrvk }} \
-D BUILD_TESTS=OFF \
Expand All @@ -70,6 +71,7 @@ jobs:
-D ANDROID_NDK=$ANDROID_NDK_ROOT \
-D ANDROID_USE_LEGACY_TOOLCHAIN_FILE=NO \
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-D BUILD_SHADERS=OFF \
-D BUILD_AS_STATIC=ON \
-D ENABLE_XRVK=${{ matrix.enable_xrvk }} \
-D BUILD_TESTS=OFF \
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/_src_desktop_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
cmake -B ${{ steps.strings.outputs.build-output-dir }} \
-D CMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-D BUILD_SHADERS=OFF \
-D BUILD_AS_STATIC=${{ inputs.build-as-static }} \
-D ENABLE_XRVK=${{ matrix.enable_xrvk }} \
-S ${{ github.workspace }}
Expand All @@ -71,6 +72,7 @@ jobs:
cmake -B ${{ steps.strings.outputs.build-output-dir }} `
-D CMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} `
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }} `
-D BUILD_SHADERS=OFF `
-D BUILD_AS_STATIC=${{ inputs.build-as-static }} `
-D ENABLE_XRVK=${{ matrix.enable_xrvk }} `
-S ${{ github.workspace }}
Expand Down
49 changes: 26 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(XRLIB_CONFIG_OUT "${XRLIB_INCLUDE}/project_config.h")

# Set project wide options
option(BUILD_AS_STATIC "Build as static library" OFF)
option(BUILD_SHADERS "Build shaders in resource directory" ON)
option(ENABLE_XRVK "Compile xrvk - pbr render module" ON)
option(ENABLE_RENDERDOC "Enable renderdoc for render debugs" OFF)
option(ENABLE_VULKAN_DEBUG "Enable vulkan debugging" OFF)
Expand Down Expand Up @@ -136,29 +137,31 @@ file(GLOB_RECURSE XRVK_SHADERS
)

# Compile shaders
set(SHADER_OUTPUT_FILES)
foreach(SHADER ${XRVK_SHADERS})
# Get the filename with extension
get_filename_component(SHADER_NAME ${SHADER} NAME)

# Define the output .spv file path
set(OUTPUT_FILE "${XRVK_SHADERS_BIN}/${SHADER_NAME}.spv")

# Add custom command to run glslc for each shader file
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND glslc ${SHADER} -o ${OUTPUT_FILE}
COMMENT "Compiling ${SHADER} to ${OUTPUT_FILE}"
VERBATIM
DEPENDS ${SHADER} # Check if the shader file has changed
)

# Collect all output files
list(APPEND SHADER_OUTPUT_FILES ${OUTPUT_FILE})
endforeach()
if(BUILD_SHADERS)
set(SHADER_OUTPUT_FILES)
foreach(SHADER ${XRVK_SHADERS})
# Get the filename with extension
get_filename_component(SHADER_NAME ${SHADER} NAME)

# Define the output .spv file path
set(OUTPUT_FILE "${XRVK_SHADERS_BIN}/${SHADER_NAME}.spv")

# Add custom command to run glslc for each shader file
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND glslc ${SHADER} -o ${OUTPUT_FILE}
COMMENT "Compiling ${SHADER} to ${OUTPUT_FILE}"
VERBATIM
DEPENDS ${SHADER} # Check if the shader file has changed
)

# Collect all output files
list(APPEND SHADER_OUTPUT_FILES ${OUTPUT_FILE})
endforeach()

# Create a custom target that depends on all shader output files
add_custom_target(CompileShaders ALL DEPENDS ${SHADER_OUTPUT_FILES})
# Create a custom target that depends on all shader output files
add_custom_target(CompileShaders ALL DEPENDS ${SHADER_OUTPUT_FILES})
endif()

# Set openxr
set(OPENXR_ROOT "${THIRD_PARTY}/openxr")
Expand Down Expand Up @@ -376,7 +379,7 @@ add_custom_command(TARGET ${XRLIB} POST_BUILD


# Compile shaders only if we're not in an android build
if(NOT ANDROID AND NOT DEFINED ENV{GITHUB_WORKFLOW})
if(BUILD_SHADERS)
add_custom_command(TARGET ${XRLIB} POST_BUILD
COMMAND ${CMAKE_COMMAND} --build . --target CompileShaders
)
Expand Down

0 comments on commit 5aa18e7

Please sign in to comment.