Skip to content

Commit d8bbe7f

Browse files
perseoGIAbrilRBS
andauthored
Documented cmaketoolchain:extra_variables (#16229) (#3719)
* Documented cmaketoolchain:generator_instance (#16229) * Substituted generator_instance for extra_variables * Updated changes with new version of extra_variables * Updated extra_variable docs * Reviewed threads * Update reference/tools/cmake/cmaketoolchain.rst Co-authored-by: Rubén Rincón Blanco <rubenrb@jfrog.com> --------- Co-authored-by: Rubén Rincón Blanco <rubenrb@jfrog.com>
1 parent 3a934a2 commit d8bbe7f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

reference/config_files/global_conf.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ All the values will be interpreted by Conan as the result of the python built-in
143143
tools.microsoft.msbuildtoolchain:compile_options={"ExceptionHandling": "Async"}
144144
145145
146+
.. _configuration_data_operators:
147+
146148
Configuration data operators
147149
----------------------------
148150

reference/tools/cmake/cmaketoolchain.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,42 @@ CMakeToolchain is affected by these ``[conf]`` variables:
653653
- **tools.cmake.cmaketoolchain:system_name** is not necessary in most cases and is only used to force-define ``CMAKE_SYSTEM_NAME``.
654654
- **tools.cmake.cmaketoolchain:system_version** is not necessary in most cases and is only used to force-define ``CMAKE_SYSTEM_VERSION``.
655655
- **tools.cmake.cmaketoolchain:system_processor** is not necessary in most cases and is only used to force-define ``CMAKE_SYSTEM_PROCESSOR``.
656+
- **tools.cmake.cmaketoolchain:extra_variables**: dict-like python object which specifies the CMake variable name and value. Value can be a plain string, number or a dict-like python object which must specifies ``value`` (string/number) , ``cache`` (boolean), ``type`` (CMake cache type) and optionally, ``docstring`` (string: defaulted to variable name). Potential override of CMakeToolchain defined variables, users are at their own risk. E.g.
657+
658+
.. code-block:: text
659+
660+
[conf]
661+
tools.cmake.cmaketoolchain:extra_variables={'MY_CMAKE_VAR': 'MyValue'}
662+
663+
Resulting in:
664+
665+
.. code-block:: cmake
666+
667+
set(MY_CMAKE_VAR "MyValue")
668+
669+
Which will be injected later so it can override default Conan variables.
670+
671+
Another advanced usage:
672+
673+
.. code-block:: text
674+
675+
tools.cmake.cmaketoolchain:extra_variables={'MyIntegerVariable': 42, 'CMAKE_GENERATOR_INSTANCE': '${ENV}/buildTools/'}
676+
tools.cmake.cmaketoolchain:extra_variables*={'CACHED_VAR': {'value': '/var/run', 'cache': True, 'type': 'PATH', 'docstring': 'test cache var'}}
677+
678+
Resulting in:
679+
680+
.. code-block:: cmake
681+
682+
set(MyIntegerVariable 42)
683+
set(CMAKE_GENERATOR_INSTANCE "${ENV}/buildTools/")
684+
set(CACHED_VAR "/var/run" CACHE BOOL "test cache var")
685+
686+
This block injects ``$`` which will be expanded later. It also defines a cache variable of type ``PATH``.
687+
688+
.. tip::
689+
690+
Use the :ref:`configuration data operator<configuration_data_operators>` ``*=`` to **update** (instead of redefining) conf variables already set in profiles or the global configuration.
691+
656692
- **tools.cmake.cmaketoolchain:toolset_arch**: Will add the ``,host=xxx`` specifier in the ``CMAKE_GENERATOR_TOOLSET`` variable of ``conan_toolchain.cmake`` file.
657693
- **tools.cmake.cmaketoolchain:toolset_cuda**: (Experimental) Will add the ``,cuda=xxx`` specifier in the ``CMAKE_GENERATOR_TOOLSET`` variable of ``conan_toolchain.cmake`` file.
658694
- **tools.cmake.cmake_layout:build_folder_vars**: Settings, Options, and/or ``self.name`` and ``self.version`` that will produce a different build folder and different CMake presets names.

0 commit comments

Comments
 (0)