How to clean up unused cache variables?

I have a project that has an option:

option(FOOBAR "hello world")

After a while I realize I don’t need this option. So I remove it from my project.

However, it’s still in my cache. This can cause confusion for other developers who don’t realize I removed it. Since the value will still show up in cmake-gui.

Is there a way to automatically delete unused project cache variables?

Automatically? No.

This (old) feature request might be of interest though since it would basically end up tracking cache variables anyways. It could be extended to track non-advanced variables that aren’t used at all (though it’d likely be an extension).

Well if there is no way to clean up unused cache variables, then what’s the workflow for CMake supposed to look like? Delete the cache once a month?

I don’t think there’s a “supposed to” for this. Generally they just accumulate and if they start to get noisy, a refreshing the build tree is always an option.

Can’t this be fixed? I’m 100% sure this is going to cause confusion at my company eventually.

That issue is the closest thing I’m aware of on the issue tracker. Anything related to this is likely going to share similar roots with what that needs.

Gotcha.