Skip to content

Commit

Permalink
- improve docs on preprocessor_definitions
Browse files Browse the repository at this point in the history
Signed-off-by: SSE4 <[email protected]>
  • Loading branch information
SSE4 committed Jun 29, 2021
1 parent 2eee0f3 commit 4bc42b2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
29 changes: 25 additions & 4 deletions reference/conanfile/tools/cmake/cmaketoolchain.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,38 @@ constructor
Most of the arguments are optional and will be deduced from the current ``settings``, and not
necessary to define them.


preprocessor_definitions
++++++++++++++++++++++++

This attribute allows defining compiler preprocessor definitions, for multiple configurations (Debug, Release, etc).

.. code:: python
def generate(self):
tc = CMakeToolchain(self)
tc.preprocessor_definitions["MYDEF"] = "MyValue"
tc.preprocessor_definitions.debug["MYCONFIGDEF"] = "MyDebugValue"
tc.preprocessor_definitions.release["MYCONFIGDEF"] = "MyReleaseValue"
tc.generate()
This will be translated to:

- One ``add_definitions()`` definition for ``MYDEF`` in ``conan_toolchain.cmake`` file.
- One ``add_definitions()`` definition, using a cmake generator expression in ``conan_toolchain.cmake`` file,
using the different values for different configurations.

variables
+++++++++

This attribute allows defining CMake variables, for multiple configurations (Debug, Release, etc).

.. code:: python
def generate(self):
tc = CMakeToolchain(self)
tc.preprocessor_definitions["MYVAR"] = "MyValue"
tc.preprocessor_definitions.debug["MYCONFIGVAR"] = "MyDebugValue"
tc.preprocessor_definitions.release["MYCONFIGVAR"] = "MyReleaseValue"
tc.variables["MYVAR"] = "MyValue"
tc.variables.debug["MYCONFIGVAR"] = "MyDebugValue"
tc.variables.release["MYCONFIGVAR"] = "MyReleaseValue"
tc.generate()
This will be translated to:
Expand All @@ -100,6 +119,8 @@ This will be translated to:
- One ``set()`` definition, using a cmake generator expression in ``conan_toolchain.cmake`` file,
using the different values for different configurations.

Generators
++++++++++

The ``CMakeToolchain`` is intended to run with the ``CMakeDeps`` dependencies generator. It might temporarily
work with others like ``cmake_find_package`` and ``cmake_find_package_multi``, but this will be removed soon.
Expand Down
17 changes: 17 additions & 0 deletions reference/conanfile/tools/meson.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The ``MesonToolchain`` can be used in the ``generate()`` method:
def generate(self):
tc = MesonToolchain(self)
tc.preprocessor_definitions["MYDEFINE"] = "MYDEF_VALUE"
tc.generate()
Expand Down Expand Up @@ -87,6 +88,22 @@ This attribute allows defining Meson project options:
- One project options definition for ``MYVAR`` in ``conan_meson_native.init`` or ``conan_meson_cross.ini`` file.

preprocessor_definitions
++++++++++++++++++++++++

This attribute allows defining compiler preprocessor definitions, for multiple configurations (Debug, Release, etc).

.. code:: python
def generate(self):
tc = MesonToolchain(self)
tc.preprocessor_definitions["MYDEF"] = "MyValue"
tc.generate()
This will be translated to:

- One preprocessor definition for ``MYDEF`` in ``conan_meson_native.init`` or ``conan_meson_cross.ini`` file.

Generators
++++++++++

Expand Down

0 comments on commit 4bc42b2

Please sign in to comment.