openvr icon indicating copy to clipboard operation
openvr copied to clipboard

CMake targets not provided when using vcpkg

Open JoeRosselli opened this issue 1 year ago • 2 comments

I'm attempting to integrate openvr into my CMake/vcpkg-based project, developing on an Ubuntu machine.

When I add 'openvr' to my vcpkg manifest it seems to work to pull down dynamic openvr libraries (libopenvr_api.so, libopenvr_api.so.dbg) and include files, but no cmake files are included in the vcpkg distribution like most other projects.

This means I'm unable to simply link against openvr and am forced to write custom CMake code to manually search for the openvr include and libraries that vcpkg installed.

I'm new to vcpkg but it seems like openvr ideally needs to provide cmake find/target files along with the openvr binaries, when distributed via vcpkg.

The simplest repo of the issue would be creating a simple project like so:

==vcpkg.json==

{
  "dependencies": ["openvr"],
  "name": "temp",
  "version": "0.1.0"
}

==CMakeLists.txt==

cmake_minimum_required(VERSION 3.19.0)
project(Temp)
find_package(openvr REQUIRED) # Or find_package(openvr CONFIG REQUIRED)
file(Temp_Sources "stub.cpp")
add_library(Temp STATIC ${Temp_Sources})

CMake will be unable to find the 'openvr' package (Or 'OpenVR') and fail to configure. There's no way to just simply use vcpkg/cmake to take a dependency on openvr without going down the rabbit hole of writing a custom "find openvr" cmake file or similar.

Alternatively, if from a fresh vcpkg install you run 'vcpkg install openvr' you'll note it pulls down openvr binaries and include files, but again no cmake files of any sort are pulled down, which would allow a cmake-based project to simply make use of what vcpkg provided.

Thanks!

JoeRosselli avatar Oct 11 '23 19:10 JoeRosselli

Hi, yes, you'll need to do some extra work to add OpenVR with cmake + vcpkg. If you just want to get it working, you can check out this script to find OpenVR. https://github.com/LucidVR/opengloves-driver/blob/develop/cmake/FindOpenVR.cmake

You can then just do a target_link_libraries to OpenVR::OpenVR

danwillm avatar Oct 12 '23 10:10 danwillm

Bump. I've been using the above linked FindOpenVR file for a while but now I'm having linking/runtime issues related to OpenVR when I'm trying to package/install my library and then consume the installed library in another project. I don't know if it's something I'm doing wrong or if it's a limitation of the custom FindOpenVR file.

Either way, there should be a legitimate way to consume OpenVR via a package management system, without needing to run custom logic imported from a random project to make it work.

JoeRosselli avatar Aug 05 '24 05:08 JoeRosselli