forked from Eyescale/CMake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Findleveldb.cmake
116 lines (106 loc) · 3.8 KB
/
Findleveldb.cmake
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright (c) 2014 Stefan.Eilemann@epfl.ch
# - Try to find the Leveldb library
# Once done this will define
#
# LEVELDB_ROOT - Set this variable to the root installation
#
# Read-Only variables:
# LEVELDB_FOUND - system has the Leveldb library
# LEVELDB_INCLUDE_DIR - the Leveldb include directory
# LEVELDB_LIBRARIES - The libraries needed to use Leveldb
# LEVELDB_VERSION - This is set to $major.$minor.$patch (eg. 0.9.8)
include(FindPackageHandleStandardArgs)
if(leveldb_FIND_REQUIRED)
set(_LEVELDB_output_type FATAL_ERROR)
else()
set(_LEVELDB_output_type STATUS)
endif()
if(leveldb_FIND_QUIETLY)
set(_LEVELDB_output)
else()
set(_LEVELDB_output 1)
endif()
find_path(_LEVELDB_INCLUDE_DIR leveldb/db.h
HINTS ${CMAKE_SOURCE_DIR}/../../.. $ENV{LEVELDB_ROOT} ${LEVELDB_ROOT}
PATH_SUFFIXES include
PATHS /usr /usr/local /opt /opt/local)
if(_LEVELDB_INCLUDE_DIR AND EXISTS "${_LEVELDB_INCLUDE_DIR}/leveldb/db.h")
set(_LEVELDB_Version_file "${_LEVELDB_INCLUDE_DIR}/leveldb/db.h")
file(READ ${_LEVELDB_Version_file} _LEVELDB_header_contents)
string(REGEX REPLACE ".*kMajorVersion = ([0-9]+).*kMinorVersion = ([0-9]+).*"
"\\1.\\2" _LEVELDB_VERSION "${_LEVELDB_header_contents}")
set(LEVELDB_VERSION ${_LEVELDB_VERSION} CACHE INTERNAL
"The version of leveldb which was detected")
else()
set(_LEVELDB_EPIC_FAIL TRUE)
if(_LEVELDB_output)
message(${_LEVELDB_output_type}
"Can't find leveldb header file leveldb/db.h.")
endif()
endif()
# Version checking
if(LEVELDB_FIND_VERSION AND LEVELDB_VERSION)
if(LEVELDB_FIND_VERSION_EXACT)
if(NOT LEVELDB_VERSION VERSION_EQUAL ${LEVELDB_FIND_VERSION})
set(_LEVELDB_version_not_exact TRUE)
endif()
else()
# version is too low
if(NOT LEVELDB_VERSION VERSION_EQUAL ${LEVELDB_FIND_VERSION} AND
NOT LEVELDB_VERSION VERSION_GREATER ${LEVELDB_FIND_VERSION})
set(_LEVELDB_version_not_high_enough TRUE)
endif()
endif()
endif()
find_library(LEVELDB_LIBRARY leveldb
HINTS ${CMAKE_SOURCE_DIR}/../../.. $ENV{LEVELDB_ROOT} ${LEVELDB_ROOT}
PATH_SUFFIXES lib lib64
PATHS /usr /usr/local /opt /opt/local)
# Inform the users with an error message based on what version they
# have vs. what version was required.
if(NOT LEVELDB_VERSION)
set(_LEVELDB_EPIC_FAIL TRUE)
if(_LEVELDB_output)
message(${_LEVELDB_output_type}
"Version not found in ${_LEVELDB_Version_file}.")
endif()
elseif(_LEVELDB_version_not_high_enough)
set(_LEVELDB_EPIC_FAIL TRUE)
if(_LEVELDB_output)
message(${_LEVELDB_output_type}
"Version ${LEVELDB_FIND_VERSION} or higher of leveldb is required. "
"Version ${LEVELDB_VERSION} was found in ${_LEVELDB_Version_file}.")
endif()
elseif(_LEVELDB_version_not_exact)
set(_LEVELDB_EPIC_FAIL TRUE)
if(_LEVELDB_output)
message(${_LEVELDB_output_type}
"Version ${LEVELDB_FIND_VERSION} of leveldb is required exactly. "
"Version ${LEVELDB_VERSION} was found.")
endif()
else()
if(leveldb_FIND_REQUIRED)
if(LEVELDB_LIBRARY MATCHES "LEVELDB_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Missing the leveldb library.\n"
"Consider using CMAKE_PREFIX_PATH or the LEVELDB_ROOT environment variable. "
"See the ${CMAKE_CURRENT_LIST_FILE} for more details.")
endif()
endif()
find_package_handle_standard_args(leveldb DEFAULT_MSG
LEVELDB_LIBRARY _LEVELDB_INCLUDE_DIR)
endif()
if(_LEVELDB_EPIC_FAIL)
# Zero out everything, we didn't meet version requirements
set(LEVELDB_FOUND FALSE)
set(LEVELDB_LIBRARY)
set(_LEVELDB_INCLUDE_DIR)
set(LEVELDB_INCLUDE_DIRS)
set(LEVELDB_LIBRARIES)
else()
set(LEVELDB_INCLUDE_DIRS ${_LEVELDB_INCLUDE_DIR})
set(LEVELDB_LIBRARIES ${LEVELDB_LIBRARY})
if(_LEVELDB_output)
message(STATUS
"Found leveldb ${LEVELDB_VERSION} in ${LEVELDB_INCLUDE_DIRS};${LEVELDB_LIBRARIES}")
endif()
endif()