user3487347
user3487347

Reputation: 77

How to make CMake build in CLion after changes in resource files

In a CLion project, I need some resources to be copied to the binary folder. They are GLSL shaders, so when I edit them, I want to be able to see the result. Unfortunately, CLion only rebuilds the project when there are changes to the source, so if I edit the GLSL files but leave the source files unchanged, CLion won't rebuild and thus the new files will not be copied to the binary directory. How do I fix this?

This is my code to move the files into the binary directory of the target OpenGL_Test:

add_custom_command(TARGET OpenGL_Test PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res 
    $<TARGET_FILE_DIR:OpenGL_Test>/res
)

Upvotes: 2

Views: 2207

Answers (1)

vinograd47
vinograd47

Reputation: 6420

You can use add_custom_target with ALL option, which will force CMake to copy the directory on every build:

add_custom_target(copy_shaders ALL
    COMMAND ${CMAKE_COMMAND} -E copy_directory 
        "${CMAKE_SOURCE_DIR}/res" "$<TARGET_FILE_DIR:OpenGL_Test>/res"
    COMMENT "Copy shaders to build tree"
    VERBATIM)

Upvotes: 4

Related Questions