Skip to content

Commit

Permalink
(#8379) aravis: Add a new recipe.
Browse files Browse the repository at this point in the history
* aravis: Add a new recipe.

* aravis: Full package id for gstreamer too.

* aravis: Ensure gstreamer libraries are static/shared.

* aravis: Downgrade glib version.

* aravis: Disable gstreamer plugin for now.

* aravis: Fix MSVC build.

* aravis: Review suggestions.

* aravis: Set glib 'shared' property in configure.

* aravis: Add environment variables for meson to fix glib-compile-resources.

* aravis: Bump versions.

* aravis: Disable macOS builds due to System Integrity Protection issue.

* aravis: Bump version in config.yml as well.

* aravis: Review suggestion. Replace shutil.move() with tools.rename().
  • Loading branch information
sh0 authored Feb 2, 2022
1 parent 4bfe060 commit b8401b1
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 0 deletions.
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.20":
url: "https://github.com/AravisProject/aravis/releases/download/0.8.20/aravis-0.8.20.tar.xz"
sha256: "0c0eb5a76109f29180c09c7e6a23fd403633bf22bbe8468a0ae44995c4449f46"
patches:
"0.8.20":
- patch_file: "patches/0.8.19-gst-shared-lib.patch"
base_path: "source_subfolder"
169 changes: 169 additions & 0 deletions recipes/aravis/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
from conans import ConanFile, Meson, RunEnvironment, tools
from conans.errors import ConanInvalidConfiguration
import os
import glob


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
self.options["glib"].shared = True

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")
if self.settings.os == "Macos":
raise ConanInvalidConfiguration("macOS builds are disabled until conan-io/conan#7324 gets merged to fix macOS SIP issue #8443")

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

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()
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()
with tools.environment_append(RunEnvironment(self).vars):
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))
tools.rename(filename_old, filename_new)

def package(self):
self.copy("COPYING", src=self._source_subfolder, dst="licenses", keep_path=False)
with tools.environment_append(RunEnvironment(self).vars):
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.20":
folder: all

0 comments on commit b8401b1

Please sign in to comment.