install(FILES ...) to ignore install of files when file at DESTINATION is newer/has been modified

Hello !

I’m looking for a way to prevent the install(FILES <myfile> DESTINATION <myfolder>) to re-install <myfile> when the file at destination <folder>/<myfile> is newer than the source.

To put things into context:
We install our runtime configuration files for debugging and tuning our science algorithms at the same time than our libs and executables. These files can be modified on the fly by the user to enable/disable some log outputs and change some constants, so we really only need them to be updated only if the original file in the project source tree is newer than the one at destination (for instance when a new mandatory parameter has been added) so we don’t overwrite the changes made by the user to the destination file in the meantime.
As of this moment, every call to make install re-installs the source tree version, which is a bit frustrating.

install() checks for file contents, not “newer”. You’ll need custom install(CODE) to do this detection to avoid the installation.

Thanks for the reply ! I’ll have to check how the CODE install works then :slight_smile:

I’m curious on how the content check is performed ?
Because we’ve had this other case of a file that is not updated on install when the install directive is :


With SOME_VAR given as a cmake command line define -DSOME_VAR=pattern, and the some_file being different for each possible pattern.

Hmm. Maybe there is some timestamp shortcircuit going on too? But any source is likely to be “newer” than any given install if git is used.