Environment variable <PackageName>_ROOT ignored with a cmake minimum required 3.22

Hello, I recently faced a curious situation.

My project has the following structure: my CMakeLists.txt starts with a cmake_minimum_required(VERSION 3.22) then calls find_package(Foo REQUIRED). The file FooConfig.cmake calls find_dependency(Bar) then find_dependency(Baz). My environment contains the variables Foo_ROOT, Bar_ROOT and Baz_ROOT.

The configuration stopped because cmake could not find Baz. During the configuration it displayed the warning “Policy CMP0074 is not set: find_package uses _ROOT variables.”.

I found it surprising as the minimum required that I asked should have defined the policy CMP0074 to NEW.

I noticed that the file BarConfig.cmake was calling cmake_minimum_required(VERSION 3.8) then include(CMakeFindDependencyMacro). My understanding is that the macro find_dependency was redefined capturing a policy CMP0074 unset due to the new minimum required 3.8. Back in the file FooConfig.cmake, the find_dependency(Baz) command called find_package in a scope where the policy CMP0074 was then unset thus ignoring the Baz_ROOT variable.

Can you confirm that it makes sense ?