CMake can compile shaders;

This commit is contained in:
bjorn 2022-06-07 21:19:42 -07:00
parent ef19a334a9
commit 711a7df43b
2 changed files with 25 additions and 1 deletions

View File

@ -460,6 +460,30 @@ if(LOVR_ENABLE_GRAPHICS)
target_compile_definitions(lovr PRIVATE LOVR_WGPU)
target_sources(lovr PRIVATE src/core/gpu_webgpu.c)
endif()
add_custom_target(compile_shaders ALL)
add_dependencies(lovr compile_shaders)
function(compile_shaders)
file(GLOB shader_files "etc/shaders/*.${ARGV0}")
foreach(shader_file ${shader_files})
string(REGEX MATCH "([^\/]+)\.${ARGV0}" shader ${shader_file})
string(REPLACE ".${ARGV0}" "" shader ${shader})
add_custom_command(TARGET compile_shaders POST_BUILD
COMMAND
glslangValidator
--quiet
--target-env vulkan1.1
--vn lovr_shader_${shader}_${ARGV0}
-o ${shader_file}.h
${shader_file}
)
endforeach()
endfunction()
compile_shaders("vert")
compile_shaders("frag")
compile_shaders("comp")
else()
target_compile_definitions(lovr PRIVATE LOVR_DISABLE_GRAPHICS)
endif()

View File

@ -452,7 +452,7 @@ comp = 'etc/shaders/*.comp'
function compileShaders(stage)
pattern = 'etc/shaders/*.' .. stage
tup.foreach_rule(pattern, 'glslangValidator --target-env vulkan1.1 --vn lovr_shader_%B_' .. stage .. ' -o %o %f', '%f.h')
tup.foreach_rule(pattern, 'glslangValidator --quiet --target-env vulkan1.1 --vn lovr_shader_%B_' .. stage .. ' -o %o %f', '%f.h')
end
compileShaders('vert')