Skip to content

Commit

Permalink
make shared library loader optional
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Nov 7, 2024
1 parent 5e52ade commit ae13436
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ option(USE_FLATPAK_ICON "Use flatpak icon name for desktop files" Off)
option(ENABLE_EMOJI "Enable emoji module" On)
option(ENABLE_LIBUUID "Use libuuid for uuid generation" On)
option(BUILD_SPELL_DICT "Build en_dict.fscd for English spell check" On)
option(ENABLE_DL "Enable dynamic loading addons" On)
set(NO_PREEDIT_APPS "gvim.*,wps.*,wpp.*,et.*" CACHE STRING "Disable preedit for follwing app by default.")

if (ENABLE_EMOJI)
Expand Down Expand Up @@ -81,7 +82,14 @@ endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "BSD|DragonFly")
find_package(LibKVM REQUIRED)
endif()
find_package(DL REQUIRED)

if(ENABLE_DL)
find_package(DL REQUIRED)
set(DL_TARGET DL::DL)
else()
add_definitions("-DFCITX_NO_DL")
set(DL_TARGET)
endif()

if (NOT TARGET LibIntl::LibIntl)
find_package(LibIntl REQUIRED)
Expand Down
7 changes: 5 additions & 2 deletions src/lib/fcitx-utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ set(FCITX_UTILS_SOURCES
i18nstring.cpp
event_common.cpp
eventdispatcher.cpp
library.cpp
fs.cpp
standardpath.cpp
unixfd.cpp
Expand All @@ -62,6 +61,10 @@ set(FCITX_UTILS_SOURCES
keydata.cpp
)

if (ENABLE_DL)
list(APPEND FCITX_UTILS_SOURCES library.cpp)
endif()

set(FCITX_UTILS_HEADERS
macros.h
stringutils.h
Expand Down Expand Up @@ -129,7 +132,7 @@ target_include_directories(Fcitx5Utils PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}/Fcitx5/Utils>)
target_link_libraries(Fcitx5Utils PRIVATE DL::DL LibIntl::LibIntl Pthread::Pthread ${FMT_TARGET})
target_link_libraries(Fcitx5Utils PRIVATE ${DL_TARGET} LibIntl::LibIntl Pthread::Pthread ${FMT_TARGET})
if(LIBKVM_FOUND)
target_link_libraries(Fcitx5Utils PRIVATE LibKVM::LibKVM)
endif()
Expand Down
5 changes: 5 additions & 0 deletions src/lib/fcitx/addoninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ const I18NString &AddonInfo::comment() const {
}

const std::string &AddonInfo::type() const {
#ifdef FCITX_NO_DL
static const std::string staticLibrary = "StaticLibrary";
return staticLibrary;
#else
FCITX_D();
return d->addon->type.value();
#endif
}

AddonCategory AddonInfo::category() const {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/fcitx/addonloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace fcitx {

AddonLoader::~AddonLoader() {}

#ifndef FCITX_NO_DL
SharedLibraryLoader::~SharedLibraryLoader() {}

AddonInstance *SharedLibraryLoader::load(const AddonInfo &info,
Expand Down Expand Up @@ -67,6 +68,7 @@ AddonInstance *SharedLibraryLoader::load(const AddonInfo &info,
}
return nullptr;
}
#endif

StaticLibraryLoader::StaticLibraryLoader(StaticAddonRegistry *registry_)
: registry(registry_) {}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/fcitx/addonloader_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace fcitx {

#ifndef FCITX_NO_DL
class SharedLibraryFactory {
public:
SharedLibraryFactory(Library lib) : library_(std::move(lib)) {
Expand Down Expand Up @@ -50,6 +51,7 @@ class SharedLibraryLoader : public AddonLoader {
std::unordered_map<std::string, std::unique_ptr<SharedLibraryFactory>>
registry_;
};
#endif

class StaticLibraryLoader : public AddonLoader {
public:
Expand Down
2 changes: 2 additions & 0 deletions src/lib/fcitx/addonmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ void AddonManager::unregisterLoader(const std::string &name) {
}

void AddonManager::registerDefaultLoader(StaticAddonRegistry *registry) {
#ifndef FCITX_NO_DL
registerLoader(std::make_unique<SharedLibraryLoader>());
#endif
if (registry) {
registerLoader(std::make_unique<StaticLibraryLoader>(registry));
}
Expand Down

0 comments on commit ae13436

Please sign in to comment.