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

aravis: Add a new recipe. #8379

Merged
merged 13 commits into from
Feb 2, 2022
8 changes: 8 additions & 0 deletions recipes/aravis/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
"0.8.19":
url: "https://github.com/AravisProject/aravis/releases/download/0.8.19/aravis-0.8.19.tar.xz"
sha256: "ddadf4fcc253ca2d8eb765f6a365f2d5dbcff9cd7a431b07eb978dff3b9b1034"
patches:
"0.8.19":
- patch_file: "patches/0.8.19-gst-shared-lib.patch"
base_path: "source_subfolder"
165 changes: 165 additions & 0 deletions recipes/aravis/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
from conans import ConanFile, Meson, tools
from conans.errors import ConanInvalidConfiguration
import os
import glob
import shutil


class AravisConan(ConanFile):
name = "aravis"
license = "LGPL-2.1-or-later"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/AravisProject/aravis"
description = "A vision library for genicam based cameras."
topics = ("usb", "camera")
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
"usb": [True, False],
"packet_socket": [True, False],
"gst_plugin": [True, False],
"tools": [True, False],
"introspection": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"usb": True,
"packet_socket": True,
"gst_plugin": False,
"tools": True,
"introspection": False
}
generators = "pkg_config"

_meson = None

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

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _aravis_api_version(self):
return ".".join(self.version.split(".")[0:2])

@property
def _is_msvc(self):
return self.settings.compiler == "Visual Studio"

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

def configure(self):
if self.options.shared:
del self.options.fPIC
sh0 marked this conversation as resolved.
Show resolved Hide resolved

def validate(self):
if self._is_msvc and self.settings.get_safe("compiler.runtime", "").startswith("MT"):
raise ConanInvalidConfiguration("Static MT/MTd runtime is not supported on Windows due to GLib issues")
if not self.options["glib"].shared and self.options.shared:
raise ConanInvalidConfiguration("Shared Aravis cannot link to static GLib")

def build_requirements(self):
self.build_requires("meson/0.60.2")
self.build_requires("pkgconf/1.7.4")
if self.options.introspection:
self.build_requires("gobject-introspection/1.70.0")

def requirements(self):
self.requires("glib/2.70.0")
self.requires("libxml2/2.9.12")
self.requires("zlib/1.2.11")
if self.options.usb:
self.requires("libusb/1.0.24")
if self.options.gst_plugin:
self.requires("gstreamer/1.19.2")
self.requires("gst-plugins-base/1.19.2")

sh0 marked this conversation as resolved.
Show resolved Hide resolved
def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

def _configure_meson(self):
if self._meson:
return self._meson
defs = dict()
sh0 marked this conversation as resolved.
Show resolved Hide resolved
defs["wrap_mode"] = "nofallback"
defs["usb"] = "enabled" if self.options.usb else "disabled"
defs["gst-plugin"] = "enabled" if self.options.gst_plugin else "disabled"
defs["packet-socket"] = "enabled" if self.options.get_safe("packet_socket") else "disabled"
defs["introspection"] = "enabled" if self.options.introspection else "disabled"
defs["viewer"] = "disabled"
defs["tests"] = "false"
defs["documentation"] = "disabled"
if self.settings.get_safe("compiler.runtime"):
defs["b_vscrt"] = str(self.settings.compiler.runtime).lower()
self._meson = Meson(self)
self._meson.configure(defs=defs, source_folder=self._source_subfolder, build_folder=self._build_subfolder)
return self._meson

def build(self):
self._patch_sources()
meson = self._configure_meson()
meson.build()

def _fix_library_names(self, path):
# https://github.com/mesonbuild/meson/issues/1412
if not self.options.shared and self._is_msvc:
with tools.chdir(path):
for filename_old in glob.glob("*.a"):
filename_new = filename_old[3:-2] + ".lib"
self.output.info("rename %s into %s" % (filename_old, filename_new))
shutil.move(filename_old, filename_new)
sh0 marked this conversation as resolved.
Show resolved Hide resolved

def package(self):
self.copy("COPYING", src=self._source_subfolder, dst="licenses", keep_path=False)
meson = self._configure_meson()
meson.install()

self._fix_library_names(os.path.join(self.package_folder, "lib"))
if self.options.gst_plugin:
self._fix_library_names(os.path.join(self.package_folder, "lib", "gstreamer-1.0"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.remove_files_by_mask(self.package_folder, "*.pdb")
if not self.options.tools:
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "arv-*")

def package_id(self):
self.info.requires["glib"].full_package_mode()
if self.options.gst_plugin:
self.info.requires["gstreamer"].full_package_mode()
self.info.requires["gst-plugins-base"].full_package_mode()

def package_info(self):
aravis_name = "aravis-{}".format(self._aravis_api_version)
self.cpp_info.names["pkg_config"] = aravis_name
self.cpp_info.includedirs = [os.path.join("include", aravis_name)]
self.cpp_info.libs = [aravis_name]
if self.settings.os == "Linux":
self.cpp_info.system_libs.extend(["dl", "pthread", "m", "resolv"])
elif self.settings.os == "Windows":
self.cpp_info.system_libs.extend(["ws2_32", "iphlpapi"])

if self.options.tools:
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)
if self.options.gst_plugin and self.options.shared:
gst_plugin_path = os.path.join(self.package_folder, "lib", "gstreamer-1.0")
self.output.info("Appending GST_PLUGIN_PATH env var: {}".format(gst_plugin_path))
self.env_info.GST_PLUGIN_PATH.append(gst_plugin_path)
11 changes: 11 additions & 0 deletions recipes/aravis/all/patches/0.8.19-gst-shared-lib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/gst/meson.build
+++ b/gst/meson.build
@@ -15,7 +15,7 @@ gst_c_args = [

gst_plugin_filename = 'gstaravis.@0@'.format (aravis_api_version)

-gst_plugin = shared_library (gst_plugin_filename,
+gst_plugin = library (gst_plugin_filename,
gst_sources, gst_headers,
name_suffix: [],
link_with: aravis_library,
10 changes: 10 additions & 0 deletions recipes/aravis/all/test_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 LANGUAGES C)

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

find_package(aravis REQUIRED CONFIG)

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


class AravisTestConan(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):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
16 changes: 16 additions & 0 deletions recipes/aravis/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <arv.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv)
{
printf("Enumerating Aravis interfaces:\n");
unsigned int if_count = arv_get_n_interfaces();
for (unsigned int if_index = 0; if_index < if_count; if_index++) {
const char* if_name = arv_get_interface_id(if_index);
if (if_name)
printf("* '%s'\n", if_name);
}
arv_shutdown();
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/aravis/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.8.19":
folder: all