14
14
#ifndef CABIN_CABIN_PKG_VERSION
15
15
# error "CABIN_CABIN_PKG_VERSION is not defined"
16
16
#endif
17
+
17
18
#ifndef CABIN_CABIN_COMMIT_SHORT_HASH
18
19
# error "CABIN_CABIN_COMMIT_SHORT_HASH is not defined"
20
+ #else
21
+ # define COMMIT_SHORT_HASH CABIN_CABIN_COMMIT_SHORT_HASH
19
22
#endif
23
+
20
24
#ifndef CABIN_CABIN_COMMIT_HASH
21
25
# error "CABIN_CABIN_COMMIT_HASH is not defined"
26
+ #else
27
+ # define COMMIT_HASH CABIN_CABIN_COMMIT_HASH
22
28
#endif
29
+
23
30
#ifndef CABIN_CABIN_COMMIT_DATE
24
31
# error "CABIN_CABIN_COMMIT_DATE is not defined"
32
+ #else
33
+ # define COMMIT_DATE CABIN_CABIN_COMMIT_DATE
34
+ #endif
35
+
36
+ #if defined(__GNUC__) && !defined(__clang__)
37
+ # define COMPILER_VERSION " GCC " __VERSION__
38
+ #else
39
+ # define COMPILER_VERSION __VERSION__
25
40
#endif
26
41
27
42
const Subcmd VERSION_CMD = //
@@ -30,17 +45,18 @@ const Subcmd VERSION_CMD = //
30
45
.setMainFn(versionMain);
31
46
32
47
static consteval std::string_view
33
- checkAvailability (const std::string_view str) noexcept {
34
- return str.empty () ? " unavailable" : str;
48
+ commitInfo () noexcept {
49
+ if (sizeof (COMMIT_SHORT_HASH) <= 1 && sizeof (COMMIT_DATE) <= 1 ) {
50
+ return " \n " ;
51
+ } else if (sizeof (COMMIT_SHORT_HASH) <= 1 ) {
52
+ return " (" COMMIT_DATE " )\n " ;
53
+ } else if (sizeof (COMMIT_DATE) <= 1 ) {
54
+ return " (" COMMIT_SHORT_HASH " )\n " ;
55
+ } else {
56
+ return " (" COMMIT_SHORT_HASH " " COMMIT_DATE " )\n " ;
57
+ }
35
58
}
36
59
37
- static constinit const std::string_view COMMIT_SHORT_HASH =
38
- checkAvailability (CABIN_CABIN_COMMIT_SHORT_HASH);
39
- static constinit const std::string_view COMMIT_HASH =
40
- checkAvailability (CABIN_CABIN_COMMIT_HASH);
41
- static constinit const std::string_view COMMIT_DATE =
42
- checkAvailability (CABIN_CABIN_COMMIT_DATE);
43
-
44
60
static consteval char
45
61
firstMonthChar (const std::string_view month) noexcept {
46
62
return (month[0 ] == ' O' || month[0 ] == ' N' || month[0 ] == ' D' ) ? ' 1' : ' 0' ;
@@ -128,22 +144,15 @@ versionMain(const std::span<const std::string_view> args) noexcept {
128
144
}
129
145
}
130
146
131
- std::cout << " cabin " << CABIN_CABIN_PKG_VERSION;
132
- if (COMMIT_SHORT_HASH == " unavailable" && COMMIT_DATE == " unavailable" ) {
133
- std::cout << ' \n ' ;
134
- } else if (COMMIT_SHORT_HASH == " unavailable" ) {
135
- std::cout << " (" << COMMIT_DATE << " )\n " ;
136
- } else if (COMMIT_DATE == " unavailable" ) {
137
- std::cout << " (" << COMMIT_SHORT_HASH << " )\n " ;
138
- } else {
139
- std::cout << " (" << COMMIT_SHORT_HASH << ' ' << COMMIT_DATE << " )\n " ;
140
- }
141
-
147
+ std::cout << " cabin " CABIN_CABIN_PKG_VERSION << commitInfo ();
142
148
if (isVerbose ()) {
143
- std::cout << " release: " << CABIN_CABIN_PKG_VERSION << ' \n '
144
- << " commit-hash: " << COMMIT_HASH << ' \n '
145
- << " commit-date: " << COMMIT_DATE << ' \n '
146
- << " compiler: " << __VERSION__ << ' \n '
149
+ std::cout << " release: " CABIN_CABIN_PKG_VERSION
150
+ " \n "
151
+ " commit-hash: " COMMIT_HASH
152
+ " \n "
153
+ " commit-date: " COMMIT_DATE
154
+ " \n "
155
+ " compiler: " COMPILER_VERSION " \n "
147
156
<< " compile-date: " << COMPILE_DATE << ' \n '
148
157
<< " libgit2: " << git2::Version () << ' \n '
149
158
<< " libcurl: " << curl::Version () << ' \n ' ;
0 commit comments