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: Bump deps and upgrade for conan v2 #16913

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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.

15 changes: 14 additions & 1 deletion recipes/openvr/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@ sources:
patches:
"1.16.8":
- patch_file: "patches/fix-includes-and-assert-1.16.8.patch"
base_path: "source_subfolder"
patch_description: "Fix compilaton errors due to wrong headers folder and usage of missing assert.h"
patch_type: "backport"
paulharris marked this conversation as resolved.
Show resolved Hide resolved
patch_source: "https://github.com/ValveSoftware/openvr/pull/1524 https://github.com/ValveSoftware/openvr/pull/1542"
- patch_file: "patches/1.16.8-fix-jsoncpp.patch"
patch_description: "Fix jsoncpp inclusion"
patch_type: "conan"
"1.14.15":
- patch_file: "patches/1.16.8-fix-jsoncpp.patch"
patch_description: "Fix jsoncpp inclusion"
patch_type: "conan"
"1.12.5":
- patch_file: "patches/1.16.8-fix-jsoncpp.patch"
patch_description: "Fix jsoncpp inclusion"
patch_type: "conan"
110 changes: 65 additions & 45 deletions recipes/openvr/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.files import apply_conandata_patches, export_conandata_patches, replace_in_file, rmdir, collect_libs, get, copy
from conan.tools.build import check_min_cppstd, stdcpp_library
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.scm import Version
import os
from conans import ConanFile, tools, CMake
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.59.0"
paulharris marked this conversation as resolved.
Show resolved Hide resolved

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", )
topics = ("vr")
paulharris marked this conversation as resolved.
Show resolved Hide resolved
package_type = "library"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/ValveSoftware/openvr"
license = "BSD-3-Clause"
Expand All @@ -20,83 +28,95 @@ class OpenvrConan(ConanFile):
"fPIC": True,
}

exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
_cmake = None
@property
def _min_cppstd(self):
return 11

@property
def _source_subfolder(self):
return "source_subfolder"
def _compilers_minimum_version(self):
return {
"Visual Studio": "15",
"msvc": "14.1",
"gcc": "5",
"clang": "5",
"apple-clang": "5.1",
}
Copy link
Contributor

@SpaceIm SpaceIm May 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides wrong msvc version, why do you restrict more than before? It was raising for gcc < 5 only, so we know it works for Visual Studio 2015 for example. You should keep previous logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok then, I've reverted :)


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")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

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.variables["BUILD_SHARED"] = self.options.shared
tc.variables["BUILD_UNIVERSAL"] = False
tc.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", "")
replace_in_file(self, os.path.join(self.source_folder, "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, "src", "CMakeLists.txt"), "jsoncpp.cpp", "")
rmdir(self, os.path.join(self.source_folder, "src", "json"))

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

def package(self):
self.copy("LICENSE", src=os.path.join(self.source_folder, self._source_subfolder), dst="licenses")
cmake = self._configure_cmake()
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
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"))
copy(self, pattern="openvr_api*.dll", dst=os.path.join(self.package_folder, "bin"), src=os.path.join(self.source_folder, "bin"), keep_path=False)
paulharris marked this conversation as resolved.
Show resolved Hide resolved
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 = collect_libs(self)
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):
if is_apple_os(self):
self.cpp_info.frameworks.append("Foundation")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["pkg_config"] = "openvr"
paulharris marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions recipes/openvr/all/patches/1.16.8-fix-jsoncpp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,6 +31,8 @@

add_definitions( -DVR_API_PUBLIC )

+find_package(jsoncpp CONFIG REQUIRED)
+
# Check if 32 or 64 bit system.
set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -98,7 +98,8 @@
set(EXTRA_LIBS ${EXTRA_LIBS} c++ c++abi)
endif()

target_link_libraries(${LIBNAME} ${EXTRA_LIBS} ${CMAKE_DL_LIBS})
+target_link_libraries(${LIBNAME} PUBLIC JsonCpp::JsonCpp)
target_include_directories(${LIBNAME} PUBLIC ${OPENVR_HEADER_DIR})

install(TARGETS ${LIBNAME} DESTINATION lib)
14 changes: 7 additions & 7 deletions recipes/openvr/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.15)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
project(test_package CXX)

add_executable(${CMAKE_PROJECT_NAME} test_package.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY CXX_STANDARD 11)
find_package(openvr REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE openvr::openvr)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_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.bindirs[0], "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/)
19 changes: 19 additions & 0 deletions recipes/openvr/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


# legacy validation with Conan 1.x
class TestPackageV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

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

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