# How do I know when I can read the CMakeCache.txt

**URL:** <https://discourse.cmake.org/t/how-do-i-know-when-i-can-read-the-cmakecache-txt/7811>\
**Category:** Code\
**Created:** [April 3, 2023, 12:47pm UTC](https://discourse.cmake.org/t/how-do-i-know-when-i-can-read-the-cmakecache-txt/7811 "2023-04-03T12:47:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eriols](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eriols/32/945_2.png) [@eriols](https://discourse.cmake.org/u/eriols)\
**Post date:** [April 3, 2023, 12:47pm UTC](https://discourse.cmake.org/t/how-do-i-know-when-i-can-read-the-cmakecache-txt/7811/1 "2023-04-03T12:47:15Z")

</div>

If I within cmake want to know when the CMakeCache file from the configure step is ready to be read, what would be a good way to do this?  
I was looking at using `cmake_language DEFER DIRECTORY ${CMAKE_SOURCE_DIR} CALL my_cache_reading_function())` but that gives that this file “cannot be read” despite being there at this time.

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [April 3, 2023, 1:03pm UTC](https://discourse.cmake.org/t/how-do-i-know-when-i-can-read-the-cmakecache-txt/7811/2 "2023-04-03T13:03:56Z")

</div>

`CMakeCache.txt` is not written until after the configure step is done, so you can’t read from it during the processing of `CMakeLists.txt`. If you really want to read from it, I would defer it with an `add_custom_command()`.

---

<div class="post-metadata">

**Author:** ![eriols](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eriols/32/945_2.png) [@eriols](https://discourse.cmake.org/u/eriols)\
**Post date:** [April 3, 2023, 1:11pm UTC](https://discourse.cmake.org/t/how-do-i-know-when-i-can-read-the-cmakecache-txt/7811/3 "2023-04-03T13:11:46Z")

</div>

Thanks, yes, I’ll go that route then.
