From 7e15bfd42a9d029e50b5595ea703acc22d113693 Mon Sep 17 00:00:00 2001 From: Ashish Sadanandan Date: Sun, 22 Jan 2023 19:28:30 -0700 Subject: [PATCH] CMakeDeps: heed _FIND_QUIETLY Conan packages using the CMakeDeps generator will now stop printing status messages if the QUIET argument is passed to the respective find_package() CMake call. Fixes #9959 Fixes #10857 --- conan/tools/cmake/cmakedeps/templates/config.py | 10 ++++++++-- conan/tools/cmake/cmakedeps/templates/targets.py | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/conan/tools/cmake/cmakedeps/templates/config.py b/conan/tools/cmake/cmakedeps/templates/config.py index 5892a4160bc..2153bbe3c9f 100644 --- 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(${{{ 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(${{{ 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 index c3cea116d37..d3009140255 100644 --- a/conan/tools/cmake/cmakedeps/templates/targets.py +++ b/conan/tools/cmake/cmakedeps/templates/targets.py @@ -58,6 +58,10 @@ def template(self): get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) file(GLOB DATA_FILES "{{data_pattern}}") + if(NOT DEFINED {{ file_name }}_MESSAGE_MODE) + set({{ file_name }}_MESSAGE_MODE STATUS) + endif() + foreach(f ${DATA_FILES}) include(${f}) endforeach() @@ -66,13 +70,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(${{{ 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(${{{ file_name }}_MESSAGE_MODE} "Conan: Target declared '{{ root_target_name }}'") endif() {%- for alias, target in cmake_target_aliases.items() %}