[CMake] write file if different?
Matthew Woehlke
matthew.woehlke at kitware.com
Thu May 30 18:19:00 EDT 2013
On 2013-05-29 03:32, Michael Wild wrote:
> On 28.05.2013 22:07, Matthew Woehlke wrote:
>> Is there a built-in way to write a string to a file (a la FILE(WRITE))
>> that will only write the file if the content would be different? (Or
>> does FILE(WRITE) already work this way despite no obvious hint in the
>> documentation that it does?)
>>
>> Right now I am writing to a temporary file and running cmake -E
>> copy_if_different, then removing the temporary file, but this seems
>> inelegant and I am wondering if there is a better solution.
>
> AFAIK the file is written unconditionally, but you can then use
> configure_file(... COPYONLY) instead of a round-about execute_process()
> that calls cmake -E copy_if_different.
Actually... no. Well, I could (it would technically work), but because I
always write the file, it causes the build rules to always be out of
date (i.e. CMake is re-run every time), which is decidedly sub-optimal :-).
(Didn't realize that until I finally decided to try it, just now.
Although I wonder now if I had actually tried configure_file originally
and switched to execute_process for exactly this reason...)
So... stronger argument for maybe adding this as an enhancement to CMake.
--
Matthew
More information about the CMake
mailing list