[CMake] File permissions on CONFIGURE_FILE output

Chris Hillery chillery-cmake at lambda.nu
Wed Feb 3 04:16:24 EST 2010


On Wed, Feb 3, 2010 at 1:09 AM, Michael Wild <themiwi at gmail.com> wrote:

>
> On 2. Feb, 2010, at 22:31 , Aaron_Wright at selinc.com wrote:
>
> > I run CONFIGURE_FILE on a file that is read only. The output file is also
> > read only, which is a problem because I need to append to it. Is there a
> > way to change this behavior? Or a work around?
> >
>
> Either change the source-file permissions or use file(COPY ...) after
> configure_file.
>

There doesn't seem to be a way in cmake to change file permissions, which is
an odd hole (there's lots of stuff about setting permissions at
install-time, but nothing else). You'd have to do something system-specific
like execute_process(COMMAND chmod).

There's also no file(COPY). I tried an experiment using cmake -E copy, but
it also maintains permissions just like configure_file()!

The only work-around I've found is to copy the file "manually":

configure_file("${CMAKE_SOURCE_DIR}/readonly.txt"
"${CMAKE_BINARY_DIR}/readonly.txt")
file(READ "${CMAKE_BINARY_DIR}/readonly.txt" myfile)
file(REMOVE "${CMAKE_BINARY_DIR}/readonly.txt")
file(WRITE "${CMAKE_BINARY_DIR}/readonly.txt" "${myfile}")

This actually works, because it creates a new file with default permissions.
Alternately, you could write to a new file with a different name; in that
case you could skip the file(REMOVE).

I do agree, though, that ideally you wouldn't want to muck with a configured
file after configuring it. However, I expect there are some non-ideal
situations which might require that, so the above work-around should get you
going.

Ceej
aka Chris Hillery
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100203/8052e8dd/attachment.htm>


More information about the CMake mailing list