aliBuild: version-dependent cmake option

Hi, if I want to add a CMake option to the alidist recipe depending on the version that is built (e.g. add the option for all FairMQ v1.4+). What is the canonical way of doing this?

Should I just add an if block in the bash section of the recipe and somehow do my version compare against $PKGVERSION? Do we have any helpers for version comparisons? Can I assume python is available (in the bash section)?

I think that checking the version is always the wrong approach. This will break in case we use something other than versions (e.g. hashes).

The best way is grepping the piece of code in the source directory that makes you discriminate between the two distinct behaviors. You would grep for the old code (because it’s old, and will never change): if you find it, you enable the old behavior. If you don’t, you fall back on the new one.

There’s an example in alidist already, but I frankly forgot.

Good point. Can I consult the git metadata? e.g.

git --no-pager tag -l --merged HEAD --contains "v1.4.0" >/dev/null 2>&1 would return success if the tag v1.4.0 is reachable from HEAD.

I think you are missing my point :slight_smile:

Ordering Git tags is a tough business. Don’t do that. This, incidentally, breaks in case you are using the package in development mode, and in case your local source is unaware of the remote tags.

You can only rely on the source code itself for this (data, not metadata). If there is some specific -DSOMETHING=ON option, I believe you can grep CMakeLists.txt to see if SOMETHING is somehow handled.

This would be a different condition (the option exists since a long time), but I want to switch it on only from releases v1.4.2+. The FairMQ version does not exist anywhere else but as a tag (We have no dist tarballs at the moment, where one would bake the version into the source tree).

Aside from how to implement the version condition, how would I make the dependency asiofi in the yaml section of the recipe depending on that same condition?

To simplify the matter: Alternatively to the version check, I could live also with a “manual” switch.

  • What is the recommended approach here?
  • Environment variable?
  • How can I make the dependency in the yaml section optional based on the environment?
  • Is this :(?...) syntax any python string substitution magic?