CMake: Don't recompile shaders on every build;
Recompile them only when needed.
@@ -476,9 +476,6 @@ if(LOVR_ENABLE_GRAPHICS)
target_sources(lovr PRIVATE src/core/gpu_webgpu.c)
endif()
- add_custom_target(compile_shaders ALL)
- add_dependencies(lovr compile_shaders)
-
function(compile_shaders)
if(LOVR_USE_GLSLANG AND ENABLE_GLSLANG_BINARIES AND NOT ANDROID)
set(GLSLANG_VALIDATOR $<TARGET_FILE:glslangValidator>)
@@ -494,7 +491,9 @@ if(LOVR_ENABLE_GRAPHICS)
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
+ add_custom_command(
+ OUTPUT ${shader_file}.h
+ DEPENDS ${shader_file}
COMMAND
${GLSLANG_VALIDATOR}
--quiet
@@ -503,6 +502,7 @@ if(LOVR_ENABLE_GRAPHICS)
-o ${shader_file}.h
${shader_file}
)
+ target_sources(lovr PRIVATE ${shader_file}.h)
endforeach()
endfunction()
