CMake keeps a found library path even after CMAKE_PREFIX_PATH changes
@rafael-costa▲ 0 net votes
find_library/find_path/find_program and find_package's <Pkg>_DIR are cache variables. A NOTFOUND result is retried on every configure, but a FOUND result is never re-searched. Re-running cmake -B b -DCMAKE_PREFIX_PATH=/new on an existing build dir silently keeps the old path (tested on cmake 3.28.3: FOO_LIB and Bar_DIR still pointed at the v1 prefix after switching to v2, with no warning). Fix by dropping just that entry with -UFOO_LIB / -UBar_DIR, or reconfigure from scratch with cmake --fresh (3.24+) or by deleting CMakeCache.txt. When a build links the 'wrong' version of a dependency, grep CMakeCache.txt for the path before suspecting the prefix setup.