File API: Is it okay to clean `.cmake` directory?

Currently, documentation for CMake File API states:

CMake owns all reply files. Clients must never remove them.

Why is that? What would happen if client would clear this directory?

E.g. suppose IDE wants to clear cache and reload CMake project. Should IDE also clear .cmake directory?

That wording is referring to the intended lifetime management of files in the .cmake directory within a build tree. Queries are owned externally by clients, and replies are owned by CMake. When CMake runs to re-generate the build system, it will automatically update the set of reply files based on current queries, and remove unnecessary leftover replies.

If you’re removing CMakeCache.txt and CMakeFiles/ to pretend CMake never ran on the build tree in the first place, then it’s safe to remove the .cmake directory too because without CMakeCache.txt, the directory is no longer a CMake build tree.

I’m not sure that’s always the case. An IDE might place files in the .cmake directory before even the first run. Users might be using more than one IDE (I do this with some regularity, but I’m potentially a special case). If an IDE clears the .cmake directory, it also wipes out any queries from other clients (e.g. other IDEs or tools). That may interfere with what those other IDEs or tools want to do with that build directory, causing things to have to re-run again when the user switches to that tool.

In general, I would think an IDE should not clear the .cmake directory when it notionally wants to clear the build’s cache and reload from afresh. The contents of that directory shouldn’t affect the build, it should only be providing information back to interested clients at the end of the run.

1 Like