如何在cmake中通过add_custom_command复制时更改文件权限 [英] How to change file permission when copying by add_custom_command in cmake

查看:1971
本文介绍了如何在cmake中通过add_custom_command复制时更改文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用像

file(GLOB IMAGES ${PROJECT_SOURCE_DIR}/Image/*)
file(COPY ${IMAGES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Image
     FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ)

但是缺点是这个命令只有在重新配置cmake时被调用。

but the downside is this command will only be invoked when cmake is reconfigured. I figured out a way to copy them whenever a build is triggered like below

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                  COMMAND ${CMAKE_COMMAND} -E copy_directory
                  "${PROJECT_SOURCE_DIR}/Image"
                  "${CMAKE_CURRENT_BINARY_DIR}/Image")

这适合我的需要,我不能找出一种方法来改变文件权限,像第一种方法。我需要交替文件权限,以确保它是正确的,否则一些图片可能被错误地分类为可执行文件,当运行以下命令

this suits my needs by I am not able to figure out a way to alter the file permission like the first method. I need to alternate the file permission to make sure it is right otherwise some images might be wrongly classified as executable when running the below command

find . -executable -type f

从add_custom_command复制时是否可以更改文件权限?

Is it possible to alter the file permission when copying from add_custom_command?

推荐答案

CMake开发人员实际上回复了一个有效的答案。关键是创建一个临时的cmake脚本文件(COPY)并调用它。

CMake developers actually responds back with an answer that works. The key is creating a temporary cmake script with file(COPY) in it and invoke it.

file(GLOB IMAGES ${PROJECT_SOURCE_DIR}/Image/*)

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/foo.cmake" "file(COPY ${IMAGES} 
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Image 
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ)")

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND 
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/foo.cmake)

这篇关于如何在cmake中通过add_custom_command复制时更改文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆