1# - try to find OpenHaptics libraries 2# 3# Cache Variables: (probably not for direct use in your scripts) 4# HDAPI_INCLUDE_DIR 5# HDAPI_LIBRARY 6# HDAPI_LIBRARY_RELEASE 7# HDAPI_LIBRARY_DEBUG 8# HDAPI_HDU_INCLUDE_DIR 9# HDAPI_HDU_LIBRARY 10# HDAPI_HDU_LIBRARY_RELEASE 11# HDAPI_HDU_LIBRARY_DEBUG 12# HLAPI_INCLUDE_DIR 13# HLAPI_LIBRARY 14# HLAPI_LIBRARY_RELEASE 15# HLAPI_LIBRARY_DEBUG 16# HLAPI_HLU_INCLUDE_DIR 17# HLAPI_HLU_LIBRARY 18# HLAPI_HLU_LIBRARY_RELEASE 19# HLAPI_HLU_LIBRARY_DEBUG 20# 21# Non-cache variables you might use in your CMakeLists.txt: 22# OPENHAPTICS_FOUND 23# HDAPI_INCLUDE_DIRS 24# HDAPI_LIBRARIES 25# HDAPI_HDU_INCLUDE_DIRS 26# HDAPI_HDU_LIBRARIES 27# HLAPI_INCLUDE_DIRS 28# HLAPI_LIBRARIES 29# HLAPI_HLU_INCLUDE_DIRS 30# HLAPI_HLU_LIBRARIES 31# OPENHAPTICS_LIBRARIES - includes HD, HDU, HL, HLU 32# OPENHAPTICS_RUNTIME_LIBRARY_DIRS 33# OPENHAPTICS_ENVIRONMENT 34# OPENHAPTICS_LIBRARY_DIRS 35# OPENHAPTICS_INCLUDE_DIRS 36# 37# Requires these CMake modules: 38# CleanDirectoryList 39# CleanLibraryList 40# ListCombinations 41# ProgramFilesGlob 42# SelectLibraryConfigurations (included with CMake >=2.8.0) 43# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) 44# CMake 2.6.3 (uses "unset") 45# 46# Original Author: 47# 2009-2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> 48# http://academic.cleardefinition.com 49# Iowa State University HCI Graduate Program/VRAC 50# 51# Copyright Iowa State University 2009-2010. 52# Distributed under the Boost Software License, Version 1.0. 53# (See accompanying file LICENSE_1_0.txt or copy at 54# http://www.boost.org/LICENSE_1_0.txt) 55 56cmake_minimum_required(VERSION 2.6.3) 57 58set(OPENHAPTICS_ROOT_DIR 59 "${OPENHAPTICS_ROOT_DIR}" 60 CACHE 61 PATH 62 "Path to search for OpenHaptics") 63option(OPENHAPTICS_NESTED_TARGETS 64 "Whether we should compile HDU and HLU, if needed, as a part of the solution" 65 ON) 66mark_as_advanced(OPENHAPTICS_NESTED_TARGETS) 67 68### 69# Configure OpenHaptics 70### 71 72include(SelectLibraryConfigurations) 73include(ListCombinations) 74include(CleanDirectoryList) 75include(CleanLibraryList) 76include(ProgramFilesGlob) 77 78set(_nest_targets) 79set(_incsearchdirs) 80set(_libsearchdirs) 81set(OPENHAPTICS_ENVIRONMENT) 82set(OPENHAPTICS_RUNTIME_LIBRARY_DIRS) 83 84set(_dirs) 85if(NOT "$ENV{OH_SDK_BASE}" STREQUAL "") 86 list(APPEND _dirs "$ENV{OH_SDK_BASE}") 87elseif(NOT "$ENV{3DTOUCH_BASE}" STREQUAL "") 88 list(APPEND _dirs "$ENV{3DTOUCH_BASE}") 89endif() 90if(WIN32) 91 program_files_fallback_glob(_pfdirs "/Sensable/3DTouch*/") 92 foreach(_OH_DEFAULT_LOCATION "C:/OpenHaptics/3.1" "C:/OpenHaptics/Academic/3.1") 93 if(EXISTS "${_OH_DEFAULT_LOCATION}") 94 list(APPEND _dirs "${_OH_DEFAULT_LOCATION}") 95 endif() 96 endforeach() 97 set(_dirs "${_dirs};${_pfdirs}") 98 if(MSVC60) 99 set(_vc "vc6") 100 elseif(MSVC70 OR MSVC71) 101 set(_vc "vc7") 102 elseif(MSVC80) 103 set(_vc "vc8") 104 endif() 105 if(CMAKE_SIZEOF_VOID_P MATCHES "8") 106 # 64-bit 107 list_combinations(_libsearch 108 PREFIXES 109 "${OPENHAPTICS_ROOT_DIR}" 110 ${_dirs} 111 SUFFIXES 112 "/lib/x64") 113 list_combinations(_libsearch2 114 PREFIXES 115 "${OPENHAPTICS_ROOT_DIR}" 116 ${_dirs} 117 SUFFIXES 118 "/utilities/lib/x64") 119 else() 120 # 32-bit 121 list_combinations(_libsearch 122 PREFIXES 123 "${OPENHAPTICS_ROOT_DIR}" 124 ${_dirs} 125 SUFFIXES 126 "/lib" 127 "/lib/win32") 128 list_combinations(_libsearch2 129 PREFIXES 130 "${OPENHAPTICS_ROOT_DIR}" 131 ${_dirs} 132 SUFFIXES 133 "/utilities/lib/Win32" 134 "/utilities/lib" 135 "/utilities/lib/${_vc}") 136 endif() 137 138 clean_directory_list(_libsearchdirs ${_libsearch} ${_libsearch2}) 139endif() 140 141list_combinations(_incsearch 142 PREFIXES 143 "${OPENHAPTICS_ROOT_DIR}" 144 ${_dirs} 145 SUFFIXES 146 "/include") 147list_combinations(_incsearch2 148 PREFIXES 149 "${OPENHAPTICS_ROOT_DIR}" 150 ${_dirs} 151 SUFFIXES 152 "/utilities/include") 153clean_directory_list(_incsearchdirs ${_incsearch} ${_incsearch2}) 154 155set(_deps_check) 156set(_deps_libs) 157 158### 159# HDAPI: HD 160### 161 162if(UNIX) 163 find_library(HDAPI_PHANToMIO_LIBRARY 164 NAMES 165 PHANToMIO 166 HINTS 167 ${_libsearchdirs}) 168 mark_as_advanced(HDAPI_PHANToMIO_LIBRARY) 169 list(APPEND _deps_check HDAPI_PHANToMIO_LIBRARY) 170 list(APPEND _deps_libs "${HDAPI_PHANToMIO_LIBRARY}") 171endif() 172 173find_path(HDAPI_INCLUDE_DIR 174 NAMES 175 HD/hd.h 176 HINTS 177 ${_incsearchdirs}) 178 179find_library(HDAPI_LIBRARY_RELEASE 180 NAMES 181 HD 182 PATH_SUFFIXES 183 ReleaseAcademicEdition 184 Release 185 HINTS 186 ${_libsearchdirs}) 187 188find_library(HDAPI_LIBRARY_DEBUG 189 NAMES 190 HD 191 PATH_SUFFIXES 192 DebugAcademicEdition 193 Debug 194 HINTS 195 ${_libsearchdirs}) 196 197select_library_configurations(HDAPI) 198 199### 200# HDAPI: HDU 201### 202find_path(HDAPI_HDU_INCLUDE_DIR 203 NAMES 204 HDU/hdu.h 205 HINTS 206 ${_incsearchdirs}) 207 208find_library(HDAPI_HDU_LIBRARY_RELEASE 209 NAMES 210 HDU 211 PATH_SUFFIXES 212 ReleaseAcademicEdition 213 Release 214 HINTS 215 ${_libsearchdirs}) 216 217find_library(HDAPI_HDU_LIBRARY_DEBUG 218 NAMES 219 HDU 220 PATH_SUFFIXES 221 DebugAcademicEdition 222 Debug 223 HINTS 224 ${_libsearchdirs}) 225 226# Fallback 227find_library(HDAPI_HDU_LIBRARY_DEBUG 228 NAMES 229 HDUD 230 PATH_SUFFIXES 231 DebugAcademicEdition 232 Debug 233 HINTS 234 ${_libsearchdirs}) 235 236select_library_configurations(HDAPI_HDU) 237 238if(OPENHAPTICS_NESTED_TARGETS OR NOT HDAPI_HDU_LIBRARY) 239 if(HDAPI_HDU_SOURCE_DIR AND NOT EXISTS "${HDAPI_HDU_SOURCE_DIR}/hdu.cpp") 240 unset(HDAPI_HDU_SOURCE_DIR) 241 endif() 242 find_path(HDAPI_HDU_SOURCE_DIR 243 NAMES 244 hdu.cpp 245 PATH_SUFFIXES 246 src 247 src/HDU 248 src/HDU/src 249 libsrc/HDU 250 HINTS 251 "${HDAPI_HDU_INCLUDE_DIR}/.." 252 "${HDAPI_HDU_INCLUDE_DIR}/../share/3DTouch") 253 list(APPEND _deps_check HDAPI_HDU_SOURCE_DIR) 254 if(HDAPI_HDU_SOURCE_DIR) 255 mark_as_advanced(HDAPI_HDU_SOURCE_DIR) 256 set(_nest_targets YES) 257 set(HDAPI_HDU_LIBRARY 258 "openhaptics_hdu_nested_target" 259 CACHE 260 STRING 261 "We will build the OpenHaptics HDU lib." 262 FORCE) 263 set(HDAPI_HDU_LIBRARIES ${HDAPI_HDU_LIBRARY}) 264 endif() 265endif() 266 267 268### 269# HLAPI: HL 270### 271find_path(HLAPI_INCLUDE_DIR 272 NAMES 273 HL/hl.h 274 HINTS 275 ${_incsearchdirs}) 276 277find_library(HLAPI_LIBRARY_RELEASE 278 NAMES 279 HL 280 PATH_SUFFIXES 281 ReleaseAcademicEdition 282 Release 283 HINTS 284 ${_libsearchdirs}) 285 286find_library(HLAPI_LIBRARY_DEBUG 287 NAMES 288 HL 289 PATH_SUFFIXES 290 DebugAcademicEdition 291 Debug 292 HINTS 293 ${_libsearchdirs}) 294 295select_library_configurations(HLAPI) 296 297### 298# HLAPI: HLU 299### 300find_path(HLAPI_HLU_INCLUDE_DIR 301 NAMES 302 HLU/hlu.h 303 HINTS 304 ${_incsearchdirs}) 305 306find_library(HLAPI_HLU_LIBRARY_RELEASE 307 NAMES 308 HLU 309 PATH_SUFFIXES 310 ReleaseAcademicEdition 311 Release 312 HINTS 313 ${_libsearchdirs}) 314 315find_library(HLAPI_HLU_LIBRARY_DEBUG 316 NAMES 317 HLU 318 PATH_SUFFIXES 319 DebugAcademicEdition 320 Debug 321 HINTS 322 ${_libsearchdirs}) 323 324# fallback 325find_library(HLAPI_HLU_LIBRARY_DEBUG 326 NAMES 327 HLUD 328 PATH_SUFFIXES 329 DebugAcademicEdition 330 Debug 331 HINTS 332 ${_libsearchdirs}) 333 334select_library_configurations(HLAPI_HLU) 335 336if(OPENHAPTICS_NESTED_TARGETS OR NOT HLAPI_HLU_LIBRARY) 337 if(HLAPI_HLU_SOURCE_DIR AND NOT EXISTS "${HLAPI_HLU_SOURCE_DIR}/hlu.cpp") 338 unset(HLAPI_HLU_SOURCE_DIR) 339 endif() 340 find_path(HLAPI_HLU_SOURCE_DIR 341 NAMES 342 hlu.cpp 343 PATH_SUFFIXES 344 src 345 src/HLU 346 src/HLU/src 347 libsrc/HLU 348 HINTS 349 "${HLAPI_HLU_INCLUDE_DIR}/.." 350 "${HLAPI_HLU_INCLUDE_DIR}/../share/3DTouch") 351 list(APPEND _deps_check HLAPI_HLU_SOURCE_DIR) 352 if(HLAPI_HLU_SOURCE_DIR) 353 mark_as_advanced(HLAPI_HLU_SOURCE_DIR) 354 set(_nest_targets YES) 355 set(HLAPI_HLU_LIBRARY 356 "openhaptics_hlu_nested_target" 357 CACHE 358 STRING 359 "We will build the OpenHaptics HLU lib." 360 FORCE) 361 set(HLAPI_HLU_LIBRARIES ${HLAPI_HLU_LIBRARY}) 362 endif() 363endif() 364 365### 366# Add dependencies: Libraries 367### 368set(HDAPI_LIBRARIES "${HDAPI_LIBRARY}" ${_deps_libs}) 369 370if(HDAPI_HDU_LIBRARIES AND HDAPI_LIBRARIES) 371 list(APPEND HDAPI_HDU_LIBRARIES ${HDAPI_LIBRARIES}) 372else() 373 set(HDAPI_HDU_LIBRARIES) 374endif() 375 376if(HLAPI_LIBRARY AND HDAPI_LIBRARIES) 377 set(HLAPI_LIBRARIES ${HLAPI_LIBRARY} ${HDAPI_LIBRARIES}) 378else() 379 set(HLAPI_LIBRARIES) 380endif() 381 382if(HLAPI_HLU_LIBRARIES AND HLAPI_LIBRARIES) 383 list(APPEND HLAPI_HLU_LIBRARIES ${HLAPI_LIBRARIES}) 384else() 385 set(HLAPI_HLU_LIBRARIES) 386endif() 387 388### 389# Add dependencies: Include dirs 390### 391if(HDAPI_INCLUDE_DIR) 392 set(HDAPI_INCLUDE_DIRS ${HDAPI_INCLUDE_DIR}) 393 394 if(HDAPI_HDU_INCLUDE_DIR) 395 set(HDAPI_HDU_INCLUDE_DIRS 396 ${HDAPI_INCLUDE_DIRS} 397 ${HDAPI_HDU_INCLUDE_DIR}) 398 399 if(HDAPI_HDU_INCLUDE_DIR) 400 set(HLAPI_INCLUDE_DIRS ${HDAPI_INCLUDE_DIRS} ${HLAPI_INCLUDE_DIR}) 401 402 if(HLAPI_HLU_INCLUDE_DIR) 403 set(HLAPI_HLU_INCLUDE_DIRS 404 ${HLAPI_INCLUDE_DIRS} 405 ${HLAPI_HLU_INCLUDE_DIR}) 406 407 endif() 408 endif() 409 endif() 410endif() 411 412# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if 413# all listed variables are TRUE 414include(FindPackageHandleStandardArgs) 415find_package_handle_standard_args(OpenHaptics 416 DEFAULT_MSG 417 HDAPI_LIBRARY 418 HDAPI_INCLUDE_DIR 419 HDAPI_HDU_INCLUDE_DIR 420 HDAPI_HDU_LIBRARY 421 HLAPI_INCLUDE_DIR 422 HLAPI_LIBRARY 423 HLAPI_HLU_INCLUDE_DIR 424 HLAPI_HLU_LIBRARY 425 ${_deps_check}) 426 427if(OPENHAPTICS_FOUND) 428 # Recurse into the nested targets subdirectory if needed 429 if(_nest_targets) 430 get_filename_component(_moddir "${CMAKE_CURRENT_LIST_FILE}" PATH) 431 add_subdirectory("${_moddir}/nested_targets/OpenHaptics" "OpenHapticsNestedTargets") 432 endif() 433 434 set(OPENHAPTICS_LIBRARIES 435 ${HDAPI_LIBRARY} 436 ${HDAPI_HDU_LIBRARY} 437 ${HLAPI_LIBRARY} 438 ${HLAPI_HLU_LIBRARY}) 439 set(OPENHAPTICS_LIBRARY_DIRS) 440 foreach(_lib 441 ${_deps_check} 442 HDAPI_LIBRARY_RELEASE 443 HDAPI_LIBRARY_DEBUG 444 HDAPI_HDU_LIBRARY_RELEASE 445 HDAPI_HDU_LIBRARY_DEBUG 446 HLAPI_LIBRARY_RELEASE 447 HLAPI_LIBRARY_DEBUG 448 HLAPI_HLU_LIBRARY_RELEASE 449 HLAPI_HLU_LIBRARY_DEBUG) 450 get_filename_component(_libdir ${${_lib}} PATH) 451 list(APPEND OPENHAPTICS_LIBRARY_DIRS ${_libdir}) 452 endforeach() 453 454 set(OPENHAPTICS_INCLUDE_DIRS 455 ${HLAPI_HLU_INCLUDE_DIRS} 456 ${HDAPI_HDU_INCLUDE_DIRS}) 457 458 clean_directory_list(OPENHAPTICS_LIBRARY_DIRS) 459 clean_directory_list(OPENHAPTICS_INCLUDE_DIRS) 460 461 list(APPEND 462 OPENHAPTICS_RUNTIME_LIBRARY_DIRS 463 ${OPENHAPTICS_LIBRARY_DIRS}) 464 465 clean_library_list(OPENHAPTICS_LIBRARIES) 466 467 mark_as_advanced(OPENHAPTICS_ROOT_DIR) 468endif() 469 470mark_as_advanced(HDAPI_INCLUDE_DIR 471 HDAPI_LIBRARY_RELEASE 472 HDAPI_LIBRARY_DEBUG 473 HDAPI_HDU_INCLUDE_DIR 474 HDAPI_HDU_LIBRARY_RELEASE 475 HDAPI_HDU_LIBRARY_DEBUG 476 HLAPI_INCLUDE_DIR 477 HLAPI_LIBRARY_RELEASE 478 HLAPI_LIBRARY_DEBUG 479 HLAPI_HLU_INCLUDE_DIR 480 HLAPI_HLU_LIBRARY_RELEASE 481 HLAPI_HLU_LIBRARY_DEBUG) 482