Should a change to CMAKE_PREFIX_PATH invalidate find_package()

In a super-build I’m switching sub-cmake-project’s CMAKE_PREFIX_PATH to different versions of my support packages.

However, when changing from one version to another, the cmake-configure-step is executed, but the find_package-calls inside are not invalidated - so when compiling, it still uses the previous package-version which points to the previous PREFIX_PATH-path.

Is this expected behavior?

Yes, it is expected.

find_package caches the found packages, so that subsequent calls just return immediatelly. It’s basically impossible to clean all those cached variables.

So if you want to use new value for CMAKE_PREFIX_PATH, you need to remove the cache file.

My real problem was a wrong dependency analysis of GNU Make. TL;DR: when changing the support-packages version (actually untarring an archive) I have to touch recursively all files (tar -m) so that their modification times change to untar-time.

This makes all dependencies work correctly, with make.