CMake Modules for Kinect SDK

CMake Modules for Kinect SDK

CMake is cross-platform build tool that is widely used in open source software.
You can generate build file for variety development environments from simple configuration script (CMakeLists.txt).
CMake has been used in many libraries such as OpenCV and Point Cloud Library.

CMake retrieve settings using module that is provided for each libraries.
However, CMake can’t find Kinect SDK, because CMake doesn’t have find module for Kinect SDK.
Therefor, I created CMake modules for find Kinect SDK v1/v2.
This modules are supports all features of Kinect SDK (Basic Streams and Application Streams).

Download Modules

You can download CMake modules for Kinect SDK (FindKinectSDK.cmake, FindKinectSDK2.cmake).

CMake Module for Kinect SDK v1

CMake Module for Kinect SDK v2

Module Results

CMake module returns macros by searching package (find_package()).
These macro is defined settings that matched your development environments.
This modules will searching Kinect SDK based on environment variable (KINECTSDK10_DIR, KINECTSDK20_DIR).
That returns the following macros.*1

*1 If you want more information about these modules, Please refer to module files.

FindKinectSDK Macros

KinectSDK_FOUND Return “TRUE” when Kinect SDK v1 found. Otherwise, Return “FALSE”.
KinectSDK_INCLUDE_DIRS Kinect SDK v1 include directories.
(${KinectSDK_DIR}/inc)
KinectSDK_LIBRARY_DIRS Kinect SDK v1 library directories.
(${KinectSDK_DIR}/lib/x86 or ${KinectSDK_DIR}/lib/amd64)
KinectSDK_LIBRARIES Kinect SDK v1 library files.
(${KinectSDK_LIBRARY_DIRS}/Kinect10.lib)

FindKinectSDK2 Macros

KinectSDK2_FOUND Return “TRUE” when Kinect SDK v2 found. Otherwise, Return “FALSE”.
KinectSDK2_INCLUDE_DIRS Kinect SDK v2 include directories.
(${KinectSDK2_DIR}/inc)
KinectSDK2_LIBRARY_DIRS Kinect SDK v2 library directories.
(${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64)
KinectSDK2_LIBRARIES Kinect SDK v2 library files.
(${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib)
KinectSDK2_COMMANDS Copy commands of redist files for application functions of Kinect SDK v2.
(If uncheck the box of all application features, this variable has defined empty command.)

How to use Modules in CMakeLists

You can use these modules as following CMakeLists.

How to Find Kinect SDK v1

cmake_minimum_required( VERSION 3.6 )

# Create Project
project( solution )
add_executable( project main.cpp )
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "project" )

# Find Kinect SDK v1
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
find_package( KinectSDK REQUIRED )

# Project Settings for Kinect SDK v1
if( KinectSDK_FOUND )
  # Additional Include Directories
  # [C/C++]>[General]>[Additional Include Directories]
  include_directories( ${KinectSDK_INCLUDE_DIRS} )

  # Additional Library Directories
  # [Linker]>[General]>[Additional Library Directories]
  link_directories( ${KinectSDK_LIBRARY_DIRS} )

  # Additional Dependencies
  # [Linker]>[Input]>[Additional Dependencies]
  target_link_libraries( project ${KinectSDK_LIBRARIES} )
endif()

How to Find Kinect SDK v2

cmake_minimum_required( VERSION 3.6 )

# Create Project
project( solution )
add_executable( project main.cpp )
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "project" )

# Find Kinect SDK v2
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
find_package( KinectSDK2 REQUIRED )

# Project Settings for Kinect SDK v2
if( KinectSDK2_FOUND )
  # Additional Include Directories
  # [C/C++]>[General]>[Additional Include Directories]
  include_directories( ${KinectSDK2_INCLUDE_DIRS} )

  # Additional Library Directories
  # [Linker]>[General]>[Additional Library Directories]
  link_directories( ${KinectSDK2_LIBRARY_DIRS} )

  # Additional Dependencies
  # [Linker]>[Input]>[Additional Dependencies]
  target_link_libraries( project ${KinectSDK2_LIBRARIES} )

  # Post Build Event
  # [Build Events]>[Post Build Event]>[Command Line]
  add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} )
endif()

Sample Program for Kinect SDK v2

This module is used in sample programs for Kinect SDK v2.


Leave a Reply

Your email address will not be published. Required fields are marked *