From 4a83eb711f8b40f37633177f513e1323f3d0349d Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Tue, 26 Nov 2024 22:16:34 -0500 Subject: [PATCH] build: generate version info, use it for all sources of version --- CMakeLists.txt | 2 -- cmake/Definitions.cmake | 1 - cmake/Libraries.cmake | 1 - src/gui/CMakeLists.txt | 6 ++--- src/gui/src/MainWindow.cpp | 4 +-- src/gui/src/dialogs/AboutDialog.cpp | 12 +++++---- src/gui/src/main.cpp | 4 +-- src/lib/common/CMakeLists.txt | 11 +++----- src/lib/common/constants.h | 40 ----------------------------- src/lib/common/constants.h.in | 19 ++++++++++++++ src/lib/common/version.h | 38 --------------------------- src/lib/config.h.in | 4 --- src/lib/deskflow/App.cpp | 5 +--- src/lib/gui/VersionChecker.cpp | 2 +- src/lib/gui/messages.cpp | 4 +-- 15 files changed, 39 insertions(+), 114 deletions(-) delete mode 100644 src/lib/common/constants.h create mode 100644 src/lib/common/constants.h.in delete mode 100644 src/lib/common/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 295722ad7..4a4b2e929 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,8 +64,6 @@ set(DESKFLOW_VERSION_MS_CSV "${DESKFLOW_VERSION_MAJOR},${DESKFLOW_VERSION_MINOR},${DESKFLOW_VERSION_PATCH},${DESKFLOW_VERSION_TWEAK}" ) -add_definitions(-DDESKFLOW_VERSION="${DESKFLOW_VERSION}") - #Define our project project( deskflow diff --git a/cmake/Definitions.cmake b/cmake/Definitions.cmake index 5eb8d9192..de8106d63 100644 --- a/cmake/Definitions.cmake +++ b/cmake/Definitions.cmake @@ -26,7 +26,6 @@ macro(configure_definitions) # Shorten the Git SHA to 8 chars for readability string(SUBSTRING "$ENV{GIT_SHA}" 0 8 GIT_SHA_SHORT) message(STATUS "Short Git SHA: ${GIT_SHA_SHORT}") - add_definitions(-DGIT_SHA_SHORT="${GIT_SHA_SHORT}") endif() if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/cmake/Libraries.cmake b/cmake/Libraries.cmake index 3c8b5ff0f..40aa0f328 100644 --- a/cmake/Libraries.cmake +++ b/cmake/Libraries.cmake @@ -335,7 +335,6 @@ macro(configure_windows_libs) /DWIN32 /D_WINDOWS /D_CRT_SECURE_NO_WARNINGS - /DDESKFLOW_VERSION=\"${DESKFLOW_VERSION}\" /D_XKEYCHECK_H) configure_openssl() diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 45a9d2e39..f3a023ee0 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -73,9 +73,9 @@ elseif(APPLE) MACOSX_BUNDLE_ICON_FILE Deskflow.icns MACOSX_BUNDLE_INFO_STRING "${CMAKE_PROJECT_DESCRIPTION}" MACOSX_BUNDLE_COPYRIGHT "© 2024 Deskflow Developers" - MACOSX_BUNDLE_BUNDLE_VERSION ${DESKFLOW_VERSION} - MACOSX_BUNDLE_LONG_VERSION_STRING ${DESKFLOW_VERSION} - MACOSX_BUNDLE_SHORT_VERSION_STRING ${DESKFLOW_VERSION} + MACOSX_BUNDLE_BUNDLE_VERSION ${CMAKE_PROJECT_VERSION} + MACOSX_BUNDLE_LONG_VERSION_STRING ${CMAKE_PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${CMAKE_PROJECT_VERSION} ) find_program(MACDEPLOYQT_BIN macdeployqt6) add_custom_command( diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 3ce7cffe5..8d535fba1 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -155,8 +155,8 @@ void MainWindow::setupControls() ui->m_pLabelIpAddresses->setText(QString("This computer's IP addresses: %1").arg(getIPAddresses())); - if (m_AppConfig.lastVersion() != DESKFLOW_VERSION) { - m_AppConfig.setLastVersion(DESKFLOW_VERSION); + if (m_AppConfig.lastVersion() != kVersion) { + m_AppConfig.setLastVersion(kVersion); } #if defined(Q_OS_MAC) diff --git a/src/gui/src/dialogs/AboutDialog.cpp b/src/gui/src/dialogs/AboutDialog.cpp index a6eadf639..ee4a60add 100644 --- a/src/gui/src/dialogs/AboutDialog.cpp +++ b/src/gui/src/dialogs/AboutDialog.cpp @@ -19,8 +19,8 @@ #include "AboutDialog.h" +#include "common/constants.h" #include "common/copyright.h" -#include "common/version.h" #include "gui/style_utils.h" #include @@ -34,19 +34,21 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent) { setWindowTitle(tr("About Deskflow")); - QString version = QString::fromStdString(deskflow::version()); - auto copyIcon = QIcon::fromTheme( QIcon::ThemeIcon::EditCopy, deskflow::gui::isDarkMode() ? QIcon(s_darkCopy) : QIcon(s_lightCopy) ); auto btnCopyVersion = new QPushButton(copyIcon, QString(), this); btnCopyVersion->setFlat(true); - connect(btnCopyVersion, &QPushButton::clicked, this, [version] { qApp->clipboard()->setText(version); }); + connect(btnCopyVersion, &QPushButton::clicked, this, [] { QGuiApplication::clipboard()->setText(kVersion); }); + + auto versionString = QString(kVersion); + if (!QString(kVersionGitSha).isEmpty()) + versionString.append(QStringLiteral(" (%1)").arg(kVersionGitSha)); auto versionLayout = new QHBoxLayout(); versionLayout->addWidget(new QLabel(tr("Version:"))); - versionLayout->addWidget(new QLabel(version)); + versionLayout->addWidget(new QLabel(versionString, this)); versionLayout->addWidget(btnCopyVersion); versionLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed)); diff --git a/src/gui/src/main.cpp b/src/gui/src/main.cpp index 7f7f367ea..d89ade836 100644 --- a/src/gui/src/main.cpp +++ b/src/gui/src/main.cpp @@ -19,7 +19,6 @@ #include "MainWindow.h" #include "SetupWizard.h" #include "common/constants.h" -#include "common/version.h" #include "gui/Logger.h" #include "gui/config/AppConfig.h" #include "gui/config/ConfigScopes.h" @@ -92,8 +91,7 @@ int main(int argc, char *argv[]) #endif qInstallMessageHandler(deskflow::gui::messages::messageHandler); - QString version = QString::fromStdString(deskflow::version()); - qInfo("%s v%s", kAppName, qPrintable(version)); + qInfo("%s v%s", kAppName, qPrintable(kVersion)); dotenv(); Logger::instance().loadEnvVars(); diff --git a/src/lib/common/CMakeLists.txt b/src/lib/common/CMakeLists.txt index 2dc4e85dc..d521ef02f 100644 --- a/src/lib/common/CMakeLists.txt +++ b/src/lib/common/CMakeLists.txt @@ -1,11 +1,13 @@ # SPDX-FileCopyrightText: (C) 2024 Chris Rizzitello # SPDX-License-Identifier: MIT +set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) + +configure_file(constants.h.in constants.h @ONLY) add_library(common INTERFACE basic_types.h common.h - constants.h copyright.h IInterface.h ipc.h @@ -23,15 +25,10 @@ add_library(common INTERFACE stdsstream.h stdstring.h stdvector.h - version.h + ${CMAKE_CURRENT_BINARY_DIR}/constants.h ) if(APPLE) target_sources(common INTERFACE MacOSXPrecomp.h) endif() -target_include_directories(common - INTERFACE - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} -) diff --git a/src/lib/common/constants.h b/src/lib/common/constants.h deleted file mode 100644 index eefce2826..000000000 --- a/src/lib/common/constants.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * Copyright (C) 2012 Symless Ltd. - * Copyright (C) 2002 Chris Schoeneman - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#if !defined(DESKFLOW_VERSION) -#error version was not passed to the compiler -#endif - -const auto kAppName = "Deskflow"; -const auto kAppId = "deskflow"; -const auto kAppDescription = "Mouse and keyboard sharing utility"; -const auto kVersion = DESKFLOW_VERSION; - -#ifdef GIT_SHA_SHORT -const auto kVersionGitSha = GIT_SHA_SHORT; -#else -const auto kVersionGitSha = ""; -#endif - -#ifndef NDEBUG -const auto kDebugBuild = true; -#else -const auto kDebugBuild = false; -#endif diff --git a/src/lib/common/constants.h.in b/src/lib/common/constants.h.in new file mode 100644 index 000000000..cdf773156 --- /dev/null +++ b/src/lib/common/constants.h.in @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: (C) 2024 Chris Rizzitello +// SPDX-FileCopyrightText: (C) 2012 Symless Ltd. +// SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman +// SPDX-License-Identifier: GPL-2.0-only + + +#pragma once + +const auto kAppName = "Deskflow"; +const auto kAppId = "deskflow"; +const auto kAppDescription = "@CMAKE_PROJECT_DESCRIPTION@"; +const auto kVersion = "@CMAKE_PROJECT_VERSION@"; +const auto kVersionGitSha = "@GIT_SHA_SHORT@"; + +#ifndef NDEBUG +const auto kDebugBuild = true; +#else +const auto kDebugBuild = false; +#endif diff --git a/src/lib/common/version.h b/src/lib/common/version.h deleted file mode 100644 index 9e718ccfd..000000000 --- a/src/lib/common/version.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * Copyright (C) 2024 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "constants.h" - -#include - -namespace deskflow { - -inline std::string version() -{ - std::string result = kVersion; - std::string gitSha = kVersionGitSha; - if (!gitSha.empty()) { - result.append(" ("); - result.append(gitSha); - result.append(")"); - } - return result; -} - -} // namespace deskflow diff --git a/src/lib/config.h.in b/src/lib/config.h.in index c14d04897..aae31281a 100644 --- a/src/lib/config.h.in +++ b/src/lib/config.h.in @@ -16,10 +16,6 @@ */ // clang-format off - -/* Define version here for Unix, but using /D for Windows. */ -#cmakedefine DESKFLOW_VERSION "@DESKFLOW_VERSION@" - /* Define to the base type of arg 3 for `accept`. */ #cmakedefine ACCEPT_TYPE_ARG3 @ACCEPT_TYPE_ARG3@ diff --git a/src/lib/deskflow/App.cpp b/src/lib/deskflow/App.cpp index 24775749e..1e284417a 100644 --- a/src/lib/deskflow/App.cpp +++ b/src/lib/deskflow/App.cpp @@ -29,7 +29,6 @@ #include "common/constants.h" #include "common/copyright.h" #include "common/ipc.h" -#include "common/version.h" #include "deskflow/ArgsBase.h" #include "deskflow/Config.h" #include "deskflow/XDeskflow.h" @@ -93,13 +92,11 @@ App::~App() void App::version() { - const auto version = deskflow::version(); - const auto kBufferLength = 1024; std::vector buffer(kBufferLength); std::snprintf( // NOSONAR buffer.data(), kBufferLength, "%s v%s, protocol v%d.%d\n%s", // - argsBase().m_pname, version.c_str(), kProtocolMajorVersion, kProtocolMinorVersion, deskflow::kCopyright + argsBase().m_pname, kVersion, kProtocolMajorVersion, kProtocolMinorVersion, deskflow::kCopyright ); std::cout << std::string(buffer.data()) << std::endl; diff --git a/src/lib/gui/VersionChecker.cpp b/src/lib/gui/VersionChecker.cpp index bc06b341d..fc1257f38 100644 --- a/src/lib/gui/VersionChecker.cpp +++ b/src/lib/gui/VersionChecker.cpp @@ -63,7 +63,7 @@ void VersionChecker::replyFinished(QNetworkReply *reply) const auto newestVersion = QString(reply->readAll()); qDebug("version check response: %s", qPrintable(newestVersion)); - if (!newestVersion.isEmpty() && compareVersions(DESKFLOW_VERSION, newestVersion) > 0) { + if (!newestVersion.isEmpty() && compareVersions(kVersion, newestVersion) > 0) { qDebug("update found"); Q_EMIT updateFound(newestVersion); } else { diff --git a/src/lib/gui/messages.cpp b/src/lib/gui/messages.cpp index 381c365eb..4b16488be 100644 --- a/src/lib/gui/messages.cpp +++ b/src/lib/gui/messages.cpp @@ -19,7 +19,6 @@ #include "Logger.h" #include "common/constants.h" -#include "common/version.h" #include "constants.h" #include "env_vars.h" #include "styles.h" @@ -66,8 +65,7 @@ void showErrorDialog(const QString &message, const QString &fileLine, QtMsgType " and copy/paste the following error:

") .arg(kUrlHelp, kColorSecondary); - const QString version = QString::fromStdString(deskflow::version()); - text += QString("
v%1\n%2\n%3
").arg(version, message, fileLine); + text += QString("
v%1\n%2\n%3
").arg(kVersion, message, fileLine); if (type == QtFatalMsg) { // create a blocking message box for fatal errors, as we want to wait