问题
I have some shader files inside of a resource directory 'Shaders'. I want my app to copy this folder to the runtime directory everytime there are changes inside of one file in it before the build. How can I achieve this?
Right now I use this here:
add_custom_command(TARGET my_app PRE_BUILD
COMMAND rm ARGS -rf ${CMAKE_CURRENT_BINARY_DIR}/Shaders
COMMAND cp ARGS -a ${CMAKE_CURRENT_SOURCE_DIR}/my_app/Viewer/Shaders ${CMAKE_CURRENT_BINARY_DIR}
)
But this does only work when I change another file so a built is needed, not the shader files themselves. What can I do?
回答1:
What I know figured out to be working is this here:
file(GLOB shaders "${CMAKE_CURRENT_SOURCE_DIR}/my_app/Viewer/Shaders/*")
message(status Copy shaders)
foreach(shader ${shaders})
message(status "From ${shader}")
get_filename_component(outputFileName ${shader} NAME)
message(status "To ${CMAKE_CURRENT_BINARY_DIR}/Shaders/${outputFileName}")
configure_file(${shader} ${CMAKE_CURRENT_BINARY_DIR}/Shaders/${outputFileName} COPYONLY)
endforeach()
来源:https://stackoverflow.com/questions/37237469/how-to-rebuild-on-resource-file-change-in-cmake