简体   繁体   English

clion在每个版本上运行cmake

[英]clion run cmake on each build

I am not sure if its possible to do this with clion, I was testing out the program and enjoy using it to write c code because the ctags and etags support is really nice. 我不确定是否可以用clion做到这一点,我正在测试该程序并喜欢用它编写c代码,因为ctags和etags支持确实很好。

I am copying some files over from the cmake source tree to the bin location on each build. 我将一些文件从cmake源代码树复制到每个版本的bin位置。 While using clion if I update some of the files that I am copying the results aren't updated within clion. 在使用clion时,如果我更新要复制的某些文件,则结果不会在clion中更新。

If I instead go back to the terminal and just run the typical cmake steps 如果我改为返回终端,然后运行典型的cmake步骤

cmake ../ && make && bin/./program

that copies the updated files and I am able to see my results. 复制更新的文件,我就能看到我的结果。

This is the CMake command that I am using in my build. 这是我在构建中使用的CMake命令。

FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin/resources/)

I might be able to restructure the cmake command to make it copy every time or it might just be a clion issue. 我也许能够重组cmake命令以使其每次都复制,或者这可能只是一个问题。 I am unsure and would like to be able to take care of this all from within clion, instead of going back to the terminal to run the cmake command for updates to take effect. 我不确定,并且希望能够从clion内解决所有问题,而不是回到终端以运行cmake命令使更新生效。

If you want CMake to make some action whenever some file is changed, you should create a rule using add_custom_command and pass file via DEPENDS argument. 如果您希望CMake在更改某些文件时采取任何措施,则应使用add_custom_command创建一条规则,并通过DEPENDS参数传递文件。 Note, that only file-level dependencies are supported by CMake, for make dependency on directory you need to list all files in it. 请注意,CMake仅支持文件级依赖关系,要使依赖于目录,您需要列出其中的所有文件。

# Collect list of files within directory.
FILES(GLOB files_list RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/resources/
    "${CMAKE_CURRENT_SOURCE_DIR}/resources/*") 
# This will contain full paths to files in binary directory. 
set(binary_files_list)
foreach(file ${files_list})
    set(source_file ${CMAKE_CURRENT_SOURCE_DIR}/resources/${file})
    set(binary_file ${CMAKE_CURRENT_BINARY_DIR}/bin/resources/${file})
    add_custom_command(OUTPUT ${binary_file}
        COMMAND cmake -E ${source_file} ${binary_file}
        DEPENDS ${source_file})
    list(APPEND binary_files_list ${binary_file})
endforeach()
add_custom_target(resources DEPENDS ${binary_files_list})

Note, that in case of adding/removing files you should to run cmake explicitely. 请注意,在添加/删除文件的情况下,应显式运行cmake That's why hardcoded files list is preferred to GLOB ing. 这就是为什么硬编码文件列表优先于GLOB ing的原因。

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

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