find_package not searching a package in Config mode again after Module mode failure

In an application, I’m using

find_package(Libxc 5.1.2 COMPONENTS Fortran)

Based on find_package documentaiton, it tries Module mode
and found FindLibxc.cmake which is provided by the application .
However, on one machine, FindLibxc.cmake fails to find the package.
Based on documentation,
“If the MODULE option is not specified in the above signature, CMake first searches for the package using Module mode. Then, if the package is not found, it searches again using Config mode.”
CMake will attempt Config mode.
However after CMake failed finding the package in Module mode, it went on without trying Config mode based on --debug-find printout. I tried 3.18 and 3.19. If I use

find_package(Libxc 5.1.2 COMPONENTS Fortran CONFIG)

Then the package got found in Config mode.

Do I misunderstand the documentation or there is a potential bug?

Now I have to write

find_package(Libxc 5.1.2 COMPONENTS Fortran)
If (NOT Libxc_FOUND)
  find_package(Libxc 5.1.2 COMPONENTS Fortran CONFIG)
endif()

For me the documentation is a bit ambiguous. The paragraph you’ve cited says that if the PACKAGE is not found by the FIND_MODULE it’ll try again in CONFIG mode.

However just a few paragraphs before that:

If no module is found the command falls back to Config mode, described below. This fall back is disabled if the MODULE option is given.

Which suggests that only if the FIND_MODULE itself isn’t found, the CONFIG mode will be tried.

So which one is it? Or do those two paragraphs indeed talk about different things?

My feeling is that the documentation doesn’t have ambiguity.
One is about how Module/Config modes are choose based on the search of module file. This the first step.
One is about how a mode is chosen based on the package search results. This is a second step.

It seems to me that the implementation is not doing as what the documentation says.

I am simply not sure. I didn’t have to rely on any of that behaviour and could always simply specify what I wanted but reading this section is a bit confusing. I mean after reading it few times I am not sure what happens when because the modes seem to fall back to each other unless they don’t.
So if nothing more, rewording this few paragraphs could be beneficial.