[CMake] How to work around permission deficiencies of file(GENERATE...)? (was cmp0026, file(GENERATE...), and configure_file)
Alan W. Irwin
irwin at beluga.phys.uvic.ca
Wed Apr 29 19:18:24 EDT 2015
While attempting to use the configure_file_generate function discussed
in a recent thread here, I discovered a permission deficiency of the
file(GENERATE ...) command which was that permissions are not copied
from input file to output file like they are with configure_file.
@CMake developers: was this treatment of permissions by design or is
this a bug in the implementation of the file(GENERATE...) command that
you are willing to fix?
Here is my initial (non-working) attempt to work around this issue
in my configure_file_generate function.
[...]
# Configure generator expressions.
# N.B. these ${output_file} results will only be available
# at generate time.
file(GENERATE
OUTPUT ${output_file}
INPUT ${intermediate_file}
)
if(UNIX OR MSYS)
# This covers all platforms which have permissions,
# i.e., Unix, Cygwin, and MSYS platforms.
# Work around bad permission semantics of file(GENERATE...) which
# does not copy permissions from input file. Note this --reference
# syntax is probably a non-posix extension of the GNU version of chmod.
# So this will silently fail to change permissions
# on platforms without access to the GNU version of chmod.
execute_process(
COMMAND chmod --reference=${intermediate_file} ${output_file}
)
endif(UNIX OR MSYS)
Obviously this workaround does not currently work since
execute_process occurs at configure time rather than generate time as
can be seen from these results:
software at raven> ls -l examples/tk/tk01*
-rw-r--r-- 1 software software 3692 Apr 29 15:45 examples/tk/tk01
-rwxr-xr-x 1 software software 3658 Apr 29 15:45 examples/tk/tk01_cf_only*
where the first file (with bad permissions) is the ${output_file} and
the second file the ${intermediate_file} used in the
configure_file_generate function.
Is there any method I can use at generate time to change permissions
on the OUTPUT file generated by file(GENERATE...), e.g., is there any
way I can force execute_process to work at generate time?
Of course, I could fix permissions at build time, but that is a big
maintenance issue trying to keep track of every file processed by
configure_file_generate so I would far prefer to change the
permissions at generate time within the configure_file_generate
function.
Alan
__________________________
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________
Linux-powered Science
__________________________
More information about the CMake
mailing list