Skip to content

Commit

Permalink
Version: implement parsing of version from Git
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidB137 committed Sep 4, 2024
1 parent 55ab342 commit 773a9f4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/kvik/version.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file version.hpp
* @author Dávid Benko ([email protected])
* @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
10 changes: 10 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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}\"")
11 changes: 11 additions & 0 deletions test/tests/version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <catch2/catch_test_macros.hpp>

#include "kvik/version.hpp"
#include "kvik/logger.hpp"

using namespace kvik;

TEST_CASE("Version is not unknown", "[Version]")
{
REQUIRE(VERSION != "unknown");
}

0 comments on commit 773a9f4

Please sign in to comment.