From 8b5f7ec1e8461d1ad44a083873c5ac360ec01cbb Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 27 Nov 2024 09:48:04 +0100 Subject: [PATCH] new cmake build option tailored for msys2 flavor of rssguard --- CMakeLists.txt | 7 +++++++ src/cmake_plugins.cmake | 8 ++------ src/librssguard/CMakeLists.txt | 4 ++-- src/librssguard/miscellaneous/application.cpp | 5 ----- src/librssguard/miscellaneous/pluginfactory.cpp | 7 +------ src/librssguard/miscellaneous/settings.cpp | 11 ++++++----- src/rssguard/CMakeLists.txt | 6 ++---- 7 files changed, 20 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6881733f..3df746e26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,8 @@ # # Variables: # BUILD_WITH_QT6 - Build either with Qt 6 or Qt 5. +# BUILD_MSYS2 - Build RSS Guard for MSYS2 distribution, this particularly +# enables relevant MSYS2 FHS tweaks. # USE_SYSTEM_SQLITE - Use system-wide SQLite3 library and header file. Defaults to "ON". # NO_UPDATE_CHECK - Disable automatic checking for new application updates. # IS_FLATPAK_BUILD - Set to "ON" when building RSS Guard with Flatpak. @@ -118,6 +120,7 @@ endif() # Global compilation switches. option(BUILD_WITH_QT6 "Build application with Qt 6." ON) +option(BUILD_MSYS2 "Build application for MSYS2 ecosystem." OFF) option(USE_SYSTEM_SQLITE "Use system-wide SQLite3 library." ON) option(NO_LITE "Enable QtWebEngine and other more demanding components." ON) option(UPDATE_TRANSLATIONS "Call lupdate to update translation files from source (Qt 6 only)." OFF) @@ -288,6 +291,10 @@ if(IS_FLATPAK_BUILD) add_compile_definitions(IS_FLATPAK_BUILD) endif() +if(BUILD_MSYS2) + add_compile_definitions(BUILD_MSYS2) +endif() + # Configure and copy some needed files. if(WIN32) configure_file( diff --git a/src/cmake_plugins.cmake b/src/cmake_plugins.cmake index 41770d914..5760d49b7 100644 --- a/src/cmake_plugins.cmake +++ b/src/cmake_plugins.cmake @@ -28,13 +28,9 @@ function(prepare_rssguard_plugin plugin_target_name) ${LIBRSSGUARD_SOURCE_PATH} ) - if(MSVC OR OS2) + if((WIN32 AND NOT BUILD_MSYS2) OR OS2) install(TARGETS ${plugin_target_name} DESTINATION plugins) - elseif(MINGW) - include (GNUInstallDirs) - install(TARGETS ${plugin_target_name} - DESTINATION ${CMAKE_INSTALL_DATADIR}/rssguard/plugins) - elseif(UNIX AND NOT APPLE AND NOT ANDROID) + elseif((MINGW AND BUILD_MSYS2) OR (UNIX AND NOT APPLE AND NOT ANDROID)) include (GNUInstallDirs) install(TARGETS ${plugin_target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR}/rssguard diff --git a/src/librssguard/CMakeLists.txt b/src/librssguard/CMakeLists.txt index 25685b3de..dad38aee5 100644 --- a/src/librssguard/CMakeLists.txt +++ b/src/librssguard/CMakeLists.txt @@ -628,10 +628,10 @@ elseif(WIN32) ) endif() -if(MSVC OR OS2) +if((WIN32 AND NOT BUILD_MSYS2) OR OS2) install(TARGETS rssguard DESTINATION .) set(HEADERS_FOLDER "include/librssguard") -elseif(MINGW) +elseif(MINGW AND BUILD_MSYS2) include (GNUInstallDirs) install(TARGETS rssguard LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/src/librssguard/miscellaneous/application.cpp b/src/librssguard/miscellaneous/application.cpp index 829a7bd1e..a1ebae54d 100644 --- a/src/librssguard/miscellaneous/application.cpp +++ b/src/librssguard/miscellaneous/application.cpp @@ -579,12 +579,7 @@ QString Application::userDataAppFolder() const { // In "app" folder, we would like to separate all user data into own subfolder, // therefore stick to "data" folder in this mode. -#ifdef _MSC_VER return QDir::toNativeSeparators(applicationDirPath() + QDir::separator() + QSL("data%1").arg(major_version)); -#else - return QDir::toNativeSeparators(applicationDirPath() + QDir::separator() + QSL("..") + QDir::separator() + - QSL("share") + QDir::separator() + QSL(APP_LOW_NAME) + QDir::separator() + QSL("data%1").arg(major_version)); -#endif } QString Application::userDataFolder() { diff --git a/src/librssguard/miscellaneous/pluginfactory.cpp b/src/librssguard/miscellaneous/pluginfactory.cpp index 475814afe..be4c1f596 100644 --- a/src/librssguard/miscellaneous/pluginfactory.cpp +++ b/src/librssguard/miscellaneous/pluginfactory.cpp @@ -73,16 +73,11 @@ QList PluginFactory::loadPlugins() const { QStringList PluginFactory::pluginPaths() const { QStringList paths; -#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) +#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(BUILD_MSYS2) paths << QCoreApplication::applicationDirPath() + QDir::separator() + QL1S("..") + QDir::separator() + QL1S(RSSGUARD_LIBDIR) + QDir::separator() + QL1S(APP_LOW_NAME); #elif defined(Q_OS_WIN) -#ifdef _MSC_VER paths << QCoreApplication::applicationDirPath() + QDir::separator() + QL1S("plugins"); -#else - paths << QCoreApplication::applicationDirPath() + QDir::separator() + QL1S("..") + QDir::separator() + - QL1S("share") + QDir::separator() + QL1S(APP_LOW_NAME) + QDir::separator() + QL1S("plugins"); -#endif #else paths << QCoreApplication::applicationDirPath(); #endif diff --git a/src/librssguard/miscellaneous/settings.cpp b/src/librssguard/miscellaneous/settings.cpp index 0514b3cb8..aef405071 100644 --- a/src/librssguard/miscellaneous/settings.cpp +++ b/src/librssguard/miscellaneous/settings.cpp @@ -31,7 +31,7 @@ DKEY Node::ID = "nodejs"; DKEY Node::NodeJsExecutable = QSL("nodejs_executable_") + OS_ID; -#if (defined(Q_OS_WIN) && defined(_MSC_VER)) || defined(Q_OS_OS2) +#if (defined(Q_OS_WIN) && !defined(BUILD_MSYS2)) || defined(Q_OS_OS2) DVALUE(QString) Node::NodeJsExecutableDef = "node.exe"; #else DVALUE(QString) Node::NodeJsExecutableDef = "node"; @@ -39,7 +39,7 @@ DVALUE(QString) Node::NodeJsExecutableDef = "node"; DKEY Node::NpmExecutable = QSL("npm_executable_") + OS_ID; -#if defined(Q_OS_WIN) && defined(_MSC_VER) +#if defined(Q_OS_WIN) && !defined(BUILD_MSYS2) DVALUE(QString) Node::NpmExecutableDef = "npm.cmd"; #elif defined(Q_OS_OS2) DVALUE(QString) Node::NpmExecutableDef = "npm.exe"; @@ -620,6 +620,7 @@ SettingsProperties Settings::determineProperties() { SettingsProperties properties; properties.m_settingsSuffix = QDir::separator() + QSL(APP_CFG_PATH) + QDir::separator() + QSL(APP_CFG_FILE); + const QString app_path = qApp->userDataAppFolder(); const QString home_path = qApp->userDataHomeFolder(); const QString custom_path = qApp->customDataFolder(); @@ -630,10 +631,10 @@ SettingsProperties Settings::determineProperties() { properties.m_baseDirectory = custom_path; } else { - // We will use PORTABLE settings only and only if it is available and NON-PORTABLE + // We will use PORTABLE settings only if it is available and NON-PORTABLE // settings was not initialized before. -#if defined(Q_OS_UNIX) - // DO NOT use portable settings for *nix, it is really not used on that platform. +#if defined(Q_OS_UNIX) || defined(BUILD_MSYS2) + // DO NOT use portable settings for *nix or MSYS2, it is really not used on those platforms. const bool will_we_use_portable_settings = false; #else const QString exe_path = qApp->applicationDirPath(); diff --git a/src/rssguard/CMakeLists.txt b/src/rssguard/CMakeLists.txt index fa48a7d7a..18c8cdad0 100644 --- a/src/rssguard/CMakeLists.txt +++ b/src/rssguard/CMakeLists.txt @@ -41,7 +41,7 @@ elseif(WIN32) ) endif() -if(MSVC) +if(WIN32 AND NOT BUILD_MSYS2) install(TARGETS app DESTINATION .) install(FILES ${CMAKE_SOURCE_DIR}/resources/graphics/${CMAKE_PROJECT_NAME}.ico DESTINATION . @@ -55,9 +55,7 @@ if(MSVC) ) elseif(OS2) install(TARGETS app DESTINATION .) -elseif(MINGW) - install(TARGETS app DESTINATION ${CMAKE_INSTALL_BINDIR}) -elseif(UNIX AND NOT APPLE AND NOT ANDROID) +elseif((MINGW AND BUILD_MSYS2) OR (UNIX AND NOT APPLE AND NOT ANDROID)) include (GNUInstallDirs) install(TARGETS app DESTINATION ${CMAKE_INSTALL_BINDIR}