From 773a9f494836421fe45ac0e1fc1b5513e11c0a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Benko?= Date: Wed, 4 Sep 2024 19:52:49 +0200 Subject: [PATCH] Version: implement parsing of version from Git --- include/kvik/version.hpp | 22 ++++++++++++++++++++++ test/CMakeLists.txt | 10 ++++++++++ test/tests/version.cpp | 11 +++++++++++ 3 files changed, 43 insertions(+) create mode 100644 include/kvik/version.hpp create mode 100644 test/tests/version.cpp diff --git a/include/kvik/version.hpp b/include/kvik/version.hpp new file mode 100644 index 0000000..43fad55 --- /dev/null +++ b/include/kvik/version.hpp @@ -0,0 +1,22 @@ +/** + * @file version.hpp + * @author Dávid Benko (davidbenko@davidbenko.dev) + * @brief Current version of Kvik + * + * @copyright Copyright (c) 2024 + * + */ + +#pragma once + +namespace kvik +{ + /** + * @brief Version of Kvik + */ +#ifdef GIT_VERSION + constexpr const char* const VERSION = GIT_VERSION; +#else + constexpr const char* const VERSION = "unknown"; +#endif +} // namespace kvik diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7c8e7a1..8ad985d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,12 +9,21 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(Catch2) +# Parse version from git +execute_process( + COMMAND git describe --all --tags --dirty + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE +) + include_directories( "../include" "../priv_include" ) file(GLOB srcs CONFIGURE_DEPENDS "../src/common/*.cpp" + "../src/linux/logger.cpp" "../src/testing/*.cpp" "tests/*.cpp" ) @@ -26,3 +35,4 @@ set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) target_link_libraries(kvik_test PRIVATE Threads::Threads) target_link_libraries(kvik_test PRIVATE Catch2::Catch2WithMain) +target_compile_definitions(kvik_test PRIVATE "-DGIT_VERSION=\"${GIT_VERSION}\"") diff --git a/test/tests/version.cpp b/test/tests/version.cpp new file mode 100644 index 0000000..7858c28 --- /dev/null +++ b/test/tests/version.cpp @@ -0,0 +1,11 @@ +#include + +#include "kvik/version.hpp" +#include "kvik/logger.hpp" + +using namespace kvik; + +TEST_CASE("Version is not unknown", "[Version]") +{ + REQUIRE(VERSION != "unknown"); +}