source: libs/SamgarWRUTed/tags/1.0/FindOpenCV.cmake @ 447

Revision 447, 7.9 KB checked in by lmalek, 10 years ago (diff)

tree structure reorganization

Line 
1# - Try to find OpenCV library installation
2# See http://sourceforge.net/projects/opencvlibrary/
3#
4# The follwoing variables are optionally searched for defaults
5#  OpenCV_ROOT_DIR:            Base directory of OpenCv tree to use.
6#  OpenCV_FIND_REQUIRED_COMPONENTS : FIND_PACKAGE(OpenCV COMPONENTS ..)
7#    compatible interface. typically  CV CXCORE CVAUX HIGHGUI CVCAM .. etc.
8#
9# The following are set after configuration is done:
10#  OpenCV_FOUND
11#  OpenCV_INCLUDE_DIR
12#  OpenCV_LIBRARIES
13#  OpenCV_LINK_DIRECTORIES
14#
15# deprecated:
16#  OPENCV_* uppercase replaced by case sensitive OpenCV_*
17#  OPENCV_EXE_LINKER_FLAGS
18#  OPENCV_INCLUDE_DIR : replaced by plural *_DIRS
19#
20# 2004/05 Jan Woetzel, Friso, Daniel Grest
21# 2006/01 complete rewrite by Jan Woetzel
22# 1006/09 2nd rewrite introducing ROOT_DIR and PATH_SUFFIXES
23#   to handle multiple installed versions gracefully by Jan Woetzel
24#
25# tested with:
26# -OpenCV 0.97 (beta5a):  MSVS 7.1, gcc 3.3, gcc 4.1
27# -OpenCV 0.99 (1.0rc1):  MSVS 7.1
28#
29# www.mip.informatik.uni-kiel.de/~jw
30# --------------------------------
31
32
33MACRO(DBG_MSG _MSG)
34  #  MESSAGE(STATUS "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}):\n${_MSG}")
35ENDMACRO(DBG_MSG)
36
37
38
39# required cv components with header and library if COMPONENTS unspecified
40IF    (NOT OpenCV_FIND_COMPONENTS)
41  # default
42  SET(OpenCV_FIND_REQUIRED_COMPONENTS   CV CXCORE CVAUX HIGHGUI )
43  IF   (WIN32)
44    LIST(APPEND OpenCV_FIND_REQUIRED_COMPONENTS  CVCAM ) # WIN32 only actually
45  ENDIF(WIN32) 
46ENDIF (NOT OpenCV_FIND_COMPONENTS)
47
48
49# typical root dirs of installations, exactly one of them is used
50SET (OpenCV_POSSIBLE_ROOT_DIRS
51  "${OpenCV_ROOT_DIR}"
52  "$ENV{OpenCV_ROOT_DIR}" 
53  "$ENV{OPENCV_DIR}"  # only for backward compatibility deprecated by ROOT_DIR
54  "$ENV{OPENCV_HOME}" # only for backward compatibility
55  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Intel(R) Open Source Computer Vision Library_is1;Inno Setup: App Path]"
56  "$ENV{ProgramFiles}/OpenCV"
57  /usr/local
58  /usr
59  )
60
61
62# MIP Uni Kiel /opt/net network installation
63# get correct prefix for current gcc compiler version for gcc 3.x  4.x
64IF    (${CMAKE_COMPILER_IS_GNUCXX})
65  IF    (NOT OpenCV_FIND_QUIETLY)
66    MESSAGE(STATUS "Checking GNUCXX version 3/4 to determine  OpenCV /opt/net/ path")
67  ENDIF (NOT OpenCV_FIND_QUIETLY)
68  EXEC_PROGRAM(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE CXX_COMPILER_VERSION) 
69  IF   (CXX_COMPILER_VERSION MATCHES ".*3\\.[0-9].*")
70    SET(IS_GNUCXX3 TRUE)
71    LIST(APPEND OpenCV_POSSIBLE_ROOT_DIRS /opt/net/gcc33/OpenCV )
72  ENDIF(CXX_COMPILER_VERSION MATCHES ".*3\\.[0-9].*") 
73  IF   (CXX_COMPILER_VERSION MATCHES ".*4\\.[0-9].*")
74    SET(IS_GNUCXX4 TRUE)
75    LIST(APPEND OpenCV_POSSIBLE_ROOT_DIRS /opt/net/gcc41/OpenCV )
76  ENDIF(CXX_COMPILER_VERSION MATCHES ".*4\\.[0-9].*")
77ENDIF (${CMAKE_COMPILER_IS_GNUCXX})
78
79#DBG_MSG("DBG (OpenCV_POSSIBLE_ROOT_DIRS=${OpenCV_POSSIBLE_ROOT_DIRS}")
80
81#
82# select exactly ONE OpenCV base directory/tree
83# to avoid mixing different version headers and libs
84#
85FIND_PATH(OpenCV_ROOT_DIR
86  NAMES
87  cv/include/cv.h     # windows
88  include/opencv/cv.h # linux /opt/net
89  include/cv/cv.h
90  include/cv.h
91  PATHS ${OpenCV_POSSIBLE_ROOT_DIRS})
92DBG_MSG("OpenCV_ROOT_DIR=${OpenCV_ROOT_DIR}")
93
94
95# header include dir suffixes appended to OpenCV_ROOT_DIR
96SET(OpenCV_INCDIR_SUFFIXES
97  include
98  include/cv
99  include/opencv
100  cv/include
101  cxcore/include
102  cvaux/include
103  otherlibs/cvcam/include
104  otherlibs/highgui
105  otherlibs/highgui/include
106  otherlibs/_graphics/include
107  )
108
109# library linkdir suffixes appended to OpenCV_ROOT_DIR
110SET(OpenCV_LIBDIR_SUFFIXES
111  lib
112  OpenCV/lib
113  otherlibs/_graphics/lib
114  )
115#DBG_MSG("OpenCV_LIBDIR_SUFFIXES=${OpenCV_LIBDIR_SUFFIXES}")
116
117
118#
119# find incdir for each lib
120#
121FIND_PATH(OpenCV_CV_INCLUDE_DIR
122  NAMES cv.h     
123  PATHS ${OpenCV_ROOT_DIR}
124  PATH_SUFFIXES ${OpenCV_INCDIR_SUFFIXES} )
125FIND_PATH(OpenCV_CXCORE_INCLUDE_DIR   
126  NAMES cxcore.h
127  PATHS ${OpenCV_ROOT_DIR}
128  PATH_SUFFIXES ${OpenCV_INCDIR_SUFFIXES} )
129FIND_PATH(OpenCV_CVAUX_INCLUDE_DIR   
130  NAMES cvaux.h
131  PATHS ${OpenCV_ROOT_DIR}
132  PATH_SUFFIXES ${OpenCV_INCDIR_SUFFIXES} )
133FIND_PATH(OpenCV_HIGHGUI_INCLUDE_DIR 
134  NAMES highgui.h
135  PATHS ${OpenCV_ROOT_DIR}
136  PATH_SUFFIXES ${OpenCV_INCDIR_SUFFIXES} )
137FIND_PATH(OpenCV_CVCAM_INCLUDE_DIR   
138  NAMES cvcam.h
139  PATHS ${OpenCV_ROOT_DIR}
140  PATH_SUFFIXES ${OpenCV_INCDIR_SUFFIXES} )
141
142#
143# find sbsolute path to all libraries
144# some are optionally, some may not exist on Linux
145#
146FIND_LIBRARY(OpenCV_CV_LIBRARY   
147  NAMES cv opencv
148  PATHS ${OpenCV_ROOT_DIR} 
149  PATH_SUFFIXES  ${OpenCV_LIBDIR_SUFFIXES} )
150FIND_LIBRARY(OpenCV_CVAUX_LIBRARY
151  NAMES cvaux
152  PATHS ${OpenCV_ROOT_DIR}  PATH_SUFFIXES ${OpenCV_LIBDIR_SUFFIXES} )
153FIND_LIBRARY(OpenCV_CVCAM_LIBRARY   
154  NAMES cvcam
155  PATHS ${OpenCV_ROOT_DIR}  PATH_SUFFIXES ${OpenCV_LIBDIR_SUFFIXES} )
156FIND_LIBRARY(OpenCV_CVHAARTRAINING_LIBRARY
157  NAMES cvhaartraining
158  PATHS ${OpenCV_ROOT_DIR}  PATH_SUFFIXES ${OpenCV_LIBDIR_SUFFIXES} )
159FIND_LIBRARY(OpenCV_CXCORE_LIBRARY 
160  NAMES cxcore
161  PATHS ${OpenCV_ROOT_DIR}  PATH_SUFFIXES ${OpenCV_LIBDIR_SUFFIXES} )
162FIND_LIBRARY(OpenCV_CXTS_LIBRARY   
163  NAMES cxts
164  PATHS ${OpenCV_ROOT_DIR}  PATH_SUFFIXES ${OpenCV_LIBDIR_SUFFIXES} )
165FIND_LIBRARY(OpenCV_HIGHGUI_LIBRARY 
166  NAMES highgui
167  PATHS ${OpenCV_ROOT_DIR}  PATH_SUFFIXES ${OpenCV_LIBDIR_SUFFIXES} )
168FIND_LIBRARY(OpenCV_ML_LIBRARY 
169  NAMES ml
170  PATHS ${OpenCV_ROOT_DIR}  PATH_SUFFIXES ${OpenCV_LIBDIR_SUFFIXES} )
171FIND_LIBRARY(OpenCV_TRS_LIBRARY 
172  NAMES trs
173  PATHS ${OpenCV_ROOT_DIR}  PATH_SUFFIXES ${OpenCV_LIBDIR_SUFFIXES} )
174
175
176
177#
178# Logic selecting required libs and headers
179#
180SET(OpenCV_FOUND ON)
181DBG_MSG("OpenCV_FIND_REQUIRED_COMPONENTS=${OpenCV_FIND_REQUIRED_COMPONENTS}")
182FOREACH(NAME ${OpenCV_FIND_REQUIRED_COMPONENTS} )
183
184  # only good if header and library both found   
185  IF    (OpenCV_${NAME}_INCLUDE_DIR AND OpenCV_${NAME}_LIBRARY)
186    LIST(APPEND OpenCV_INCLUDE_DIRS ${OpenCV_${NAME}_INCLUDE_DIR} )
187    LIST(APPEND OpenCV_LIBRARIES    ${OpenCV_${NAME}_LIBRARY} )
188    #DBG_MSG("appending for NAME=${NAME} ${OpenCV_${NAME}_INCLUDE_DIR} and ${OpenCV_${NAME}_LIBRARY}" )
189  ELSE  (OpenCV_${NAME}_INCLUDE_DIR AND OpenCV_${NAME}_LIBRARY)
190    DBG_MSG("OpenCV component NAME=${NAME} not found! "
191      "\nOpenCV_${NAME}_INCLUDE_DIR=${OpenCV_${NAME}_INCLUDE_DIR} "
192      "\nOpenCV_${NAME}_LIBRARY=${OpenCV_${NAME}_LIBRARY} ")
193    SET(OpenCV_FOUND OFF)
194  ENDIF (OpenCV_${NAME}_INCLUDE_DIR AND OpenCV_${NAME}_LIBRARY)
195 
196ENDFOREACH(NAME)
197
198DBG_MSG("OpenCV_INCLUDE_DIRS=${OpenCV_INCLUDE_DIRS}")
199DBG_MSG("OpenCV_LIBRARIES=${OpenCV_LIBRARIES}")
200
201# get the link directory for rpath to be used with LINK_DIRECTORIES:
202IF    (OpenCV_CV_LIBRARY)
203  GET_FILENAME_COMPONENT(OpenCV_LINK_DIRECTORIES ${OpenCV_CV_LIBRARY} PATH)
204ENDIF (OpenCV_CV_LIBRARY)
205
206MARK_AS_ADVANCED(
207  OpenCV_ROOT_DIR
208  OpenCV_INCLUDE_DIRS
209  OpenCV_CV_INCLUDE_DIR
210  OpenCV_CXCORE_INCLUDE_DIR
211  OpenCV_CVAUX_INCLUDE_DIR
212  OpenCV_CVCAM_INCLUDE_DIR
213  OpenCV_HIGHGUI_INCLUDE_DIR
214  OpenCV_LIBRARIES
215  OpenCV_CV_LIBRARY
216  OpenCV_CXCORE_LIBRARY
217  OpenCV_CVAUX_LIBRARY
218  OpenCV_CVCAM_LIBRARY
219  OpenCV_CVHAARTRAINING_LIBRARY
220  OpenCV_CXTS_LIBRARY
221  OpenCV_HIGHGUI_LIBRARY
222  OpenCV_ML_LIBRARY
223  OpenCV_TRS_LIBRARY
224  )
225
226
227# be backward compatible:
228SET(OPENCV_LIBRARIES   ${OpenCV_LIBRARIES} )
229SET(OPENCV_INCLUDE_DIR ${OpenCV_INCLUDE_DIRS} )
230SET(OPENCV_FOUND       ${OpenCV_FOUND})
231
232
233
234# display help message
235IF(NOT OpenCV_FOUND)
236  # make FIND_PACKAGE friendly
237  IF(NOT OpenCV_FIND_QUIETLY)
238    IF(OpenCV_FIND_REQUIRED)
239      MESSAGE(FATAL_ERROR
240        "OpenCV required but some headers or libs not found. Please specify it's location with OpenCV_ROOT_DIR env. variable.")
241    ELSE(OpenCV_FIND_REQUIRED)
242      MESSAGE(STATUS
243        "ERROR: OpenCV was not found.")
244    ENDIF(OpenCV_FIND_REQUIRED)
245  ENDIF(NOT OpenCV_FIND_QUIETLY)
246ENDIF(NOT OpenCV_FOUND)
Note: See TracBrowser for help on using the repository browser.