5 # Find Fast Library for Approximate Nearest Neighbors (FLANN). 6 # See http://www.cs.ubc.ca/research/flann for details. 8 # This module considers the following CMake variables set by find_package: 12 # FLANN_FIND_COMPONENTS - Names of requested components: 13 # cpp - shared or static C++ library 14 # cpp_shared - shared C++ library 15 # cpp_static - static C++ library 16 # c - shared or static C bindings library 17 # c_shared - shared C bindings library 18 # c_static - static C bindings library 19 # matlab - MATLAB bindings 20 # python - Python bindings 21 # FLANN_FIND_REQUIRED_<C> - Whether FLANN component <C> is required. 22 # FLANN is considered to be not found when at least 23 # one required library or its include path is missing. 24 # When no FLANN_FIND_COMPONENTS are specified, 25 # the static and shared C++ libraries are looked for. 26 # FLANN_FIND_REQUIRED - Raise FATAL_ERROR when required components not found. 27 # FLANN_FIND_QUIETLY - Suppress all other (status) messages. 31 # The "matlab" and "python" components are currently not supported yet. 33 # This module caches the following variables: 37 # FLANN_INCLUDE_DIR - Include path of C/C++ header files. 38 # FLANN_C_LIBRARY_SHARED - Path of shared C bindings link library. 39 # FLANN_C_LIBRARY_STATIC - Path of static C bindings link library. 40 # FLANN_CPP_LIBRARY_SHARED - Path of shared C++ link library. 41 # FLANN_CPP_LIBRARY_STATIC - Path of static c++ link library. 43 # It further defines the following uncached variables: 47 # FLANN_FOUND - Whether all required FLANN components were found. 48 # FLANN_<C>_FOUND - Whether library component <C> was found. 49 # FLANN_C_LIBRARY - Path of C bindings link library (shared preferred). 50 # FLANN_CPP_LIBRARY - Path of C++ link library (shared preferred). 51 # FLANN_LIBRARIES - Paths of all found libraries (shared preferred). 52 # FLANN_VERSION - Version for use in VERSION_LESS et al. comparisons. 53 # FLANN_VERSION_MAJOR - Major library version number. 54 # FLANN_VERSION_MINOR - Minor library version number. 55 # FLANN_VERSION_PATCH - Patch library version number. 56 # FLANN_VERSION_STRING - Version string for output messages. 58 #============================================================================= 59 # Copyright 2016 Andreas Schuh <andreas.schuh.84@gmail.com> 61 # Distributed under the OSI-approved BSD License (the "License"); 62 # see accompanying file Copyright.txt for details. 64 # This software is distributed WITHOUT ANY WARRANTY; without even the 65 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 66 # See the License for more information. 67 #============================================================================= 68 # (To distribute this file outside of CMake, substitute the full 69 # License text for the above reference.) 71 if (NOT FLANN_FIND_QUIETLY)
76 if (NOT FLANN_FIND_REQUIRED)
79 message(STATUS
"${_FLANN_FIND_STATUS}...")
82 # ------------------------------------------------------------------------------ 86 set(_FLANN_FIND_${_FLANN_COMPONENT} FALSE)
90 set(FLANN_FIND_COMPONENTS cpp)
94 foreach (_FLANN_COMPONENT IN LISTS FLANN_FIND_COMPONENTS)
95 if (_FLANN_COMPONENT MATCHES
"^c$")
97 elseif (_FLANN_COMPONENT MATCHES
"^(c_shared|flann)$")
99 elseif (_FLANN_COMPONENT MATCHES
"^(c_static|flann_s)$")
101 elseif (_FLANN_COMPONENT MATCHES
"^cpp$")
103 elseif (_FLANN_COMPONENT MATCHES
"^(cpp_shared|flann_cpp)$")
105 elseif (_FLANN_COMPONENT MATCHES
"^(cpp_static|cpp_s|flann_cpp_s)$")
107 elseif (_FLANN_COMPONENT MATCHES
"^(matlab|mex)$")
108 message(FATAL_ERROR
"FLANN library component \"${_FLANN_COMPONENT}\" not supported yet")
109 elseif (_FLANN_COMPONENT MATCHES "^python$")
110 message(FATAL_ERROR "FLANN library component \"python\" not supported yet")
112 message(FATAL_ERROR "Unknown FLANN library component: ${_FLANN_COMPONENT}\n
" 113 "Valid component names are: c, c_shared|flann, c_static|flann_s, cpp_shared|flann_cpp, cpp_static|cpp_s|flann_cpp_s, matlab|mex, python
") 118 message("** FindFLANN: Components = [${FLANN_FIND_COMPONENTS}]
") 119 foreach (_FLANN_COMPONENT IN LISTS _FLANN_COMPONENTS) 120 message("** FindFLANN: - Find component ${_FLANN_COMPONENT} = ${_FLANN_FIND_${_FLANN_COMPONENT}}
") 124 # ------------------------------------------------------------------------------ 125 # Construct a set of search paths 126 set(_FLANN_INC_DIR_HINTS) 127 set(_FLANN_LIB_DIR_HINTS) 130 file(TO_CMAKE_PATH "$ENV{FLANN_ROOT}
" FLANN_ROOT) 133 find_package(PkgConfig QUIET) 135 pkg_check_modules(_FLANN flann QUIET) 136 if (_FLANN_INCLUDEDIR) 137 list(APPEND _FLANN_INC_DIR_HINTS ${_FLANN_INCLUDEDIR}) 139 if (_FLANN_INCLUDE_DIRS) 140 list(APPEND _FLANN_INC_DIR_HINTS ${_FLANN_INCLUDE_DIRS}) 143 list(APPEND _FLANN_LIB_DIR_HINTS ${_FLANN_LIBDIR}) 145 if (_FLANN_LIBRARY_DIRS) 146 list(APPEND _FLANN_LIB_DIR_HINTS ${_FLANN_LIBRARY_DIRS}) 148 unset(_FLANN_INCLUDEDIR) 149 unset(_FLANN_INCLUDE_DIRS) 151 unset(_FLANN_LIBRARY_DIRS) 152 unset(_FLANN_CFLAGS_OTHER) 156 message("** FindFLANN: Initial search paths:
") 157 message("** FindFLANN: - Root directory hints = [${FLANN_ROOT}]
") 158 message("** FindFLANN: - PkgConfig include path = [${_FLANN_INC_DIR_HINTS}]
") 159 message("** FindFLANN: - PkgConfig library path = [${_FLANN_LIB_DIR_HINTS}]
") 162 # ------------------------------------------------------------------------------ 163 # Find common include directory 165 # Looking for flann/config.h because we use this path later to read this file 166 # in order to extract the version information. 167 find_path(FLANN_INCLUDE_DIR 169 HINTS ${FLANN_ROOT} ${_FLANN_INC_DIR_HINTS} 172 mark_as_advanced(FLANN_INCLUDE_DIR) 174 # ------------------------------------------------------------------------------ 175 # Derive FLANN_ROOT from FLANN_INCLUDE_DIR if unset 176 if (FLANN_INCLUDE_DIR AND NOT FLANN_ROOT) 177 get_filename_component(FLANN_ROOT "${FLANN_INCLUDE_DIR}
" DIRECTORY) 181 message("** FindFLANN: After initial search of FLANN include path
") 182 message("** FindFLANN: - FLANN_INCLUDE_DIR = ${FLANN_INCLUDE_DIR}
") 183 message("** FindFLANN: - FLANN_ROOT = [${FLANN_ROOT}]
") 186 # ------------------------------------------------------------------------------ 188 unset(FLANN_C_LIBRARY) 189 unset(FLANN_CPP_LIBRARY) 191 set(FLANN_INCLUDE_DIRS ${FLANN_INCLUDE_DIR}) 194 foreach (_FLANN_COMPONENT IN LISTS FLANN_FIND_COMPONENTS) 195 set(FLANN_${_FLANN_COMPONENT}_FOUND FALSE) 198 if (FLANN_INCLUDE_DIR) 201 if (_FLANN_FIND_c OR _FLANN_FIND_c_shared) 202 find_library(FLANN_C_LIBRARY_SHARED 204 HINTS ${FLANN_ROOT} ${_FLANN_LIB_DIR_HINTS} 206 if (FLANN_C_LIBRARY_SHARED) 207 set(FLANN_c_FOUND TRUE) 208 set(FLANN_c_shared_FOUND TRUE) 210 mark_as_advanced(FLANN_C_LIBRARY_SHARED) 214 if (_FLANN_FIND_c OR _FLANN_FIND_c_static) 215 find_library(FLANN_C_LIBRARY_STATIC 217 HINTS ${FLANN_ROOT} ${_FLANN_LIB_DIR_HINTS} 219 if (FLANN_C_LIBRARY_STATIC) 220 set(FLANN_c_FOUND TRUE) 221 set(FLANN_c_static_FOUND TRUE) 223 mark_as_advanced(FLANN_C_LIBRARY_STATIC) 226 # Set FLANN_C_LIBRARY and add it to FLANN_LIBRARIES 227 if (FLANN_C_LIBRARY_SHARED) 228 set(FLANN_C_LIBRARY ${FLANN_C_LIBRARY_SHARED}) 229 elseif (FLANN_C_LIBRARY_STATIC) 230 set(FLANN_C_LIBRARY ${FLANN_C_LIBRARY_STATIC}) 233 list(APPEND FLANN_LIBRARIES ${FLANN_C_LIBRARY}) 237 if (_FLANN_FIND_cpp OR _FLANN_FIND_cpp_shared) 238 find_library(FLANN_CPP_LIBRARY_SHARED 240 HINTS ${FLANN_ROOT} ${_FLANN_LIB_DIR_HINTS} 242 if (FLANN_CPP_LIBRARY_SHARED) 243 set(FLANN_cpp_FOUND TRUE) 244 set(FLANN_cpp_shared_FOUND TRUE) 246 mark_as_advanced(FLANN_CPP_LIBRARY_SHARED) 250 if (_FLANN_FIND_cpp OR _FLANN_FIND_cpp_static) 251 find_library(FLANN_CPP_LIBRARY_STATIC 253 HINTS ${FLANN_ROOT} ${_FLANN_LIB_DIR_HINTS} 255 if (FLANN_CPP_LIBRARY_STATIC) 256 set(FLANN_cpp_FOUND TRUE) 257 set(FLANN_cpp_static_FOUND TRUE) 259 mark_as_advanced(FLANN_CPP_LIBRARY_STATIC) 262 # Set FLANN_CPP_LIBRARY and add it to FLANN_LIBRARIES 263 if (FLANN_CPP_LIBRARY_SHARED) 264 set(FLANN_CPP_LIBRARY ${FLANN_CPP_LIBRARY_SHARED}) 265 elseif (FLANN_CPP_LIBRARY_STATIC) 266 set(FLANN_CPP_LIBRARY ${FLANN_CPP_LIBRARY_STATIC}) 268 if (FLANN_CPP_LIBRARY) 269 list(APPEND FLANN_LIBRARIES ${FLANN_CPP_LIBRARY}) 273 message("** FindFLANN: C/C++ library paths:
") 275 message("** FindFLANN: - FLANN_C_LIBRARY_SHARED = ${FLANN_C_LIBRARY_SHARED}
") 276 message("** FindFLANN: - FLANN_C_LIBRARY_STATIC = ${FLANN_C_LIBRARY_STATIC}
") 278 message("** FindFLANN: - FLANN_CPP_LIBRARY_SHARED = ${FLANN_CPP_LIBRARY_SHARED}
") 279 message("** FindFLANN: - FLANN_CPP_LIBRARY_STATIC = ${FLANN_CPP_LIBRARY_STATIC}
") 280 message("** FindFLANN: - FLANN_LIBRARIES = [${FLANN_LIBRARIES}]
") 284 # ------------------------------------------------------------------------------ 285 # Extract library version from flann/config.h 286 if (FLANN_INCLUDE_DIR) 287 if (NOT DEFINED FLANN_VERSION_MAJOR OR 288 NOT DEFINED FLANN_VERSION_MINOR OR 289 NOT DEFINED FLANN_VERSION_PATCH) 290 file(READ "${FLANN_INCLUDE_DIR}/flann/config.h
" _FLANN_CONFIG_CONTENTS LIMIT 2048) 291 if (_FLANN_CONFIG_CONTENTS MATCHES "#define FLANN_VERSION_? \
"([0-9]+)\\.([0-9]+)\\.([0-9]+)\"")
296 if (NOT FLANN_FIND_QUIETLY)
297 message(WARNING
"Could not extract FLANN version numbers from: ${FLANN_INCLUDE_DIR}/flann/config.h")
303 unset(_FLANN_CONFIG_CONTENTS)
309 unset(FLANN_VERSION_MAJOR) 310 unset(FLANN_VERSION_MINOR) 311 unset(FLANN_VERSION_PATCH) 312 unset(FLANN_VERSION_STRING) 316 message("** FindFLANN: Version information from ${FLANN_INCLUDE_DIR}/flann/config.h
") 323 # ------------------------------------------------------------------------------ 324 # Handle QUIET, REQUIRED, and [EXACT] VERSION arguments and set FLANN_FOUND 325 include(FindPackageHandleStandardArgs) 326 find_package_handle_standard_args(FLANN 327 REQUIRED_VARS FLANN_INCLUDE_DIR 328 VERSION_VAR FLANN_VERSION 332 if (NOT FLANN_FIND_QUIETLY) 340 # ------------------------------------------------------------------------------ 341 # Unset local auxiliary variables 342 foreach (_FLANN_COMPONENT IN LISTS _FLANN_COMPONENTS) 343 unset(_FLANN_FIND_${_FLANN_COMPONENT}) 345 unset(_FLANN_COMPONENT) 346 unset(_FLANN_COMPONENTS) 347 unset(_FLANN_FIND_STATUS)
cmake _FLANN_FIND_cpp_shared
cmake FLANN_VERSION_PATCH
cmake FLANN_FIND_COMPONENTS
cmake FLANN_VERSION_MAJOR
cmake FLANN_FIND_REQUIRED_cpp
cmake FLANN_VERSION_MINOR
cmake _FLANN_FIND_c_static
cmake _FLANN_FIND_c_shared
cmake _FLANN_FIND_cpp_static
cmake FLANN_VERSION_STRING