build: add git revision to version

This commit is contained in:
outfoxxed 2024-03-08 23:08:50 -08:00
parent 73fd022b1e
commit b720dfa165
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 24 additions and 3 deletions

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
project(quickshell VERSION "0.0.1") project(quickshell VERSION "0.1.0")
set(QT_MIN_VERSION "6.6.0") set(QT_MIN_VERSION "6.6.0")
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
@ -21,6 +21,14 @@ if (WAYLAND)
message(STATUS " Session Lock: ${WAYLAND_SESSION_LOCK}") message(STATUS " Session Lock: ${WAYLAND_SESSION_LOCK}")
endif () endif ()
if (NOT DEFINED GIT_REVISION)
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REVISION
)
endif()
add_compile_options(-Wall -Wextra) add_compile_options(-Wall -Wextra)
# nix workaround # nix workaround

View file

@ -11,6 +11,16 @@
wayland, wayland,
wayland-protocols, wayland-protocols,
gitRev ? (let
headExists = builtins.pathExists ./.git/HEAD;
headContent = builtins.readFile ./.git/HEAD;
in if headExists
then (let
matches = builtins.match "ref: refs/heads/(.*)\n" headContent;
in if matches != null
then builtins.readFile ./.git/refs/heads/${builtins.elemAt matches 0}
else headContent)
else "unknown"),
debug ? false, debug ? false,
enableWayland ? true, enableWayland ? true,
}: stdenv.mkDerivation { }: stdenv.mkDerivation {
@ -44,7 +54,9 @@
cmakeConfigurePhase cmakeConfigurePhase
''; '';
cmakeFlags = lib.optional (!enableWayland) "-DWAYLAND=OFF"; cmakeFlags = [
"-DGIT_REVISION=${gitRev}"
] ++ lib.optional (!enableWayland) "-DWAYLAND=OFF";
buildPhase = "ninjaBuildPhase"; buildPhase = "ninjaBuildPhase";
enableParallelBuilding = true; enableParallelBuilding = true;

View file

@ -17,6 +17,7 @@ qt_add_executable(quickshell
panelinterface.cpp panelinterface.cpp
) )
set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS GIT_REVISION="${GIT_REVISION}")
qt_add_qml_module(quickshell URI Quickshell VERSION 0.1) qt_add_qml_module(quickshell URI Quickshell VERSION 0.1)
target_link_libraries(quickshell PRIVATE ${QT_DEPS}) target_link_libraries(quickshell PRIVATE ${QT_DEPS})

View file

@ -20,7 +20,7 @@
int main(int argc, char** argv) { int main(int argc, char** argv) {
const auto app = QGuiApplication(argc, argv); const auto app = QGuiApplication(argc, argv);
QGuiApplication::setApplicationName("quickshell"); QGuiApplication::setApplicationName("quickshell");
QGuiApplication::setApplicationVersion("0.1.0"); QGuiApplication::setApplicationVersion("0.1.0 (" GIT_REVISION ")");
QCommandLineParser parser; QCommandLineParser parser;
parser.addHelpOption(); parser.addHelpOption();