Skip to content

Commit

Permalink
(conan-io#16464) vaapi: conan V2 compatibility
Browse files Browse the repository at this point in the history
* vaapi: conan V2 compatibility

* Update conanfile.py

* fix conan V2 test
  • Loading branch information
ericLemanissier authored and 0xFireWolf committed Apr 2, 2023
1 parent d3760eb commit 4d283fe
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 38 deletions.
35 changes: 9 additions & 26 deletions recipes/vaapi/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration, ConanException
from conan.errors import ConanInvalidConfiguration
from conan.tools.gnu import PkgConfig
from conan.tools.system import package_manager
from conans import tools

required_conan_version = ">=1.47"

Expand All @@ -21,27 +21,9 @@ def validate(self):
raise ConanInvalidConfiguration("This recipe supports only Linux and FreeBSD")

def package_id(self):
self.info.header_only()

def _fill_cppinfo_from_pkgconfig(self, name):
pkg_config = tools.PkgConfig(name)
if not pkg_config.provides:
raise ConanException("VAAPI development files aren't available, give up")
libs = [lib[2:] for lib in pkg_config.libs_only_l]
lib_dirs = [lib[2:] for lib in pkg_config.libs_only_L]
ldflags = [flag for flag in pkg_config.libs_only_other]
include_dirs = [include[2:] for include in pkg_config.cflags_only_I]
cflags = [flag for flag in pkg_config.cflags_only_other if not flag.startswith("-D")]
defines = [flag[2:] for flag in pkg_config.cflags_only_other if flag.startswith("-D")]

self.cpp_info.system_libs.extend(libs)
self.cpp_info.libdirs.extend(lib_dirs)
self.cpp_info.sharedlinkflags.extend(ldflags)
self.cpp_info.exelinkflags.extend(ldflags)
self.cpp_info.defines.extend(defines)
self.cpp_info.includedirs.extend(include_dirs)
self.cpp_info.cflags.extend(cflags)
self.cpp_info.cxxflags.extend(cflags)
del self.info.settings.compiler
del self.info.settings.arch
del self.info.settings.build_type

def system_requirements(self):
dnf = package_manager.Dnf(self)
Expand All @@ -63,8 +45,9 @@ def system_requirements(self):
pkg.install(["libva"], update=True, check=True)

def package_info(self):
self.cpp_info.includedirs = []
self.cpp_info.libdirs = []
if self.settings.os in ["Linux", "FreeBSD"]:
for name in ['libva', 'libva-x11', 'libva-drm']:
self._fill_cppinfo_from_pkgconfig(name)
pkg_config = PkgConfig(self, name)
self.cpp_info.components[name].includedirs = []
self.cpp_info.components[name].libdirs = []
pkg_config.fill_cpp_info(self.cpp_info.components[name])
12 changes: 5 additions & 7 deletions recipes/vaapi/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
project(test_package LANGUAGES C)

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

set(SOURCES test_package.c)

add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
add_executable(test_package test_package.c)
target_link_libraries(test_package PRIVATE vaapi::vaapi xorg::xorg)
19 changes: 14 additions & 5 deletions recipes/vaapi/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, cmake_layout


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
generators = "CMakeToolchain", "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv"
requires = ("xorg/system",)

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 not cross_building(self):
cmd = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(cmd, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/vaapi/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

set(SOURCES ../test_package/test_package.c)

add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
18 changes: 18 additions & 0 deletions recipes/vaapi/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
requires = ("xorg/system",)

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)

0 comments on commit 4d283fe

Please sign in to comment.