cmake: explicit GIT_TAG for releases

Tagged versions shouls use GIT_TAG instead of GIT_DESC+GIT_COMMIT
When using GIT_TAG, apk download will be done from WiVRn releases
In other cases, GIT_COMMIT will be used to download from WiVRn-APK
releases.

If none is set, git is used to compute the values
This commit is contained in:
Patrick Nicolas
2026-06-14 17:25:12 +02:00
parent 0f6da3498e
commit 29b1770ba0
8 changed files with 80 additions and 47 deletions
+8 -2
View File
@@ -23,8 +23,13 @@ include(FetchContent)
include(ExternalProject)
include(GNUInstallDirs)
set(GIT_DESC "" CACHE STRING "Version to show in UI (from git if empty)")
set(GIT_COMMIT "" CACHE STRING "Git SHA used to fetch client APK (from git if empty)")
set(GIT_TAG "" CACHE STRING "Build for a tag (from git if empty)")
set(GIT_DESC "" CACHE STRING "Version to show in UI (from git if empty, exclusive with GIT_TAG)")
set(GIT_COMMIT "" CACHE STRING "Git SHA used to fetch client APK (from git if empty, exclusive with GIT_TAG)")
if (GIT_TAG AND (GIT_DESC OR GIT_COMMIT))
message(FATAL_ERROR "cannot use GIT_DESC or GIT_COMMIT when using GIT_TAG")
endif()
option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON)
option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" ON)
@@ -288,6 +293,7 @@ add_custom_target(wivrn-version ALL
-D OUTPUT_FILE=${CMAKE_BINARY_DIR}/version.cpp
-D INPUT_FILE_1=${CMAKE_CURRENT_SOURCE_DIR}/server/u_git_tag.cpp.in
-D OUTPUT_FILE_1=${CMAKE_BINARY_DIR}/u_git_tag.cpp
-D GIT_TAG="${GIT_TAG}"
-D GIT_DESC="${GIT_DESC}"
-D GIT_COMMIT="${GIT_COMMIT}"
-P ${CMAKE_SOURCE_DIR}/cmake/GitVersion.cmake
+1 -1
View File
@@ -95,7 +95,7 @@ void libcurl::curl_thread_fn()
};
#endif
std::string user_agent = std::string("WiVRn/") + wivrn::git_version;
std::string user_agent = std::string("WiVRn/") + wivrn::display_version();
// We can't use auto here because of curl_easy_setopt
size_t (*write_callback)(void *, size_t, size_t, void *) = [](void * buffer, size_t size, size_t nmemb, void * userp) -> size_t {
+44 -22
View File
@@ -1,32 +1,54 @@
if (NOT GIT_DESC)
if (GIT_TAG AND (GIT_DESC OR GIT_COMMIT))
message(FATAL_ERROR "cannot use GIT_DESC or GIT_COMMIT when using GIT_TAG")
endif()
if (NOT (GIT_TAG OR GIT_DESC OR GIT_COMMIT))
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always
OUTPUT_VARIABLE GIT_DESC
COMMAND ${GIT_EXECUTABLE} describe --exact-match --tags
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
string(STRIP "${GIT_DESC}" GIT_DESC)
message(STATUS "Setting version to ${GIT_DESC} from git")
endif()
if (GIT_TAG)
set(GIT_DESC "${GIT_TAG}")
set(GIT_COMMIT "${GIT_TAG}")
set(GIT_TAG true)
message(STATUS "Building for git tag ${GIT_DESC}")
else()
message(STATUS "Setting version to ${GIT_DESC} from parameters")
endif()
if (NOT GIT_DESC)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always
OUTPUT_VARIABLE GIT_DESC
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
message(STATUS "Setting version to ${GIT_DESC} from git")
else()
message(STATUS "Setting version to ${GIT_DESC} from parameters")
endif()
if (NOT GIT_COMMIT)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE GIT_COMMIT
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
string(STRIP "${GIT_COMMIT}" GIT_COMMIT)
endif()
if (NOT GIT_COMMIT)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE GIT_COMMIT
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
string(STRIP "${GIT_COMMIT}" GIT_COMMIT)
endif()
if (NOT GIT_DESC)
message(FATAL_ERROR "GIT_DESC cannot be inferred from .git and was not provided at build time")
endif()
if (NOT GIT_DESC)
message(FATAL_ERROR "GIT_DESC cannot be inferred from .git and was not provided at build time")
endif()
if (GIT_COMMIT)
message(STATUS "Setting commit to ${GIT_COMMIT}")
else()
message(FATAL_ERROR "GIT_COMMIT cannot be inferred from .git and was not provided at build time")
if (GIT_COMMIT)
message(STATUS "Setting commit to ${GIT_COMMIT}")
else()
message(FATAL_ERROR "GIT_COMMIT cannot be inferred from .git and was not provided at build time")
endif()
set(GIT_TAG false)
endif()
configure_file(${INPUT_FILE} ${OUTPUT_FILE})
+12 -9
View File
@@ -20,19 +20,22 @@
#include <cctype>
#include <iterator>
static const char git_desc[] = "@GIT_DESC@";
namespace wivrn
{
extern const char git_version[];
const char git_version[] = "@GIT_DESC@";
extern const char git_commit[];
const char git_commit[] = "@GIT_COMMIT@";
extern const char git_commit[];
const char git_commit[] = "@GIT_COMMIT@";
const char* display_version()
extern const bool is_tag;
const bool is_tag = @GIT_TAG@;
const char * display_version()
{
if (std::size(git_version) > 2 and git_version[0] == 'v' and isdigit(git_version[1]))
return git_version + 1;
if (std::size(git_desc) > 2 and git_desc[0] == 'v' and isdigit(git_desc[1]))
return git_desc + 1;
else
return git_version;
}
return git_desc;
}
} // namespace wivrn
+1 -1
View File
@@ -2,8 +2,8 @@
namespace wivrn
{
extern const char git_version[];
extern const char git_commit[];
extern const bool is_tag;
const char * display_version();
} // namespace wivrn
+3 -7
View File
@@ -23,21 +23,17 @@
#include <QCoroNetworkReply>
#include <QCoroProcess>
#include <nlohmann/json.hpp>
#include <regex>
using namespace std::chrono_literals;
apk_installer::apk_installer()
{
if (isTagged())
m_apkFile.setFileName(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/wivrn-" + QString::fromStdString(wivrn::git_version) + ".apk");
else
m_apkFile.setFileName(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/wivrn-" + QString::fromStdString(wivrn::git_commit) + ".apk");
m_apkFile.setFileName(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/wivrn-" + QString::fromStdString(wivrn::git_commit) + ".apk");
}
bool apk_installer::isTagged() const
{
return not std::regex_match(wivrn::git_version, std::regex(".*-g[0-9a-f]+"));
return wivrn::is_tag;
}
QString apk_installer::currentVersion() const
@@ -74,7 +70,7 @@ QCoro::Task<> apk_installer::doRefreshLatestVersion()
QUrl metadata_url;
if (isTagged())
metadata_url = QString{"https://api.github.com/repos/WiVRn/WiVRn/releases/tags/"} + wivrn::git_version;
metadata_url = QString{"https://api.github.com/repos/WiVRn/WiVRn/releases/tags/"} + wivrn::git_commit;
else
metadata_url = QString{"https://api.github.com/repos/WiVRn/WiVRn-APK/releases/tags/apk-"} + wivrn::git_commit;
+2
View File
@@ -349,6 +349,7 @@ modules:
- -DWIVRN_WERROR=ON
- -DFETCHCONTENT_FULLY_DISCONNECTED=ON
- -DFETCHCONTENT_BASE_DIR=deps
- -DGIT_TAG=WIVRN_GIT_TAG
- -DGIT_DESC=WIVRN_GIT_DESC
- -DGIT_COMMIT=WIVRN_GIT_COMMIT
- -Wno-dev
@@ -385,6 +386,7 @@ modules:
- -DWIVRN_FEATURE_STEAMVR_LIGHTHOUSE=OFF
- -DFETCHCONTENT_FULLY_DISCONNECTED=ON
- -DFETCHCONTENT_BASE_DIR=deps
- -DGIT_TAG=WIVRN_GIT_TAG
- -DGIT_DESC=WIVRN_GIT_DESC
- -DGIT_COMMIT=WIVRN_GIT_COMMIT
- -Wno-dev
+9 -5
View File
@@ -63,20 +63,23 @@ if __name__ == "__main__":
boost_sha256 = cmake.get("boost", "URL_HASH").split("=")[-1]
try:
git_commit = subprocess.check_output(
git_tag = subprocess.check_output(
["git", "describe", "--exact-match", "--tags"],
cwd=root,
stderr=subprocess.DEVNULL
).decode().strip()
git_commit = ""
git_desc = ""
except subprocess.CalledProcessError:
git_tag = ""
git_commit = subprocess.check_output(
["git", "rev-parse", "HEAD"],
cwd=root
).decode().strip()
git_desc = subprocess.check_output(
["git", "describe", "--tags", "--always"],
cwd=root
).decode().strip()
git_desc = subprocess.check_output(
["git", "describe", "--tags", "--always"],
cwd=root
).decode().strip()
if args.git or args.gitlocal:
template = template.replace("WIVRN_SRC1", "type: git")
@@ -90,6 +93,7 @@ if __name__ == "__main__":
template = template.replace("WIVRN_SRC2", f"path: {root}")
template = template.replace("WIVRN_SRC3", "")
template = template.replace("WIVRN_GIT_TAG", git_tag)
template = template.replace("WIVRN_GIT_DESC", git_desc)
template = template.replace("WIVRN_GIT_COMMIT", git_commit)