Reputation: 117
I created a shell script using CMake just like this:
file(WRITE somescript.sh "echo foo!")
I want the user to be able to execute that script right away. For this, it would be nice to change the permissions of that file from within CMake.
Is there something like chmod u+x somescript.sh
in CMake?
Upvotes: 2
Views: 11780
Reputation: 11
Since cmake version 3.19, it's now possible to use the file(CHMOD ...) command. The syntax is:
file(CHMOD <files>... <directories>... [PERMISSIONS <permissions>...] [FILE_PERMISSIONS <permissions>...] [DIRECTORY_PERMISSIONS <permissions>...])
For example:
file(CHMOD somescript.sh PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
See the documentation for more details.
Upvotes: 1
Reputation: 903
In case you want to copy a binary I would use USE_SOURCE_PERMISSIONS
Upvotes: 0
Reputation: 117
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:
${CMAKE_BINARY_DIR}/tmp
file (COPY ${CMAKE_BINARY_DIR}/tmp/somescript.sh DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
file(REMOVE_RECURSIVE ${CMAKE_BINARY_DIR}/tmp/)
Upvotes: 4
Reputation: 303
You can do that in the istall command. Use this tags:
install(
FILES somescript.sh
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
DESTINATION /some/destination
)
Upvotes: 1