Conan: Question: Is it possible to add options during configure_options or other method?

Created on 26 Jun 2018  路  3Comments  路  Source: conan-io/conan

Hi,

We have a global template for conan projects, defining options. One project now needs additional options. Is it possible to add an additional option during a method like configure_options?
Conan version: 1.4.x

Thanks, Claas

To help us debug your issue please explain:

  • [X] I've read the CONTRIBUTING guide.
  • [X] I've specified the Conan version, operating system version and any tool that can be relevant.
  • [X] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.
question

Most helpful comment

Hi,

Your assumptions are true :-)
I ended up with the following code (requires python 3.5+):

class MyPackageconan(ConanTemplate):
    options = {**ConanTemplate.options, **{'extraOption': [True, False] }}
    default_options = ConanTemplate.default_options + ("extraOption=True",)

The suggestion with update did not work on class attributes.

All 3 comments

I guess you are subclassing the four ConanFile class with s custom template class.

You could just do something like:

    options.update({"tests": [True, False]})
    default_options = default_options + ("tests=True",)

Hi,

If it is subclassing, yes, what @danimtb suggested can work, because it is normal python evaluation (the inheritance is evaluated before conan converts those things to conan objects). If not, please ellaborate a bit further in which way you are using that global template. Many thanks!

Hi,

Your assumptions are true :-)
I ended up with the following code (requires python 3.5+):

class MyPackageconan(ConanTemplate):
    options = {**ConanTemplate.options, **{'extraOption': [True, False] }}
    default_options = ConanTemplate.default_options + ("extraOption=True",)

The suggestion with update did not work on class attributes.

Was this page helpful?
0 / 5 - 0 ratings