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

add cmakedeps listening to system_package_version property #14808

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
4 changes: 3 additions & 1 deletion conan/tools/cmake/cmakedeps/templates/config_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def context(self):
policy = "SameMajorVersion"
if policy not in ("AnyNewerVersion", "SameMajorVersion", "SameMinorVersion", "ExactVersion"):
raise ConanException(f"Unknown cmake_config_version_compat={policy} in {self.conanfile}")
return {"version": self.conanfile.ref.version,
version = self.cmakedeps.get_property("system_package_version", self.conanfile)
version = version or self.conanfile.ref.version
return {"version": version,
"policy": policy}

@property
Expand Down
4 changes: 3 additions & 1 deletion conan/tools/gnu/pkgconfigdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ def _get_context(self, info):
}
if info.cpp_info is not None:
context.update({
"version": info.cpp_info.get_property("component_version") or self._dep.ref.version,
"version": (info.cpp_info.get_property("component_version") or
info.cpp_info.get_property("system_package_version") or
self._dep.ref.version),
"cflags": self._get_cflags([d for d in pc_variables if d.startswith("includedir")],
info.cpp_info),
"libflags": self._get_lib_flags([d for d in pc_variables if d.startswith("libdir")],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,51 @@ def generate(self):
assert expected in dep


class TestSystemPackageVersion:
def test_component_version(self):
c = TestClient()
dep = textwrap.dedent("""\
from conan import ConanFile
class Pkg(ConanFile):
name = "dep"
version = "system"
def package_info(self):
self.cpp_info.set_property("system_package_version", "1.0")
self.cpp_info.components["mycomp"].set_property("component_version", "2.3")
""")

c.save({"conanfile.py": dep})
c.run("create .")
c.run("install --requires=dep/system -g CMakeDeps -g PkgConfigDeps")
dep = c.load("dep-config-version.cmake")
assert 'set(PACKAGE_VERSION "1.0")' in dep
dep = c.load("dep.pc")
assert 'Version: 1.0' in dep
dep = c.load("dep-mycomp.pc")
assert 'Version: 2.3' in dep

def test_component_version_consumer(self):
c = TestClient()
app = textwrap.dedent("""\
from conan import ConanFile
from conan.tools.cmake import CMakeDeps
class Pkg(ConanFile):
settings = "build_type"
requires = "dep/system"
def generate(self):
deps = CMakeDeps(self)
deps.set_property("dep", "system_package_version", "1.0")
deps.generate()
""")

c.save({"dep/conanfile.py": GenConanfile("dep", "system"),
"app/conanfile.py": app})
c.run("create dep")
c.run("install app")
dep = c.load("app/dep-config-version.cmake")
assert 'set(PACKAGE_VERSION "1.0")' in dep


def test_cmakedeps_set_property_overrides():
c = TestClient()
app = textwrap.dedent("""\
Expand Down