简体   繁体   English

CMake:如何在安装期间创建具有某些访问权限的目录?

[英]CMake : how to create a directory during installation with certain access rights?

I have an application that is installed in /opt (this is the way it is done here). 我有一个安装在/ opt中的应用程序(这是在这里完成的方式)。 It is fine to have all the files and folders belonging to root apart from the logs directory that must be writable by anyone. 最好将所有文件和文件夹都属于root,而不是任何人都可以写的logs目录。

To create the logs directory I do 创建日志目录

INSTALL(CODE "FILE(MAKE_DIRECTORY \${ENV}\${CMAKE_INSTALL_PREFIX}/logs)")

How can I then chmod the directory ? 然后我如何chmod目录?

Instead of using the CODE variant of the INSTALL command, consider using the DIRECTORY variant instead. 与其使用INSTALL命令的CODE变体, INSTALL考虑使用DIRECTORY变体。 This one lets you specify the file system permissions, ie: 这使您可以指定文件系统权限,即:

install (DIRECTORY "Logs" DESTINATION "." DIRECTORY_PERMISSIONS 
    OWNER_WRITE OWNER_READ OWNER_EXECUTE
    GROUP_WRITE GROUP_READ GROUP_EXECUTE
    WORLD_WRITE WORLD_READ WORLD_EXECUTE)

For the install command to succeed, an empty directory Logs must exist in the source folder. 为使install命令成功,源文件夹中必须存在一个空目录Logs

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

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