How add execution permissions to file generated by CMake?

Viewed 5427

I have a file, wrapper.sh.in, that has something like the following:

#!/bin/bash
DEPENDENCY_VERSION=@dependency_VERSION@
/location/of/installed/dependency/${DEPENDENCY_VERSION}/some_script.sh "$@"

This wrapper.sh.in script has the usual file permissions for a regular non-executable files (0644), but I need the file generated by CMake to have execution permissions, since it is a script, and therefore meant to be run.


Here's what I am currently doing in my CMakeLists.txt in order to generate my wrapper script:

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


Here's what I've tried for changing the permissions for the generated wrapper.sh script.

Attempt #1 (FAIL):

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

Attempt #2 (FAIL):

install(
    FILES ${CMAKE_CURRENT_SOURCE_DIR}/wrapper.sh
    DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
    COMPONENT runtime
    )


What would be the correct way to change the file permissions of the generated wrapper.sh script to those of a normal script (0755)?

1 Answers
Related