1# Main variables:
2# OPENNI_LIBRARY and OPENNI_INCLUDES to link OpenCV modules with OpenNI
3# HAVE_OPENNI for conditional compilation OpenCV with/without OpenNI
4
5if(NOT "${OPENNI_LIB_DIR}" STREQUAL "${OPENNI_LIB_DIR_INTERNAL}")
6    unset(OPENNI_LIBRARY CACHE)
7    unset(OPENNI_LIB_DIR CACHE)
8endif()
9
10if(NOT "${OPENNI_INCLUDE_DIR}" STREQUAL "${OPENNI_INCLUDE_DIR_INTERNAL}")
11    unset(OPENNI_INCLUDES CACHE)
12    unset(OPENNI_INCLUDE_DIR CACHE)
13endif()
14
15if(NOT "${OPENNI_PRIME_SENSOR_MODULE_BIN_DIR}" STREQUAL "${OPENNI_PRIME_SENSOR_MODULE_BIN_DIR_INTERNAL}")
16    unset(OPENNI_PRIME_SENSOR_MODULE CACHE)
17    unset(OPENNI_PRIME_SENSOR_MODULE_BIN_DIR CACHE)
18endif()
19
20if(WIN32)
21    if(NOT (MSVC64 OR MINGW64))
22        find_file(OPENNI_INCLUDES "XnCppWrapper.h" PATHS "$ENV{OPEN_NI_INSTALL_PATH}Include" DOC "OpenNI c++ interface header")
23        find_library(OPENNI_LIBRARY "OpenNI" PATHS $ENV{OPEN_NI_LIB} DOC "OpenNI library")
24    else()
25        find_file(OPENNI_INCLUDES "XnCppWrapper.h" PATHS "$ENV{OPEN_NI_INSTALL_PATH64}Include" DOC "OpenNI c++ interface header")
26        find_library(OPENNI_LIBRARY "OpenNI64" PATHS $ENV{OPEN_NI_LIB64} DOC "OpenNI library")
27    endif()
28elseif(UNIX OR APPLE)
29    find_file(OPENNI_INCLUDES "XnCppWrapper.h" PATHS "/usr/include/ni" "/usr/include/openni" DOC "OpenNI c++ interface header")
30    find_library(OPENNI_LIBRARY "OpenNI" PATHS "/usr/lib" DOC "OpenNI library")
31endif()
32
33if(OPENNI_LIBRARY AND OPENNI_INCLUDES)
34    set(HAVE_OPENNI TRUE)
35    # the check: are PrimeSensor Modules for OpenNI installed
36    if(WIN32)
37    if(NOT (MSVC64 OR MINGW64))
38            find_file(OPENNI_PRIME_SENSOR_MODULE "XnCore.dll" PATHS "$ENV{OPEN_NI_INSTALL_PATH}../PrimeSense/Sensor/Bin" "$ENV{OPEN_NI_INSTALL_PATH}../PrimeSense/SensorKinect/Bin" DOC "Core library of PrimeSensor Modules for OpenNI")
39        else()
40            find_file(OPENNI_PRIME_SENSOR_MODULE "XnCore64.dll" PATHS "$ENV{OPEN_NI_INSTALL_PATH64}../PrimeSense/Sensor/Bin64" "$ENV{OPEN_NI_INSTALL_PATH64}../PrimeSense/SensorKinect/Bin64" DOC "Core library of PrimeSensor Modules for OpenNI")
41        endif()
42    elseif(UNIX OR APPLE)
43        find_library(OPENNI_PRIME_SENSOR_MODULE "XnCore" PATHS "/usr/lib" DOC "Core library of PrimeSensor Modules for OpenNI")
44    endif()
45
46    if(OPENNI_PRIME_SENSOR_MODULE)
47        set(HAVE_OPENNI_PRIME_SENSOR_MODULE TRUE)
48    endif()
49endif() #if(OPENNI_LIBRARY AND OPENNI_INCLUDES)
50
51get_filename_component(OPENNI_LIB_DIR "${OPENNI_LIBRARY}" PATH)
52get_filename_component(OPENNI_INCLUDE_DIR ${OPENNI_INCLUDES} PATH)
53get_filename_component(OPENNI_PRIME_SENSOR_MODULE_BIN_DIR "${OPENNI_PRIME_SENSOR_MODULE}" PATH)
54
55if(HAVE_OPENNI)
56  set(OPENNI_LIB_DIR "${OPENNI_LIB_DIR}" CACHE PATH "Path to OpenNI libraries" FORCE)
57  set(OPENNI_INCLUDE_DIR "${OPENNI_INCLUDE_DIR}" CACHE PATH "Path to OpenNI headers" FORCE)
58  set(OPENNI_PRIME_SENSOR_MODULE_BIN_DIR "${OPENNI_PRIME_SENSOR_MODULE_BIN_DIR}" CACHE PATH "Path to OpenNI PrimeSensor Module binaries" FORCE)
59endif()
60
61if(OPENNI_LIBRARY)
62    set(OPENNI_LIB_DIR_INTERNAL "${OPENNI_LIB_DIR}" CACHE INTERNAL "This is the value of the last time OPENNI_LIB_DIR was set successfully." FORCE)
63else()
64    message( WARNING, " OpenNI library directory (set by OPENNI_LIB_DIR variable) is not found or does not have OpenNI libraries." )
65endif()
66
67if(OPENNI_INCLUDES)
68    set(OPENNI_INCLUDE_DIR_INTERNAL "${OPENNI_INCLUDE_DIR}" CACHE INTERNAL "This is the value of the last time OPENNI_INCLUDE_DIR was set successfully." FORCE)
69else()
70    message( WARNING, " OpenNI include directory (set by OPENNI_INCLUDE_DIR variable) is not found or does not have OpenNI include files." )
71endif()
72
73if(OPENNI_PRIME_SENSOR_MODULE)
74    set(OPENNI_PRIME_SENSOR_MODULE_BIN_DIR_INTERNAL "${OPENNI_PRIME_SENSOR_MODULE_BIN_DIR}" CACHE INTERNAL "This is the value of the last time OPENNI_PRIME_SENSOR_MODULE_BIN_DIR was set successfully." FORCE)
75else()
76    message( WARNING, " PrimeSensor Module binaries directory (set by OPENNI_PRIME_SENSOR_MODULE_BIN_DIR variable) is not found or does not have PrimeSensor Module binaries." )
77endif()
78
79mark_as_advanced(FORCE OPENNI_PRIME_SENSOR_MODULE)
80mark_as_advanced(FORCE OPENNI_LIBRARY)
81mark_as_advanced(FORCE OPENNI_INCLUDES)
82
83if(HAVE_OPENNI)
84  ocv_parse_header("${OPENNI_INCLUDE_DIR}/XnVersion.h" OPENNI_VERSION_LINES XN_MAJOR_VERSION XN_MINOR_VERSION XN_MAINTENANCE_VERSION XN_BUILD_VERSION)
85  if(XN_MAJOR_VERSION)
86    set(OPENNI_VERSION_STRING ${XN_MAJOR_VERSION}.${XN_MINOR_VERSION}.${XN_MAINTENANCE_VERSION} CACHE INTERNAL "OpenNI version")
87    set(OPENNI_VERSION_BUILD ${XN_BUILD_VERSION} CACHE INTERNAL "OpenNI build version")
88  endif()
89endif()
90