Cmake:How to Change File Permissions When Installing

cmake : How to change file permissions when installing?

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
)

Change permissions of file in CMake

The problem with install is that existing files are not overwritten when the destination directory is equal to the source directory and when the files themselves did not change (CMake seems to compare timestamps). But nevermind, I found a working solution for everyone reading along:

  1. Create the file as shown in the question but in a temporary folder ${CMAKE_BINARY_DIR}/tmp
  2. Use file (COPY ${CMAKE_BINARY_DIR}/tmp/somescript.sh DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
  3. Remove the old file and the temporary directory: file(REMOVE_RECURSIVE ${CMAKE_BINARY_DIR}/tmp/)

How add execution permissions to file generated by CMake?

Copying file "at place" is bad idea in most cases.

Instead, configure file into one (intermediate) place, and copy it (with changed permissions) into the final location:

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/wrapper.sh.in
${CMAKE_CURRENT_SOURCE_DIR}/tmp/wrapper.sh
@ONLY
)

file(
COPY ${CMAKE_CURRENT_SOURCE_DIR}/tmp/wrapper.sh
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)

Set permissions of the installation directory

to do so, you may use install command w/ the following signature:

install([[SCRIPT <file>] [CODE <code>]] [...])`

and write a code to change permissions at install time. I.e. smth like this:

execute_process(COMMAND /bin/chmod ARGS 0700 "${CMAKE_INSTALL_PREFIX}")

put this to a chmod.cmake or to a string and then call install above.

Change an existing file's permissions using cmake

Write a shell script that changes permissions and run it during installation using install(CODE "execute_process(COMMAND \"yourscript.sh\")".

CMake - setting file permissions after installation (java)

The install_jar() definition is, basically, just install() call:

function(INSTALL_JAR _TARGET_NAME _DESTINATION)
get_property(__FILES
TARGET ${_TARGET_NAME}
PROPERTY INSTALL_FILES
)

if (__FILES)
install(FILES ${__FILES}
DESTINATION ${_DESTINATION}
)
else (__FILES)
message(SEND_ERROR "The target ${_TARGET_NAME} is not known in this scope.")
endif (__FILES)
endfunction(INSTALL_JAR _TARGET_NAME _DESTINATION)

So you can just write your own install_jar_with_args() and add PERMISSIONS keyword to the install() call.

Probably, this problem needs to be reported to CMake devs.

Keep a single file's permissions when using install() in CMake

You can install files with +x permission using

install(PROGRAMS ...

command.

Alternatively, you can install whole directory preserving file permissions:

install(DIRECTORIES ... USE_SOURCE_PERMISSIONS)

See documentation for install command for more info.



Related Topics



Leave a reply



Submit