Skip to content

Commit ae13436

Browse files
committed
make shared library loader optional
1 parent 5e52ade commit ae13436

File tree

6 files changed

+25
-3
lines changed

6 files changed

+25
-3
lines changed

CMakeLists.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ option(USE_FLATPAK_ICON "Use flatpak icon name for desktop files" Off)
3737
option(ENABLE_EMOJI "Enable emoji module" On)
3838
option(ENABLE_LIBUUID "Use libuuid for uuid generation" On)
3939
option(BUILD_SPELL_DICT "Build en_dict.fscd for English spell check" On)
40+
option(ENABLE_DL "Enable dynamic loading addons" On)
4041
set(NO_PREEDIT_APPS "gvim.*,wps.*,wpp.*,et.*" CACHE STRING "Disable preedit for follwing app by default.")
4142

4243
if (ENABLE_EMOJI)
@@ -81,7 +82,14 @@ endif()
8182
if(${CMAKE_SYSTEM_NAME} MATCHES "BSD|DragonFly")
8283
find_package(LibKVM REQUIRED)
8384
endif()
84-
find_package(DL REQUIRED)
85+
86+
if(ENABLE_DL)
87+
find_package(DL REQUIRED)
88+
set(DL_TARGET DL::DL)
89+
else()
90+
add_definitions("-DFCITX_NO_DL")
91+
set(DL_TARGET)
92+
endif()
8593

8694
if (NOT TARGET LibIntl::LibIntl)
8795
find_package(LibIntl REQUIRED)

src/lib/fcitx-utils/CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ set(FCITX_UTILS_SOURCES
4747
i18nstring.cpp
4848
event_common.cpp
4949
eventdispatcher.cpp
50-
library.cpp
5150
fs.cpp
5251
standardpath.cpp
5352
unixfd.cpp
@@ -62,6 +61,10 @@ set(FCITX_UTILS_SOURCES
6261
keydata.cpp
6362
)
6463

64+
if (ENABLE_DL)
65+
list(APPEND FCITX_UTILS_SOURCES library.cpp)
66+
endif()
67+
6568
set(FCITX_UTILS_HEADERS
6669
macros.h
6770
stringutils.h
@@ -129,7 +132,7 @@ target_include_directories(Fcitx5Utils PUBLIC
129132
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
130133
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
131134
$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}/Fcitx5/Utils>)
132-
target_link_libraries(Fcitx5Utils PRIVATE DL::DL LibIntl::LibIntl Pthread::Pthread ${FMT_TARGET})
135+
target_link_libraries(Fcitx5Utils PRIVATE ${DL_TARGET} LibIntl::LibIntl Pthread::Pthread ${FMT_TARGET})
133136
if(LIBKVM_FOUND)
134137
target_link_libraries(Fcitx5Utils PRIVATE LibKVM::LibKVM)
135138
endif()

src/lib/fcitx/addoninfo.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ const I18NString &AddonInfo::comment() const {
108108
}
109109

110110
const std::string &AddonInfo::type() const {
111+
#ifdef FCITX_NO_DL
112+
static const std::string staticLibrary = "StaticLibrary";
113+
return staticLibrary;
114+
#else
111115
FCITX_D();
112116
return d->addon->type.value();
117+
#endif
113118
}
114119

115120
AddonCategory AddonInfo::category() const {

src/lib/fcitx/addonloader.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace fcitx {
1414

1515
AddonLoader::~AddonLoader() {}
1616

17+
#ifndef FCITX_NO_DL
1718
SharedLibraryLoader::~SharedLibraryLoader() {}
1819

1920
AddonInstance *SharedLibraryLoader::load(const AddonInfo &info,
@@ -67,6 +68,7 @@ AddonInstance *SharedLibraryLoader::load(const AddonInfo &info,
6768
}
6869
return nullptr;
6970
}
71+
#endif
7072

7173
StaticLibraryLoader::StaticLibraryLoader(StaticAddonRegistry *registry_)
7274
: registry(registry_) {}

src/lib/fcitx/addonloader_p.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace fcitx {
1919

20+
#ifndef FCITX_NO_DL
2021
class SharedLibraryFactory {
2122
public:
2223
SharedLibraryFactory(Library lib) : library_(std::move(lib)) {
@@ -50,6 +51,7 @@ class SharedLibraryLoader : public AddonLoader {
5051
std::unordered_map<std::string, std::unique_ptr<SharedLibraryFactory>>
5152
registry_;
5253
};
54+
#endif
5355

5456
class StaticLibraryLoader : public AddonLoader {
5557
public:

src/lib/fcitx/addonmanager.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ void AddonManager::unregisterLoader(const std::string &name) {
250250
}
251251

252252
void AddonManager::registerDefaultLoader(StaticAddonRegistry *registry) {
253+
#ifndef FCITX_NO_DL
253254
registerLoader(std::make_unique<SharedLibraryLoader>());
255+
#endif
254256
if (registry) {
255257
registerLoader(std::make_unique<StaticLibraryLoader>(registry));
256258
}

0 commit comments

Comments
 (0)