Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openvr: migrate to Conan v2 #18788

Merged
merged 7 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions recipes/openvr/all/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion recipes/openvr/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
url: https://github.com/ValveSoftware/openvr/archive/refs/tags/v1.16.8.tar.gz
sha256: 387c98c0540f66595c4594e5f3340a1095dd90e954ff14fd5d89cc849ba32d1b
patches:
"1.16.8":
- patch_file: "patches/fix-includes-and-assert-1.16.8.patch"

Check warning on line 13 in recipes/openvr/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/fix-incl ... ^ (line: 13)
base_path: "source_subfolder"
127 changes: 75 additions & 52 deletions recipes/openvr/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import os
from conans import ConanFile, tools, CMake
from conans.errors import ConanInvalidConfiguration

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd, stdcpp_library
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rmdir, \
save, mkdir
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class OpenvrConan(ConanFile):
name = "openvr"
description = "API and runtime that allows access to VR hardware from applications have specific knowledge of the hardware they are targeting."
topics = ("conan", "openvr", "vr", )
description = (
"API and runtime that allows access to VR hardware from applications "
"have specific knowledge of the hardware they are targeting."
)
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/ValveSoftware/openvr"
license = "BSD-3-Clause"
topics = ("vr", "virtual reality")

settings = "os", "compiler", "build_type", "arch"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -20,83 +34,92 @@ class OpenvrConan(ConanFile):
"fPIC": True,
}

exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"
def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, "11")
self.options.rm_safe("fPIC")

if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < "5":
raise ConanInvalidConfiguration("OpenVR can't be compiled by {0} {1}".format(self.settings.compiler,
self.settings.compiler.version))
def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("jsoncpp/1.9.4")
self.requires("jsoncpp/1.9.5", transitive_headers=True, transitive_libs=True)

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, 11)
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "5":
raise ConanInvalidConfiguration(
f"OpenVR can't be compiled by {self.settings.compiler} {self.settings.compiler.version}"
)

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = "{}-{}".format(self.name, self.version)
os.rename(extracted_dir, self._source_subfolder)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["BUILD_SHARED"] = self.options.shared
tc.cache_variables["BUILD_UNIVERSAL"] = False
# Let Conan handle the stdlib setting, even if we are using libc++
tc.cache_variables["USE_LIBCXX"] = False
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
apply_conandata_patches(self)
# Honor fPIC=False
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"-fPIC", "")
# Unvendor jsoncpp (we rely on our CMake wrapper for jsoncpp injection)
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"),
"jsoncpp.cpp", "")
tools.rmdir(os.path.join(self._source_subfolder, "src", "json"))

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_SHARED"] = self.options.shared
self._cmake.definitions["BUILD_UNIVERSAL"] = False
self._cmake.definitions["USE_LIBCXX"] = False
self._cmake.configure()

return self._cmake
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "-fPIC", "")
# Unvendor jsoncpp
replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"), "jsoncpp.cpp", "")
rmdir(self, os.path.join(self.source_folder, "src", "json"))
# Add jsoncpp dependency from Conan
save(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"),
"find_package(jsoncpp REQUIRED CONFIG)\n"
"target_link_libraries(${LIBNAME} JsonCpp::JsonCpp)",
append=True)

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

@property
def _lib_name(self):
if self.settings.os == "Windows" and self.settings.arch == "x86_64":
return "openvr_api64"
return "openvr_api"

def package(self):
self.copy("LICENSE", src=os.path.join(self.source_folder, self._source_subfolder), dst="licenses")
cmake = self._configure_cmake()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
self.copy(pattern="openvr_api*.dll", dst="bin", src="bin", keep_path=False)
tools.rmdir(os.path.join(self.package_folder, "share"))
if self.settings.os == "Windows" and self.options.shared:
mkdir(self, os.path.join(self.package_folder, "bin"))
os.rename(os.path.join(self.package_folder, "lib", f"{self._lib_name}.dll"),
os.path.join(self.package_folder, "bin", f"{self._lib_name}.dll"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.names["pkg_config"] = "openvr"
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.set_property("pkg_config_name", "openvr")
self.cpp_info.libs = [self._lib_name]
self.cpp_info.includedirs.append(os.path.join("include", "openvr"))

if not self.options.shared:
self.cpp_info.defines.append("OPENVR_BUILD_STATIC")
libcxx = tools.stdcpp_library(self)
libcxx = stdcpp_library(self)
if libcxx:
self.cpp_info.system_libs.append(libcxx)

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("dl")

if tools.is_apple_os(self.settings.os):
self.cpp_info.frameworks.append("Foundation")
if is_apple_os(self):
self.cpp_info.frameworks.extend(["Foundation", "CoreFoundation"])
9 changes: 4 additions & 5 deletions recipes/openvr/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(openvr REQUIRED CONFIG)

add_executable(${CMAKE_PROJECT_NAME} test_package.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE openvr::openvr)
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY CXX_STANDARD 11)
22 changes: 16 additions & 6 deletions recipes/openvr/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/openvr/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
16 changes: 16 additions & 0 deletions recipes/openvr/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conans import ConanFile, CMake, tools
import os

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)