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

simplify cmake #24

Merged
merged 1 commit into from
Nov 13, 2024
Merged
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
12 changes: 0 additions & 12 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
[submodule "engines/fcitx5-rime"]
path = engines/fcitx5-rime
url = https://github.com/fcitx/fcitx5-rime
[submodule "data/rime-essay"]
path = data/rime-essay
url = https://github.com/rime/rime-essay
[submodule "data/rime-prelude"]
path = data/rime-prelude
url = https://github.com/rime/rime-prelude
[submodule "data/rime-luna-pinyin"]
path = data/rime-luna-pinyin
url = https://github.com/rime/rime-luna-pinyin
[submodule "data/rime-stroke"]
path = data/rime-stroke
url = https://github.com/rime/rime-stroke
[submodule "deps/AlertToast"]
path = deps/AlertToast
url = https://github.com/fcitx-contrib/AlertToast
27 changes: 20 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ include(AddSwift)
set(KEYBOARD_NAME "Keyboard")
set(KEYBOARD_LANGUAGE "zh-Hans")

set(PREBUILDER_LIB_DIR "${PROJECT_BINARY_DIR}/sysroot/usr/lib")
set(PREBUILDER_SHARE_DIR "${PROJECT_BINARY_DIR}/sysroot/usr/share")
set(FIND_ROOT_PATH "${PROJECT_BINARY_DIR}/sysroot/usr")
set(PREBUILDER_LIB_DIR "${FIND_ROOT_PATH}/lib")
set(PREBUILDER_SHARE_DIR "${FIND_ROOT_PATH}/share")

set(ENV{PKG_CONFIG_PATH} "${PREBUILDER_LIB_DIR}/pkgconfig")

# For dependencies not to be find via pkg-config
set(LibIntl_DIR "${PREBUILDER_LIB_DIR}/cmake")
find_package(LibIntl)
set(fmt_DIR "${PREBUILDER_LIB_DIR}/cmake/fmt")
find_package(fmt)
list(APPEND CMAKE_FIND_ROOT_PATH "${FIND_ROOT_PATH}")

add_subdirectory(deps)

Expand Down Expand Up @@ -76,6 +73,22 @@ option(RIME "" OFF)
set(ADDONS)
set(DEFAULT_INPUT_METHODS)

function(copy_to_keyboard cmd file relative_path)
add_custom_command(TARGET ${BUNDLE_NAME}
POST_BUILD COMMAND /bin/sh -c \"
${CMAKE_COMMAND} -E ${cmd} ${file}
${PROJECT_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/${relative_path}
\")
endfunction()

function(copy_to_app cmd file relative_path)
add_custom_command(TARGET ${BUNDLE_NAME}
POST_BUILD COMMAND /bin/sh -c \"
${CMAKE_COMMAND} -E ${cmd} ${file}
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app/${relative_path}
\")
endfunction()

if (HALLELUJAH)
add_definitions(-DHALLELUJAH)
add_subdirectory(engines/fcitx5-hallelujah)
Expand Down
63 changes: 0 additions & 63 deletions data/default.yaml

This file was deleted.

1 change: 0 additions & 1 deletion data/rime-essay
Submodule rime-essay deleted from e0519d
1 change: 0 additions & 1 deletion data/rime-luna-pinyin
Submodule rime-luna-pinyin deleted from ce5c82
1 change: 0 additions & 1 deletion data/rime-prelude
Submodule rime-prelude deleted from 3803f0
1 change: 0 additions & 1 deletion data/rime-stroke
Submodule rime-stroke deleted from 65fdbb
10 changes: 0 additions & 10 deletions iosfrontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,3 @@ target_include_directories(iosfrontend PUBLIC

configure_file(iosfrontend.conf.in.in iosfrontend.conf.in @ONLY)
fcitx5_translate_desktop_file(${CMAKE_CURRENT_BINARY_DIR}/iosfrontend.conf.in iosfrontend.conf)

add_custom_command(
TARGET iosfrontend
POST_BUILD COMMAND /bin/sh -c
\"
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/iosfrontend.conf
${PROJECT_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/fcitx5/addon/iosfrontend.conf
\"
)
10 changes: 0 additions & 10 deletions iosnotifications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,3 @@ target_link_libraries(iosnotifications Fcitx5::Core Fcitx5::Module::Notification

configure_file(notifications.conf.in.in notifications.conf.in @ONLY)
fcitx5_translate_desktop_file(${CMAKE_CURRENT_BINARY_DIR}/notifications.conf.in notifications.conf)

add_custom_command(
TARGET iosnotifications
POST_BUILD COMMAND /bin/sh -c
\"
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/notifications.conf
${PROJECT_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/fcitx5/addon/notifications.conf
\"
)
9 changes: 0 additions & 9 deletions keyboard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,3 @@ target_link_libraries(keyboard PRIVATE
)

add_dependencies(keyboard gen_profile)
add_custom_command(
TARGET keyboard
POST_BUILD COMMAND /bin/sh -c
\"
${CMAKE_COMMAND} -E copy
${PROJECT_BINARY_DIR}/profile
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/profile
\"
)
4 changes: 2 additions & 2 deletions patches/fcitx5.patch
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ index 85c9865b..edf51a44 100644
)
target_include_directories(Fcitx5Config PUBLIC
diff --git a/src/lib/fcitx-utils/CMakeLists.txt b/src/lib/fcitx-utils/CMakeLists.txt
index dd67e07d..2b942b28 100644
index e1498a14..4dfbe2e1 100644
--- a/src/lib/fcitx-utils/CMakeLists.txt
+++ b/src/lib/fcitx-utils/CMakeLists.txt
@@ -119,23 +119,22 @@ ecm_setup_version(PROJECT
@@ -121,23 +121,22 @@ ecm_setup_version(PROJECT
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/Fcitx5UtilsConfigVersion.cmake"
SOVERSION 2)

Expand Down
46 changes: 1 addition & 45 deletions patches/hallelujah.patch
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,8 @@ index 7ffcf34..a57a061 100644

add_subdirectory(src)
if (ENABLE_TEST)
diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
index 4e8b3f7..eef37ec 100644
--- a/data/CMakeLists.txt
+++ b/data/CMakeLists.txt
@@ -5,3 +5,21 @@ add_custom_target(google ALL
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/google_227800_words.bin" DESTINATION ${DEST_DIR} COMPONENT config)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/words.json" DESTINATION ${DEST_DIR} COMPONENT config)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cedict.json" DESTINATION ${DEST_DIR} COMPONENT config)
+
+add_custom_command(
+ TARGET google
+ POST_BUILD COMMAND /bin/zsh -c
+ \"
+ ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_BINARY_DIR}/google_227800_words.bin
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/hallelujah/google_227800_words.bin
+ \;
+ ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/words.json
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/hallelujah/words.json
+ \;
+ ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/cedict.json
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/hallelujah/cedict.json
+ \"
+)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dcbd627..6b0f00d 100644
index dcbd627..05832b4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,4 +1,4 @@
Expand All @@ -56,24 +30,6 @@ index dcbd627..6b0f00d 100644
target_link_libraries(hallelujah Fcitx5::Core Fcitx5::Module::Spell fmt::fmt ${MARISA_TARGET} ${JSONC_TARGET})
install(TARGETS hallelujah DESTINATION "${FCITX_INSTALL_LIBDIR}/fcitx5")
fcitx5_translate_desktop_file(hallelujah.conf.in hallelujah.conf)
@@ -6,3 +6,17 @@ configure_file(hallelujah-addon.conf.in.in hallelujah-addon.conf.in)
fcitx5_translate_desktop_file("${CMAKE_CURRENT_BINARY_DIR}/hallelujah-addon.conf.in" hallelujah-addon.conf)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hallelujah.conf" DESTINATION "${FCITX_INSTALL_PKGDATADIR}/inputmethod" COMPONENT config)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hallelujah-addon.conf" RENAME hallelujah.conf DESTINATION "${FCITX_INSTALL_PKGDATADIR}/addon" COMPONENT config)
+
+add_custom_command(
+ TARGET hallelujah
+ POST_BUILD COMMAND /bin/sh -c
+ \"
+ ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_BINARY_DIR}/hallelujah-addon.conf
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/fcitx5/addon/hallelujah.conf
+ \;
+ ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_BINARY_DIR}/hallelujah.conf
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/fcitx5/inputmethod/hallelujah.conf
+ \"
+)
diff --git a/src/hallelujah.h b/src/hallelujah.h
index 2dcee57..caf1bec 100644
--- a/src/hallelujah.h
Expand Down
38 changes: 1 addition & 37 deletions patches/rime.patch
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ index 1a1637a..92a41e0 100644
add_subdirectory(po)
add_subdirectory(src)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0854a9a..14c1cd1 100644
index 0854a9a..a3ef4a0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -22,7 +22,9 @@ else()
Expand All @@ -35,42 +35,6 @@ index 0854a9a..14c1cd1 100644
target_link_libraries(rime ${RIME_LINK_LIBRARIES})
install(TARGETS rime DESTINATION "${CMAKE_INSTALL_LIBDIR}/fcitx5")
fcitx5_translate_desktop_file(rime.conf.in rime.conf)
@@ -31,3 +33,35 @@ fcitx5_translate_desktop_file("${CMAKE_CURRENT_BINARY_DIR}/rime-addon.conf.in" r
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rime.conf" DESTINATION "${FCITX_INSTALL_PKGDATADIR}/inputmethod" COMPONENT config)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rime-addon.conf" RENAME rime.conf DESTINATION "${FCITX_INSTALL_PKGDATADIR}/addon" COMPONENT config)

+
+add_custom_command(
+ TARGET rime
+ POST_BUILD COMMAND /bin/sh -c
+ \"
+ ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_BINARY_DIR}/rime-addon.conf
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/fcitx5/addon/rime.conf
+ \;
+ ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_BINARY_DIR}/rime.conf
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/fcitx5/inputmethod/rime.conf
+ \;
+ mkdir -p ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/rime-data
+ \;
+ cp ${CMAKE_SOURCE_DIR}/data/rime-prelude/*.yaml ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/rime-data
+ \;
+ cp ${CMAKE_SOURCE_DIR}/data/rime-essay/essay.txt ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/rime-data
+ \;
+ cp ${CMAKE_SOURCE_DIR}/data/rime-luna-pinyin/*.yaml ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/rime-data
+ \;
+ cp ${CMAKE_SOURCE_DIR}/data/rime-stroke/*.yaml ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/rime-data
+ \;
+ ${CMAKE_COMMAND} -E copy
+ ${CMAKE_SOURCE_DIR}/data/default.yaml
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/rime-data/default.yaml
+ \;
+ ${CMAKE_COMMAND} -E copy_directory
+ ${PREBUILDER_SHARE_DIR}/opencc
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/rime-data/opencc
+ \"
+)
diff --git a/src/rimeengine.cpp b/src/rimeengine.cpp
index 090ee37..e924ba7 100644
--- a/src/rimeengine.cpp
Expand Down
10 changes: 10 additions & 0 deletions scripts/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ done
sed -i '' "s|=/usr/include|=$(pwd)/$EXTRACT_DIR/include|" $EXTRACT_DIR/lib/pkgconfig/{json-c,libuv,marisa,rime}.pc
sed -i '' "s|-L\${libdir} -luv|$(pwd)/$EXTRACT_DIR/lib/libuv.a|" $EXTRACT_DIR/lib/pkgconfig/libuv.pc
sed -E -i '' "s|Libs:.*-l(.*)|Libs: $(pwd)/$EXTRACT_DIR/lib/lib\1.a|" $EXTRACT_DIR/lib/pkgconfig/json-c.pc

plugins=(
rime
)

for plugin in "${plugins[@]}"; do
file=$plugin-any.tar.bz2
[[ -f cache/$file ]] || wget -P cache https://github.com/fcitx-contrib/fcitx5-macos-plugins/releases/download/latest/$file
tar xjvf cache/$file -C $EXTRACT_DIR
done
56 changes: 26 additions & 30 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ target_link_libraries(${BUNDLE_NAME} PRIVATE
${ADDONS}
)

# Make main app the last target so that keyboard can be copied into it.
add_dependencies(${BUNDLE_NAME} keyboard)

set_target_properties(${BUNDLE_NAME} PROPERTIES
Expand All @@ -45,36 +46,31 @@ set_target_properties(${BUNDLE_NAME} PROPERTIES

set_xcode_property(${BUNDLE_NAME} CODE_SIGN_ENTITLEMENTS ${PROJECT_SOURCE_DIR}/assets/app.entitlements)

add_custom_command(
TARGET ${BUNDLE_NAME}
POST_BUILD COMMAND /bin/sh -c
\"
${CMAKE_COMMAND} -E copy_directory
${PROJECT_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app/PlugIns/keyboard.appex
\"
)
copy_to_keyboard(copy "${PROJECT_BINARY_DIR}/profile" profile)
copy_to_keyboard(copy "${PROJECT_BINARY_DIR}/iosfrontend/iosfrontend.conf" "share/fcitx5/addon/iosfrontend.conf")
copy_to_keyboard(copy "${PROJECT_BINARY_DIR}/iosnotifications/notifications.conf" "share/fcitx5/addon/notifications.conf")
copy_to_keyboard(copy "${PROJECT_BINARY_DIR}/uipanel/uipanel.conf" "share/fcitx5/addon/uipanel.conf")

if (HALLELUJAH)
set(HALLELUJAH_SOURCE_DIR "${PROJECT_SOURCE_DIR}/engines/fcitx5-hallelujah")
set(HALLELUJAH_BINARY_DIR "${PROJECT_BINARY_DIR}/engines/fcitx5-hallelujah")
copy_to_keyboard(copy "${HALLELUJAH_BINARY_DIR}/data/google_227800_words.bin" "share/hallelujah/google_227800_words.bin")
copy_to_keyboard(copy "${HALLELUJAH_SOURCE_DIR}/data/words.json" "share/hallelujah/words.json")
copy_to_keyboard(copy "${HALLELUJAH_SOURCE_DIR}/data/cedict.json" "share/hallelujah/cedict.json")
copy_to_keyboard(copy "${HALLELUJAH_BINARY_DIR}/src/hallelujah-addon.conf" "share/fcitx5/addon/hallelujah.conf")
copy_to_keyboard(copy "${HALLELUJAH_BINARY_DIR}/src/hallelujah.conf" "share/fcitx5/inputmethod/hallelujah.conf")
endif()

if (RIME)
set(RIME_BINARY_DIR "${PROJECT_BINARY_DIR}/engines/fcitx5-rime")
copy_to_keyboard(copy "${RIME_BINARY_DIR}/src/rime-addon.conf" "share/fcitx5/addon/rime.conf")
copy_to_keyboard(copy "${RIME_BINARY_DIR}/src/rime.conf" "share/fcitx5/inputmethod/rime.conf")
copy_to_keyboard(copy_directory "${PREBUILDER_SHARE_DIR}/rime-data" "share/rime-data")
endif()

# Embed keyboard.appex in app.
copy_to_app(copy_directory "${PROJECT_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex" "PlugIns/keyboard.appex")
# Copy share directory, icon and profile.
add_custom_command(
TARGET ${BUNDLE_NAME}
POST_BUILD COMMAND /bin/sh -c
\"
${CMAKE_COMMAND} -E copy_directory
${PROJECT_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app/PlugIns/keyboard.appex
\;
${CMAKE_COMMAND} -E copy_directory
${PROJECT_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app/share
\;
${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/assets/${ICON_FILE}
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app
\;
${CMAKE_COMMAND} -E copy
${PROJECT_BINARY_DIR}/profile
${PROJECT_BINARY_DIR}/src/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/${BUNDLE_NAME}.app/profile
\"
)
copy_to_app(copy_directory "${PROJECT_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share" "share")
copy_to_app(copy "${PROJECT_SOURCE_DIR}/assets/${ICON_FILE}" "${ICON_FILE}")
copy_to_app(copy "${PROJECT_BINARY_DIR}/profile" profile)
Loading