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 retrieve the Meson project version within the (C++) source code #4144

Closed
kelson42 opened this issue Sep 9, 2018 · 8 comments

Comments

@kelson42
Copy link

kelson42 commented Sep 9, 2018

I want to get that number (the project "version" in meson.build) printed if I call:

$ my_soft --version

I failed so far to get the documentation explaining how to get that number from Meson?

@xclaesse
Copy link
Member

xclaesse commented Sep 9, 2018

Pass it in your cpp_args: executable('app', sources, cpp_args : '-DVERSION=@0@'.format(meson.project_version()))

Then in cpp file you can use VERSION define.

@kelson42
Copy link
Author

kelson42 commented Sep 9, 2018

@xclaesse Thank you, I will try this

@boazsegev
Copy link

I find it a very poor idea to have the version controlled by the mason.build file, especially in projects that supports multiple build systems (make, CMake, mason...).

Is there any way for mason to dynamically read the version number from an external file?

@wszqkzqk
Copy link

Pass it in your cpp_args: executable('app', sources, cpp_args : '-DVERSION=@0@'.format(meson.project_version()))

Then in cpp file you can use VERSION define.

But vala doesn't support this🥲

@dcbaker
Copy link
Member

dcbaker commented Jan 14, 2023

Valac has a -D/—define option, you should be able to pass that to vala_args

@wszqkzqk
Copy link

Valac has a -D/—define option, you should be able to pass that to vala_args

But Vala cannot define a value, it can only used in conditional compiling

@wszqkzqk
Copy link

I can only write a version.vala.in to do this.

@dcbaker
Copy link
Member

dcbaker commented Jan 14, 2023

Ah, yeah. vcs_tag() might be what you want then

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

5 participants