Is it safe to delete CMakeCache.txt before each incremental build?

My incremental CI builds frequently get:

##[error]CMake Error: Target xxx has dependency information when it shouldn't.
##[error]Your cache is probably stale. Please remove the entry xxx_LIB_DEPENDS from the cache.

Is it safe to delete the cache file before each build?
Will most build binaries be still up to date, or will this trigger a full rebuild?

Note: this is a copy of my SO Question. I just posted it there first out of habit and forgot about this specialized forum :slight_smile:

if you delete CMakeCache.txt before each build you must make sure to configure and generate cmake. Without it is not “safe” because the cached variables are missing in the next build.

Deleting CMakeCache.txt should not affect any binaries, a full rebuild is not triggered. Otherwise you might have a local variable passed on before being cached which then leads to inconsistent runs.

The regeneration of the project can trigger rebuilds if the configuration is different to the previous one.

1 Like