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_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_BUNDLE_RESOURCE "Do not bundle any resources within FramelessHelper." OFF)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
@ -48,7 +49,7 @@ endif()
if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE)
# 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.
if(NOT MINGW)
if(NOT (MINGW OR FRAMELESSHELPER_BUILD_STATIC))
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
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("Deploy Qt libraries after compilation: ${FRAMELESSHELPER_EXAMPLES_DEPLOYQT}")
message("Suppress debug messages from FramelessHelper: ${FRAMELESSHELPER_NO_DEBUG_OUTPUT}")
message("Do not bundle any resources within FramelessHelper: ${FRAMELESSHELPER_NO_BUNDLE_RESOURCE}")
message("#######################################")

View File

@ -124,6 +124,7 @@ endif()
add_library(${PROJECT_NAME}::${SUB_PROJ_NAME} ALIAS ${SUB_PROJ_NAME})
add_library(${PROJECT_NAME}::${SUB_MOD_NAME} ALIAS ${SUB_PROJ_NAME})
if(NOT FRAMELESSHELPER_NO_BUNDLE_RESOURCE)
if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2)
qt_add_resources(${SUB_PROJ_NAME} framelesshelpercore
PREFIX
@ -137,6 +138,7 @@ else()
framelesshelpercore.qrc
)
endif()
endif()
if(FRAMELESSHELPER_BUILD_STATIC)
target_compile_definitions(${SUB_PROJ_NAME} PUBLIC
@ -150,6 +152,12 @@ if(FRAMELESSHELPER_NO_DEBUG_OUTPUT)
)
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
QT_NO_KEYWORDS
FRAMELESSHELPER_CORE_LIBRARY

View File

@ -38,6 +38,7 @@
# include "winverhelper_p.h"
#endif
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
// 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
// then call it instead inside the namespace, that's also the recommended
@ -46,6 +47,7 @@ static inline void initResource()
{
Q_INIT_RESOURCE(framelesshelpercore);
}
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
FRAMELESSHELPER_BEGIN_NAMESPACE
@ -76,16 +78,20 @@ Q_GLOBAL_STATIC(FramelessManagerHelper, g_helper)
Q_GLOBAL_STATIC(FramelessManager, g_manager)
[[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(IconFontFamilyName_win11, "Segoe Fluent Icons")
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win10, "Segoe MDL2 Assets")
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb")
# ifdef Q_OS_MACOS
[[maybe_unused]] static constexpr const int kIconFontPointSize = 10;
#else
# else // !Q_OS_MACOS
[[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()
{
static const auto result = []() -> QString {
@ -96,11 +102,12 @@ FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb")
if (WindowsVersionHelper::isWin10OrGreater()) {
return kIconFontFamilyName_win10;
}
#endif
#endif // Q_OS_WINDOWS
return kIconFontFamilyName_common;
}();
return result;
}
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
FramelessManagerPrivate::FramelessManagerPrivate(FramelessManager *q) : QObject(q)
{
@ -134,6 +141,7 @@ const FramelessManagerPrivate *FramelessManagerPrivate::get(const FramelessManag
void FramelessManagerPrivate::initializeIconFont()
{
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
static bool inited = false;
if (inited) {
return;
@ -147,10 +155,14 @@ void FramelessManagerPrivate::initializeIconFont()
} else {
DEBUG << "Successfully registered icon font:" << QFontDatabase::applicationFontFamilies(id);
}
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
}
QFont FramelessManagerPrivate::getIconFont()
{
#ifdef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
return {};
#else // !FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
static const auto font = []() -> QFont {
QFont f = {};
f.setFamily(iconFontFamilyName());
@ -158,6 +170,7 @@ QFont FramelessManagerPrivate::getIconFont()
return f;
}();
return font;
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
}
SystemTheme FramelessManagerPrivate::systemTheme() const

View File

@ -37,6 +37,7 @@
#include <QtGui/private/qguiapplication_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,
// 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
@ -45,6 +46,7 @@ static inline void initResource()
{
Q_INIT_RESOURCE(framelesshelpercore);
}
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
FRAMELESSHELPER_BEGIN_NAMESPACE
@ -562,6 +564,7 @@ void MicaMaterialPrivate::maybeGenerateBlurredWallpaper(const bool force)
void MicaMaterialPrivate::updateMaterialBrush()
{
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
initResource();
static const QImage noiseTexture = QImage(kNoiseImageFilePath);
QImage micaTexture = QImage(QSize(64, 64), QImage::Format_ARGB32_Premultiplied);
@ -581,6 +584,7 @@ void MicaMaterialPrivate::updateMaterialBrush()
Q_Q(MicaMaterial);
Q_EMIT q->shouldRedraw();
}
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
}
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;
#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
struct FONT_ICON
{
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::Close), {0xE8BB, 0xEADA}}
};
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
Qt::CursorShape Utils::calculateCursorShape(const QWindow *window, const QPoint &pos)
{
@ -141,6 +143,9 @@ Qt::Edges Utils::calculateWindowEdges(const QWindow *window, const QPoint &pos)
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);
if (!g_fontIconsTable.contains(index)) {
WARNING << "FIXME: Add FONT_ICON value for button" << button;
@ -154,10 +159,11 @@ QString Utils::getSystemButtonIconCode(const SystemButtonType button)
if (WindowsVersionHelper::isWin10OrGreater()) {
return QChar(icon.segoe);
}
#endif
# endif // Q_OS_WINDOWS
// We always use Micon on UNIX platforms because Microsoft doesn't allow distributing
// the Segoe icon font to other platforms than Windows.
return QChar(icon.micon);
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
}
QWindow *Utils::findWindow(const WId windowId)

View File

@ -162,6 +162,12 @@ if(FRAMELESSHELPER_NO_DEBUG_OUTPUT)
)
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
FRAMELESSHELPER_QUICK_LIBRARY
)

View File

@ -101,6 +101,12 @@ if(FRAMELESSHELPER_NO_DEBUG_OUTPUT)
)
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
QT_NO_KEYWORDS
FRAMELESSHELPER_WIDGETS_LIBRARY