OSDN Git Service

make ICU support non-runtime
authorIvailo Monev <xakepa10@gmail.com>
Sat, 23 Jul 2016 22:49:32 +0000 (22:49 +0000)
committerIvailo Monev <xakepa10@gmail.com>
Sat, 23 Jul 2016 22:49:32 +0000 (22:49 +0000)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/tools/qlocale_icu.cpp
src/core/tools/tools.cmake

index 0b2ac2c..c0e321b 100644 (file)
 #include "qlibrary.h"
 #include "qdebug.h"
 
-#include "unicode/uversion.h"
-#include "unicode/ucol.h"
+#include <unicode/ucol.h>
 
 QT_BEGIN_NAMESPACE
 
-typedef UCollator *(*Ptr_ucol_open)(const char *loc, UErrorCode *status);
-typedef void (*Ptr_ucol_close)(UCollator *coll);
-typedef UCollationResult (*Ptr_ucol_strcoll)(const UCollator *coll, const UChar *source, int32_t sourceLength, const UChar *target, int32_t targetLength);
 typedef int32_t (*Ptr_u_strToCase)(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, const char *locale, UErrorCode *pErrorCode);
 
-static Ptr_ucol_open ptr_ucol_open = 0;
-static Ptr_ucol_strcoll ptr_ucol_strcoll = 0;
-static Ptr_ucol_close ptr_ucol_close = 0;
-static Ptr_u_strToCase ptr_u_strToUpper = 0;
-static Ptr_u_strToCase ptr_u_strToLower = 0;
-
-enum LibLoadStatus
-{
-    ErrorLoading = -1,
-    NotLoaded = 0,
-    Loaded = 1
-};
-
-static LibLoadStatus status = NotLoaded;
-
 static UCollator *icuCollator = 0;
 
-#define STRINGIFY2(x) #x
-#define STRINGIFY(x) STRINGIFY2(x)
-
 bool qt_initIcu(const QString &localeString)
 {
-    if (status == ErrorLoading)
-        return false;
-
-#ifdef QT_NO_LIBRARY
-    status = ErrorLoading;
-    return false;
-#else
-    if (status == NotLoaded) {
-
-        // resolve libicui18n
-        QLibrary lib(QLatin1String("icui18n"), QLatin1String(U_ICU_VERSION_SHORT));
-        lib.setLoadHints(QLibrary::ImprovedSearchHeuristics);
-        if (!lib.load()) {
-            qWarning() << "Unable to load library icui18n" << lib.errorString();
-            status = ErrorLoading;
-            return false;
-        }
-
-        ptr_ucol_open = (Ptr_ucol_open)lib.resolve("ucol_open");
-        ptr_ucol_close = (Ptr_ucol_close)lib.resolve("ucol_close");
-        ptr_ucol_strcoll = (Ptr_ucol_strcoll)lib.resolve("ucol_strcoll");
-
-        if (!ptr_ucol_open || !ptr_ucol_close || !ptr_ucol_strcoll) {
-            // try again with decorated symbol names
-            ptr_ucol_open = (Ptr_ucol_open)lib.resolve("ucol_open" STRINGIFY(U_ICU_VERSION_SUFFIX));
-            ptr_ucol_close = (Ptr_ucol_close)lib.resolve("ucol_close" STRINGIFY(U_ICU_VERSION_SUFFIX));
-            ptr_ucol_strcoll = (Ptr_ucol_strcoll)lib.resolve("ucol_strcoll" STRINGIFY(U_ICU_VERSION_SUFFIX));
-        }
-
-        if (!ptr_ucol_open || !ptr_ucol_close || !ptr_ucol_strcoll) {
-            ptr_ucol_open = 0;
-            ptr_ucol_close = 0;
-            ptr_ucol_strcoll = 0;
-
-            qWarning("Unable to find symbols in icui18n");
-            status = ErrorLoading;
-            return false;
-        }
-
-        // resolve libicuuc
-        QLibrary ucLib(QLatin1String("icuuc"), QLatin1String(U_ICU_VERSION_SHORT));
-        ucLib.setLoadHints(QLibrary::ImprovedSearchHeuristics);
-        if (!ucLib.load()) {
-            qWarning() << "Unable to load library icuuc" << ucLib.errorString();
-            status = ErrorLoading;
-            return false;
-        }
-
-        ptr_u_strToUpper = (Ptr_u_strToCase)ucLib.resolve("u_strToUpper");
-        ptr_u_strToLower = (Ptr_u_strToCase)ucLib.resolve("u_strToLower");
-
-        if (!ptr_u_strToUpper || !ptr_u_strToLower) {
-            ptr_u_strToUpper = (Ptr_u_strToCase)ucLib.resolve("u_strToUpper" STRINGIFY(U_ICU_VERSION_SUFFIX));
-            ptr_u_strToLower = (Ptr_u_strToCase)ucLib.resolve("u_strToLower" STRINGIFY(U_ICU_VERSION_SUFFIX));
-        }
-
-        if (!ptr_u_strToUpper || !ptr_u_strToLower) {
-            ptr_u_strToUpper = 0;
-            ptr_u_strToLower = 0;
-
-            qWarning("Unable to find symbols in icuuc");
-            status = ErrorLoading;
-            return false;
-        }
-
-        // success :)
-        status = Loaded;
-    }
-#endif // QT_NO_LIBRARY
-
     if (icuCollator) {
-        ptr_ucol_close(icuCollator);
+        ucol_close(icuCollator);
         icuCollator = 0;
     }
 
     UErrorCode icuStatus = U_ZERO_ERROR;
-    icuCollator = ptr_ucol_open(localeString.toLatin1().constData(), &icuStatus);
+    icuCollator = ucol_open(localeString.toLatin1().constData(), &icuStatus);
 
     if (!icuCollator) {
         qWarning("Unable to open locale %s in ICU, error code %d", qPrintable(localeString), icuStatus);
@@ -170,7 +78,7 @@ bool qt_ucol_strcoll(const QChar *source, int sourceLength, const QChar *target,
     if (!icuCollator)
         return false;
 
-    *result = ptr_ucol_strcoll(icuCollator, reinterpret_cast<const UChar *>(source), int32_t(sourceLength),
+    *result = ucol_strcoll(icuCollator, reinterpret_cast<const UChar *>(source), int32_t(sourceLength),
                                reinterpret_cast<const UChar *>(target), int32_t(targetLength));
 
     return true;
@@ -220,12 +128,12 @@ static bool qt_u_strToCase(const QString &str, QString *out, const QLocale &loca
 
 bool qt_u_strToUpper(const QString &str, QString *out, const QLocale &locale)
 {
-    return qt_u_strToCase(str, out, locale, ptr_u_strToUpper);
+    return qt_u_strToCase(str, out, locale, u_strToUpper);
 }
 
 bool qt_u_strToLower(const QString &str, QString *out, const QLocale &locale)
 {
-    return qt_u_strToCase(str, out, locale, ptr_u_strToLower);
+    return qt_u_strToCase(str, out, locale, u_strToLower);
 }
 
 QT_END_NAMESPACE
index aba2af4..0b0335e 100644 (file)
@@ -134,6 +134,10 @@ if(WITH_ICU AND ICU_FOUND)
         ${CORE_SOURCES}
         ${CMAKE_CURRENT_SOURCE_DIR}/tools/qlocale_icu.cpp
     )
+    set(EXTRA_CORE_LIBS
+        ${EXTRA_CORE_LIBS}
+        ${ICU_LIBRARIES}
+    )
     add_definitions(-DQT_USE_ICU)
     include_directories(${ICU_INCLUDES})
 endif()
@@ -143,9 +147,7 @@ if(WITH_HARFBUZZ AND HARFBUZZ_FOUND)
         ${EXTRA_CORE_LIBS}
         ${HARFBUZZ_LIBRARIES}
     )
-    include_directories(
-        ${HARFBUZZ_INCLUDE_DIRS}
-    )
+    include_directories(${HARFBUZZ_INCLUDE_DIRS})
 else()
     # TODO: move to main CMakeLists?
     add_definitions(-DHB_EXPORT=Q_CORE_EXPORT)