11# Copyright (c) Microsoft Corporation. All rights reserved.
22# Licensed under the MIT License.
33
4- cmake_minimum_required (VERSION 2.8.3 )
4+ cmake_minimum_required (VERSION 3.5 )
55project (azure_kinect_ros_driver LANGUAGES C CXX)
66
7-
8- if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
9- add_compile_options (/std:c++latest)
10- else ()
11- add_compile_options (-std=c++11)
12- endif ()
13-
147list (INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR} /cmake)
158
169## Find catkin macros and libraries
@@ -60,13 +53,17 @@ add_executable(${PROJECT_NAME}_node
6053 src/k4a_calibration_transform_data.cpp
6154 )
6255
56+ target_compile_features (${PROJECT_NAME} _node PUBLIC cxx_std_11)
57+
6358add_library (${PROJECT_NAME} _nodelet
6459 src/k4a_ros_bridge_nodelet.cpp
6560 src/k4a_ros_device.cpp
6661 src/k4a_ros_device_params.cpp
6762 src/k4a_calibration_transform_data.cpp
6863 )
6964
65+ target_compile_features (${PROJECT_NAME} _nodelet PUBLIC cxx_std_11)
66+
7067## Rename C++ executable without prefix
7168## The above recommended prefix causes long target names, the following renames the
7269## target back to the shorter version for ease of user use
@@ -77,51 +74,6 @@ set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX ""
7774#### AZURE KINECT SDK ######
7875############################
7976
80- macro (process_ext_sdk)
81- message (STATUS "K4A SDK found in ext/sdk!" )
82- message (STATUS "!! Not searching for SDK in system path !!" )
83-
84- # mark that the K4A SDK will need to be copied to the output binary folder
85- # this is needed even on Linux if the SDK is not installed to the system path
86- set (K4A_INSTALL_NEEDED true )
87-
88- get_target_property (K4A_INCLUDE_DIRS k4a::k4a INTERFACE_INCLUDE_DIRECTORIES )
89- get_target_property (K4A_CONFIGS k4a::k4a IMPORTED_CONFIGURATIONS )
90- message ("Configs: ${K4A_CONFIGS} " )
91-
92- # TODO: if we find more than one configuration, we should fail
93- # TODO: potentially clean this logic up
94- foreach (imported_config ${K4A_CONFIGS} )
95- if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
96- get_target_property (K4A_CONFIG_LIBS k4a::k4a IMPORTED_IMPLIB_${imported_config} )
97- get_target_property (K4A_CONFIG_DLLS k4a::k4a IMPORTED_LOCATION_${imported_config} )
98- list (APPEND K4A_LIBS ${K4A_CONFIG_LIBS} )
99- list (APPEND K4A_DLL_FILES ${K4A_CONFIG_DLLS} )
100- elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
101- get_target_property (K4A_CONFIG_LIBS k4a::k4a IMPORTED_LOCATION_${imported_config} )
102- get_target_property (K4A_CONFIG_DLLS k4a::k4a IMPORTED_LOCATION_${imported_config} )
103- list (APPEND K4A_LIBS ${K4A_CONFIG_LIBS} )
104- list (APPEND K4A_DLL_FILES ${K4A_CONFIG_DLLS} )
105- endif ()
106- endforeach ()
107-
108- if (DEFINED DEPTHENGINE_DLL)
109- ## Find the depth engine DLL
110- file (GLOB_RECURSE DEPTHENGINE_DLL_FILE
111- "${CMAKE_CURRENT_SOURCE_DIR} /ext/sdk/*/${DEPTHENGINE_DLL} " )
112- list (APPEND K4A_DLL_FILES ${DEPTHENGINE_DLL_FILE} )
113- endif ()
114- endmacro ()
115-
116- # Define the names of some files that we are going to try and find
117- if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
118- set (DEPTHENGINE_DLL "depthengine_1_0.dll" )
119- elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
120- set (DEPTHENGINE_DLL "libdepthengine.so.1.0" )
121- else ()
122- message (FATAL_ERROR "Platform ${CMAKE_SYSTEM_NAME} is not supported" )
123- endif ()
124-
12577message ("Finding K4A SDK binaries" )
12678
12779# Disable cached locations for K4A SDK binaries.
@@ -132,112 +84,32 @@ message("Finding K4A SDK binaries")
13284# differently (one needs install, one doesn't) we must disable the cache
13385# so that find_package(k4a) will fail in all cases if not installed via the .deb.
13486unset (k4a_DIR CACHE )
135- unset (azure-kinect-sensor-sdk_DIR CACHE )
136-
137- if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
138- message ("Linux mode: Searching for K4A in system path and ./ext/sdk" )
139-
140- # Test if we can find the k4a library in the system path
141- find_package (k4a 1.1.0 QUIET )
142-
143- if (${k4a_FOUND} )
144- message ("K4A SDK found in system libraries!" )
145- # For system libraries on linux, we can just append the target name (k4a::k4a)
146- # to what will be passed into target_link_libraries()
147- list (APPEND K4A_LIBS k4a::k4a)
148- else ()
149- message ("K4A SDK not found in system libraries. Searching ./ext/sdk..." )
150- find_package (k4a 1.1.0 PATHS "${CMAKE_CURRENT_SOURCE_DIR} /ext/sdk" )
151-
152- if (${k4a_FOUND} )
153- set (K4A_INSTALL_NEEDED true )
154- message ("K4A SDK found in ./ext/sdk!" )
155- process_ext_sdk()
156- else ()
157- message (FATAL_ERROR "K4A SDK not found in system libraries or ./ext/sdk. Please install the Azure Kinect SDK." )
158- endif ()
15987
160- endif ()
161-
162- elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
163- # Windows will always need K4A install for all targets
164- set (K4A_INSTALL_NEEDED true )
165-
166- # Try to find K4A installed to Program Files
167- find_package (azure-kinect-sensor-sdk 1.1.0 EXACT QUIET PATHS "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
168-
169- if (${azure-kinect-sensor-sdk_FOUND})
170- message ("K4A SDK found in Program Files!" )
171-
172- list (APPEND K4A_LIBS ${azure-kinect-sensor-sdk_LIBRARIES})
173- list (APPEND K4A_BINS ${azure-kinect-sensor-sdk_BINARIES})
174- set (K4A_INCLUDE_DIRS ${azure-kinect-sensor-sdk_INCLUDE_DIRS})
175-
176- # Create a list of all K4A DLLs
177- list (APPEND K4A_DLLS ${azure-kinect-sensor-sdk_LIBRARIES})
178- list (APPEND K4A_DLLS ${azure-kinect-sensor-sdk_BINARIES})
179-
180- foreach (DLL ${K4A_DLLS} )
181- set (prop "PROPERTY-NOTFOUND" )
182- get_property (prop TARGET ${DLL} PROPERTY IMPORTED_LOCATION )
183- message (STATUS "IMPORTED_LOCATION: ${prop} " )
184-
185- if ((NOT prop) OR (prop EQUAL "PROPERTY-NOTFOUND" ))
186- message (FATAL_ERROR "Target '${DLL} ' in package azure-kinect-sensor-sdk does not contain an IMPORTED_LOCATION property" )
187- endif ()
188-
189- list (APPEND K4A_DLL_FILES ${prop} )
190- endforeach (DLL)
191- else ()
192- # Try to find K4A installed to ./ext/sdk
193- find_package (k4a 1.1.0 QUIET PATHS "${CMAKE_CURRENT_SOURCE_DIR} /ext/sdk" )
194-
195- if (${k4a_FOUND} )
196- message ("K4A SDK found in ./ext/sdk!" )
197- process_ext_sdk()
198- else ()
199- message (FATAL_ERROR "K4A SDK not found in Program Files or ./ext/sdk. Please install the Azure Kinect SDK." )
200- endif ()
201- endif ()
88+ # Force running the Findk4a.cmake module
89+ find_package (k4a 1.2.0 QUIET MODULE REQUIRED)
90+ set (K4A_LIBS k4a::k4a;k4a::k4arecord)
91+
92+ # Try to find and enable the body tracking SDK
93+ find_package (k4abt 0.9.2 QUIET MODULE)
94+ if (k4abt_FOUND)
95+ list (APPEND K4A_LIBS k4abt::k4abt)
96+ message (STATUS "Body Tracking SDK found: compiling support for Body Tracking" )
97+ target_compile_definitions (${PROJECT_NAME} _node PUBLIC K4A_BODY_TRACKING)
98+ target_compile_definitions (${PROJECT_NAME} _nodelet PUBLIC K4A_BODY_TRACKING)
99+ else ()
100+ message ("!!! Body Tracking SDK not found: body tracking features will not be available !!!" )
202101endif ()
203102
204- message ("K4A Include Dirs: ${K4A_INCLUDE_DIRS} " )
205- message ("K4A Libs: ${K4A_LIBS} " )
206- message ("K4A DLLs: ${K4A_DLL_FILES} " )
207- message ("K4A Install Needed: ${K4A_INSTALL_NEEDED} " )
208-
209- if (${K4A_INSTALL_NEEDED} )
210- # Tell cmake that we need to reconfigure if any of the DLL files change
211- set_property (DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${K4A_DLL_FILES} )
212-
213- # We need to copy the DLLs into the CATKIN_PACKAGE_LIB_DESTINATION so
214- # the node executable can find them on launch, and CATKIN_PACKAGE_BIN_DESTINATION
215- # so the nodelet can find them on launch
216- set (DLL_COPY_DIRECTORY "${CATKIN_DEVEL_PREFIX} /${CATKIN_PACKAGE_BIN_DESTINATION} ;${CATKIN_DEVEL_PREFIX} /${CATKIN_PACKAGE_LIB_DESTINATION} " )
217-
218- foreach (DIRECTORY ${DLL_COPY_DIRECTORY} )
219- file (MAKE_DIRECTORY "${DIRECTORY} " )
220- endforeach (DIRECTORY )
221-
222- foreach (DLL ${K4A_DLL_FILES} )
223- foreach (DIRECTORY ${DLL_COPY_DIRECTORY} )
224- file (COPY "${DLL} " DESTINATION "${DIRECTORY} " )
225- get_filename_component (DLL_NAME ${DLL} NAME )
226- message (STATUS "Copied dll from ${DLL_NAME} to ${DIRECTORY} " )
227- # Tell cmake that we need to clean up these DLLs on a "make clean"
228- set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${DIRECTORY} /${DLL_NAME} " )
229- endforeach (DIRECTORY )
230- endforeach (DLL)
231-
232- endif ()
103+ # This reads the K4A_LIBS and K4A_INSTALL_REQUIRED variables and decides how to install
104+ # the various shared objects / DLLs
105+ include (Installk4a)
233106
234107##################################
235108###### END AZURE KINECT SDK ######
236109##################################
237110
238111include_directories (
239112 ${catkin_INCLUDE_DIRS}
240- ${K4A_INCLUDE_DIRS}
241113 "include"
242114)
243115
@@ -271,14 +143,3 @@ install(
271143 launch
272144 DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
273145)
274-
275- ## Run a custom install script for the K4A components
276- ## Running the two "CODE" blocks populates the cmake_install.cmake script with the information
277- ## about which DLLs to install, and where to install them.
278- ## We then run the more complex script to actually perform the installation.
279- if (${K4A_INSTALL_NEEDED} )
280- message ("Installing K4A SDK to binary output folder" )
281- install (CODE "set(K4A_DLL_FILES \" ${K4A_DLL_FILES} \" )" )
282- install (CODE "set(DLL_COPY_DIRECTORY \" ${CMAKE_INSTALL_PREFIX} /${CATKIN_PACKAGE_BIN_DESTINATION} \" )" )
283- install (SCRIPT "./cmake/azure-kinect-sensor-sdk-install.cmake" )
284- endif ()
0 commit comments