Repository: conan-io/conan-center-index

Issue:
[request] dav1d - AV1 decoder
### Package Details
  * Package Name/Version: **dav1d/latest**
  * Website: **https://github.com/videolan/dav1d**
  * Source code: https://github.com/videolan/dav1d - https://code.videolan.org/videolan/dav1d


### Description Of The Library / Tool

> dav1d is a new AV1 cross-platform decoder, open-source, and focused on speed and correctness.

AV1 is an open codec from the [Alliance For Open Media](https://aomedia.org)



Discussion:

Resolving patch:
diff --git a/recipes/dav1d/all/conanfile.py b/recipes/dav1d/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/dav1d/all/conanfile.py
@@ -0,0 +1,117 @@
+import os
+from conans import ConanFile, Meson, tools
+
+required_conan_version = ">= 1.29.1"
+
+class Dav1dConan(ConanFile):
+    name = "dav1d"
+    description = "dav1d is a new AV1 cross-platform decoder, open-source, and focused on speed, size and correctness."
+    homepage = "https://www.videolan.org/projects/dav1d.html"
+    topics = ("conan", "av1", "codec", "video", "decoding")
+    license = "BSD-2-Clause"
+    url = "https://github.com/conan-io/conan-center-index"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+        "bit_depth": ["all", 8, 16],
+        "with_tools": [True, False],
+        "assembly": [True, False],
+        "with_avx512": [True, False],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+        "bit_depth": "all",
+        "with_tools": True,
+        "assembly": True,
+        "with_avx512": False
+    }
+    settings = "os", "arch", "compiler", "build_type"
+    generators = "cmake"
+
+    _meson = None
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    @property
+    def _build_subfolder(self):
+        return "build_subfolder"
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+        if self.settings.compiler == "Visual Studio" and self.settings.build_type == "Debug":
+            # debug builds with assembly often causes linker hangs or LNK1000
+            self.options.assembly = False
+
+    def configure(self):
+        if self.options.shared:
+            del self.options.fPIC
+        if not self.options.assembly:
+            del self.options.with_avx512
+        del self.settings.compiler.libcxx
+        del self.settings.compiler.cppstd
+
+    def build_requirements(self):
+        # Meson versions since 0.51.0 do not work with autodetect symbol prefix
+        # so the nasm build is broken
+        # See upstream bug https://github.com/mesonbuild/meson/issues/5482
+        self.build_requires("meson/0.51.0")
+        if self.options.assembly:
+            self.build_requires("nasm/2.15.05")
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        os.rename("dav1d-{}".format(self.version), self._source_subfolder)
+
+    def _patch_sources(self):
+        tools.replace_in_file(os.path.join(self._source_subfolder, "meson.build"),
+                              "subdir('doc')", "")
+
+    def _configure_meson(self):
+        if self._meson:
+            return self._meson
+        self._meson = Meson(self)
+        self._meson.options["enable_tests"] = False
+        self._meson.options["enable_asm"] = self.options.assembly
+        self._meson.options["enable_avx512"] = self.options.get_safe("with_avx512", False)
+        self._meson.options["enable_tools"] = self.options.with_tools
+        if self.options.bit_depth == "all":
+            self._meson.options["bitdepths"] = "8,16"
+        else:
+            self._meson.options["bitdepths"] = str(self.options.bit_depth)
+        self._meson.configure(source_folder=self._source_subfolder, build_folder=self._build_subfolder, pkg_config_paths=[self.install_folder])
+        return self._meson
+
+    def build(self):
+        self._patch_sources()
+        meson = self._configure_meson()
+        meson.build()
+
+    def package(self):
+        self.copy("COPYING", src=self._source_subfolder, dst="licenses")
+        meson = self._configure_meson()
+        meson.install()
+
+        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
+
+        tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.pdb")
+        tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.pdb")
+
+        if self.settings.compiler == "Visual Studio" and not self.options.shared:
+            # https://github.com/mesonbuild/meson/issues/7378
+            os.rename(os.path.join(self.package_folder, "lib", "libdav1d.a"),
+                      os.path.join(self.package_folder, "lib", "dav1d.lib"))
+
+    def package_info(self):
+        self.cpp_info.libs = ["dav1d"]
+        self.cpp_info.names["pkg_config"] = "dav1d"
+        if self.settings.os == "Linux":
+            self.cpp_info.system_libs.extend(["dl", "pthread"])
+
+        if self.options.with_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)


Test patch:
diff --git a/recipes/dav1d/all/test_package/CMakeLists.txt b/recipes/dav1d/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/dav1d/all/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package C)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(${PROJECT_NAME} test_package.c)
+target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
diff --git a/recipes/dav1d/all/test_package/conanfile.py b/recipes/dav1d/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/dav1d/all/test_package/conanfile.py
@@ -0,0 +1,17 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake"
+
+    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)
diff --git a/recipes/dav1d/all/test_package/test_package.c b/recipes/dav1d/all/test_package/test_package.c
new file mode 100644
--- /dev/null
+++ b/recipes/dav1d/all/test_package/test_package.c
@@ -0,0 +1,9 @@
+#include "dav1d/dav1d.h"
+
+#include <stdio.h>
+
+int main()
+{
+    printf("dav1d version: %s\n", dav1d_version());
+    return 0;
+}