From 16970197a9b9e11c5cc2d7cd87a5e8f5cdba87c3 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Sun, 8 Dec 2024 21:19:35 -0500 Subject: [PATCH] use FCITX_DEFINE_STATIC_ADDON_REGISTRY (#214) --- CMakeLists.txt | 11 ++++++----- deps/url-filter | 2 +- fcitx5 | 2 +- fcitx5-beast | 2 +- fcitx5-webview | 2 +- keycode/CMakeLists.txt | 2 +- logging/CMakeLists.txt | 2 +- macosnotifications/CMakeLists.txt | 8 ++++---- scripts/check-validity.sh | 7 ++++++- src/CMakeLists.txt | 7 ++++++- src/fcitx.cpp | 11 ++--------- 11 files changed, 30 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85f81f7..105b6e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,16 +90,17 @@ add_compile_definitions($<$:-DFCITX_GETTEXT_DOMAIN=\"fci add_subdirectory(keycode) add_subdirectory(macosfrontend) add_subdirectory(macosnotifications) -add_subdirectory(webpanel) - -add_subdirectory(src) -add_subdirectory(assets) option(BUILD_PREVIEW "" OFF) add_subdirectory(fcitx5-webview) +add_subdirectory(webpanel) -set(ADDON_TYPE "StaticLibrary") +set(BUILD_SHARED_FCITX_ADDON OFF) +include(fcitx5/src/lib/fcitx-utils/Fcitx5Macros.cmake) add_subdirectory(fcitx5-beast/src) +add_subdirectory(src) +add_subdirectory(assets) + enable_testing() add_subdirectory(tests) diff --git a/deps/url-filter b/deps/url-filter index 23a48e7..2cc2033 160000 --- a/deps/url-filter +++ b/deps/url-filter @@ -1 +1 @@ -Subproject commit 23a48e7842c482c104e96ec61ec805e7140b8551 +Subproject commit 2cc2033fc8b0f4c8dcc79bf1b4ad8e8ff4b6d3b9 diff --git a/fcitx5 b/fcitx5 index 9a2148c..9a281f1 160000 --- a/fcitx5 +++ b/fcitx5 @@ -1 +1 @@ -Subproject commit 9a2148c61d940a239a3257e305594fafd47171ac +Subproject commit 9a281f148fdf6376666334570dc63376fd3daecf diff --git a/fcitx5-beast b/fcitx5-beast index 31bb4fd..7b9b60e 160000 --- a/fcitx5-beast +++ b/fcitx5-beast @@ -1 +1 @@ -Subproject commit 31bb4fd32500c3593b919de8890d852712724aea +Subproject commit 7b9b60eb1359e3812aacbdd0f484b880cb6143f0 diff --git a/fcitx5-webview b/fcitx5-webview index 4b2f2e6..536eb33 160000 --- a/fcitx5-webview +++ b/fcitx5-webview @@ -1 +1 @@ -Subproject commit 4b2f2e6148f99e962351811c59d895682cc5c8ba +Subproject commit 536eb33588639962c9185bbf49b8c55a56256202 diff --git a/keycode/CMakeLists.txt b/keycode/CMakeLists.txt index af3d4cb..d7093cd 100644 --- a/keycode/CMakeLists.txt +++ b/keycode/CMakeLists.txt @@ -1,3 +1,3 @@ -add_library(Keycode keycode.cpp) +add_library(Keycode STATIC keycode.cpp) target_include_directories(Keycode PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(Keycode Fcitx5::Utils) diff --git a/logging/CMakeLists.txt b/logging/CMakeLists.txt index a576976..c07cbab 100644 --- a/logging/CMakeLists.txt +++ b/logging/CMakeLists.txt @@ -5,4 +5,4 @@ else() endif() configure_file(debug.swift.in ${CMAKE_CURRENT_SOURCE_DIR}/debug.swift @ONLY) -add_library(Logging logging.swift debug.swift) +add_library(Logging STATIC logging.swift debug.swift) diff --git a/macosnotifications/CMakeLists.txt b/macosnotifications/CMakeLists.txt index aec37e3..62ef65e 100644 --- a/macosnotifications/CMakeLists.txt +++ b/macosnotifications/CMakeLists.txt @@ -12,10 +12,10 @@ _swift_generate_cxx_header( DEPENDS Logging ) -add_library(macosnotifications STATIC macosnotifications.cpp) -add_dependencies(macosnotifications SwiftNotify) -target_link_libraries(macosnotifications Fcitx5::Core Fcitx5::Module::Notifications) -target_include_directories(macosnotifications PUBLIC +add_library(notifications STATIC macosnotifications.cpp) +add_dependencies(notifications SwiftNotify) +target_link_libraries(notifications Fcitx5::Core Fcitx5::Module::Notifications) +target_include_directories(notifications PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include" "${CMAKE_SOURCE_DIR}/src" ) diff --git a/scripts/check-validity.sh b/scripts/check-validity.sh index d3a2222..c8719e1 100755 --- a/scripts/check-validity.sh +++ b/scripts/check-validity.sh @@ -2,6 +2,7 @@ set -e has_homebrew_deps=0 has_xcode_rpath=0 +has_extra_dylib=0 cd /Library/Input\ Methods/Fcitx5.app/Contents libs=(MacOS/Fcitx5) @@ -18,6 +19,10 @@ for lib in "${libs[@]}"; do otool -l $lib | grep -A2 LC_RPATH has_xcode_rpath=2 fi + n_dylib=$(otool -L MacOS/Fcitx5 | grep rpath | wc -l | xargs) + if [[ $n_dylib != 3 ]]; then + has_extra_dylib=4 + fi done -exit $((has_homebrew_deps + has_xcode_rpath)) +exit $((has_homebrew_deps + has_xcode_rpath + has_extra_dylib)) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d9fec6..b5e793d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,7 +25,7 @@ target_link_libraries(Fcitx5Objs webpanel beast macosfrontend - macosnotifications + notifications WebviewCandidateWindow Logging ) @@ -46,6 +46,11 @@ target_link_libraries(Fcitx5 SwiftNotify ) +fcitx5_import_addons(Fcitx5 + REGISTRY_VARNAME getStaticAddon + ADDONS beast keyboard webpanel macosfrontend notifications +) + set(APP_PATH "${CMAKE_CURRENT_BINARY_DIR}/Fcitx5.app/Contents") set(BINARY_LIB_PATH "${PROJECT_BINARY_DIR}/fcitx5/src/lib") diff --git a/src/fcitx.cpp b/src/fcitx.cpp index cac9565..4911344 100644 --- a/src/fcitx.cpp +++ b/src/fcitx.cpp @@ -25,14 +25,7 @@ namespace fs = std::filesystem; #define APP_CONTENTS_PATH "/Library/Input Methods/Fcitx5.app/Contents" -fcitx::BeastFactory beastFactory; -fcitx::StaticAddonRegistry staticAddons = { - std::make_pair("beast", &beastFactory)}; - -FCITX_IMPORT_ADDON_FACTORY(staticAddons, keyboard); -FCITX_IMPORT_ADDON_FACTORY(staticAddons, webpanel); -FCITX_IMPORT_ADDON_FACTORY(staticAddons, macosfrontend); -FCITX_IMPORT_ADDON_FACTORY(staticAddons, notifications); +FCITX_DEFINE_STATIC_ADDON_REGISTRY(getStaticAddon) static std::string join_paths(const std::vector &paths, char sep = ':'); @@ -139,7 +132,7 @@ void Fcitx::setupInstance() { instance_ = std::make_unique(0, nullptr); dispatcher_ = std::make_unique(); auto &addonMgr = instance_->addonManager(); - addonMgr.registerDefaultLoader(&staticAddons); + addonMgr.registerDefaultLoader(&getStaticAddon()); instance_->initialize(); dispatcher_->attach(&instance_->eventLoop()); }