Repository: conan-io/conan

Issue:
[feature] Support `QUIET` option when `find_package` config files generated by `CMakeDeps`.
According to the [CMake](https://cmake.org/cmake/help/latest/command/find_package.html#basic-signature) documentation, we can use `QUIET` option in `find_package`. 

> The `QUIET` option disables informational messages, including those indicating that the package cannot be found if it is not `REQUIRED`.

Therefore, the output messages won't be too much. However, it seems that those messages **still exist** even though I add `QUIET` option in `find_package`.

According to the [CMake](https://cmake.org/cmake/help/latest/command/find_package.html#package-file-interface-variables) documentation, it seems that the solution is to add `<PackageName>_FIND_QUIETLY` variable in Config files.

> `<PackageName>_FIND_QUIETLY`
> &emsp;&emsp;True if `QUIET` option was given

## Screenshots

![image](https://user-images.githubusercontent.com/71438617/159626216-486e88d3-540c-40c5-9749-e003bc3cbc5c.png)

## Output Messages

<details><summary>Click to expand output message of find_package</summary>

```
[cmake] -- Conan: Component target declared 'Qt6::Core'
[cmake] -- Conan: Component target declared 'Qt6::Platform'
[cmake] -- Conan: Component target declared 'Qt6::Gui'
[cmake] -- Conan: Component target declared 'Qt6::QWindowsIntegrationPlugin'
[cmake] -- Conan: Component target declared 'Qt6::QSQLiteDriverPlugin'
[cmake] -- Conan: Component target declared 'Qt6::QPSQLDriverPlugin'
[cmake] -- Conan: Component target declared 'Qt6::Network'
[cmake] -- Conan: Component target declared 'Qt6::Sql'
[cmake] -- Conan: Component target declared 'Qt6::Test'
[cmake] -- Conan: Component target declared 'Qt6::Widgets'
[cmake] -- Conan: Component target declared 'Qt6::PrintSupport'
[cmake] -- Conan: Component target declared 'Qt6::OpenGL'
[cmake] -- Conan: Component target declared 'Qt6::OpenGLWidgets'
[cmake] -- Conan: Component target declared 'Qt6::Concurrent'
[cmake] -- Conan: Component target declared 'Qt6::Xml'
[cmake] -- Conan: Component target declared 'Qt6::LinguistTools'
[cmake] -- Conan: Component target declared 'Qt6::UiPlugin'
[cmake] -- Conan: Component target declared 'Qt6::UiTools'
[cmake] -- Conan: Component target declared 'Qt6::Designer'
[cmake] -- Conan: Component target declared 'Qt6::Help'
[cmake] -- Conan: Component target declared 'Qt6::EntryPointImplementation'
[cmake] -- Conan: Component target declared 'Qt6::EntryPointPrivate'
[cmake] -- Conan: Target declared 'qt::qt'
[cmake] -- Conan: Target declared 'ZLIB::ZLIB'
[cmake] -- Conan: Component target declared 'pcre2::pcre2-8'
[cmake] -- Conan: Component target declared 'pcre2::pcre2-posix'
[cmake] -- Conan: Component target declared 'pcre2::pcre2-16'
[cmake] -- Conan: Component target declared 'pcre2::pcre2-32'
[cmake] -- Conan: Target declared 'pcre2::pcre2'
[cmake] -- Conan: Target declared 'BZip2::BZip2'
[cmake] -- Conan: Including build module from 'C:/.conan/a06b72/1/lib/cmake/conan-official-bzip2-variables.cmake'
[cmake] -- Conan: Target declared 'double-conversion::double-conversion'
[cmake] -- Conan: Target declared 'freetype'
[cmake] -- Conan: Target declared 'PNG::PNG'
[cmake] -- Conan: Component target declared 'brotli::brotlicommon'
[cmake] -- Conan: Component target declared 'brotli::brotlidec'
[cmake] -- Conan: Component target declared 'brotli::brotlienc'
[cmake] -- Conan: Target declared 'brotli::brotli'
[cmake] -- Conan: Including build module from 'C:/.conan/d7e406/1/lib/cmake/conan-official-freetype-variables.cmake'
[cmake] -- Conan: Target declared 'harfbuzz::harfbuzz'
[cmake] -- Conan: Component target declared 'glib::glib-2.0'
[cmake] -- Conan: Component target declared 'glib::gmodule-no-export-2.0'
[cmake] -- Conan: Component target declared 'glib::gmodule-export-2.0'
[cmake] -- Conan: Component target declared 'glib::gmodule-2.0'
[cmake] -- Conan: Component target declared 'glib::gobject-2.0'
[cmake] -- Conan: Component target declared 'glib::gthread-2.0'
[cmake] -- Conan: Component target declared 'glib::gio-2.0'
[cmake] -- Conan: Component target declared 'glib::gio-windows-2.0'
[cmake] -- Conan: Component target declared 'glib::gresource'
[cmake] -- Conan: Target declared 'glib::glib'
[cmake] -- Conan: Component target declared 'pcre::libpcre'
[cmake] -- Conan: Component target declared 'pcre::libpcreposix'
[cmake] -- Conan: Component target declared 'pcre::libpcre16'
[cmake] -- Conan: Component target declared 'pcre::libpcre32'
[cmake] -- Conan: Target declared 'pcre::pcre'
[cmake] -- Conan: Target declared 'Intl::Intl'
[cmake] -- Conan: Target declared 'Iconv::Iconv'
[cmake] -- Conan: Target declared 'libffi::libffi'
[cmake] -- Conan: Target declared 'libelf::libelf'
[cmake] -- Conan: Component target declared 'SQLite::SQLite3'
[cmake] -- Conan: Component target declared 'libpq::pgcommon'
[cmake] -- Conan: Component target declared 'libpq::pgport'
[cmake] -- Conan: Component target declared 'libpq::pq'
[cmake] -- Conan: Target declared 'PostgreSQL::PostgreSQL'
[cmake] -- Conan: Component target declared 'OpenSSL::Crypto'
[cmake] -- Conan: Component target declared 'OpenSSL::SSL'
[cmake] -- Conan: Target declared 'openssl::openssl'
[cmake] -- Conan: Including build module from 'C:/.conan/ea0190/1/lib/cmake/conan-official-openssl-variables.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Gui/conan_qt_qt6_guiprivate.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Widgets/conan_qt_qt6_widgetsprivate.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Core/conan_qt_executables_variables.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Core/conan_qt_qt6_coreprivate.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Core/conan_qt_entry_point.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicCMakeVersionHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicFinalizerHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicFindPackageHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicPluginHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicTargetHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicWasmToolchainHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Core/Qt6CoreMacros.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Widgets/Qt6WidgetsMacros.cmake'
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6EntryPointd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Helpd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Designerd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6UiToolsd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Xmld_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Concurrentd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6OpenGLWidgetsd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6OpenGLd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6PrintSupportd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Widgetsd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Testd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Sqld_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Networkd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Guid_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Cored_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_EntryPointImplementation_Qt6EntryPointd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Help_Qt6Helpd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Designer_Qt6Designerd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_UiTools_Qt6UiToolsd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Xml_Qt6Xmld_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Concurrent_Qt6Concurrentd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_OpenGLWidgets_Qt6OpenGLWidgetsd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_OpenGL_Qt6OpenGLd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_PrintSupport_Qt6PrintSupportd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Widgets_Qt6Widgetsd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Test_Qt6Testd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Sql_Qt6Sqld_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Network_Qt6Networkd_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Gui_Qt6Guid_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Core_Qt6Cored_DEBUG
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6EntryPoint_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Help_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Designer_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6UiTools_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Xml_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Concurrent_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6OpenGLWidgets_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6OpenGL_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6PrintSupport_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Widgets_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Test_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Sql_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Network_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Gui_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6Core_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_EntryPointImplementation_Qt6EntryPoint_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Help_Qt6Help_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Designer_Qt6Designer_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_UiTools_Qt6UiTools_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Xml_Qt6Xml_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Concurrent_Qt6Concurrent_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_OpenGLWidgets_Qt6OpenGLWidgets_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_OpenGL_Qt6OpenGL_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_PrintSupport_Qt6PrintSupport_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Widgets_Qt6Widgets_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Test_Qt6Test_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Sql_Qt6Sql_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Network_Qt6Network_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Gui_Qt6Gui_RELEASE
[cmake] -- Skipping already existing target: CONAN_LIB::qt_Qt6_Core_Qt6Core_RELEASE
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Gui/conan_qt_qt6_guiprivate.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Widgets/conan_qt_qt6_widgetsprivate.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Core/conan_qt_executables_variables.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Core/conan_qt_qt6_coreprivate.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Core/conan_qt_entry_point.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicCMakeVersionHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicFinalizerHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicFindPackageHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicPluginHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicTargetHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6/QtPublicWasmToolchainHelpers.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Core/Qt6CoreMacros.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake'
[cmake] -- Conan: Including build module from 'C:/.conan/b9fb5546/1/lib/cmake/Qt6Widgets/Qt6WidgetsMacros.cmake'
```

</details>


Discussion:

Resolving patch:
diff --git a/conan/tools/cmake/cmakedeps/templates/config.py b/conan/tools/cmake/cmakedeps/templates/config.py
--- a/conan/tools/cmake/cmakedeps/templates/config.py
+++ b/conan/tools/cmake/cmakedeps/templates/config.py
@@ -45,6 +45,12 @@ def template(self):
             message(FATAL_ERROR "The 'CMakeDeps' generator only works with CMake >= 3.15")
         endif()
 
+        if({{ file_name }}_FIND_QUIETLY)
+            set({{ file_name }}_MESSAGE_MODE VERBOSE)
+        else()
+            set({{ file_name }}_MESSAGE_MODE STATUS)
+        endif()
+
         include(${CMAKE_CURRENT_LIST_DIR}/cmakedeps_macros.cmake)
         include(${CMAKE_CURRENT_LIST_DIR}/{{ targets_include_file }})
         include(CMakeFindDependencyMacro)
@@ -66,7 +72,7 @@ def template(self):
 
         # Only the first installed configuration is included to avoid the collision
         foreach(_BUILD_MODULE {{ '${' + pkg_name + '_BUILD_MODULES_PATHS' + config_suffix + '}' }} )
-            message(STATUS "Conan: Including build module from '${_BUILD_MODULE}'")
+            message({% raw %}${{% endraw %}{{ file_name }}_MESSAGE_MODE} "Conan: Including build module from '${_BUILD_MODULE}'")
             include({{ '${_BUILD_MODULE}' }})
         endforeach()
 
@@ -76,7 +82,7 @@ def template(self):
         if({{ file_name }}_FIND_COMPONENTS)
             foreach(_FIND_COMPONENT {{ '${'+file_name+'_FIND_COMPONENTS}' }})
                 if (TARGET ${_FIND_COMPONENT})
-                    message(STATUS "Conan: Component '${_FIND_COMPONENT}' found in package '{{ pkg_name }}'")
+                    message({% raw %}${{% endraw %}{{ file_name }}_MESSAGE_MODE} "Conan: Component '${_FIND_COMPONENT}' found in package '{{ pkg_name }}'")
                 else()
                     message(FATAL_ERROR "Conan: Component '${_FIND_COMPONENT}' NOT found in package '{{ pkg_name }}'")
                 endif()
diff --git a/conan/tools/cmake/cmakedeps/templates/targets.py b/conan/tools/cmake/cmakedeps/templates/targets.py
--- a/conan/tools/cmake/cmakedeps/templates/targets.py
+++ b/conan/tools/cmake/cmakedeps/templates/targets.py
@@ -66,13 +66,13 @@ def template(self):
         foreach(_COMPONENT {{ '${' + pkg_name + '_COMPONENT_NAMES' + '}' }} )
             if(NOT TARGET ${_COMPONENT})
                 add_library(${_COMPONENT} INTERFACE IMPORTED)
-                message(STATUS "Conan: Component target declared '${_COMPONENT}'")
+                message({% raw %}${{% endraw %}{{ file_name }}_MESSAGE_MODE} "Conan: Component target declared '${_COMPONENT}'")
             endif()
         endforeach()
 
         if(NOT TARGET {{ root_target_name }})
             add_library({{ root_target_name }} INTERFACE IMPORTED)
-            message(STATUS "Conan: Target declared '{{ root_target_name }}'")
+            message({% raw %}${{% endraw %}{{ file_name }}_MESSAGE_MODE} "Conan: Target declared '{{ root_target_name }}'")
         endif()
 
         {%- for alias, target in cmake_target_aliases.items() %}


Test patch:
diff --git a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py
--- a/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py
+++ b/conans/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps.py
@@ -657,3 +657,42 @@ def package_info(self):
     assert "hello/1.0: Hello World Release!" in client.out
     assert "talk: Release!" in client.out
     assert "main: Debug!" in client.out
+
+
+@pytest.mark.tool_cmake
+def test_quiet():
+    conanfile = textwrap.dedent("""
+        from conan import ConanFile
+
+        class Test(ConanFile):
+            name = "test"
+            version = "0.1"
+
+            def package_info(self):
+                self.cpp_info.system_libs = ["lib1"]
+        """)
+    client = TestClient()
+    client.save({"conanfile.py": conanfile})
+    client.run("create .")
+
+    conanfile = textwrap.dedent("""
+        [requires]
+        test/0.1
+
+        [generators]
+        CMakeDeps
+        """)
+    cmakelists = textwrap.dedent("""
+        cmake_minimum_required(VERSION 3.15)
+        project(consumer NONE)
+        set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
+        set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
+        find_package(test QUIET)
+        """)
+
+    client.save({"conanfile.txt": conanfile,
+                 "CMakeLists.txt": cmakelists}, clean_first=True)
+    client.run("install .")
+    client.run_command('cmake . -DCMAKE_BUILD_TYPE=Release')
+    # Because we used QUIET, not in output
+    assert "Target declared 'test::test'" not in client.out