7

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 ?

Barth
  • 15,135
  • 20
  • 70
  • 105

1 Answers1

6

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, i.e.:

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.

sakra
  • 62,199
  • 16
  • 168
  • 151
  • 6
    to create the empty directory logs I do : FILE(MAKE_DIRECTORY logs) Thank you for your help – Barth Sep 14 '12 at 07:21
  • 1
    @Barth Alternatively, `DIRECTORY DESTINATION "Logs"` creates the directory `Logs` at installation time without that requirement of `Logs` to exist at all. – YSC May 20 '19 at 14:12
  • @YSC your variant should be in the accepted answer. The behavior for missing DIRECTORY argument is well [documented](https://cmake.org/cmake/help/latest/command/install.html#directory) in CMake: `If no input directory names are given the destination directory will be created but nothing will be installed into it.` – Alex Che Apr 14 '23 at 15:24