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

preparing migration of names to CMakeDeps #8568

Merged
merged 3 commits into from Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions conan/tools/cmake/cmakedeps.py
Expand Up @@ -560,12 +560,24 @@ def _check_component_in_requirements(require):
for pkg_require in cpp_info.requires:
_check_component_in_requirements(pkg_require)

def _get_name(self, cpp_info):
# FIXME: This is a workaround to be able to use existing recipes that declare
# FIXME: cpp_info.names["cmake_find_package_multi"] = "xxxxx"
return cpp_info.names.get(self.name, cpp_info.names.get("cmake_find_package_multi",
cpp_info._name))

def _get_filename(self, cpp_info):
# FIXME: This is a workaround to be able to use existing recipes that declare
# FIXME: cpp_info.filenames["cmake_find_package_multi"] = "xxxxx"
return cpp_info.filenames.get(self.name, cpp_info.filenames.get("cmake_find_package_multi",
cpp_info._name))

def _get_require_name(self, pkg_name, req):
pkg, cmp = req.split(COMPONENT_SCOPE) if COMPONENT_SCOPE in req else (pkg_name, req)
pkg_cpp_info = self._conanfile.deps_cpp_info[pkg]
pkg_name = pkg_cpp_info.get_name(self.name)
pkg_name = self._get_name(pkg_cpp_info)
if cmp in pkg_cpp_info.components:
cmp_name = pkg_cpp_info.components[cmp].get_name(self.name)
cmp_name = self._get_name(pkg_cpp_info.components[cmp])
else:
cmp_name = pkg_name
return pkg_name, cmp_name
Expand All @@ -575,7 +587,7 @@ def _get_components(self, pkg_name, cpp_info):
sorted_comps = cpp_info._get_sorted_components()

for comp_name, comp in sorted_comps.items():
comp_genname = cpp_info.components[comp_name].get_name(self.name)
comp_genname = self._get_name(cpp_info.components[comp_name])
comp_requires_gennames = []
for require in comp.requires:
comp_requires_gennames.append(self._get_require_name(pkg_name, require))
Expand Down Expand Up @@ -617,8 +629,8 @@ def content(self):

for pkg_name, cpp_info in self._conanfile.deps_cpp_info.dependencies:
self._validate_components(cpp_info)
pkg_filename = cpp_info.get_filename(self.name)
pkg_findname = cpp_info.get_name(self.name)
pkg_filename = self._get_filename(cpp_info)
pkg_findname = self._get_name(cpp_info)
pkg_version = cpp_info.version

public_deps = self.get_public_deps(cpp_info)
Expand All @@ -628,7 +640,7 @@ def content(self):
if name not in deps_names:
deps_names.append(name)
deps_names = ';'.join(deps_names)
pkg_public_deps_filenames = [self._conanfile.deps_cpp_info[it[0]].get_filename(self.name)
pkg_public_deps_filenames = [self._get_filename(self._conanfile.deps_cpp_info[it[0]])
for it in public_deps]
config_version = self.config_version_template.format(version=pkg_version)
ret[self._config_version_filename(pkg_filename)] = config_version
Expand Down
24 changes: 24 additions & 0 deletions conans/test/unittests/tools/cmake/test_cmakedeps.py
@@ -0,0 +1,24 @@
from conan.tools.cmake import CMakeDeps
from conans import ConanFile, Settings
from conans.model.build_info import CppInfo
from conans.model.env_info import EnvValues
from conans.test.utils.mocks import TestBufferConanOutput


def test_cpp_info_name_cmakedeps():

conanfile = ConanFile(TestBufferConanOutput(), None)
conanfile.settings = "os", "compiler", "build_type", "arch"
conanfile.initialize(Settings({"os": ["Windows"],
"compiler": ["gcc"],
"build_type": ["Release"],
"arch": ["x86"]}), EnvValues())

cpp_info = CppInfo("mypkg", "dummy_root_folder1")
cpp_info.names["cmake_find_package_multi"] = "MySuperPkg1"
cpp_info.filenames["cmake_find_package_multi"] = "ComplexFileName1"
conanfile.deps_cpp_info.add("mypkg", cpp_info)

cmakedeps = CMakeDeps(conanfile)
files = cmakedeps.content
assert "TARGET MySuperPkg1::MySuperPkg1" in files["ComplexFileName1Config.cmake"]