diff --git a/conan/tools/cmake/cmakedeps/cmakedeps.py b/conan/tools/cmake/cmakedeps/cmakedeps.py index 238d77cc4bf..5a9b7c252ef 100644 --- a/conan/tools/cmake/cmakedeps/cmakedeps.py +++ b/conan/tools/cmake/cmakedeps/cmakedeps.py @@ -60,6 +60,10 @@ def content(self): if dep.is_build_context and dep.ref.name not in self.build_context_activated: continue + if dep.new_cpp_info.get_property("skip_deps_file", "CMakeDeps"): + # Skip the generation of config files for this node, it will be located externally + continue + config_version = ConfigVersionTemplate(self, require, dep) ret[config_version.filename] = config_version.render() diff --git a/conans/test/integration/toolchains/cmake/__init__.py b/conans/test/integration/toolchains/cmake/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/conans/test/integration/toolchains/cmake/cmakedeps/__init__.py b/conans/test/integration/toolchains/cmake/cmakedeps/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py b/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py new file mode 100644 index 00000000000..d85d7d166b6 --- /dev/null +++ b/conans/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py @@ -0,0 +1,39 @@ +import os + +from conans.test.assets.genconanfile import GenConanfile +from conans.test.utils.tools import TestClient + + +def test_package_from_system(): + """ + If a node declares "system_package" property, the CMakeDeps generator will skip generating + the -config.cmake and the other files for that node but will keep the "find_dependency" for + the nodes depending on it. That will cause that cmake looks for the config files elsewhere + https://github.com/conan-io/conan/issues/8919""" + client = TestClient() + dep2 = str(GenConanfile().with_name("dep2").with_version("1.0") + .with_settings("os", "arch", "build_type", "compiler")) + dep2 += """ + def package_info(self): + self.cpp_info.set_property("skip_deps_file", True) + self.cpp_info.set_property("cmake_file_name", "custom_dep2") + + """ + client.save({"conanfile.py": dep2}) + client.run("create .") + + dep1 = GenConanfile().with_name("dep1").with_version("1.0").with_require("dep2/1.0")\ + .with_settings("os", "arch", "build_type", "compiler") + client.save({"conanfile.py": dep1}) + client.run("create .") + + consumer = GenConanfile().with_name("consumer").with_version("1.0").\ + with_require("dep1/1.0").with_generator("CMakeDeps").\ + with_settings("os", "arch", "build_type", "compiler") + client.save({"conanfile.py": consumer}) + client.run("install .") + assert os.path.exists(os.path.join(client.current_folder, "dep1-config.cmake")) + assert not os.path.exists(os.path.join(client.current_folder, "dep2-config.cmake")) + assert not os.path.exists(os.path.join(client.current_folder, "custom_dep2-config.cmake")) + contents = client.load("dep1-release-x86_64-data.cmake") + assert 'set(dep1_FIND_DEPENDENCY_NAMES ${dep1_FIND_DEPENDENCY_NAMES} custom_dep2)' in contents diff --git a/conans/test/unittests/tools/cmake/test_cmakedeps.py b/conans/test/unittests/tools/cmake/test_cmakedeps.py index 24b223e851b..c25d127d43f 100644 --- a/conans/test/unittests/tools/cmake/test_cmakedeps.py +++ b/conans/test/unittests/tools/cmake/test_cmakedeps.py @@ -171,4 +171,3 @@ def test_component_name_same_package(): data_cmake = files["mypkg-release-x86-data.cmake"] assert 'set(mypkg_mypkg_INCLUDE_DIRS_RELEASE ' \ '"${mypkg_PACKAGE_FOLDER_RELEASE}/includedirs1")' in data_cmake -