# Does CMake write some kind of "stamp" file ?

**URL:** https://discourse.cmake.org/t/does-cmake-write-some-kind-of-stamp-file/10184
**Category:** Development
**Created:** [February 25, 2024, 2:24pm UTC](https://discourse.cmake.org/t/does-cmake-write-some-kind-of-stamp-file/10184 "2024-02-25T14:24:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![neundorf](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neundorf/32/2075_2.png) [@neundorf](https://discourse.cmake.org/u/neundorf)
#### Post date: [February 25, 2024, 2:24pm UTC](https://discourse.cmake.org/t/does-cmake-write-some-kind-of-stamp-file/10184/1 "2024-02-25T14:24:55Z")

</div>

Hi,

in the kate build plugin I’d like to react if cmake was rerun on the current build tree (in order to read the updated file API files).  
Is there some file I could “watch” ?  
I’d prefer not to have different cases for watching a regenerated “Makefile” or “build.ninja” or projectname.sln depending on which generator is used.  
The reply files are different on every run if I understand correctly, so I cannot watch one of them.

Is there some file I could “watch” ?

Thanks  
Alex

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [February 25, 2024, 9:46pm UTC](https://discourse.cmake.org/t/does-cmake-write-some-kind-of-stamp-file/10184/2 "2024-02-25T21:46:47Z")

</div>

Maybe the `CMakeCache.txt` file in the build directory. I don’t know if its timestamp gets updated if its contents don’t change, but you should be able to test that fairly easily to confirm one way or the other.

Technically, `CMakeCache.txt` will be updated at the end of the configure phase. This only matters here because while `cmake` always executes both the configure and generation phases, `ccmake` and CMake-GUI require the user to execute them separately. So it would be possible to encounter situations where the user executes the configure phase but not the generation phase. That would cause `CMakeCache.txt` to be updated, but not the project files (`Makefile`, `build.ninja`, etc.). It’s probably not a corner case you’d really need to support though, I suspect.

---

<div class="post-metadata">

### Author: ![neundorf](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neundorf/32/2075_2.png) [@neundorf](https://discourse.cmake.org/u/neundorf)
#### Post date: [February 27, 2024, 8:09pm UTC](https://discourse.cmake.org/t/does-cmake-write-some-kind-of-stamp-file/10184/3 "2024-02-27T20:09:13Z")

</div>

No, the CMakeCache.txt is only modifed if actually some setting has changed.  
It’s the other way round, if the CMakeCache.txt has changed, then cmake runs again. Wouldn’t it be an endless loop otherwise ? 😉

I looked a bit around and found the file CMakeFiles/cmake.check\_cache, which says:  
“# This file is generated by cmake for dependency checking of the CMakeCache.txt file”

So it looks like this file is modified by every cmake run.  
But can I rely on this file, or may it change in the fuure ? And since when does it exist ?

Alex

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [February 27, 2024, 8:42pm UTC](https://discourse.cmake.org/t/does-cmake-write-some-kind-of-stamp-file/10184/4 "2024-02-27T20:42:07Z")

</div>

~~The `CMakeCache.txt` timestamp is always updated when CMake re-runs. That’s used to check if the generated build system is up to date w.r.t. the CMake inputs. You may rely on it.~~ EDIT: Sorry, this is totally wrong. `CMakeCache.txt` is among the CMake inputs.

---

<div class="post-metadata">

### Author: ![neundorf](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neundorf/32/2075_2.png) [@neundorf](https://discourse.cmake.org/u/neundorf)
#### Post date: [February 27, 2024, 9:00pm UTC](https://discourse.cmake.org/t/does-cmake-write-some-kind-of-stamp-file/10184/5 "2024-02-27T21:00:03Z")

</div>

Not sure I’m not misunderstanding something.  
If I “touch” CMakeCache.txt e.g. at 9:00, then wait 5 minutes, and then build, cmake is rerun.  
ls -al still shows the time 9:00 for CMakeCache.txt. Building then again of course does not trigger a rerun of cmake.  
The file CMakeFiles/cmake.check\_cache OTOH does show the time of when cmake was run, i.e. 9:05.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [February 28, 2024, 1:19pm UTC](https://discourse.cmake.org/t/does-cmake-write-some-kind-of-stamp-file/10184/6 "2024-02-28T13:19:11Z")

</div>

> in the kate build plugin I’d like to react if cmake was rerun on the current build tree (in order to read the updated file API files).

See the [file-api docs](https://cmake.org/cmake/help/v3.29/manual/cmake-file-api.7.html#v1-reply-index-file) on the reply index file. Clients of the file-api should watch the `.cmake/api/v1/reply/` directory for the appearance of new `index-*.json` files.

---

<div class="post-metadata">

### Author: ![neundorf](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neundorf/32/2075_2.png) [@neundorf](https://discourse.cmake.org/u/neundorf)
#### Post date: [February 28, 2024, 9:47pm UTC](https://discourse.cmake.org/t/does-cmake-write-some-kind-of-stamp-file/10184/7 "2024-02-28T21:47:56Z")

</div>

Currently I read these files if “I” trigger the rerun of cmake, but I don’t want to read them whenever a build has been run.  
So I have to use a filesystem watcher on the directory `.cmake/api/v1/reply/` ?  
I’m wondering whether it is cross-platform cross-filesystem reliable that I’ll be notified that the directory has been modified if a new file has been written into the directory.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [February 28, 2024, 10:11pm UTC](https://discourse.cmake.org/t/does-cmake-write-some-kind-of-stamp-file/10184/8 "2024-02-28T22:11:13Z")

</div>

> [@neundorf](#):
>
> So I have to use a filesystem watcher on the directory `.cmake/api/v1/reply/` ?

Yes. Several IDEs do this AFAIK. That’s the intended way for IDEs to reload the file-api replies.
