File: FindEnchant.cmake

package info (click to toggle)
fcitx 1%3A4.2.9.9-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,800 kB
  • sloc: ansic: 134,151; cpp: 7,280; sh: 2,778; python: 800; xml: 345; makefile: 42
file content (85 lines) | stat: -rw-r--r-- 3,156 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# - Try to find the Enchant libraries
# Once done this will define
#
#  ENCHANT_FOUND - system has ENCHANT
#  ENCHANT_INCLUDE_DIR - the ENCHANT include directory
#  ENCHANT_LIBRARIES - ENCHANT library
#
# Copyright (c) 2012 CSSlayer <wengxt@gmail.com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

if(ENCHANT_INCLUDE_DIR AND ENCHANT_LIBRARIES)
  # Already in cache, be silent
  set(ENCHANT_FIND_QUIETLY TRUE)
endif(ENCHANT_INCLUDE_DIR AND ENCHANT_LIBRARIES)

find_package(PkgConfig)
pkg_check_modules(PC_ENCHANT enchant-2 enchant)

find_path(ENCHANT_INCLUDE_DIR
  NAMES enchant.h
  HINTS ${PC_ENCHANT_INCLUDE_DIRS}
  PATH_SUFFIXES enchant-2 enchant)

find_library(ENCHANT_LIBRARIES
  NAMES enchant-2 enchant
  HINTS ${PC_ENCHANT_LIBRARY_DIRS})

if(ENCHANT_INCLUDE_DIR AND ENCHANT_LIBRARIES)
  check_c_compiler_flag("-Werror" ENCHANT_HAVE_WERROR)
  set(CMAKE_C_FLAGS_BACKUP "${CMAKE_C_FLAGS}")
  if(ENCHANT_HAVE_WERROR)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
  endif(ENCHANT_HAVE_WERROR)
  set(CMAKE_REQUIRED_INCLUDES "${ENCHANT_INCLUDE_DIR}")
  set(CMAKE_REQUIRED_LIBRARIES "${ENCHANT_LIBRARIES}")
  check_c_source_compiles("
  #include <stdlib.h>
  #include <stddef.h>
  #include <string.h>
  #include <enchant.h>

  EnchantBroker *enchant_broker_init();
  char **enchant_dict_suggest(EnchantDict *dict, const char *str,
                              ssize_t len, size_t *out_n);
  void enchant_dict_free_string_list(EnchantDict *dict, char **str_list);
  void enchant_broker_free_dict(EnchantBroker *broker, EnchantDict *dict);
  void enchant_broker_free(EnchantBroker *broker);
  EnchantDict *enchant_broker_request_dict(EnchantBroker *broker,
                                           const char *const tag);
  void enchant_broker_set_ordering(EnchantBroker *broker,
                                   const char *const tag,
                                   const char *const ordering);
  void enchant_dict_add(EnchantDict *dict, const char *const word,
                                    ssize_t len);

  int main()
  {
      void *enchant;
      void *dict;
      char **suggestions = NULL;
      size_t number;
      enchant = enchant_broker_init();
      enchant_broker_set_ordering(enchant, \"*\", \"aspell,myspell,ispell\");
      dict = enchant_broker_request_dict(enchant, \"en\");
      enchant_dict_add(dict, \"Fcitx\", strlen(\"Fcitx\"));
      suggestions = enchant_dict_suggest(dict, \"Fcitx\", strlen(\"Fcitx\"),
                                         &number);
      enchant_dict_free_string_list(dict, suggestions);
      enchant_broker_free_dict(enchant, dict);
      enchant_broker_free(enchant);
      return 0;
  }
  " ENCHANT_API_COMPATIBLE)
  set(CMAKE_REQUIRED_INCLUDES)
  set(CMAKE_REQUIRED_LIBRARIES)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BACKUP}")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Enchant DEFAULT_MSG ENCHANT_LIBRARIES
  ENCHANT_INCLUDE_DIR ENCHANT_API_COMPATIBLE)

mark_as_advanced(ENCHANT_INCLUDE_DIR ENCHANT_LIBRARIES PC_ENCHANT_INCLUDEDIR PC_ENCHANT_LIBDIR)