Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make shared library loader optional #1174

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading