diff --git a/reference/conanfile/tools/cmake.rst b/reference/conanfile/tools/cmake.rst index 012f94599d7..29fb40379ff 100644 --- a/reference/conanfile/tools/cmake.rst +++ b/reference/conanfile/tools/cmake.rst @@ -10,6 +10,7 @@ conan.tools.cmake .. toctree:: :maxdepth: 2 + cmake/cmakedeps cmake/cmaketoolchain cmake/cmake diff --git a/reference/conanfile/tools/cmake/cmakedeps.rst b/reference/conanfile/tools/cmake/cmakedeps.rst index 5d78bf6c7d6..0c5f87f0d9e 100644 --- a/reference/conanfile/tools/cmake/cmakedeps.rst +++ b/reference/conanfile/tools/cmake/cmakedeps.rst @@ -130,3 +130,38 @@ Use the **build_context_build_modules** attribute to specify require names to in # Choose the build modules from "build" context cmake.build_context_build_modules = ["my_tool"] cmake.generate() + +Properties +++++++++++ + +The following properties affect the CMakeDeps generator: + +- **cmake_file_name**: The config file generated for the current package will follow the ``-config.cmake`` pattern, + so to find the package you write ``find_package()``. +- **cmake_target_name**: Name of the target to be consumed. When set on the root ``cpp_info``, + it changes the namespace of the target. When set to a component, it changes the name of the target + (see the example below). +- **cmake_build_modules**: List of ``.cmake`` files (route relative to root package folder) that are automatically + included when the consumer run the ``find_package()``. +- **skip_deps_file**: It tells the ``CMakeDeps`` generator to skip the creation of files for the package declaring + this property. It can be used, for instance, to create a system wrapper package so the consumers find + the config files in the CMake installation config path and not in the generated by Conan (because it has been skipped). + +Example: + +.. code-block:: python + + def package_info(self): + ... + # MyFileName-config.cmake + self.cpp_info.set_property("cmake_file_name", "MyFileName") + # Foo:: namespace for the targets (Foo::Foo if no components) + self.cpp_info.set_property("cmake_target_name", "Foo") + # Foo::Var target name for the component "mycomponent" + self.cpp_info.components["mycomponent"].set_property("cmake_target_name", "Var") + # Automatically include the lib/mypkg.cmake file when calling find_package() + self.cpp_info.components["mycomponent"].set_property("cmake_build_modules", [os.path.join("lib", "mypkg.cmake")]) + + # Skip this package when generating the files for the whole dependency tree in the consumer + # note: it will make useless the previous adjustements. + self.cpp_info.set_property("skip_deps_file", True)