forked from rpavlik/cmake-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindOpenHMD.cmake
More file actions
130 lines (121 loc) · 4.17 KB
/
FindOpenHMD.cmake
File metadata and controls
130 lines (121 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Copyright 2019 Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Original Author:
# 2019 Ryan Pavlik <ryan.pavlik@collabora.com>
#.rst:
# FindOpenHMD
# ---------------
#
# Find the OpenHMD immersive computing interface library.
#
# See http://www.openhmd.net/
#
# Targets
# ^^^^^^^
#
# If successful, the following import target is created.
#
# ``openhmd::openhmd``
#
# Cache variables
# ^^^^^^^^^^^^^^^
#
# The following cache variable may also be set to assist/control the operation of this module:
#
# ``OPENHMD_ROOT_DIR``
# The root to search for OpenHMD.
set(OPENHMD_ROOT_DIR
"${OPENHMD_ROOT_DIR}"
CACHE PATH "Root to search for OpenHMD")
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
set(_old_prefix_path "${CMAKE_PREFIX_PATH}")
# So pkg-config uses OPENHMD_ROOT_DIR too.
if(OPENHMD_ROOT_DIR)
list(APPEND CMAKE_PREFIX_PATH ${OPENHMD_ROOT_DIR})
endif()
pkg_check_modules(PC_OPENHMD QUIET openhmd)
# Restore
set(CMAKE_PREFIX_PATH "${_old_prefix_path}")
endif()
find_path(
OPENHMD_INCLUDE_DIR
NAMES openhmd.h
PATHS ${OPENHMD_ROOT_DIR}
HINTS ${PC_OPENHMD_INCLUDE_DIRS}
PATH_SUFFIXES include openhmd include/openhmd)
find_library(
OPENHMD_LIBRARY
NAMES openhmd
PATHS ${OPENHMD_ROOT_DIR} ${OPENHMD_ROOT_DIR}/build
HINTS ${PC_OPENHMD_LIBRARY_DIRS}
PATH_SUFFIXES lib)
find_library(OPENHMD_LIBRT rt)
find_library(OPENHMD_LIBM m)
find_package(Threads QUIET)
set(_ohmd_extra_deps)
set(OPENHMD_HIDAPI_TYPE)
if(OPENHMD_LIBRARY AND "${OPENHMD_LIBRARY}" MATCHES
"${CMAKE_STATIC_LIBRARY_SUFFIX}")
# Looks like a static library
if(PC_OPENHMD_FOUND)
# See if we need a particular hidapi.
list(REMOVE_ITEM PC_OPENHMD_LIBRARIES openhmd)
if("${PC_OPENHMD_LIBRARIES}" MATCHES hidapi-libusb)
set(OPENHMD_HIDAPI_TYPE libusb)
find_package(HIDAPI QUIET COMPONENTS libusb)
list(APPEND _ohmd_extra_deps HIDAPI_libusb_FOUND)
elseif("${PC_OPENHMD_LIBRARIES}" MATCHES hidapi-hidraw)
set(OPENHMD_HIDAPI_TYPE hidraw)
find_package(HIDAPI QUIET COMPONENTS hidraw)
list(APPEND _ohmd_extra_deps HIDAPI_hidraw_FOUND)
endif()
endif()
if(NOT PC_OPENHMD_FOUND OR NOT OPENHMD_HIDAPI_TYPE)
# Undifferentiated
set(OPENHMD_HIDAPI_TYPE undifferentiated)
find_package(HIDAPI QUIET)
list(APPEND _ohmd_extra_deps HIDAPI_FOUND)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
OpenHMD REQUIRED_VARS OPENHMD_INCLUDE_DIR OPENHMD_LIBRARY THREADS_FOUND)
if(OPENHMD_FOUND)
set(OPENHMD_INCLUDE_DIRS "${OPENHMD_INCLUDE_DIR}")
set(OPENHMD_LIBRARIES "${OPENHMD_LIBRARY}")
if(NOT TARGET OpenHMD::OpenHMD)
add_library(OpenHMD::OpenHMD UNKNOWN IMPORTED)
endif()
set_target_properties(
OpenHMD::OpenHMD
PROPERTIES IMPORTED_LOCATION "${OPENHMD_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${OPENHMD_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
if("${OPENHMD_HIDAPI_TYPE}" STREQUAL libusb)
set_property(
TARGET OpenHMD::OpenHMD
APPEND
PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES HIDAPI::hidapi-libusb)
list(APPEND OPENHMD_LIBRARIES HIDAPI::hidapi-libusb)
elseif("${OPENHMD_HIDAPI_TYPE}" STREQUAL hidraw)
set_property(
TARGET OpenHMD::OpenHMD
APPEND
PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES HIDAPI::hidapi-hidraw)
list(APPEND OPENHMD_LIBRARIES HIDAPI::hidapi-hidraw)
elseif("${OPENHMD_HIDAPI_TYPE}" STREQUAL undifferentiated)
set_property(
TARGET OpenHMD::OpenHMD
APPEND
PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES HIDAPI::hidapi)
list(APPEND OPENHMD_LIBRARIES HIDAPI::hidapi)
endif()
mark_as_advanced(OPENHMD_INCLUDE_DIR OPENHMD_LIBRARY)
endif()
mark_as_advanced(OPENHMD_ROOT_DIR OPENHMD_LIBRT OPENHMD_LIBM)