diff --git a/meson.build b/meson.build index 86e7ba4d..c16d7854 100644 --- a/meson.build +++ b/meson.build @@ -32,10 +32,15 @@ git = find_program('git', native: true, required: false) if not git.found() add_project_arguments('-DVERSION="@0@"'.format(meson.project_version()), language: 'cpp') else - git_commit_hash = run_command([git.path(), 'describe', '--always', '--tags']).stdout().strip() - git_branch = run_command([git.path(), 'rev-parse', '--abbrev-ref', 'HEAD']).stdout().strip() - version = '"@0@ (" __DATE__ ", branch \'@1@\')"'.format(git_commit_hash, git_branch) - add_project_arguments('-DVERSION=@0@'.format(version), language: 'cpp') + git_path = run_command([git.path(), 'rev-parse', '--show-toplevel']).stdout().strip() + if meson.source_root() == git_path + git_commit_hash = run_command([git.path(), 'describe', '--always', '--tags']).stdout().strip() + git_branch = run_command([git.path(), 'rev-parse', '--abbrev-ref', 'HEAD']).stdout().strip() + version = '"@0@ (" __DATE__ ", branch \'@1@\')"'.format(git_commit_hash, git_branch) + add_project_arguments('-DVERSION=@0@'.format(version), language: 'cpp') + else + add_project_arguments('-DVERSION="@0@"'.format(meson.project_version()), language: 'cpp') + endif endif if not compiler.has_header('filesystem')