1# - try to find InterSense library
2#
3# Cache Variables: (probably not for direct use in your scripts)
4#  INTERSENSE_INCLUDE_DIR
5#  INTERSENSE_ISENSEC_DIR - location of the isense.c "import library" substitute.
6#  INTERSENSE_LIBRARY
7#
8# Non-cache variables you might use in your CMakeLists.txt:
9#  INTERSENSE_FOUND
10#  INTERSENSE_INCLUDE_DIRS
11#  INTERSENSE_LIBRARIES
12#
13# Requires these CMake modules:
14#  FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
15#
16# Author:
17# 2013 Eric Marsh <bits@wemarsh.com>
18# http://wemarsh.com/
19# Kognitiv Neuroinformatik, Universität Bremen
20#
21# (building on Ryan Pavlik's templates)
22#
23# 2013 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
24# http://academic.cleardefinition.com
25# Iowa State University HCI Graduate Program/VRAC
26#
27# Distributed under the Boost Software License, Version 1.0.
28# (See accompanying file LICENSE_1_0.txt or copy at
29# http://www.boost.org/LICENSE_1_0.txt)
30
31set(INTERSENSE_ROOT_DIR
32	"${INTERSENSE_ROOT_DIR}"
33	CACHE
34	PATH
35	"Directory to search for the Intersense SDK")
36
37if(APPLE)
38	set(_ARCH UniversalLib)
39else()
40	if(CMAKE_SIZEOF_VOID_P MATCHES "8")
41		set(_IS_ARCH x86_64)
42	else()
43		set(_IS_ARCH x86_32)
44	endif()
45endif()
46
47set(_IS_INSTALLDIRS)
48if(APPLE)
49	set(_IS_SDKDIR MacOSX)
50elseif(WIN32)
51	set(_IS_SDKDIR Windows)
52	# Default locations, as well as registry places it records install locations,
53	# if you installed from a (actual or downloaded) product "CD"
54	foreach(_IS_PROD "IS-900 Software" "InertiaCube Software")
55		get_filename_component(_IS_REGPATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\InterSense\\${_IS_PROD};Path]" ABSOLUTE)
56		if(_IS_REGPATH AND (NOT "${_IS_REGPATH}" STREQUAL "/registry"))
57			list(APPEND _IS_INSTALLDIRS "${_IS_REGPATH}/SDK")
58		endif()
59		list(APPEND _IS_INSTALLDIRS "C:/InterSense/${_IS_PROD}/SDK")
60	endforeach()
61else() # Assume Linux, since that's the only other platform supported by this library
62	set(_IS_SDKDIR Linux)
63endif()
64
65find_path(INTERSENSE_INCLUDE_DIR
66	NAMES isense.h
67	PATHS "${INTERSENSE_ROOT_DIR}" "${INTERSENSE_ROOT_DIR}/SDK" ${_IS_INSTALLDIRS})
68
69find_path(INTERSENSE_ISENSEC_DIR
70	NAMES isense.c
71	PATHS "${INTERSENSE_ROOT_DIR}" "${INTERSENSE_ROOT_DIR}/SDK" ${_IS_INSTALLDIRS}
72	PATH_SUFFIXES
73	"Windows/Sample/Visual C++ 2005"
74	"Windows/Sample/Visual C++ 2005 (single tracker)"
75	Linux/Sample
76	MacOSX/Sample)
77
78include(FindPackageHandleStandardArgs)
79
80# This is a weird one - no import library is supplied, and instead, at least on Windows, they use
81# an isense.c file to call into the DLL. Not sure if MinGW can link right against the dll in this case.
82if(WIN32)
83	find_package_handle_standard_args(InterSense
84		DEFAULT_MSG
85		INTERSENSE_INCLUDE_DIR
86		INTERSENSE_ISENSEC_DIR)
87	if(INTERSENSE_FOUND)
88		set(INTERSENSE_LIBRARIES "")
89		set(INTERSENSE_INCLUDE_DIRS "${INTERSENSE_INCLUDE_DIR}" "${INTERSENSE_ISENSEC_DIR}")
90	endif()
91else() # Only MSVC on Windows theoretically needs import libraries, so...
92	find_library(INTERSENSE_LIBRARY
93		NAMES isense
94		PATHS "${INTERSENSE_ROOT_DIR}" "${INTERSENSE_ROOT_DIR}/SDK" ${_IS_INSTALLDIRS}
95		PATH_SUFFIXES "${_IS_SDKDIR}/${_IS_ARCH}")
96
97	find_package_handle_standard_args(InterSense
98		DEFAULT_MSG
99		INTERSENSE_LIBRARY
100		INTERSENSE_INCLUDE_DIR)
101
102	if(INTERSENSE_FOUND)
103		set(INTERSENSE_LIBRARIES "${INTERSENSE_LIBRARY}" ${CMAKE_DL_LIBS})
104		set(INTERSENSE_INCLUDE_DIRS "${INTERSENSE_INCLUDE_DIR}")
105	endif()
106endif()
107
108mark_as_advanced(INTERSENSE_INCLUDE_DIR INTERSENSE_ISENSEC_DIR INTERSENSE_LIBRARY)
109