FindOpenVR.cmake
Go to the documentation of this file.
1 # Note that OpenVR lacks a useful install tree. This should work if
2 # `OpenVR_ROOT` is set to the source directory of OpenVR.
3 
4 # TODO: fails for universal builds
5 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
6  set(_openvr_bitness 64)
7 else ()
8  set(_openvr_bitness 32)
9 endif ()
10 
11 set(_openvr_platform_base)
12 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
13  set(_openvr_platform_base osx)
14  # SteamVR only supports 32-bit on OS X
15  set(OpenVR_PLATFORM osx32)
16 else ()
17  if (CMAKE_SYSTEM_NAME MATCHES "Linux")
18  set(_openvr_platform_base linux)
19  elseif (WIN32)
20  set(_openvr_platform_base win)
21  endif ()
22  set(OpenVR_PLATFORM ${_openvr_platform_base}${_openvr_bitness})
23 endif ()
24 
25 find_path(OpenVR_INCLUDE_DIR
26  NAMES
27  openvr_driver.h
28  PATH_SUFFIXES
29  headers
30  public/headers
31  steam
32  public/steam
33  DOC "OpenVR include directory")
34 mark_as_advanced(OpenVR_INCLUDE_DIR)
35 
36 find_library(OpenVR_LIBRARY
37  NAMES openvr_api
38  PATH_SUFFIXES
39  "${OpenVR_PLATFORM}"
40  "bin/${OpenVR_PLATFORM}"
41  DOC "OpenVR API library")
42 mark_as_advanced(OpenVR_LIBRARY)
43 
44 include(FindPackageHandleStandardArgs)
45 find_package_handle_standard_args(OpenVR
46  REQUIRED_VARS OpenVR_LIBRARY OpenVR_INCLUDE_DIR)
47 
48 if (OpenVR_FOUND)
49  set(OpenVR_INCLUDE_DIRS "${OpenVR_INCLUDE_DIR}")
50  set(OpenVR_LIBRARIES "${OpenVR_LIBRARY}")
51  if (NOT TARGET OpenVR::OpenVR)
52  add_library(OpenVR::OpenVR UNKNOWN IMPORTED)
53  set_target_properties(OpenVR::OpenVR PROPERTIES
54  IMPORTED_LOCATION "${OpenVR_LIBRARY}"
55  INTERFACE_INCLUDE_DIRECTORIES "${OpenVR_INCLUDE_DIR}")
56  endif ()
57 endif ()
58 
59 unset(_openvr_bitness)
60 unset(_openvr_platform_base)