Skip to content

Commit

Permalink
Merge pull request #73 from oblivioncth/build_details
Browse files Browse the repository at this point in the history
Add build details to Core
  • Loading branch information
oblivioncth authored Nov 2, 2023
2 parents 121f299 + 83df719 commit eee5b4f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
18 changes: 18 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Pre-configure target
set(CLIFP_SOURCE
kernel/buildinfo.h
kernel/core.h
kernel/core.cpp
kernel/driver.h
Expand Down Expand Up @@ -132,6 +133,23 @@ ob_add_cpp_vars(${APP_TARGET_NAME}
APP_NAME "\"${PROJECT_FORMAL_NAME}\""
)

## Add build info
if(BUILD_SHARED_LIBS)
set(link_str "Shared")
else()
set(link_str "Static")
endif()

ob_add_cpp_vars(${APP_TARGET_NAME}
NAME "_buildinfo"
PREFIX "BUILDINFO_"
VARS
SYSTEM "\"${CMAKE_SYSTEM_NAME}\""
LINKAGE "\"${link_str}\""
COMPILER "u\"${CMAKE_CXX_COMPILER_ID}\"_s"
COMPILER_VER_STR "u\"${CMAKE_CXX_COMPILER_VERSION}\"_s"
)

## Add exe details on Windows
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
# Set target exe details
Expand Down
19 changes: 19 additions & 0 deletions app/src/kernel/buildinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef BUILDINFO_H
#define BUILDINFO_H

// Qt Includes
#include <QString>
#include <QVersionNumber>

struct BuildInfo
{
enum System{Windows, Linux};
enum Linkage{Static, Shared};

System system;
Linkage linkage;
QString compiler;
QVersionNumber compilerVersion;
};

#endif // BUILDINFO_H
20 changes: 19 additions & 1 deletion app/src/kernel/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "task/t-awaitdocker.h"
#endif
#include "utility.h"
#include "project_vars.h"
#include "_buildinfo.h"

//===============================================================================================================
// CoreError
Expand Down Expand Up @@ -869,3 +869,21 @@ void Core::setStatus(QString heading, QString message)
mStatusMessage = message;
emit statusChanged(heading, message);
}

BuildInfo Core::buildInfo() const
{
constexpr auto sysOpt = magic_enum::enum_cast<BuildInfo::System>(BUILDINFO_SYSTEM);
static_assert(sysOpt.has_value(), "Configured on unsupported system!");

constexpr auto linkOpt = magic_enum::enum_cast<BuildInfo::Linkage>(BUILDINFO_LINKAGE);
static_assert(linkOpt.has_value(), "Invalid BuildInfo linkage string!");

static BuildInfo info{
.system = sysOpt.value(),
.linkage = linkOpt.value(),
.compiler = BUILDINFO_COMPILER,
.compilerVersion = QVersionNumber::fromString(BUILDINFO_COMPILER_VER_STR)
};

return info;
}
4 changes: 4 additions & 0 deletions app/src/kernel/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// Project Includes
#include "task/task.h"
#include "project_vars.h"
#include "kernel/buildinfo.h"

// General Aliases
using ErrorCode = quint32;
Expand Down Expand Up @@ -307,6 +308,9 @@ class Core : public QObject
QString statusMessage();
void setStatus(QString heading, QString message);

// Other
BuildInfo buildInfo() const;

//-Signals & Slots------------------------------------------------------------------------------------------------------------
signals:
void statusChanged(const QString& statusHeading, const QString& statusMessage);
Expand Down

0 comments on commit eee5b4f

Please sign in to comment.