Skip to content

Commit 602d1e5

Browse files
authored
use fcitx5's static addon & lib support (#29)
1 parent b9ffe5e commit 602d1e5

24 files changed

+111
-312
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ jobs:
4848
git apply --directory=fcitx5 patches/fcitx5.patch
4949
git apply --directory=engines/libime/src/libime/core/kenlm patches/kenlm.patch
5050
git apply --directory=engines/libime patches/libime.patch
51-
git apply --directory=engines/fcitx5-chinese-addons patches/chinese-addons.patch
52-
git apply --directory=engines/fcitx5-hallelujah patches/hallelujah.patch
5351
git apply --directory=engines/fcitx5-rime patches/rime.patch
5452
cmake -B build -G Xcode \
5553
-DURL_SCHEME=fcitx \

CMakeLists.txt

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ set(ENV{PKG_CONFIG_PATH} "${PREBUILDER_LIB_DIR}/pkgconfig")
4040

4141
list(APPEND CMAKE_FIND_ROOT_PATH "${FIND_ROOT_PATH}")
4242

43+
option(BUILD_SHARED_LIBS "" OFF)
44+
option(BUILD_SHARED_FCITX_ADDON "" OFF)
45+
4346
add_subdirectory(deps)
4447

4548
option(ENABLE_TESTING_ADDONS "" OFF)
@@ -81,9 +84,6 @@ option(CHINESE_ADDONS "" ON)
8184
option(HALLELUJAH "" OFF)
8285
option(RIME "" OFF)
8386

84-
set(ADDONS)
85-
set(DEFAULT_INPUT_METHODS)
86-
8787
function(copy_to_keyboard cmd file relative_path)
8888
add_custom_command(TARGET ${BUNDLE_NAME}
8989
POST_BUILD COMMAND /bin/sh -c \"
@@ -104,78 +104,9 @@ function(copy_to_app cmd file relative_path)
104104
\")
105105
endfunction()
106106

107-
if (CHINESE_ADDONS)
108-
option(ENABLE_GUI OFF)
109-
option(ENABLE_CLOUDPINYIN OFF)
110-
option(ENABLE_DATA OFF)
111-
add_definitions(-DCHINESE_ADDONS)
112-
set(_Fcitx5Macro_SELF_DIR "${PROJECT_SOURCE_DIR}/fcitx5/src/lib/fcitx-utils")
113-
set(HAS_STD_FILESYSTEM 1)
114-
set(ENABLE_TOOLS OFF)
115-
add_subdirectory(engines/libime)
116-
# suppress configure error
117-
install(TARGETS kenlm EXPORT LibIMECoreTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib)
118-
add_subdirectory(engines/fcitx5-chinese-addons)
119-
list(APPEND ADDONS chttrans fullwidth pinyin pinyinhelper punctuation table)
120-
list(APPEND DEFAULT_INPUT_METHODS pinyin shuangpin wbx)
121-
endif()
122-
if (HALLELUJAH)
123-
add_library(Marisa_static STATIC IMPORTED)
124-
set_target_properties(Marisa_static PROPERTIES
125-
IMPORTED_LOCATION "${PREBUILDER_LIB_DIR}/libmarisa.a"
126-
INTERFACE_INCLUDE_DIRECTORIES "${PREBUILDER_INCLUDE_DIR}"
127-
)
128-
set(MARISA_TARGET Marisa_static)
129-
add_library(JsonC_static STATIC IMPORTED)
130-
set_target_properties(JsonC_static PROPERTIES
131-
IMPORTED_LOCATION "${PREBUILDER_LIB_DIR}/libjson-c.a"
132-
INTERFACE_INCLUDE_DIRECTORIES "${PREBUILDER_INCLUDE_DIR}"
133-
)
134-
set(JSONC_TARGET JsonC_static)
135-
136-
add_definitions(-DHALLELUJAH)
137-
add_subdirectory(engines/fcitx5-hallelujah)
138-
list(APPEND ADDONS hallelujah)
139-
list(APPEND DEFAULT_INPUT_METHODS hallelujah)
140-
endif()
141-
if (RIME)
142-
# RIME_DATA_DIR is not actually used but must exist.
143-
set(RIME_DATA_DIR "/usr/share/rime-data")
144-
set(Rime_dependencies
145-
"${PREBUILDER_LIB_DIR}/libleveldb.a"
146-
"${PREBUILDER_LIB_DIR}/libyaml-cpp.a"
147-
"${PREBUILDER_LIB_DIR}/libmarisa.a"
148-
"${PREBUILDER_LIB_DIR}/libopencc.a"
149-
"${PREBUILDER_LIB_DIR}/libglog.a"
150-
"${PREBUILDER_LIB_DIR}/liblua.a"
151-
)
152-
add_library(Rime_static STATIC IMPORTED)
153-
set_target_properties(Rime_static PROPERTIES
154-
IMPORTED_LOCATION "-Wl,-force_load,${PREBUILDER_LIB_DIR}/librime.a" # plugins use __attribute__((constructor))
155-
INTERFACE_INCLUDE_DIRECTORIES "${PREBUILDER_INCLUDE_DIR}"
156-
INTERFACE_LINK_LIBRARIES "${Rime_dependencies}"
157-
)
158-
set(RIME_TARGET Rime_static)
159-
set(Rime_VERSION "1.12")
160-
161-
add_definitions(-DRIME)
162-
add_subdirectory(engines/fcitx5-rime)
163-
list(APPEND ADDONS rime)
164-
list(APPEND DEFAULT_INPUT_METHODS rime)
165-
endif()
166-
167-
add_custom_command(
168-
OUTPUT "${PROJECT_BINARY_DIR}/profile"
169-
COMMAND python scripts/configure.py ${DEFAULT_INPUT_METHODS}
170-
DEPENDS "${PROJECT_SOURCE_DIR}/default"
171-
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
172-
COMMENT "Generating profile"
173-
)
174-
add_custom_target(gen_profile DEPENDS "${PROJECT_BINARY_DIR}/profile")
107+
add_subdirectory(engines)
175108

176-
if (CHINESE_ADDONS OR HALLELUJAH)
177-
list(APPEND ADDONS spell)
178-
endif()
109+
fcitx5_get_addon_targets(ADDON_TARGETS iosnotifications engines fcitx5 iosfrontend uipanel)
179110

180111
add_subdirectory(common)
181112
add_subdirectory(keyboard)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../fcitx5/src/lib/fcitx-utils/Fcitx5Download.cmake.in
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../fcitx5/src/lib/fcitx-utils/Fcitx5Macros.cmake
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../fcitx5/src/lib/fcitx-utils/Fcitx5ModuleTemplate.cmake.in

cmake/FindFcitx5Utils.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ set(Fcitx5Utils_FOUND TRUE)
44
# "${FCITX_INSTALL_CMAKECONFIG_DIR}/Fcitx5Utils/Fcitx5CompilerSettings.cmake"
55
# to locate Fcitx5CompilerSettings
66
set(FCITX_INSTALL_CMAKECONFIG_DIR "${CMAKE_CURRENT_LIST_DIR}")
7+
8+
# mimic fcitx5/src/lib/fcitx-utils/Fcitx5UtilsConfig.cmake.in
9+
include("${CMAKE_CURRENT_LIST_DIR}/Fcitx5Utils/Fcitx5Macros.cmake")

common/common.cpp

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,13 @@
11
#include "common.h"
2-
#include "../engines/fcitx5-hallelujah/src/factory.h"
3-
#include "../fcitx5/src/lib/fcitx/addoninstance.h"
42
#include "../fcitx5/src/lib/fcitx/addonmanager.h"
53
#include "nativestreambuf.h"
64
#include <filesystem>
75

86
#include <thread>
97

10-
#ifdef HALLELUJAH
11-
fcitx::HallelujahFactory HallelujahFactory;
12-
#endif
13-
148
namespace fs = std::filesystem;
159

16-
static fcitx::StaticAddonRegistry addons = {
17-
#ifdef HALLELUJAH
18-
std::make_pair<std::string, fcitx::AddonFactory *>("hallelujah",
19-
&HallelujahFactory),
20-
#endif
21-
};
22-
23-
FCITX_IMPORT_ADDON_FACTORY(addons, iosfrontend);
24-
FCITX_IMPORT_ADDON_FACTORY(addons, notifications);
25-
FCITX_IMPORT_ADDON_FACTORY(addons, uipanel);
26-
27-
#ifdef CHINESE_ADDONS
28-
FCITX_IMPORT_ADDON_FACTORY(addons, pinyin);
29-
FCITX_IMPORT_ADDON_FACTORY(addons, table);
30-
FCITX_IMPORT_ADDON_FACTORY(addons, chttrans);
31-
FCITX_IMPORT_ADDON_FACTORY(addons, fullwidth);
32-
FCITX_IMPORT_ADDON_FACTORY(addons, pinyinhelper);
33-
FCITX_IMPORT_ADDON_FACTORY(addons, punctuation);
34-
#endif
35-
36-
#if defined(HALLELUJAH) || defined(CHINESE_ADDONS)
37-
FCITX_IMPORT_ADDON_FACTORY(addons, spell);
38-
#endif
39-
40-
#ifdef RIME
41-
FCITX_IMPORT_ADDON_FACTORY(addons, rime);
42-
#endif
10+
extern fcitx::StaticAddonRegistry &getStaticAddon();
4311

4412
std::unique_ptr<fcitx::Instance> instance;
4513
std::unique_ptr<fcitx::EventDispatcher> dispatcher;
@@ -85,7 +53,7 @@ void setupFcitx(const char *bundlePath, const char *appGroupPath,
8553
instance->setVirtualKeyboardAutoShow(true);
8654
instance->setVirtualKeyboardAutoHide(true);
8755
auto &addonMgr = instance->addonManager();
88-
addonMgr.registerDefaultLoader(&addons);
56+
addonMgr.registerDefaultLoader(&getStaticAddon());
8957
instance->initialize();
9058
dispatcher = std::make_unique<fcitx::EventDispatcher>();
9159
dispatcher->attach(&instance->eventLoop());

engines/CMakeLists.txt

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
set(DEFAULT_INPUT_METHODS)
2+
3+
if (CHINESE_ADDONS)
4+
option(ENABLE_GUI OFF)
5+
option(ENABLE_CLOUDPINYIN OFF)
6+
option(ENABLE_DATA OFF)
7+
add_definitions(-DCHINESE_ADDONS)
8+
set(_Fcitx5Macro_SELF_DIR "${PROJECT_SOURCE_DIR}/fcitx5/src/lib/fcitx-utils")
9+
set(HAS_STD_FILESYSTEM 1)
10+
set(ENABLE_TOOLS OFF)
11+
add_subdirectory(libime)
12+
# suppress configure error
13+
install(TARGETS kenlm EXPORT LibIMECoreTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib)
14+
add_subdirectory(fcitx5-chinese-addons)
15+
list(APPEND DEFAULT_INPUT_METHODS pinyin shuangpin wbx)
16+
endif()
17+
18+
if (HALLELUJAH)
19+
add_library(Marisa_static STATIC IMPORTED)
20+
set_target_properties(Marisa_static PROPERTIES
21+
IMPORTED_LOCATION "${PREBUILDER_LIB_DIR}/libmarisa.a"
22+
INTERFACE_INCLUDE_DIRECTORIES "${PREBUILDER_INCLUDE_DIR}"
23+
)
24+
set(MARISA_TARGET Marisa_static)
25+
add_library(JsonC_static STATIC IMPORTED)
26+
set_target_properties(JsonC_static PROPERTIES
27+
IMPORTED_LOCATION "${PREBUILDER_LIB_DIR}/libjson-c.a"
28+
INTERFACE_INCLUDE_DIRECTORIES "${PREBUILDER_INCLUDE_DIR}"
29+
)
30+
set(JSONC_TARGET JsonC_static)
31+
32+
add_definitions(-DHALLELUJAH)
33+
add_subdirectory(fcitx5-hallelujah)
34+
list(APPEND DEFAULT_INPUT_METHODS hallelujah)
35+
endif()
36+
37+
if (RIME)
38+
# RIME_DATA_DIR is not actually used but must exist.
39+
set(RIME_DATA_DIR "/usr/share/rime-data")
40+
set(Rime_dependencies
41+
"${PREBUILDER_LIB_DIR}/libleveldb.a"
42+
"${PREBUILDER_LIB_DIR}/libyaml-cpp.a"
43+
"${PREBUILDER_LIB_DIR}/libmarisa.a"
44+
"${PREBUILDER_LIB_DIR}/libopencc.a"
45+
"${PREBUILDER_LIB_DIR}/libglog.a"
46+
"${PREBUILDER_LIB_DIR}/liblua.a"
47+
)
48+
add_library(Rime_static STATIC IMPORTED)
49+
set_target_properties(Rime_static PROPERTIES
50+
IMPORTED_LOCATION "-Wl,-force_load,${PREBUILDER_LIB_DIR}/librime.a" # plugins use __attribute__((constructor))
51+
INTERFACE_INCLUDE_DIRECTORIES "${PREBUILDER_INCLUDE_DIR}"
52+
INTERFACE_LINK_LIBRARIES "${Rime_dependencies}"
53+
)
54+
set(RIME_TARGET Rime_static)
55+
set(Rime_VERSION "1.12")
56+
57+
add_definitions(-DRIME)
58+
add_subdirectory(fcitx5-rime)
59+
target_include_directories(rime PRIVATE "${PROJECT_BINARY_DIR}/ipc/include")
60+
add_dependencies(rime FcitxIpc)
61+
list(APPEND DEFAULT_INPUT_METHODS rime)
62+
endif()
63+
64+
add_custom_command(
65+
OUTPUT "${PROJECT_BINARY_DIR}/profile"
66+
COMMAND python scripts/configure.py ${DEFAULT_INPUT_METHODS}
67+
DEPENDS "${PROJECT_SOURCE_DIR}/default"
68+
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
69+
COMMENT "Generating profile"
70+
)
71+
add_custom_target(gen_profile DEPENDS "${PROJECT_BINARY_DIR}/profile")

0 commit comments

Comments
 (0)