How to rebuild on resource file change in cmake?

試著忘記壹切 提交于 2020-01-17 05:33:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!