File: FindOpenCC.cmake

package info (click to toggle)
fcitx 1%3A4.2.9.9-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 19,800 kB
  • sloc: ansic: 134,151; cpp: 7,280; sh: 2,778; python: 800; xml: 345; makefile: 42
file content (58 lines) | stat: -rw-r--r-- 1,732 bytes parent folder | download | duplicates (7)
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
# - Try to find the Opencc libraries
# Once done this will define
#
#  OPENCC_FOUND - system has OPENCC
#  OPENCC_INCLUDE_DIR - the OPENCC include directory
#  OPENCC_LIBRARIES - OPENCC 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(OPENCC_INCLUDE_DIR AND OPENCC_LIBRARIES)
  # Already in cache, be silent
  set(OPENCC_FIND_QUIETLY TRUE)
endif(OPENCC_INCLUDE_DIR AND OPENCC_LIBRARIES)

find_package(PkgConfig)
pkg_check_modules(PC_OPENCC opencc)

find_path(OPENCC_INCLUDE_DIR
  NAMES opencc.h
  HINTS ${PC_OPENCC_INCLUDE_DIRS}
)

find_library(OPENCC_LIBRARIES
  NAMES opencc
  HINTS ${PC_OPENCC_LIBDIR})

if(OPENCC_INCLUDE_DIR AND OPENCC_LIBRARIES)
  check_c_compiler_flag("-Werror" OPENCC_HAVE_WERROR)
  set(CMAKE_C_FLAGS_BACKUP "${CMAKE_C_FLAGS}")
  if(OPENCC_HAVE_WERROR)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
  endif(OPENCC_HAVE_WERROR)
  set(CMAKE_REQUIRED_INCLUDES "${OPENCC_INCLUDE_DIR}")
  set(CMAKE_REQUIRED_LIBRARIES "${OPENCC_LIBRARIES}")
  check_c_source_compiles("
  #include <opencc.h>

  opencc_t opencc_open(const char* config_file);
  char* opencc_convert_utf8(opencc_t opencc, const char* inbuf, size_t length);

  int main()
  {
      return 0;
  }
  " OPENCC_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(OpenCC DEFAULT_MSG OPENCC_LIBRARIES
  OPENCC_INCLUDE_DIR OPENCC_API_COMPATIBLE)

mark_as_advanced(OPENCC_INCLUDE_DIR OPENCC_LIBRARIES PC_OPENCC_INCLUDEDIR PC_OPENCC_LIBDIR)