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.
I would expect cmake_language(DEFER) to have the same problems. It will run at the end of the current scope (or a specified directory’s scope) but still during the configure phase. My understanding is that the CMakeCache.txt file is only written out after the whole project has completed its configure stage, so it isn’t accessible from a cmake_language(DEFER).
ETA: Note that this has the benefit of saving the cache from ccmake or cmake-gui only once the generate step is used. Repeated configures don’t make “bogus” cache snapshots.