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

improve message for new CMakeDeps #17821

Merged
merged 1 commit into from
Feb 20, 2025
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
18 changes: 10 additions & 8 deletions conan/tools/cmake/cmakedeps2/cmakedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _content(self):
continue

if require.direct:
direct_deps.append(dep)
direct_deps.append((require, dep))
config = ConfigTemplate2(self, dep)
ret[config.filename] = config.content()
config_version = ConfigVersionTemplate2(self, dep)
Expand All @@ -78,14 +78,16 @@ def _content(self):
def _print_help(self, direct_deps):
if direct_deps:
msg = ["CMakeDeps necessary find_package() and targets for your CMakeLists.txt"]
targets = []
for dep in direct_deps:
msg.append(f" find_package({self.get_cmake_filename(dep)})")
if not dep.cpp_info.exe:
link_targets = []
for (require, dep) in direct_deps:
note = " # Optional. This is a tool-require, can't link its targets" \
if require.build else ""
msg.append(f" find_package({self.get_cmake_filename(dep)}){note}")
if not require.build and not dep.cpp_info.exe:
target_name = self.get_property("cmake_target_name", dep)
targets.append(target_name or f"{dep.ref.name}::{dep.ref.name}")
if targets:
msg.append(f" target_link_libraries(... {' '.join(targets)})")
link_targets.append(target_name or f"{dep.ref.name}::{dep.ref.name}")
if link_targets:
msg.append(f" target_link_libraries(... {' '.join(link_targets)})")
self._conanfile.output.info("\n".join(msg), fg=Color.CYAN)

def set_property(self, dep, prop, value, build_context=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@ def test_tool_requires(self):
.with_tool_requires("tool/0.1")})
c.run("create tool")
c.run(f"install pkg -g CMakeDeps -c tools.cmake.cmakedeps:new={new_value}")
assert "find_package(tool) # Optional. This is a tool-require, " \
"can't link its targets" in c.out
assert "target_link_libraries" not in c.out
tool_config = c.load("pkg/tool-config.cmake")
assert 'set(tool_INCLUDE_DIRS' not in tool_config
assert 'set(tool_INCLUDE_DIR' not in tool_config
Expand Down
Loading