[CMake] [cmake-developers] Debugging find_package() search behavior?

Brad King brad.king at kitware.com
Tue Aug 29 12:37:49 EDT 2017


On 08/29/2017 12:21 PM, Robert Dailey wrote:
> 3. Second find_package() happens, but "AlreadyInCache" is true (line
> 28 in cmFindPathCommand.cxx) this time, so it doesn't search for it
> again.
> 
> Hard to tell where the bug is here. I'd argue that AlreadyInCache
> shouldn't be set to true since an exact version was not found>, and the
> next find_package() command should do a full path search. Is this a
> bug in the C++ code or the find module script? What determines the
> AlreadyInCache variable?

This is one of the problems with find modules.  The individual find_*
call result *was* found and is already cached.  There is no way to
tell that apart from the user setting it explicitly in the cache.
That it proved insufficient for FPHSA's version check is not the
concern of the find_ command.

The find_package "config" mode uses only a single result variable
and performs a version check before setting it, so it can do
multiple searches like that.  Find modules can't do that because
they need to search for things piecemeal.  At most they can report
at the end that whatever was found is not suitable.  In typical
use cases with only a single find_package call it is then up to
the user to correct the cached settings.

-Brad


More information about the CMake mailing list