Repository: conan-io/conan
Pull request #18611 (2025-07-09 09:27:39)

CMakeConfigDeps filter requires() to package_type=application
Changelog: Fix: CMakeConfigDeps filter requires() to package_type=application
Docs: Omit

Close https://github.com/conan-io/conan/issues/18597


Patch:
diff --git a/conan/tools/cmake/cmakedeps2/target_configuration.py b/conan/tools/cmake/cmakedeps2/target_configuration.py
index 9b7bdc033..30b71b0ea 100644
--- a/conan/tools/cmake/cmakedeps2/target_configuration.py
+++ b/conan/tools/cmake/cmakedeps2/target_configuration.py
@@ -51,6 +51,8 @@ class TargetConfigurationTemplate2:
         if not requires and not components:  # global cpp_info without components definition
             # require the pkgname::pkgname base (user defined) or INTERFACE base target
             for d in transitive_reqs.values():
+                if d.package_type is PackageType.APP:
+                    continue
                 dep_target = self._cmakedeps.get_property("cmake_target_name", d)
                 dep_target = dep_target or f"{d.ref.name}::{d.ref.name}"
                 link = not (pkg_type is PackageType.SHARED and d.package_type is PackageType.SHARED)


Test patch:
diff --git a/test/integration/toolchains/cmake/cmakedeps2/test_cmakedeps.py b/test/integration/toolchains/cmake/cmakedeps2/test_cmakedeps.py
index 887d7b055..ef72cc991 100644
--- a/test/integration/toolchains/cmake/cmakedeps2/test_cmakedeps.py
+++ b/test/integration/toolchains/cmake/cmakedeps2/test_cmakedeps.py
@@ -383,3 +383,102 @@ def test_cmake_find_mode_deprecated():
     args = f"-g CMakeDeps -c tools.cmake.cmakedeps:new={new_value}"
     tc.run(f"install --requires=dep/0.1 {args}")
     assert "CMakeConfigDeps does not support module find mode"
+
+
+def test_requires_to_application():
+    c = TestClient()
+    automake = textwrap.dedent("""
+        from conan import ConanFile
+        class Dependent(ConanFile):
+            name = "automake"
+            version = "0.1"
+            package_type = "application"
+        """)
+
+    conanfile = textwrap.dedent("""
+        from conan import ConanFile
+        class Pkg(ConanFile):
+            name = "libtool"
+            version = "0.1"
+            package_type = "static-library"
+
+            def requirements(self):
+                self.requires('automake/0.1')
+        """)
+    test_package = textwrap.dedent("""
+        from conan import ConanFile
+        from conan.tools.cmake import CMake
+
+        class TestPkg(ConanFile):
+            settings = "os", "compiler", "arch", "build_type"
+            generators = "CMakeDeps", "CMakeToolchain"
+
+            def requirements(self):
+                self.requires(self.tested_reference_str)
+
+            def test(self):
+                pass
+        """)
+
+    c.save({"automake/conanfile.py": automake,
+            "libtool/conanfile.py": conanfile,
+            "libtool/test_package/conanfile.py":test_package})
+    c.run("create automake")
+    c.run(f"create libtool -c tools.cmake.cmakedeps:new={new_value}")
+    targets = c.load("libtool/test_package/libtool-Targets-release.cmake")
+    # The libtool shouldn't depend on the automake::automake target
+    assert "automake::automake" not in targets
+
+
+def test_requires_to_application_component():
+    c = TestClient()
+    automake = textwrap.dedent("""
+        from conan import ConanFile
+        class Dependent(ConanFile):
+            name = "automake"
+            version = "0.1"
+            package_type = "application"
+
+            def package_info(self):
+                self.cpp_info.components["myapp"].exe = "myapp"
+                self.cpp_info.components["myapp"].location = "path/to/myapp"
+                self.cpp_info.components["mylibapp"].type = "header-library"
+        """)
+
+    conanfile = textwrap.dedent("""
+        from conan import ConanFile
+        class Pkg(ConanFile):
+            name = "libtool"
+            version = "0.1"
+            package_type = "static-library"
+
+            def requirements(self):
+                self.requires('automake/0.1')
+            def package_info(self):
+                self.cpp_info.requires = ["automake::mylibapp"]
+        """)
+    test_package = textwrap.dedent("""
+        from conan import ConanFile
+        from conan.tools.cmake import CMake
+
+        class TestPkg(ConanFile):
+            settings = "os", "compiler", "arch", "build_type"
+            generators = "CMakeDeps", "CMakeToolchain"
+
+            def requirements(self):
+                self.requires(self.tested_reference_str)
+
+            def test(self):
+                pass
+        """)
+
+    c.save({"automake/conanfile.py": automake,
+            "libtool/conanfile.py": conanfile,
+            "libtool/test_package/conanfile.py":test_package})
+    c.run("create automake")
+    c.run(f"create libtool -c tools.cmake.cmakedeps:new={new_value}")
+    targets = c.load("libtool/test_package/libtool-Targets-release.cmake")
+    # The libtool shouldn't depend on the automake::automake target
+    assert "automake::automake" not in targets
+    assert "# Requirement automake::mylibapp => Full link: True" in targets
+    assert "$<$<CONFIG:RELEASE>:automake::mylibapp>" in targets