Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMakeDeps: heed <PackageName>_FIND_QUIETLY #12967

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I unset {{ file_name }}_MESSAGE_MODE at the end of either/both files?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might not be necessary, as the scope is well defined, shouldn't be an issue.

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
Original file line number Diff line number Diff line change
Expand Up @@ -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