Skip to content

Commit 2b22808

Browse files
committed
make shared library loader optional
1 parent 9d72f4c commit 2b22808

6 files changed

Lines changed: 28 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ option(ENABLE_EMOJI "Enable emoji module" On)
4141
option(ENABLE_LIBUUID "Use libuuid for uuid generation" On)
4242
option(BUILD_SPELL_DICT "Build en_dict.fscd for English spell check" On)
4343
option(BUILD_SHARED_LIBS "Build library as shared libs" On)
44+
option(ENABLE_DL "Enable dynamic loading addons" On)
4445
option(USE_SYSTEM_YOGA "Use system installed yoga library" Off)
4546
set(NO_PREEDIT_APPS "gvim.*,wps.*,wpp.*,et.*" CACHE STRING "Disable preedit for following app by default.")
4647
set(EVENT_LOOP_BACKEND "auto" CACHE STRING "Set the underlying event loop implementation, valid values are auto,systemd,libuv,none")
@@ -119,7 +120,10 @@ endif()
119120
if(${CMAKE_SYSTEM_NAME} MATCHES "BSD|DragonFly")
120121
find_package(LibKVM REQUIRED)
121122
endif()
122-
find_package(DL REQUIRED)
123+
124+
if (ENABLE_DL)
125+
find_package(DL REQUIRED)
126+
endif()
123127

124128
if (NOT TARGET LibIntl::LibIntl)
125129
find_package(LibIntl REQUIRED)

src/lib/fcitx-utils/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ list(APPEND FCITX_UTILS_SOURCES
5454
color.cpp
5555
i18nstring.cpp
5656
eventdispatcher.cpp
57-
library.cpp
5857
fs.cpp
5958
fs_deprecated.cpp
6059
standardpath.cpp
@@ -90,7 +89,6 @@ set(FCITX_UTILS_HEADERS
9089
event.h
9190
eventloopinterface.h
9291
eventdispatcher.h
93-
library.h
9492
cutf8.h
9593
fs.h
9694
standardpath.h
@@ -125,6 +123,11 @@ set(FCITX_UTILS_HEADERS
125123
${CMAKE_CURRENT_BINARY_DIR}/fcitxutils_export.h
126124
)
127125

126+
if (ENABLE_DL)
127+
list(APPEND FCITX_UTILS_SOURCES library.cpp)
128+
list(APPEND FCITX_UTILS_HEADERS library.h)
129+
endif()
130+
128131
set(FCITX_UTILS_DBUS_HEADERS
129132
dbus/message.h
130133
dbus/objectvtable.h
@@ -150,10 +153,13 @@ target_include_directories(Fcitx5Utils PUBLIC
150153
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
151154
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/..>
152155
$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}/Fcitx5/Utils>)
153-
target_link_libraries(Fcitx5Utils PRIVATE DL::DL LibIntl::LibIntl Pthread::Pthread)
156+
target_link_libraries(Fcitx5Utils PRIVATE LibIntl::LibIntl Pthread::Pthread)
154157
if(LIBKVM_FOUND)
155158
target_link_libraries(Fcitx5Utils PRIVATE LibKVM::LibKVM)
156159
endif()
160+
if (ENABLE_DL)
161+
target_link_libraries(Fcitx5Utils PRIVATE DL::DL)
162+
endif()
157163
target_link_libraries(Fcitx5Utils PRIVATE ${FCITX_UTILS_DEPS})
158164

159165
configure_file(Fcitx5Utils.pc.in ${CMAKE_CURRENT_BINARY_DIR}/Fcitx5Utils.pc @ONLY)

src/lib/fcitx/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ if (ENABLE_LIBUUID)
8888
target_link_libraries(Fcitx5Core PRIVATE LibUUID::LibUUID)
8989
endif()
9090

91+
if (NOT ENABLE_DL)
92+
target_compile_definitions(Fcitx5Core PRIVATE -DFCITX_NO_DL)
93+
endif()
94+
9195
configure_file(Fcitx5Core.pc.in ${CMAKE_CURRENT_BINARY_DIR}/Fcitx5Core.pc @ONLY)
9296

9397
install(TARGETS Fcitx5Core EXPORT Fcitx5CoreTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")

src/lib/fcitx/addonloader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include <utility>
1515
#include <vector>
1616
#include "fcitx-utils/flags.h"
17+
#ifndef FCITX_NO_DL
1718
#include "fcitx-utils/library.h"
19+
#endif
1820
#include "fcitx-utils/log.h"
1921
#include "fcitx-utils/standardpaths.h"
2022
#include "fcitx-utils/stringutils.h"
@@ -27,6 +29,7 @@ namespace fcitx {
2729

2830
AddonLoader::~AddonLoader() {}
2931

32+
#ifndef FCITX_NO_DL
3033
SharedLibraryLoader::~SharedLibraryLoader() {}
3134

3235
AddonInstance *SharedLibraryLoader::load(const AddonInfo &info,
@@ -100,6 +103,7 @@ AddonInstance *SharedLibraryLoader::load(const AddonInfo &info,
100103
}
101104
return nullptr;
102105
}
106+
#endif
103107

104108
StaticLibraryLoader::StaticLibraryLoader(StaticAddonRegistry *registry_)
105109
: registry(registry_) {}

src/lib/fcitx/addonloader_p.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include <unordered_map>
1414
#include <utility>
1515
#include <vector>
16+
#ifndef FCITX_NO_DL
1617
#include <fcitx-utils/library.h>
18+
#endif
1719
#include <fcitx-utils/standardpaths.h>
1820
#include <fcitx-utils/stringutils.h>
1921
#include <fcitx/addonfactory.h>
@@ -27,6 +29,7 @@ namespace {
2729
constexpr char FCITX_ADDON_FACTORY_ENTRY[] = "fcitx_addon_factory_instance";
2830
}
2931

32+
#ifndef FCITX_NO_DL
3033
class SharedLibraryFactory {
3134
public:
3235
SharedLibraryFactory(const AddonInfo &info, std::vector<Library> libraries)
@@ -71,6 +74,7 @@ class SharedLibraryLoader : public AddonLoader {
7174
std::unordered_map<std::string, std::unique_ptr<SharedLibraryFactory>>
7275
registry_;
7376
};
77+
#endif
7478

7579
class StaticLibraryLoader : public AddonLoader {
7680
public:

src/lib/fcitx/addonmanager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ void AddonManager::unregisterLoader(const std::string &name) {
249249
}
250250

251251
void AddonManager::registerDefaultLoader(StaticAddonRegistry *registry) {
252+
#ifndef FCITX_NO_DL
252253
registerLoader(std::make_unique<SharedLibraryLoader>());
254+
#endif
253255
if (registry) {
254256
registerLoader(std::make_unique<StaticLibraryLoader>(registry));
255257
}

0 commit comments

Comments
 (0)