Skip to content
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

[question] How to access self.options of a parent library package from its test package? #16491

Closed
1 task done
PauloCarvalhoRJ opened this issue Jun 17, 2024 · 2 comments
Closed
1 task done
Assignees

Comments

@PauloCarvalhoRJ
Copy link

PauloCarvalhoRJ commented Jun 17, 2024

Greetings,

So, I have a test package (test_package sub-directory in the source repository) inside a package named zlib/1.2.11. In zlib's own recipe, I have:

    options = {"shared": [True, False],
               "fPIC": [True, False],
               "minizip": [True, False],
               "os_version": ["linux", "windows", "other"],
               }

I need to access zlib's self.options.minizip value in test package's recipe:

cmake.definitions["WITH_MINIZIP"] = self.options["zlib"].minizip

The code above works with Conan 1, but in Conan 2 I get this error:

ERROR: zlib/1.2.11 (test package): Error in build() method, line 20
        cmake.definitions["WITH_MINIZIP"] = self.options["zlib"].minizip
        ConanException: option 'minizip' doesn't exist
Possible options are []

Then the question is: How can one now (Conan 2) access options values of library packages in their respective test packages?

Thanks in advance,

PC

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@PauloCarvalhoRJ PauloCarvalhoRJ changed the title [question] How to access self.options of a parent or dependency package? [question] How to access self.options of a parent library package from its test package? Jun 17, 2024
@AbrilRBS AbrilRBS self-assigned this Jun 17, 2024
@AbrilRBS
Copy link
Member

AbrilRBS commented Jun 17, 2024

Hi @PauloCarvalhoRJ thanks a lot for your question.

In Conan 2 (And new enough Conan 1 versions!) you'll be looking for the self.dependencies (docs here) accessor

With this, you can query your tested package options like so in a test_package: self.dependencies[self.tested_reference_str].options.minizip (Or just replace the self.tested_reference_str for the library name for any other dependency if needed in general recipes)

I hope this helps :)

@PauloCarvalhoRJ
Copy link
Author

Hello,

Thank you. The new API is more readable in Conan 2. The error shifted to the cmake.dependencies side, but I'll start another question for the issue.

best,

PC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants