CMake: how to create a directory during installation with specific permissions?

I have an application that is installed in / opt (which is how it is done here). It’s good to have all the files and folders owned by root, except for the log directory, which should be writable by anyone.

To create a log directory, I do

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

How can I then chmod in a directory?

+5
source share
1 answer

Instead of using a variant of the CODEcommand INSTALL, use the variant instead DIRECTORY. This allows you to specify file system permissions, that is:

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 a successful command, INSTALLan empty directory must exist in the source folder Logs.

+4
source

All Articles