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 3 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
5 changes: 4 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,10 @@ 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("component_version", self.conanfile)
if version is None:
version = self.conanfile.ref.version
return {"version": version,
"policy": policy}

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,50 @@ def generate(self):
assert expected in dep


class TestComponentVersion:
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("component_version", "1.0")
""")

c.save({"conanfile.py": dep})
c.run("create .")
c.run("install --requires=dep/system -g CMakeDeps")
dep = c.load("dep-config-version.cmake")
expected = textwrap.dedent("""\
set(PACKAGE_VERSION "1.0")""")
assert expected 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", "component_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")
expected = textwrap.dedent("""\
set(PACKAGE_VERSION "1.0")""")
assert expected in dep


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