FindPkgConfig sets ..._FOUND variables as cache variables, interaction with CMP0126 NEW behavior
The FindPkgConfig
module uses an internal _pkgconfig_set()
function to set various variables. It is also used to set ${_prefix}_FOUND
variables to 1, but this then makes that variable visible outside of the current scope. This interacts with the changes in CMake 3.21 associated with CMP0126, leading to unexpected behavior when projects update to set CMP0126 to NEW. For an example of this see QTBUG-95635.
I'd argue that the module shouldn't be setting any ..._FOUND
variables in the cache, but I don't know if we can change that to only set non-cache variables now. We would have to also consider the scenario where there was already such values in the cache from an earlier CMake version if we did change the behavior.