Cmake : How to change file permissions when installing?

Asked
Active3 hr before
Viewed126 times

6 Answers

change
90%

How do I do it? How to change the file permission, without changing the permissions of the source file?, Thanks, it works. But the page you linked talks about FILE_PERMISSIONS. I just noticed it is not for install(), but the file() command. Would it be possible to set permission using file() command as it seems to provide better control? – BЈовић Oct 16 '13 at 9:56 , By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. , Not familiar with it, just commented based on the first revision on the question. I would suggest saving the current umask, but let's see what other people suggest. – fedorqui 'SO stop harming' Oct 16 '13 at 9:49

There is no FILE_PERMISSIONS argument in install(FILES ...). Use PERMISSIONS instead:

install(
   FILES common.sh PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ DESTINATION / rootfs / usr / bin
)
88%

Default permissions for directories created implicitly during installation of files by install() and file(INSTALL).,If make install is invoked and directories are implicitly created they get permissions set by CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS variable or platform specific default permissions if the variable is not set.,Implicitly created directories are created if they are not explicitly installed by install() command but are needed to install a file on a certain path. Example of such locations are directories created due to the setting of CMAKE_INSTALL_PREFIX.,Expected content of the CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS variable is a list of permissions that can be used by install() command PERMISSIONS section.

set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ)
72%

I’m trying to install files in a directory (let’s call it /install) where I have write permissions, but that we share with people in the same “group”,This seems to be because that directory is owned by another user in our group. Permissions are,which seems fine to me. This also happens with existing single files owned by another user. I can delete these files/directories and then everything works.,CMake does assume that it can set permissions on files and directories it installs. The install() command has options to control the permissions that get set so we need to be able to set them to honor those (even if just the defaults). An install(DIRECTORY) call implies that permissions should be set on the installed directory.

Doing “make install” runs fine until I get

CMake Error at src / cmake_install.cmake: 45(file):
   file INSTALL cannot set permissions on "/install/include"
load more v
65%

CMake has no other ways for set permissions for installed files except PERMISSIONS option for install command. But there are many ways for simplify permissions settings.,Is there a mechanism in cmake to add a permission to an installed target without repeating all the default permissions?,For example, you can define variable, contained default permissions set:,I can do this using the PERMISSIONS clause and specify SETUID. But when I do this, I lose all the default permissions unless I specify all of those, too.

For example, you can define variable, contained default permissions set:

set(PROGRAM_PERMISSIONS_DEFAULT OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
load more v
75%

Some projects require to generate executable scripts, since the source for the scripts don't have execute permissions we face an issue while testing on Unix platforms., Repository Repository Files Commits Branches Tags Contributors Graph Compare

Current way

configure_file(executable_script.in temp / executable_script)
file(COPY $ {
      CMAKE_BINARY_DIR
   }
   /temp/executable_script
   DESTINATION $ {
      CMAKE_BINARY_DIR
   }
   FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ)
file(REMOVE $ {
      CMAKE_BINARY_DIR
   }
   /temp/executable_script)
load more v
40%

0 Changing default file permissions for cmake install command,0 CPACK .deb installer backup previous installed version,3 CPack multiple packages with own dependencies,0 cpack MSI installation exceeding 2GB - packing into multiple CAB files

I have a CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(MyProject VERSION 1.0 .0)

install(DIRECTORY images DESTINATION "."
   DIRECTORY_PERMISSIONS WORLD_READ WORLD_WRITE FILES_MATCHING PATTERN "*.png")

install(FILES file.json DESTINATION "."
   PERMISSIONS WORLD_READ WORLD_WRITE)

include(CPack)

Other "change-undefined" queries related to "Cmake : How to change file permissions when installing?"