From 658490c56b47017096014950cdd62e648f7cc631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Mon, 29 Sep 2025 12:47:51 +0200 Subject: [PATCH 1/2] Docs for cmake_extra_variables property --- reference/tools/cmake/cmakedeps.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/reference/tools/cmake/cmakedeps.rst b/reference/tools/cmake/cmakedeps.rst index 959035f2fdce..5ddd262924cb 100644 --- a/reference/tools/cmake/cmakedeps.rst +++ b/reference/tools/cmake/cmakedeps.rst @@ -252,6 +252,12 @@ The following properties affect the CMakeDeps generator: - **cmake_additional_variables_prefixes**: List of prefixes to be used when creating CMake variables in the config files. These variables are created with ``file_name`` as prefix by default, but setting this property will create additional variables with the specified prefixes alongside the default ``file_name`` one. +- **cmake_extra_variables**: Dictionary of extra variables to be added to the generated config file. + The keys of the dictionary are the variable names and the values are the variable values, + which can be a plain string, a number or a dict-like python object which must specify + the ``value`` (string/number) , ``cache`` (boolean), ``type`` (CMake cache type) and optionally, + ``docstring`` (string: defaulted to variable name) and ``force`` (boolean) keys. Note that this has + less preference over those values defined in the ``tools.cmake.cmaketoolchain:extra_variables`` conf. Example: From e7fd168f96b8bdef8a6ad01a482fd229478a2fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Mon, 29 Sep 2025 12:57:59 +0200 Subject: [PATCH 2/2] Code example --- reference/tools/cmake/cmakedeps.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/reference/tools/cmake/cmakedeps.rst b/reference/tools/cmake/cmakedeps.rst index 5ddd262924cb..96b03e4df61e 100644 --- a/reference/tools/cmake/cmakedeps.rst +++ b/reference/tools/cmake/cmakedeps.rst @@ -288,6 +288,14 @@ Example: # Generate both MyFileNameConfig.cmake and FindMyFileName.cmake self.cpp_info.set_property("cmake_find_mode", "both") + # Add extra variables to the generated config file + self.cpp_info.set_property("cmake_extra_variables", { + "FOO": 42, + "CMAKE_GENERATOR_INSTANCE": "${GENERATOR_INSTANCE}/buildTools/", + "CACHE_VAR_DEFAULT_DOC": {"value": "hello world", + "cache": True, "type": "STRING"} + }) + Overwrite properties from the consumer side using CMakeDeps.set_property() ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++