diff --git a/CMakeLists.txt b/CMakeLists.txt index aa90bad4a..01a44a4e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/src/lib/fcitx-utils/CMakeLists.txt b/src/lib/fcitx-utils/CMakeLists.txt index dd67e07db..0486263f0 100644 --- a/src/lib/fcitx-utils/CMakeLists.txt +++ b/src/lib/fcitx-utils/CMakeLists.txt @@ -47,7 +47,6 @@ set(FCITX_UTILS_SOURCES i18nstring.cpp event_common.cpp eventdispatcher.cpp - library.cpp fs.cpp standardpath.cpp unixfd.cpp @@ -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 @@ -129,7 +132,7 @@ target_include_directories(Fcitx5Utils PUBLIC $ $ $) -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() diff --git a/src/lib/fcitx/addoninfo.cpp b/src/lib/fcitx/addoninfo.cpp index 49d8c6e4c..62a3b8204 100644 --- a/src/lib/fcitx/addoninfo.cpp +++ b/src/lib/fcitx/addoninfo.cpp @@ -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 { diff --git a/src/lib/fcitx/addonloader.cpp b/src/lib/fcitx/addonloader.cpp index efa9515ca..a69eccedc 100644 --- a/src/lib/fcitx/addonloader.cpp +++ b/src/lib/fcitx/addonloader.cpp @@ -14,6 +14,7 @@ namespace fcitx { AddonLoader::~AddonLoader() {} +#ifndef FCITX_NO_DL SharedLibraryLoader::~SharedLibraryLoader() {} AddonInstance *SharedLibraryLoader::load(const AddonInfo &info, @@ -67,6 +68,7 @@ AddonInstance *SharedLibraryLoader::load(const AddonInfo &info, } return nullptr; } +#endif StaticLibraryLoader::StaticLibraryLoader(StaticAddonRegistry *registry_) : registry(registry_) {} diff --git a/src/lib/fcitx/addonloader_p.h b/src/lib/fcitx/addonloader_p.h index f07a6aa7b..00719b821 100644 --- a/src/lib/fcitx/addonloader_p.h +++ b/src/lib/fcitx/addonloader_p.h @@ -17,6 +17,7 @@ namespace fcitx { +#ifndef FCITX_NO_DL class SharedLibraryFactory { public: SharedLibraryFactory(Library lib) : library_(std::move(lib)) { @@ -50,6 +51,7 @@ class SharedLibraryLoader : public AddonLoader { std::unordered_map> registry_; }; +#endif class StaticLibraryLoader : public AddonLoader { public: diff --git a/src/lib/fcitx/addonmanager.cpp b/src/lib/fcitx/addonmanager.cpp index 55269f333..7c9a4b7e1 100644 --- a/src/lib/fcitx/addonmanager.cpp +++ b/src/lib/fcitx/addonmanager.cpp @@ -250,7 +250,9 @@ void AddonManager::unregisterLoader(const std::string &name) { } void AddonManager::registerDefaultLoader(StaticAddonRegistry *registry) { +#ifndef FCITX_NO_DL registerLoader(std::make_unique()); +#endif if (registry) { registerLoader(std::make_unique(registry)); }