Let’s say I have a recipe foo.bb containing:
PACKAGECONFIG[option1] = "..."
PACKAGECONFIG[option2] = "..."
Now, I want to write a recipe for package bar. In order to run, bar requires package foo to be compiled with option option1 but not option2.
I know that Yocto is inspired from Gentoo Portage. In portage, this kind of dependency would be written (https://devmanual.gentoo.org/general-concepts/dependencies/#built-with-use-dependencies):
RDEPENDS="foo[option1,-option2]"
How can I do the same with Yocto?
There is no such mechanism for RDEPENDS in yocto. You can get the same result by:
Putting the foo.bb instructions in an .inc file
#foo.inc
PACKAGECONFIG[option1] = "..."
PACKAGECONFIG[option2] = "..."
Create foo-option1.bb and foo-option2.bb based on the .inc and the relevant PACKAGECONFIG variable
#foo-option1.bb
require foo.inc
PACKAGECONFIG = "option1"
#foo-option2.bb
require foo.inc
PACKAGECONFIG = "option2"
Having bar.bb RDEPEND on the correct package
#bar.bb
# Can be foo-option2. Up to you
RDEPENDS_${PN} += "foo-option1"
The other way is that you add a global variable that you set in a global configuration file, like local.conf or distro.conf and make foo.bb use it to enable the option and bar.conf to check if the setting is set and refuse if not. This is fragile in my opinion but is a valid alternative.
There are other ways but I believe this is the easiest from my perspective. If you really want to know other ways let me know, but they are uglier.
PS: Remember that RDEPENDS is used to declare dependencies of packages to runtime packages, not recipes. This means that RDEPENDS should always be RDEPENDS_${PN} or the name of the package it is related to.