]> git.lyx.org Git - lyx.git/commitdiff
Add support for enchant 2.x
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 24 Jan 2018 15:19:34 +0000 (16:19 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 30 Jan 2018 11:11:22 +0000 (12:11 +0100)
As of enchant 2.x, it is required to create a Broker instance instead
of relying on a static one provided by the library.

Add autoconf and cmake (courtesy of Kornel) tests that check whether
one can indeed instantiate a Broker object, and act on the result in a
new broker() helper function.

Fixes bug #10986.

config/spell.m4
development/cmake/ConfigureChecks.cmake
development/cmake/config.h.cmake
src/EnchantChecker.cpp

index 8185939c4250ad2a904c54d5ff43c9bfaaee83c0..5810f17eed5e1055c50dca4dfda2accb5b9c8efc 100644 (file)
@@ -23,7 +23,21 @@ AC_DEFUN([CHECK_WITH_ASPELL],
        fi
        ])
 
-# Macro to add for using enchant spellchecker libraries!     -*- sh -*-
+AC_DEFUN([LYX_HAVE_ENCHANT2],
+[
+  AC_MSG_CHECKING([whether enchant is version 2.x at least])
+  save_CXXFLAGS=$CXXFLAGS
+  CXXFLAGS="$ENCHANT_CFLAGS $AM_CXXFLAGS $CXXFLAGS"
+
+  AC_TRY_COMPILE([#include <enchant++.h>],
+      [enchant::Broker broker;],
+      [AC_MSG_RESULT(yes)
+       AC_DEFINE(HAVE_ENCHANT2, 1, [Define to 1 if enchant 2.x is detected])
+      ],
+      [AC_MSG_RESULT(no)])
+  CXXFLAGS=$save_CXXFLAGS
+])
+
 AC_DEFUN([CHECK_WITH_ENCHANT],
 [
        lyx_use_enchant=true
@@ -36,6 +50,7 @@ AC_DEFUN([CHECK_WITH_ENCHANT],
                if $lyx_use_enchant ; then
                    AC_MSG_RESULT(yes)
                    AC_DEFINE(USE_ENCHANT, 1, [Define as 1 to use the enchant library])
+                   LYX_HAVE_ENCHANT2
                    lyx_flags="$lyx_flags use-enchant"
                else
                    AC_MSG_RESULT(no)
index f09ba8bd921c460d69d83f1d3d10f9664558009e..d2695b041ad116510eff824a9d4a85e6ba2c5cfc 100644 (file)
@@ -195,6 +195,24 @@ check_cxx_source_compiles(
   "
 LYX_USE_STD_CALL_ONCE)
 
+if (ENCHANT_FOUND)
+  set(CMAKE_REQUIRED_INCLUDES ${ENCHANT_INCLUDE_DIR})
+  set(CMAKE_REQUIRED_LIBRARIES ${ENCHANT_LIBRARY})
+  # Check, whether enchant is version 2.x at least
+  check_cxx_source_compiles(
+    "
+    #include <enchant++.h>
+    enchant::Broker broker;
+    int main() {
+      return(0);
+    }
+    "
+  HAVE_ENCHANT2)
+  if (HAVE_ENCHANT2)
+    message(STATUS "ENCHANT2 found")
+  endif()
+endif()
+
 set(USE_LLVM_LIBCPP)
 set(STD_STRING_USES_COW)
 set(USE_GLIBCXX_CXX11_ABI)
index 7fac0b00b574b1f569d4448b9f7f7d13ecf26efa..fd08c45587e358c848dd54887229ec0004f1db3c 100644 (file)
@@ -88,6 +88,9 @@ ${Include_used_spellchecker}
 // Define to 1 if std::call_once is supported by the compiler
 #cmakedefine LYX_USE_STD_CALL_ONCE 1
 
+// Define to 1 if enchant is version 2.x at least
+#cmakedefine HAVE_ENCHANT2 1
+
 #endif // config.h guard
 
 #define MYTHES_H_LOCATION <${MYTHES_DIR}/mythes.hxx>
index 5ef399a24ad14ea8769d387223fd36a2a5e69793..47eb35e52ec208eaa331a5ecaba3786c65e20212 100644 (file)
@@ -30,6 +30,17 @@ namespace lyx {
 
 namespace {
 
+enchant::Broker & broker()
+{
+#ifdef HAVE_ENCHANT2
+       static enchant::Broker thebroker;
+       return thebroker;
+#else
+       return *enchant::Broker::instance();
+#endif
+}
+
+
 struct Speller {
        enchant::Dict * speller;
 };
@@ -68,12 +79,11 @@ EnchantChecker::Private::~Private()
 
 enchant::Dict * EnchantChecker::Private::addSpeller(string const & lang)
 {
-       enchant::Broker * instance = enchant::Broker::instance();
        Speller m;
 
        try {
                LYXERR(Debug::FILES, "request enchant speller for language " << lang);
-               m.speller = instance->request_dict(lang);
+               m.speller = broker().request_dict(lang);
        }
        catch (enchant::Exception & e) {
                // FIXME error handling?
@@ -186,8 +196,7 @@ bool EnchantChecker::hasDictionary(Language const * lang) const
 {
        if (!lang)
                return false;
-       enchant::Broker * instance = enchant::Broker::instance();
-       return (instance->dict_exists(lang->code()));
+       return broker().dict_exists(lang->code());
 }