Tue, 28 Jun 2022 11:51:17 +0300
- Add CMake build type to about page and window title
- Use locale-dependant short date format in window title and long format in about page
- Move version definition into project() call
- Renamed the c++ macros to match CMake variable names
CMakeLists.txt | file | annotate | diff | comparison | revisions | |
src/about.ui | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions | |
src/version.cpp | file | annotate | diff | comparison | revisions | |
src/version.h | file | annotate | diff | comparison | revisions | |
widgets/designerplugins.cpp | file | annotate | diff | comparison | revisions |
--- a/CMakeLists.txt Tue Jun 28 11:19:33 2022 +0300 +++ b/CMakeLists.txt Tue Jun 28 11:51:17 2022 +0300 @@ -1,19 +1,8 @@ -project(LDForge) -cmake_minimum_required(VERSION 2.8.12) -set(VERSION_MAJOR 1) -set(VERSION_MINOR 0) -set(VERSION_PATCH 0) +cmake_minimum_required(VERSION 3.0) +project(LDForge VERSION 1.0) set(COPYRIGHT "Copyright (C) 2013 - 2022 Teemu Piippo") -set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") string(TOLOWER ${PROJECT_NAME} TARGET_NAME) -add_definitions(-DVERSION_MAJOR=${VERSION_MAJOR}) -add_definitions(-DVERSION_MINOR=${VERSION_MINOR}) -add_definitions(-DVERSION_PATCH=${VERSION_PATCH}) -add_definitions(-DAPPNAME="${PROJECT_NAME}") -add_definitions(-DVERSION_STRING="${VERSION_STRING}") -add_definitions(-DCOPYRIGHT="${COPYRIGHT}") - set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake") set(OpenGL_GL_PREFERENCE GLVND) find_package(Qt6 COMPONENTS Core Widgets OpenGL UiPlugin OpenGLWidgets) @@ -57,11 +46,18 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override -Wundefined-func-template -Wundefined-reinterpret-cast") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized-const-reference -Wunreachable-code -Wunreachable-code-break -Wunreachable-code-return") endif() -add_definitions(-DCOMPILER_ID="${CMAKE_CXX_COMPILER_ID}") -add_definitions(-DCOMPILER_VERSION="${CMAKE_CXX_COMPILER_VERSION}") -add_definitions(-DCOMPILER_FLAGS="${CMAKE_CXX_FLAGS}") -add_definitions(-DCOMPILER_CPU="${CMAKE_SYSTEM_PROCESSOR}") -add_definitions(-DCOMPILER_SYSTEM="${CMAKE_SYSTEM}") + +# Pass some CMake variables down to the source code +add_definitions(-DCMAKE_PROJECT_NAME="${CMAKE_PROJECT_NAME}") +add_definitions(-DTARGET_NAME="${TARGET_NAME}") +add_definitions(-DCMAKE_PROJECT_VERSION="${CMAKE_PROJECT_VERSION}") +add_definitions(-DCOPYRIGHT="${COPYRIGHT}") +add_definitions(-DCMAKE_CXX_COMPILER_ID="${CMAKE_CXX_COMPILER_ID}") +add_definitions(-DCMAKE_CXX_COMPILER_VERSION="${CMAKE_CXX_COMPILER_VERSION}") +add_definitions(-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}") +add_definitions(-DCMAKE_SYSTEM_PROCESSOR="${CMAKE_SYSTEM_PROCESSOR}") +add_definitions(-DCMAKE_SYSTEM="${CMAKE_SYSTEM}") +add_definitions(-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}") add_subdirectory(widgets)
--- a/src/about.ui Tue Jun 28 11:19:33 2022 +0300 +++ b/src/about.ui Tue Jun 28 11:51:17 2022 +0300 @@ -36,6 +36,7 @@ </style></head><body style=" font-family:'EPSONEXT 丸ã´ã·ãã¯ä½ï¼'; font-size:11pt; font-weight:400; font-style:normal;"> <h1 style=" margin-top:18px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src=":/icons/appicon.png" height="64" /><span style=" font-size:xx-large; font-weight:600;"> %APPNAME% %VERSION%</span></h1> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt version: %QTVERSION%</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Build type: %BUILDTYPE%</p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Compiler: %COMPILER_ID% %COMPILER_VERSION%</p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Compiler system: %COMPILER_SYSTEM% (%COMPILER_CPU%)</p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Compiler flags: %COMPILER_FLAGS%</p></body></html></string>
--- a/src/main.cpp Tue Jun 28 11:19:33 2022 +0300 +++ b/src/main.cpp Tue Jun 28 11:51:17 2022 +0300 @@ -70,7 +70,7 @@ static void doQtRegistrations() { - QCoreApplication::setApplicationName(QStringLiteral(APPNAME)); + QCoreApplication::setApplicationName(QStringLiteral(CMAKE_PROJECT_NAME)); QCoreApplication::setOrganizationName("hecknology.net"); QCoreApplication::setOrganizationDomain("hecknology.net"); qRegisterMetaType<Message>(); @@ -218,12 +218,20 @@ { QMdiSubWindow* subWindow = ui->mdiArea->activeSubWindow(); QString titlestring; + const QString versionString = fullVersionString(QLocale::ShortFormat); if (subWindow != nullptr) { - return QObject::tr("%1 - %2").arg(subWindow->windowTitle(), fullVersionString()); + titlestring = QObject::tr("%1 - %2").arg(subWindow->windowTitle(), versionString); } else { - return fullVersionString(); + titlestring = versionString; } + if (/* DISABLES CODE */ (true) + and std::strcmp(CMAKE_BUILD_TYPE, "Release") != 0 + and std::strcmp(CMAKE_BUILD_TYPE, "MinSizeRel") != 0 + ) { + titlestring += QObject::tr(" [%1]").arg(CMAKE_BUILD_TYPE); + } + return titlestring; } static ColorTable loadColors(const LibrariesModel* libraries) @@ -373,19 +381,20 @@ for (QTextBrowser* browser : dialog.findChildren<QTextBrowser*>()) { browser->setHtml( browser->toHtml() - .replace("%APPNAME%", APPNAME) + .replace("%APPNAME%", CMAKE_PROJECT_NAME) .replace("%COPYRIGHT%", COPYRIGHT) .replace("%QTVERSION%", qVersion()) - .replace("%VERSION%", detailedVersionString()) - .replace("%REVDATE%", revisionDateString()) - .replace("%COMPILER_ID%", COMPILER_ID) - .replace("%COMPILER_VERSION%", COMPILER_VERSION) - .replace("%COMPILER_FLAGS%", COMPILER_FLAGS) - .replace("%COMPILER_CPU%", COMPILER_CPU) - .replace("%COMPILER_SYSTEM%", COMPILER_SYSTEM) + .replace("%VERSION%", detailedVersionString(QLocale::LongFormat)) + .replace("%REVDATE%", revisionDateString(QLocale::LongFormat)) + .replace("%BUILDTYPE%", CMAKE_BUILD_TYPE) + .replace("%COMPILER_ID%", CMAKE_CXX_COMPILER_ID) + .replace("%COMPILER_VERSION%", CMAKE_CXX_COMPILER_VERSION) + .replace("%COMPILER_FLAGS%", CMAKE_CXX_FLAGS) + .replace("%COMPILER_CPU%", CMAKE_SYSTEM_PROCESSOR) + .replace("%COMPILER_SYSTEM%", CMAKE_SYSTEM) ); } - dialog.setWindowTitle(QObject::tr("About %1").arg(APPNAME)); + dialog.setWindowTitle(QObject::tr("About %1").arg(CMAKE_PROJECT_NAME)); dialog.exec(); } @@ -755,7 +764,7 @@ } restoreSettings(); updateRenderPreferences(&ui, &renderPreferences, &documents); - ui.actionAbout->setText(ui.actionAbout->text().arg(APPNAME)); + ui.actionAbout->setText(ui.actionAbout->text().arg(CMAKE_PROJECT_NAME)); updateTitle(); mainWindow.show(); const int result = app.exec();
--- a/src/version.cpp Tue Jun 28 11:19:33 2022 +0300 +++ b/src/version.cpp Tue Jun 28 11:51:17 2022 +0300 @@ -18,6 +18,7 @@ #include <QString> #include <QDateTime> +#include <QLocale> #include <QObject> #include <time.h> #include <hginfo.h> @@ -29,35 +30,35 @@ # define HGTEXT HG_NODE #endif -QString detailedVersionString() +QString detailedVersionString(QLocale::FormatType formatType) { - return QStringLiteral(VERSION_STRING "-" HGTEXT) - + " (" + revisionDateString() + ")"; + return QStringLiteral(CMAKE_PROJECT_VERSION "-" HGTEXT) + + " (" + revisionDateString(formatType) + ")"; } -QString versionString() +QString versionString(QLocale::FormatType formatType) { #ifndef HG_VERSION_TAG - return detailedVersionString(); + return detailedVersionString(formatType); #else return QStringLiteral(HG_VERSION_TAG); #endif } -static QString makeFullVersionString() +static QString makeFullVersionString(QLocale::FormatType formatType) { - QString versionstring = APPNAME " " + versionString(); + QString versionstring = CMAKE_PROJECT_NAME " " + versionString(formatType); return versionstring; } -const QString& fullVersionString() +const QString& fullVersionString(QLocale::FormatType formatType) { - static const QString cached = makeFullVersionString(); + static const QString cached = makeFullVersionString(formatType); return cached; } -QString revisionDateString() +QString revisionDateString(QLocale::FormatType formatType) { const QDateTime dt = QDateTime::fromSecsSinceEpoch(HG_DATE_TIME); - return dt.toString(QObject::tr("d MMM yyyy")); + return QLocale{}.toString(dt.date(), formatType); }
--- a/src/version.h Tue Jun 28 11:19:33 2022 +0300 +++ b/src/version.h Tue Jun 28 11:51:17 2022 +0300 @@ -27,7 +27,7 @@ # undef DEBUG #endif // RELEASE -const QString& fullVersionString(); -QString detailedVersionString(); -QString versionString(); -QString revisionDateString(); +const QString& fullVersionString(QLocale::FormatType formatType); +QString detailedVersionString(QLocale::FormatType formatType); +QString versionString(QLocale::FormatType formatType); +QString revisionDateString(QLocale::FormatType formatType);
--- a/widgets/designerplugins.cpp Tue Jun 28 11:19:33 2022 +0300 +++ b/widgets/designerplugins.cpp Tue Jun 28 11:51:17 2022 +0300 @@ -23,7 +23,7 @@ QString Vec3EditorPlugin::group() const { - return APPNAME; + return CMAKE_PROJECT_NAME; } QString Vec3EditorPlugin::toolTip() const @@ -63,7 +63,7 @@ QString MatrixEditorPlugin::group() const { - return APPNAME; + return CMAKE_PROJECT_NAME; } QString MatrixEditorPlugin::toolTip() const @@ -104,7 +104,7 @@ QString ColorButtonPlugin::group() const { - return APPNAME; + return CMAKE_PROJECT_NAME; } QString ColorButtonPlugin::toolTip() const