diff --git a/cmake/GitVersion.cmake b/cmake/GitVersion.cmake index 5732ce39..431a7520 100644 --- a/cmake/GitVersion.cmake +++ b/cmake/GitVersion.cmake @@ -13,7 +13,6 @@ execute_process( if (GIT_DESC) string(STRIP ${GIT_DESC} GIT_DESC) - string(REGEX REPLACE "^v([0-9])" "\\1" GIT_DESC ${GIT_DESC}) message(STATUS "Setting version to ${GIT_DESC} from git") else() set(GIT_DESC v${CMAKE_PROJECT_VERSION}) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index fa2db43c..96a2c7b7 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -7,7 +7,6 @@ else() endif() if (GIT_DESC) - string(REGEX REPLACE "^v([0-9])" "\\1" GIT_DESC ${GIT_DESC}) configure_file(version.cpp.in version.cpp) else () add_custom_target(wivrn-version ALL diff --git a/common/version.cpp.in b/common/version.cpp.in index 9cd7a709..06b78254 100644 --- a/common/version.cpp.in +++ b/common/version.cpp.in @@ -17,6 +17,9 @@ * along with this program. If not, see . */ +#include +#include + namespace wivrn { extern const char git_version[]; @@ -24,4 +27,12 @@ namespace wivrn extern const char git_commit[]; const char git_commit[] = "@GIT_COMMIT@"; + +const char* display_version() +{ + if (std::size(git_version) > 2 and git_version[0] == 'v' and isdigit(git_version[1])) + return git_version + 1; + else + return git_version; +} } diff --git a/common/version.h b/common/version.h index 4e33d8ea..77c60887 100644 --- a/common/version.h +++ b/common/version.h @@ -4,4 +4,6 @@ namespace wivrn { extern const char git_version[]; extern const char git_commit[]; + +const char * display_version(); } // namespace wivrn diff --git a/dashboard/apk_installer.cpp b/dashboard/apk_installer.cpp index df2f1568..288574d9 100644 --- a/dashboard/apk_installer.cpp +++ b/dashboard/apk_installer.cpp @@ -42,9 +42,7 @@ bool apk_installer::isTagged() const QString apk_installer::currentVersion() const { - if (wivrn::git_version[0] == 'v') - return &wivrn::git_version[1]; - return wivrn::git_version; + return wivrn::display_version(); } QCoro::Task<> apk_installer::doRefreshLatestVersion() diff --git a/server/main.cpp b/server/main.cpp index fd5e6229..9867dacc 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -354,7 +354,7 @@ void start_publishing() sprintf(protocol_string, "%016" PRIx64, wivrn::protocol_version); std::map TXT = { {"protocol", protocol_string}, - {"version", wivrn::git_version}, + {"version", wivrn::display_version()}, {"cookie", server_cookie()}, }; publisher.emplace(poll_api, hostname(), "_wivrn._tcp", wivrn::default_port, TXT); @@ -889,7 +889,7 @@ auto create_dbus_connection() int inner_main(int argc, char * argv[], bool show_instructions) { - std::cerr << "WiVRn " << wivrn::git_version << " starting" << std::endl; + std::cerr << "WiVRn " << wivrn::display_version() << " starting" << std::endl; if (show_instructions) { if (auto command = steam_command(); not command.empty()) @@ -998,7 +998,7 @@ int main(int argc, char * argv[]) if (*version_flag) { - std::cout << "WiVRn version " << wivrn::git_version << std::endl; + std::cout << "WiVRn version " << wivrn::display_version() << std::endl; return 0; }