diff --git a/examples/tools/cmake/cmake_toolchain/use_package_config_cmake.rst b/examples/tools/cmake/cmake_toolchain/use_package_config_cmake.rst index 9984f8b3e653..0e39e5ba3841 100644 --- a/examples/tools/cmake/cmake_toolchain/use_package_config_cmake.rst +++ b/examples/tools/cmake/cmake_toolchain/use_package_config_cmake.rst @@ -51,6 +51,16 @@ This is a very typical recipe, the main difference is the ``package_info()`` met - It is defining that it will contain the build scripts (like the ``xxx-config.cmake`` package) inside that folder, to be located by consumers. +.. note:: + + If the in-package ``xxx-config.cmake`` file has a different name than the Conan + package name, set the ``cmake_file_name`` property with the right value, so that + ``find_package()`` can locate it: + + .. code-block:: python + + self.cpp_info.set_property("cmake_file_name", "MyPkg") + So the responsibility of defining the package details has been transferred to the ``CMakeLists.txt`` that contains: .. code-block:: cmake diff --git a/tutorial/creating_packages/define_package_information.rst b/tutorial/creating_packages/define_package_information.rst index 7c6002e561d9..374b3c8fbbb4 100644 --- a/tutorial/creating_packages/define_package_information.rst +++ b/tutorial/creating_packages/define_package_information.rst @@ -301,9 +301,19 @@ And re-create the package: You can see how Conan now declares the target ``hello::myhello`` instead of the default ``hello::hello`` and the *test_package* builds successfully. +Similarly, if the CMake config file name differs from the Conan package name, set the +``cmake_file_name`` property so consumers can call ``find_package()`` with the right name, +for example if the consumers are expected to do ``find_package(MyHello CONFIG REQUIRED)`` + +.. code-block:: python + :caption: *conanfile.py* + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "MyHello") + The target name is not the only property you can set in the ``CMakeDeps`` generator. For a complete list of properties that affect the ``CMakeDeps`` generator behaviour, please check -the :ref:`reference`. +the :ref:`reference`. Propagating environment or configuration information to consumers -----------------------------------------------------------------