From a2b09de92a73dfa4ae43d3ac8a4ffa1aa791f6c5 Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Sun, 22 Nov 2020 23:42:44 -0800 Subject: [PATCH] Allow set CLDR dir Fix #154 --- CMakeLists.txt | 22 +++++++++++++++++++--- config.h.in | 2 +- src/modules/emoji/CMakeLists.txt | 2 +- src/modules/emoji/emoji.cpp | 8 +++----- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6763dd06..fc84b4b68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,19 @@ option(ENABLE_WAYLAND "Enable wayland support" On) option(ENABLE_DOC "Build doxygen" Off) option(USE_SYSTEMD "Use systemd for event loop and dbus, will fallback to libevent/libdbus if not found." On) option(ENABLE_XDGAUTOSTART "Enable xdg autostart desktop file installation" On) +set(CLDR_DIR "" CACHE STRING "Unicode CLDR (Common Locale Data Repository) directory") + +if (CLDR_DIR STREQUAL "") + if (IS_DIRECTORY "${CMAKE_INSTALL_FULL_DATADIR}/unicode/cldr") + set(CLDR_DIR "${CMAKE_INSTALL_FULL_DATADIR}/unicode/cldr") + else(IS_DIRECTORY "/usr/share/unicode/cldr") + set(CLDR_DIR "/usr/share/unicode/cldr") + endif() +endif() + +if (NOT IS_DIRECTORY "${CLDR_DIR}") + message(FATAL_ERROR "Could not find Unicode CLDR directory") +endif() ####################################################################### # Find packages @@ -73,7 +86,6 @@ pkg_check_modules(CairoXCB IMPORTED_TARGET cairo-xcb) pkg_check_modules(Pango IMPORTED_TARGET pango pangocairo) pkg_check_modules(GdkPixbuf IMPORTED_TARGET gdk-pixbuf-2.0) pkg_check_modules(GioUnix IMPORTED_TARGET gio-unix-2.0) -pkg_check_modules(CldrEmojiAnnotation REQUIRED IMPORTED_TARGET cldr-emoji-annotation) if (ENABLE_WAYLAND) find_package(Wayland REQUIRED COMPONENTS Client Egl) @@ -106,10 +118,14 @@ else() set(WAYLAND_FOUND FALSE) endif() +if (NOT EXISTS "${CLDR_DIR}") + message(FATAL_ERROR "Could not find Unicode CLDR directory: ${CLDR_DIR}") +endif() + set(DEFAULT_XKB_RULES_FILES "${XKEYBOARDCONFIG_XKBBASE}/rules/${DEFAULT_XKB_RULES}.xml") if (NOT EXISTS "${DEFAULT_XKB_RULES_FILES}") -message(FATAL_ERROR "Could not find default xkb rules file: ${DEFAULT_XKB_RULES_FILES}") -endif () + message(FATAL_ERROR "Could not find default xkb rules file: ${DEFAULT_XKB_RULES_FILES}") +endif() # directory needed by bsd if(NOT CMAKE_INSTALL_LIBDATADIR) diff --git a/config.h.in b/config.h.in index 09bf002cf..429115256 100644 --- a/config.h.in +++ b/config.h.in @@ -33,7 +33,7 @@ #cmakedefine HAS_DLMOPEN #define XKEYBOARDCONFIG_DATADIR "@XKEYBOARDCONFIG_DATADIR@" #define DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@" -#define CLDR_EMOJI_ANNOTATION_PREFIX "@CldrEmojiAnnotation_PREFIX@" +#define CLDR_DIR "@CLDR_DIR@" #ifndef _GNU_SOURCE #define _GNU_SOURCE diff --git a/src/modules/emoji/CMakeLists.txt b/src/modules/emoji/CMakeLists.txt index 9fa84bbb6..57ae48bd1 100644 --- a/src/modules/emoji/CMakeLists.txt +++ b/src/modules/emoji/CMakeLists.txt @@ -1,4 +1,4 @@ -if (NOT IS_DIRECTORY ${CldrEmojiAnnotation_PREFIX}/share/unicode/cldr/common/annotations) +if ("${CLDR_DIR}" STREQUAL "" OR NOT IS_DIRECTORY "${CLDR_DIR}/common/annotations") return() endif() diff --git a/src/modules/emoji/emoji.cpp b/src/modules/emoji/emoji.cpp index 5606a37c5..805aef7df 100644 --- a/src/modules/emoji/emoji.cpp +++ b/src/modules/emoji/emoji.cpp @@ -126,7 +126,7 @@ bool noSpace(const std::string &str) { const EmojiMap *Emoji::loadEmoji(const std::string &language, bool fallbackToEn) { - // This is to match the file in cldr-emoji-annotation. + // This is to match the file in CLDR. static const std::unordered_map languageMap = { {"zh_TW", "zh_Hant"}, {"zh_CN", "zh"}, {"zh_HK", "zh_Hant_HK"}}; @@ -172,10 +172,8 @@ const EmojiMap *Emoji::loadEmoji(const std::string &language, return utf8::lengthValidated(str) > 2; }}}; const auto *filter = findValue(filterMap, lang); - const auto file = - stringutils::joinPath(CLDR_EMOJI_ANNOTATION_PREFIX, - "/share/unicode/cldr/common/annotations", - stringutils::concat(lang, ".xml")); + const auto file = stringutils::joinPath( + CLDR_DIR, "/common/annotations", stringutils::concat(lang, ".xml")); EmojiParser parser(filter ? *filter : nullptr); if (parser.parse(file)) { emojiMap = &(langToEmojiMap_[lang] = std::move(parser.emojiMap_));