# Best practices for notifications in config files

**URL:** https://discourse.cmake.org/t/best-practices-for-notifications-in-config-files/12880
**Category:** Usage
**Created:** [November 1, 2024, 4:39pm UTC](https://discourse.cmake.org/t/best-practices-for-notifications-in-config-files/12880 "2024-11-01T16:39:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![hebasto](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hebasto/32/4713_2.png) [@hebasto](https://discourse.cmake.org/u/hebasto)
#### Post date: [November 1, 2024, 4:39pm UTC](https://discourse.cmake.org/t/best-practices-for-notifications-in-config-files/12880/1 "2024-11-01T16:39:29Z")

</div>

Hi,

The `FindPackageHandleStandardArgs` module is quite handy for use in Find modules. In addition to other functionality, it provides a clear notification when a package is found.

What are the best practices for notifying users about a package’s details (such as path and version) when working with a config file?

Thanks.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [November 1, 2024, 10:10pm UTC](https://discourse.cmake.org/t/best-practices-for-notifications-in-config-files/12880/2 "2024-11-01T22:10:40Z")

</div>

That’s a contentious question. I’ll give my opinion, but you should expect others to have opposite views. Personally, I follow the principle of “if things are successful, there should be no output by default”. This is what compilers do, and it ensures the log is fairly concise. This means when something is output to the log, the user is more likely to notice it. If you output a lot of information, you train the users to ignore all the output, so they miss warnings and other important messages that get lost in the noise.

There’s nothing wrong with outputting more info if the verbosity level is raised. You could use `cmake_language(GET_MESSAGE_LOG_LEVEL)` to work out what the verbosity level is, but you should check if the user is using a new enough CMake version (3.25) before you try to do that. Don’t call it if the user is using CMake 3.24 or older, just assume the default verbosity level in that case.

As for `FindPackageHandleStandardArgs`, or more specifically the `find_package_handle_standard_args()` command it provides, I actually never use that myself. Before the more target-centric “modern CMake” became a thing, `find_package_handle_standard_args()` was a useful way to handle “was I successful or not” processing at the end of a Find module. But now that Find modules are generally going to be providing targets too (or at least should ideally be), a well-behaved Find module should not create any targets if it is going to be unsuccessful, and that usually means you would have to manually implement all the checks yourself anyway. By the time you get to the point in your Find module’s logic where you would call `find_package_handle_standard_args()`, you would already have implemented most of it. The `find_package_handle_standard_args()` command also logs output, and as I mentioned above, I much prefer to output nothing by default unless there is a problem.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [November 1, 2024, 10:20pm UTC](https://discourse.cmake.org/t/best-practices-for-notifications-in-config-files/12880/3 "2024-11-01T22:20:48Z")

</div>

Sorry, I skipped over an important part of your question. You were asking about _config files_, not Find modules. A package config file should follow the same principle, not outputting anything unless there’s a problem. But for config files, it is a bit more complicated. A single call to `find_package()` can read and process _many_ config packages’ version files (`packagename-config-version.cmake` or `PackageNameConfigVersion.cmake`). These must never log any output at all. For the actual config file (`packagename-config.cmake` or `PackageNameConfig.cmake`), it should not log any messages directly, but rather it should provide error information by setting `${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE` if there’s a problem. The `find_package()` command will then use that to provide the relevant handling. The [Importing and Exporting Guide](https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html) contains an example that demonstrates its use.
