From 9d2175180e1dafeecefef5d7870376c199107b6c Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Mon, 7 Apr 2025 02:22:51 -0700 Subject: [PATCH] build: Move versioning to CMake file. (#2752) --- CMakeLists.txt | 7 ++++--- src/common/config.cpp | 10 +++++----- src/common/scm_rev.cpp.in | 22 +++++++++------------- src/common/scm_rev.h | 3 +++ src/common/version.h | 14 -------------- src/emulator.cpp | 11 +++++------ src/input/input_handler.cpp | 1 - src/qt_gui/check_update.cpp | 5 ++--- src/qt_gui/gui_context_menus.h | 6 +++--- src/qt_gui/main_window.cpp | 9 ++++----- src/qt_gui/settings_dialog.cpp | 4 ++-- src/sdl_window.cpp | 1 - 12 files changed, 37 insertions(+), 56 deletions(-) delete mode 100644 src/common/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2af30ed46..844553340 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,6 +202,8 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) +set(APP_VERSION "0.7.1 WIP") +set(APP_IS_RELEASE false) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/common/scm_rev.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/src/common/scm_rev.cpp" @ONLY) message("end git things, remote: ${GIT_REMOTE_NAME}, branch: ${GIT_BRANCH}") @@ -671,7 +673,6 @@ set(COMMON src/common/logging/backend.cpp src/common/uint128.h src/common/unique_function.h src/common/va_ctx.h - src/common/version.h src/common/ntapi.h src/common/ntapi.cpp src/common/number_utils.h @@ -1193,8 +1194,8 @@ if (ENABLE_QT_GUI) MACOSX_BUNDLE ON MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/dist/MacOSBundleInfo.plist.in" MACOSX_BUNDLE_ICON_FILE "shadPS4.icns" - MACOSX_BUNDLE_SHORT_VERSION_STRING "0.4.1" - ) + MACOSX_BUNDLE_SHORT_VERSION_STRING "${APP_VERSION}" + ) set_source_files_properties(src/images/shadPS4.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources) diff --git a/src/common/config.cpp b/src/common/config.cpp index 2657cd12a..111c0cfa9 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -7,10 +7,10 @@ #include // for wstring support #include +#include "common/config.h" +#include "common/logging/formatter.h" #include "common/path_util.h" -#include "config.h" -#include "logging/formatter.h" -#include "version.h" +#include "common/scm_rev.h" namespace toml { template @@ -763,7 +763,7 @@ void load(const std::filesystem::path& path) { logFilter = toml::find_or(general, "logFilter", ""); logType = toml::find_or(general, "logType", "sync"); userName = toml::find_or(general, "userName", "shadPS4"); - if (Common::isRelease) { + if (Common::g_is_release) { updateChannel = toml::find_or(general, "updateChannel", "Release"); } else { updateChannel = toml::find_or(general, "updateChannel", "Nightly"); @@ -1108,7 +1108,7 @@ void setDefaultValues() { logFilter = ""; logType = "sync"; userName = "shadPS4"; - if (Common::isRelease) { + if (Common::g_is_release) { updateChannel = "Release"; } else { updateChannel = "Nightly"; diff --git a/src/common/scm_rev.cpp.in b/src/common/scm_rev.cpp.in index 2de04e0be..71c4c2d0a 100644 --- a/src/common/scm_rev.cpp.in +++ b/src/common/scm_rev.cpp.in @@ -3,21 +3,17 @@ #include "common/scm_rev.h" -#define GIT_REV "@GIT_REV@" -#define GIT_BRANCH "@GIT_BRANCH@" -#define GIT_DESC "@GIT_DESC@" -#define GIT_REMOTE_NAME "@GIT_REMOTE_NAME@" -#define GIT_REMOTE_URL "@GIT_REMOTE_URL@" -#define BUILD_DATE "@BUILD_DATE@" - namespace Common { -const char g_scm_rev[] = GIT_REV; -const char g_scm_branch[] = GIT_BRANCH; -const char g_scm_desc[] = GIT_DESC; -const char g_scm_remote_name[] = GIT_REMOTE_NAME; -const char g_scm_remote_url[] = GIT_REMOTE_URL; -const char g_scm_date[] = BUILD_DATE; +constexpr char g_version[] = "@APP_VERSION@"; +constexpr bool g_is_release = @APP_IS_RELEASE@; + +constexpr char g_scm_rev[] = "@GIT_REV@"; +constexpr char g_scm_branch[] = "@GIT_BRANCH@"; +constexpr char g_scm_desc[] = "@GIT_DESC@"; +constexpr char g_scm_remote_name[] = "@GIT_REMOTE_NAME@"; +constexpr char g_scm_remote_url[] = "@GIT_REMOTE_URL@"; +constexpr char g_scm_date[] = "@BUILD_DATE@"; } // namespace diff --git a/src/common/scm_rev.h b/src/common/scm_rev.h index f38efff42..36b844e94 100644 --- a/src/common/scm_rev.h +++ b/src/common/scm_rev.h @@ -5,6 +5,9 @@ namespace Common { +extern const char g_version[]; +extern const bool g_is_release; + extern const char g_scm_rev[]; extern const char g_scm_branch[]; extern const char g_scm_desc[]; diff --git a/src/common/version.h b/src/common/version.h deleted file mode 100644 index 652f36e6d..000000000 --- a/src/common/version.h +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include -#include - -namespace Common { - -constexpr char VERSION[] = "0.7.1 WIP"; -constexpr bool isRelease = false; - -} // namespace Common diff --git a/src/emulator.cpp b/src/emulator.cpp index 5f94f008a..1a71b99cb 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -22,7 +22,6 @@ #include "common/polyfill_thread.h" #include "common/scm_rev.h" #include "common/singleton.h" -#include "common/version.h" #include "core/file_format/psf.h" #include "core/file_format/trp.h" #include "core/file_sys/fs.h" @@ -123,7 +122,7 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector", id, title, app_version); std::string window_title = ""; - if (Common::isRelease) { - window_title = fmt::format("shadPS4 v{} | {}", Common::VERSION, game_title); + if (Common::g_is_release) { + window_title = fmt::format("shadPS4 v{} | {}", Common::g_version, game_title); } else { std::string remote_url(Common::g_scm_remote_url); std::string remote_host; @@ -208,10 +207,10 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector #include #include -#include #include "check_update.h" using namespace Common::FS; @@ -52,7 +51,7 @@ void CheckUpdate::CheckForUpdates(const bool showMessage) { url = QUrl("https://api.github.com/repos/shadps4-emu/shadPS4/releases/latest"); checkName = false; } else { - if (Common::isRelease) { + if (Common::g_is_release) { Config::setUpdateChannel("Release"); } else { Config::setUpdateChannel("Nightly"); @@ -162,7 +161,7 @@ tr("The Auto Updater allows up to 60 update checks per hour.\\nYou have reached QString currentRev = (updateChannel == "Nightly") ? QString::fromStdString(Common::g_scm_rev) - : "v." + QString::fromStdString(Common::VERSION); + : "v." + QString::fromStdString(Common::g_version); QString currentDate = Common::g_scm_date; QDateTime dateTime = QDateTime::fromString(latestDate, Qt::ISODate); diff --git a/src/qt_gui/gui_context_menus.h b/src/qt_gui/gui_context_menus.h index b5732d0ca..0aff80ccc 100644 --- a/src/qt_gui/gui_context_menus.h +++ b/src/qt_gui/gui_context_menus.h @@ -13,7 +13,7 @@ #include "cheats_patches.h" #include "common/config.h" #include "common/path_util.h" -#include "common/version.h" +#include "common/scm_rev.h" #include "compatibility_info.h" #include "game_info.h" #include "trophy_viewer.h" @@ -115,7 +115,7 @@ public: compatibilityMenu->addAction(updateCompatibility); compatibilityMenu->addAction(viewCompatibilityReport); - if (Common::isRelease) { + if (Common::g_is_release) { compatibilityMenu->addAction(submitCompatibilityReport); } @@ -571,7 +571,7 @@ public: query.addQueryItem("game-name", QString::fromStdString(m_games[itemID].name)); query.addQueryItem("game-serial", QString::fromStdString(m_games[itemID].serial)); query.addQueryItem("game-version", QString::fromStdString(m_games[itemID].version)); - query.addQueryItem("emulator-version", QString(Common::VERSION)); + query.addQueryItem("emulator-version", QString(Common::g_version)); url.setQuery(query); QDesktopServices::openUrl(url); diff --git a/src/qt_gui/main_window.cpp b/src/qt_gui/main_window.cpp index 072ad70e5..60ab58274 100644 --- a/src/qt_gui/main_window.cpp +++ b/src/qt_gui/main_window.cpp @@ -18,7 +18,6 @@ #include "common/path_util.h" #include "common/scm_rev.h" #include "common/string_util.h" -#include "common/version.h" #include "control_settings.h" #include "game_install_dialog.h" #include "kbm_gui.h" @@ -58,8 +57,8 @@ bool MainWindow::Init() { // show ui setMinimumSize(720, 405); std::string window_title = ""; - if (Common::isRelease) { - window_title = fmt::format("shadPS4 v{}", Common::VERSION); + if (Common::g_is_release) { + window_title = fmt::format("shadPS4 v{}", Common::g_version); } else { std::string remote_url(Common::g_scm_remote_url); std::string remote_host; @@ -69,10 +68,10 @@ bool MainWindow::Init() { remote_host = "unknown"; } if (remote_host == "shadps4-emu" || remote_url.length() == 0) { - window_title = fmt::format("shadPS4 v{} {} {}", Common::VERSION, Common::g_scm_branch, + window_title = fmt::format("shadPS4 v{} {} {}", Common::g_version, Common::g_scm_branch, Common::g_scm_desc); } else { - window_title = fmt::format("shadPS4 v{} {}/{} {}", Common::VERSION, remote_host, + window_title = fmt::format("shadPS4 v{} {}/{} {}", Common::g_version, remote_host, Common::g_scm_branch, Common::g_scm_desc); } } diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index 25c27fef3..5ee802b0c 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -9,7 +9,7 @@ #include #include "common/config.h" -#include "common/version.h" +#include "common/scm_rev.h" #include "qt_gui/compatibility_info.h" #ifdef ENABLE_DISCORD_RPC #include "common/discord_rpc_handler.h" @@ -491,7 +491,7 @@ void SettingsDialog::LoadValuesFromConfig() { QString updateChannel = QString::fromStdString(Config::getUpdateChannel()); ui->updateComboBox->setCurrentText( channelMap.key(updateChannel != "Release" && updateChannel != "Nightly" - ? (Common::isRelease ? "Release" : "Nightly") + ? (Common::g_is_release ? "Release" : "Nightly") : updateChannel)); #endif diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index fcdde7240..e369240c6 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -10,7 +10,6 @@ #include "common/assert.h" #include "common/config.h" #include "common/elf_info.h" -#include "common/version.h" #include "core/debug_state.h" #include "core/libraries/kernel/time.h" #include "core/libraries/pad/pad.h"