build2 / libbuild2-autoconf

Autoconf emulation build system module for build2
MIT License
6 stars 2 forks source link

Handling of `#cmakedefine01` in CMake-Flavored Config Files #63

Closed lyrahgames closed 4 months ago

lyrahgames commented 8 months ago

Thank you all very much for the work on this module. I want to package a third-party project that uses #cmakedefine01. Unfortunately, the module and the code show that this is not supported, yet. Would you mind adding this feature?

I would also offer my help and try to do it myself. However, as I have never worked with build2 modules and this module in particular, it would take me a large amount of time because I would need to read and comprehend the documentation and the source code and, initially, probably do a lot of mistakes.

boris-kolpackov commented 8 months ago

It is available in today's staged toolchain. Could you give it a try and let me know if there are any issues? Thanks!

lyrahgames commented 8 months ago

I have tested it and it works. Thank you very much.

Unfortunately, the project also uses CMake-based variable substitution, e.g.

#define SNITCH_VERSION "${PROJECT_VERSION}"

And I wanted to address these by providing the key-value pairs as assignments, like in the following snippet.

using autoconf

# ...

hxx{snitch_config}: in{snitch_config.hpp.config}
{
  autoconf.flavor = cmake
  PROJECT_VERSION = $version
  # ...
}

However, it seems to ignore the substitution. I might have misunderstood the flavor variable. Is CMake-based substitution supported in the autoconf module?

boris-kolpackov commented 8 months ago

No, CMake ${VAR} style substitutions are not supported and it won't be easy to add this support (since we rely on the in module for actual substitution handling).

I suggest that you replace ${VAR} with @VAR@. If you don't want to patch upstream code, you can do it during the build with an ad hoc recipe along these lines:

in{snitch_config.hpp.config.in}: file{snitch_config.hpp.config}
{{
  sed -e 's/\$\{(.+)\}/@\1@/g' $path($<) >$path($>)
}}

hxx{snitch_config}: in{snitch_config.hpp.config.in}
{{
  ...
}}