Post-configuration task

Hi all,

I’m sure this has been asked before, but I couldn’t find any existing threads.

I’m developing a C++ platform that our clients regularly compile for themselves. They often compile multiple different configurations of the platform. I’d like to archive the CMakeCache.txt file as a fail-safe - if the client has a record of the cache file used, that goes most of the way to ensuring they can replicate the build.

I’d like to copy the cache to a secondary location every time it’s re-generated. A naive approach would be to write a custom command with a file-level dependency on the cache file, but that doesn’t work. I assume this is because custom commands are all parsed before the cache file is re-generated.

Old stack overflow threads suggest this isn’t possible ( However, that thread is nearly a decade old. Is there a nice way to achieve what I want with recent versions of CMake?