From 83df719019ae21379a89dd174d066ffd4da3bb59 Mon Sep 17 00:00:00 2001 From: Christian Heimlich Date: Thu, 2 Nov 2023 03:24:18 -0400 Subject: [PATCH] Add build details to Core --- app/CMakeLists.txt | 18 ++++++++++++++++++ app/src/kernel/buildinfo.h | 19 +++++++++++++++++++ app/src/kernel/core.cpp | 20 +++++++++++++++++++- app/src/kernel/core.h | 4 ++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 app/src/kernel/buildinfo.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 6895803..e4e7aca 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -2,6 +2,7 @@ # Pre-configure target set(CLIFP_SOURCE + kernel/buildinfo.h kernel/core.h kernel/core.cpp kernel/driver.h @@ -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 diff --git a/app/src/kernel/buildinfo.h b/app/src/kernel/buildinfo.h new file mode 100644 index 0000000..c3664ff --- /dev/null +++ b/app/src/kernel/buildinfo.h @@ -0,0 +1,19 @@ +#ifndef BUILDINFO_H +#define BUILDINFO_H + +// Qt Includes +#include +#include + +struct BuildInfo +{ + enum System{Windows, Linux}; + enum Linkage{Static, Shared}; + + System system; + Linkage linkage; + QString compiler; + QVersionNumber compilerVersion; +}; + +#endif // BUILDINFO_H diff --git a/app/src/kernel/core.cpp b/app/src/kernel/core.cpp index b0e2a54..bb6fbff 100644 --- a/app/src/kernel/core.cpp +++ b/app/src/kernel/core.cpp @@ -25,7 +25,7 @@ #include "task/t-awaitdocker.h" #endif #include "utility.h" -#include "project_vars.h" +#include "_buildinfo.h" //=============================================================================================================== // CoreError @@ -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); + static_assert(sysOpt.has_value(), "Configured on unsupported system!"); + + constexpr auto linkOpt = magic_enum::enum_cast(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; +} diff --git a/app/src/kernel/core.h b/app/src/kernel/core.h index 8c4eca3..d59ce9d 100644 --- a/app/src/kernel/core.h +++ b/app/src/kernel/core.h @@ -23,6 +23,7 @@ // Project Includes #include "task/task.h" #include "project_vars.h" +#include "kernel/buildinfo.h" // General Aliases using ErrorCode = quint32; @@ -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);