summaryrefslogtreecommitdiff
path: root/cmake/FindCLucene.cmake
blob: 0930d95d89061f4eb158b2f11426663dd4d1fc56 (plain)
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
#
# SOURCE: http://websvn.kde.org/trunk/kdesupport/strigi/cmake/FindCLucene.cmake?view=log
#
# ONE FIX: /usr/lib64 added to work on Fedora
#

#
# This module looks for clucene (http://clucene.sf.net) support
# It will define the following values
#
# CLucene_INCLUDE_DIR  = where CLucene/StdHeader.h can be found
# CLucene_LIBRARY_DIR  = where CLucene/clucene-config.h can be found
# CLucene_LIBRARY      = the library to link against CLucene
# CLucene_VERSION      = The CLucene version string
# CLucene_FOUND        = set to 1 if clucene is found
#

INCLUDE(KDE4FindLibraryWithDebug)

IF(NOT CLucene_MIN_VERSION)
  SET(CLucene_MIN_VERSION "0.9.19")
ENDIF()

FIND_LIBRARY_WITH_DEBUG(CLucene_LIBRARY
                        NAMES clucene clucene-core clucene-cored)
IF(CLucene_LIBRARY)
  MESSAGE(STATUS "Found CLucene library: ${CLucene_LIBRARY}")
ENDIF()
FIND_PATH(CLucene_INCLUDE_DIR NAMES CLucene.h)

IF(CLucene_INCLUDE_DIR)
  MESSAGE(STATUS "Found CLucene include dir: ${CLucene_INCLUDE_DIR}")
ENDIF()

SET(CLucene_GOOD_VERSION TRUE)

# Work around clucene-config.h being installed in weird places on some distros:
GET_FILENAME_COMPONENT(CLucene_LIBRARY_DIR_HINTS "${CLucene_LIBRARY}" PATH)

FIND_PATH(CLucene_LIBRARY_DIR
          NAMES "CLucene/clucene-config.h"
          HINTS "${CLucene_LIBRARY_DIR_HINTS}")
IF(CLucene_LIBRARY_DIR)
  MESSAGE(STATUS "Found CLucene library dir: ${CLucene_LIBRARY_DIR}")
  FILE(READ ${CLucene_LIBRARY_DIR}/CLucene/clucene-config.h CLCONTENT)
  STRING(REGEX MATCH "_CL_VERSION +\".*\"" CLMATCH ${CLCONTENT})
  IF(CLMATCH)
    STRING(REGEX REPLACE "_CL_VERSION +\"(.*)\"" "\\1" CLucene_VERSION ${CLMATCH})
    IF(CLucene_VERSION VERSION_LESS "${CLucene_MIN_VERSION}")
      MESSAGE(ERROR " CLucene version ${CLucene_VERSION} is less than the required minimum ${CLucene_MIN_VERSION}")
      SET(CLucene_GOOD_VERSION FALSE)
    ENDIF()
    IF(CLucene_VERSION VERSION_GREATER "2.0.0")
      ADD_DEFINITIONS(-DCLUCENE2)
      FIND_LIBRARY_WITH_DEBUG(CLucene_SHARED_LIB
                              NAMES clucene-shared clucene-sharedd)
      IF(CLucene_SHARED_LIB)
        MESSAGE(STATUS "Found CLucene shared library: ${CLucene_SHARED_LIB}")
        SET(CLucene_LIBRARY ${CLucene_LIBRARY} ${CLucene_SHARED_LIB})
      ELSE()
        MESSAGE(FATAL_ERROR "Unable to find CLucene shared library.")
        SET(CLucene_GOOD_VERSION FALSE)
      ENDIF()
    ENDIF()
  ENDIF()
ELSE()
  MESSAGE(STATUS "CLucene library dir not found.")
ENDIF()

IF(CLucene_INCLUDE_DIR AND CLucene_LIBRARY AND CLucene_LIBRARY_DIR AND CLucene_GOOD_VERSION)
  SET(CLucene_FOUND TRUE)
ENDIF()

IF(CLucene_FOUND)
  IF(NOT CLucene_FIND_QUIETLY)
    MESSAGE(STATUS "Found CLucene: ${CLucene_LIBRARY}")
  ENDIF()
ELSE()
  IF(CLucene_FIND_REQUIRED)
    MESSAGE(FATAL_ERROR "Could not find CLucene.")
  ENDIF()
ENDIF()

MARK_AS_ADVANCED(CLucene_INCLUDE_DIR CLucene_LIBRARY_DIR CLucene_LIBRARY)