Skip to content

Documented cmaketoolchain:extra_variables (#16229) #3719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions reference/config_files/global_conf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ All the values will be interpreted by Conan as the result of the python built-in
tools.microsoft.msbuildtoolchain:compile_options={"ExceptionHandling": "Async"}


.. _configuration_data_operators:

Configuration data operators
----------------------------

Expand Down
22 changes: 21 additions & 1 deletion reference/tools/cmake/cmaketoolchain.rst
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,26 @@ CMakeToolchain is affected by these ``[conf]`` variables:
- **tools.cmake.cmaketoolchain:system_name** is not necessary in most cases and is only used to force-define ``CMAKE_SYSTEM_NAME``.
- **tools.cmake.cmaketoolchain:system_version** is not necessary in most cases and is only used to force-define ``CMAKE_SYSTEM_VERSION``.
- **tools.cmake.cmaketoolchain:system_processor** is not necessary in most cases and is only used to force-define ``CMAKE_SYSTEM_PROCESSOR``.
- **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.

.. code-block:: text

[conf]
tools.cmake.cmaketoolchain:extra_variables*={'STR': 'string value', 'NUM': 1.3, 'CMAKE_GENERATOR_INSTANCE': '${ENV}/buildTools/', 'SOME_DICT': {'value': '42 sense', 'cache': True, 'type': 'BOOL', 'docstring': 'test cache var'}}

Resulting in:

.. code-block:: cmake

set(STR "string value")
set(NUM 1.3)
set(CMAKE_GENERATOR_INSTANCE "${ENV}/buildTools/")
set(SOME_DICT "42 sense" CACHE BOOL "test cache var")

.. tip::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL! Can I get a pic of how this looks when built?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
It looks good to me, but maybe it is not what we want.
As a noobie, I like command examples so that's why I added it. And also the *= looks very important because really nobody read the docs xD

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final result
image


Use the ``*=`` operator described in :ref:`configuration data operators <configuration_data_operators>` to update the dictionary merging it with previous definitions of ``extra_variables``.

- **tools.cmake.cmaketoolchain:toolset_arch**: Will add the ``,host=xxx`` specifier in the ``CMAKE_GENERATOR_TOOLSET`` variable of ``conan_toolchain.cmake`` file.
- **tools.cmake.cmaketoolchain:toolset_cuda**: (Experimental) Will add the ``,cuda=xxx`` specifier in the ``CMAKE_GENERATOR_TOOLSET`` variable of ``conan_toolchain.cmake`` file.
- **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.
Expand Down Expand Up @@ -653,4 +673,4 @@ CMakeToolchain is affected by these ``[conf]`` variables:
* ``fortran``: will set ``CMAKE_Fortran_COMPILER`` in *conan_toolchain.cmake*.
* ``asm``: will set ``CMAKE_ASM_COMPILER`` in *conan_toolchain.cmake*.
* ``hip``: will set ``CMAKE_HIP_COMPILER`` in *conan_toolchain.cmake*.
* ``ispc``: will set ``CMAKE_ISPC_COMPILER`` in *conan_toolchain.cmake*.
* ``ispc``: will set ``CMAKE_ISPC_COMPILER`` in *conan_toolchain.cmake*.