核心技术
产品中心
开发者
如何购买
资源中心
Orbbec SDK 文档
欢迎阅读Orbbec SDK(以下简称“SDK”)的使用教程!SDK 不仅提供了简洁的高阶API,又提供全面、灵活的低阶API,能够让您更快速的了解和使用奥比中光3D传感摄像头。
知识库——Examples CMake配置说明

CMake配置说明

Examples CMake工程结构

  1. Examples
  2. ├─c
  3. ├─CMakeLists.txt
  4. ├─Sample-ColorViewer
  5. └── CMakeLists.txt
  6. ├─Sample-DepthWorkMode
  7. └── CMakeLists.txt
  8. ├─Sample-DepthViewer
  9. └── CMakeLists.txt
  10. ├─Sample-HelloOrbbec
  11. └── CMakeLists.txt
  12. ├─Sample-HotPlugin
  13. └── CMakeLists.txt
  14. ├─Sample-InfraredViewer
  15. └── CMakeLists.txt
  16. ├─Sample-NetDevice
  17. └── CMakeLists.txt
  18. ├─Sample-PointCloud
  19. └── CMakeLists.txt
  20. └─Sample-SensorControl
  21. └── CMakeLists.txt
  22. └─cpp
  23. ├─CMakeLists.txt
  24. ├─Sample-ColorViewer
  25. └── CMakeLists.txt
  26. ├─Sample-DepthWorkMode
  27. └── CMakeLists.txt
  28. ├─Sample-DepthViewer
  29. └── CMakeLists.txt
  30. ├─Sample-HelloOrbbec
  31. └── CMakeLists.txt
  32. ├─Sample-HotPlugin
  33. └── CMakeLists.txt
  34. ├─Sample-ImuReader
  35. └── CMakeLists.txt
  36. ├─Sample-InfraredViewer
  37. └── CMakeLists.txt
  38. ├─Sample-MultiDevice
  39. └── CMakeLists.txt
  40. ├─Sample-MultiDeviceSync
  41. └── CMakeLists.txt
  42. ├─Sample-NetDevice
  43. └── CMakeLists.txt
  44. ├─Sample-PointCloud
  45. └── CMakeLists.txt
  46. ├─Sample-SaveToDisk
  47. └── CMakeLists.txt
  48. ├─Sample-SensorControl
  49. └── CMakeLists.txt
  50. ├─Sample-SyncAlignViewer
  51. | └── CMakeLists.txt
  52. ├─Sample-Recorder
  53. | └── CMakeLists.txt
  54. └─Sample-Playback
  55. └── CMakeLists.txt
如上树型结构,整个CMake工程结构可分为三层,与程序目录结构相同。每一层都会有一个CMakeLists.txt文件,第一层根目录中CMakeLists.txt是主CMakeLists.txt。第二层的CMakeLists.txt被放在两个不同的目录下,分别对应C版本和C++版本的Example。第三层的CMakeLists.txt是放在各自Example目录下。

主CMakeLists.txt说明

下面从根目录的CMakeLists.txt开始介绍:
  1. 设置需要使用CMake的最低版本为3.1.15
    1. cmake_minimum_required(VERSION 3.1.15)
  2. 生成一个名为OrbbecSDK-Examples工程,使用C++和C语言
    1. project(OrbbecSDK-Examples LANGUAGES CXX C)
  3. 使用标准的C++ 11进行编译
    1. set(CMAKE_CXX_STANDARD 11)
    2. set(CMAKE_CXX_STANDARD_REQUIRED True)
  4. 设置SDK的头文件及库路径
    1. set(OBSensor_DIR ${CMAKE_SOURCE_DIR}/../SDK)
    2. set(OBSensor_LIBRARY_DIRS ${OBSensor_ROOT_DIR}/lib/${CMAKE_BUILD_TYPE})
    3. set(OBSensor_INCLUDE_DIR ${OBSensor_ROOT_DIR}/include)
    4. include_directories(${OBSensor_INCLUDE_DIR})
    5. link_directories(${OBSensor_LIBRARY_DIRS})
  5. 查找opencv库
    1. # set(OpenCV_DIR "your/path/to/opencv") # 可通过该命令指定OpenCV_DIR模块查找路径
    2. find_package(OpenCV QUIET)
    3. if(${OpenCV_FOUND})
    4. include_directories(${OpenCV_INCLUDE_DIR})
    5. link_directories(${OpenCV_LIBRARY_DIRS})
    6. ENDIF(${OpenCV_FOUND})
  6. 设置ARCHIVE、LIBRARY、RUNTIME的输出目录,
    1. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
    2. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
    3. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
    关于这三个变量的说明参考:
Windows Unix
RUNTIME .exe、.dll 可执行程序
LIBRARY .so
ARCHIVE .a、.lib .a
  1. 添加子工程目录
    1. add_subdirectory(c)
    2. add_subdirectory(cpp)

    C语言版本Examples 主CMakeLists说明

    ``` cmake_minimum_required(VERSION 3.1.15)
add_subdirectory(Sample-HelloOrbbec) add_subdirectory(Sample-SensorControl) add_subdirectory(Sample-HotPlugin) add_subdirectory(Sample-DepthWorkMode)

opencv required

IF(${OpenCV_FOUND}) add_subdirectory(Sample-ColorViewer) add_subdirectory(Sample-DepthViewer) add_subdirectory(Sample-InfraredViewer) add_subdirectory(Sample-PointCloud) add_subdirectory(Sample-NetDevice) ENDIF(${OpenCV_FOUND})
  1. 这个文件比较简单,这里做一个简要说明。主要是根据是否有查找到opencv库及各example属性是否依赖opencv库决定是否将该example添加到工程。
  2. ## C语言版本Examples 子CMakeLists说明
  3. 在各Example子目录下包含各自的CMakeLists.txt, Sample-HelloOrbbec为例:
cmake_minimum_required(VERSION 3.1.15) set(CMAKE_CXX_STANDARD 11) project(Sample-HelloOrbbec) add_executable(hello_orbbec HelloOrbbec.c) target_link_libraries(hello_orbbec obsensor)
  1. 内容比较简单,主要是指定将源文件HelloOrbbec.c生产可执行文件hello_orbbecwindows平台生成文件待.exe后缀),并指定连接obsensor库。
  2. ## C++版本Examples 主CMakeLists说明
cmake_minimum_required(VERSION 3.1.15) add_subdirectory(Sample-HelloOrbbec) add_subdirectory(Sample-SensorControl) add_subdirectory(Sample-ImuReader) add_subdirectory(Sample-DepthWorkMode)

opencv required

IF(${OpenCV_FOUND}) add_subdirectory(Sample-ColorViewer) add_subdirectory(Sample-DepthViewer) add_subdirectory(Sample-InfraredViewer) add_subdirectory(Sample-SyncAlignViewer) add_subdirectory(Sample-HotPlugin) add_subdirectory(Sample-PointCloud) add_subdirectory(Sample-MultiDevice) add_subdirectory(Sample-MultiDeviceSync) add_subdirectory(Sample-NetDevice) add_subdirectory(Sample-SaveToDisk) add_subdirectory(Sample-Recorder) add_subdirectory(Sample-Playback) ENDIF(${OpenCV_FOUND})
  1. C++版本Examples CMakeLists.txt目标和内容和C语言版本基本一致,这里不再赘述。不同的是C++版本提供了更为丰富的例程。
  2. ## C++版本Examples 子CMakeLists说明
  3. C语言版本基本一致,这里不再复述。