Skip to content

Commit

Permalink
Add subproject_options documentation (#3655)
Browse files Browse the repository at this point in the history
* Add subproject_options documentation

* Update reference/tools/meson/mesontoolchain.rst

* Update reference/tools/meson/mesontoolchain.rst

* redirect to original source for installation

* revert requirement add

---------

Co-authored-by: Francisco Ramírez <franchuti688@gmail.com>
Co-authored-by: czoido <mrgalleta@gmail.com>
  • Loading branch information
3 people committed Apr 30, 2024
1 parent 856de24 commit 70a7a05
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.md
Expand Up @@ -5,16 +5,20 @@ Documentation for Conan C/C++ package manager: https://conan.io
How to build
============

- Install prerequisites:
- [graphviz](https://graphviz.org/download)
- [enchant](https://pyenchant.github.io/pyenchant/install.html)

- Install python and [pip docs](https://pip.pypa.io/en/stable/installing/).
- Install the requirements (sphinx):

`$ pip install -r requirements.txt`

- Point to the Conan source code folder (``git clone https://github.com/conan-io/conan && cd conan && git checkout develop2``)

Windows:
- Windows:
`$ set PYTHONPATH=<your/path/to/conan>;%PYTHONPATH%`
Linux:
- Linux:
`$ export PYTHONPATH=<your/path/to/conan>:$PYTHONPATH`


Expand Down
24 changes: 23 additions & 1 deletion reference/tools/meson/mesontoolchain.rst
Expand Up @@ -151,6 +151,24 @@ The ``wrap_mode: nofallback`` is defined by default as a project option, to make
Note that in this case, Meson might be able to find dependencies in "wraps", it is the responsibility of the user to check the behavior and make sure about the dependencies origin.

subproject_options
^^^^^^^^^^^^^^^^^^

This attribute allows defining Meson subproject options:

.. code:: python
def generate(self):
tc = MesonToolchain(self)
tc.subproject_options["SUBPROJECT"] = [{'MYVAR': 'MyValue'}]
tc.generate()
This is translated to:

- One subproject ``SUBPROJECT`` and option definition for ``MYVAR`` in the ``conan_meson_native.ini`` or ``conan_meson_cross.ini`` file.

Note that in contrast to ``project_options``, ``subproject_options`` is a dictionary of lists of dictionaries. This is because Meson allows multiple subprojects, and each subproject can have multiple options.

preprocessor_definitions
^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -209,7 +227,9 @@ values:
def generate(self):
tc = MesonToolchain(self)
tc.project_options["DYNAMIC"] = bool(self.options.shared) # shared is bool
tc.project_options["GREETINGS"] = str(self.options.with_msg) # with_msg is str
tc.project_options["GREETINGS"] = str(self.options.with_msg) # with_msg is str
tc.subproject_options["SUBPROJECT"] = [{'MYVAR': str(self.options.with_msg)}] # with_msg is str
tc.subproject_options["SUBPROJECT"].append({'MYVAR': bool(self.options.shared)}) # shared is bool
tc.generate()
In contrast, directly assigning a Conan option as a Meson value is strongly discouraged:
Expand All @@ -223,6 +243,8 @@ In contrast, directly assigning a Conan option as a Meson value is strongly disc
tc = MesonToolchain(self)
tc.project_options["DYNAMIC"] = self.options.shared # == <PackageOption object>
tc.project_options["GREETINGS"] = self.options.with_msg # == <PackageOption object>
tc.subproject_options["SUBPROJECT"] = [{'MYVAR': self.options.with_msg}] # == <PackageOption object>
tc.subproject_options["SUBPROJECT"].append({'MYVAR': self.options.shared}) # == <PackageOption object>
tc.generate()
These are not boolean or string values but an internal Conan class representing such
Expand Down

0 comments on commit 70a7a05

Please sign in to comment.