summarylogtreecommitdiffstats
path: root/findflann-v0.1.patch
blob: bd9f2e94440feff73ca8adb01d579aeaa0989d84 (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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b4faa693..7e5e04c9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -286,7 +286,7 @@ endif()
 # ==============================================================================
 if (NOT DEFINED FLANN_INCLUDE_DIR_HINTS)
   set(FLANN_INCLUDE_DIR_HINTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/flann/src/cpp)
-  set(OpenMVG_USE_INTERNAL_FLANN ON)
+#  set(OpenMVG_USE_INTERNAL_FLANN ON)
 endif()
 find_package(Flann QUIET)
 if (NOT FLANN_FOUND OR OpenMVG_USE_INTERNAL_FLANN)
diff --git a/src/cmakeFindModules/FindFlann.cmake b/src/cmakeFindModules/FindFlann.cmake
index 41e74a1d..06e897b1 100644
--- a/src/cmakeFindModules/FindFlann.cmake
+++ b/src/cmakeFindModules/FindFlann.cmake
@@ -2,50 +2,83 @@
 #                  Find Flann Library
 #----------------------------------------------------------
 
-FIND_PATH(FLANN_DIR flann.hpp
-    HINTS "${FLANN_ROOT}" "$ENV{FLANN_ROOT}" "${FLANN_INCLUDE_DIR_HINTS}"
-    PATHS "$ENV{PROGRAMFILES}/flann" "$ENV{PROGRAMW6432}/flann"
-    PATH_SUFFIXES flann
-    DOC "Root directory of FLANN includes")
+# This sets the following variables:
+# FLANN_FOUND - True if FLANN was found.
+# FLANN_INCLUDE_DIRS - Directories containing the FLANN include files.
+# FLANN_LIBRARIES - Libraries needed to use FLANN.
+# FLANN_DEFINITIONS - Compiler flags for FLANN.
 
 ##====================================================
-## Include FLANN library
+## Use PKG-CONFIG for local FLANN instance
 ##----------------------------------------------------
-IF(EXISTS "${FLANN_DIR}" AND NOT "${FLANN_DIR}" STREQUAL "")
-        SET(FLANN_FOUND TRUE)
-        SET(FLANN_INCLUDE_DIRS ${FLANN_DIR})
-        SET(FLANN_DIR "${FLANN_DIR}" CACHE PATH "" FORCE)
-        MARK_AS_ADVANCED(FLANN_DIR)
-
-        # Extract Flann version from config.h
-        SET(FLANN_VERSION_FILE ${FLANN_INCLUDE_DIRS}/config.h)
-        IF (NOT EXISTS ${FLANN_VERSION_FILE})
-                FLANN_REPORT_NOT_FOUND(
-                  "Could not find file: ${FLANN_VERSION_FILE} "
-                  "containing version information in Flann install located at: "
-                  "${FLANN_INCLUDE_DIRS}.")
-        ELSE (NOT EXISTS ${FLANN_VERSION_FILE})
-            FILE(READ ${FLANN_VERSION_FILE} FLANN_VERSION_FILE_CONTENTS)
-            STRING(REGEX MATCH "#define FLANN_VERSION_ \"([0-9.]+)\""
-              FLANN_VERSION "${FLANN_VERSION_FILE_CONTENTS}")
-            STRING(REGEX REPLACE "#define FLANN_VERSION_ \"([0-9.]+)\"" "\\1"
-              FLANN_VERSION "${FLANN_VERSION}")
-        ENDIF (NOT EXISTS ${FLANN_VERSION_FILE})
-        SET(FLANN_INCLUDE_DIR ${FLANN_DIR})
-
-        FIND_LIBRARY(FLANN_LIBRARY NAMES flann_cpp)
-
-        # locate Flann libraries
-        IF(DEFINED FLANN_LIBRARY)
-          SET(FLANN_LIBRARIES ${FLANN_LIBRARY})
-        ENDIF()
-
-        MESSAGE(STATUS "Flann ${FLANN_VERSION} found (include: ${FLANN_INCLUDE_DIRS})")
+find_package(PkgConfig)
+pkg_check_modules(PC_FLANN flann)
+IF(PC_FLANN_FOUND)
+  set(FLANN_FOUND ${PC_FLANN_FOUND})
+  set(FLANN_DEFINITIONS ${PC_FLANN_CFLAGS_OTHER})
+
+  find_path(FLANN_INCLUDE_DIR flann/flann.hpp
+      HINTS ${PC_FLANN_INCLUDEDIR} ${PC_FLANN_INCLUDE_DIRS})
+
+  find_library(FLANN_LIBRARY flann
+      HINTS ${PC_FLANN_LIBDIR} ${PC_FLANN_LIBRARY_DIRS})
+
+  set(FLANN_INCLUDE_DIRS ${FLANN_INCLUDE_DIR})
+  set(FLANN_LIBRARIES  ${PC_FLANN_LIBRARIES};lz4)
+  set(FLANN_VERSION ${PC_FLANN_VERSION})
+
+  include(FindPackageHandleStandardArgs)
+  find_package_handle_standard_args(Flann DEFAULT_MSG
+      FLANN_LIBRARY FLANN_INCLUDE_DIR)
+
+  mark_as_advanced(FLANN_LIBRARY FLANN_INCLUDE_DIR)
 ELSE()
-  MESSAGE(FATAL_ERROR "You are attempting to build without Flann. "
-          "Please use cmake variable -DFLANN_INCLUDE_DIR_HINTS:STRING=\"PATH\" "
-          "or FLANN_INCLUDE_DIR_HINTS env. variable to a valid Flann path. "
-          "Or install last Flann version.")
-  package_report_not_found(FLANN "Flann cannot be found")
+  FIND_PATH(FLANN_DIR flann.hpp
+      HINTS "${FLANN_ROOT}" "$ENV{FLANN_ROOT}" "${FLANN_INCLUDE_DIR_HINTS}"
+      PATHS "$ENV{PROGRAMFILES}/flann" "$ENV{PROGRAMW6432}/flann"
+      PATH_SUFFIXES flann
+      DOC "Root directory of FLANN includes")
+
+  ##====================================================
+  ## Include FLANN library
+  ##----------------------------------------------------
+  IF(EXISTS "${FLANN_DIR}" AND NOT "${FLANN_DIR}" STREQUAL "")
+          SET(FLANN_FOUND TRUE)
+          SET(FLANN_INCLUDE_DIRS ${FLANN_DIR})
+          SET(FLANN_DIR "${FLANN_DIR}" CACHE PATH "" FORCE)
+          MARK_AS_ADVANCED(FLANN_DIR)
+
+          # Extract Flann version from config.h
+          SET(FLANN_VERSION_FILE ${FLANN_INCLUDE_DIRS}/config.h)
+          IF (NOT EXISTS ${FLANN_VERSION_FILE})
+                  FLANN_REPORT_NOT_FOUND(
+                    "Could not find file: ${FLANN_VERSION_FILE} "
+                    "containing version information in Flann install located at: "
+                    "${FLANN_INCLUDE_DIRS}.")
+          ELSE (NOT EXISTS ${FLANN_VERSION_FILE})
+              FILE(READ ${FLANN_VERSION_FILE} FLANN_VERSION_FILE_CONTENTS)
+              STRING(REGEX MATCH "#define FLANN_VERSION_ \"([0-9.]+)\""
+                FLANN_VERSION "${FLANN_VERSION_FILE_CONTENTS}")
+              STRING(REGEX REPLACE "#define FLANN_VERSION_ \"([0-9.]+)\"" "\\1"
+                FLANN_VERSION "${FLANN_VERSION}")
+          ENDIF (NOT EXISTS ${FLANN_VERSION_FILE})
+          SET(FLANN_INCLUDE_DIR ${FLANN_DIR})
+
+          FIND_LIBRARY(FLANN_LIBRARY NAMES flann)
+
+          # locate Flann libraries
+          IF(DEFINED FLANN_LIBRARY)
+            SET(FLANN_LIBRARIES ${FLANN_LIBRARY})
+          ENDIF()
+          SET(OpenMVG_USE_INTERNAL_FLANN TRUE)
+          MESSAGE(STATUS "Flann ${FLANN_VERSION} found (include: ${FLANN_INCLUDE_DIRS})")
+  ELSE()
+    MESSAGE(FATAL_ERROR "You are attempting to build without Flann. "
+            "Please use cmake variable -DFLANN_INCLUDE_DIR_HINTS:STRING=\"PATH\" "
+            "or FLANN_INCLUDE_DIR_HINTS env. variable to a valid Flann path. "
+            "Or install last Flann version.")
+    package_report_not_found(FLANN "Flann cannot be found")
+  ENDIF()
 ENDIF()
+
 ##====================================================