In Windows, I can impress or update information including a build version into a DLL after it is built, as a post-process step before deploying.
There does not seem to be such a feature in Linux shared object files. It appears that I need to include this while building.
How can I have meson automatically put the git commit ID of the current repository state into a text file so I can refer to that in the source code? In the end, I want the .so file to "know" its own version and will (for example) log that as part of its operation, or can return that string from a published API of that library.
I understand that meson has "generative" features, but I could not follow how to use it from the online manual.
You can use vcs_tag command:
You should provide git-version.h.in in your code base with @VCS_TAG@ which will be replace with git commit id (result of the command), replacement string can be changed - see docs.
The file will be placed in the configured build directory in the same relative directory, so that output can be used as it's replacing the input in-place, e.g. you can include git_version.h from the directory where git_version.h.in is located.
And note, that
e.g.
UPDATE Here is working sample project:
Building/running
And if we look inside generated ninja file, we can notice this works because dir is added to compiler include paths: