简体   繁体   English

资源文件更改后如何在CLion中构建CMake

[英]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. 在CLion项目中,我需要将一些资源复制到二进制文件夹。 They are GLSL shaders, so when I edit them, I want to be able to see the result. 它们是GLSL着色器,因此当我编辑它们时,我希望能够看到结果。 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. 不幸的是,CLion仅在源代码发生更改时才重建项目,因此,如果我编辑GLSL文件但不更改源文件,则CLion不会重建,因此新文件将不会复制到二进制目录。 How do I fix this? 我该如何解决?

This is my code to move the files into the binary directory of the target OpenGL_Test: 这是我的代码,用于将文件移动到目标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
)

You can use add_custom_target with ALL option, which will force CMake to copy the directory on every build: 您可以使用带有ALL选项的add_custom_target ,这将强制CMake在每个版本上复制目录:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM