Skip to content

Commit

Permalink
CMakeDeps: heed <PackageName>_FIND_QUIETLY
Browse files Browse the repository at this point in the history
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
  • Loading branch information
praetorian20 committed Jan 24, 2023
1 parent 43c1834 commit aaaf8cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions conan/tools/cmake/cmakedeps/templates/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions conan/tools/cmake/cmakedeps/templates/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() %}
Expand Down

0 comments on commit aaaf8cc

Please sign in to comment.