简体   繁体   中英

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). It is fine to have all the files and folders belonging to root apart from the logs directory that must be writable by anyone.

To create the logs directory I do

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

How can I then chmod the directory ?

Instead of using the CODE variant of the INSTALL command, consider using the DIRECTORY variant instead. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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