diff --git a/include/utils.h b/include/utils.h index efe1899..dc0c0c1 100644 --- a/include/utils.h +++ b/include/utils.h @@ -16,13 +16,6 @@ #define C_STD "C89" #endif -#ifndef GIT_HASH -#define GIT_HASH "0000000000" -#endif - -#ifndef GIT_COMMITS -#define GIT_COMMITS "1" -#endif #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) diff --git a/include/version.h.in b/include/version.h.in new file mode 100644 index 0000000..96ced3b --- /dev/null +++ b/include/version.h.in @@ -0,0 +1,3 @@ +#pragma once +#define GIT_HASH "@GIT_HASH@" +#define GIT_COMMITS "@GIT_COMMITS@" \ No newline at end of file diff --git a/meson.build b/meson.build index 7f92d8f..9df8566 100644 --- a/meson.build +++ b/meson.build @@ -24,25 +24,22 @@ srcs = [ cc = meson.get_compiler('c') -git = find_program('git', required : false) +git = find_program('git') +git_hash = run_command(git, 'rev-parse', '--short', 'HEAD', check: false).stdout().strip() +git_commits = run_command(git, 'rev-list', '--count', 'HEAD', check: false).stdout().strip() -if git.found() - git_hash = run_command(git, 'rev-parse', '--short', 'HEAD', check: false).stdout().strip() - git_commits = run_command(git, 'rev-list', '--count', 'HEAD', check: false).stdout().strip() -else - git_hash = 'unknown' - git_commits = '0' -endif - -add_project_arguments( - '-DGIT_HASH="' + git_hash + '"', - '-DGIT_COMMITS="' + git_commits + '"', - language: 'c' +version_h = configure_file( + input : 'include/version.h.in', + output : 'version.h', + configuration : { + 'GIT_HASH' : git_hash, + 'GIT_COMMITS' : git_commits, + } ) executable( 'linuxSmartie', - srcs, + srcs + [version_h], include_directories : include_directories('include'), dependencies : [ dependency('libusb-1.0', required : true),