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

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.

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().

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