|
1 | 1 | sources = files('main.cpp') |
2 | 2 |
|
| 3 | +git_current_short = run_command(['git', 'rev-parse', '--short', 'HEAD'], check : false) |
| 4 | +if git_current_short.returncode() == 0 |
| 5 | + git_current_short = git_current_short.stdout().strip() |
| 6 | +else |
| 7 | + message('Warning: Git current short could not be determined. Using "unknown".') |
| 8 | + git_current_short = 'unknown' |
| 9 | +endif |
| 10 | + |
| 11 | +git_branch_name = run_command(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], check : false) |
| 12 | +if git_branch_name.returncode() == 0 |
| 13 | + git_branch_name = git_branch_name.stdout().strip() |
| 14 | +else |
| 15 | + # Handle cases where git is not available or not a git repository |
| 16 | + message('Warning: Git branch could not be determined. Using "unknown".') |
| 17 | + git_branch_name = 'unknown' |
| 18 | +endif |
| 19 | + |
| 20 | +build_time = run_command(['date', '+%Y-%m-%d %H:%M:%S'], check : false) |
| 21 | +if build_time.returncode() == 0 |
| 22 | + build_time = build_time.stdout().strip() |
| 23 | +else |
| 24 | + message('Warning: Build time could not be determined. Using "unknown".') |
| 25 | + build_time = 'unknown' |
| 26 | +endif |
| 27 | + |
| 28 | +git_is_dirty = run_command(['git', 'status', '--porcelain'], check : false) |
| 29 | + if git_is_dirty.returncode() == 0 |
| 30 | + # Command ran successfully. Check if its standard output is empty. |
| 31 | + if git_is_dirty.stdout().strip() == '' |
| 32 | + # Output is empty, meaning the Git repository is clean. |
| 33 | + git_is_dirty = '' |
| 34 | + else |
| 35 | + # Output is NOT empty, meaning there are uncommitted changes (dirty). |
| 36 | + git_is_dirty = '1' |
| 37 | + endif |
| 38 | + else |
| 39 | + message('Warning: Git is not available or not a git repository. Assuming clean.') |
| 40 | + git_is_dirty = '' |
| 41 | +endif |
| 42 | + |
| 43 | +configure_file( |
| 44 | + input : 'version.h.in', |
| 45 | + output : 'version.h', |
| 46 | + configuration : {'GIT_BRANCH_NAME': git_branch_name, 'GIT_CURRENT_SHORT': git_current_short, 'BUILD_TIME': build_time, 'GIT_IS_DIRTY': git_is_dirty} |
| 47 | +) |
3 | 48 | executable('utild', sources, dependencies: [lipc_dep], cpp_args: ['-static-libstdc++'], link_args: ['-static-libstdc++']) |
0 commit comments