From 7ec346b5a595e4bd77e3bac39ca2bf832caac7e9 Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Fri, 3 Oct 2025 11:15:06 +0200 Subject: [PATCH] Retrieving core name and version from CMakeLists.txt and use it in GenericCore::toString(). --- CMakeLists.txt | 4 ++++ CoreConfig.h.in | 2 ++ genericcore.cpp | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 CoreConfig.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 2305309..593c663 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core LinguistTools) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core LinguistTools) +configure_file(CoreConfig.h.in CoreConfig.h) + set(TS_FILES ${TARGET_APP}_en_US.ts) add_library(${TARGET_APP} STATIC @@ -20,6 +22,8 @@ add_library(${TARGET_APP} STATIC ${TS_FILES} ) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + target_link_libraries(${TARGET_APP} PRIVATE Qt${QT_VERSION_MAJOR}::Core) target_compile_definitions(${TARGET_APP} PRIVATE ${TARGET_APP}_LIBRARY) diff --git a/CoreConfig.h.in b/CoreConfig.h.in new file mode 100644 index 0000000..89c634a --- /dev/null +++ b/CoreConfig.h.in @@ -0,0 +1,2 @@ +#define CORE_NAME "${PROJECT_NAME}" +#define CORE_VERSION "${PROJECT_VERSION}" diff --git a/genericcore.cpp b/genericcore.cpp index 9e17aaa..f296c21 100644 --- a/genericcore.cpp +++ b/genericcore.cpp @@ -3,12 +3,16 @@ #include #include +#include "CoreConfig.h" + using namespace std; GenericCore::GenericCore() { qDebug() << "Creating core..."; } GenericCore::~GenericCore() { qDebug() << "Destroying core..."; } -QString GenericCore::toString() const { return QString("GenericCore (Version x.y.z)"); } +QString GenericCore::toString() const { + return QString("%1 (Version %2)").arg(CORE_NAME).arg(CORE_VERSION); +} void GenericCore::sayHello() const { qDebug() << "Hello from the core!"; }