cmake: allow disable resource bundle

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-11-26 16:44:41 +08:00
parent 9c08c69a4d
commit 40058a1e79
7 changed files with 66 additions and 21 deletions

View File

@ -37,6 +37,7 @@ option(FRAMELESSHELPER_BUILD_QUICK "Build FramelessHelper's Quick module." ON)
option(FRAMELESSHELPER_BUILD_EXAMPLES "Build FramelessHelper demo applications." ON) option(FRAMELESSHELPER_BUILD_EXAMPLES "Build FramelessHelper demo applications." ON)
option(FRAMELESSHELPER_EXAMPLES_DEPLOYQT "Deploy the Qt framework after building the demo projects." ON) option(FRAMELESSHELPER_EXAMPLES_DEPLOYQT "Deploy the Qt framework after building the demo projects." ON)
option(FRAMELESSHELPER_NO_DEBUG_OUTPUT "Suppress the debug messages from FramelessHelper." OFF) option(FRAMELESSHELPER_NO_DEBUG_OUTPUT "Suppress the debug messages from FramelessHelper." OFF)
option(FRAMELESSHELPER_NO_BUNDLE_RESOURCE "Do not bundle any resources within FramelessHelper." OFF)
include(GNUInstallDirs) include(GNUInstallDirs)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
@ -48,7 +49,7 @@ endif()
if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE) if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE)
# MinGW has many bugs when LTO is enabled, and they are all very # MinGW has many bugs when LTO is enabled, and they are all very
# hard to workaround, so just don't enable LTO at all for MinGW. # hard to workaround, so just don't enable LTO at all for MinGW.
if(NOT MINGW) if(NOT (MINGW OR FRAMELESSHELPER_BUILD_STATIC))
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
endif() endif()
endif() endif()
@ -175,4 +176,5 @@ message("Build the FramelessHelper::Quick module: ${FRAMELESSHELPER_BUILD_QUICK}
message("Build the FramelessHelper demo applications: ${FRAMELESSHELPER_BUILD_EXAMPLES}") message("Build the FramelessHelper demo applications: ${FRAMELESSHELPER_BUILD_EXAMPLES}")
message("Deploy Qt libraries after compilation: ${FRAMELESSHELPER_EXAMPLES_DEPLOYQT}") message("Deploy Qt libraries after compilation: ${FRAMELESSHELPER_EXAMPLES_DEPLOYQT}")
message("Suppress debug messages from FramelessHelper: ${FRAMELESSHELPER_NO_DEBUG_OUTPUT}") message("Suppress debug messages from FramelessHelper: ${FRAMELESSHELPER_NO_DEBUG_OUTPUT}")
message("Do not bundle any resources within FramelessHelper: ${FRAMELESSHELPER_NO_BUNDLE_RESOURCE}")
message("#######################################") message("#######################################")

View File

@ -124,18 +124,20 @@ endif()
add_library(${PROJECT_NAME}::${SUB_PROJ_NAME} ALIAS ${SUB_PROJ_NAME}) add_library(${PROJECT_NAME}::${SUB_PROJ_NAME} ALIAS ${SUB_PROJ_NAME})
add_library(${PROJECT_NAME}::${SUB_MOD_NAME} ALIAS ${SUB_PROJ_NAME}) add_library(${PROJECT_NAME}::${SUB_MOD_NAME} ALIAS ${SUB_PROJ_NAME})
if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2) if(NOT FRAMELESSHELPER_NO_BUNDLE_RESOURCE)
qt_add_resources(${SUB_PROJ_NAME} framelesshelpercore if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2)
PREFIX qt_add_resources(${SUB_PROJ_NAME} framelesshelpercore
"/org.wangwenx190.${PROJECT_NAME}" PREFIX
FILES "/org.wangwenx190.${PROJECT_NAME}"
"resources/fonts/Micon.ttf" FILES
"resources/images/noise.png" "resources/fonts/Micon.ttf"
) "resources/images/noise.png"
else() )
target_sources(${SUB_PROJ_NAME} PRIVATE else()
framelesshelpercore.qrc target_sources(${SUB_PROJ_NAME} PRIVATE
) framelesshelpercore.qrc
)
endif()
endif() endif()
if(FRAMELESSHELPER_BUILD_STATIC) if(FRAMELESSHELPER_BUILD_STATIC)
@ -150,6 +152,12 @@ if(FRAMELESSHELPER_NO_DEBUG_OUTPUT)
) )
endif() endif()
if(FRAMELESSHELPER_NO_BUNDLE_RESOURCE)
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
)
endif()
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
QT_NO_KEYWORDS QT_NO_KEYWORDS
FRAMELESSHELPER_CORE_LIBRARY FRAMELESSHELPER_CORE_LIBRARY

View File

@ -38,6 +38,7 @@
# include "winverhelper_p.h" # include "winverhelper_p.h"
#endif #endif
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
// The "Q_INIT_RESOURCE()" macro can't be used within a namespace, // The "Q_INIT_RESOURCE()" macro can't be used within a namespace,
// so we wrap it into a separate function outside of the namespace and // so we wrap it into a separate function outside of the namespace and
// then call it instead inside the namespace, that's also the recommended // then call it instead inside the namespace, that's also the recommended
@ -46,6 +47,7 @@ static inline void initResource()
{ {
Q_INIT_RESOURCE(framelesshelpercore); Q_INIT_RESOURCE(framelesshelpercore);
} }
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
FRAMELESSHELPER_BEGIN_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE
@ -76,16 +78,20 @@ Q_GLOBAL_STATIC(FramelessManagerHelper, g_helper)
Q_GLOBAL_STATIC(FramelessManager, g_manager) Q_GLOBAL_STATIC(FramelessManager, g_manager)
[[maybe_unused]] static constexpr const char kGlobalFlagVarName[] = "__FRAMELESSHELPER__"; [[maybe_unused]] static constexpr const char kGlobalFlagVarName[] = "__FRAMELESSHELPER__";
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFilePath, ":/org.wangwenx190.FramelessHelper/resources/fonts/Micon.ttf") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFilePath, ":/org.wangwenx190.FramelessHelper/resources/fonts/Micon.ttf")
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win11, "Segoe Fluent Icons") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win11, "Segoe Fluent Icons")
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win10, "Segoe MDL2 Assets") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win10, "Segoe MDL2 Assets")
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb")
#ifdef Q_OS_MACOS # ifdef Q_OS_MACOS
[[maybe_unused]] static constexpr const int kIconFontPointSize = 10; [[maybe_unused]] static constexpr const int kIconFontPointSize = 10;
#else # else // !Q_OS_MACOS
[[maybe_unused]] static constexpr const int kIconFontPointSize = 8; [[maybe_unused]] static constexpr const int kIconFontPointSize = 8;
#endif # endif // Q_OS_MACOS
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
[[nodiscard]] static inline QString iconFontFamilyName() [[nodiscard]] static inline QString iconFontFamilyName()
{ {
static const auto result = []() -> QString { static const auto result = []() -> QString {
@ -96,11 +102,12 @@ FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb")
if (WindowsVersionHelper::isWin10OrGreater()) { if (WindowsVersionHelper::isWin10OrGreater()) {
return kIconFontFamilyName_win10; return kIconFontFamilyName_win10;
} }
#endif #endif // Q_OS_WINDOWS
return kIconFontFamilyName_common; return kIconFontFamilyName_common;
}(); }();
return result; return result;
} }
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
FramelessManagerPrivate::FramelessManagerPrivate(FramelessManager *q) : QObject(q) FramelessManagerPrivate::FramelessManagerPrivate(FramelessManager *q) : QObject(q)
{ {
@ -134,6 +141,7 @@ const FramelessManagerPrivate *FramelessManagerPrivate::get(const FramelessManag
void FramelessManagerPrivate::initializeIconFont() void FramelessManagerPrivate::initializeIconFont()
{ {
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
static bool inited = false; static bool inited = false;
if (inited) { if (inited) {
return; return;
@ -147,10 +155,14 @@ void FramelessManagerPrivate::initializeIconFont()
} else { } else {
DEBUG << "Successfully registered icon font:" << QFontDatabase::applicationFontFamilies(id); DEBUG << "Successfully registered icon font:" << QFontDatabase::applicationFontFamilies(id);
} }
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
} }
QFont FramelessManagerPrivate::getIconFont() QFont FramelessManagerPrivate::getIconFont()
{ {
#ifdef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
return {};
#else // !FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
static const auto font = []() -> QFont { static const auto font = []() -> QFont {
QFont f = {}; QFont f = {};
f.setFamily(iconFontFamilyName()); f.setFamily(iconFontFamilyName());
@ -158,6 +170,7 @@ QFont FramelessManagerPrivate::getIconFont()
return f; return f;
}(); }();
return font; return font;
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
} }
SystemTheme FramelessManagerPrivate::systemTheme() const SystemTheme FramelessManagerPrivate::systemTheme() const

View File

@ -37,6 +37,7 @@
#include <QtGui/private/qguiapplication_p.h> #include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qmemrotate_p.h> #include <QtGui/private/qmemrotate_p.h>
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
// The "Q_INIT_RESOURCE()" macro can't be used within a namespace, // The "Q_INIT_RESOURCE()" macro can't be used within a namespace,
// so we wrap it into a separate function outside of the namespace and // so we wrap it into a separate function outside of the namespace and
// then call it instead inside the namespace, that's also the recommended // then call it instead inside the namespace, that's also the recommended
@ -45,6 +46,7 @@ static inline void initResource()
{ {
Q_INIT_RESOURCE(framelesshelpercore); Q_INIT_RESOURCE(framelesshelpercore);
} }
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
FRAMELESSHELPER_BEGIN_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE
@ -562,6 +564,7 @@ void MicaMaterialPrivate::maybeGenerateBlurredWallpaper(const bool force)
void MicaMaterialPrivate::updateMaterialBrush() void MicaMaterialPrivate::updateMaterialBrush()
{ {
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
initResource(); initResource();
static const QImage noiseTexture = QImage(kNoiseImageFilePath); static const QImage noiseTexture = QImage(kNoiseImageFilePath);
QImage micaTexture = QImage(QSize(64, 64), QImage::Format_ARGB32_Premultiplied); QImage micaTexture = QImage(QSize(64, 64), QImage::Format_ARGB32_Premultiplied);
@ -581,6 +584,7 @@ void MicaMaterialPrivate::updateMaterialBrush()
Q_Q(MicaMaterial); Q_Q(MicaMaterial);
Q_EMIT q->shouldRedraw(); Q_EMIT q->shouldRedraw();
} }
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
} }
void MicaMaterialPrivate::paint(QPainter *painter, const QSize &size, const QPoint &pos) void MicaMaterialPrivate::paint(QPainter *painter, const QSize &size, const QPoint &pos)

View File

@ -54,6 +54,7 @@ Q_LOGGING_CATEGORY(lcUtilsCommon, "wangwenx190.framelesshelper.core.utils.common
using namespace Global; using namespace Global;
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
struct FONT_ICON struct FONT_ICON
{ {
quint32 segoe = 0; quint32 segoe = 0;
@ -69,6 +70,7 @@ static const QHash<int, FONT_ICON> g_fontIconsTable = {
{static_cast<int>(SystemButtonType::Restore), {0xE923, 0xEAE2}}, {static_cast<int>(SystemButtonType::Restore), {0xE923, 0xEAE2}},
{static_cast<int>(SystemButtonType::Close), {0xE8BB, 0xEADA}} {static_cast<int>(SystemButtonType::Close), {0xE8BB, 0xEADA}}
}; };
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
Qt::CursorShape Utils::calculateCursorShape(const QWindow *window, const QPoint &pos) Qt::CursorShape Utils::calculateCursorShape(const QWindow *window, const QPoint &pos)
{ {
@ -141,23 +143,27 @@ Qt::Edges Utils::calculateWindowEdges(const QWindow *window, const QPoint &pos)
QString Utils::getSystemButtonIconCode(const SystemButtonType button) QString Utils::getSystemButtonIconCode(const SystemButtonType button)
{ {
#ifdef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
return {};
#else // !FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
const auto index = static_cast<int>(button); const auto index = static_cast<int>(button);
if (!g_fontIconsTable.contains(index)) { if (!g_fontIconsTable.contains(index)) {
WARNING << "FIXME: Add FONT_ICON value for button" << button; WARNING << "FIXME: Add FONT_ICON value for button" << button;
return {}; return {};
} }
const FONT_ICON icon = g_fontIconsTable.value(index); const FONT_ICON icon = g_fontIconsTable.value(index);
#ifdef Q_OS_WINDOWS # ifdef Q_OS_WINDOWS
// Windows 11: Segoe Fluent Icons (https://docs.microsoft.com/en-us/windows/apps/design/style/segoe-fluent-icons-font) // Windows 11: Segoe Fluent Icons (https://docs.microsoft.com/en-us/windows/apps/design/style/segoe-fluent-icons-font)
// Windows 10: Segoe MDL2 Assets (https://docs.microsoft.com/en-us/windows/apps/design/style/segoe-ui-symbol-font) // Windows 10: Segoe MDL2 Assets (https://docs.microsoft.com/en-us/windows/apps/design/style/segoe-ui-symbol-font)
// Windows 7~8.1: Micon (http://xtoolkit.github.io/Micon/) // Windows 7~8.1: Micon (http://xtoolkit.github.io/Micon/)
if (WindowsVersionHelper::isWin10OrGreater()) { if (WindowsVersionHelper::isWin10OrGreater()) {
return QChar(icon.segoe); return QChar(icon.segoe);
} }
#endif # endif // Q_OS_WINDOWS
// We always use Micon on UNIX platforms because Microsoft doesn't allow distributing // We always use Micon on UNIX platforms because Microsoft doesn't allow distributing
// the Segoe icon font to other platforms than Windows. // the Segoe icon font to other platforms than Windows.
return QChar(icon.micon); return QChar(icon.micon);
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
} }
QWindow *Utils::findWindow(const WId windowId) QWindow *Utils::findWindow(const WId windowId)

View File

@ -162,6 +162,12 @@ if(FRAMELESSHELPER_NO_DEBUG_OUTPUT)
) )
endif() endif()
if(FRAMELESSHELPER_NO_BUNDLE_RESOURCE)
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
FRAMELESSHELPER_QUICK_NO_BUNDLE_RESOURCE
)
endif()
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
FRAMELESSHELPER_QUICK_LIBRARY FRAMELESSHELPER_QUICK_LIBRARY
) )

View File

@ -101,6 +101,12 @@ if(FRAMELESSHELPER_NO_DEBUG_OUTPUT)
) )
endif() endif()
if(FRAMELESSHELPER_NO_BUNDLE_RESOURCE)
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
FRAMELESSHELPER_WIDGETS_NO_BUNDLE_RESOURCE
)
endif()
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
QT_NO_KEYWORDS QT_NO_KEYWORDS
FRAMELESSHELPER_WIDGETS_LIBRARY FRAMELESSHELPER_WIDGETS_LIBRARY