# find\_package not searching a package in Config mode again after Module mode failure

**URL:** <https://discourse.cmake.org/t/find-package-not-searching-a-package-in-config-mode-again-after-module-mode-failure/2899>\
**Category:** Usage\
**Created:** [March 5, 2021, 3:12pm UTC](https://discourse.cmake.org/t/find-package-not-searching-a-package-in-config-mode-again-after-module-mode-failure/2899 "2021-03-05T15:12:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xw111luoye](https://discourse.cmake.org/user_avatar/discourse.cmake.org/xw111luoye/32/1273_2.png) [@xw111luoye](https://discourse.cmake.org/u/xw111luoye)\
**Post date:** [March 5, 2021, 3:12pm UTC](https://discourse.cmake.org/t/find-package-not-searching-a-package-in-config-mode-again-after-module-mode-failure/2899/1 "2021-03-05T15:12:39Z")

</div>

In an application, I’m using

```auto
find_package(Libxc 5.1.2 COMPONENTS Fortran)

```

Based on find\_package documentaiton, it tries Module mode  
and found [FindLibxc.cmake](https://gitlab.com/toxa81/q-e/-/blob/develop/cmake/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

```auto
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

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

```

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [March 5, 2021, 3:59pm UTC](https://discourse.cmake.org/t/find-package-not-searching-a-package-in-config-mode-again-after-module-mode-failure/2899/2 "2021-03-05T15:59:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![xw111luoye](https://discourse.cmake.org/user_avatar/discourse.cmake.org/xw111luoye/32/1273_2.png) [@xw111luoye](https://discourse.cmake.org/u/xw111luoye)\
**Post date:** [March 5, 2021, 4:08pm UTC](https://discourse.cmake.org/t/find-package-not-searching-a-package-in-config-mode-again-after-module-mode-failure/2899/3 "2021-03-05T16:08:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [March 5, 2021, 4:44pm UTC](https://discourse.cmake.org/t/find-package-not-searching-a-package-in-config-mode-again-after-module-mode-failure/2899/4 "2021-03-05T16:44:21Z")

</div>

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.
