是否有OpenNI2的CMakeLists?

时间:2014-07-10 14:38:48

标签: c++ cmake ubuntu-10.04 openni

大家好!

如果有适合OpenNI 2的CMakelist命令,我一直在网上搜索,但没有找到任何似乎有用的东西。我在下一页找到了一个CMakelists: CMAKE can't find OpenNI 但事实证明它对我不起作用。我使用的是Ubuntu 10.04,我的CMakeLists.txt看起来像这样:

cmake_minimum_required(VERSION 2.8)

project( DisplayImage )

# ***************************************
# OpenCV

find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
# ***************************************

# *************************************
# OpenNI 2

OPTION (ENABLE_OPENNI2_NITE2 ON)

IF( ENABLE_OPENNI2_NITE2 )
set(OPENNI2_DEFINITIONS ${PC_OPENNI_CFLAGS_OTHER})

FIND_LIBRARY( OPENNI2_LIBRARY
             NAMES OpenNI2
             HINTS ${PC_OPENNI2_LIBDIR} ${PC_OPENNI2_LIBRARY_DIRS} /usr/lib
             PATHS "$ENV{PROGRAMFILES}/OpenNI2/Lib${OPENNI2_SUFFIX}"    "$ENV{PROGRAMW6432}/OpenNI2/Lib${OPENNI2_SUFFIX}" "$ENV{PROGRAMW6432}/OpenNI2"
             PATH_SUFFIXES lib lib64
)
FIND_PATH( OPENNI2_INCLUDE_DIR OpenNI.h
          HINTS ${PC_OPENNI2_INCLUDEDIR} ${PC_OPENNI2_INCLUDE_DIRS} 
                  /usr/include/openni2 /usr/include/ni2
                  PATHS "$ENV{PROGRAMFILES}/OpenNI2/include" "$ENV{PROGRAMW6432}/OpenNI2/include"
          PATH_SUFFIXES openni2 ni2)

FIND_LIBRARY( NITE2_LIBRARY
             NAMES NiTE2
             HINTS ${PC_OPENNI2_LIBDIR} ${PC_OPENNI2_LIBRARY_DIRS} /usr/lib
             PATHS "$ENV{PROGRAMFILES}/PrimeSense/NiTE2/lib${OPENNI2_SUFFIX}" "$ENV{PROGRAMW6432}/PrimeSense/NiTE2/lib${OPENNI2_SUFFIX}"
             PATH_SUFFIXES lib
)
FIND_PATH( NITE2_INCLUDE_DIR NiTE.h
      HINTS ${PC_OPENNI2_INCLUDEDIR} ${PC_OPENNI2_INCLUDE_DIRS} /usr/include/openni2 /usr/include/nite2
      PATHS "$ENV{PROGRAMFILES}/PrimeSense/NiTE2/include" "$ENV{PROGRAMW6432}/PrimeSense/NiTE2/include"
      PATH_SUFFIXES openni2         
)
ENDIF( ENABLE_OPENNI2_NITE2 )

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenNI2 DEFAULT_MSG
    OPENNI2_LIBRARY OPENNI2_INCLUDE_DIR)

mark_as_advanced(OPENNI2_LIBRARY OPENNI2_INCLUDE_DIR)

if (OPENNI2_FOUND)
    INCLUDE_DIRECTORIES( ${OPENNI2_INCLUDE_DIR} ${NITE2_INCLUDE_DIR} )
    message (STATUS "OpenNI2 found (include: ${OPENNI2_INCLUDE_DIR}, lib: ${OPENNI2_LIBRARY})")
link_directories( ${OPENNI2_LIBRARY} ${NITE2_LIBRARY} 
endif (OPENNI2_FOUND))
# *************************************

# *************************************
# My source codes
# set (SRC_DIR src)
# set (BUILD_DIR build)
# set (INC_DIR include)

# add the binary tree to the search path for include files
# so that we will find the header file
# include_directories("${INC_DIR}")

# you must add the list of your source files for the current target
# set (HEADERS ${INC_DIR}/printer.h)

# *************************************

# *************************************
# Set the output directories
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIR}/bin ) # this is for the binary file
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BUILD_DIR}/arc) # this is for the archives
set (CMAKE_LIBRARIES_OUTPUT_DIRECTORY ${BUILD_DIR}/lib) # this is for the libraries
# *************************************

add_executable( DisplayImage main.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} ${OPENNI2_LIBRARY} ${NITE2_LIBRARY} )

尝试编译程序后,终端显示以下错误消息:

-- Could NOT find OpenNI2 (missing:  OPENNI2_LIBRARY OPENNI2_INCLUDE_DIR) 
CMake Error in CMakeLists.txt:
  A logical block opening on the line

    /home/charly/OpenCV Test/KinectDisplay/src/CMakeLists.txt:51 (if)

  is not closed.


-- Configuring incomplete, errors occurred!
make: *** [cmake_check_build_system] Error 1

但OpenNI2目录与上述CMakeLists中提到的目录相同。我错过了什么?提前谢谢!

1 个答案:

答案 0 :(得分:2)

我认为错误在:

link_directories( ${OPENNI2_LIBRARY} ${NITE2_LIBRARY} 

您缺少右括号,因此将具有endif的下一行作为目录而不是if结束。

此外,这个cmake只能在windows中工作......我在linux中使用了openni2,并且安装了"只是usb和两个环境变量的规则....

所以,如果你想制作一个程序的可移植版本,你可能需要添加一些if用于linux的情况(可能是mac,但我还没有在mac中使用它,所以我可以&#t; t告诉你很多信息)