From 465297442ac49cacf840c43df49e73a5cd4a861d Mon Sep 17 00:00:00 2001 From: redstrate <54911369+redstrate@users.noreply.github.com> Date: Tue, 11 May 2021 16:32:59 -0400 Subject: [PATCH] Copy shader files properly on SDL2 apps --- platforms/sdl/CMakeLists.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/platforms/sdl/CMakeLists.txt b/platforms/sdl/CMakeLists.txt index 5d2810c..0b4d79c 100644 --- a/platforms/sdl/CMakeLists.txt +++ b/platforms/sdl/CMakeLists.txt @@ -15,7 +15,19 @@ function(add_platform_commands target) add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/data $/data) endif() - add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $/shaders) + # we HAVE to create this dummy target to convince CMake to properly copy over shader files. + # before you ask, we have used POST_BUILD before but that only runs if the TARGET specified is built. + # when you change a shader source file on disk, BuildShaders is triggered but that doesn't retrigger your actual + # app target to be rebuilt, so the shaders are never copied correctly. With this (dumb) system, we ensure they + # always are. WHY CMAKE WHY + set(DUMMY_NAME ${target}-CopyShaders) - add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/shaders $/shaders) + add_custom_target(${DUMMY_NAME} ALL DEPENDS ${CMAKE_BINARY_DIR}/dummy) + + add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/dummy + COMMAND ${CMAKE_COMMAND} -E make_directory $/shaders + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/shaders $/shaders + ) + + add_dependencies(${target} ${DUMMY_NAME}) endfunction()