From 6753ee3dad6bc01b8ff1138dbc443e01679de277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 7 May 2019 20:23:51 +0200 Subject: [PATCH] meson: set project version Export project version with -DF00BAR_VERSION. This is by default set to the meson project version. However, if git is found, and we manage to run 'git describe' and 'git branch' in the source directory, version is set to the output of that instead. --- doc/meson.build | 1 - meson.build | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/doc/meson.build b/doc/meson.build index f91e311..76967f8 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -1,4 +1,3 @@ -sh = find_program('sh', native: true) scdoc = dependency('scdoc', native: true) scdoc_prog = find_program(scdoc.get_pkgconfig_variable('scdoc'), native: true) diff --git a/meson.build b/meson.build index c4c86a9..cf4fa32 100644 --- a/meson.build +++ b/meson.build @@ -1,10 +1,33 @@ project('f00bar', 'c', + version: '1.0.0', license: 'MIT', meson_version: '>=0.48.0', default_options: ['c_std=c11', 'warning_level=1', 'werror=true']) plugs_as_libs = get_option('core-plugins-as-shared-libraries') +version = '"@0@"'.format(meson.project_version()) + +sh = find_program('sh', native: true) +git = find_program('git', required: false, native: true) + +if git.found() + commit_hash = run_command( + [sh.path(), '-c', + '@0@ --git-dir=$MESON_SOURCE_ROOT/.git describe --always --tags'.format( + git.path())]) + + branch = run_command( + [sh.path(), '-c', + '@0@ --git-dir=$MESON_SOURCE_ROOT/.git rev-parse --abbrev-ref HEAD'.format( + git.path())]) + + if commit_hash.returncode() == 0 and branch.returncode() == 0 + version = '"@0@ (" __DATE__ ", branch \'@1@\')"'.format( + commit_hash.stdout().strip(), branch.stdout().strip()) + endif +endif + # Common dependencies cc = meson.get_compiler('c') dl = cc.find_library('dl', required : false) @@ -34,7 +57,8 @@ wlroots = dependency('wlroots', required: get_option('backend-wayland')) backend_wayland = wayland_client.found() and wayland_cursor.found() and wlroots.found() add_project_arguments( - ['-D_GNU_SOURCE'] + + ['-D_GNU_SOURCE', + '-DF00BAR_VERSION=@0@'.format(version)] + (backend_x11 ? ['-DENABLE_X11'] : []) + (backend_wayland ? ['-DENABLE_WAYLAND'] : []) + (plugs_as_libs ? ['-DCORE_PLUGINS_AS_SHARED_LIBRARIES'] : []),