33 lines
1.4 KiB
CMake
33 lines
1.4 KiB
CMake
function(add_shader TARGET SHADER)
|
|
find_package(Vulkan REQUIRED COMPONENTS dxc)
|
|
|
|
get_filename_component(vulkan-bin-dir ${Vulkan_GLSLC_EXECUTABLE} DIRECTORY)
|
|
|
|
find_program(slangc_exe NAMES "slangc")
|
|
if (NOT slangc_exe STREQUAL "slangc_exe-NOTFOUND")
|
|
set(slangc_exe_FOUND true)
|
|
endif()
|
|
|
|
get_filename_component(shader-ext ${SHADER} LAST_EXT)
|
|
|
|
set(current-shader-path ${CMAKE_CURRENT_SOURCE_DIR}/${SHADER})
|
|
set(current-output-path ${CMAKE_CURRENT_BINARY_DIR}/${SHADER}.slang-module)
|
|
set(current-copy-path ${CMAKE_CURRENT_BINARY_DIR}/${SHADER})
|
|
|
|
get_filename_component(current-output-dir ${current-output-path} DIRECTORY)
|
|
file(MAKE_DIRECTORY ${current-output-dir})
|
|
|
|
if (${shader-ext} STREQUAL ".slang")
|
|
add_custom_command(
|
|
OUTPUT ${current-output-path} ${current-copy-path}
|
|
COMMAND ${slangc_exe} ${current-shader-path} -o ${current-output-path}
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${current-shader-path} ${current-copy-path}
|
|
DEPENDS ${current-shader-path}
|
|
IMPLICIT_DEPENDS CXX ${current-shader-path}
|
|
VERBATIM)
|
|
endif ()
|
|
|
|
# Make sure our build depends on this output.
|
|
set_source_files_properties(${current-output-path} PROPERTIES GENERATED TRUE)
|
|
target_sources(${TARGET} PRIVATE ${current-output-path})
|
|
endfunction(add_shader) |